Selaa lähdekoodia

Added double-click to date editors to set todays date
Fixed Issues with Code Popup Editor
Added PopupEditor functionality to DynamicGrid Direct Editing
Added RPC to Serializer Protocol to use new Socket transports
Fixed occasional issues wit Tax calculations

frogsoftware 1 vuosi sitten
vanhempi
commit
8395fb5aa0

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

@@ -9,7 +9,8 @@ namespace InABox.Clients
 {
 {
     public enum SerializerProtocol
     public enum SerializerProtocol
     {
     {
-        Rest
+        Rest,
+        RPC
     }
     }
 
 
     public class QueryMultipleResults
     public class QueryMultipleResults

+ 11 - 2
InABox.Core/Entity.cs

@@ -248,6 +248,10 @@ namespace InABox.Core
                     return;
                     return;
 
 
                 bTaxing = true;
                 bTaxing = true;
+                try
+                {
+
+
 
 
                 var taxable = this as ITaxable;
                 var taxable = this as ITaxable;
 
 
@@ -273,8 +277,13 @@ namespace InABox.Core
                     taxable.ExTax = (double)after / ((100.0F + taxable.TaxRate) / 100.0F);
                     taxable.ExTax = (double)after / ((100.0F + taxable.TaxRate) / 100.0F);
                     taxable.Tax = (double)after - taxable.ExTax;
                     taxable.Tax = (double)after - taxable.ExTax;
                 }
                 }
-
-
+                
+                }
+                catch (Exception e)
+                {
+                    Logger.Send(LogType.Error, "", String.Join("\n",e.Message,e.StackTrace));
+                }
+                
                 bTaxing = false;
                 bTaxing = false;
             }
             }
         }
         }

+ 2 - 0
InABox.Core/LinkedProperties.cs

@@ -10,6 +10,8 @@ namespace InABox.Core
 
 
         private static readonly List<ILinkedProperty> _LinkedProperties = new List<ILinkedProperty>();
         private static readonly List<ILinkedProperty> _LinkedProperties = new List<ILinkedProperty>();
 
 
+        public static IEnumerable<ILinkedProperty> All => _LinkedProperties;
+        
         public static void Register<TLinkedEntity, TEntityLink, TType>(Expression<Func<TLinkedEntity,TEntityLink>> path, Expression<Func<TEntityLink, TType>> source,
         public static void Register<TLinkedEntity, TEntityLink, TType>(Expression<Func<TLinkedEntity,TEntityLink>> path, Expression<Func<TEntityLink, TType>> source,
             Expression<Func<TLinkedEntity, TType>> target)
             Expression<Func<TLinkedEntity, TType>> target)
         {
         {

+ 144 - 11
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -30,6 +30,7 @@ using Syncfusion.UI.Xaml.Grid.Helpers;
 using Syncfusion.Windows.Controls.Cells;
 using Syncfusion.Windows.Controls.Cells;
 using Syncfusion.Windows.Controls.Grid;
 using Syncfusion.Windows.Controls.Grid;
 using Syncfusion.Windows.Shared;
 using Syncfusion.Windows.Shared;
+using Syncfusion.Windows.Tools;
 using Syncfusion.Windows.Tools.Controls;
 using Syncfusion.Windows.Tools.Controls;
 using Syncfusion.XPS;
 using Syncfusion.XPS;
 using Brush = System.Windows.Media.Brush;
 using Brush = System.Windows.Media.Brush;
@@ -979,7 +980,7 @@ namespace InABox.DynamicGrid
             if (e.Column is GridCheckBoxColumn)
             if (e.Column is GridCheckBoxColumn)
                 inplaceeditor = LoadItem(Data.Rows[e.RowColumnIndex.RowIndex - headerrows]);
                 inplaceeditor = LoadItem(Data.Rows[e.RowColumnIndex.RowIndex - headerrows]);
             if (inplaceeditor is not null)
             if (inplaceeditor is not null)
-                UpdateData(inplaceeditor, e.RowColumnIndex.ColumnIndex);
+                UpdateData(inplaceeditor, DataGrid.Columns[e.RowColumnIndex.ColumnIndex].MappingName);
             if (e.Column is GridCheckBoxColumn)
             if (e.Column is GridCheckBoxColumn)
                 inplaceeditor = null;
                 inplaceeditor = null;
             if (inplaceeditor is not null)
             if (inplaceeditor is not null)
@@ -1016,30 +1017,32 @@ namespace InABox.DynamicGrid
             var headerrows = Options.Contains(DynamicGridOption.FilterRows) ? 2 : 1;
             var headerrows = Options.Contains(DynamicGridOption.FilterRows) ? 2 : 1;
             if (e.RowColumnIndex.RowIndex < headerrows)
             if (e.RowColumnIndex.RowIndex < headerrows)
                 return;
                 return;
-            if (inplaceeditor is not null && bChanged) UpdateData(inplaceeditor, e.RowColumnIndex.ColumnIndex);
+            if (inplaceeditor is not null && bChanged) 
+                UpdateData(inplaceeditor, DataGrid.Columns[e.RowColumnIndex.ColumnIndex].MappingName);
             bChanged = false;
             bChanged = false;
             inplaceeditor = null;
             inplaceeditor = null;
             DataGridItems?.AcceptChanges();
             DataGridItems?.AcceptChanges();
         }
         }
 
 
