-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGettingStartedViewModel.cs
379 lines (324 loc) · 16.4 KB
/
GettingStartedViewModel.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
#region Copyright Syncfusion® Inc. 2001-2025.
// Copyright Syncfusion® Inc. 2001-2025. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using Microsoft.UI.Xaml.Media;
using Syncfusion.UI.Xaml.Core;
using Syncfusion.UI.Xaml.Scheduler;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI;
using Windows.UI;
namespace Syncfusion.SchedulerDemos.WinUI
{
public class GettingStartedViewModel : NotificationObject, IDisposable
{
private ScheduleAppointmentCollection events;
private ScheduleAppointmentCollection timelineEvents;
public GettingStartedViewModel()
{
Events = GenerateRandomAppointments();
TimelineEvents = GenerateTimelineRandomAppointments();
MinDate = DateTime.Now.Date.AddMonths(-3);
MaxDate = DateTime.Now.AddMonths(3);
DisplayDate = DateTime.Now.Date.AddHours(9);
this.SchedulerViewTypes = SchedulerViewTypeHelper.GetSchedulerViewTypes();
this.CalendarTypes = SchedulerViewTypeHelper.GetCalendarTypes();
}
public DateTime MinDate { get; set; }
public DateTime MaxDate { get; set; }
public DateTime DisplayDate { get; set; }
/// <summary>
/// Gets or sets scheduler view type collection
/// </summary>
public ObservableCollection<SchedulerViewTypeModel> SchedulerViewTypes { get; set; }
/// <summary>
/// Gets or sets calendar type collection
/// </summary>
public ObservableCollection<CalenderTypeViewModel> CalendarTypes { get; set; }
public ScheduleAppointmentCollection Events
{
get { return events; }
set
{
events = value;
RaisePropertyChanged("Events");
}
}
public ScheduleAppointmentCollection TimelineEvents
{
get { return timelineEvents; }
set
{
timelineEvents = value;
RaisePropertyChanged("TimelineEvents");
}
}
/// <summary>
/// Method to dispose objects.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool isdisposable)
{
if (isdisposable)
{
if (this.Events != null)
{
this.Events.Clear();
this.Events = null;
}
if (this.SchedulerViewTypes != null)
{
this.SchedulerViewTypes.Clear();
this.SchedulerViewTypes = null;
}
}
}
/// <summary>
/// Method to get foreground color based on background.
/// </summary>
/// <param name="backgroundColor"></param>
/// <returns></returns>
private Brush GetAppointmentForeground(Brush backgroundColor)
{
var brush = backgroundColor as SolidColorBrush;
if (brush.Color.ToString().Equals("#FF8551F2") || brush.Color.ToString().Equals("#FF5363FA") || brush.Color.ToString().Equals("#FF2D99FF"))
return new SolidColorBrush(Microsoft.UI.Colors.White);
else
return new SolidColorBrush(Color.FromArgb(255, 51, 51, 51));
}
private ScheduleAppointmentCollection GenerateRandomAppointments()
{
var WorkWeekDays = new ObservableCollection<DateTime>();
var WorkWeekSubjects = new ObservableCollection<string>()
{ "GoToMeeting", "Business Meeting", "Conference", "Project Status Discussion",
"Auditing", "Client Meeting", "Generate Report", "Target Meeting", "General Meeting" };
var NonWorkingDays = new ObservableCollection<DateTime>();
var NonWorkingSubjects = new ObservableCollection<string>()
{ "Go to party", "Order Pizza", "Buy Gift",
"Vacation" };
var YearlyOccurrance = new ObservableCollection<DateTime>();
var YearlyOccurranceSubjects = new ObservableCollection<string>() { "Wedding Anniversary", "Sam's Birthday", "Jenny's Birthday" };
var MonthlyOccurrance = new ObservableCollection<DateTime>();
var MonthlyOccurranceSubjects = new ObservableCollection<string>() { "Pay House Rent", "Car Service", "Medical Check Up" };
var WeekEndOccurrance = new ObservableCollection<DateTime>();
var WeekEndOccurranceSubjects = new ObservableCollection<string>() { "FootBall Match", "TV Show" };
var brush = new ObservableCollection<SolidColorBrush>();
brush.Add(new SolidColorBrush(Color.FromArgb(255, 133, 81, 242)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 140, 245, 219)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 83, 99, 250)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 255, 222, 133)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 45, 153, 255)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 253, 183, 165)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 198, 237, 115)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 253, 185, 222)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 83, 99, 250)));
Random ran = new Random();
DateTime today = DateTime.Now;
if (today.Month == 12)
{
today = today.AddMonths(-1);
}
else if (today.Month == 1)
{
today = today.AddMonths(1);
}
DateTime startMonth = new DateTime(today.Year, today.Month - 1, 1, 0, 0, 0);
DateTime endMonth = new DateTime(today.Year, today.Month + 1, 30, 0, 0, 0);
DateTime dt = new DateTime(today.Year, today.Month, 15, 0, 0, 0);
int day = (int)startMonth.DayOfWeek;
DateTime CurrentStart = startMonth.AddDays(-day);
var appointments = new ScheduleAppointmentCollection();
for (int i = 0; i < 90; i++)
{
if (i % 7 == 0 || i % 7 == 6)
{
//add weekend appointments
NonWorkingDays.Add(CurrentStart.AddDays(i));
}
else
{
//Add Workweek appointment
WorkWeekDays.Add(CurrentStart.AddDays(i));
}
}
for (int i = 0; i < 50; i++)
{
DateTime date = WorkWeekDays[ran.Next(0, WorkWeekDays.Count)].AddHours(ran.Next(9, 17));
var appointment = new ScheduleAppointment();
appointment.StartTime = date;
appointment.EndTime = date.AddHours(1);
appointment.AppointmentBackground = brush[i % brush.Count];
appointment.Foreground = GetAppointmentForeground(appointment.AppointmentBackground);
appointment.Subject = WorkWeekSubjects[i % WorkWeekSubjects.Count];
appointments.Add(appointment);
}
int j = 0;
int k = 0;
int l = 0;
while (j < YearlyOccurranceSubjects.Count)
{
DateTime date = NonWorkingDays[ran.Next(0, NonWorkingDays.Count)];
var appointment = new ScheduleAppointment();
appointment.StartTime = date;
appointment.EndTime = date.AddHours(1);
appointment.AppointmentBackground = brush[1];
appointment.Foreground = GetAppointmentForeground(appointment.AppointmentBackground);
appointment.Subject = YearlyOccurranceSubjects[j];
appointments.Add(appointment);
j++;
}
while (k < MonthlyOccurranceSubjects.Count)
{
DateTime date = NonWorkingDays[ran.Next(0, NonWorkingDays.Count)].AddHours(ran.Next(9, 23));
var appointment = new ScheduleAppointment();
appointment.StartTime = date;
appointment.EndTime = date.AddHours(1);
appointment.AppointmentBackground = brush[k];
appointment.Foreground = GetAppointmentForeground(appointment.AppointmentBackground);
appointment.Subject = MonthlyOccurranceSubjects[k];
appointments.Add(appointment);
k++;
}
while (l < WeekEndOccurranceSubjects.Count)
{
DateTime date = NonWorkingDays[ran.Next(0, NonWorkingDays.Count)].AddHours(ran.Next(0, 23));
var appointment = new ScheduleAppointment();
appointment.StartTime = date;
appointment.EndTime = date.AddHours(1);
appointment.AppointmentBackground = brush[l];
appointment.Foreground = GetAppointmentForeground(appointment.AppointmentBackground);
appointment.Subject = WeekEndOccurranceSubjects[l];
appointments.Add(appointment);
l++;
}
return appointments;
}
private ScheduleAppointmentCollection GenerateTimelineRandomAppointments()
{
var WorkWeekDays = new ObservableCollection<DateTime>();
var WorkWeekSubjects = new ObservableCollection<string>()
{ "GoToMeeting", "Business Meeting", "Conference", "Project Status Discussion",
"Auditing", "Client Meeting", "Generate Report", "Target Meeting", "General Meeting" };
var NonWorkingDays = new ObservableCollection<DateTime>();
var NonWorkingSubjects = new ObservableCollection<string>()
{ "Go to party", "Order Pizza", "Buy Gift",
"Vacation" };
var YearlyOccurrance = new ObservableCollection<DateTime>();
var YearlyOccurranceSubjects = new ObservableCollection<string>() { "Wedding Anniversary", "Sam's Birthday", "Jenny's Birthday" };
var MonthlyOccurrance = new ObservableCollection<DateTime>();
var MonthlyOccurranceSubjects = new ObservableCollection<string>() { "Pay House Rent", "Car Service", "Medical Check Up" };
var WeekEndOccurrance = new ObservableCollection<DateTime>();
var WeekEndOccurranceSubjects = new ObservableCollection<string>() { "FootBall Match", "TV Show" };
var brush = new ObservableCollection<SolidColorBrush>();
brush.Add(new SolidColorBrush(Color.FromArgb(255, 133, 81, 242)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 140, 245, 219)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 83, 99, 250)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 255, 222, 133)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 45, 153, 255)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 253, 183, 165)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 198, 237, 115)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 253, 185, 222)));
brush.Add(new SolidColorBrush(Color.FromArgb(255, 83, 99, 250)));
Random ran = new Random();
DateTime today = DateTime.Now;
if (today.Month == 12)
{
today = today.AddMonths(-1);
}
else if (today.Month == 1)
{
today = today.AddMonths(1);
}
DateTime startMonth = new DateTime(today.Year, today.Month - 1, 1, 0, 0, 0);
DateTime endMonth = new DateTime(today.Year, today.Month + 1, 30, 0, 0, 0);
DateTime dt = new DateTime(today.Year, today.Month, 15, 0, 0, 0);
int day = (int)startMonth.DayOfWeek;
DateTime CurrentStart = startMonth.AddDays(-day);
var appointments = new ScheduleAppointmentCollection();
for (int i = 0; i < 90; i++)
{
if (i % 7 == 0 || i % 7 == 6)
{
//add weekend appointments
NonWorkingDays.Add(CurrentStart.AddDays(i));
}
else
{
//Add Workweek appointment
WorkWeekDays.Add(CurrentStart.AddDays(i));
}
}
for (int i = 0; i < 50; i++)
{
DateTime date = WorkWeekDays[ran.Next(0, WorkWeekDays.Count)].AddHours(ran.Next(9, 17));
var appointment = new ScheduleAppointment();
appointment.StartTime = date;
appointment.EndTime = date.AddHours(1);
appointment.AppointmentBackground = brush[i % brush.Count];
appointment.Foreground = GetAppointmentForeground(appointment.AppointmentBackground);
appointment.Subject = WorkWeekSubjects[i % WorkWeekSubjects.Count];
appointments.Add(appointment);
}
DateTime currentDate = DateTime.Now.AddMonths(-1);
ScheduleAppointment weeklyEvent = new ScheduleAppointment
{
Subject = "Weekly recurring meeting",
StartTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 11, 0, 0),
EndTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 13, 0, 0),
AppointmentBackground = brush[1],
Foreground = GetAppointmentForeground(brush[1]),
RecurrenceRule = "FREQ=WEEKLY;BYDAY=MO,WE,FR;INTERVAL=1;COUNT=20",
RecurrenceExceptionDates = new ObservableCollection<DateTime>()
};
appointments.Add(weeklyEvent);
ScheduleAppointment monthlyEvent = new ScheduleAppointment
{
Subject = "Monthly recurring Meeting",
StartTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 12, 0, 0),
EndTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 14, 0, 0),
AppointmentBackground = brush[2],
Foreground = GetAppointmentForeground(brush[2]),
RecurrenceRule = "FREQ=MONTHLY;BYDAY=TU;BYSETPOS=1;INTERVAL=1;COUNT=50",
RecurrenceExceptionDates = new ObservableCollection<DateTime>()
};
appointments.Add(monthlyEvent);
ScheduleAppointment dailyEvent = new ScheduleAppointment
{
Subject = "Daily scrum meeting",
StartTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 9, 0, 0),
EndTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 11, 0, 0),
AppointmentBackground = brush[3],
Foreground = GetAppointmentForeground(brush[3]),
RecurrenceRule = "FREQ=DAILY;INTERVAL=1;COUNT=50",
Id = 1
};
appointments.Add(dailyEvent);
//Add ExceptionDates to avoid occurrence on specific dates.
DateTime changedExceptionDate1 = DateTime.Now.AddDays(-1).Date;
DateTime changedExceptionDate2 = DateTime.Now.Date.AddDays(4).Date;
DateTime deletedExceptionDate1 = DateTime.Now.Date.AddDays(2);
DateTime deletedExceptionDate2 = DateTime.Now.Date.AddDays(6);
DateTime deletedExceptionDate3 = DateTime.Now.Date.AddDays(8);
dailyEvent.RecurrenceExceptionDates = new ObservableCollection<DateTime>()
{
changedExceptionDate1,
changedExceptionDate2,
deletedExceptionDate1,
deletedExceptionDate2,
};
return appointments;
}
}
}