瀏覽代碼

Started on redoing the Calendar screen

Kenric Nugteren 2 月之前
父節點
當前提交
08eca714a6
共有 2 個文件被更改,包括 139 次插入99 次删除
  1. 46 11
      prs.desktop/Components/Calendar/Calendar.xaml
  2. 93 88
      prs.desktop/Components/Calendar/Calendar.xaml.cs

+ 46 - 11
prs.desktop/Components/Calendar/Calendar.xaml

@@ -4,10 +4,12 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:local="clr-namespace:PRSDesktop"
+             xmlns:wpf="clr-namespace:InABox.Wpf;assembly=InABox.Wpf"
              xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
              xmlns:dynamicGrid="clr-namespace:InABox.DynamicGrid;assembly=InABox.Wpf"
              mc:Ignorable="d"
-             d:DesignHeight="600" d:DesignWidth="800" SizeChanged="Calendar_OnSizeChanged">
+             d:DesignHeight="600" d:DesignWidth="800" SizeChanged="Calendar_OnSizeChanged"
+             Name="Main">
     
     <UserControl.Resources>
 
@@ -34,7 +36,40 @@
         OnChanged="_splitPanel_OnOnChanged">
         
         <dynamicGrid:DynamicSplitPanel.Master>
-            <local:SfScheduler2
+            <Grid>
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="Auto"/>
+                    <RowDefinition Height="*"/>
+                </Grid.RowDefinitions>
+                <DockPanel Grid.Row="0" LastChildFill="False"
+                           Margin="0,0,0,4"
+                           Visibility="{Binding HeaderVisibility, ElementName=Main}">
+                    <Button DockPanel.Dock="Left"
+                            MinWidth="25" MinHeight="25"
+                            Margin="0,0,4,0">
+                        <Polyline Points="6,0 0,6 6,12"
+                                  Stroke="Black"
+                                  StrokeThickness="1"/>
+                    </Button>
+                    <Button DockPanel.Dock="Left"
+                            MinWidth="25" MinHeight="25"
+                            Margin="0,0,4,0">
+                        <Polyline Points="0,0 6,6 0,12"
+                                  Stroke="Black"
+                                  StrokeThickness="1"/>
+                    </Button>
+                    <DatePicker DockPanel.Dock="Left"/>
+                    <Button DockPanel.Dock="Right"
+                            Content="Today"
+                            MinHeight="25"
+                            Margin="4,0,0,0"/>
+                </DockPanel>
+                <wpf:CalendarControl Name="Calendar"
+                                     Grid.Row="1">
+                    
+                </wpf:CalendarControl>
+            </Grid>
+            <!--local:SfScheduler2
                 x:Name="Bookings"
                 HeaderDateFormat="dd MMMM yyyy"
                 SizeChanged="Schedule_SizeChanged"
@@ -50,11 +85,11 @@
                 FirstDayOfWeek="Monday"
                 >
                 
-                <!-- <syncfusion:SfScheduler.HeaderTemplate> -->
-                <!--     <DataTemplate> -->
-                <!--         <Border BorderBrush="Transparent" Background="Transparent" Height="0" Width="200"/> -->
-                <!--     </DataTemplate> -->
-                <!-- </syncfusion:SfScheduler.HeaderTemplate> -->
+                <- <syncfusion:SfScheduler.HeaderTemplate> ->
+                <-     <DataTemplate> ->
+                <-         <Border BorderBrush="Transparent" Background="Transparent" Height="0" Width="200"/> ->
+                <-     </DataTemplate> ->
+                <- </syncfusion:SfScheduler.HeaderTemplate> ->
                 
                 <syncfusion:SfScheduler.CellContextMenu>
                     <ContextMenu />
@@ -87,9 +122,9 @@
                             <DataTemplate>
                                 <Border BorderThickness="0" Background="{Binding AppointmentBackground}" Padding="2" CornerRadius="2">
                         
-                                    <!-- <Border.ToolTip> -->
-                                    <!--     <local:CalendarBlock DataContext="{Binding}" /> -->
-                                    <!-- </Border.ToolTip> -->
+                                    <!- <Border.ToolTip> ->
+                                    <!-     <local:CalendarBlock DataContext="{Binding}" /> ->
+                                    <!- </Border.ToolTip> ->
                                     
                                     <local:CalendarBlock DataContext="{Binding}" />
                         