-        private void UpdateData(T obj, int columnindex)
+        private void UpdateData(T obj, String mappedname)
         {
         {
+            if (!SelectedRows.Any())
+                return;
             var table = DataGridItems;
             var table = DataGridItems;
-
+            
             var iRow = SelectedRows.First().Index; //e.RowColumnIndex.RowIndex - (Options.Contains(DynamicGridOptions.FilterRows) ? 2 : 1);
             var iRow = SelectedRows.First().Index; //e.RowColumnIndex.RowIndex - (Options.Contains(DynamicGridOptions.FilterRows) ? 2 : 1);
             if (table is null || iRow > table.Rows.Count)
             if (table is null || iRow > table.Rows.Count)
                 return;
                 return;
             var row = table.Rows[iRow];
             var row = table.Rows[iRow];
-            var colname = DataGrid.Columns[columnindex].MappingName;
-            var value = row[colname];
+            var value = row[mappedname];
 
 
-            var colno = table.Columns.IndexOf(colname);
+            var colno = table.Columns.IndexOf(mappedname);
             var corecol = Data.Columns[colno].ColumnName;
             var corecol = Data.Columns[colno].ColumnName;
             var corerow = Data.Rows[iRow];
             var corerow = Data.Rows[iRow];
             corerow[corecol] = value;
             corerow[corecol] = value;
 
 
             Dictionary<String, object> changes = new Dictionary<string, object>();
             Dictionary<String, object> changes = new Dictionary<string, object>();
-            if (DataGrid.Columns[colname] is GridComboBoxColumn combo)
+            if (DataGrid.Columns[mappedname] is GridComboBoxColumn combo)
             {
             {
 
 
                 var prefix = String.Join(".", corecol.Split(".").Reverse().Skip(1).Reverse());
                 var prefix = String.Join(".", corecol.Split(".").Reverse().Skip(1).Reverse());
@@ -1071,10 +1074,10 @@ namespace InABox.DynamicGrid
                 UpdateCell(iRow, key, changes[key]);
                 UpdateCell(iRow, key, changes[key]);
             //Data.LoadRow(corerow, obj);
             //Data.LoadRow(corerow, obj);
 
 
-            foreach (var column in Data.Columns.Where(x => !string.Equals(corecol, x.ColumnName)))
+            foreach (var c in Data.Columns.Where(x => !string.Equals(corecol, x.ColumnName)))
             {
             {
-                var scol = column.ColumnName.Replace('.', '_');
-                row[scol] = corerow[column.ColumnName] ?? DBNull.Value;
+                var scol = c.ColumnName.Replace('.', '_');
+                row[scol] = corerow[c.ColumnName] ?? DBNull.Value;
             }
             }
 
 
             for (var i = 0; i < ActionColumns.Count; i++)
             for (var i = 0; i < ActionColumns.Count; i++)
@@ -1608,6 +1611,35 @@ namespace InABox.DynamicGrid
             return !IsSequenced;
             return !IsSequenced;
         }
         }
 
 
+        private  class PopupConverter : IMultiValueConverter
+        {
+
+            private Dictionary<string, object?> _dictionary = new Dictionary<string, object?>();
+
+            private Type _type;
+            
+            public PopupConverter(IColumns columns, Type type)
+            {
+                foreach (var column in columns.ColumnNames())
+                    _dictionary[column] = null;
+                _type = type;
+            }
+            
+            public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+            {
+                if ((values.Length != _dictionary.Keys.Count))
+                    return "";
+                for (int i = 0; i < values.Length; i++)
+                    _dictionary[_dictionary.Keys.ElementAt(i)] = values[i] == DependencyProperty.UnsetValue ? null : values[i];
+                return LookupFactory.FormatLookup(_type, _dictionary, new String[] { });
+            }
+
+            public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+            {
+                throw new NotImplementedException();
+            }
+        }
+        
         private void ReloadColumns()
         private void ReloadColumns()
         {
         {
 
 
@@ -1795,6 +1827,107 @@ namespace InABox.DynamicGrid
                         newcol = imgcol;
                         newcol = imgcol;
                         filtering = false;
                         filtering = false;
                     }
                     }
+                    else if (prop.Editor is PopupEditor pEditor)
+                    {
+                        
+                        var prefix = String.Join(".", column.ColumnName.Split('.').Reverse().Skip(1).Reverse());
+                        var displaycols = new List<String>();
+                        var lookupcolumns = LookupFactory.DefineColumns(pEditor.Type);
+                        foreach (var lookupcolumn in lookupcolumns.GetColumns())
+                        {
+                            var displaycol = String.IsNullOrWhiteSpace(prefix)
+                                ? lookupcolumn.Property
+                                : $"{prefix}.{lookupcolumn.Property}";
+                            displaycols.Add(displaycol.Replace('.', '_'));
+                        }
+                        
+                        var templatecolumn = new GridTemplateColumn();
+                        templatecolumn.CellTemplate = TemplateGenerator.CreateDataTemplate
+                        (
+                            () =>
+                            {
+                                var result = new Label();
+                                var binding = new MultiBinding();
+                                foreach (var displaycol in displaycols)
+                                    binding.Bindings.Add(new Binding(displaycol));
+                                binding.Converter = new PopupConverter(lookupcolumns, pEditor.Type);
+                                result.SetBinding(Label.ContentProperty, binding);
+                                result.Background = new SolidColorBrush(Colors.LightYellow);
+                                return result;
+                            }
+                        );
+                        templatecolumn.EditTemplate = TemplateGenerator.CreateDataTemplate
+                        (
+                            () =>
+                            {
+                                var result = new DockPanel();
+                                if (Options.Contains(DynamicGridOption.DirectEdit))
+                                {
+                                    var button = new Button();
+                                    button.Content = "..";
+                                    button.Width = 25;
+                                    button.SetValue(DockPanel.DockProperty, Dock.Right);
+                                    button.Tag = templatecolumn;
+                                    button.Margin = new Thickness(2);
+
+                                    button.Click += (sender, args) =>
+                                    {
+                                        var view = (sender as Button)?.DataContext as DataRowView;
+                                        var col = (sender as Button)?.Tag as GridTemplateColumn;
+                                        if ((view != null) && (col != null))
+                                        {
+                                            var id = view[col.MappingName];
+                                            if (id is Guid)
+                                            {
+                                                var list = new PopupList(
+                                                    pEditor.Type,
+                                                    (Guid)id,
+                                                    pEditor.OtherColumns.Keys.ToArray()
+                                                );
+                                                list.OnDefineFilter += type =>
+                                                    LookupFactory.DefineFilter(pEditor.Type, typeof(T),
+                                                        new T[] { inplaceeditor });
+                                                if (list.ShowDialog() == true)
+                                                {
+                                                    var colno = DataGridItems.Columns.IndexOf(col.MappingName);
+                                                    view[col.MappingName] = list.ID;
+                                                    UpdateData(inplaceeditor,col.MappingName);
+                                                    
+                                                    var prefix = String.Join(".", Data.Columns[colno].ColumnName.Split('.').Reverse().Skip(1).Reverse());
+                                                    foreach (var key in list.OtherValues.Keys)
+                                                    {
+                                                        var othercol = String.IsNullOrWhiteSpace(prefix)
+                                                            ? key
+                                                            : $"{prefix}.{key}";
+                                                        othercol = othercol.Replace('.', '_');
+                                                        view[othercol] = list.OtherValues[key] ?? DBNull.Value;
+                                                        UpdateData(inplaceeditor,othercol);
+                                                    }
+                                                    
+                                                    DataGrid.SelectionController.CurrentCellManager.EndEdit();
+                                                }
+                                            }
+                                        }
+                                    };
+                                    result.Children.Add(button);
+                                }
+                                var label = new Label();
+                                var binding = new MultiBinding();
+                                foreach (var displaycol in displaycols)
+                                    binding.Bindings.Add(new Binding(displaycol));
+                                binding.Converter = new PopupConverter(lookupcolumns, pEditor.Type);
+                                label.SetBinding(Label.ContentProperty, binding);
+                                label.SetValue(DockPanel.DockProperty, Dock.Left);
+                                label.Background = new SolidColorBrush(Colors.LightYellow);
+                                result.Children.Add(label);
+                                return result;
+                            }
+                        );
+                        templatecolumn.SetCellBoundValue = false;
+
+                        newcol = templatecolumn;
+
+                    }
                     else if (prop.Editor is ILookupEditor lookupEditor)
                     else if (prop.Editor is ILookupEditor lookupEditor)
                     {
                     {
                         var lookupcol = new GridComboBoxColumn();
                         var lookupcol = new GridComboBoxColumn();

+ 11 - 8
inabox.wpf/DynamicGrid/Editors/CodePopupEditor/CodePopupEditorControl.cs

@@ -184,7 +184,7 @@ namespace InABox.DynamicGrid
                 var columns = LookupFactory.DefineColumns(_type);
                 var columns = LookupFactory.DefineColumns(_type);
                 var cols = OtherColumns.Keys.ToList();
                 var cols = OtherColumns.Keys.ToList();
                 foreach (var column in columns.ColumnNames())
                 foreach (var column in columns.ColumnNames())
-                    if (cols.Contains(column))
+                    if (!cols.Contains(column))
                         cols.Add(column);
                         cols.Add(column);
 
 
                 var list = new PopupList(_type, _value, cols.ToArray(), new Dictionary<string, string> { { CodeColumn, code } });
                 var list = new PopupList(_type, _value, cols.ToArray(), new Dictionary<string, string> { { CodeColumn, code } });
@@ -209,7 +209,7 @@ namespace InABox.DynamicGrid
 
 
                     Description.Text =
                     Description.Text =
                         LookupFactory.FormatLookup(_type, display,
                         LookupFactory.FormatLookup(_type, display,
-                            new[] { CodeColumn }); //String.Join(" / ", display.Where(x=>(x != null) && !String.IsNullOrWhiteSpace(x.ToString())));
+                            new[] { CodeColumn });
                 }
                 }
             }
             }
 
 
