Parcourir la source

Added IEditorInformation to Editor Controls
Fixed Save Issue when Entity Contains ChildEntityLinks
Fixed Readonly problem with Desktop Digital Forms
Cleaned Up CodePopupEditor and DateTimEditor UI

frogsoftware il y a 11 mois
Parent
commit
1b088db3a8

+ 43 - 1
InABox.Core/Editors/BaseEditor.cs

@@ -1,4 +1,5 @@
 using System;
+using System.ComponentModel;
 using System.Linq;
 
 namespace InABox.Core
@@ -28,18 +29,42 @@ namespace InABox.Core
         Summary Summary { get; set; }
 
         SecurityAttribute[] Security { get; set; }
+        
+        Type? Information { get; set; }
 
         BaseEditor CloneEditor();
         public object Clone();
     }
 
+    public interface IEditorInformation
+    {
+        string Display(BaseObject[] items);
+    }
+    
+    public abstract class EditorInformation<T> : IEditorInformation where T : class
+    {
+
+        public abstract string GetInfo(T item);
+        
+        public string Display(BaseObject[] items)
+        {
+            var _results = items.OfType<T>().Select(GetInfo).ToArray();
+            return _results.Length == 0
+                ? ""
+                : _results.Length == 1
+                    ? _results[0]
+                    : "(Multiple Values)";
+            
+        }
+    }
+
     public abstract class BaseEditor : Attribute, IEnclosedEntity, ICloneable, IBaseEditor
     {
 
         private BaseObject _linkedParent;
 
         private string _linkedPath;
-
+        
         public void SetLinkedParent(BaseObject parent)
         {
             _linkedParent = parent;
@@ -105,6 +130,22 @@ namespace InABox.Core
         [NullEditor]
         public SecurityAttribute[] Security { get; set; }
 
+        private Type? _information;
+        public Type? Information
+        {
+            get => _information;
+            set
+            {
+                if (value?.GetInterfaces(typeof(IEditorInformation)) != null)
+                    _information = value;
+                else
+                {
+                    if (value != null)
+                        throw new Exception($"{value.EntityName()} does not implement IEditorInformation!");
+                }
+            }
+        }
+
         public BaseEditor CloneEditor()
         {
             var result = DoClone();
@@ -120,6 +161,7 @@ namespace InABox.Core
             result.Summary = Summary;
             result.ToolTip = ToolTip;
             result.Security = Security.Select(x => x.Clone()).ToArray();
+            result.Information = Information;
 
             return result;
         }

+ 4 - 0
inabox.database.sqlite/SQLiteProvider.cs

@@ -2307,6 +2307,10 @@ namespace InABox.Database.SQLite
                 if (insert[key] is UserProperties)
                     continue;
 
+                if (DatabaseSchema.Property(T,key)?.Parent?.GetAttribute<ChildEntityAttribute>() != null)
+                    continue;
+
+
                 var sParam = string.Format("@p{0}", iParam++);
                 object? value = null;
                 try

+ 1 - 1
inabox.wpf/DigitalForms/Designer/Controls/DynamicFormFieldControl.cs

@@ -90,7 +90,7 @@ namespace InABox.DynamicGrid
         protected override void AfterSetControl(TField control)
         {
             base.AfterSetControl(control);
-            if (!string.IsNullOrWhiteSpace(control.Properties.Expression) || control.Properties.ReadOnlyProperty)
+            if (!string.IsNullOrWhiteSpace(control.Properties.Expression) && control.Properties.ReadOnlyProperty)
             {
                 IsEnabled = false;
             }

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicEditorGrid.xaml.cs

@@ -285,7 +285,7 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
                     GeneralHeight += iHeight + 5.0F;
                 }
 
-                double iWidth = element.DesiredWidth();
+                double iWidth = element.EditorDefinition?.Information != null ? int.MaxValue : element.DesiredWidth();
                 if (iWidth == int.MaxValue)
                 {
                     element.HorizontalAlignment = HorizontalAlignment.Stretch;

+ 46 - 4
inabox.wpf/DynamicGrid/Editors/BaseDynamicEditorControl.cs

@@ -1,3 +1,4 @@
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Linq;
@@ -5,6 +6,7 @@ using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
 using InABox.Core;
+using RoslynPad.Editor;
 
 namespace InABox.DynamicGrid
 {
@@ -42,6 +44,8 @@ namespace InABox.DynamicGrid
             get => (string)GetValue(ColumnNameProperty);
             set => SetValue(ColumnNameProperty, value);
         }
+        
+        protected TextBox? Information { get; private set; }
 
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
         public IBaseEditor EditorDefinition
@@ -50,11 +54,44 @@ namespace InABox.DynamicGrid
             set
             {
                 _editordefinition = value;
-                Content = CreateEditor();
+                
+                if (_editordefinition.Information != null)
+                {
+                    DockPanel _dock = new DockPanel();
+                    var _editor = CreateEditor();
+                    _editor.SetValue(DockPanel.DockProperty, Dock.Left);
+                    _dock.Children.Add(_editor);
+                    Information = new TextBox()
+                    {
+                        VerticalAlignment = VerticalAlignment.Stretch,
+                        VerticalContentAlignment = VerticalAlignment.Center,
+                        HorizontalAlignment = HorizontalAlignment.Stretch,
+                        Margin = new Thickness(5, 0, 0, 0),
+                        IsReadOnly = true,
+                        Focusable = false,
+                        Background = new SolidColorBrush(Colors.WhiteSmoke),
+                        BorderBrush = new SolidColorBrush(Colors.Silver)
+                    };
+                    Information.SetValue(DockPanel.DockProperty, Dock.Left);
+                    _dock.Children.Add(Information);
+                    Content = _dock;
+                }
+                else
+                    Content = CreateEditor();
+
                 SetColor(Color);
             }
         }
 
+        protected void UpdateInformation()
+        {
+            if (EditorDefinition?.Information != null  && Information != null)
+            {
+                var _info = Activator.CreateInstance(EditorDefinition.Information) as IEditorInformation;
+                Information.Text = _info?.Display(Host.GetItems()) ?? "";
+            }
+        }
+
         [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
         public bool Loaded { get; set; }
 
@@ -72,8 +109,11 @@ namespace InABox.DynamicGrid
 
         public abstract void SetVisible(bool visible);
 
-        public abstract void SetValue(string property, object? value);
-
+        public virtual void SetValue(string property, object? value)
+        {
+            UpdateInformation();
+        }
+        
         /// <summary>
         /// 
         /// </summary>
@@ -145,8 +185,10 @@ namespace InABox.DynamicGrid
             }
             return buttons;
         }
+        
+        
     }
