|
@@ -14,15 +14,19 @@ using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Data;
|
|
|
+using System.Windows.Documents;
|
|
|
using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Animation;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Threading;
|
|
|
+using FastReport.DevComponents.AdvTree;
|
|
|
using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.Scripting;
|
|
|
using InABox.WPF;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
+using Org.BouncyCastle.Crypto;
|
|
|
using Syncfusion.Data;
|
|
|
using Syncfusion.UI.Xaml.Grid;
|
|
|
using Syncfusion.UI.Xaml.Grid.Cells;
|
|
@@ -526,6 +530,8 @@ namespace InABox.DynamicGrid
|
|
|
DataGrid.RowStyleSelector = RowStyleSelector;
|
|
|
DataGrid.TableSummaryCellStyleSelector = new DynamicGridSummaryStyleSelector(this);
|
|
|
|
|
|
+ DataGrid.CellRenderers.Add("PopupRenderer", new DynamicGridPopupColumnRenderer(this));
|
|
|
+
|
|
|
//DataGrid.MouseMove += DataGrid_MouseMove;
|
|
|
DataGrid.CellToolTipOpening += DataGrid_CellToolTipOpening;
|
|
|
|
|
@@ -993,7 +999,7 @@ namespace InABox.DynamicGrid
|
|
|
bChanged = true;
|
|
|
}
|
|
|
|
|
|
- protected void UpdateCell(int row, string colname, object value)
|
|
|
+ protected void UpdateCell(int row, string colname, object? value)
|
|
|
{
|
|
|
var datacolname = colname.Replace(".", "_");
|
|
|
var table = DataGridItems;
|
|
@@ -1033,10 +1039,9 @@ namespace InABox.DynamicGrid
|
|
|
var corerow = Data.Rows[iRow];
|
|
|
corerow[corecol] = value;
|
|
|
|
|
|
- Dictionary<String, object> changes = new Dictionary<string, object>();
|
|
|
+ var changes = new Dictionary<string, object?>();
|
|
|
if (DataGrid.Columns[colname] is GridComboBoxColumn combo)
|
|
|
{
|
|
|
-
|
|
|
var prefix = String.Join(".", corecol.Split(".").Reverse().Skip(1).Reverse());
|
|
|
var field = corecol.Split(".").Last();
|
|
|
var lookups = (combo.ItemsSource as DataView)?.Table;
|
|
@@ -1050,14 +1055,29 @@ namespace InABox.DynamicGrid
|
|
|
var prop = String.IsNullOrWhiteSpace(prefix)
|
|
|
? lookupcol.ColumnName
|
|
|
: String.Join(".", new String[] { prefix, lookupcol.ColumnName });
|
|
|
- DynamicGridUtils.UpdateEditorValue(new BaseObject[] { inplaceeditor }, prop, lookuprow[lookupcol], changes);
|
|
|
+ DynamicGridUtils.UpdateEditorValue(new BaseObject[] { obj }, prop, lookuprow[lookupcol], changes);
|
|
|
//CoreUtils.SetPropertyValue(obj, prop, lookuprow[lookupcol]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ else if (DataGrid.Columns[colname] is DynamicGridPopupColumn popup)
|
|
|
+ {
|
|
|
+ var prefix = String.Join(".", corecol.Split(".").SkipLast(1));
|
|
|
+ var field = corecol.Split(".").Last();
|
|
|
+
|
|
|
+ DynamicGridUtils.UpdateEditorValue(new BaseObject[] { obj }, corecol, value, changes);
|
|
|
+
|
|
|
+ foreach (var column in popup.Editor.OtherColumns.Keys)
|
|
|
+ {
|
|
|
+ var prop = String.IsNullOrWhiteSpace(prefix)
|
|
|
+ ? column
|
|
|
+ : String.Join(".", prefix, column);
|
|
|
+ DynamicGridUtils.UpdateEditorValue(new BaseObject[] { obj }, prop, corerow[column], changes);
|
|
|
+ }
|
|
|
+ }
|
|
|
else
|
|
|
- DynamicGridUtils.UpdateEditorValue(new BaseObject[] { inplaceeditor }, corecol, value, changes);
|
|
|
+ DynamicGridUtils.UpdateEditorValue(new BaseObject[] { obj }, corecol, value, changes);
|
|
|
//CoreUtils.SetPropertyValue(obj, corecol, value);
|
|
|
|
|
|
|
|
@@ -1601,6 +1621,134 @@ namespace InABox.DynamicGrid
|
|
|
return !IsSequenced;
|
|
|
}
|
|
|
|
|
|
+ private class DynamicGridPopupColumnRenderer : GridVirtualizingCellRenderer<DynamicGridPopupColumnCell, DynamicGridPopupColumnCell>
|
|
|
+ {
|
|
|
+ public delegate void SelectEvent();
|
|
|
+ public delegate void ClearEvent();
|
|
|
+
|
|
|
+ public event SelectEvent? OnSelect;
|
|
|
+ public event ClearEvent? OnClear;
|
|
|
+
|
|
|
+ public DynamicGrid<T> Grid { get; set; }
|
|
|
+
|
|
|
+ public DynamicGridPopupColumnRenderer(DynamicGrid<T> grid)
|
|
|
+ {
|
|
|
+ Grid = grid;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void SetFocus(FrameworkElement uiElement, bool needToFocus)
|
|
|
+ {
|
|
|
+ base.SetFocus(uiElement, needToFocus);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SetDisplay(DynamicGridPopupColumnCell cell, CoreRow row, DynamicGridPopupColumn col, string columnName)
|
|
|
+ {
|
|
|
+ var linkName = string.Join('.', columnName.Split('.').SkipLast(1));
|
|
|
+ var values = new Dictionary<string, object?>();
|
|
|
+ foreach (var column in row.Table.Columns)
|
|
|
+ {
|
|
|
+ if (column.ColumnName.StartsWith(linkName + "."))
|
|
|
+ {
|
|
|
+ var name = column.ColumnName[(linkName.Length + 1)..];
|
|
|
+ if (name != "ID")
|
|
|
+ {
|
|
|
+ values[name] = row[column.ColumnName];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cell.Display = LookupFactory.FormatLookup(col.Editor.Type, values, Enumerable.Empty<string>());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void InitializeElement(DataColumnBase dataColumn, DynamicGridPopupColumnCell cell, object dataContext)
|
|
|
+ {
|
|
|
+ if (dataColumn.GridColumn is DynamicGridPopupColumn col && dataContext is DataRowView rowview && Grid.DataGridItems is not null)
|
|
|
+ {
|
|
|
+ var row = Grid.GetRowFromIndex(dataColumn.RowIndex);
|
|
|
+ var mapName = dataColumn.GridColumn.MappingName;
|
|
|
+ var colName = Grid.Data.Columns[Grid.DataGridItems.Columns.IndexOf(mapName)].ColumnName;
|
|
|
+
|
|
|
+ SetDisplay(cell, row, col, colName);
|
|
|
+
|
|
|
+ var binding = new Binding
|
|
|
+ {
|
|
|
+ Source = dataContext,
|
|
|
+ Path = new PropertyPath(mapName),
|
|
|
+ UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
|
|
|
+ };
|
|
|
+ cell.SetBinding(DynamicGridPopupColumnCell.ValueProperty, binding);
|
|
|
+
|
|
|
+ cell.OnValueChanged += (value) =>
|
|
|
+ {
|
|
|
+ SetDisplay(cell, row, col, colName);
|
|
|
+ };
|
|
|
+ cell.OnClear = () =>
|
|
|
+ {
|
|
|
+ var columns = LookupFactory.DefineColumns(col.Editor.Type);
|
|
|
+ row[colName] = Guid.Empty;
|
|
|
+ var linkName = string.Join('.', colName.Split('.').SkipLast(1));
|
|
|
+ foreach (var column in columns.ColumnNames())
|
|
|
+ {
|
|
|
+ if(column != "ID")
|
|
|
+ {
|
|
|
+ row[linkName + "." + column] = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Grid.InvalidateRow(row);
|
|
|
+
|
|
|
+ var data = Grid.LoadItem(row);
|
|
|
+ Grid.UpdateData(data, dataColumn.ColumnIndex);
|
|
|
+ Grid.UpdateCell(row.Index, colName, Guid.Empty);
|
|
|
+ };
|
|
|
+ cell.OnSelect = () =>
|
|
|
+ {
|
|
|
+ var columns = LookupFactory.DefineColumns(col.Editor.Type);
|
|
|
+ var data = Grid.LoadItem(row);
|
|
|
+ var popupList = new PopupList(col.Editor.Type, (Guid)(row[colName] ?? Guid.Empty), columns.ColumnNames().ToArray());
|
|
|
+ popupList.OnDefineFilter += t => { return Grid.DefineFilter(t, new T[] { data }); };
|
|
|
+ if (popupList.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ row[colName] = popupList.ID;
|
|
|
+ var linkName = string.Join('.', colName.Split('.').SkipLast(1));
|
|
|
+ foreach (var column in columns.ColumnNames())
|
|
|
+ {
|
|
|
+ if (column != "ID")
|
|
|
+ {
|
|
|
+ row[linkName + "." + column] = popupList.OtherValues[column];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Grid.InvalidateRow(row);
|
|
|
+
|
|
|
+ data = Grid.LoadItem(row);
|
|
|
+ Grid.UpdateData(data, dataColumn.ColumnIndex);
|
|
|
+ Grid.UpdateCell(row.Index, colName, Guid.Empty);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void OnInitializeDisplayElement(DataColumnBase dataColumn, DynamicGridPopupColumnCell cell, object dataContext)
|
|
|
+ {
|
|
|
+ base.OnInitializeDisplayElement(dataColumn, cell, dataContext);
|
|
|
+ InitializeElement(dataColumn, cell, dataContext);
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void OnInitializeEditElement(DataColumnBase dataColumn, DynamicGridPopupColumnCell cell, object dataContext)
|
|
|
+ {
|
|
|
+ base.OnInitializeEditElement(dataColumn, cell, dataContext);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private class DynamicGridPopupColumn : GridColumn
|
|
|
+ {
|
|
|
+ public DataLookupEditor Editor { get; set; }
|
|
|
+
|
|
|
+ public DynamicGridPopupColumn(DataLookupEditor editor)
|
|
|
+ {
|
|
|
+ Editor = editor;
|
|
|
+ SetCellType("PopupRenderer");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void ReloadColumns()
|
|
|
{
|
|
|
|
|
@@ -1790,23 +1938,31 @@ namespace InABox.DynamicGrid
|
|
|
}
|
|
|
else if (prop.Editor is ILookupEditor lookupEditor)
|
|
|
{
|
|
|
- var lookupcol = new GridComboBoxColumn();
|
|
|
-
|
|
|
- //var lookups = editor.Values(column.ColumnName).ToDictionary(column.ColumnName, "Display");
|
|
|
- //lookupcol.SelectedValuePath = "Key";
|
|
|
- //lookupcol.DisplayMemberPath = "Value";
|
|
|
- //lookupcol.ItemsSource = lookups;
|
|
|
-
|
|
|
- var table = lookupEditor.Values(column.ColumnName).ToDataTable();
|
|
|
- lookupcol.SelectedValuePath = table.Columns[0].ColumnName;
|
|
|
- lookupcol.DisplayMemberPath = "Display";
|
|
|
- lookupcol.ItemsSource = table.DefaultView;
|
|
|
- newcol = lookupcol;
|
|
|
+ if (Options.Contains(DynamicGridOption.DirectEdit) && lookupEditor is PopupEditor popup)
|
|
|
+ {
|
|
|
+ var popupcol = new DynamicGridPopupColumn(popup);
|
|
|
+ newcol = popupcol;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var lookupcol = new GridComboBoxColumn();
|
|
|
+
|
|
|
+ //var lookups = editor.Values(column.ColumnName).ToDictionary(column.ColumnName, "Display");
|
|
|
+ //lookupcol.SelectedValuePath = "Key";
|
|
|
+ //lookupcol.DisplayMemberPath = "Value";
|
|
|
+ //lookupcol.ItemsSource = lookups;
|
|
|
+
|
|
|
+ var table = lookupEditor.Values(column.ColumnName).ToDataTable();
|
|
|
+ lookupcol.SelectedValuePath = table.Columns[0].ColumnName;
|
|
|
+ lookupcol.DisplayMemberPath = "Display";
|
|
|
+ lookupcol.ItemsSource = table.DefaultView;
|
|
|
+ newcol = lookupcol;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
var textcol = new GridTextColumn();
|
|
|
- if (!(prop.Editor is MemoEditor))
|
|
|
+ if (prop.Editor is not MemoEditor)
|
|
|
gridRowResizingOptions.ExcludeColumns.Add(scolname);
|
|
|
textcol.TextWrapping = TextWrapping.NoWrap;
|
|
|
newcol = textcol;
|