@@ -276,7 +276,7 @@ namespace InABox.DynamicGrid
             CoreUtils.SetPropertyValue(filter, "Value", value);
             CoreUtils.SetPropertyValue(filter, "Value", value);
 
 
             var lookup = client.Query(filter, columns, sort);
             var lookup = client.Query(filter, columns, sort);
-            var display = new List<object>();
+            var display = new Dictionary<string,object?>();
             var code = "";
             var code = "";
             var id = Guid.Empty;
             var id = Guid.Empty;
             var displaycols = LookupFactory.DefineColumns(_type).ColumnNames();
             var displaycols = LookupFactory.DefineColumns(_type).ColumnNames();
@@ -285,17 +285,20 @@ namespace InABox.DynamicGrid
 
 
             code = row[CodeColumn]?.ToString();
             code = row[CodeColumn]?.ToString();
             id = (Guid)row["ID"];
             id = (Guid)row["ID"];
-
+            
             foreach (var col in displaycols.Where(x => !x.Equals("ID") && !x.Equals(CodeColumn)))
             foreach (var col in displaycols.Where(x => !x.Equals("ID") && !x.Equals(CodeColumn)))
-                display.Add(row[col]);
-
+                display[col] = row[col];
+            
             foreach (var key in OtherColumns.Keys)
             foreach (var key in OtherColumns.Keys)
                 if (lookup.Columns.Any(x => x.ColumnName.Equals(key)))
                 if (lookup.Columns.Any(x => x.ColumnName.Equals(key)))
                     OtherValues[OtherColumns[key]] = row[key];
                     OtherValues[OtherColumns[key]] = row[key];
