/
Form1.cs
129 lines (110 loc) · 6.41 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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraScheduler;
using System.Data.SqlClient;
namespace GanttExample {
public partial class Form1 : Form {
private int LastSplitContainerControlSplitterPosition;
public Form1() {
InitializeComponent();
#region #AppointmentEvents
schedulerDataStorage1.AppointmentsInserted += new PersistentObjectsEventHandler(schedulerDataStorage1_AppointmentsInserted);
schedulerDataStorage1.AppointmentsChanged += new PersistentObjectsEventHandler(schedulerDataStorage1_AppointmentsChanged);
schedulerDataStorage1.AppointmentsDeleted += new PersistentObjectsEventHandler(schedulerDataStorage1_AppointmentsDeleted);
#endregion #AppointmentEvents
#region #AppointmentDependencyEvents
schedulerDataStorage1.AppointmentDependenciesInserted += new PersistentObjectsEventHandler(schedulerDataStorage1_AppointmentDependenciesInserted);
schedulerDataStorage1.AppointmentDependenciesChanged += new PersistentObjectsEventHandler(schedulerDataStorage1_AppointmentDependenciesChanged);
schedulerDataStorage1.AppointmentDependenciesDeleted += new PersistentObjectsEventHandler(schedulerDataStorage1_AppointmentDependenciesDeleted);
#endregion #AppointmentDependencyEvents
//Fix the view type and splitter position.
schedulerControl1.ActiveViewChanged += new EventHandler(schedulerControl1_ActiveViewChanged);
this.splitContainerControl1.SplitterPositionChanged += new System.EventHandler(this.splitContainerControl1_SplitterPositionChanged);
// Set the date to show existing appointments from the database.
schedulerControl1.Start = new DateTime(2017, 6, 02);
}
private void Form1_Load(object sender, EventArgs e) {
LastSplitContainerControlSplitterPosition = 180;
// TODO: This line of code loads data into the 'gantTestDataSet.TaskDependencies' table. You can move, or remove it, as needed.
this.taskDependenciesTableAdapter.Fill(this.gantTestDataSet.TaskDependencies);
// TODO: This line of code loads data into the 'gantTestDataSet.Resources' table. You can move, or remove it, as needed.
this.resourcesTableAdapter.Fill(this.gantTestDataSet.Resources);
// TODO: This line of code loads data into the 'gantTestDataSet.Appointments' table. You can move, or remove it, as needed.
this.appointmentsTableAdapter.Fill(this.gantTestDataSet.Appointments);
this.appointmentsTableAdapter.Adapter.RowUpdated += new SqlRowUpdatedEventHandler(appointmentsTableAdapter_RowUpdated);
#region #Adjustment
schedulerControl1.ActiveViewType = SchedulerViewType.Gantt;
schedulerControl1.GroupType = SchedulerGroupType.Resource;
schedulerControl1.GanttView.CellsAutoHeightOptions.Enabled = true;
// Hide unnecessary visual elements.
schedulerControl1.GanttView.ShowResourceHeaders = false;
schedulerControl1.GanttView.NavigationButtonVisibility = NavigationButtonVisibility.Never;
// Disable user sorting in the Resource Tree (clicking the column will not change the sort order).
colDescription.OptionsColumn.AllowSort = false;
#endregion #Adjustment
}
#region #Appointment
private void schedulerDataStorage1_AppointmentsChanged(object sender, PersistentObjectsEventArgs e) {
CommitTask();
}
private void schedulerDataStorage1_AppointmentsDeleted(object sender, PersistentObjectsEventArgs e) {
CommitTask();
}
private void schedulerDataStorage1_AppointmentsInserted(object sender, PersistentObjectsEventArgs e) {
CommitTask();
schedulerDataStorage1.SetAppointmentId(((Appointment)e.Objects[0]), id);
}
void CommitTask() {
appointmentsTableAdapter.Update(gantTestDataSet);
this.gantTestDataSet.AcceptChanges();
}
#endregion #Appointment
#region #TaskDependencies
private void schedulerDataStorage1_AppointmentDependenciesChanged(object sender, PersistentObjectsEventArgs e) {
CommitTaskDependency();
}
private void schedulerDataStorage1_AppointmentDependenciesDeleted(object sender, PersistentObjectsEventArgs e) {
CommitTaskDependency();
}
private void schedulerDataStorage1_AppointmentDependenciesInserted(object sender, PersistentObjectsEventArgs e) {
CommitTaskDependency();
}
void CommitTaskDependency() {
taskDependenciesTableAdapter.Update(this.gantTestDataSet);
this.gantTestDataSet.AcceptChanges();
}
#endregion #TaskDependencies
#region #RowUpdatedHandlers
int id = 0;
private void appointmentsTableAdapter_RowUpdated(object sender, SqlRowUpdatedEventArgs e) {
if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) {
id = 0;
using (SqlCommand cmd = new SqlCommand("SELECT @@IDENTITY", appointmentsTableAdapter.Connection)) {
id = Convert.ToInt32(cmd.ExecuteScalar());
e.Row["UniqueId"] = id;
}
}
}
#endregion #RowUpdatedHandlers
private void schedulerControl1_ActiveViewChanged(object sender, EventArgs e) {
this.splitContainerControl1.SplitterPositionChanged -= new System.EventHandler(this.splitContainerControl1_SplitterPositionChanged);
bool isGanttView = schedulerControl1.ActiveViewType == SchedulerViewType.Gantt;
try {
splitContainerControl1.SplitterPosition = (isGanttView) ? LastSplitContainerControlSplitterPosition : 0;
}
finally {
this.splitContainerControl1.SplitterPositionChanged += new System.EventHandler(this.splitContainerControl1_SplitterPositionChanged);
}
}
private void splitContainerControl1_SplitterPositionChanged(object sender, EventArgs e) {
LastSplitContainerControlSplitterPosition = splitContainerControl1.SplitterPosition;
}
}
}