Ver Fonte

Added Currency Symbol to CurrencyEditor, and fixed Digits/Width Handling for other editors

frogsoftware há 1 ano atrás
pai
commit
fb80ee55cc

+ 6 - 6
InABox.Core/Editors/CurrencyEditor.cs

@@ -13,17 +13,17 @@
             
         }
         
-        public new int Digits
-        { 
-            get => base.Digits;
-            set => base.Digits = value;
-        }
+        public string CurrencySymbol { get; set; }
         
         public EditorButton[]? Buttons { get; set; }
 
         protected override BaseEditor DoClone()
         {
-            return new CurrencyEditor(Digits) { Buttons = Buttons };
+            return new CurrencyEditor(Digits)
+            {
+                Buttons = Buttons, 
+                CurrencySymbol = CurrencySymbol
+            };
         }
 
 

+ 2 - 8
InABox.Core/Editors/DoubleEditor.cs

@@ -2,7 +2,7 @@
 {
     public class DoubleEditor : NumericEditor
     {
-        public DoubleEditor(int digits) : base(2)
+        public DoubleEditor(int digits) : base(digits)
         {
             Format = $"F{digits}";
         }
@@ -11,13 +11,7 @@
         {
             
         }
-
-        public new int Digits
-        { 
-            get => base.Digits;
-            set => base.Digits = value;
-        }
-
+        
         protected override BaseEditor DoClone()
         {
             return new DoubleEditor(Digits);

+ 3 - 1
InABox.Core/Editors/NumericEditor.cs

@@ -10,6 +10,8 @@ namespace InABox.Core
             Digits = digits;
         }
 
-        public int Digits { get; protected set; }
+        public virtual int Digits { get; set; }
+        
+        
     }
 }

+ 2 - 0
inabox.wpf/DynamicGrid/Columns/EditorColumns/DynamicGridCurrencyColumn.cs

@@ -13,6 +13,7 @@ public class DynamicGridCurrencyColumn<TEntity> : DynamicGridNumericColumn<TEnti
     protected override void Configure(GridCurrencyColumn column, CurrencyEditor editor)
     {
         column.CurrencyDecimalDigits = GetDigits(editor);
+        column.CurrencySymbol = string.IsNullOrEmpty(editor.CurrencySymbol) ? "$" : $"{editor.CurrencySymbol} ";
         column.CurrencyGroupSeparator = ",";
         column.CurrencyGroupSizes = new Int32Collection(new[] { 3, 3, 3, 3, 3, 3 });
     }
@@ -20,6 +21,7 @@ public class DynamicGridCurrencyColumn<TEntity> : DynamicGridNumericColumn<TEnti
     protected override void Configure(TreeGridCurrencyColumn column, CurrencyEditor editor)
     {
         column.CurrencyDecimalDigits = GetDigits(editor);
+        column.CurrencySymbol = string.IsNullOrEmpty(editor.CurrencySymbol) ? "$" : $"{editor.CurrencySymbol} ";
         column.CurrencyGroupSeparator = ",";
         column.CurrencyGroupSizes = new Int32Collection(new[] { 3, 3, 3, 3, 3, 3 });
     }

+ 30 - 3
inabox.wpf/DynamicGrid/Editors/CurrencyEditor/CurrencyEditorControl.cs

@@ -16,7 +16,22 @@ namespace InABox.DynamicGrid
             //DynamicEditorControlFactory.Register<CurrencyEditorControl, CurrencyEditor>();
         }
         
-        private CurrencyTextBox Editor;
+        private CurrencyTextBox? Editor;
+        
+        private String _currencySymbol = "";
+
+        public String CurrencySymbol
+        {
+            get => _currencySymbol;
+            set
+            {
+                _currencySymbol = value;
+                if (Editor != null) 
+                    Editor.CurrencySymbol = String.IsNullOrEmpty(value)
+                        ? "$" : 
+                        $"{value} ";
+            }
+        }
 
         public CurrencyEditorControl()
         {
@@ -47,7 +62,7 @@ namespace InABox.DynamicGrid
                 VerticalAlignment = VerticalAlignment.Stretch,
                 VerticalContentAlignment = VerticalAlignment.Center,
                 HorizontalContentAlignment = HorizontalAlignment.Center,
-                CurrencyDecimalDigits = (EditorDefinition as CurrencyEditor).Digits
+                CurrencyDecimalDigits = EditorDefinition.Digits
             };
             Editor.ValueChanged += (o, e) => { CheckChanged(); };
             Editor.SetValue(DockPanel.DockProperty, Dock.Left);
@@ -58,6 +73,10 @@ namespace InABox.DynamicGrid
                 Editor.IsEnabled = false;
             }
 
+            Editor.CurrencySymbol = String.IsNullOrEmpty(EditorDefinition.CurrencySymbol)
+                ? "$" : 
+                $"{EditorDefinition.CurrencySymbol} ";
+
             DockPanel.Children.Add(Editor);
 
 
@@ -86,7 +105,15 @@ namespace InABox.DynamicGrid
 
         protected override void UpdateValue(double value)
         {
-            Editor.Value = Convert.ToDecimal(value);
+            try
+            {
+                Editor.Value = Convert.ToDecimal(value);
+            }
+            catch (Exception e)
+            {
+                Editor.Value = 0m;
+            }
+            
         }
 
         public override void SetFocus()

+ 6 - 0
inabox.wpf/DynamicGrid/Editors/TextBoxEditor/TextBoxEditorControl.cs

@@ -26,6 +26,12 @@ public class TextBoxEditorControl : DynamicEditorControl<string, TextBoxEditor>
     {
         var dock = new DockPanel();
 
+        if (EditorDefinition.Width != 0)
+        {
+            dock.HorizontalAlignment = HorizontalAlignment.Left;
+            dock.Width = EditorDefinition.Width;
+        }
+
         var buttons = CreateButtons(out var DisableEditor);
         foreach (var button in buttons)
         {

+ 1 - 1
inabox.wpf/DynamicGrid/UIComponent/IDynamicGridUIComponent.cs

@@ -50,7 +50,7 @@ public interface IDynamicGridUIComponentParent<T> : IDynamicGrid<T>
 public interface IDynamicGridUIComponent<T>
     where T : BaseObject, new()
 {
-    IDynamicGridUIComponentParent<T> Parent { set; }
+    IDynamicGridUIComponentParent<T> Parent { get; set; }
 
     FrameworkElement Control { get; }