Jelajahi Sumber

Ensured that when refreshing direct edit panels, the user is prompted to save the item.

Kenric Nugteren 1 tahun lalu
induk
melakukan
313e7df708

+ 11 - 3
prs.desktop/Panels/DataEntry/DataEntryPanel.xaml.cs

@@ -90,7 +90,11 @@ namespace PRSDesktop
         
         public void Refresh()
         {
-            _documents.Refresh();
+            if (CheckSaved())
+            {
+                _documents.Refresh();
+                IsChanged = false;
+            }
         }
 
         public bool IsReady { get; set; }
@@ -131,10 +135,14 @@ namespace PRSDesktop
         
         private void CheckSaved(CancelEventArgs cancel)
         {
+            if (!_isChanged)
+            {
+                return;
+            }
             var result = MessageBox.Show("You have changes that have not been saved; do you wish to save these changes?", "Save Changes?", MessageBoxButton.YesNoCancel);
             if (result == MessageBoxResult.Yes)
             {
-                Editor.SaveItem(cancel);
+                DoSave(false);
                 if (!cancel.Cancel)
                     MessageBox.Show("Item saved.");
             }
@@ -152,7 +160,7 @@ namespace PRSDesktop
 
         public void Shutdown(CancelEventArgs? cancel)
         {
-            if (cancel != null && _isChanged)
+            if (cancel != null)
                 CheckSaved(cancel);
             if (cancel?.Cancel != true) 
                 _documents.Shutdown(cancel);

+ 5 - 1
prs.desktop/Panels/Products/Reservation Management/JobRequisitionsPanel.xaml.cs

@@ -233,6 +233,10 @@ namespace PRSDesktop
 
         private void CheckSaved(CancelEventArgs cancel)
         {
+            if (!purchasing.EditorChanged)
+            {
+                return;
+            }
             var result = MessageBox.Show("You have changes that have not been saved; do you wish to save these changes?", "Save Changes?", MessageBoxButton.YesNoCancel);
             if (result == MessageBoxResult.Yes)
             {
@@ -256,7 +260,7 @@ namespace PRSDesktop
 
         public void Shutdown(CancelEventArgs? cancel)
         {
-            if(purchasing.EditorChanged)
+            if(cancel is not null && purchasing.EditorChanged)
             {
                 CheckSaved(cancel);
             }

+ 2 - 2
prs.desktop/Panels/Requisitions/RequisitionItemHoldingGrid.cs

@@ -68,8 +68,8 @@ namespace PRSDesktop
             return row.ToObject<RequisitionItem>();
         }
 
-        protected override void Reload(Filters<RequisitionItem> criteria, Columns<RequisitionItem> columns, ref SortOrder<RequisitionItem> sort,
-            Action<CoreTable, Exception> action)
+        protected override void Reload(Filters<RequisitionItem> criteria, Columns<RequisitionItem> columns, ref SortOrder<RequisitionItem>? sort,
+            Action<CoreTable?, Exception?> action)
         {
             action?.Invoke(MasterData, null);
         }

+ 20 - 11
prs.desktop/Panels/Suppliers/Bills/SupplierBillPanel.xaml.cs

@@ -47,7 +47,11 @@ namespace PRSDesktop
 
         public void Refresh()
         {
-            Bills.Refresh(false, true);
+            if (CheckSaved())
+            {
+                Bills.Refresh(false, true);
+                SetChanged(true);
+            }
         }
 
         public void Setup()
@@ -58,6 +62,10 @@ namespace PRSDesktop
         
         private void CheckSaved(CancelEventArgs cancel)
         {
+            if (!bChanged)
+            {
+                return;
+            }
             var result = MessageBox.Show("You have an unsaved Supplier Bill; do you wish to save these changes?", "Save Changes?", MessageBoxButton.YesNoCancel);
             if (result == MessageBoxResult.Yes)
             {
@@ -81,7 +89,7 @@ namespace PRSDesktop
 
         public void Shutdown(CancelEventArgs? cancel)
         {
-            if(bChanged)
+            if(cancel is not null)
             {
                 CheckSaved(cancel);
             }
@@ -133,9 +141,7 @@ namespace PRSDesktop
                 if (!cancel.Cancel)
                 {
                     ReloadBills();
-                    Bills.IsEnabled = true;
-                    Bill.HideButtons = true;
-                    bChanged = false;
+                    SetChanged(false);
                 }
             }
         }
@@ -143,17 +149,20 @@ namespace PRSDesktop
         private void Bill_OnOnCancel()
         {
             ReloadBills();
-            Bills.IsEnabled = true;
-            Bill.HideButtons = true;
-            bChanged = false;
+            SetChanged(false);
+        }
+
+        private void SetChanged(bool changed)
+        {
+            bChanged = changed;
+            Bills.IsEnabled = !changed;
+            Bill.HideButtons = !changed;
         }
 
         private bool bChanged = false;
         private void Bill_OnOnChanged(object? sender, EventArgs e)
         {
-            Bills.IsEnabled = false;
-            Bill.HideButtons = false;
-            bChanged = true;
+            SetChanged(true);
         }
     }
 }

+ 20 - 11
prs.desktop/Panels/Suppliers/PurchaseOrders/SupplierPurchaseOrderPanel.xaml.cs

@@ -81,7 +81,11 @@ namespace PRSDesktop
 
         public void Refresh()
         {
-            Orders.Refresh(false, true);
+            if (CheckSaved())
+            {
+                Orders.Refresh(false, true);
+                SetChanged(false);
+            }
         }
 
         public void Setup()
@@ -124,6 +128,10 @@ namespace PRSDesktop
 
         private void CheckSaved(CancelEventArgs cancel)
         {
+            if(_orders is null || !_orders.Any(x => x.IsChanged()))
+            {
+                return;
+            }
             var result = MessageBox.Show("You have an unsaved Purchase Order; do you wish to save these changes?", "Save Changes?", MessageBoxButton.YesNoCancel);
             if (result == MessageBoxResult.Yes)
             {
@@ -147,7 +155,7 @@ namespace PRSDesktop
 
         public void Shutdown(CancelEventArgs? cancel)
         {
-            if(_orders is not null && cancel is not null && _orders.Any(x => x.IsChanged()))
+            if(cancel is not null)
             {
                 CheckSaved(cancel);
             }
@@ -248,6 +256,13 @@ namespace PRSDesktop
             }
         }
 
+        private void SetChanged(bool changed)
+        {
+            bChanged = changed;
+            Orders.IsEnabled = !changed;
+            PurchaseOrder.HideButtons = !changed;
+        }
+
         private void PurchaseOrder_OnOK()
         {
             using (new WaitCursor())
@@ -258,9 +273,7 @@ namespace PRSDesktop
                 if (!cancel.Cancel)
                 {
                     ReloadOrders();
-                    bChanged = false;
-                    Orders.IsEnabled = true;
-                    PurchaseOrder.HideButtons = true;
+                    SetChanged(false);
                 }
             }
         }
@@ -268,17 +281,13 @@ namespace PRSDesktop
         private void PurchaseOrder_OnCancel()
         {
             ReloadOrders();
-            bChanged = false;
-            Orders.IsEnabled = true;
-            PurchaseOrder.HideButtons = true;
+            SetChanged(false);
         }
 
         private bool bChanged = false;
         private void PurchaseOrder_OnOnChanged(object? sender, EventArgs e)
         {
-            Orders.IsEnabled = false;
-            PurchaseOrder.HideButtons = false;
-            bChanged = true;
+            SetChanged(true);
         }
     }
 }