| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using System;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Diagnostics.CodeAnalysis;
- using System.Runtime.CompilerServices;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.WPF;
- using PropertyChanged;
- using Syncfusion.UI.Xaml.Scheduler;
- namespace PRSDesktop
- {
-
- public interface ICalendarAppointment
- {
- // object Id { get; }
- Brush Background { get; }
- Brush BorderBrush { get; }
- Brush Foreground { get; }
- string? Subject { get; }
- string? Notes { get; }
- // ObservableCollection<object> ResourceIdCollection { get; }
- // DateTime StartTime { get; }
- // DateTime EndTime { get; }
-
- BitmapImage? Image { get; }
- object Model { get; }
- Employee? Employee { get; }
- TimeSpan StartTime { get; }
- TimeSpan EndTime { get; }
- DateTime Date { get; }
- bool CanAdjust { get; }
- }
-
- public interface ICalendarAppointment<T> : ICalendarAppointment where T : notnull
- {
- new T Model { get; }
- object ICalendarAppointment.Model => Model;
- }
-
- [DoNotNotify]
- public abstract class CalendarAppointment<T> : ICalendarAppointment<T>, INotifyPropertyChanged
- where T : notnull
- {
- private Employee? _employee;
- // Nullable because this assignment might be rendered on a column that doesn't exist.
- public virtual Employee? Employee
- {
- get => _employee;
- set
- {
- _employee = value;
- OnPropertyChanged();
- }
- }
- public BitmapImage? Image { get; set; }
- public string? Subject { get; set; }
- public string? Notes { get; set; }
-
- public T Model { get; }
- private Brush _background;
- public Brush Background
- {
- get => _background;
- [MemberNotNull(nameof(_background), nameof(BorderBrush))]
- private set
- {
- _background = value;
- if(value is SolidColorBrush brush)
- {
- BorderBrush = brush.Color.AdjustBrightness(-0.5f).ToBrush();
- }
- else
- {
- BorderBrush = Colors.Black.ToBrush();
- }
- }
- }
- public Brush BorderBrush { get; private set; }
- public Brush Foreground { get; private set; }
- public abstract TimeSpan StartTime { get; set; }
- public abstract TimeSpan EndTime { get; set; }
- public abstract DateTime Date { get; set; }
- public abstract bool CanAdjust { get; }
- private Func<T, string?> Colour;
- public CalendarAppointment(T model, Employee employee, Func<T, string?> color)
- {
- Model = model;
- _employee = employee;
- Colour = color;
- UpdateColour();
- }
- [MemberNotNull(nameof(_background), nameof(Foreground), nameof(BorderBrush))]
- protected void UpdateColour()
- {
- var c = Colour(Model);
- Color c2 = string.IsNullOrWhiteSpace(c)
- ? Colors.White
- : (Color)ColorConverter.ConvertFromString(c);
-
- Background = new SolidColorBrush(c2);
- Foreground = new SolidColorBrush(ImageUtils.GetForegroundColor(c2));
- }
- public event PropertyChangedEventHandler? PropertyChanged;
- protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
- {
- PropertyChanged?.Invoke(this, new(propertyName));
- }
- }
-
- public class CalendarAppointments : ScheduleAppointmentCollection //ObservableCollection<ICalendarAppointment> { }}
- {
- }
- }
|