Procházet zdrojové kódy

Fix to documents not being attached on the data entry grid; also fixed validation bug.

Kenric Nugteren před 5 měsíci
rodič
revize
f66357a718

+ 24 - 9
prs.desktop/Panels/DataEntry/DataEntryPanel.xaml.cs

@@ -39,8 +39,13 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
     private IDynamicDataGrid? _grid;
     
     private Type? _selectedType;
+
+    // The id of the entity currently being edited.
     private Guid _entityID;
+    // The id of the entity we selected from the grid, as it was when we selected it; this is to cancel, because the lookup for the item
+    // updates _entityID, and we need to set it back when cancelling.
     private Guid _originalID;
+
     private bool _processenabled;
 
     private Entity? _entity;
@@ -56,10 +61,10 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
             if(_isChanged != value)
             {
                 _isChanged = value;
-                Editor.HideButtons = !value;// (_entity?.IsChanged() != true) && (_originalID == _entityID);
+                Editor.HideButtons = !value;
                 if (_process != null)
-                    _process.IsEnabled = value;// ((_entity?.ID ?? Guid.Empty) != Guid.Empty) || (_entity?.IsChanged() != false);
-                _documents._dataEntryGrid.IsEnabled = !value;// (_entity?.IsChanged() != true) && (_originalID == _entityID);
+                    _process.IsEnabled = value;
+                _documents._dataEntryGrid.IsEnabled = !value;
             }
         }
     }
@@ -73,12 +78,10 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
 
         if (_selectedType != null)
         {
-            ClearEditor();
             CreateEditor();
             PopulateEditor();
             //LoadPopup();
         }
-            
     }
     
     private void ScanPanel_OnSelectScan(string appliesto, Guid entityid, bool processenabled)
@@ -174,6 +177,11 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
         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)
         {
+            if (!Editor.Validate())
+            {
+                cancel.Cancel = true;
+                return;
+            }
             DoSave(false);
             if (!cancel.Cancel)
                 MessageBox.Show("Item saved.");
@@ -249,7 +257,7 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
         Editor.OnCancel += () =>
         {
             _entityID = _originalID;
-            Select(_selectedType,_entityID);
+            Select(_selectedType, _entityID);
         };
         Editor.OnChanged += (sender, args) => IsChanged = true;
         
@@ -340,7 +348,7 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
         }
 
         var doc = (IEntityDocument)Activator.CreateInstance(doctype)!;
-        CoreUtils.SetPropertyValue(doc,"EntityLink.ID",_entityID);
+        CoreUtils.SetPropertyValue(doc, "EntityLink.ID", _entityID);
         doc.DocumentLink.ID = dataEntryDocument.Document.ID;
         doc.Thumbnail = dataEntryDocument.Thumbnail;
         ClientFactory.CreateClient(doctype).Save(doc,"Added from Data Entry Screen");
@@ -352,11 +360,12 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
         var cancel = new System.ComponentModel.CancelEventArgs();
         if (markasprocessed && (_entity is IDataEntryInstance scannable))
             scannable.DataEntered = DateTime.Now;
-        Editor.SaveItem(cancel);
+        Editor.SaveItem(cancel, validate: false);
 
         if (!cancel.Cancel)
         {
             _originalID = _entityID;
+            _entityID = _entity.ID;
             IsChanged = false;
             var row = _documents._dataEntryGrid.SelectedRows.FirstOrDefault();
             if (row != null)
@@ -410,7 +419,13 @@ public partial class DataEntryPanel : UserControl, IBasePanel, IDynamicEditorHos
             Padding = new Thickness(10, 0, 10, 0),
             IsEnabled = _processenabled
         };
-        _process.Click += (sender, args) => DoSave(true);
+        _process.Click += (sender, args) =>
+        {
+            if (Editor.Validate())
+            {
+                DoSave(true);
+            }
+        };
         Editor.AddButton(_process);
         IsChanged = false;
 

+ 1 - 1
prs.desktop/Panels/PurchaseOrders/SupplierPurchaseOrderPanel.xaml.cs

@@ -256,7 +256,7 @@ public partial class SupplierPurchaseOrderPanel : UserControl, IPanel<PurchaseOr
             var rows = Orders.SelectedRows;
 
             var cancel = new System.ComponentModel.CancelEventArgs();
-            PurchaseOrder.SaveItem(cancel);
+            PurchaseOrder.SaveItem(cancel, validate: false);
 
             if (!cancel.Cancel)
             {

+ 1 - 1
prs.desktop/Panels/Reservation Management/Purchasing/ReservationManagementPurchasing.xaml.cs

@@ -149,7 +149,7 @@ public partial class ReservationManagementPurchasing : UserControl
         Editor.OnOK += () =>
         {
             var cancel = new System.ComponentModel.CancelEventArgs();
-            Editor.SaveItem(cancel);
+            Editor.SaveItem(cancel, validate: false);
             Editor.HideButtons = true;
 
             SaveJRIPOIs();

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

@@ -282,7 +282,7 @@ public partial class SupplierBillPanel : UserControl, IPanel<Bill>, IPropertiesP
             SaveApproval();
 
             var cancel = new System.ComponentModel.CancelEventArgs();
-            Bill.SaveItem(cancel);
+            Bill.SaveItem(cancel, validate: false);
             if (!cancel.Cancel)
             {
                 if(_editRows is not null && _bills is not null)