-
+    
     public abstract class BaseDynamicEditorControl<TEditor> : BaseDynamicEditorControl
         where TEditor : IBaseEditor
     {

+ 5 - 6
inabox.wpf/DynamicGrid/Editors/CodePopupEditor/CodePopupEditorControl.cs

@@ -34,8 +34,8 @@ public class CodePopupEditorControl : DynamicEditorControl<Guid, CodePopupEditor
             VerticalAlignment = VerticalAlignment.Stretch,
             HorizontalAlignment = HorizontalAlignment.Stretch
         };
-        Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(130, GridUnitType.Pixel) });
-        Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20, GridUnitType.Pixel) });
+        Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(131, GridUnitType.Pixel) });
+        Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(19, GridUnitType.Pixel) });
         Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
 
 
@@ -46,7 +46,7 @@ public class CodePopupEditorControl : DynamicEditorControl<Guid, CodePopupEditor
             VerticalContentAlignment = VerticalAlignment.Center,
             HorizontalAlignment = HorizontalAlignment.Stretch
         };
-        Editor.BorderThickness = new Thickness(0.75);
+        Editor.BorderThickness = new Thickness(1,1,0,1);
         Editor.BorderBrush = new SolidColorBrush(Colors.Silver);
         Editor.SetValue(Grid.ColumnProperty, 0);
         Editor.SetValue(Grid.RowProperty, 0);
@@ -65,8 +65,8 @@ public class CodePopupEditorControl : DynamicEditorControl<Guid, CodePopupEditor
             Content = "..",
             Focusable = false
         };
-        Select.BorderThickness = new Thickness(0, 0.75, 0.75, 0.75);
-        Select.BorderBrush = new SolidColorBrush(Colors.Gray);
+        Select.BorderThickness = new Thickness(1);
+        Select.BorderBrush = new SolidColorBrush(Colors.DimGray);
         Select.SetValue(Grid.ColumnProperty, 1);
         Select.SetValue(Grid.RowProperty, 0);
         Select.Click += Select_Click;
@@ -287,7 +287,6 @@ public class CodePopupEditorControl : DynamicEditorControl<Guid, CodePopupEditor
         _value = id;
         Editor.Text = code;
         
-
         Description.Text = LookupFactory.FormatLookup(_type, display, new[] { CodeColumn });
     }
 

+ 2 - 1
inabox.wpf/DynamicGrid/Editors/DateTimeEditor/DateTimeEditorControl.cs

@@ -38,7 +38,8 @@ namespace InABox.DynamicGrid
                 VerticalContentAlignment = VerticalAlignment.Center,
                 HorizontalContentAlignment = HorizontalAlignment.Center,
                 CalendarDisplayMode = CalendarMode.Month,
-                ShowButtonSpinner = false
+                ShowButtonSpinner = false,
+                Width=150
             };
 
             Editor.GotFocus += (o, e) => { new Timer(s => { Dispatcher.Invoke(() => { Editor.SelectAll(); }); }, Editor, 100, Timeout.Infinite); };

+ 4 - 1
inabox.wpf/DynamicGrid/Editors/DynamicEditorControl.cs

@@ -1,4 +1,5 @@
-using InABox.Core;
+using System;
+using InABox.Core;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Windows;
@@ -74,6 +75,7 @@ namespace InABox.DynamicGrid
                     Changed = true;
                     Updating = false;
                 }
+                UpdateInformation();
             }
 
             return Changed;
@@ -82,6 +84,7 @@ namespace InABox.DynamicGrid
         public override void SetValue(string property, object? value)
         {
             UpdateValue(value != null ? (T)value : default);
+            base.SetValue(property,value);
         }
 
         public override object? GetValue(string property)

+ 1 - 0
inabox.wpf/DynamicGrid/Editors/DynamicEnclosedEditorControl.cs

@@ -92,6 +92,7 @@ namespace InABox.DynamicGrid
             if (!property.StartsWith($"{ColumnName}.")) return;
             property = property[(ColumnName.Length + 1)..];
             SetChildValue(property, value);
+            base.SetValue(property,value);
         }
     }
 }