From 59951a65410befe7aee6a191696f7d0bfb5f58a7 Mon Sep 17 00:00:00 2001 From: "CORP\\tochilkin.alexander" <13348208+AlexMedusa@users.noreply.github.com> Date: Tue, 24 Aug 2021 18:10:58 +0300 Subject: [PATCH] Updated the SchedulerStorage1_AppointmentChanging event --- CS/SimpleCustomFields/Form1.cs | 42 +++++++++++++--------------------- VB/SimpleCustomFields/Form1.vb | 25 +++++++++++--------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/CS/SimpleCustomFields/Form1.cs b/CS/SimpleCustomFields/Form1.cs index bb11ea7..e79ab46 100644 --- a/CS/SimpleCustomFields/Form1.cs +++ b/CS/SimpleCustomFields/Form1.cs @@ -10,12 +10,9 @@ using DevExpress.XtraScheduler; #endregion #usings -namespace SimpleCustomFields -{ - public partial class Form1 : Form - { - public Form1() - { +namespace SimpleCustomFields { + public partial class Form1 : Form { + public Form1() { InitializeComponent(); schedulerDataStorage1.AppointmentInserting += SchedulerStorage1_AppointmentInserting; @@ -27,8 +24,7 @@ public Form1() this.schedulerControl1.Start = new DateTime(2010, 07, 01); } - private void Form1_Load(object sender, EventArgs e) - { + private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'carsDBDataSet.Cars' table. You can move, or remove it, as needed. this.carsTableAdapter.Fill(this.carsDBDataSet.Cars); // TODO: This line of code loads data into the 'carsDBDataSet.CarScheduling' table. You can move, or remove it, as needed. @@ -37,44 +33,35 @@ private void Form1_Load(object sender, EventArgs e) } - private void OnApptChangedInsertedDeleted(object sender, PersistentObjectsEventArgs e) - { + private void OnApptChangedInsertedDeleted(object sender, PersistentObjectsEventArgs e) { carSchedulingTableAdapter.Update(carsDBDataSet); carsDBDataSet.AcceptChanges(); } - private void carSchedulingTableAdapter_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) - { - if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) - { + private void carSchedulingTableAdapter_RowUpdated(object sender, OleDbRowUpdatedEventArgs e) { + if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) { int id = 0; using (OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", - carSchedulingTableAdapter.Connection)) - { + carSchedulingTableAdapter.Connection)) { id = (int)cmd.ExecuteScalar(); } e.Row["ID"] = id; } } #region #EditAppointmentFormShowing - private void schedulerControl1_EditAppointmentFormShowing(object sender, AppointmentFormEventArgs e) - { + private void schedulerControl1_EditAppointmentFormShowing(object sender, AppointmentFormEventArgs e) { MyAppointmentForm form = new MyAppointmentForm(sender as SchedulerControl, e.Appointment, e.OpenRecurrenceForm); - try - { + try { e.DialogResult = form.ShowDialog(); e.Handled = true; - } - finally - { + } finally { form.Dispose(); } } #endregion #EditAppointmentFormShowing #region #InitNewAppointment - private void schedulerControl1_InitNewAppointment(object sender, DevExpress.XtraScheduler.AppointmentEventArgs e) - { + private void schedulerControl1_InitNewAppointment(object sender, DevExpress.XtraScheduler.AppointmentEventArgs e) { e.Appointment.Description += "Created at runtime at " + String.Format("{0:g}", DateTime.Now); e.Appointment.CustomFields["Amount"] = 00.01d; e.Appointment.CustomFields["ContactInfo"] = "someone@somecompany.com"; @@ -87,8 +74,11 @@ private void SchedulerStorage1_AppointmentInserting(object sender, PersistentObj #endregion #AppointmentInserting #region #AppointmentChanging private void SchedulerStorage1_AppointmentChanging(object sender, PersistentObjectCancelEventArgs e) { + if (((DevExpress.XtraScheduler.AdvPersistentObjectCancelEventArgs)e).PropertyName == "StatusKey") { + return; + } object busyKey = schedulerDataStorage1.Appointments.Statuses.GetByType(AppointmentStatusType.Busy).Id; - if (((Appointment)e.Object).StatusKey == busyKey) e.Cancel = true; + if (((Appointment)e.Object).StatusKey.Equals(busyKey)) e.Cancel = true; } #endregion #AppointmentChanging } diff --git a/VB/SimpleCustomFields/Form1.vb b/VB/SimpleCustomFields/Form1.vb index 487ee23..2d5a1b6 100644 --- a/VB/SimpleCustomFields/Form1.vb +++ b/VB/SimpleCustomFields/Form1.vb @@ -23,7 +23,7 @@ Namespace SimpleCustomFields AddHandler schedulerDataStorage1.AppointmentsChanged, AddressOf OnApptChangedInsertedDeleted AddHandler schedulerDataStorage1.AppointmentsDeleted, AddressOf OnApptChangedInsertedDeleted - Me.schedulerControl1.Start = New Date(2010, 07, 01) + Me.schedulerControl1.Start = New Date(2010, 7, 1) End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load @@ -49,7 +49,7 @@ Namespace SimpleCustomFields e.Row("ID") = id End If End Sub - #Region "#EditAppointmentFormShowing" +#Region "#EditAppointmentFormShowing" Private Sub schedulerControl1_EditAppointmentFormShowing(ByVal sender As Object, ByVal e As AppointmentFormEventArgs) Handles schedulerControl1.EditAppointmentFormShowing Dim form As New MyAppointmentForm(TryCast(sender, SchedulerControl), e.Appointment, e.OpenRecurrenceForm) Try @@ -59,29 +59,32 @@ Namespace SimpleCustomFields form.Dispose() End Try End Sub - #End Region ' #EditAppointmentFormShowing +#End Region ' #EditAppointmentFormShowing - #Region "#InitNewAppointment" +#Region "#InitNewAppointment" Private Sub schedulerControl1_InitNewAppointment(ByVal sender As Object, ByVal e As DevExpress.XtraScheduler.AppointmentEventArgs) Handles schedulerControl1.InitNewAppointment e.Appointment.Description &= "Created at runtime at " & String.Format("{0:g}", Date.Now) - e.Appointment.CustomFields("Amount") = 00.01R + e.Appointment.CustomFields("Amount") = 0.01R e.Appointment.CustomFields("ContactInfo") = "someone@somecompany.com" End Sub - #End Region ' #InitNewAppointment - #Region "#AppointmentInserting" +#End Region ' #InitNewAppointment +#Region "#AppointmentInserting" Private Sub SchedulerStorage1_AppointmentInserting(ByVal sender As Object, ByVal e As PersistentObjectCancelEventArgs) If CType(e.Object, Appointment).Start < Date.Now Then e.Cancel = True End If End Sub - #End Region ' #AppointmentInserting - #Region "#AppointmentChanging" +#End Region ' #AppointmentInserting +#Region "#AppointmentChanging" Private Sub SchedulerStorage1_AppointmentChanging(ByVal sender As Object, ByVal e As PersistentObjectCancelEventArgs) + If CType(e, DevExpress.XtraScheduler.AdvPersistentObjectCancelEventArgs).PropertyName = "StatusKey" Then + Return + End If Dim busyKey As Object = schedulerDataStorage1.Appointments.Statuses.GetByType(AppointmentStatusType.Busy).Id - If CType(e.Object, Appointment).StatusKey Is busyKey Then + If CType(e.Object, Appointment).StatusKey.Equals(busyKey) Then e.Cancel = True End If End Sub - #End Region ' #AppointmentChanging +#End Region ' #AppointmentChanging End Class End Namespace \ No newline at end of file