Переглянути джерело

Fixed aggregate filter; added cell double click event handler for DynamicGrid

Kenric Nugteren 2 роки тому
батько
коміт
bdc9eb171a

+ 3 - 3
InABox.Core/Aggregate.cs

@@ -150,7 +150,7 @@ namespace InABox.Core
 
 
         public Dictionary<string, string> Links => GetLinks();
         public Dictionary<string, string> Links => GetLinks();
 
 
-        public object? Filter => GetFilter();
+        public IFilter? Filter => GetFilter();
 
 
         #region Internal (Reflection) functions
         #region Internal (Reflection) functions
 
 
@@ -230,7 +230,7 @@ namespace InABox.Core
             return AggregateCalculation.None;
             return AggregateCalculation.None;
         }
         }
 
 
-        private object? GetFilter()
+        private IFilter? GetFilter()
         {
         {
             var intf = Calculator.GetType().GetInterfaces()
             var intf = Calculator.GetType().GetInterfaces()
                 .FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICoreAggregate<,,>));
                 .FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICoreAggregate<,,>));
@@ -238,7 +238,7 @@ namespace InABox.Core
             {
             {
                 var prop = intf.GetProperty("Filter");
                 var prop = intf.GetProperty("Filter");
                 if (prop != null)
                 if (prop != null)
-                    return prop.GetValue(Calculator);
+                    return prop.GetValue(Calculator) as IFilter;
             }
             }
 
 
             return null;
             return null;

+ 2 - 1
InABox.Core/DatabaseSchema/DatabaseSchema.cs

@@ -155,7 +155,8 @@ namespace InABox.Core
                                 Page = page ?? "",
                                 Page = page ?? "",
                                 Required = required,
                                 Required = required,
                                 Loggable = loggable,
                                 Loggable = loggable,
-                                Parent = parent
+                                Parent = parent,
+                                Property = prop
                             };
                             };
 
 
                             if (prop.PropertyType.GetInterfaces().Contains(typeof(IEntityLink)) ||
                             if (prop.PropertyType.GetInterfaces().Contains(typeof(IEntityLink)) ||

+ 7 - 4
InABox.Core/Filter.cs

@@ -98,6 +98,7 @@ namespace InABox.Core
 
 
         public IFilter And(IFilter filter);
         public IFilter And(IFilter filter);
         public IFilter And<T>(Expression<Func<T,object>> expression);
         public IFilter And<T>(Expression<Func<T,object>> expression);
+        public IFilter And(string property);
 
 
         public IFilter Or(IFilter filter);
         public IFilter Or(IFilter filter);
         public IFilter Or<T>(Expression<Func<T,object>> expression);
         public IFilter Or<T>(Expression<Func<T,object>> expression);
@@ -244,7 +245,9 @@ namespace InABox.Core
                 return And(filterT);
                 return And(filterT);
             throw new Exception($"Cannot add filter of type {filter.GetType()} to Filter<{typeof(T)}>");
             throw new Exception($"Cannot add filter of type {filter.GetType()} to Filter<{typeof(T)}>");
         }
         }
-        
+
+        IFilter IFilter.And(string property) => And(property);
+
         public Filter<T> TextSearch(string terms, params Expression<Func<T, string>>[] expressions)
         public Filter<T> TextSearch(string terms, params Expression<Func<T, string>>[] expressions)
         {
         {
             //String[] comps = terms.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
             //String[] comps = terms.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
@@ -1090,9 +1093,9 @@ namespace InABox.Core
         }
         }
 
 
         #endregion
         #endregion
-        
-        
-        
+
+
+
     }
     }
 
 
     public class Filters<T> //where T : Entity
     public class Filters<T> //where T : Entity

+ 2 - 1
InABox.DynamicGrid/DynamicDataGrid.cs

@@ -697,6 +697,7 @@ namespace InABox.DynamicGrid
                         && x.IsSubclassOf(typeof(Entity))
                         && x.IsSubclassOf(typeof(Entity))
                         && !x.Equals(typeof(AuditTrail))
                         && !x.Equals(typeof(AuditTrail))
                         && !x.Equals(typeof(TEntity))
                         && !x.Equals(typeof(TEntity))
+                        && x.GetCustomAttribute<AutoEntity>() == null
                 ).ToArray();
                 ).ToArray();
 
 
                 foreach (var type in types)
                 foreach (var type in types)
@@ -736,7 +737,7 @@ namespace InABox.DynamicGrid
                 if (histories.Any())
                 if (histories.Any())
                     new Client<AuditTrail>().Save(histories, "");
                     new Client<AuditTrail>().Save(histories, "");
 
 
-                var deletes = new List<TEntity>();
+                var deletes = new List<object>();
                 foreach (var otherid in otherids)
                 foreach (var otherid in otherids)
                 {
                 {
                     var delete = new TEntity();
                     var delete = new TEntity();

+ 28 - 7
InABox.DynamicGrid/DynamicGrid.cs

@@ -22,6 +22,7 @@ using InABox.Clients;
 using InABox.Core;
 using InABox.Core;
 using InABox.Scripting;
 using InABox.Scripting;
 using InABox.WPF;
 using InABox.WPF;
+using NPOI.SS.Formula.Functions;
 using Syncfusion.Data;
 using Syncfusion.Data;
 using Syncfusion.UI.Xaml.Grid;
 using Syncfusion.UI.Xaml.Grid;
 using Syncfusion.UI.Xaml.Grid.Cells;
 using Syncfusion.UI.Xaml.Grid.Cells;
@@ -352,6 +353,8 @@ namespace InABox.DynamicGrid
 
 
         public event OnDoubleClick? OnDoubleClick;
         public event OnDoubleClick? OnDoubleClick;
 
 
+        public event OnCellDoubleClick? OnCellDoubleClick;
+
         public OnGridChanged? OnChanged;
         public OnGridChanged? OnChanged;
 
 
         public event EditorValueChangedHandler? OnEditorValueChanged;
         public event EditorValueChangedHandler? OnEditorValueChanged;
@@ -757,6 +760,17 @@ namespace InABox.DynamicGrid
                     { DisplayText = x, ActualValue = x, IsSelected = column.SelectedFilters == null || column.SelectedFilters.Contains(x) });
                     { DisplayText = x, ActualValue = x, IsSelected = column.SelectedFilters == null || column.SelectedFilters.Contains(x) });
         }
         }
 
 
