12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Globalization;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Threading;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using Org.BouncyCastle.Asn1.X509.Qualified;
- using PRS.Shared;
- using Syncfusion.SfSkinManager;
- using Syncfusion.UI.Xaml.Scheduler;
- using Selection = InABox.Core.Selection;
- using SelectionChangedEventArgs = System.Windows.Controls.SelectionChangedEventArgs;
- namespace PRSDesktop
- {
- public class SfScheduler2 : SfScheduler
- {
- public static readonly DependencyProperty HeaderVisibilityProperty =
- DependencyProperty.Register(
- nameof(HeaderVisibility),
- typeof(Visibility),
- typeof(SfScheduler2),
- new UIPropertyMetadata(Visibility.Collapsed)
- );
- public Visibility HeaderVisibility
- {
- get => (Visibility)GetValue(HeaderVisibilityProperty);
- set
- {
- SetValue(HeaderVisibilityProperty,value);
- SetHeaderVisibility();
- }
- }
- private void SetHeaderVisibility()
- {
- if (GetTemplateChild("PART_ScheduleHeaderControl") is SchedulerHeaderControl cell)
- cell.Visibility = HeaderVisibility;
- }
- public override void OnApplyTemplate()
- {
- base.OnApplyTemplate();
- SetHeaderVisibility();
- }
- }
-
- public partial class Calendar
- {
- private enum Suppress
- {
- Selector, // Prevent the Selector from Being Changed
- Calendar, // Prevent the Calendar from Being Reconfigured
- Events, // Prevent the Selectors from Responding to Events
- Refresh, // Stop the Data from Being refreshed
- Settings // Dont allow settings to be updated
- }
- private EventSuppressor suppressor = null;
- public void DisableUpdate()
- {
- if (suppressor == null)
- suppressor = new EventSuppressor(Suppress.Refresh, Suppress.Settings);
- }
- public void EnableUpdate()
- {
- if (suppressor != null)
- {
- suppressor.Dispose();
- suppressor = null;
- }
- }
-
- private void DoSetValue<T>(DependencyProperty property, T value, Action? updateselector, Action? updateinterface)
- {
- SetValue(property, value);
-
- if (!EventSuppressor.IsSet(Suppress.Selector) && (updateselector != null))
- using (new EventSuppressor(Suppress.Events))
- updateselector();
- if (!EventSuppressor.IsSet(Suppress.Calendar) && (updateinterface != null))
- updateinterface();
- if (!EventSuppressor.IsSet(Suppress.Refresh))
- Refresh();
- if (!EventSuppressor.IsSet(Suppress.Settings))
- {
- Properties.SettingsVisible = SettingsVisible;
- Properties.Date = SelectedDate;
- Properties.StartHour = (int)Bookings.DaysViewSettings.StartHour;
- Properties.EndHour = (int)Bookings.DaysViewSettings.EndHour;
- Properties.CalendarView = CalendarView;
- Properties.EmployeeSelector = EmployeeSettings;
- Properties.EmployeeSelection = EmployeeSelection;
- Properties.TimeInterval = TimeInterval;
- Properties.AssignmentType = AssignmentType;
- Properties.BackgroundType = BackgroundType;
- Properties.Zoom = Zoom;
- SaveSettings?.Invoke(this, Properties);
- }
- }
-
- #region HeaderVisibility Dependency Property
-
- public static readonly DependencyProperty HeaderVisibilityProperty =
- DependencyProperty.Register(
- nameof(HeaderVisibility),
- typeof(Visibility),
- typeof(Calendar),
- new UIPropertyMetadata(Visibility.Collapsed)
- );
-
- public Visibility HeaderVisibility
- {
- get => (Visibility)GetValue(HeaderVisibilityProperty);
- set
- {
- SetValue(HeaderVisibilityProperty,value);
- Bookings.HeaderVisibility = value;
- }
- }
-
- #endregion
-
- #region SettingsVisible Dependency Property
-
- public static readonly DependencyProperty SettingsVisibleProperty =
- DependencyProperty.Register(
- nameof(SettingsVisible),
- typeof(CalendarSettingsVisibility),
- typeof(Calendar),
- new UIPropertyMetadata(CalendarSettingsVisibility.Disabled)
- );
-
- public CalendarSettingsVisibility SettingsVisible
- {
- get => (CalendarSettingsVisibility)GetValue(SettingsVisibleProperty);
- set => SetSettingsVisibility(value);
- }
-
- private void SetSettingsVisibility(CalendarSettingsVisibility value)
- {
- DoSetValue(
- SettingsVisibleProperty,
- value,
- () => { },
- () =>
- {
- _splitPanel.View = value == CalendarSettingsVisibility.Visible
- ? DynamicSplitPanelView.Combined
- : DynamicSplitPanelView.Master;
- _splitPanel.AllowableViews = value == CalendarSettingsVisibility.Disabled
- ? DynamicSplitPanelView.Master
- : DynamicSplitPanelView.Master | DynamicSplitPanelView.Combined;
- ResizeColumns(this.ActualWidth);
- }
- );
- }
-
- #endregion
-
- #region CalendarView Dependency Property
-
- public static readonly DependencyProperty CalendarViewProperty =
- DependencyProperty.Register(
- nameof(CalendarView),
- typeof(CalendarViewType),
- typeof(Calendar),
- new UIPropertyMetadata(CalendarViewType.Day)
- );
-
- public CalendarViewType CalendarView
- {
- get => (CalendarViewType)GetValue(CalendarViewProperty);
- set => SetCalendarView(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);
- }
- );
- }
-
- private void CalendarViewSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- using (new EventSuppressor(Suppress.Selector))
- SetCalendarView((CalendarViewType)CalendarViewSelector.SelectedIndex);
- }
- #endregion
-
- #region EmployeeSelector Dependency Property
-
- public static readonly DependencyProperty EmployeeSelectionProperty =
- DependencyProperty.Register(
- nameof(EmployeeSelection),
- typeof(EmployeeSelectorData),
- typeof(Calendar),
- new UIPropertyMetadata(new EmployeeSelectorData())
- );
-
- public EmployeeSelectorData EmployeeSelection
- {
- get => (EmployeeSelectorData)GetValue(EmployeeSelectionProperty);
- set => SetEmployeeSelection(value);
- }
-
- private void SetEmployeeSelection(EmployeeSelectorData value)
- {
- DoSetValue(
- EmployeeSelectionProperty,
- value,
- () => EmployeeSelector.Selection = value,
- () =>
- {
- _employees = EmployeeSelector.GetEmployeeData((row, rosters) => new EmployeeResourceModel(row, rosters));
- ReloadColumns();
- }
- );
- }
-
- private void EmployeeSelector_OnSelectionChanged(object sender, EmployeeSelectorSelectionChangedArgs args)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- using (new EventSuppressor(Suppress.Selector))
- SetEmployeeSelection(args.Selection);
- }
-
- #endregion
-
- #region EmployeeSettings Dependency Property
-
- public static readonly DependencyProperty EmployeeSettingsProperty =
- DependencyProperty.Register(
- nameof(EmployeeSettings),
- typeof(EmployeeSelectorSettings),
- typeof(Calendar),
- new UIPropertyMetadata(new EmployeeSelectorSettings())
- );
-
- public EmployeeSelectorSettings EmployeeSettings
- {
- get => (EmployeeSelectorSettings)GetValue(EmployeeSettingsProperty);
- set => SetEmployeeSettings(value);
- }
-
- private void SetEmployeeSettings(EmployeeSelectorSettings value)
- {
- DoSetValue(
- EmployeeSettingsProperty,
- value,
- () => EmployeeSelector.Settings = value,
- () =>
- {
- // Nothing to do here
- }
- );
- }
- private void EmployeeSelector_OnSettingsChanged(object sender, EmployeeSelectorSettingsChangedArgs args)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- using (new EventSuppressor(Suppress.Selector))
- SetEmployeeSettings(args.Settings);
- }
- #endregion
-
- #region TimeInterval DependencyProperty
-
- public static readonly DependencyProperty TimeIntervalProperty =
- DependencyProperty.Register(
- "TimeInterval",
- typeof(CalendarTimeInterval),
- typeof(Calendar),
- new PropertyMetadata(CalendarTimeInterval.FifteenMinutes)
- );
- public CalendarTimeInterval TimeInterval
- {
- get => (CalendarTimeInterval)GetValue(TimeIntervalProperty);
- set => SetTimeInterval(value);
- }
- private void SetTimeInterval(CalendarTimeInterval value)
- {
- DoSetValue(
- TimeIntervalProperty,
- value,
- () => IntervalSelector.SelectedIndex = (int)value,
- () =>
- {
- Bookings.DaysViewSettings.TimeInterval = TimeIntervalToTimeSpan(value);
- UpdateZoom();
- });
- }
-
- private void IntervalSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- using (new EventSuppressor(Suppress.Selector))
- SetTimeInterval((CalendarTimeInterval)IntervalSelector.SelectedIndex);
- }
- public TimeSpan TimeIntervalToTimeSpan(CalendarTimeInterval interval)
- {
- return interval switch
- {
- CalendarTimeInterval.FiveMinutes => new TimeSpan(0, 5, 0),
- CalendarTimeInterval.SixMinutes => new TimeSpan(0, 6, 0),
- CalendarTimeInterval.TenMinutes => new TimeSpan(0, 10, 0),
- CalendarTimeInterval.FifteenMinutes => new TimeSpan(0, 15, 0),
- CalendarTimeInterval.TwentyMinutes => new TimeSpan(0, 20, 0),
- CalendarTimeInterval.ThirtyMinutes => new TimeSpan(0, 30, 0),
- _ => new TimeSpan(1, 0, 0)
- };
- }
-
- public int BlocksPerHour(CalendarTimeInterval interval)
- {
- return interval switch
- {
- CalendarTimeInterval.FiveMinutes => 12,
- CalendarTimeInterval.SixMinutes => 10,
- CalendarTimeInterval.TenMinutes => 6,
- CalendarTimeInterval.FifteenMinutes => 4,
- CalendarTimeInterval.TwentyMinutes => 3,
- CalendarTimeInterval.ThirtyMinutes => 2,
- _ => 1
- };
- }
- private TimeSpan AdjustStartTime(TimeSpan time)
- {
- long blocksize = TimeIntervalToTimeSpan(TimeInterval).Ticks;
- //long blocksperday = TimeSpan.FromDays(1).Ticks / ;
- long blocknumber = time.Ticks / blocksize;
- long blockstart = blocknumber * blocksize;
- return TimeSpan.FromTicks(blockstart);
- }
-
- #endregion
-
- #region SelectedDate Dependency Property
-
- public static readonly DependencyProperty SelectedDateProperty =
- DependencyProperty.Register(
- nameof(SelectedDate),
- typeof(DateTime),
- typeof(Calendar),
- new UIPropertyMetadata(DateTime.Today)
- );
- public DateTime SelectedDate
- {
- get => (DateTime)GetValue(SelectedDateProperty);
- set => SetSelectedDate(value);
- }
- private void SetSelectedDate(DateTime value)
- {
- DoSetValue(
- SelectedDateProperty,
- value,
- () => { /* DateSelector.Date = value; */ },
- () => {
- Bookings.DisplayDate = value;
- Bookings.SelectedDate = value;
- });
- }
- // private void DateSelector_DateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- // {
- // if (EventSuppressor.IsSet(Suppress.Events))
- // return;
- // using (new EventSuppressor(Suppress.Selector))
- // SetSelectedDate(DateSelector.Date);
- // }
- public DateTime StartDate => (Properties?.CalendarView ?? CalendarViewType.Day) == CalendarViewType.Day
- ? SelectedDate
- : SelectedDate.StartOfWeek(DayOfWeek.Monday);
- public DateTime EndDate => Properties.CalendarView == CalendarViewType.Day
- ? StartDate.AddDays(1)
- : Properties.CalendarView == CalendarViewType.WorkWeek
- ? StartDate.AddDays(5)
- : StartDate.AddDays(7);
-
- #endregion
-
- #region StartHour Dependency Properties
-
- public static readonly DependencyProperty StartHourProperty =
- DependencyProperty.Register(
- nameof(StartHour),
- typeof(int),
- typeof(Calendar),
- new UIPropertyMetadata(6)
- );
-
- public int StartHour
- {
- get => (int)GetValue(StartHourProperty);
- set => SetStartHour(value);
- }
-
- private void SetStartHour(int value)
- {
- value = Math.Min(EndHour-1,Math.Max(0, value));
- DoSetValue(
- StartHourProperty,
- value,
- () => StartTimeSelector.Text = FormatHour(value),
- () =>
- {
- Bookings.DaysViewSettings.StartHour = value;
- UpdateZoom();
- });
- }
-
- private void StartTimeSelector_Down_Click(object sender, RoutedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- SetStartHour(StartHour - 1);
- }
- private void StartTimeSelector_Up_Click(object sender, RoutedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- SetStartHour(StartHour + 1);
- }
-
- #endregion
-
- #region End Hour Property
-
- public static readonly DependencyProperty EndHourProperty =
- DependencyProperty.Register(
- nameof(EndHour),
- typeof(int),
- typeof(Calendar),
- new UIPropertyMetadata(18)
- );
- public int EndHour
- {
- get => (int)GetValue(EndHourProperty);
- set => SetEndHour(value);
- }
- private void SetEndHour(int value)
- {
- value = Math.Max(StartHour + 1, Math.Min(24, value));
- DoSetValue(
- EndHourProperty,
- value,
- () => FinishTimeSelector.Text = FormatHour(value),
- () =>
- {
- Bookings.DaysViewSettings.EndHour = value;
- UpdateZoom();
- });
- }
-
- private void FinishTimeSelector_Down_Click(object sender, RoutedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- SetEndHour(EndHour - 1);
- }
- private void FinishTimeSelector_Up_Click(object sender, RoutedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- SetEndHour(EndHour + 1);
- }
-
- private string FormatHour(int hour)
- {
- return hour <= 0 || hour >= 24
- ? "Midnight"
- : hour < 12
- ? string.Format("{0}:00 AM", hour)
- : hour > 12
- ? string.Format("{0}:00 PM", hour)
- : "12:00 NN";
- }
-
- #endregion
-
- #region AssignmentType Dependency Property
-
- public static readonly DependencyProperty AssignmentTypeProperty =
- DependencyProperty.Register(
- nameof(AssignmentType),
- typeof(CalendarAssignmentType),
- typeof(Calendar),
- new UIPropertyMetadata(CalendarAssignmentType.Booked)
- );
-
- public CalendarAssignmentType AssignmentType
- {
- get => (CalendarAssignmentType)GetValue(AssignmentTypeProperty);
- set => SetAssignmentType(value);
- }
- private void SetAssignmentType(CalendarAssignmentType value)
- {
- DoSetValue(
- AssignmentTypeProperty,
- value,
- () => AssignmentTypeSelector.SelectedIndex = (int)value,
- null
- );
- }
- private void AssignmentTypeSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- using (new EventSuppressor(Suppress.Selector))
- SetAssignmentType((CalendarAssignmentType)AssignmentTypeSelector.SelectedIndex);
- }
-
- #endregion
-
- #region BackgroundType Dependency Property
-
- public static readonly DependencyProperty BackgroundTypeProperty =
- DependencyProperty.Register(
- nameof(BackgroundType),
- typeof(CalendarBackgroundType),
- typeof(Calendar),
- new UIPropertyMetadata(CalendarBackgroundType.Roster)
- );
-
- public CalendarBackgroundType BackgroundType
- {
- get => (CalendarBackgroundType)GetValue(BackgroundTypeProperty);
- set => SetBackgroundType(value);
- }
-
- private void SetBackgroundType(CalendarBackgroundType type)
- {
- DoSetValue(
- BackgroundTypeProperty,
- type,
- () => BackgroundTypeSelector.SelectedIndex = (int)type,
- null
- );
- }
- private void BackgroundTypeSelector_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- using (new EventSuppressor(Suppress.Selector))
- SetBackgroundType((CalendarBackgroundType)BackgroundTypeSelector.SelectedIndex);
- }
- #endregion
-
- #region Zoom Dependency Properties
-
- public static readonly DependencyProperty ZoomProperty =
- DependencyProperty.Register(
- nameof(Zoom),
- typeof(double),
- typeof(Calendar),
- new UIPropertyMetadata((double)100F)
- );
-
- public double Zoom
- {
- get => (double)GetValue(ZoomProperty);
- set => SetZoom(value);
- }
-
- private void SetZoom(double value)
- {
- DoSetValue(
- ZoomProperty,
- value,
- () => ZoomSelector.Text = $"{value:F0}%",
- () => UpdateZoom()
- );
- }
- private void UpdateZoom()
- {
- if (double.IsNaN(this.ActualHeight) || (this.ActualHeight == 0.0F))
- return;
- var blocksize = (this.ActualHeight - (Bookings.DaysViewSettings.ViewHeaderHeight + Bookings.DaysViewSettings.ResourceHeaderSize + 2.0F)) / ((EndHour - StartHour) * this.BlocksPerHour(TimeInterval));
- Bookings.DaysViewSettings.TimeIntervalSize = (double)Zoom * blocksize / 100.0F;
- }
- private void ZoomSelector_Down_Click(object sender, RoutedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- ZoomOut();
- }
-
- private void ZoomSelector_Up_Click(object sender, RoutedEventArgs e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- ZoomIn();
- }
- public void ZoomIn() => SetZoom(Zoom * 1.125F);
- public void ZoomOut() => SetZoom(Zoom / 1.125F);
- public void ResetZoom() => SetZoom(100.0F);
-
- #endregion
-
- #region Event Handlers
-
- public event LoadSettings<CalendarSettings> LoadSettings;
-
- public event SaveSettings<CalendarSettings> SaveSettings;
- public CalendarConfigurationEvent ConfigurationChanged;
-
- public event CalendarDataEvent CustomiseContextMenu;
-
- public event CalendarDataEvent SelectionChanged;
- public event CalendarDataEvent ItemCreated;
-
- public event CalendarDataEvent ItemChanged;
- public event CalendarHandledEvent ItemEditing;
-
- #endregion
- public void SelectEmployee(Guid employeeid) => EmployeeSelector.SelectEmployee(employeeid);
- // Populated as requiew when EmployeeSelector.SelectionChanged is triggered
- private EmployeeResourceModel[] _employees = new EmployeeResourceModel[] { };
-
- // Populated once at startup
- private StandardLeaveModel[] _standardleaves = new StandardLeaveModel[] { };
- private LeaveRequestModel[] _leaverequests = new LeaveRequestModel[] { };
- // Populated on each Refresh
- private TimeSheetModel[] _timesheets = new TimeSheetModel[] { };
-
- // Populated on each Refresh
- private List<AssignmentModel> _assignments = new List<AssignmentModel>();
-
- private bool bColumnsLoaded;
-
- private AssignmentGrid ag;
- private DynamicDataGrid<Meeting> mg;
-
- public bool IsReady { get; set; }
-
- public CalendarSettings Properties { get; set; }
- //public SfScheduler2? Bookings => this.FindName("_bookings") as SfScheduler2;
-
- public Calendar()
- {
- using (EventSuppressor.All<Suppress>())
- {
- InitializeComponent();
- SetValue(StartHourProperty, 0);
- SetValue(EndHourProperty, 24);
- SfSkinManager.SetTheme(Bookings, new Theme() { ThemeName = "Office2019White", ScrollBarMode = ScrollBarMode.Compact });
- }
- }
-
- public virtual void Setup()
- {
- using (new EventSuppressor(Suppress.Settings, Suppress.Refresh, Suppress.Events))
- {
-
- Properties = LoadSettings?.Invoke(this) ?? new CalendarSettings();
- SetCalendarView(Properties.CalendarView);
- SetSettingsVisibility(Properties.SettingsVisible);
- SetSelectedDate(Properties.Date);
- SetStartHour(Properties.StartHour);
- SetEndHour(Properties.EndHour);
- SetTimeInterval(Properties.TimeInterval);
- SetAssignmentType(Properties.AssignmentType);
- SetBackgroundType(Properties.BackgroundType);
- SetCalendarView(Properties.CalendarView);
- SetZoom(Properties.Zoom);
- EmployeeSelector.Setup();
- SetEmployeeSettings(Properties.EmployeeSelector);
- SetEmployeeSelection(Properties.EmployeeSelection);
-
- _employees = EmployeeSelector.GetEmployeeData((row, rosters) => new EmployeeResourceModel(row, rosters));
-
- MultiQuery query = new MultiQuery();
-
- query.Add(
- new Filter<LeaveRequest>(x=>x.Status).IsNotEqualTo(LeaveRequestStatus.Rejected),
- LeaveRequestModel.Columns
- );
-
- query.Add(
- null,
- StandardLeaveModel.Columns
- );
- query.Query();
- _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;
-
- }
- }
-
- public virtual void Shutdown(CancelEventArgs? cancel)
- {
- }
-
- private bool bFirst = true;
-
- public virtual void Refresh()
- {
- RefreshData(StartDate, EndDate);
- }
- private void RefreshData(DateTime startDate, DateTime endDate)
- {
- if (EventSuppressor.IsSet(Suppress.Refresh))
- return;
- using (new WaitCursor())
- {
- if (!bColumnsLoaded)
- ReloadColumns();
- MultiQuery query = new MultiQuery();
- var empids = _employees.Select(x => x.ID).ToArray();
-
- if (BackgroundType != CalendarBackgroundType.Roster)
- {
- query.Add<TimeSheet>(
- new Filter<TimeSheet>(x => x.EmployeeLink.ID).InList(empids)
- .And(x => x.Date).IsGreaterThanOrEqualTo(startDate)
- .And(x => x.Date).IsLessThanOrEqualTo(endDate)
- .And(x=>x.LeaveRequestLink.ID).IsEqualTo(Guid.Empty)
- .And(x=>x.StandardLeaveLink.ID).IsEqualTo(Guid.Empty),
- TimeSheetModel.Columns
- );
- }
-
- query.Add<Assignment>(
- new Filter<Assignment>(x => x.EmployeeLink.ID).InList(empids)
- .And(x => x.Date).IsGreaterThanOrEqualTo(startDate)
- .And(x => x.Date).IsLessThanOrEqualTo(endDate),
- AssignmentModel.Columns,
- new SortOrder<Assignment>(x => x.EmployeeLink.ID).ThenBy(x => x.Date).ThenBy(x => x.Booked.Duration, SortDirection.Descending)
- );
-
- query.Query();
-
- _timesheets = (BackgroundType == CalendarBackgroundType.Roster)
- ? new TimeSheetModel[] { }
- : query.Get<TimeSheet>().Rows.Select(r => new TimeSheetModel(r)).ToArray();
-
- _assignments = query.Get<Assignment>().Rows.Select(r => new AssignmentModel(r)).ToList();
-
- LoadBackground();
- var appointments = new CalendarAppointments();
- LoadStandardLeaves(appointments);
- LoadLeaveRequests(appointments);
- LoadAssignments(appointments);
-
- try
- {
- Bookings.DisplayDate = Bookings.SelectedDate.HasValue ? Bookings.SelectedDate.Value : StartDate;
- Bookings.ItemsSource = appointments;
- }
- catch (Exception e)
- {
- Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
- }
- bFirst = false;
- }
- }
- public EmployeeRosterItem GetRoster(Guid employeeid, DateTime date)
- {
- var employee = _employees.FirstOrDefault(x => x.ID == employeeid);
- var roster = RosterUtils.GetRoster(employee?.Roster, employee?.RosterStart, date);
- return roster;
- }
- public bool GetActiveWindow(Guid employeeid, DateTime date, ref TimeSpan start, ref TimeSpan finish)
- {
- bool result = false;
-
- foreach (var assignment in _assignments.Where(a => (a.EmployeeID == employeeid) && (a.Date) == date))
- {
- result = true;
- var curstart = AssignmentType switch
- {
- CalendarAssignmentType.Booked => assignment.BookedStart,
- CalendarAssignmentType.Actual => assignment.ActualStart,
- _ => Assignment.EffectiveTime(assignment.ActualStart, assignment.BookedStart)
- };
-
- var curfinish = AssignmentType switch
- {
- CalendarAssignmentType.Booked => assignment.BookedFinish,
- CalendarAssignmentType.Actual => assignment.ActualFinish,
- _ => Assignment.EffectiveTime(
- assignment.ActualFinish,
- Assignment.EffectiveTime(assignment.ActualStart, assignment.BookedStart)
- .Add(assignment.BookedDuration)
- )
- };
-
- start = start > curstart ? curstart : start;
- finish = finish < curfinish ? curfinish : finish;
- }
- if ((BackgroundType == CalendarBackgroundType.Roster) ||
- ((BackgroundType == CalendarBackgroundType.Automatic) && (date >= DateTime.Today)))
- {
- var employee = _employees.FirstOrDefault(x => x.ID == employeeid);
- if (employee != null)
- {
- var roster = RosterUtils.GetRoster(employee.Roster, employee.RosterStart, date);
- if (roster != null)
- {
- var blocks = roster.GetBlocks(date, TimeSpan.MinValue, TimeSpan.MaxValue);
- foreach (var block in blocks)
- {
- start = start > block.Start ? block.Start : start;
- finish = finish < block.Finish ? block.Finish : finish;
- }
- }
- }
- }
- else
- {
- foreach (var timesheet in _timesheets.Where(t => (t.EmployeeID == employeeid) && (t.Date == date)))
- {
- result = true;
- var curstart = !timesheet.Approved.IsEmpty()
- ? timesheet.ApprovedStart
- : timesheet.Start;
- var curfinish = !timesheet.Approved.IsEmpty()
- ? timesheet.ApprovedFinish
- : timesheet.Finish;
- start = start > curstart ? curstart : start;
- finish = finish < curfinish ? curfinish : finish;
- }
- }
-
- return result;
- }
- public CoreRow[] GetAssignments(Guid employeeid, DateTime date)
- {
- return _assignments.Where(a => (a.Row != null) && (a.EmployeeID == employeeid) && (a.Date == date)).Select(x => x.Row!).ToArray();
- }
-
- public void UpdateAssignment(Assignment assignment)
- {
-
- void UpdateCalendar<TEntity, TModel>(
- TEntity entity,
- List<TModel> collection,
- Action<TModel> refresh
- ) where TEntity : Entity where TModel : class, IModel
- {
-
- if (Bookings.ItemsSource is CalendarAppointments appointments)
- {
- var appointment = appointments.FirstOrDefault(x => (Guid)x.Id == entity.ID) as ScheduleAppointment;
- if (appointment != null)
- {
- appointments.Remove(appointment);
- var calappt = appointment as ICalendarAppointment<TModel>;
- if (calappt != null)
- collection.Remove(calappt.Model);
- }
- var table = new CoreTable();
- table.LoadColumns(typeof(TEntity));
- var row = table.NewRow();
- table.LoadRow(row, entity);
- var model = (Activator.CreateInstance(typeof(TModel),row) as TModel)!;
- collection.Add(model);
- refresh(model);
- }
- }
-
- if (Bookings.ItemsSource is CalendarAppointments appointments)
- UpdateCalendar(assignment, _assignments, (model) => LoadAssignment(model,appointments));
-
- }
-
- private void LoadBackground()
- {
- var regions = new ObservableCollection<SpecialTimeRegion>();
- foreach (var resource in Bookings.ResourceCollection)
- {
- var sEmpID = (((SchedulerResource)resource).Id as string) ?? "";
- var empid = Guid.Parse(sEmpID);
- var employee = _employees.FirstOrDefault(x => x.ID == empid);
- for (var date = StartDate; date < EndDate; date = date.AddDays(1))
- {
- if ((BackgroundType == CalendarBackgroundType.Roster) ||
- ((BackgroundType == CalendarBackgroundType.Automatic) && (date >= DateTime.Today)))
- {
- var roster = RosterUtils.GetRoster(employee?.Roster, employee?.RosterStart, date);
- if (roster != null)
- {
- var blocks = roster.GetBlocks(date, TimeSpan.FromSeconds(0), TimeSpan.FromDays(1));
- foreach (var block in blocks)
- {
- regions.Add(
- new SpecialTimeRegion
- {
- StartTime = date.Add(block.Start),
- EndTime = date.Add(block.Finish.Subtract(TimeSpan.FromSeconds(1))),
- ResourceIdCollection = new ObservableCollection<object> { ((SchedulerResource)resource).Id },
- Background = new SolidColorBrush(Colors.Yellow) {Opacity = 0.3},
- Foreground = new SolidColorBrush(Colors.Black),
- Text = ""
- }
- );
- }
- }
-
- }
- else
- {
- foreach (var timesheet in _timesheets.Where(t => (t.EmployeeID == empid) && (t.Date == date)))
- {
-
- var start = !timesheet.Approved.IsEmpty()
- ? timesheet.ApprovedStart
- : timesheet.Start;
- var finish = !timesheet.Approved.IsEmpty()
- ? timesheet.ApprovedFinish
- : timesheet.Finish;
- regions.Add(
- new SpecialTimeRegion
- {
- StartTime = date.Add(start),
- EndTime = date.Add(finish),
- ResourceIdCollection = new ObservableCollection<object> { ((SchedulerResource)resource).Id },
- Background = new SolidColorBrush(!timesheet.Approved.IsEmpty() ? Colors.LightGreen : Colors.LightSalmon) { Opacity = 0.4 },
- Foreground = new SolidColorBrush(Colors.Transparent),
- Text = "",
- CanMergeAdjacentRegions = false
- }
- );
- }
-
- }
- }
- }
- Bookings.DaysViewSettings.SpecialTimeRegions = regions;
- }
-
- private void LoadStandardLeaves(CalendarAppointments appointments)
- {
- for (var date = StartDate; date < EndDate; date = date.AddDays(1))
- {
- var leaves = _standardleaves.Where(x =>
- (x.From <= date)
- && (x.To.Add(x.ToTime) > date)
- ).ToArray();
- foreach (var leave in leaves)
- {
-
- foreach (var resource in Bookings.ResourceCollection)
- {
- var sEmpID = ((SchedulerResource)resource).Id as string;
- var empid = Guid.Parse(sEmpID);
- var employee = _employees.FirstOrDefault(x => x.ID == empid);
- var start = (date.Date == leave.From.Date) ? leave.FromTime : TimeSpan.FromSeconds(0);
- var finish = (date.Date == leave.To.Date) ? leave.ToTime : TimeSpan.FromDays(1).Subtract(TimeSpan.FromSeconds(1));
- var roster = RosterUtils.GetRoster(employee?.Roster, employee?.RosterStart, date);
- if (roster != null)
- {
- var blocks = roster.GetBlocks(date, start, finish);
- foreach (var block in blocks)
- {
- var appt = new StandardLeaveAppointment(leave, _ => empid, x => x.Color, block);
- appointments.Add(appt);
- }
- }
- }
- }
- }
- }
- private void LoadLeaveRequests(CalendarAppointments appointments)
- {
- for (var date = StartDate; date < EndDate; date = date.AddDays(1))
- {
- var ids = Bookings.ResourceCollection
- .Cast<SchedulerResource>()
- .Where(x=>!String.IsNullOrWhiteSpace(x.Id as String))
- .Select(x => Guid.Parse(x.Id.ToString() ?? ""));
- var leaves = _leaverequests.Where(x =>
- (x.From <= date)
- && (x.To.Add(x.ToTime) > date)
- && ids.Contains(x.EmployeeID)
- ).ToArray();
- foreach (var leave in leaves)
- {
- var employee = _employees.FirstOrDefault(x => x.ID == leave.EmployeeID);
-
- var roster = RosterUtils.GetRoster(employee?.Roster, employee?.RosterStart, date);
- if (roster != null)
- {
- var start = (date.Date == leave.From.Date) ? leave.FromTime : TimeSpan.FromSeconds(0);
- var finish = (date.Date == leave.To.Date) ? leave.ToTime : TimeSpan.FromDays(1).Subtract(TimeSpan.FromSeconds(1));
- var blocks = roster.GetBlocks(date, start, finish);
- foreach (var block in blocks)
- {
- var appt = new LeaveRequestAppointment(leave, x=>x.EmployeeID, x => x.Color, block);
- appointments.Add(appt);
- }
- }
- }
- }
- }
-
- private void LoadAssignment(AssignmentModel assignment, CalendarAppointments appointments)
- {
- var model = new AssignmentAppointment(assignment, x => x.EmployeeID, x => x.Color, AssignmentType);
- appointments.Add(model);
- }
- private void LoadAssignments(CalendarAppointments appointments)
- {
- foreach (var assignment in _assignments)
- LoadAssignment(assignment, appointments);
- }
-
- public DataModel DataModel(Selection selection)
- {
- var ids = _assignments.Select(x => x.ID).ToArray();
- return new AutoDataModel<Assignment>(new Filter<Assignment>(x => x.ID).InList(ids));
- }
- // private void ResizeIntervals(double height)
- // {
- // if (Bookings.FindVisualChildren<ScrollPanel>().Any())
- // {
- //
- // if (height > 95 && Bookings.DaysViewSettings.EndHour - Bookings.DaysViewSettings.StartHour > 0)
- // {
- // double scrollheight = _employees.Length * 75 > Bookings.ActualWidth ? 15.0F : 0.0F;
- // var header = _employees.Length > 1 ? 93.0F + scrollheight : 50.0F;
- // Bookings.DaysViewSettings.TimeIntervalSize =
- // (height - header) / ((Bookings.DaysViewSettings.EndHour - Bookings.DaysViewSettings.StartHour) * 2.0F);
- // }
- // }
- //
- // // var scrollers = Bookings.FindVisualChildren<ScrollViewer>().Where(x => string.Equals(x.Name, "PART_TimeSlotScrollViewer")).ToArray();
- // // foreach (var scroll in scrollers)
- // // scroll.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
- //
- // }
- private void Schedule_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- //ResizeIntervals(e.NewSize.Height);
- ResizeColumns(e.NewSize.Width);
- }
- 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;
- }
- }
- }
- }
- private T CheckGrid<T>(ref T grid) where T : new()
- {
- if (grid == null)
- grid = new T();
- return grid;
- }
- private void ReloadColumns()
- {
-
- ResizeColumns(Bookings.ActualWidth);
- var colwidth = GetResourceColumnWidth();
- var resources = new List<SchedulerResource>();
- foreach (var emp in _employees)
- {
- var comps = emp.Name.Split(' ');
- var display = emp.Name;
- if (colwidth < 75)
- display = CoreUtils.Codify(emp.Name);
- else if (colwidth < 150)
- display = string.Format("{0} {1}", comps.Length > 0 ? comps.First() : "", comps.Length > 1 ? comps.Skip(1).First().Substring(0, 1).ToUpper() : "");
- resources.Add(new SchedulerResource { Name = display, Id = emp.ID.ToString() });
- }
- var sorted = new ObservableCollection<SchedulerResource>();
- foreach (var resource in resources.OrderBy(x => x.Name))
- sorted.Add(resource);
- try
- {
- Bookings.DaysViewSettings.ResourceHeaderSize = sorted.Count <= 1 ? 0 : 45;
- }
- catch (Exception e)
- {
- Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
- }
- //ResizeIntervals(Bookings.ActualHeight);
- try
- {
- Bookings.ResourceCollection = sorted;
- }
- catch (Exception e)
- {
- Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
- }
- bColumnsLoaded = true;
- }
- // private SchedulerResource GetCurrentResource()
- // {
- // var p = Mouse.GetPosition(Bookings);
- // var panels = Bookings.FindVisualChildren<ScrollViewer>().FirstOrDefault(x => string.Equals(x.Name, "PART_ViewHeaderScrollViewer"));
- // var resource = (int)((p.X + panels.HorizontalOffset - (Bookings.DaysViewSettings.TimeRulerSize + 20F)) / GetResourceColumnWidth());
- // return (Bookings.ResourceCollection as Collection<SchedulerResource>)[resource];
- // }
- //
- // private DateTime GetCurrentTime()
- // {
- // var p = Mouse.GetPosition(Bookings);
- // var hours = (p.Y - (_employees.Length > 1 ? 95.0F : 50.0F)) / (Bookings.DaysViewSettings.TimeIntervalSize * 2F) +
- // Bookings.DaysViewSettings.StartHour;
- // var result = Bookings.SelectedDate.Value + TimeSpan.FromHours(hours);
- // return result;
- // }
- private double GetResourceColumnWidth()
- {
- var colcount = Math.Max(1, _employees.Length);
- colcount = colcount * (Bookings.ViewType == SchedulerViewType.Day ? 1 : Bookings.ViewType == SchedulerViewType.Day ? 5 : 7);
- var colwidth = Bookings.ActualWidth / colcount;
- var minwidth = (Bookings.ActualWidth - (Bookings.DaysViewSettings.TimeRulerSize + 20F)) / Bookings.DaysViewSettings.VisibleResourceCount;
- return Math.Max(minwidth, colwidth);
- }
-
- private void Schedule_AppointmentEditorOpening(object sender, AppointmentEditorOpeningEventArgs e)
- {
- e.Cancel = true;
- }
-
-
- private Dictionary<CalendarMenuName, MenuItem> _menuitems = new Dictionary<CalendarMenuName, MenuItem>();
- public MenuItem? FindMenu(CalendarMenuName name)
- {
- _menuitems.TryGetValue(name, out MenuItem result);
- return result;
- }
-
- MenuItem CreateMenu<T>(ItemsControl menu, CalendarMenuName name, string header, Action<T?>? action = null, T? data = null) where T : class
- {
- var item = new MenuItem();
- item.Name = name.ToString();
- item.Header = header;
- if (action != null)
- item.Click += (o,args) => action(data);
- item.IsEnabled = data != null;
- menu.Items.Add(item);
- _menuitems[name] = item;
- return item;
- }
-
- private void Bookings_OnSchedulerContextMenuOpening(object? sender, SchedulerContextMenuOpeningEventArgs e)
- {
-
- e.ContextMenu.Items.Clear();
- if ((e.MenuType == SchedulerContextMenuType.Appointment) && (e.MenuInfo.Appointment is AssignmentAppointment appointment))
- {
-
- if (appointment.Model.MeetingID != Guid.Empty)
- CreateMenu(e.ContextMenu, CalendarMenuName.Edit, "Edit Meeting", EditMeeting, appointment.Model);
- else
- {
- CreateMenu(e.ContextMenu, CalendarMenuName.Edit, "Edit Assignment", EditAssignment, appointment.Model);
- e.ContextMenu.Items.Add(new Separator());
- CreateMenu(e.ContextMenu, CalendarMenuName.Copy, "Copy Assignment", CopyAssignment, appointment.Model);
- e.ContextMenu.Items.Add(new Separator());
- CreateMenu(e.ContextMenu, CalendarMenuName.Fill, "Fill Available Time", FillAssignment, appointment.Model);
- }
- e.ContextMenu.Items.Add(new Separator());
-
- CreateDigitalFormsMenu(e.ContextMenu, appointment);
- if (appointment.Model.MeetingID != Guid.Empty)
- CreateMenu(e.ContextMenu, CalendarMenuName.Edit, "Delete Meeting", DeleteMeeting, appointment.Model);
- else
- CreateMenu(e.ContextMenu, CalendarMenuName.Delete, "Delete Assignment", DeleteAssignment, appointment.Model);
-
- e.ContextMenu.Items.Add(new Separator());
-
- CreateMenu<object>(e.ContextMenu, CalendarMenuName.ZoomIn, "Zoom In", (data) => ZoomIn(), null);
- CreateMenu<object>(e.ContextMenu, CalendarMenuName.ZoomOut, "Zoom Out", (data) => ZoomOut(), null);
- CreateMenu<object>(e.ContextMenu, CalendarMenuName.ResetZoom, "Reset Zoom", (data) => ResetZoom(), null);
-
- CustomiseContextMenu?.Invoke(e.ContextMenu, new CalendarDataEventArgs<object>((e.MenuInfo.Appointment as ICalendarAppointment)?.Model));
-
- }
- else if (e.MenuType == SchedulerContextMenuType.TimeSlotCell)
- {
- if (Guid.TryParse(e.MenuInfo.Resource.Id?.ToString(), out Guid employeeid))
- {
- var slot = new CalendarTimeSlot(employeeid, e.MenuInfo.DateTime.Value);
-
- var createmenu = new MenuItem() { Header = "Create.." };
- CreateMenu(createmenu, CalendarMenuName.CreateNew, "New Assignment", (data) => CreateAssignment(slot), slot);
- CreateMenu(createmenu, CalendarMenuName.CreateNew, "New Meeting", (data) => CreateMeeting(slot), slot);
- e.ContextMenu.Items.Add(createmenu);
- if (_copiedmodel != null)
- {
- e.ContextMenu.Items.Add(new Separator());
- CreateMenu(e.ContextMenu, CalendarMenuName.Paste, "Paste Assignment", (data) => PasteAssignment(slot), slot);
- }
- e.ContextMenu.Items.Add(new Separator());
- CreateMenu<object>(e.ContextMenu, CalendarMenuName.ZoomIn, "Zoom In", (data) => ZoomIn(), slot);
- CreateMenu<object>(e.ContextMenu, CalendarMenuName.ZoomOut, "Zoom Out", (data) => ZoomOut(), slot);
- CreateMenu<object>(e.ContextMenu, CalendarMenuName.ResetZoom, "Reset Zoom", (data) => ResetZoom(), slot);
- CustomiseContextMenu?.Invoke(e.ContextMenu, new CalendarDataEventArgs<CalendarTimeSlot>(slot));
- }
- }
-
- }
-
- private static void CreateDigitalFormsMenu(ContextMenu menu, AssignmentAppointment appointment)
- {
- var digitalForms = new MenuItem { Header = "Digital Forms" };
- DynamicGridUtils.PopulateFormMenu<AssignmentForm, Assignment, AssignmentLink>(
- digitalForms,
- appointment.Model.ID,
- () => new Client<Assignment>().Load(new Filter<Assignment>(x => x.ID).IsEqualTo(appointment.Model.ID)).First(),
- false);
- menu.Items.Add(digitalForms);
- menu.Items.Add(new Separator());
- }
-
- public void CreateMeeting(CalendarTimeSlot slot)
- {
- if (slot == null)
- {
- MessageBox.Show("Please select an employee first!");
- return;
- }
- var meeting = new Meeting();
- meeting.Date = slot.Time.Date;
- meeting.Time.Start = AdjustStartTime(slot.Time.TimeOfDay);
- meeting.Time.Duration = TimeIntervalToTimeSpan(TimeInterval);
- meeting.Time.Finish = meeting.Time.Start + meeting.Time.Duration;
-
- ItemCreated?.Invoke(this, new CalendarDataEventArgs<Meeting>(meeting));
-
- var args = new CalendarHandledEventArgs<Meeting>(meeting);
- ItemEditing?.Invoke(this, args);
-
- if (args.Status == CalendarHandledStatus.Cancel)
- return;
- if (args.Status == CalendarHandledStatus.Handled)
- {
- Refresh();
- return;
- }
- CheckGrid(ref mg);
- var items = new[] { meeting };
- bool bOK = mg.EditItems(
- items,
- (type) =>
- {
- if (type == typeof(Assignment))
- return LoadMeetingEmployees(meeting, slot.EmployeeID);
- else if (type == typeof(MeetingItem))
- return LoadMeetingItems();
- return null;
- },
- true
- );
- if (bOK)
- Refresh();
- }
- private CoreTable LoadMeetingEmployees(Meeting meeting, Guid employeeid)
- {
- var result = new CoreTable();
- result.LoadColumns(typeof(Assignment));
- var assignment = new Assignment();
- assignment.EmployeeLink.ID = employeeid;
- var emp = new Client<Employee>().Load(new Filter<Employee>(x => x.ID).IsEqualTo(employeeid)).FirstOrDefault();
- if (emp != null)
- assignment.EmployeeLink.Synchronise(emp);
- result.LoadRows(new[] { assignment });
- return result;
- }
- private CoreTable LoadMeetingItems()
- {
- var result = new CoreTable();
- result.LoadColumns(typeof(MeetingItem));
- return result;
- }
- private void EditMeeting(AssignmentModel model)
- {
- if (model == null)
- {
- MessageBox.Show("Please select an entry first!");
- return;
- }
- CheckGrid(ref mg);
-
- var meeting = new Client<Meeting>().Query(
- new Filter<Meeting>(x => x.ID).IsEqualTo(model.MeetingID),
- mg.LoadEditorColumns()
- ).Rows.FirstOrDefault()?.ToObject<Meeting>();
- if ((meeting != null) && (mg.EditItems(new[] { meeting })))
- {
- ItemChanged?.Invoke(this, new CalendarDataEventArgs<Meeting>(meeting));
- Refresh();
- }
- }
-
- private void DeleteMeeting(AssignmentModel model)
- {
- if (model == null)
- {
- MessageBox.Show("Please select an entry first!");
- return;
- }
- if (MessageBox.Show("Are you sure you wish to delete this meeting?", "Confirm Delete", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
- return;
-
- var meeting = new Meeting { ID = model.MeetingID };
- new Client<Meeting>().Delete(meeting, "Meeting Deleted from Scheduler");
- ItemChanged?.Invoke(this, new CalendarDataEventArgs<Meeting>(meeting));
- Refresh();
- SelectionChanged?.Invoke(this, new CalendarDataEventArgs<Meeting>(null));
- }
-
- public Assignment CreateAssignment(CalendarTimeSlot slot)
- {
- if (slot == null)
- {
- MessageBox.Show("Please select an employee first!");
- return null;
- }
- var ass = new Assignment();
- ass.Date = slot.Time.Date;
- ass.Booked.Start = AdjustStartTime(slot.Time.TimeOfDay);
- ass.Booked.Duration = TimeIntervalToTimeSpan(TimeInterval);
- ass.Booked.Finish = ass.Booked.Start + ass.Booked.Duration;
- if ((AssignmentType == CalendarAssignmentType.Actual) || ((AssignmentType == CalendarAssignmentType.Automatic) && (ass.Date <= DateTime.Today)))
- {
- ass.Actual.Start = ass.Booked.Start;
- ass.Actual.Duration = ass.Booked.Duration;
- ass.Actual.Finish = ass.Actual.Start + ass.Actual.Duration;
- }
-
- ass.EmployeeLink.ID = slot.EmployeeID;
- ItemCreated?.Invoke(this, new CalendarDataEventArgs<Assignment>(ass));
-
- var args = new CalendarHandledEventArgs<Assignment>(ass);
- ItemEditing?.Invoke(this, args);
- if (args.Status == CalendarHandledStatus.Cancel)
- return null;
-
- if ((args.Status == CalendarHandledStatus.Handled) || CheckGrid(ref ag).EditItems(new[] { ass }))
- {
- UpdateAssignment(ass);
- _copiedmodel = null;
- }
- return ass;
- }
- private void FillAssignment(AssignmentModel model)
- {
- MessageBox.Show("Not Yet Implemented");
- }
- private void EditAssignment(AssignmentModel model)
- {
- if (model == null)
- {
- MessageBox.Show("Please select an entry first!");
- return;
- }
- var grid = CheckGrid(ref ag);
- var ass = new Client<Assignment>().Query(new Filter<Assignment>(x => x.ID).IsEqualTo(model.ID), grid.LoadEditorColumns())
- .ToObjects<Assignment>().FirstOrDefault();
- if (grid.EditItems(new[] { ass }))
- {
- ItemChanged?.Invoke(this, new CalendarDataEventArgs<Assignment>(ass));
- Refresh();
- }
-
- }
- private void DeleteAssignment(AssignmentModel model)
- {
- if (model == null)
- {
- MessageBox.Show("Please select an entry first!");
- return;
- }
- if (MessageBox.Show("Are you sure you wish to delete this assignment?", "Confirm Delete", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
- return;
-
- var ass = new Assignment { ID = model.ID };
- new Client<Assignment>().Delete(ass, "Assignment Deleted from Scheduler");
- ItemChanged?.Invoke(this, new CalendarDataEventArgs<Assignment>(ass));
- Refresh();
- SelectionChanged?.Invoke(this, new CalendarDataEventArgs<Assignment>(null));
- }
-
- private AssignmentModel _copiedmodel;
- private void CopyAssignment(AssignmentModel model)
- {
- if (model == null)
- {
- MessageBox.Show("Please select an entry first!");
- return;
- }
- _copiedmodel = model;
- }
- private Assignment PasteAssignment(CalendarTimeSlot slot)
- {
- if (slot == null)
- {
- MessageBox.Show("Please select an employee first!");
- return null;
- }
-
- var ass = _assignments.FirstOrDefault(a => a.ID == _copiedmodel.ID)?.Row?.ToObject<Assignment>();
- if (ass == null)
- {
- MessageBox.Show("Cannot find copied entry!");
- return null;
- }
-
- ass.Date = SelectedDate.Date;
- ass.ID = Guid.Empty;
- ass.Number = 0;
- ass.CommitChanges();
-
- ass.Booked.Start = AdjustStartTime(slot.Time.TimeOfDay);
- ass.Booked.Duration = TimeIntervalToTimeSpan(TimeInterval);
- ass.Booked.Finish = ass.Booked.Start + ass.Booked.Duration;
- if ((AssignmentType == CalendarAssignmentType.Actual) || ((AssignmentType == CalendarAssignmentType.Automatic) && (ass.Date <= DateTime.Today)))
- {
- ass.Actual.Start = ass.Booked.Start;
- ass.Actual.Duration = ass.Booked.Duration;
- ass.Actual.Finish = ass.Actual.Start + ass.Actual.Duration;
- }
-
- ass.EmployeeLink.ID = slot.EmployeeID;
- new Client<Assignment>().Save(ass, "");
- UpdateAssignment(ass);
- _copiedmodel = null;
- return ass;
- }
-
- private void Bookings_OnAppointmentTapped(object? sender, AppointmentTappedArgs e)
- {
- //if (e.Appointment is AssignmentModel model)
- if (e.Appointment is AssignmentAppointment appointment)
- {
-
- ICalendarDataEventArgs args = new CalendarDataEventArgs<Assignment>(
- appointment.Model.Row?.ToObject<Assignment>()
- );
- SelectionChanged?.Invoke(this, args);
- }
- else
- SelectionChanged?.Invoke(this, new CalendarDataEventArgs<Assignment>(null));
-
- }
- private void Calendar_OnSizeChanged(object sender, SizeChangedEventArgs e)
- {
- if (double.IsNaN(this.ActualHeight) || (this.ActualHeight == 0))
- return;
- UpdateZoom();
- }
- private void _settingsButton_OnClick(object sender, RoutedEventArgs e)
- {
- _splitPanel.View = DynamicSplitPanelView.Master;
- }
- private void _splitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
- {
- if (EventSuppressor.IsSet(Suppress.Events))
- return;
- if (e.View == DynamicSplitPanelView.Combined && SettingsVisible != CalendarSettingsVisibility.Visible)
- SetSettingsVisibility(CalendarSettingsVisibility.Visible);
- else if (e.View == DynamicSplitPanelView.Master && SettingsVisible == CalendarSettingsVisibility.Visible)
- SetSettingsVisibility(CalendarSettingsVisibility.Hidden);
- }
-
- private void Bookings_OnQueryAppointments(object? sender, QueryAppointmentsEventArgs e)
- {
- if (bFirst)
- return;
- SelectedDate = e.VisibleDateRange.StartDate.Date;
- }
- }
- }
|