|
@@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Data;
|
|
|
+using System.Windows.Forms.VisualStyles;
|
|
|
using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Animation;
|
|
@@ -28,6 +29,7 @@ using Syncfusion.UI.Xaml.Grid.Helpers;
|
|
|
using Syncfusion.Windows.Shared;
|
|
|
using Brush = System.Windows.Media.Brush;
|
|
|
using Color = System.Drawing.Color;
|
|
|
+using Columns = InABox.Core.Columns;
|
|
|
using DataColumn = System.Data.DataColumn;
|
|
|
using DataRow = System.Data.DataRow;
|
|
|
using FilterElement = Syncfusion.UI.Xaml.Grid.FilterElement;
|
|
@@ -39,6 +41,7 @@ using Image = System.Windows.Controls.Image;
|
|
|
using RowColumnIndex = Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex;
|
|
|
using SolidColorBrush = System.Windows.Media.SolidColorBrush;
|
|
|
using String = System.String;
|
|
|
+using VerticalAlignment = System.Windows.VerticalAlignment;
|
|
|
using VirtualizingCellsControl = Syncfusion.UI.Xaml.Grid.VirtualizingCellsControl;
|
|
|
|
|
|
namespace InABox.DynamicGrid
|
|
@@ -1190,6 +1193,28 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void UpdateData(Dictionary<String,object> changes)
|
|
|
+ {
|
|
|
+ if (!SelectedRows.Any())
|
|
|
+ return;
|
|
|
+
|
|
|
+ var iRow = SelectedRows.First().Index; //e.RowColumnIndex.RowIndex - (HasOption(DynamicGridOptions.FilterRows) ? 2 : 1);
|
|
|
+ if (DataGridItems is null || iRow > DataGridItems.Rows.Count)
|
|
|
+ return;
|
|
|
+
|
|
|
+ var updates = new Dictionary<CoreColumn, object>();
|
|
|
+ foreach (var key in changes.Keys)
|
|
|
+ {
|
|
|
+ var colno = DataGridItems.Columns.IndexOf(key);
|
|
|
+ var column = Data.Columns[colno];
|
|
|
+ updates[column] = changes[key];
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateData(updates);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void UpdateData(String mappedname)
|
|
|
{
|
|
|
if (!SelectedRows.Any())
|
|
@@ -1951,6 +1976,8 @@ namespace InABox.DynamicGrid
|
|
|
newcol = imgcol;
|
|
|
filtering = false;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
else if (prop.Editor is PopupEditor pEditor)
|
|
|
{
|
|
|
|
|
@@ -2052,6 +2079,131 @@ namespace InABox.DynamicGrid
|
|
|
newcol = templatecolumn;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ else if (prop.Editor is CodePopupEditor cpEditor)
|
|
|
+ {
|
|
|
+ var prefix = String.Join(".", column.ColumnName.Split('.').Reverse().Skip(1).Reverse());
|
|
|
+
|
|
|
+ var colname = String.IsNullOrWhiteSpace(cpEditor.CodeColumn)
|
|
|
+ ? CoreUtils.PropertyList(cpEditor.Type, p => p.GetEditor() is UniqueCodeEditor)
|
|
|
+ .FirstOrDefault()?.Name ?? ""
|
|
|
+ : cpEditor.CodeColumn;
|
|
|
+
|
|
|
+ var codecolname = String.IsNullOrWhiteSpace(prefix)
|
|
|
+ ? colname
|
|
|
+ : $"{prefix}.{colname}";
|
|
|
+ codecolname = codecolname.Replace('.', '_');
|
|
|
+
|
|
|
+ var templatecolumn = new GridTemplateColumn();
|
|
|
+ templatecolumn.CellTemplate = TemplateGenerator.CreateDataTemplate
|
|
|
+ (
|
|
|
+ () =>
|
|
|
+ {
|
|
|
+ var result = new Label();
|
|
|
+ result.SetBinding(Label.ContentProperty, new Binding(codecolname));
|
|
|
+ result.VerticalContentAlignment = VerticalAlignment.Center;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ );
|
|
|
+ templatecolumn.EditTemplate = TemplateGenerator.CreateDataTemplate
|
|
|
+ (
|
|
|
+ () =>
|
|
|
+ {
|
|
|
+ if (IsDirectEditMode())
|
|
|
+ {
|
|
|
+ var result = new Grid();
|
|
|
+ result.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star)});
|
|
|
+ result.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto)});
|
|
|
+
|
|
|
+ var textbox = new TextBox();
|
|
|
+ textbox.CharacterCasing = CharacterCasing.Upper;
|
|
|
+ textbox.SetBinding(TextBox.TextProperty, new Binding(codecolname));
|
|
|
+ textbox.SetValue(Grid.ColumnProperty, 0);
|
|
|
+ textbox.SetValue(Grid.ColumnSpanProperty, 2);
|
|
|
+ textbox.Tag = false;
|
|
|
+ textbox.Padding = new Thickness(2, 0, 0, 0);
|
|
|
+ textbox.VerticalContentAlignment = VerticalAlignment.Center;
|
|
|
+ textbox.PreviewTextInput += (sender, args) => textbox.Tag = true;
|
|
|
+ textbox.SetValue(FocusManagerHelper.FocusedElementProperty, true);
|
|
|
+ textbox.TextChanged += (sender, args) =>
|
|
|
+ {
|
|
|
+ if (Equals(textbox.Tag, false))
|
|
|
+ textbox.SelectAll();
|
|
|
+ };
|
|
|
+
|
|
|
+ //textbox.GotFocus += (sender, args) => textbox.SelectAll();
|
|
|
+ textbox.LostFocus += (sender, args) =>
|
|
|
+ {
|
|
|
+ if (sender is TextBox { Tag: true } box &&
|
|
|
+ (sender as FrameworkElement)?.DataContext is DataRowView view)
|
|
|
+ {
|
|
|
+ if (String.IsNullOrWhiteSpace(box.Text))
|
|
|
+ {
|
|
|
+ UpdateCodePopupColumnValue(
|
|
|
+ templatecolumn,
|
|
|
+ Guid.Empty,
|
|
|
+ codecolname,
|
|
|
+ "",
|
|
|
+ view);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var lookup = ClientFactory.CreateClient(cpEditor.Type).Query(
|
|
|
+ Filter.Create(cpEditor.Type, colname, Operator.BeginsWith,
|
|
|
+ box.Text),
|
|
|
+ Columns.Create(cpEditor.Type, "ID", colname),
|
|
|
+ null
|
|
|
+ );
|
|
|
+ if (lookup.Rows.Count == 1)
|
|
|
+ {
|
|
|
+ UpdateCodePopupColumnValue(
|
|
|
+ templatecolumn,
|
|
|
+ lookup.Rows[0].Get<Guid>("ID"),
|
|
|
+ codecolname,
|
|
|
+ lookup.Rows[0].Get<String>(colname),
|
|
|
+ view);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ PopupCodeList(sender, templatecolumn, cpEditor, colname,
|
|
|
+ codecolname);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+ result.Children.Add(textbox);
|
|
|
+
|
|
|
+ var button = new Button();
|
|
|
+ button.Content = "..";
|
|
|
+ button.Width = 25;
|
|
|
+ button.SetValue(Grid.ColumnProperty, 1);
|
|
|
+ button.Margin = new Thickness(1);
|
|
|
+ button.BorderThickness = new Thickness(0.75, 0, 0, 0);
|
|
|
+ button.Click += (sender, args) =>
|
|
|
+ {
|
|
|
+ PopupCodeList(sender, templatecolumn, cpEditor, colname, codecolname);
|
|
|
+ };
|
|
|
+ result.Children.Add(button);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var result = new Label();
|
|
|
+ result.SetBinding(Label.ContentProperty, new Binding(codecolname));
|
|
|
+ result.VerticalContentAlignment = VerticalAlignment.Center;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ templatecolumn.SetCellBoundValue = false;
|
|
|
+
|
|
|
+ newcol = templatecolumn;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
else if (prop.Editor is ILookupEditor lookupEditor)
|
|
|
{
|
|
|
var lookupcol = new GridComboBoxColumn();
|
|
@@ -2200,6 +2352,41 @@ namespace InABox.DynamicGrid
|
|
|
ResizeColumns(DataGrid, DataGrid.ActualWidth - 2, DataGrid.ActualHeight - 2);
|
|
|
}
|
|
|
|
|
|
+ private void PopupCodeList(object sender, GridTemplateColumn col, CodePopupEditor cpEditor, string colname, string codecolname)
|
|
|
+ {
|
|
|
+ if ((sender as FrameworkElement)?.DataContext is DataRowView view)
|
|
|
+ {
|
|
|
+ var id = view[col.MappingName];
|
|
|
+ if (id is Guid)
|
|
|
+ {
|
|
|
+ var list = new PopupList(
|
|
|
+ cpEditor.Type,
|
|
|
+ (Guid)id,
|
|
|
+ new String[] { colname }
|
|
|
+ );
|
|
|
+ list.OnDefineFilter += type =>
|
|
|
+ LookupFactory.DefineFilter(cpEditor.Type, typeof(T),
|
|
|
+ new T[] { inplaceeditor });
|
|
|
+ if (list.ShowDialog() == true)
|
|
|
+ UpdateCodePopupColumnValue(col, list.ID, codecolname, list.OtherValues[colname], view);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void UpdateCodePopupColumnValue(GridTemplateColumn col, Guid value, string codecolname, object? code, DataRowView view)
|
|
|
+ {
|
|
|
+
|
|
|
+ UpdateData(new Dictionary<String, object>()
|
|
|
+ {
|
|
|
+ { col.MappingName, value },
|
|
|
+ { codecolname, code ?? DBNull.Value }
|
|
|
+ });
|
|
|
+ DataGrid.SelectionController.CurrentCellManager.EndEdit();
|
|
|
+ //view[col.MappingName] = value;
|
|
|
+ //UpdateData(col.MappingName);
|
|
|
+ //view[codecolname] = code ?? DBNull.Value;
|
|
|
+ }
|
|
|
+
|
|
|
private void ApplyFilterStyle(GridColumn column, bool filtering, bool isactioncolumn)
|
|
|
{
|
|
|
var filterstyle = new Style();
|