Sfoglia il codice sorgente

Fixed Display Issues with DynamicGrid / DirectEdit

frogsoftware 1 anno fa
parent
commit
98b5020aaa
2 ha cambiato i file con 22 aggiunte e 15 eliminazioni
  1. 2 6
      InABox.Core/Entity.cs
  2. 20 9
      inabox.wpf/DynamicGrid/DynamicGrid.cs

+ 2 - 6
InABox.Core/Entity.cs

@@ -271,17 +271,13 @@ namespace InABox.Core
         
         private void CheckTax(string name, object? before, object? after)
         {
-            if (this is ITaxable)
+            if (this is ITaxable taxable && !bTaxing)
             {
-                if (bTaxing)
-                    return;
-
+                
                 bTaxing = true;
                 try
                 {
                     
-                    var taxable = this as ITaxable;
-
                     if (name.Equals("ExTax"))
                     {
                         taxable.Tax = (double)after * (taxable.TaxRate / 100.0F);

+ 20 - 9
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -963,6 +963,7 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
         foreach (var (key, value) in changes)
         {
             row[key] = value;
+            UIComponent.UpdateCell(row,key,value);
         }
 
         UIComponent.UpdateRow(row);
@@ -1455,7 +1456,20 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
 
         if (IsDirectEditMode() && !OpenEditorOnDirectEdit)
         {
-            var item = CreateItem();
+            CreateItems(null);
+        }
+        else if (AddEditClick(null))
+        {
+            Refresh(false, true);
+        }
+    }
+
+    protected void CreateItems(Func<IEnumerable<T>> create)
+    {
+        List<CoreRow> newrows = new List<CoreRow>();
+        var items = create?.Invoke() ?? new T[] { CreateItem() };
+        foreach (var item in items)
+        {
             if (!AfterCreate(item))
                 return;
             SaveItem(item);
@@ -1463,21 +1477,18 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
             var datarow = Data.NewRow();
             ObjectToRow(item, datarow);
             Data.Rows.Add(datarow);
+            newrows.Add(datarow);
 
             var masterrow = MasterData.NewRow();
             ObjectToRow(item, masterrow);
             MasterData.Rows.Add(masterrow);
 
             _recordmap[datarow] = masterrow;
-
-            InvalidateGrid();
-            SelectedRows = new[] { datarow };
-            OnChanged?.Invoke(this, EventArgs.Empty);
-        }
-        else if (AddEditClick(null))
-        {
-            Refresh(false, true);
         }
+
+        InvalidateGrid();
+        SelectedRows = newrows.ToArray();
+        OnChanged?.Invoke(this, EventArgs.Empty);
     }
 
     private void Add_Click(object sender, RoutedEventArgs e)