-
+            
             _value = id;
             _value = id;
             Editor.Text = code;
             Editor.Text = code;
-            Description.Text = string.Join(" / ", display.Where(x => x != null && !string.IsNullOrWhiteSpace(x.ToString())));
+            
+
+            Description.Text =
+                LookupFactory.FormatLookup(_type, display, new[] { CodeColumn });
         }
         }
 
 
         private string GetCodeColumn()
         private string GetCodeColumn()

+ 1 - 0
inabox.wpf/DynamicGrid/Editors/DateEditor/DateEditorControl.cs

@@ -82,6 +82,7 @@ namespace InABox.DynamicGrid
                 }
                 }
             };
             };
             Editor.LostFocus += (o, e) => { };
             Editor.LostFocus += (o, e) => { };
+            Editor.MouseDoubleClick += (o, e) => Editor.Value = DateTime.Today;
             Editor.SetValue(DockPanel.DockProperty, Dock.Left);
             Editor.SetValue(DockPanel.DockProperty, Dock.Left);
 
 
             var todayvisible = TodayVisible || (EditorDefinition is DateEditor && (EditorDefinition as DateEditor).TodayVisible);
             var todayvisible = TodayVisible || (EditorDefinition is DateEditor && (EditorDefinition as DateEditor).TodayVisible);