コード例 #1
0
        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);
        }
コード例 #2
0
            void EvalTransactionState()
            {
                var objectsToSave = TransactionalChangeHandler.ObjectsToSave(unitOfWork);

                saveChangesItem.Enabled        =
                    discardChangesItem.Enabled = objectsToSave;
            }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 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);
 }
コード例 #5
0
 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);
         }
     }
 }
コード例 #6
0
 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();
             }
         }
     }
 }
コード例 #7
0
 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;
         }
     }
 }
コード例 #8
0
 public void SaveChangesItemClickHandler(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     TransactionalChangeHandler.ValidateAndCommit(unitOfWork);
 }
コード例 #9
0
 private void CustomerList_Load(object sender, System.EventArgs e)
 {
     TransactionalChangeHandler.Hookup <Customer>(
         DocumentManager.FromControl(ParentForm).View, unitOfWork, saveChangesItem,
         discardChangesItem, customerCollection);
 }
コード例 #10
0
 private void EventView_Load(object sender, System.EventArgs e)
 {
     TransactionalChangeHandler.Hookup <Event>(
         DocumentManager.FromControl(ParentForm).View, unitOfWork, commitChangesItem,
         discardChangesItem, eventCollection);
 }