-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppointmentForm.ascx.cs
301 lines (258 loc) · 13.2 KB
/
AppointmentForm.ascx.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
using System;
using System.Web.UI;
using DevExpress.XtraScheduler;
using DevExpress.Web;
using DevExpress.Web.ASPxScheduler;
using DevExpress.Web.ASPxScheduler.Internal;
using System.Collections;
using System.Collections.Generic;
using DevExpress.XtraScheduler.Localization;
using DevExpress.Web.ASPxScheduler.Localization;
using DevExpress.Utils;
using System.Web.UI.WebControls;
using DevExpress.Utils.Localization;
using DevExpress.Web.ASPxScheduler.Controls;
public partial class AppointmentForm : SchedulerFormControl {
public override string ClassName { get { return "ASPxAppointmentForm"; } }
public bool CanShowReminders {
get {
return ((AppointmentFormTemplateContainer)Parent).Control.Storage.EnableReminders;
}
}
public bool ResourceSharing {
get {
return ((AppointmentFormTemplateContainer)Parent).Control.Storage.ResourceSharing;
}
}
public IEnumerable ResourceDataSource {
get {
return ((AppointmentFormTemplateContainer)Parent).ResourceDataSource;
}
}
public bool TimeZonesEnabled {
get {
return ((AppointmentFormTemplateContainer)Parent).TimeZonesEnabled;
}
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
Localize();
tbSubject.Focus();
}
void Localize() {
appointmentFormMainLayout.FindItemOrGroupByName("itemSubject").Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_Subject);
appointmentFormMainLayout.FindItemOrGroupByName("itemLocation").Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_Location);
appointmentFormMainLayout.FindItemOrGroupByName("itemLabel").Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_Label);
appointmentFormMainLayout.FindItemOrGroupByName("itemStart").Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_StartTime);
appointmentFormMainLayout.FindItemOrGroupByName("itemEnd").Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_EndTime);
appointmentFormMainLayout.FindItemOrGroupByName("itemStatus").Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_Status);
appointmentFormMainLayout.FindItemOrGroupByName("itemAllDay").Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_AllDayEvent);
LayoutItemBase multipleResourceItem = appointmentFormMainLayout.FindItemOrGroupByName("itemResourceMultiple");
LayoutItemBase singleResourceItem = appointmentFormMainLayout.FindItemOrGroupByName("itemResourceSingle");
multipleResourceItem.Caption = singleResourceItem.Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_Resource);
multipleResourceItem.Visible = ResourceSharing;
singleResourceItem.Visible = !ResourceSharing;
LayoutItemBase reminderItem = appointmentFormMainLayout.FindItemOrGroupByName("itemReminder");
reminderItem.Visible = CanShowReminders;
reminderItem.Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_Reminder);
LayoutItemBase timeZoneItem = appointmentFormMainLayout.FindItemOrGroupByName("itemTimeZone");
timeZoneItem.Visible = TimeZonesEnabled;
timeZoneItem.Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_TimeZone);
LayoutItemBase recInfoItem = appointmentFormMainLayout.FindItemOrGroupByName("itemRecurrenceInfo");
recInfoItem.Caption = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_Recurrence);
cbRecurrenceType.Items.Add(ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Caption_RecurrenceType_Daily), "Daily");
cbRecurrenceType.Items.Add(ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Caption_RecurrenceType_Weekly), "Weekly");
cbRecurrenceType.Items.Add(ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Caption_RecurrenceType_Monthly), "Monthly");
cbRecurrenceType.Items.Add(ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Caption_RecurrenceType_Yearly), "Yearly");
btnOk.Text = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_ButtonOk);
btnCancel.Text = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_ButtonCancel);
btnDelete.Text = ASPxSchedulerLocalizer.GetString(ASPxSchedulerStringId.Form_ButtonDelete);
btnOk.Wrap = DefaultBoolean.False;
btnCancel.Wrap = DefaultBoolean.False;
btnDelete.Wrap = DefaultBoolean.False;
}
public override void DataBind() {
base.DataBind();
AppointmentFormTemplateContainer container = (AppointmentFormTemplateContainer)Parent;
Appointment apt = container.Appointment;
IAppointmentStorageBase appointmentStorage = container.Control.Storage.Appointments;
IAppointmentLabel label = appointmentStorage.Labels.GetById(apt.LabelKey);
IAppointmentStatus status = appointmentStorage.Statuses.GetById(apt.StatusKey);
//SUBJECT
tbSubject.Text = apt.Subject;
//LOCATION
tbLocation.Text = apt.Location;
//LABEL
edtLabel.ValueType = apt.LabelKey.GetType();
edtLabel.SelectedIndex = appointmentStorage.Labels.IndexOf(label);
edtLabel.DataSource = container.LabelDataSource;
edtLabel.DataBindItems();
//STATUS
edtStatus.ValueType = apt.StatusKey.GetType();
edtStatus.SelectedIndex = appointmentStorage.Statuses.IndexOf(status);
edtStatus.DataSource = container.StatusDataSource;
edtStatus.DataBindItems();
//START
edtStartDate.Date = apt.Start;
edtStartTime.DateTime = apt.Start;
//END
edtEndDate.Date = apt.End;
edtEndTime.DateTime = apt.End;
//ALL DAY
chkAllDay.Checked = apt.AllDay;
//REMINDER
cbReminder.ValueType = typeof(string);
cbReminder.DataSource = container.ReminderDataSource;
cbReminder.DataBindItems();
cbReminder.Items.Insert(0, new ListEditItem("None", "None"));
if(apt.HasReminder)
cbReminder.Value = apt.Reminder.TimeBeforeStart.ToString();
else
cbReminder.SelectedIndex = 0;
//DESCRIPTION
tbDescription.Text = apt.Description;
//RESOURCE
PopulateResourceEditors(apt, container);
//TIME ZONE
if(TimeZonesEnabled) {
cbTimeZone.DataSource = TimeZoneInfo.GetSystemTimeZones();
cbTimeZone.ValueField = "Id";
cbTimeZone.TextField = "DisplayName";
cbTimeZone.DataBind();
cbTimeZone.Value = container.TimeZoneId;
cbTimeZone.Enabled = apt.Type == AppointmentType.Normal || apt.Type == AppointmentType.Pattern;
}
//RECCURRENCE
PopulateRecurrenceFormEditors(container);
schedulerStatusInfo.MasterControlID = container.Control.ID;
//btnOk.ClientSideEvents.Click = container.SaveHandler;
btnCancel.ClientSideEvents.Click = container.CancelHandler;
btnDelete.ClientSideEvents.Click = container.DeleteHandler;
JSProperties.Add("cpHasExceptions", apt.HasExceptions);
btnDelete.Enabled = !container.IsNewAppointment;
}
private void PopulateRecurrenceFormEditors(AppointmentFormTemplateContainer container) {
LayoutItemBase recInfoItem = appointmentFormMainLayout.FindItemOrGroupByName("itemRecurrenceInfo");
LayoutItemBase recInfoTypeGroup = appointmentFormMainLayout.FindItemOrGroupByName("groupRecurrenceType");
LayoutItemBase recInfoRangeGroup = appointmentFormMainLayout.FindItemOrGroupByName("groupRecurrenceRange");
recInfoItem.Visible = container.ShouldShowRecurrence;
recInfoTypeGroup.Visible = container.ShouldShowRecurrence;
recInfoRangeGroup.Visible = container.ShouldShowRecurrence;
if(container.IsRecurring) {
chkRecurrence.Checked = true;
recInfoTypeGroup.ClientVisible = true;
recInfoRangeGroup.ClientVisible = true;
cbRecurrenceType.Value = container.RecurrenceType.ToString();
dailyControl.Periodicity = container.RecurrencePeriodicity;
dailyControl.WeekDays = container.RecurrenceWeekDays;
weeklyControl.Periodicity = container.RecurrencePeriodicity;
weeklyControl.WeekDays = container.RecurrenceWeekDays;
monthlyControl.DayNumber = container.RecurrenceDayNumber;
monthlyControl.Periodicity = container.RecurrencePeriodicity;
monthlyControl.Start = container.RecurrenceStart;
monthlyControl.WeekDays = container.RecurrenceWeekDays;
monthlyControl.WeekOfMonth = container.RecurrenceWeekOfMonth;
yearlyControl.DayNumber = container.RecurrenceDayNumber;
yearlyControl.Month = container.RecurrenceMonth;
yearlyControl.Start = container.RecurrenceStart;
yearlyControl.WeekDays = container.RecurrenceWeekDays;
yearlyControl.WeekOfMonth = container.RecurrenceWeekOfMonth;
rangeControl.OccurrenceCount = container.RecurrenceOccurrenceCount;
rangeControl.Range = container.RecurrenceRange;
rangeControl.End = container.RecurrenceEnd;
}
else {
chkRecurrence.Checked = false;
cbRecurrenceType.SelectedIndex = 0;
recInfoTypeGroup.ClientVisible = false;
recInfoRangeGroup.ClientVisible = false;
}
}
private void PopulateResourceEditors(Appointment apt, AppointmentFormTemplateContainer container) {
if(ResourceSharing) {
ASPxListBox edtMultiResource = ddResource.FindControl("edtMultiResource") as ASPxListBox;
edtMultiResource.DataSource = container.ResourceDataSource;
edtMultiResource.DataBindItems();
if(edtMultiResource == null)
return;
SetListBoxSelectedValues(edtMultiResource, apt.ResourceIds);
List<String> multiResourceString = GetListBoxSelectedItemsText(edtMultiResource);
string stringResourceNone = SchedulerLocalizer.GetString(SchedulerStringId.Caption_ResourceNone);
ddResource.Value = stringResourceNone;
if(multiResourceString.Count > 0)
ddResource.Value = String.Join(", ", multiResourceString.ToArray());
ddResource.JSProperties.Add("cp_Caption_ResourceNone", stringResourceNone);
}
else {
edtResource.DataSource = container.ResourceDataSource;
edtResource.DataBindItems();
if(!Object.Equals(apt.ResourceId, EmptyResourceId.Id))
edtResource.Value = apt.ResourceId.ToString();
else
edtResource.Value = SchedulerIdHelper.EmptyResourceId;
}
}
List<String> GetListBoxSelectedItemsText(ASPxListBox listBox) {
List<String> result = new List<string>();
foreach(ListEditItem editItem in listBox.Items) {
if(editItem.Selected)
result.Add(editItem.Text);
}
return result;
}
void SetListBoxSelectedValues(ASPxListBox listBox, IEnumerable values) {
listBox.Value = null;
foreach(object value in values) {
ListEditItem item = listBox.Items.FindByValue(value.ToString());
if(item != null)
item.Selected = true;
}
}
protected override void PrepareChildControls() {
AppointmentFormTemplateContainer container = (AppointmentFormTemplateContainer)Parent;
ASPxScheduler control = container.Control;
base.PrepareChildControls();
}
protected override ASPxEditBase[] GetChildEditors() {
ASPxEditBase[] edits = new ASPxEditBase[] {
tbSubject,
chkAllDay,
edtStartDate,
edtEndDate,
edtStartTime,
edtEndTime,
tbLocation,
edtLabel,
edtStatus,
edtResource,
GetMultiResourceEditor(),
cbReminder,
cbTimeZone,
tbDescription,
chkRecurrence,
cbRecurrenceType,
};
return edits;
}
ASPxEditBase GetMultiResourceEditor() {
if(ddResource != null)
return ddResource.FindControl("edtMultiResource") as ASPxEditBase;
return null;
}
protected override ASPxButton[] GetChildButtons() {
ASPxButton[] buttons = new ASPxButton[] {
btnOk, btnCancel, btnDelete
};
return buttons;
}
protected override Control[] GetChildControls() {
return new Control[] { dailyControl, weeklyControl, monthlyControl, yearlyControl, rangeControl };
}
protected override WebControl GetDefaultButton() {
return btnOk;
}
protected override void PrepareLocalization(SchedulerLocalizationCache localizationCache) {
localizationCache.Add(SchedulerStringId.Msg_RecurrenceExceptionsWillBeLost);
localizationCache.Add(SchedulerStringId.Msg_Warning);
}
}