Ver Fonte

Brought report visibility logic into consistency and some cleanup and commenting.
Fix to DateTime editor bug.

Kenric Nugteren há 1 ano atrás
pai
commit
55491b6b78

+ 5 - 0
InABox.Core/Column.cs

@@ -44,6 +44,7 @@ namespace InABox.Core
 
         public bool IsEqualTo(string name) => 
             !string.IsNullOrWhiteSpace(name) && string.Equals(Property, name);
+        public bool IsEqualTo(Column<T> column) => string.Equals(Property, column.Property);
 
         public bool IsParentOf(string name) =>
             !string.IsNullOrWhiteSpace(name) && name.StartsWith(Property + ".");
@@ -257,6 +258,10 @@ namespace InABox.Core
 
         public bool Any() => columns.Any();
 
+        public bool Contains(string column) => Items.Any(x => x.IsEqualTo(column));
+
+        public bool Contains(Column<T> column) => Items.Any(x => x.IsEqualTo(column));
+
         public IColumns Add(string column)
         {
             if(CoreUtils.TryGetProperty(typeof(T), column, out var propertyInfo))

+ 11 - 0
inabox.wpf/DynamicGrid/DynamicEditorPage.cs

@@ -24,8 +24,19 @@ public interface IDynamicEditorPage
 
     void Load(object item, Func<Type, CoreTable?>? PageDataHandler);
 
+    /// <summary>
+    /// Called when the "OK" button is clicked on an editor, and before the item is saved.
+    /// </summary>
+    /// <param name="item"></param>
     void BeforeSave(object item);
 
+    /// <summary>
+    /// Called when the "OK" button is clicked on an editor, and after the item is saved.
+    /// </summary>
+    /// <remarks>
+    /// Generally used to save any child entities that need to be saved, since now the parent has a valid <see cref="Entity.ID"/>.
+    /// </remarks>
+    /// <param name="item"></param>
     void AfterSave(object item);
 
     event EventHandler OnChanged;

+ 73 - 60
inabox.wpf/DynamicGrid/DynamicOneToManyGrid.cs

@@ -28,7 +28,6 @@ namespace InABox.DynamicGrid
         private TMany[] MasterList = Array.Empty<TMany>();
         private readonly PropertyInfo property;
 
-        public PageType PageType => PageType.Other;
 
         protected DynamicGridCustomColumnsComponent<TMany> ColumnsComponent;
 
@@ -68,42 +67,46 @@ namespace InABox.DynamicGrid
             options.EndUpdate();
         }
 
-        private bool _readOnly;
-        public bool ReadOnly
-        {
-            get => _readOnly;
-            set
-            {
-                if(_readOnly != value)
-                {
-                    _readOnly = value;
-                    Reconfigure();
-                }
-            }
-        }
-
         private static bool IsAutoEntity => typeof(TMany).HasAttribute<AutoEntity>();
 
         protected Filters<TMany> Criteria { get; } = new Filters<TMany>();
 
         public TOne Item { get; protected set; }
 
-        public bool Ready { get; set; }
+        public List<TMany> Items { get; private set; }
 
-        public DynamicEditorGrid EditorGrid { get; set; }
+        public void LoadItems(TMany[] items)
+        {
+            Items.Clear();
+            Items.AddRange(items);
+            Refresh(false, true);
+        }
 
-        public string Caption()
+        private static string GetTag()
         {
-            var caption = typeof(TMany).GetCustomAttribute(typeof(Caption));
-            if (caption != null)
-                return ((Caption)caption).Text;
-            var result = new Inflector.Inflector(new CultureInfo("en")).Pluralize(typeof(TMany).Name);
-            return result;
+            return typeof(TOne).Name + "." + typeof(TMany).Name;
         }
 
