/
Form1.cs
67 lines (54 loc) · 3.55 KB
/
Form1.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
using System;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraScheduler;
using System.Data.Entity;
namespace SchedulerEntityFramework {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
private CarsXtraSchedulingEntities1 carsXtraSchedulingEntities = new CarsXtraSchedulingEntities1();
public Form1() {
InitializeComponent();
schedulerControl1.Start = new DateTime(2017,3,20);
schedulerControl1.ActiveViewType = SchedulerViewType.FullWeek;
schedulerControl1.Storage.FetchAppointments += Storage_FetchAppointments;
SetupMappings();
carsXtraSchedulingEntities.Cars.Load();
schedulerControl1.Storage.Resources.DataSource = carsXtraSchedulingEntities.Cars.Local;
schedulerControl1.Storage.AppointmentsChanged += schedulerStorage1_AppointmentsChangedInsertedDeleted;
schedulerControl1.Storage.AppointmentsInserted += schedulerStorage1_AppointmentsChangedInsertedDeleted;
schedulerControl1.Storage.AppointmentsDeleted += schedulerStorage1_AppointmentsChangedInsertedDeleted;
}
private void schedulerStorage1_AppointmentsChangedInsertedDeleted(object sender, DevExpress.XtraScheduler.PersistentObjectsEventArgs e) {
carsXtraSchedulingEntities.SaveChanges();
}
private void Storage_FetchAppointments(object sender, FetchAppointmentsEventArgs e) {
DateTime startTime = e.Interval.Start;
DateTime endTime = e.Interval.End;
var entities = carsXtraSchedulingEntities.CarSchedulings.Where(entity => (entity.EventType == 1) ||
(entity.EventType != 1 &&
(entity.OriginalStartTime >= startTime && entity.OriginalStartTime < endTime) || (entity.OriginalEndTime > startTime && entity.OriginalEndTime <= endTime)));
entities.Load();
var collection = carsXtraSchedulingEntities.CarSchedulings.Local.ToBindingList();
schedulerControl1.Storage.Appointments.DataSource =collection;
Text = String.Format("{0} appointments are loaded for {1} interval", collection.Count, e.Interval);
}
private void SetupMappings() {
this.schedulerStorage1.Appointments.Mappings.Subject = "Subject";
this.schedulerStorage1.Appointments.Mappings.Description = "Description";
this.schedulerStorage1.Appointments.Mappings.Location = "Location";
this.schedulerStorage1.Appointments.Mappings.Start = "StartTime";
this.schedulerStorage1.Appointments.Mappings.End = "EndTime";
this.schedulerStorage1.Appointments.Mappings.AllDay = "AllDay";
this.schedulerStorage1.Appointments.Mappings.Label = "Label";
this.schedulerStorage1.Appointments.Mappings.Status = "Status";
this.schedulerStorage1.Appointments.Mappings.Type = "EventType";
this.schedulerStorage1.Appointments.Mappings.RecurrenceInfo = "RecurrenceInfo";
this.schedulerStorage1.Appointments.Mappings.ReminderInfo = "ReminderInfo";
this.schedulerStorage1.Appointments.Mappings.ResourceId = "CarId";
this.schedulerStorage1.Appointments.Mappings.OriginalOccurrenceStart = "OriginalStartTime";
this.schedulerStorage1.Appointments.Mappings.OriginalOccurrenceEnd = "OriginalEndTime";
this.schedulerStorage1.Resources.Mappings.Id = "ID";
this.schedulerStorage1.Resources.Mappings.Caption = "Model";
}
}
}