This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
/
SchedulerDataHelper.cs
172 lines (142 loc) · 8.13 KB
/
SchedulerDataHelper.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
using DevExpress.Web.Mvc;
using DevExpress.XtraScheduler;
using DXWebApplication1.Models;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
namespace DevExpressMvcApplication1.Models {
public class SchedulerDataHelper {
public static List<CustomResource> GetResources() {
List<CustomResource> resources = new List<CustomResource>();
resources.Add(CustomResource.CreateCustomResource(1, "Max Fowler", Color.Yellow.ToArgb()));
resources.Add(CustomResource.CreateCustomResource(2, "Nancy Drewmore", Color.Green.ToArgb()));
resources.Add(CustomResource.CreateCustomResource(3, "Pak Jang", Color.LightPink.ToArgb()));
return resources;
}
static Random myRand = new Random();
public static List<CustomAppointment> GetAppointments(List<CustomResource> resources) {
List<CustomAppointment> appointments = new List<CustomAppointment>();
foreach (CustomResource item in resources) {
string subjPrefix = item.Name + "'s ";
appointments.Add(CustomAppointment.CreateCustomAppointment("meeting", item.ResID, 2, 5, lastInsertedID++));
appointments.Add(CustomAppointment.CreateCustomAppointment("travel", item.ResID, 3, 6, lastInsertedID++));
appointments.Add(CustomAppointment.CreateCustomAppointment("phone call", item.ResID, 0, 10, lastInsertedID++));
}
return appointments;
}
public static SchedulerDataObject DataObject {
get {
SchedulerDataObject dataObject = new SchedulerDataObject();
if (HttpContext.Current.Session["ResourcesList"] == null) {
HttpContext.Current.Session["ResourcesList"] = GetResources();
}
dataObject.Resources = HttpContext.Current.Session["ResourcesList"] as List<CustomResource>;
if (HttpContext.Current.Session["AppointmentsList"] == null) {
HttpContext.Current.Session["AppointmentsList"] = GetAppointments(dataObject.Resources);
}
dataObject.Appointments = HttpContext.Current.Session["AppointmentsList"] as List<CustomAppointment>;
return dataObject;
}
}
static MVCxAppointmentStorage defaultAppointmentStorage;
public static MVCxAppointmentStorage DefaultAppointmentStorage {
get {
if (defaultAppointmentStorage == null) {
defaultAppointmentStorage = CreateDefaultAppointmentStorage();
}
return defaultAppointmentStorage;
}
}
static MVCxAppointmentStorage CreateDefaultAppointmentStorage() {
MVCxAppointmentStorage appointmentStorage = new MVCxAppointmentStorage();
appointmentStorage.AutoRetrieveId = true;
appointmentStorage.Mappings.AppointmentId = "ID";
appointmentStorage.Mappings.Start = "StartTime";
appointmentStorage.Mappings.End = "EndTime";
appointmentStorage.Mappings.Subject = "Subject";
appointmentStorage.Mappings.AllDay = "AllDay";
appointmentStorage.Mappings.Description = "Description";
appointmentStorage.Mappings.Label = "Label";
appointmentStorage.Mappings.Location = "Location";
appointmentStorage.Mappings.RecurrenceInfo = "RecurrenceInfo";
appointmentStorage.Mappings.ReminderInfo = "ReminderInfo";
appointmentStorage.Mappings.ResourceId = "OwnerId";
appointmentStorage.Mappings.Status = "Status";
appointmentStorage.Mappings.Type = "EventType";
appointmentStorage.CustomFieldMappings.Add(new DevExpress.Web.ASPxScheduler.ASPxAppointmentCustomFieldMapping("AppointmentCompany", "CompanyID"));
appointmentStorage.CustomFieldMappings.Add(new DevExpress.Web.ASPxScheduler.ASPxAppointmentCustomFieldMapping("AppointmentContact", "ContactID")); return appointmentStorage;
}
static MVCxResourceStorage defaultResourceStorage;
public static MVCxResourceStorage DefaultResourceStorage {
get {
if (defaultResourceStorage == null) {
defaultResourceStorage = CreateDefaultResourceStorage();
}
return defaultResourceStorage;
}
}
static MVCxResourceStorage CreateDefaultResourceStorage() {
MVCxResourceStorage resourceStorage = new MVCxResourceStorage();
resourceStorage.Mappings.ResourceId = "ResID";
resourceStorage.Mappings.Caption = "Name";
resourceStorage.Mappings.Color = "Color";
return resourceStorage;
}
public static SchedulerSettings GetSchedulerSettings() {
SchedulerSettings settings = new SchedulerSettings();
settings.Name = "scheduler";
settings.CallbackRouteValues = new { Controller = "Home", Action = "SchedulerPartial" };
settings.EditAppointmentRouteValues = new { Controller = "Home", Action = "EditAppointment" };
settings.CustomActionRouteValues = new { Controller = "Home", Action = "CustomCallBackAction" };
settings.Storage.Appointments.Assign(SchedulerDataHelper.DefaultAppointmentStorage);
settings.Storage.Resources.Assign(SchedulerDataHelper.DefaultResourceStorage);
settings.Storage.EnableReminders = true;
settings.GroupType = SchedulerGroupType.Resource;
settings.Views.DayView.Styles.ScrollAreaHeight = 400;
settings.Start = DateTime.Now;
var dialog = settings.OptionsForms.DialogLayoutSettings.AppointmentDialog;
dialog.ViewModel = new CustomAppointmentEditDialogViewModel();
dialog.GenerateDefaultLayoutElements();
var companies = dialog.LayoutElements.CreateField((CustomAppointmentEditDialogViewModel m) => m.AppointmentCompany);
var contacts = dialog.LayoutElements.CreateField((CustomAppointmentEditDialogViewModel m) => m.AppointmentContact);
dialog.InsertBefore(companies, dialog.FindLayoutElement("Description"));
dialog.InsertAfter(contacts, companies);
return settings;
}
static void Storage_ReminderAlert(object sender, ReminderEventArgs e) {
}
static int lastInsertedID = 0;
// CRUD operations implementation
public static void InsertAppointments(CustomAppointment[] appts) {
if (appts.Length == 0)
return;
List<CustomAppointment> appointmnets = HttpContext.Current.Session["AppointmentsList"] as List<CustomAppointment>;
for (int i = 0; i < appts.Length; i++) {
appts[i].ID = lastInsertedID++;
appointmnets.Add(appts[i]);
}
}
public static void UpdateAppointments(CustomAppointment[] appts) {
if (appts.Length == 0)
return;
List<CustomAppointment> appointmnets = System.Web.HttpContext.Current.Session["AppointmentsList"] as List<CustomAppointment>;
for (int i = 0; i < appts.Length; i++) {
CustomAppointment sourceObject = appointmnets.First<CustomAppointment>(apt => apt.ID == appts[i].ID);
appts[i].ID = sourceObject.ID;
appointmnets.Remove(sourceObject);
appointmnets.Add(appts[i]);
}
}
public static void RemoveAppointments(CustomAppointment[] appts) {
if (appts.Length == 0)
return;
List<CustomAppointment> appointmnets = HttpContext.Current.Session["AppointmentsList"] as List<CustomAppointment>;
for (int i = 0; i < appts.Length; i++) {
CustomAppointment sourceObject = appointmnets.First<CustomAppointment>(apt => apt.ID == appts[i].ID);
appointmnets.Remove(sourceObject);
}
}
}
}