-        public virtual int Order()
+        #region IDynamicEditorPage
+
+        public DynamicEditorGrid EditorGrid { get; set; }
+
+        public PageType PageType => PageType.Other;
+
+        public bool Ready { get; set; }
+
+        private bool _readOnly;
+        public bool ReadOnly
         {
-            return int.MinValue;
+            get => _readOnly;
+            set
+            {
+                if (_readOnly != value)
+                {
+                    _readOnly = value;
+                    Reconfigure();
+                }
+            }
         }
 
         public virtual void Load(object item, Func<Type, CoreTable?>? PageDataHandler)
@@ -111,7 +114,9 @@ namespace InABox.DynamicGrid
             Reconfigure();
 
             Item = (TOne)item;
-            
+
+            Refresh(true, false);
+
             var data = PageDataHandler?.Invoke(typeof(TMany));
 
             if (data == null)
@@ -128,14 +133,14 @@ namespace InABox.DynamicGrid
                     criteria.Add(new Filter<TMany>(exp).IsEqualTo(Item.ID).And(exp).IsNotEqualTo(Guid.Empty));
                     criteria.AddRange(Criteria.Items);
                     var sort = LookupFactory.DefineSort<TMany>();
-                    data = new Client<TMany>().Query(criteria.Combine(), null, sort);
+                    data = new Client<TMany>().Query(criteria.Combine(), DynamicGridUtils.LoadEditorColumns(DataColumns()), sort);
                 }
             }
 
             MasterList = data.Rows.Select(x => x.ToObject<TMany>()).ToArray();
 
             Items = MasterList.ToList();
-            Refresh(true, true);
+            Refresh(false, true);
             Ready = true;
         }
 
@@ -144,16 +149,7 @@ namespace InABox.DynamicGrid
             // Don't need to do anything here
         }
 
-        protected virtual void OnDeleteItem(TMany item)
-        {
-            if (IsAutoEntity)
-            {
-                return;
-            }
-            new Client<TMany>().Delete(item, typeof(TMany).Name + " Deleted by User");
-        }
-
-        public void AfterSave(object item)
+        public virtual void AfterSave(object item)
         {
             if (IsAutoEntity)
             {
@@ -174,6 +170,39 @@ namespace InABox.DynamicGrid
             new Client<TMany>().Save(Items.Where(x => x.IsChanged()), "Updated by User");
         }
 
+        public Size MinimumSize()
+        {
+            return new Size(400, 400);
+        }
+
+        public string Caption()
+        {
+            var caption = typeof(TMany).GetCustomAttribute(typeof(Caption));
+            if (caption != null)
+                return ((Caption)caption).Text;
+            var result = new Inflector.Inflector(new CultureInfo("en")).Pluralize(typeof(TMany).Name);
+            return result;
+        }
+
+        public virtual int Order()
+        {
+            return int.MinValue;
+        }
+
+        #endregion
+
+        #region DynamicGrid
+
+        protected virtual void OnDeleteItem(TMany item)
+        {
+            if (IsAutoEntity)
+            {
+                return;
+            }
+            new Client<TMany>().Delete(item, typeof(TMany).Name + " Deleted by User");
+        }
+
+
         protected override CoreTable LoadImportKeys(string[] fields)
         {
             var result = base.LoadImportKeys(fields);
@@ -193,25 +222,6 @@ namespace InABox.DynamicGrid
 
             return result;
         }
-
-        public Size MinimumSize()
-        {
-            return new Size(400, 400);
-        }
-
-        public List<TMany> Items { get; private set; }
-
-        public void LoadItems(TMany[] items)
-        {
-            Items.Clear();
-            Items.AddRange(items);
-            Refresh(false, true);
-        }
-        private static string GetTag()
-        {
-            return typeof(TOne).Name + "." + typeof(TMany).Name;
-        }
-
         public override DynamicGridColumns GenerateColumns()
         {
             var cols = new DynamicGridColumns();
@@ -282,7 +292,7 @@ namespace InABox.DynamicGrid
         protected override void DeleteItems(params CoreRow[] rows)
         {
             var items = rows.Select(LoadItem).ToList();
-            foreach(var item in items)
+            foreach (var item in items)
             {
                 Items.Remove(item);
             }
@@ -342,14 +352,17 @@ namespace InABox.DynamicGrid
 
         protected override bool BeforePaste(IEnumerable<TMany> items, ClipAction action)
         {
-            if(action == ClipAction.Copy)
+            if (action == ClipAction.Copy)
             {
-                foreach(var item in items)
+                foreach (var item in items)
                 {
                     item.ID = Guid.Empty;
                 }
             }
             return base.BeforePaste(items, action);
         }
+
+        #endregion
+
     }
 }

+ 2 - 0
inabox.wpf/DynamicGrid/DynamicSplitPanel.cs

@@ -220,7 +220,9 @@ namespace InABox.DynamicGrid
             Changed();
         }
 