@@ -99,7 +134,7 @@
 
                     </syncfusion:DaysViewSettings>
                 </syncfusion:SfScheduler.DaysViewSettings>
-            </local:SfScheduler2>
+            </local:SfScheduler2-->
         </dynamicGrid:DynamicSplitPanel.Master>
         
         

+ 93 - 88
prs.desktop/Components/Calendar/Calendar.xaml.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 using System.Linq;
 using System.Windows;
@@ -71,11 +72,10 @@ namespace PRSDesktop
             Settings   // Dont allow settings to be updated
         }
 
-        private EventSuppressor suppressor = null;
+        private EventSuppressor? suppressor = null;
         public void DisableUpdate()
         {
-            if (suppressor == null)
-                suppressor = new EventSuppressor(Suppress.Refresh, Suppress.Settings);
+            suppressor ??= new EventSuppressor(Suppress.Refresh, Suppress.Settings);
         }
 
         public void EnableUpdate()
@@ -87,10 +87,12 @@ namespace PRSDesktop
             }
         }
         
-        private void DoSetValue<T>(DependencyProperty property, T value, Action? updateselector, Action? updateinterface)
+        private void DoSetValue<T>(DependencyProperty? property, T value, Action? updateselector, Action? updateinterface)
         {
-
-            SetValue(property, value);
+            if(property is not null)
+            {
+                SetValue(property, value);
+            }
         
             if (!EventSuppressor.IsSet(Suppress.Selector) && (updateselector != null))
                 using (new EventSuppressor(Suppress.Events))
@@ -106,8 +108,8 @@ namespace PRSDesktop
             {
                 Properties.SettingsVisible = SettingsVisible;
                 Properties.Date = SelectedDate;
-                Properties.StartHour = (int)Bookings.DaysViewSettings.StartHour;
-                Properties.EndHour = (int)Bookings.DaysViewSettings.EndHour;
+                // Properties.StartHour = (int)Bookings.DaysViewSettings.StartHour;
+                // Properties.EndHour = (int)Bookings.DaysViewSettings.EndHour;
                 Properties.CalendarView = CalendarView;
                 Properties.EmployeeSelector = EmployeeSettings;
                 Properties.EmployeeSelection = EmployeeSelection;
@@ -132,11 +134,7 @@ namespace PRSDesktop
         public Visibility HeaderVisibility
         {
             get => (Visibility)GetValue(HeaderVisibilityProperty);
-            set
-            {
-                SetValue(HeaderVisibilityProperty,value);
-                Bookings.HeaderVisibility = value;
-            }
+            set => SetValue(HeaderVisibilityProperty,value);
         }
         
         #endregion
@@ -171,7 +169,7 @@ namespace PRSDesktop
                     _splitPanel.AllowableViews = value == CalendarSettingsVisibility.Disabled
                         ? DynamicSplitPanelView.Master
                         : DynamicSplitPanelView.Master | DynamicSplitPanelView.Combined;
-                    ResizeColumns(this.ActualWidth);
+                    // ResizeColumns(this.ActualWidth);
                 }
             );
         }
@@ -185,33 +183,39 @@ namespace PRSDesktop
                 nameof(CalendarView), 
                 typeof(CalendarViewType), 
                 typeof(Calendar), 
-                new UIPropertyMetadata(CalendarViewType.Day)
+                new UIPropertyMetadata(CalendarViewType.Day, CalendarView_Changed)
             );
