private bool ValidateAndCommit() { var checkables = TransactionalChangeHandler.GetCheckables(unitOfWork); if (TransactionalChangeHandler.Validate(checkables) == false) { return(false); } var relatedRooms = checkables. OfType <RoomBooking>(). Where(rb => rb.Room != null). Select(rb => rb.Room); var relatedRoomResults = DemoDatabase.BizRulezChecker.Check("save", relatedRooms).ToList(); if (relatedRoomResults.Count > 0) { XtraMessageBox.Show("There have been errors during data validation."); return(false); } unitOfWork.CommitChanges(); return(true); }
void EvalTransactionState() { var objectsToSave = TransactionalChangeHandler.ObjectsToSave(unitOfWork); saveChangesItem.Enabled = discardChangesItem.Enabled = objectsToSave; }
public void DiscardChanges(UnitOfWork unitOfWork, XPBaseCollection collection) { var deletedTLObjects = TransactionalChangeHandler.GetDeletedTLObjects <RoomBooking>(unitOfWork); foreach (var newObject in TransactionalChangeHandler.GetSavedNewObjects(unitOfWork)) { TransactionalChangeHandler.ResetAssociations(newObject); // special behavior for this form if (newObject is RoomBooking) { // remove the appointment from the collection, this doesn't // happen automatically var appt = schedulerStorage.Appointments.Items.Find( a => object.ReferenceEquals(a.GetRow(schedulerStorage), newObject)); schedulerStorage.Appointments.Remove(appt); } } unitOfWork.ReloadChangedObjects(); // special behavior: get the right collection first var roomBookingCollection = (IList <RoomBooking>)schedulerStorage.Appointments.DataSource; foreach (var item in deletedTLObjects) { roomBookingCollection.Add(item); } }
private void RoomBookingView_Load(object sender, System.EventArgs e) { TransactionalChangeHandler.Hookup <RoomBooking>( DocumentManager.FromControl(ParentForm).View, unitOfWork, saveChangesItem, discardChangesItem, null, null, null, null, null, null, RoomBookingView_Closing, saveChangesItem_ItemClick, discardChangesItem_ItemClick); }
public void DiscardChangesItemClickHandler(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (ObjectsToSave(unitOfWork)) { if (XtraMessageBox.Show("This operation is going to discard all unsaved changes. Are you sure you want to proceed?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { TransactionalChangeHandler.DiscardChanges <T>(unitOfWork, topLevelCollection); } } }
private void discardChangesItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (TransactionalChangeHandler.ObjectsToSave(unitOfWork)) { if (XtraMessageBox.Show("This operation is going to discard all unsaved changes. Are you sure you want to proceed?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //scheduler.BeginUpdate(); try { // Use my own DiscardChanges DiscardChanges(unitOfWork, null); } finally { //scheduler.EndUpdate(); } } } }
public void DocumentClosingHandler(object sender, DocumentCancelEventArgs e) { if (TransactionalChangeHandler.ObjectsToSave(unitOfWork)) { var answer = XtraMessageBox.Show("There are unsaved changes. Do you want to validate and save before closing the list?", "Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (answer == DialogResult.Yes) { if (!TransactionalChangeHandler.ValidateAndCommit(unitOfWork)) { e.Cancel = true; } } else if (answer == DialogResult.Cancel) { e.Cancel = true; } } }
public void SaveChangesItemClickHandler(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { TransactionalChangeHandler.ValidateAndCommit(unitOfWork); }
private void CustomerList_Load(object sender, System.EventArgs e) { TransactionalChangeHandler.Hookup <Customer>( DocumentManager.FromControl(ParentForm).View, unitOfWork, saveChangesItem, discardChangesItem, customerCollection); }
private void EventView_Load(object sender, System.EventArgs e) { TransactionalChangeHandler.Hookup <Event>( DocumentManager.FromControl(ParentForm).View, unitOfWork, commitChangesItem, discardChangesItem, eventCollection); }