private void schedulerStorage1_AppointmentsChanged(object sender, PersistentObjectsEventArgs e) { try { Nested_CheckSecurityForChanging(); } catch (Exception ex) { ErrorHandler.Show(ex); return; } foreach (DevExpress.XtraScheduler.Appointment app in e.Objects) { // DevExpress.XtraScheduler.Appointment app = e.Objects[0] as DevExpress.XtraScheduler.Appointment; //imposto per sicurezza il campo allday a true; app.AllDay = true; Assignment a = app.GetSourceObject(schedulerStorage1) as Assignment; //se ho cambiato risorsa dal calendario e non dal form //(il form tiene i valori sincronizzati) recupero la risorsa e la setto if (a.ResourceId != a.Resource.Id) { BookingResourceHandler h1 = new BookingResourceHandler(); WIN.SCHEDULING_APPLICATION.DOMAIN.Booking.BookingResource res = h1.GetElementById(a.ResourceId.ToString()) as WIN.SCHEDULING_APPLICATION.DOMAIN.Booking.BookingResource; a.Resource = res; app.SetValue(schedulerStorage1, "Resource", res); } ////i save on my db AssignmentHandler h = new AssignmentHandler(); try { h.SaveOrUpdate(a); } catch (Exception ex) { WIN.SCHEDULING_APP.GUI.Utility.ErrorHandler.Show(ex); } } }
private void schedulerStorage1_AppointmentsInserted(object sender, DevExpress.XtraScheduler.PersistentObjectsEventArgs e) { ///////***************************** ///////***************************** //gets the newly created Devexpress appointment; Appointment app = e.Objects[0] as Appointment; //********************************************************* //questo codice è inserito per risolvere il problema dell'assegnazione della risorsa //dopo il grag drop DevExpress.XtraScheduler.Resource ee = app.ResourceId as DevExpress.XtraScheduler.Resource; //questa situazione si verifica quando lo scheduler non è stato in grado //di assegnare una risorsa all'appuntamento creato nella funzione GetDragData //e pertanto assegna la risorsa "All" all'appuntamento //if (ee != null) //{ // Customer ccc = app.GetValue(schedulerStorage1, "Customer") as Customer; // if (ccc != null) // { // app.SetValue(schedulerStorage1, "Resource", ccc.Resource); // app.ResourceId = ccc.Resource.Id; // } // else // { // WIN.SCHEDULING_APPLICATION.DOMAIN.ComboElements.Resource t = new ResourceHandler().GetAll()[0] as WIN.SCHEDULING_APPLICATION.DOMAIN.ComboElements.Resource; // app.SetValue(schedulerStorage1, "Resource", t); // app.ResourceId = t.Id; // } //} //else //{ app.SetValue(schedulerStorage1, "Resource", new BookingResourceHandler().GetElementById(app.ResourceId.ToString()) as WIN.SCHEDULING_APPLICATION.DOMAIN.Booking.BookingResource); //} //****************************************************************++ //imposto per sicurezza il campo allday a true; app.AllDay = true; ////i get my custom object Assignment a = app.GetSourceObject(schedulerStorage1) as Assignment; //i add the created assignment to the booking IBooking b = a.Booking; b.AddAssignment(a); ////i save on my db AssignmentHandler h = new AssignmentHandler(); try { h.SaveOrUpdate(a); } catch (Exception ex) { WIN.SCHEDULING_APP.GUI.Utility.ErrorHandler.Show(ex); return; } //notifico l'id all'oggetto appena creato Key newId = a.Key; app.SetValue(schedulerStorage1, "Key", newId); ///////***************************** ///////***************************** ///////***************************** ///////***************************** //Appointment app1 = app.Copy(); //app1.Start = DateTime.Now.AddHours(2); //schedulerStorage1.Appointments.Add(app1); //foreach (Appointment item in schedulerStorage1.Appointments.Items) //{ // MyAppointment a1 = app.GetSourceObject(schedulerStorage1) as MyAppointment; //} }