-        
+
         public CalendarViewType CalendarView
         {
             get => (CalendarViewType)GetValue(CalendarViewProperty);
-            set => SetCalendarView(value);
+            set => SetValue(CalendarViewProperty, value);
         }
         
         private void SetCalendarView(CalendarViewType value)
         {
-            DoSetValue(
-                CalendarViewProperty,
-                value,
-                () => CalendarViewSelector.SelectedIndex = (int)value,
-                () =>
-                {
-                    Bookings.ViewType = value switch
-                    {
-                        CalendarViewType.Day => SchedulerViewType.Day,
-                        CalendarViewType.WorkWeek => SchedulerViewType.WorkWeek,
-                        CalendarViewType.Week => SchedulerViewType.Week,
-                        _ => SchedulerViewType.Day
-                    };
-                    ResizeColumns(this.ActualWidth);
-                }
-            );
+            // DoSetValue(
+            //     CalendarViewProperty,
+            //     value,
+            //     () =>
+            //     {
+            //         Bookings.ViewType = value switch
+            //         {
+            //             CalendarViewType.Day => SchedulerViewType.Day,
+            //             CalendarViewType.WorkWeek => SchedulerViewType.WorkWeek,
+            //             CalendarViewType.Week => SchedulerViewType.Week,
+            //             _ => SchedulerViewType.Day
+            //         };
+            //         ResizeColumns(this.ActualWidth);
+            //     }
+            // );
+        }
+
+        private static void CalendarView_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            if (d is not Calendar calendar) return;
+            calendar.CalendarViewSelector.SelectedIndex = (int)calendar.CalendarView;
+            calendar.Properties.CalendarView = calendar.CalendarView;
         }
         
         private void CalendarViewSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -658,21 +662,21 @@ namespace PRSDesktop
         
         #region Event Handlers
         
-        public event LoadSettings<CalendarSettings> LoadSettings;
+        public event LoadSettings<CalendarSettings>? LoadSettings;
         
-        public event SaveSettings<CalendarSettings> SaveSettings;
+        public event SaveSettings<CalendarSettings>? SaveSettings;
 
-        public CalendarConfigurationEvent ConfigurationChanged;
+        public CalendarConfigurationEvent? ConfigurationChanged;
         
-        public event CalendarDataEvent CustomiseContextMenu;
+        public event CalendarDataEvent? CustomiseContextMenu;
         
-        public event CalendarDataEvent SelectionChanged;
+        public event CalendarDataEvent? SelectionChanged;
 
-        public event CalendarDataEvent ItemCreated;        
+        public event CalendarDataEvent? ItemCreated;        
         
-        public event CalendarDataEvent ItemChanged;
+        public event CalendarDataEvent? ItemChanged;
 
-        public event CalendarHandledEvent ItemEditing;
+        public event CalendarHandledEvent? ItemEditing;
         
         #endregion
 
@@ -693,8 +697,8 @@ namespace PRSDesktop
         
         private bool bColumnsLoaded;
         
-        private AssignmentGrid ag;
-        private DynamicDataGrid<Meeting> mg;
+        private AssignmentGrid? ag;
+        private DynamicDataGrid<Meeting>? mg;
         
         public bool IsReady { get; set; }
         
@@ -709,7 +713,7 @@ namespace PRSDesktop
                 InitializeComponent();
                 SetValue(StartHourProperty, 0);
                 SetValue(EndHourProperty, 24);
-                SfSkinManager.SetTheme(Bookings, new Theme() { ThemeName = "Office2019White", ScrollBarMode = ScrollBarMode.Compact });
+                // SfSkinManager.SetTheme(Bookings, new Theme() { ThemeName = "Office2019White", ScrollBarMode = ScrollBarMode.Compact });
             }
         }
         
@@ -753,16 +757,17 @@ namespace PRSDesktop
                 _standardleaves = query.Get<StandardLeave>().Rows.Select(row => new StandardLeaveModel(row)).ToArray();
                 _leaverequests = query.Get<LeaveRequest>().Rows.Select(row => new LeaveRequestModel(row)).ToArray();
 
-                var widthtimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) };
-                widthtimer.Tick += (o, e) =>
-                {
-                    if (Bookings.ActualWidth > 0.0F)
-                    {
-                        widthtimer.IsEnabled = false;
-                        ReloadColumns();
-                    }
-                };
-                widthtimer.IsEnabled = true;
+                ReloadColumns();
+                // var widthtimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) };
+                // widthtimer.Tick += (o, e) =>
+                // {
+                //     if (Bookings.ActualWidth > 0.0F)
+                //     {
+                //         widthtimer.IsEnabled = false;
+                //         ReloadColumns();
+                //     }
+                // };
+                // widthtimer.IsEnabled = true;
             
             }
         }