+        public bool IsMasterVisible() => View == DynamicSplitPanelView.Master || View == DynamicSplitPanelView.Combined;
 
+        public bool IsDetailVisible() => View == DynamicSplitPanelView.Detail || View == DynamicSplitPanelView.Combined;
 
         private void ConfigureScreen()
         {

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

@@ -88,7 +88,6 @@ namespace InABox.DynamicGrid
                     result = Editor.Value.Value;
             }
 
-            result = new DateTime(result.Year, result.Month, result.Day, result.Hour, result.Minute, 0, result.Kind);
             return result;
         }
 

+ 21 - 20
inabox.wpf/Reports/ReportUtils.cs

@@ -290,45 +290,46 @@ namespace InABox.Wpf.Reports
         public static Filter<ReportTemplate> GetReportFilter(string sectionName, DataModel model)
         {
             return new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
-                    .And(x => x.Section).IsEqualTo(sectionName);
+                    .And(x => x.Section).IsEqualTo(sectionName)
+                    .And(x => x.Visible).IsEqualTo(true);
         }
 
-        public static IEnumerable<ReportTemplate> LoadReports(string sectionName, DataModel model)
+        public static IEnumerable<ReportTemplate> LoadReports(string sectionName, DataModel model, Columns<ReportTemplate>? columns = null)
         {
             return new Client<ReportTemplate>().Query(
                 GetReportFilter(sectionName, model),
-                null,
-                new SortOrder<ReportTemplate>(x => x.Name)).Rows.Select(x => x.ToObject<ReportTemplate>());
+                columns,
+                new SortOrder<ReportTemplate>(x => x.Name))
+                .ToObjects<ReportTemplate>();
         }
 
         private static void PopulateMenu(ItemsControl menu, string sectionName, DataModel model, bool allowdesign, bool populate = false)
         {
-            var reports = new Client<ReportTemplate>().Query(
-                new Filter<ReportTemplate>(x => x.DataModel).IsEqualTo(model.Name)
-                    .And(x => x.Section).IsEqualTo(sectionName),
-                null,
-                new SortOrder<ReportTemplate>(x => x.Name)
-            );
-            foreach (var row in reports.Rows)
+            var reports = LoadReports(sectionName, model);
+            foreach (var report in reports)
             {
-                var print = new MenuItem();
-                print.Header = row.Get<ReportTemplate, string>(x => x.Name);
-                print.Tag = row.ToObject<ReportTemplate>();
+                var print = new MenuItem
+                {
+                    Header = report.Name,
+                    Tag = report
+                };
                 print.Click += (sender, args) =>
                 {
-                    var template = (sender as MenuItem)!.Tag as ReportTemplate;
-                    if (template != null)
-                        PreviewReport(template, model, false, allowdesign);
+                    PreviewReport(report, model, false, allowdesign);
                 };
                 menu.Items.Add(print);
             }
 
             if (allowdesign)
             {
-                if (reports.Rows.Any())
+                if (menu.Items.Count > 0 && menu.Items[^1] is not Separator)
+                {
                     menu.Items.Add(new Separator());
-                var manage = new MenuItem();
-                manage.Header = "Manage Reports";
+                }
+                var manage = new MenuItem
+                {
+                    Header = "Manage Reports"
+                };
                 manage.Click += (sender, args) =>
                 {
                     var manager = new ReportManager()