CalendarAppointment.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.ComponentModel;
  4. using System.Diagnostics.CodeAnalysis;
  5. using System.Runtime.CompilerServices;
  6. using System.Windows.Media;
  7. using System.Windows.Media.Imaging;
  8. using Comal.Classes;
  9. using InABox.WPF;
  10. using PropertyChanged;
  11. using Syncfusion.UI.Xaml.Scheduler;
  12. namespace PRSDesktop
  13. {
  14. public interface ICalendarAppointment
  15. {
  16. // object Id { get; }
  17. Brush Background { get; }
  18. Brush BorderBrush { get; }
  19. Brush Foreground { get; }
  20. string? Subject { get; }
  21. string? Notes { get; }
  22. // ObservableCollection<object> ResourceIdCollection { get; }
  23. // DateTime StartTime { get; }
  24. // DateTime EndTime { get; }
  25. BitmapImage? Image { get; }
  26. object Model { get; }
  27. Employee? Employee { get; }
  28. TimeSpan StartTime { get; }
  29. TimeSpan EndTime { get; }
  30. DateTime Date { get; }
  31. bool CanAdjust { get; }
  32. }
  33. public interface ICalendarAppointment<T> : ICalendarAppointment where T : notnull
  34. {
  35. new T Model { get; }
  36. object ICalendarAppointment.Model => Model;
  37. }
  38. [DoNotNotify]
  39. public abstract class CalendarAppointment<T> : ICalendarAppointment<T>, INotifyPropertyChanged
  40. where T : notnull
  41. {
  42. private Employee? _employee;
  43. // Nullable because this assignment might be rendered on a column that doesn't exist.
  44. public virtual Employee? Employee
  45. {
  46. get => _employee;
  47. set
  48. {
  49. _employee = value;
  50. OnPropertyChanged();
  51. }
  52. }
  53. public BitmapImage? Image { get; set; }
  54. public string? Subject { get; set; }
  55. public string? Notes { get; set; }
  56. public T Model { get; }
  57. private Brush _background;
  58. public Brush Background
  59. {
  60. get => _background;
  61. [MemberNotNull(nameof(_background), nameof(BorderBrush))]
  62. private set
  63. {
  64. _background = value;
  65. if(value is SolidColorBrush brush)
  66. {
  67. BorderBrush = brush.Color.AdjustBrightness(-0.5f).ToBrush();
  68. }
  69. else
  70. {
  71. BorderBrush = Colors.Black.ToBrush();
  72. }
  73. }
  74. }
  75. public Brush BorderBrush { get; private set; }
  76. public Brush Foreground { get; private set; }
  77. public abstract TimeSpan StartTime { get; set; }
  78. public abstract TimeSpan EndTime { get; set; }
  79. public abstract DateTime Date { get; set; }
  80. public abstract bool CanAdjust { get; }
  81. private Func<T, string?> Colour;
  82. public CalendarAppointment(T model, Employee employee, Func<T, string?> color)
  83. {
  84. Model = model;
  85. _employee = employee;
  86. Colour = color;
  87. UpdateColour();
  88. }
  89. [MemberNotNull(nameof(_background), nameof(Foreground), nameof(BorderBrush))]
  90. protected void UpdateColour()
  91. {
  92. var c = Colour(Model);
  93. Color c2 = string.IsNullOrWhiteSpace(c)
  94. ? Colors.White
  95. : (Color)ColorConverter.ConvertFromString(c);
  96. Background = new SolidColorBrush(c2);
  97. Foreground = new SolidColorBrush(ImageUtils.GetForegroundColor(c2));
  98. }
  99. public event PropertyChangedEventHandler? PropertyChanged;
  100. protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
  101. {
  102. PropertyChanged?.Invoke(this, new(propertyName));
  103. }
  104. }
  105. public class CalendarAppointments : ScheduleAppointmentCollection //ObservableCollection<ICalendarAppointment> { }}
  106. {
  107. }
  108. }