@@ -829,8 +834,8 @@ namespace PRSDesktop
  
                 try
                 {
-                    Bookings.DisplayDate = Bookings.SelectedDate.HasValue ? Bookings.SelectedDate.Value : StartDate;
-                    Bookings.ItemsSource = appointments;
+                    // Bookings.DisplayDate = Bookings.SelectedDate.HasValue ? Bookings.SelectedDate.Value : StartDate;
+                    Calendar.ItemsSource = appointments;
                 }
                 catch (Exception e)
                 {
@@ -930,7 +935,7 @@ namespace PRSDesktop
             ) where TEntity : Entity where TModel : class, IModel
             {
                 
-                if (Bookings.ItemsSource is CalendarAppointments appointments)
+                if (Calendar.ItemsSource is CalendarAppointments appointments)
                 {
                     var appointment = appointments.FirstOrDefault(x => (Guid)x.Id == entity.ID) as ScheduleAppointment;
                     if (appointment != null)
@@ -953,7 +958,7 @@ namespace PRSDesktop
 
             }
             
-            if (Bookings.ItemsSource is CalendarAppointments appointments)
+            if (Calendar.ItemsSource is CalendarAppointments appointments)
                 UpdateCalendar(assignment, _assignments, (model) => LoadAssignment(model,appointments));
             
         }
@@ -1144,38 +1149,38 @@ namespace PRSDesktop
             ResizeColumns(e.NewSize.Width);
         }
 
-        private void ResizeColumns(double width)
-        {
-            if (double.IsNaN(width) || !Bookings.FindVisualChildren<ScrollPanel>().Any())
-                return;
+        // private void ResizeColumns(double width)
+        // {
+        //     if (double.IsNaN(width) || !Bookings.FindVisualChildren<ScrollPanel>().Any())
+        //         return;
 
-            var maxcount = (int)width / 75;
-            Bookings.DaysViewSettings.VisibleResourceCount = Math.Min(maxcount,
-                _employees.Length * (Bookings.ViewType == SchedulerViewType.Day ? 1 : Bookings.ViewType == SchedulerViewType.WorkWeek ? 5 : 7));
-            
-            if (Bookings.ResourceCollection is ObservableCollection<SchedulerResource> resources)
-            {
-                var colwidth = GetResourceColumnWidth();
-                foreach (var emp in _employees)
-                {
-                    var resource = resources.FirstOrDefault(x => String.Equals(x.Id?.ToString(), emp.ID.ToString()));
-                    if (resource != null)
-                    {
-                        var comps = emp.Name.Split(' ');
-                        var display = emp.Name;
-                        if (colwidth < 75)
-                            display = string.Format("{0}{1}", comps[0].Length > 0 ? comps[0][..1] : "",
-                                comps.Length > 1 ? comps.Skip(1).First()[..1].ToUpper() : "");
-                        else if (colwidth < 150)
-                            display = string.Format("{0} {1}", comps.First(),
-                                comps.Length > 1 ? comps.Skip(1).First()[..1].ToUpper() : "");
-                        resource.Name = display;
-                    }
-                }
-            }
-        }
+        //     var maxcount = (int)width / 75;
+        //     Bookings.DaysViewSettings.VisibleResourceCount = Math.Min(maxcount,
+        //         _employees.Length * (Bookings.ViewType == SchedulerViewType.Day ? 1 : Bookings.ViewType == SchedulerViewType.WorkWeek ? 5 : 7));
+        //     
+        //     if (Bookings.ResourceCollection is ObservableCollection<SchedulerResource> resources)
+        //     {
+        //         var colwidth = GetResourceColumnWidth();
+        //         foreach (var emp in _employees)
+        //         {
+        //             var resource = resources.FirstOrDefault(x => String.Equals(x.Id?.ToString(), emp.ID.ToString()));
+        //             if (resource != null)
+        //             {
+        //                 var comps = emp.Name.Split(' ');
+        //                 var display = emp.Name;
+        //                 if (colwidth < 75)
+        //                     display = string.Format("{0}{1}", comps[0].Length > 0 ? comps[0][..1] : "",
+        //                         comps.Length > 1 ? comps.Skip(1).First()[..1].ToUpper() : "");
+        //                 else if (colwidth < 150)
+        //                     display = string.Format("{0} {1}", comps.First(),
+        //                         comps.Length > 1 ? comps.Skip(1).First()[..1].ToUpper() : "");
+        //                 resource.Name = display;
+        //             }
+        //         }
+        //     }
+        // }
 
-        private T CheckGrid<T>(ref T grid) where T : new()
+        private T CheckGrid<T>([NotNull] ref T? grid) where T : new()
         {
             if (grid == null)
                 grid = new T();