|
@@ -30,6 +30,7 @@ using Syncfusion.UI.Xaml.Grid.Helpers;
|
|
|
using Syncfusion.Windows.Controls.Cells;
|
|
|
using Syncfusion.Windows.Controls.Grid;
|
|
|
using Syncfusion.Windows.Shared;
|
|
|
+using Syncfusion.Windows.Tools;
|
|
|
using Syncfusion.Windows.Tools.Controls;
|
|
|
using Syncfusion.XPS;
|
|
|
using Brush = System.Windows.Media.Brush;
|
|
@@ -979,7 +980,7 @@ namespace InABox.DynamicGrid
|
|
|
if (e.Column is GridCheckBoxColumn)
|
|
|
inplaceeditor = LoadItem(Data.Rows[e.RowColumnIndex.RowIndex - headerrows]);
|
|
|
if (inplaceeditor is not null)
|
|
|
- UpdateData(inplaceeditor, e.RowColumnIndex.ColumnIndex);
|
|
|
+ UpdateData(inplaceeditor, DataGrid.Columns[e.RowColumnIndex.ColumnIndex].MappingName);
|
|
|
if (e.Column is GridCheckBoxColumn)
|
|
|
inplaceeditor = null;
|
|
|
if (inplaceeditor is not null)
|
|
@@ -1016,30 +1017,32 @@ namespace InABox.DynamicGrid
|
|
|
var headerrows = Options.Contains(DynamicGridOption.FilterRows) ? 2 : 1;
|
|
|
if (e.RowColumnIndex.RowIndex < headerrows)
|
|
|
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;
|
|
|
inplaceeditor = null;
|
|
|
DataGridItems?.AcceptChanges();
|
|
|
}
|
|
|
|
|
|
- private void UpdateData(T obj, int columnindex)
|
|
|
+ private void UpdateData(T obj, String mappedname)
|
|
|
{
|
|
|
+ if (!SelectedRows.Any())
|
|
|
+ return;
|
|
|
var table = DataGridItems;
|
|
|
-
|
|
|
+
|
|
|
var iRow = SelectedRows.First().Index; //e.RowColumnIndex.RowIndex - (Options.Contains(DynamicGridOptions.FilterRows) ? 2 : 1);
|
|
|
if (table is null || iRow > table.Rows.Count)
|
|
|
return;
|
|
|
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 corerow = Data.Rows[iRow];
|
|
|
corerow[corecol] = value;
|
|
|
|
|
|
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());
|
|
@@ -1071,10 +1074,10 @@ namespace InABox.DynamicGrid
|
|
|
UpdateCell(iRow, key, changes[key]);
|
|
|
//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++)
|
|
@@ -1608,6 +1611,35 @@ namespace InABox.DynamicGrid
|
|
|
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()
|
|
|
{
|
|
|
|
|
@@ -1795,6 +1827,107 @@ namespace InABox.DynamicGrid
|
|
|
newcol = imgcol;
|
|
|
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)
|
|
|
{
|
|
|
var lookupcol = new GridComboBoxColumn();
|