+        private CoreRow? GetRowFromIndex(int rowIndex)
+        {
+            var row = rowIndex - (Options.Contains(DynamicGridOption.FilterRows) ? 2 : 1);
+            if (row < 0)
+                return null;
+            row = DataGridItems.Rows.IndexOf((DataGrid.View.Records[row].Data as DataRowView)!.Row);
+            if (row < 0)
+                return null;
+            return Data.Rows[row];
+        }
+
         private void DataGrid_CellToolTipOpening(object? sender, GridCellToolTipOpeningEventArgs e)
         private void DataGrid_CellToolTipOpening(object? sender, GridCellToolTipOpeningEventArgs e)
         {
         {
             if (ColumnList[e.RowColumnIndex.ColumnIndex] is not DynamicActionColumn col)
             if (ColumnList[e.RowColumnIndex.ColumnIndex] is not DynamicActionColumn col)
@@ -765,15 +779,12 @@ namespace InABox.DynamicGrid
             if (toolTip is null)
             if (toolTip is null)
                 return;
                 return;
 
 
-            var row = e.RowColumnIndex.RowIndex - (Options.Contains(DynamicGridOption.FilterRows) ? 2 : 1);
-            if (row < 0)
-                return;
-            row = DataGridItems.Rows.IndexOf((DataGrid.View.Records[row].Data as DataRowView)!.Row);
-            if (row < 0)
+            var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
+            if (row is null)
                 return;
                 return;
             e.ToolTip.Template = TemplateGenerator.CreateControlTemplate(
             e.ToolTip.Template = TemplateGenerator.CreateControlTemplate(
                 typeof(ToolTip),
                 typeof(ToolTip),
-                () => toolTip.Invoke(col, Data.Rows[row])
+                () => toolTip.Invoke(col, row)
             );
             );
         }
         }
 
 
@@ -1181,6 +1192,16 @@ namespace InABox.DynamicGrid
         private void DataGrid_CellDoubleTapped(object? sender, GridCellDoubleTappedEventArgs e)
         private void DataGrid_CellDoubleTapped(object? sender, GridCellDoubleTappedEventArgs e)
         {
         {
             StopTimer();
             StopTimer();
+
+            if(OnCellDoubleClick is not null && ColumnList[e.RowColumnIndex.ColumnIndex] is DynamicGridColumn column)
+            {
+                var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
+                var args = new DynamicGridCellClickEventArgs(row, column);
+                OnCellDoubleClick?.Invoke(this, args);
+                if (args.Handled)
+                    return;
+            }
+
             if (e.Record != null)
             if (e.Record != null)
                 DoDoubleClick(this);
                 DoDoubleClick(this);
         }
         }
@@ -1189,7 +1210,7 @@ namespace InABox.DynamicGrid
 
 
         #region Column Handling
         #region Column Handling
 
 
-        private readonly List<object> ColumnList = new();
+        private readonly List<DynamicColumnBase> ColumnList = new();
 
 
         protected virtual DynamicGridColumns LoadColumns()
         protected virtual DynamicGridColumns LoadColumns()
         {
         {

+ 15 - 0
InABox.DynamicGrid/DynamicGridCommon.cs

@@ -86,5 +86,20 @@ namespace InABox.DynamicGrid
 
 
     public delegate void OnDoubleClick(object sender, HandledEventArgs args);
     public delegate void OnDoubleClick(object sender, HandledEventArgs args);
 
 
+    public class DynamicGridCellClickEventArgs : HandledEventArgs
+    {
+        public CoreRow Row { get; set; }
+
+        public DynamicGridColumn Column { get; set; }
+
+        public DynamicGridCellClickEventArgs(CoreRow row, DynamicGridColumn column)
+        {
+            Row = row;
+            Column = column;
+        }
+    }
+
+    public delegate void OnCellDoubleClick(object sender, DynamicGridCellClickEventArgs args);
+
     public delegate void OnAfterReloadEventHandler(object sender);
     public delegate void OnAfterReloadEventHandler(object sender);
 }
 }

+ 3 - 1
inabox.database.sqlite/SQLiteProvider.cs

@@ -1648,7 +1648,9 @@ namespace InABox.Database.SQLite
                                 var filter = Activator.CreateInstance(typeof(Filter<>).MakeGenericType(linkedtype), "Deleted") as IFilter;
                                 var filter = Activator.CreateInstance(typeof(Filter<>).MakeGenericType(linkedtype), "Deleted") as IFilter;
                                 filter!.Operator = Operator.IsEqualTo;
                                 filter!.Operator = Operator.IsEqualTo;
                                 filter.Value = Guid.Empty;
                                 filter.Value = Guid.Empty;
-                                if(agg.Filter is IFilter aggFilter)
+
+                                var aggFilter = agg.Filter;
+                                if(aggFilter is not null)
                                 {
                                 {
                                     var filterfields = this.GetType().GetMethod("FilterFields").MakeGenericMethod(linkedtype);
                                     var filterfields = this.GetType().GetMethod("FilterFields").MakeGenericMethod(linkedtype);
                                     List<String> ffs = new List<string>();
                                     List<String> ffs = new List<string>();