Prechádzať zdrojové kódy

Improvements to ForeignCurrencyGrid

frogsoftware 1 rok pred
rodič
commit
fe94b38753

+ 2 - 1
prs.classes/Entities/ForeignCurrency/ForeignCurrency.cs

@@ -12,10 +12,11 @@ namespace Comal.Classes
         [EditorSequence(2)]
         public string Description { get; set; }
         
-        [TextBoxEditor]
+        [TextBoxEditor(Visible = Visible.Optional)]
         [EditorSequence(3)]
         public string Identifier { get; set; }
         
+        [Caption("Rate")]
         [DoubleEditor]
         [EditorSequence(4)]
         public double ExchangeRate { get; set; }

+ 17 - 2
prs.desktop/Grids/ForeignCurrencyGrid.cs

@@ -22,7 +22,7 @@ public class ForeignCurrencyGridSettings : BaseObject, IGlobalConfigurationSetti
     public string ApiKey { get; set; }
 
     [TextBoxEditor] 
-    [EditorSequence(1)] 
+    [EditorSequence(2)] 
     public string BaseCurrency { get; set; } = "AUD";
 }
 
@@ -66,6 +66,21 @@ public class ForeignCurrencyGrid : DynamicDataGrid<ForeignCurrency>
         new Client<ForeignCurrency>().Save(fc, string.Format("Set to {0} ", fc.Active ? "Active" : "InActive"));
         return true;
     }
+    
+    protected override BaseEditor? GetEditor(object item, DynamicGridColumn column)
+    {
+        BaseEditor? editor = null;
+        if (column.ColumnName.Equals(nameof(ForeignCurrency.Identifier)) && string.IsNullOrWhiteSpace(_settings.ApiKey))
+        {
+            editor = base.GetEditor(item, column)?.CloneEditor() ?? new NullEditor();
+            editor.Editable = Editable.Hidden;
+            editor.Visible = Visible.Hidden;
+        }
+        else
+            editor = base.GetEditor(item, column);
+
+        return editor;
+    }
 
 
     private bool UpdateExchangeRates(Button button, CoreRow[] rows)
@@ -112,7 +127,7 @@ public class ForeignCurrencyGrid : DynamicDataGrid<ForeignCurrency>
                             }
                         }
 
-                        foreach (var item in items.Where(x => x.Active))
+                        foreach (var item in items)
                             item.ExchangeRate =  foreign_usd / usd_aud;
                     }
                 }