-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMainPage.xaml.cs
875 lines (825 loc) · 33.9 KB
/
MainPage.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
using DevExpress.Maui.Scheduler;
using DevExpress.Maui.Scheduler.Internal;
using System.ComponentModel;
using Microsoft.Maui.Controls;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace AgendaView
{
public partial class MainPage : ContentPage
{
bool inNavigation;
readonly DailyEmployeeCalendarViewModel viewModel = new DailyEmployeeCalendarViewModel();
public MainPage()
{
InitializeComponent();
BindingContext = viewModel;
}
async void OnTap(object sender, SchedulerGestureEventArgs e)
{
if (this.inNavigation)
return;
Page appointmentPage = storage.CreateAppointmentPageOnTap(e, true);
if (appointmentPage != null)
{
inNavigation = true;
await Navigation.PushAsync(appointmentPage);
}
}
async void OnNewAppointmentClicked(object sender, EventArgs e)
{
if (this.inNavigation)
return;
Page appointmentPage = storage.CreateAppointmentPageOnTap(agendaView.Start, false);
if (appointmentPage != null)
{
inNavigation = true;
await Navigation.PushAsync(appointmentPage);
}
}
}
public class NotificationObject : INotifyPropertyChanged
{
protected bool SetProperty<T>(ref T backingStore, T value, Action? onChanged = null, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;
backingStore = value;
onChanged?.Invoke();
OnPropertyChanged(propertyName);
return true;
}
protected bool SetProperty<T>(ref T backingStore, T value, Action<T, T> onChanged, [CallerMemberName] string propertyName = "")
{
if (EqualityComparer<T>.Default.Equals(backingStore, value))
return false;
T oldValue = backingStore;
backingStore = value;
onChanged?.Invoke(oldValue, value);
OnPropertyChanged(propertyName);
return true;
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
public class DataItem : NotificationObject
{
int id;
public int Id
{
get => id;
set => SetProperty(ref id, value);
}
}
public class TeamCalendar : DataItem
{
string? name;
public string? Name
{
get => name;
set => SetProperty(ref name, value);
}
}
public class TeamAppointment : DataItem
{
int appointmentType;
bool allDay;
DateTime start;
DateTime end;
string? subject;
string? description;
int status;
int label;
string? location;
int calendarId;
string? recurrenceInfo;
string? timeZoneId;
public int AppointmentType
{
get => appointmentType;
set => SetProperty(ref appointmentType, value);
}
public bool AllDay
{
get => allDay;
set => SetProperty(ref allDay, value);
}
public DateTime Start
{
get => start;
set => SetProperty(ref start, value);
}
public DateTime End
{
get => end;
set => SetProperty(ref end, value);
}
public string? Subject
{
get => subject;
set => SetProperty(ref subject, value);
}
public string? Description
{
get => description;
set => SetProperty(ref description, value);
}
public int Status
{
get => status;
set => SetProperty(ref status, value);
}
public int Label
{
get => label;
set => SetProperty(ref label, value);
}
public string? Location
{
get => location;
set => SetProperty(ref location, value);
}
public int CalendarId
{
get => calendarId;
set => SetProperty(ref calendarId, value);
}
public string? RecurrenceInfo
{
get => recurrenceInfo;
set => SetProperty(ref recurrenceInfo, value);
}
public string? TimeZoneId
{
get => timeZoneId;
set => SetProperty(ref timeZoneId, value);
}
}
public class Employee
{
public long EmployeeID { get; set; }
public string? LastName { get; set; }
public string? FirstName { get; set; }
public string? Title { get; set; }
public string? TitleOfCourtesy { get; set; }
public DateTime BirthDate { get; set; }
public DateTime HireDate { get; set; }
public string? Address { get; set; }
public string? City { get; set; }
public string? Region { get; set; }
public string? PostalCode { get; set; }
public string? Country { get; set; }
public string? HomePhone { get; set; }
public string? Extension { get; set; }
public byte[]? Photo { get; set; }
public string? Notes { get; set; }
public long ReportsTo { get; set; }
public string? Email { get; set; }
public string? GroupName { get; set; }
string? _FullName;
public string FullName
{
get
{
if (_FullName == null)
_FullName = String.Format("{0} {1}", FirstName, LastName);
return _FullName;
}
}
}
public static class TeamData
{
static TeamData()
{
Random = new Random();
Start = GetStart();
Employees = new List<Employee>() {
new Employee() { BirthDate = new DateTime(1978, 12, 08), FirstName = "Nancy", LastName = "Davolio" },
new Employee() { BirthDate = new DateTime(1965, 02, 19), FirstName = "Andrew", LastName = "Fuller" },
new Employee() { BirthDate = new DateTime(1968, 06, 26), FirstName = "Janet", LastName = "Leverling" },
new Employee() { BirthDate = new DateTime(1993, 05, 03), FirstName = "Margaret", LastName = "Peacock" },
new Employee() { BirthDate = new DateTime(1993, 10, 17), FirstName = "Steven", LastName = "Buchanan" },
new Employee() { BirthDate = new DateTime(1999, 10, 17), FirstName = "Michael", LastName = "Suyama" },
};
Employees[0].BirthDate = Start.AddDays(4).AddYears(-30);
Calendars = CreateCalendars().ToList();
VacationAppointments = CreateVacationsAppointments(Start).ToList();
CompanyBirthdayAppointments = CreateCompanyBirthdayAppointments(Start).ToList();
BirthdayAppointments = CreateBirthdayAppointments().ToList();
ConferenceAppointments = CreateConferenceAppointments(Start).ToList();
MeetingAppointments = CreateMeetingAppointments(Start).ToList();
PhoneCallsAppointments = CreatePhoneCallsAppointments(Start).ToList();
CarWashAppointments = CreateCarWashAppointments(Start).ToList();
TrainingAppointments = CreateTrainingAppointments(Start).ToList();
PayBillsAppointments = CreatePayBillsAppointments(Start).ToList();
DentistAppointments = CreateDentistAppointments(Start).ToList();
RestaurantAppointments = CreateRestaurantAppointments(Start).ToList();
Some3AppointmentADayFor5Years = Create3AppointmentADayFor5Years(Start).ToList();
AllAppointments = VacationAppointments
.Concat(BirthdayAppointments)
.Concat(CompanyBirthdayAppointments)
.Concat(ConferenceAppointments)
.Concat(MeetingAppointments)
.Concat(PhoneCallsAppointments)
.Concat(CarWashAppointments)
.Concat(TrainingAppointments)
.Concat(PayBillsAppointments)
.Concat(DentistAppointments)
.Concat(RestaurantAppointments)
.Concat(Some3AppointmentADayFor5Years)
.ToList();
int id = 0;
foreach (TeamAppointment apt in AllAppointments)
apt.Id = id++;
}
public static DateTime Start { get; private set; }
public static IEnumerable<TeamCalendar> Calendars { get; private set; }
public static TeamCalendar MyCalendar { get { return Calendars.ElementAt(0); } }
public static TeamCalendar TeamCalendar { get { return Calendars.ElementAt(1); } }
public static IEnumerable<TeamAppointment> AllAppointments { get; private set; }
public static IEnumerable<TeamAppointment> VacationAppointments { get; private set; }
public static IEnumerable<TeamAppointment> BirthdayAppointments { get; private set; }
public static IEnumerable<TeamAppointment> ConferenceAppointments { get; private set; }
public static IEnumerable<TeamAppointment> MeetingAppointments { get; private set; }
public static IEnumerable<TeamAppointment> PhoneCallsAppointments { get; private set; }
public static IEnumerable<TeamAppointment> CarWashAppointments { get; private set; }
public static IEnumerable<TeamAppointment> CompanyBirthdayAppointments { get; private set; }
public static IEnumerable<TeamAppointment> TrainingAppointments { get; private set; }
public static IEnumerable<TeamAppointment> PayBillsAppointments { get; private set; }
public static IEnumerable<TeamAppointment> DentistAppointments { get; private set; }
public static IEnumerable<TeamAppointment> RestaurantAppointments { get; private set; }
public static IEnumerable<TeamAppointment> Some3AppointmentADayFor5Years { get; private set; }
static readonly List<Employee> Employees;
static readonly Random Random;
static bool IsRandomEnabled = false;
static DateTime GetStart()
{
DateTime today = DateTime.Today;
DayOfWeek dayOfWeek = today.DayOfWeek;
if (dayOfWeek == DayOfWeek.Monday)
return today;
if (dayOfWeek == DayOfWeek.Sunday)
return today.AddDays(1);
return today.AddDays(-((int)dayOfWeek - 1));
}
static int nextEmployeeIndex = 0;
static Employee GetRandomEmployee()
{
if (IsRandomEnabled)
return Employees[Random.Next(0, Employees.Count)];
return Employees[nextEmployeeIndex++ % Employees.Count];
}
static TeamCalendar[] CreateCalendars()
{
return new TeamCalendar[] {
new TeamCalendar() { Id = 0, Name = "My Calendar" },
new TeamCalendar() { Id = 1, Name = "Team Calendar" },
};
}
static IEnumerable<TeamAppointment> CreateBirthdayAppointments()
{
return Employees.Select(CreateBirthdayAppointment);
}
static TeamAppointment CreateBirthdayAppointment(Employee employee)
{
DateTime date = employee.BirthDate;
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Pattern,
AllDay = true,
Start = date,
End = date.AddDays(1),
Subject = string.Format("{0}'s Birthday", employee.FirstName),
Status = 0,
Label = 8,
CalendarId = 0,
};
apt.RecurrenceInfo = new RecurrenceInfo()
{
AllDay = true,
Start = date,
Month = date.Month,
DayNumber = date.Day,
WeekOfMonth = WeekOfMonth.None,
Type = RecurrenceType.Yearly,
Range = RecurrenceRange.NoEndDate
}.ToXml();
return apt;
}
static IEnumerable<TeamAppointment> CreateConferenceAppointments(DateTime start)
{
DateTime newStart = start;
Tuple<string, DateTime>[] thisWeekList = {
Tuple.Create("DevExpress MVVM Framework", newStart.AddDays(1).AddHours(15)),
Tuple.Create("New Theme Designer", newStart.AddDays(2).AddHours(14)),
Tuple.Create("GridControl Performance Optimization", newStart.AddDays(3).AddHours(16)),
Tuple.Create("WinForms and DirectX", newStart.AddDays(4).AddHours(16)),
};
newStart = start.AddDays(-7);
Tuple<string, DateTime>[] prevWeekList = {
Tuple.Create("LOB applications", newStart.AddDays(1).AddHours(13)),
Tuple.Create("Module Injection Framework", newStart.AddDays(2).AddHours(16)),
Tuple.Create("Git tricks", newStart.AddDays(3).AddHours(10)),
Tuple.Create("Machine learning", newStart.AddDays(4).AddHours(11)),
};
newStart = start.AddDays(7);
Tuple<string, DateTime>[] nextWeekList = {
Tuple.Create("Azure", newStart.AddDays(1).AddHours(13)),
Tuple.Create("WCF Services", newStart.AddDays(2).AddHours(16)),
Tuple.Create("Docking Floating Panels", newStart.AddDays(3).AddHours(10)),
Tuple.Create("Personal Time Management", newStart.AddDays(4).AddHours(11)),
};
newStart = start.AddDays(14);
Tuple<string, DateTime>[] nextNextWeekList = {
Tuple.Create("Entity Framework Core", newStart.AddDays(1).AddHours(10)),
Tuple.Create(".Net Core", newStart.AddDays(2).AddHours(16)),
};
IEnumerable<Tuple<string, DateTime>> list = thisWeekList.Concat(prevWeekList).Concat(nextWeekList).Concat(nextNextWeekList);
List<Tuple<string, DateTime>> commonList = new List<Tuple<string, DateTime>>();
DateTimeRange interval = new DateTimeRange(start.AddDays(-7), start.AddDays(21));
IEnumerable<string> subjects = list.Select(x => x.Item1);
for (int i = 0; i < 100; i++)
{
newStart = start.AddYears(-1);
if (IsRandomEnabled)
{
newStart = newStart.AddDays(Random.Next(2 * 365));
newStart = newStart.AddHours(Random.Next(9, 18));
}
else
{
newStart = newStart.AddDays((i * 4) % 365);
newStart = newStart.AddHours((i * 3) % 9 + 9);
}
if (interval.Start <= newStart && interval.End >= newStart)
continue;
string subj = IsRandomEnabled ? subjects.ElementAt(Random.Next(0, subjects.Count())) : subjects.ElementAt(i % subjects.Count());
commonList.Add(Tuple.Create(subj, newStart));
}
return list.Concat(commonList).Select(x => CreateConferenceAppointment(x.Item1, x.Item2));
}
static TeamAppointment CreateConferenceAppointment(string subject, DateTime start)
{
Employee emp = GetRandomEmployee();
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Normal,
AllDay = false,
Start = start,
End = start.AddHours(1.5),
Subject = string.Format("Conference: {0}", subject),
Description = string.Format("{0} {1} tells us about {2}.", emp.FirstName, emp.LastName, subject),
Status = 2,
Label = 2,
Location = "Conference Room",
CalendarId = 1,
};
return apt;
}
static List<TeamAppointment> CreateMeetingAppointments(DateTime start)
{
List<TeamAppointment> res = new List<TeamAppointment>() {
CreateMeetingRecurrenceAppointment("Weekly meeting", start.AddMonths(-6).Add(new TimeSpan(5, 14, 00, 0))),
CreateLunchAppointment(Employees[0], start.AddDays(1).AddHours(13)),
CreateLunchAppointment(Employees[1], start.AddDays(3).AddHours(13)),
CreateLunchAppointment(Employees[2], start.AddDays(-4).AddHours(13)),
CreateLunchAppointment(Employees[3], start.AddDays(9).AddHours(13)),
CreateLunchAppointment(Employees[4], start.AddDays(12).AddHours(13)),
};
DateTimeRange interval = new DateTimeRange(start.AddDays(-7), start.AddDays(21));
List<int> days = new List<int>();
for (int i = 0; i < 50; i++)
{
Employee emp = IsRandomEnabled ? Employees[Random.Next(0, Employees.Count)] : Employees[(i * 3) % Employees.Count];
DateTime newStart = start.AddYears(-1);
if (IsRandomEnabled)
{
newStart = newStart.AddDays(Random.Next(365));
}
else
{
newStart = newStart.AddDays((i * 4) % 365);
}
if (interval.Start <= newStart && interval.End >= newStart)
continue;
if (days.Contains(newStart.DayOfYear))
continue;
if (VacationAppointments.Any(x => x.Start <= newStart && x.End >= newStart))
continue;
days.Add(newStart.DayOfYear);
res.Add(CreateLunchAppointment(emp, newStart.AddHours(13)));
}
return res;
}
static TeamAppointment CreateMeetingRecurrenceAppointment(string subject, DateTime start)
{
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Pattern,
AllDay = false,
Start = start,
End = start.AddHours(1),
Subject = subject,
Status = 2,
Label = 2,
CalendarId = 1,
};
apt.RecurrenceInfo = new RecurrenceInfo()
{
Start = start,
Type = RecurrenceType.Weekly,
WeekDays = WeekDays.Friday,
Month = 12,
Range = RecurrenceRange.NoEndDate
}.ToXml();
return apt;
}
static TeamAppointment CreateLunchAppointment(Employee emp, DateTime start)
{
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Normal,
AllDay = false,
Start = start,
End = start.AddHours(1),
Subject = string.Format("Lunch with {0}", emp.FirstName),
Status = 3,
Label = 3,
CalendarId = 0,
};
return apt;
}
static List<TeamAppointment> CreatePhoneCallsAppointments(DateTime start)
{
List<TeamAppointment> res = new List<TeamAppointment>() {
CreatePhoneCallAppointment(Employees[0], start.AddDays(0).AddHours(10)),
CreatePhoneCallAppointment(Employees[1], start.AddDays(3).AddHours(11)),
CreatePhoneCallAppointment(Employees[2], start.AddDays(3).AddHours(12).AddMinutes(40), TimeSpan.FromMinutes(15)),
CreatePhoneCallAppointment(Employees[3], start.AddDays(-4).AddHours(14)),
CreatePhoneCallAppointment(Employees[4], start.AddDays(9).AddHours(15)),
CreatePhoneCallAppointment(Employees[5], start.AddDays(12).AddHours(15)),
CreatePhoneCallAppointment(GetRandomEmployee(), start.AddDays(0).AddHours(16)),
CreatePhoneCallAppointment(GetRandomEmployee(), start.AddDays(2).AddHours(15.6)),
CreatePhoneCallAppointment(GetRandomEmployee(), start.AddDays(4).AddHours(15)),
CreatePhoneCallAppointment(GetRandomEmployee(), start.AddDays(5).AddHours(10.5)),
CreatePhoneCallAppointment(GetRandomEmployee(), start.AddDays(5).AddHours(16)),
CreatePhoneCallAppointment(GetRandomEmployee(), start.AddDays(6).AddHours(9.7)),
CreatePhoneCallAppointment(GetRandomEmployee(), start.AddDays(6).AddHours(16.8)),
};
DateTimeRange interval = new DateTimeRange(start.AddDays(-7), start.AddDays(21));
for (int i = 0; i < 50; i++)
{
Employee emp = (IsRandomEnabled) ? Employees[Random.Next(0, Employees.Count)] : Employees[(i * 3) % Employees.Count];
DateTime newStart = start.AddYears(-1);
if (IsRandomEnabled)
newStart = newStart.AddDays(Random.Next(365));
else
newStart = newStart.AddDays((i * 4) % 365);
if (interval.Start <= newStart && interval.End >= newStart)
continue;
if (VacationAppointments.Any(x => x.Start <= newStart && x.End >= newStart))
continue;
if (IsRandomEnabled)
res.Add(CreatePhoneCallAppointment(emp, newStart.AddHours(Random.Next(9, 18))));
else
res.Add(CreatePhoneCallAppointment(emp, newStart.AddHours((i * 3) % 9 + 9)));
}
return res;
}
static TeamAppointment CreatePhoneCallAppointment(Employee emp, DateTime start, TimeSpan? duration = null)
{
DateTime newStart = IsRandomEnabled ? start.AddMinutes(Random.Next(0, 4) * 15) : start.AddMinutes(15);
DateTime newEnd = duration != null
? newStart.Add(duration.Value)
: (IsRandomEnabled) ? newStart.AddMinutes(Random.Next(1, 6) * 5) : newStart.AddMinutes(20);
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Normal,
AllDay = false,
Start = newStart,
End = newEnd,
Subject = string.Format("Phone Call with {0}", emp.FirstName),
Status = 2,
Label = 10,
CalendarId = 0,
};
return apt;
}
static TeamAppointment[] CreateVacationsAppointments(DateTime start)
{
return new[] {
new TeamAppointment() {
AppointmentType = (int)AppointmentType.Normal,
AllDay = true,
Start = start.AddMonths(-6),
End = start.AddMonths(-6).AddDays(14),
Subject = string.Format("Vacation"),
Status = 0,
Label = 4,
CalendarId = 0,
},
new TeamAppointment() {
AppointmentType = (int)AppointmentType.Normal,
AllDay = true,
Start = start.AddMonths(6),
End = start.AddMonths(6).AddDays(14),
Subject = string.Format("Vacation"),
Status = 0,
Label = 4,
CalendarId = 0,
},
new TeamAppointment() {
AppointmentType = (int)AppointmentType.Normal,
AllDay = true,
Start = start.AddDays(4),
End = start.AddDays(8),
Subject = string.Format("Vacation"),
Status = 0,
Label = 4,
CalendarId = 0,
},
};
}
static List<TeamAppointment> CreateCarWashAppointments(DateTime start)
{
List<TeamAppointment> res = new List<TeamAppointment>() {
CreateCarWashAppointment(start.AddDays(1).AddHours(17)),
};
DateTime newStart = start.AddYears(-1);
while (newStart < start.AddMonths(1))
{
newStart = IsRandomEnabled ? newStart.AddDays(Random.Next(18, 35)) : newStart.AddDays(21);
if (VacationAppointments.Any(x => x.Start <= newStart && x.End >= newStart))
continue;
if (newStart >= start && newStart <= start.AddDays(7))
continue;
CreateCarWashAppointment(newStart);
}
return res;
}
static TeamAppointment CreateCarWashAppointment(DateTime start)
{
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Normal,
AllDay = false,
Start = start,
End = start.AddHours(1),
Subject = string.Format("Car Wash"),
Status = 3,
Label = 3,
CalendarId = 0,
};
return apt;
}
static TeamAppointment[] CreateCompanyBirthdayAppointments(DateTime start)
{
DateTime newStart = new DateTime(start.Year - 1, start.Month, start.Day);
newStart = newStart.AddDays(5);
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Pattern,
AllDay = true,
Start = newStart,
End = newStart.AddDays(1),
Subject = "Company Birthday Party",
Status = 0,
Label = 8,
CalendarId = 1,
};
apt.RecurrenceInfo = new RecurrenceInfo()
{
AllDay = true,
Start = newStart,
Type = RecurrenceType.Yearly,
Month = newStart.Month,
DayNumber = newStart.Day,
WeekOfMonth = WeekOfMonth.None,
Range = RecurrenceRange.NoEndDate
}.ToXml();
return new[] { apt };
}
static TeamAppointment[] CreateTrainingAppointments(DateTime start)
{
DateTime newStart = start.AddYears(-3).AddHours(8.5);
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Pattern,
AllDay = false,
Start = newStart,
End = newStart.AddHours(1.5),
Subject = "Sport Training",
Status = 1,
Label = 3,
CalendarId = 0,
};
apt.RecurrenceInfo = new RecurrenceInfo()
{
AllDay = false,
Start = newStart,
Type = RecurrenceType.Weekly,
WeekDays = WeekDays.Monday | WeekDays.Wednesday | WeekDays.Friday,
Range = RecurrenceRange.NoEndDate
}.ToXml();
newStart = start.AddYears(-4).AddHours(6.5);
var apt2 = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Pattern,
AllDay = false,
Start = newStart,
End = newStart.AddHours(1.5),
Subject = "Sport Training for managers",
Status = 1,
Label = 3,
CalendarId = 0,
};
apt2.RecurrenceInfo = new RecurrenceInfo()
{
AllDay = false,
Start = newStart,
Type = RecurrenceType.Weekly,
WeekDays = WeekDays.Monday | WeekDays.Wednesday | WeekDays.Friday,
Range = RecurrenceRange.NoEndDate
}.ToXml();
return new[] { apt, apt2 };
}
static TeamAppointment[] CreatePayBillsAppointments(DateTime start)
{
DateTime newStart = start.AddDays(2).AddYears(-1);
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Pattern,
AllDay = true,
Start = newStart,
End = newStart.AddDays(1),
Subject = "Pay Bills",
Status = 0,
Label = 3,
CalendarId = 0,
};
apt.RecurrenceInfo = new RecurrenceInfo()
{
AllDay = true,
Start = newStart,
Type = RecurrenceType.Monthly,
DayNumber = newStart.Day,
WeekOfMonth = WeekOfMonth.None,
Range = RecurrenceRange.NoEndDate,
}.ToXml();
return new[] { apt };
}
static List<TeamAppointment> CreateDentistAppointments(DateTime start)
{
List<TeamAppointment> res = new List<TeamAppointment>() {
CreateDentistAppointment(start.AddDays(4).AddHours(17.5)),
};
DateTime newStart = start.AddYears(-2);
while (newStart < start)
{
if (IsRandomEnabled)
newStart = newStart.AddDays(Random.Next(365 / 3, 365 / 2));
else
newStart = newStart.AddDays(34);
CreateDentistAppointment(newStart);
}
return res;
}
static TeamAppointment CreateDentistAppointment(DateTime start)
{
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Normal,
AllDay = false,
Start = start,
End = start.AddHours(2),
Subject = string.Format("Dentist"),
Status = 3,
Label = 3,
CalendarId = 0,
};
return apt;
}
static List<TeamAppointment> CreateRestaurantAppointments(DateTime start)
{
List<TeamAppointment> res = new List<TeamAppointment>() {
CreateDinnerAppointment(start.AddDays(2).AddHours(19)),
CreateDinnerAppointment(start.AddDays(14).AddHours(19)),
CreateDinnerAppointment(start.AddDays(18).AddHours(21)),
};
DateTime newStart = start.AddYears(-2);
while (newStart < start)
{
if (IsRandomEnabled)
{
newStart = newStart.AddDays(Random.Next(14, 42));
res.Add(CreateDinnerAppointment(newStart.AddHours(Random.Next(18, 22))));
}
else
{
newStart = newStart.AddDays(21);
res.Add(CreateDinnerAppointment(newStart.AddHours(19)));
}
}
return res;
}
static TeamAppointment CreateDinnerAppointment(DateTime start, TimeSpan? duration = null)
{
DateTime newStart = IsRandomEnabled ? start.AddMinutes(Random.Next(0, 4) * 15) : start.AddMinutes(15);
DateTime newEnd = duration != null
? newStart.Add(duration.Value)
: (IsRandomEnabled) ? newStart.AddMinutes(Random.Next(4, 8) * 20) : newStart.AddMinutes(20);
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Normal,
AllDay = false,
Start = newStart,
End = newEnd,
Subject = string.Format("Dinner"),
Status = 0,
Label = 5,
CalendarId = 0,
};
return apt;
}
static List<TeamAppointment> Create3AppointmentADayFor5Years(DateTime start)
{
List<TeamAppointment> res = new();
DateTime newStart = start.AddYears(-3);
while (newStart < start.AddYears(3))
{
res.AddRange(Create3AppointmentADay(newStart));
newStart = newStart.AddDays(1);
}
return res;
}
static List<TeamAppointment> Create3AppointmentADay(DateTime start)
{
List<TeamAppointment> res = new();
for (int i = 0; i < 3; i++)
{
var apt = new TeamAppointment()
{
AppointmentType = (int)AppointmentType.Normal,
AllDay = false,
Start = start.AddHours(3 * i % 24),
End = start.AddHours(3 * i % 24 + 1),
Subject = string.Format("3 appointment a day"),
Status = 0,
Label = i % 5,
CalendarId = 0,
};
res.Add(apt);
}
return res;
}
}
public class EmployeeCalendarViewModel : NotificationObject
{
DateTime start;
public EmployeeCalendarViewModel(DateTime startDate)
{
Start = startDate;
Appointments = new ObservableCollection<TeamAppointment>(TeamData.AllAppointments);
}
public EmployeeCalendarViewModel() : this(TeamData.Start)
{
}
public IEnumerable<TeamAppointment> Appointments { get; protected set; }
public DateTime Start
{
get => this.start;
set
{
this.start = value;
NotifyPropertyChanged(nameof(Start));
}
}
protected void NotifyPropertyChanged(string propertyName)
{
OnPropertyChanged(propertyName);
}
}
public class DailyEmployeeCalendarViewModel : EmployeeCalendarViewModel
{
int daysCount = 1;
public DailyEmployeeCalendarViewModel() : base(DateTime.Today)
{
}
public int DaysCount
{
get => this.daysCount;
set
{
this.daysCount = value;
NotifyPropertyChanged(nameof(DaysCount));
}
}
}
}