|
@@ -273,8 +273,24 @@ namespace InABox.DynamicGrid
|
|
|
private readonly Button Help;
|
|
|
private readonly Button Import;
|
|
|
|
|
|
+ private class DirectEditingObject
|
|
|
+ {
|
|
|
+ public T Object { get; set; }
|
|
|
+
|
|
|
+ public CoreRow Row { get; set; }
|
|
|
+
|
|
|
+ public DataRow? DataRow { get; set; }
|
|
|
+
|
|
|
+ public DirectEditingObject(T obj, CoreRow row, DataRow? dataRow)
|
|
|
+ {
|
|
|
+ Object = obj;
|
|
|
+ Row = row;
|
|
|
+ DataRow = dataRow;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private DirectEditingObject? _editingObject;
|
|
|
|
|
|
- private T? inplaceeditor;
|
|
|
|
|
|
private readonly Grid Layout;
|
|
|
private readonly Label Loading;
|
|
@@ -901,15 +917,28 @@ namespace InABox.DynamicGrid
|
|
|
{ DisplayText = x, ActualValue = x, IsSelected = column.SelectedFilters is null || column.SelectedFilters.Contains(x) });
|
|
|
}
|
|
|
|
|
|
+ // Please always use this function where possible!
|
|
|
+ /// <summary>
|
|
|
+ /// Get the <see cref="CoreRow"/> associated with a <paramref name="rowIndex"/> given from the Syncfusion DataGrid.
|
|
|
+ /// </summary>
|
|
|
+ /// <remarks>
|
|
|
+ /// This is mandatory to use whenever we want the data associated with an index which Syncfusion has given us,
|
|
|
+ /// because filtering and sorting will cause normal indexing operations to fail.
|
|
|
+ /// </remarks>
|
|
|
+ /// <param name="rowIndex"></param>
|
|
|
+ /// <returns></returns>
|
|
|
private CoreRow? GetRowFromIndex(int rowIndex)
|
|
|
{
|
|
|
- var row = rowIndex - (HasOption(DynamicGridOption.FilterRows) ? 2 : 1);
|
|
|
- if (row < 0 || DataGridItems is null)
|
|
|
+ // Syncfusion has given us the row index, so it also will give us the correct row, after sorting.
|
|
|
+ // Hence, here we use the syncfusion DataGrid.GetRecordAtRowIndex, which *should* always return a DataRowView.
|
|
|
+ var row = DataGrid.GetRecordAtRowIndex(rowIndex);
|
|
|
+ if (row is not DataRowView dataRowView || DataGridItems is not DataTable table)
|
|
|
return null;
|
|
|
- row = DataGridItems.Rows.IndexOf((DataGrid.View.Records[row].Data as DataRowView)!.Row);
|
|
|
- if (row < 0)
|
|
|
+
|
|
|
+ var rowIdx = table.Rows.IndexOf(dataRowView.Row);
|
|
|
+ if (rowIdx < 0)
|
|
|
return null;
|
|
|
- return Data.Rows[row];
|
|
|
+ return Data.Rows[rowIdx];
|
|
|
}
|
|
|
|
|
|
private void DataGrid_CellToolTipOpening(object? sender, GridCellToolTipOpeningEventArgs e)
|
|
@@ -928,66 +957,37 @@ namespace InABox.DynamicGrid
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- //private void DataGrid_MouseMove(object sender, MouseEventArgs e)
|
|
|
- //{
|
|
|
- // var visualcontainer = DataGrid.GetVisualContainer();
|
|
|
- // var point = e.GetPosition(visualcontainer);
|
|
|
- // var rowColumnIndex = visualcontainer.PointToCellRowColumnIndex(point);
|
|
|
- // var recordIndex = DataGrid.ResolveToRecordIndex(rowColumnIndex.RowIndex);
|
|
|
-
|
|
|
- // if (recordIndex < 0)
|
|
|
- // return;
|
|
|
- // if (!rowColumnIndex.IsEmpty)
|
|
|
- // {
|
|
|
- // if (DataGrid.View.TopLevelGroup != null)
|
|
|
- // {
|
|
|
- // // Get the current row record while grouping
|
|
|
- // var record = DataGrid.View.TopLevelGroup.DisplayElements[recordIndex];
|
|
|
- // if (record.GetType() == typeof(RecordEntry))
|
|
|
- // {
|
|
|
- // var data = (record as RecordEntry).Data as CoreRow;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // else
|
|
|
- // {
|
|
|
- // //For getting the record, need to resolve the corresponding record index from row index
|
|
|
- // var record1 = DataGrid.View.Records[DataGrid.ResolveToRecordIndex(rowColumnIndex.RowIndex)].Data;
|
|
|
- // }
|
|
|
- // //Gets the column from ColumnsCollection by resolving the corresponding column index from GridVisibleColumnIndex
|
|
|
- // var gridColumn = DataGrid.Columns[DataGrid.ResolveToGridVisibleColumnIndex(rowColumnIndex.ColumnIndex)];
|
|
|
- // if (gridColumn is GridImageColumn)
|
|
|
- // {
|
|
|
-
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- //}
|
|
|
-
|
|
|
protected virtual void LoadColumnsMenu(ContextMenu menu)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+ private DirectEditingObject EnsureEditingObject(CoreRow row)
|
|
|
+ {
|
|
|
+ _editingObject ??= new(LoadItem(row), row, DataGridItems?.Rows[row.Index]);
|
|
|
+ return _editingObject;
|
|
|
+ }
|
|
|
+
|
|
|
private void DataGrid_CurrentCellBeginEdit(object? sender, CurrentCellBeginEditEventArgs e)
|
|
|
{
|
|
|
- var headerrows = HasOption(DynamicGridOption.FilterRows) ? 2 : 1;
|
|
|
- if (e.RowColumnIndex.RowIndex < headerrows || DataGridItems is null)
|
|
|
+ var table = DataGridItems;
|
|
|
+ var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
|
|
|
+ if (table is null || row is null)
|
|
|
return;
|
|
|
|
|
|
- inplaceeditor ??= LoadItem(Data.Rows[e.RowColumnIndex.RowIndex - headerrows]);
|
|
|
+ EnsureEditingObject(row);
|
|
|
|
|
|
var column = DataGrid.Columns[e.RowColumnIndex.ColumnIndex] as GridComboBoxColumn;
|
|
|
if (column != null && column.ItemsSource == null)
|
|
|
{
|
|
|
var colname = column.MappingName;
|
|
|
- var colno = DataGridItems.Columns.IndexOf(colname);
|
|
|
+ var colno = table.Columns.IndexOf(colname);
|
|
|
var property = Data.Columns[colno].ColumnName;
|
|
|
var prop = CoreUtils.GetProperty(typeof(T), property);
|
|
|
var editor = prop.GetEditor();
|
|
|
- if (editor is ILookupEditor)
|
|
|
+ if (editor is ILookupEditor lookupEditor)
|
|
|
{
|
|
|
if (!Lookups.ContainsKey(property))
|
|
|
- Lookups[property] = ((ILookupEditor)editor).Values(property);
|
|
|
+ Lookups[property] = lookupEditor.Values(property);
|
|
|
var combo = column;
|
|
|
combo.ItemsSource = Lookups[property].ToDictionary(Lookups[property].Columns[0].ColumnName, "Display");
|
|
|
combo.SelectedValuePath = "Key";
|
|
@@ -1000,32 +1000,33 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
private void DataGrid_CurrentCellValueChanged(object? sender, CurrentCellValueChangedEventArgs e)
|
|
|
{
|
|
|
+ var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
|
|
|
// Are we sure that this function is ever useful? It seems that since the data in the grid hasn't been updated by this point, this function is essentially useless (the data is updated in EndEdit). Probably need to check the GridCheckBoxColumn
|
|
|
- var headerrows = HasOption(DynamicGridOption.FilterRows) ? 2 : 1;
|
|
|
- if (e.RowColumnIndex.RowIndex < headerrows)
|
|
|
- return;
|
|
|
+
|
|
|
+ if (row is null) return;
|
|
|
+
|
|
|
if (e.Column is GridCheckBoxColumn)
|
|
|
- inplaceeditor = LoadItem(Data.Rows[e.RowColumnIndex.RowIndex - headerrows]);
|
|
|
- if (inplaceeditor is not null)
|
|
|
- UpdateData(e.RowColumnIndex.ColumnIndex);
|
|
|
+ {
|
|
|
+ EnsureEditingObject(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (_editingObject is not null)
|
|
|
+ UpdateData(_editingObject.Row.Index, e.RowColumnIndex.ColumnIndex);
|
|
|
if (e.Column is GridCheckBoxColumn)
|
|
|
- inplaceeditor = null;
|
|
|
- if (inplaceeditor is not null)
|
|
|
+ _editingObject = null;
|
|
|
+ if (_editingObject is not null)
|
|
|
bChanged = true;
|
|
|
}
|
|
|
|
|
|
private void DataGrid_CurrentCellDropDownSelectionChanged(object? sender,
|
|
|
CurrentCellDropDownSelectionChangedEventArgs e)
|
|
|
{
|
|
|
- var headerrows = HasOption(DynamicGridOption.FilterRows) ? 2 : 1;
|
|
|
- if (e.RowColumnIndex.RowIndex < headerrows)
|
|
|
+ var row = GetRowFromIndex(e.RowColumnIndex.RowIndex);
|
|
|
+ if (row is null)
|
|
|
return;
|
|
|
- inplaceeditor ??= LoadItem(Data.Rows[e.RowColumnIndex.RowIndex - headerrows]);
|
|
|
- if ((inplaceeditor is not null) && (e.SelectedItem is Tuple<object?, string> tuple))
|
|
|
+ EnsureEditingObject(row);
|
|
|
+ if ((_editingObject is not null) && (e.SelectedItem is Tuple<object?, string> tuple))
|
|
|
{
|
|
|
-
|
|
|
- var iRow = SelectedRows.First().Index;
|
|
|
-
|
|
|
var mappedname = DataGrid.Columns[e.RowColumnIndex.ColumnIndex].MappingName;
|
|
|
|
|
|
var colno = DataGridItems.Columns.IndexOf(mappedname);
|
|
@@ -1060,12 +1061,12 @@ namespace InABox.DynamicGrid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- protected void UpdateCell(int row, string colname, object? value)
|
|
|
+ protected void UpdateCell(CoreRow coreRow, DataRow? dataRow, string colname, object? value)
|
|
|
{
|
|
|
var datacolname = colname.Replace(".", "_");
|
|
|
var table = DataGridItems;
|
|
|
if (table is null) return;
|
|
|
-
|
|
|
+
|
|
|
var colno = table.Columns.IndexOf(datacolname);
|
|
|
if (colno < 0)
|
|
|
{
|
|
@@ -1074,66 +1075,66 @@ namespace InABox.DynamicGrid
|
|
|
return;
|
|
|
}
|
|
|
var corecol = Data.Columns[colno].ColumnName;
|
|
|
- var corerow = Data.Rows[row];
|
|
|
- corerow[corecol] = value;
|
|
|
+ coreRow[corecol] = value;
|
|
|
+ if(dataRow is not null)
|
|
|
+ {
|
|
|
+ dataRow[datacolname] = value ?? DBNull.Value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void UpdateCell(int row, string colname, object? value)
|
|
|
+ {
|
|
|
+ var table = DataGridItems;
|
|
|
+ if (table is null) return;
|
|
|
|
|
|
- var datarow = table.Rows[row];
|
|
|
- datarow[datacolname] = value ?? DBNull.Value;
|
|
|
+ UpdateCell(Data.Rows[row], table.Rows[row], colname, value);
|
|
|
}
|
|
|
|
|
|
private void DataGrid_CurrentCellEndEdit(object? sender, CurrentCellEndEditEventArgs e)
|
|
|
{
|
|
|
- var headerrows = HasOption(DynamicGridOption.FilterRows) ? 2 : 1;
|
|
|
- if (e.RowColumnIndex.RowIndex < headerrows)
|
|
|
- return;
|
|
|
- if (inplaceeditor is not null && bChanged)
|
|
|
+ if (_editingObject is not null && bChanged)
|
|
|
{
|
|
|
- UpdateData(e.RowColumnIndex.ColumnIndex);
|
|
|
+ UpdateData(_editingObject.Row.Index, e.RowColumnIndex.ColumnIndex);
|
|
|
}
|
|
|
if (bChanged)
|
|
|
DoChanged();
|
|
|
bChanged = false;
|
|
|
- inplaceeditor = null;
|
|
|
+ _editingObject = null;
|
|
|
DataGridItems?.AcceptChanges();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- private void UpdateRow(Dictionary<string, object?> changes)
|
|
|
+ private void UpdateRow(CoreRow row, DataRow? dataRow, Dictionary<string, object?> changes)
|
|
|
{
|
|
|
- if (!SelectedRows.Any())
|
|
|
- return;
|
|
|
-
|
|
|
- var iRow = SelectedRows.First().Index;
|
|
|
- var corerow = Data.Rows[iRow];
|
|
|
- var row = DataGridItems.Rows[iRow];
|
|
|
-
|
|
|
foreach (var key in changes.Keys)
|
|
|
- UpdateCell(iRow, key, changes[key]);
|
|
|
-
|
|
|
- for (var i = 0; i < ActionColumns.Count; i++)
|
|
|
- row[$"ActionColumn{i}"] = ActionColumns[i].Data(corerow);
|
|
|
+ UpdateCell(row, dataRow, key, changes[key]);
|
|
|
+
|
|
|
+ if (dataRow is not null)
|
|
|
+ {
|
|
|
+ for (var i = 0; i < ActionColumns.Count; i++)
|
|
|
+ dataRow[$"ActionColumn{i}"] = ActionColumns[i].Data(row);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private Dictionary<string,object?> UpdateData(Dictionary<CoreColumn, object?> updates)
|
|
|
+ private Dictionary<string, object?> UpdateData(Dictionary<CoreColumn, object?> updates)
|
|
|
{
|
|
|
var result = new Dictionary<string, object?>();
|
|
|
- if (!SelectedRows.Any())
|
|
|
+
|
|
|
+ if (_editingObject is null)
|
|
|
return result;
|
|
|
|
|
|
- var iRow = SelectedRows.First().Index;
|
|
|
- var corerow = Data.Rows[iRow];
|
|
|
- var row = DataGridItems.Rows[iRow];
|
|
|
+ var coreRow = _editingObject.Row;
|
|
|
+ var row = _editingObject.DataRow;
|
|
|
|
|
|
foreach (var (col, value) in updates)
|
|
|
{
|
|
|
- UpdateRow(corerow, col.ColumnName, value, refresh: false);
|
|
|
- DynamicGridUtils.UpdateEditorValue(new BaseObject[] { inplaceeditor }, col.ColumnName, value, result);
|
|
|
+ UpdateRow(coreRow, col.ColumnName, value, refresh: false);
|
|
|
+ DynamicGridUtils.UpdateEditorValue(new BaseObject[] { _editingObject.Object }, col.ColumnName, value, result);
|
|
|
}
|
|
|
|
|
|
- SaveItem(inplaceeditor);
|
|
|
+ SaveItem(_editingObject.Object);
|
|
|
|
|
|
foreach (var key in result.Keys)
|
|
|
- UpdateCell(iRow, key, result[key]);
|
|
|
+ UpdateCell(coreRow, row, key, result[key]);
|
|
|
|
|
|
// foreach (var c in Data.Columns.Where(x => !string.Equals(column.ColumnName, x.ColumnName)))
|
|
|
// {
|
|
@@ -1141,25 +1142,23 @@ namespace InABox.DynamicGrid
|
|
|
// row[scol] = corerow[c.ColumnName] ?? DBNull.Value;
|
|
|
// }
|
|
|
|
|
|
- for (var i = 0; i < ActionColumns.Count; i++)
|
|
|
- row[string.Format("ActionColumn{0}", i)] = ActionColumns[i].Data(corerow);
|
|
|
+ if(row is not null)
|
|
|
+ {
|
|
|
+ for (var i = 0; i < ActionColumns.Count; i++)
|
|
|
+ row[string.Format("ActionColumn{0}", i)] = ActionColumns[i].Data(coreRow);
|
|
|
+ }
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void UpdateData(int columnindex)
|
|
|
+ private void UpdateData(int rowIndex, int columnIndex)
|
|
|
{
|
|
|
-
|
|
|
- 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)
|
|
|
+ var table = DataGridItems;
|
|
|
+ if (table is null)
|
|
|
return;
|
|
|
|
|
|
-
|
|
|
- var gridcol = ColumnList[columnindex] as DynamicGridColumn;
|
|
|
+ var gridcol = ColumnList[columnIndex] as DynamicGridColumn;
|
|
|
|
|
|
if (gridcol != null)
|
|
|
{
|
|
@@ -1168,11 +1167,7 @@ namespace InABox.DynamicGrid
|
|
|
{
|
|
|
var datacolindex = Data.Columns.IndexOf(datacol);
|
|
|
|
|
|
- //var colno = DataGridItems.Columns.IndexOf(mappedname);
|
|
|
- //var column = Data.Columns.FirstOrDefault(x => x.ColumnName.Equals(gridcol.ColumnName));
|
|
|
- //if (column != null)
|
|
|
- //{
|
|
|
- var value = DataGridItems.Rows[iRow][datacolindex];
|
|
|
+ var value = table.Rows[rowIndex][datacolindex];
|
|
|
if (value is DBNull)
|
|
|
value = CoreUtils.GetDefault(datacol.DataType);
|
|
|
var changes = UpdateData(new Dictionary<CoreColumn, object?>() { { datacol, value } });
|
|
@@ -1198,9 +1193,6 @@ namespace InABox.DynamicGrid
|
|
|
if (IsReady && !bRefreshing) ResizeColumns(DataGrid, e.NewSize.Width - 2, e.NewSize.Height - 2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
#region Row Selections
|
|
|
|
|
|
protected CoreRow[] GetVisibleRows()
|
|
@@ -1381,10 +1373,7 @@ namespace InABox.DynamicGrid
|
|
|
if ((columnindex < 0) || (columnindex >= ColumnList.Count))
|
|
|
return;
|
|
|
var column = ColumnList[columnindex] as DynamicActionColumn;
|
|
|
- var rowindex = rowcolumnindex.RowIndex - (HasOption(DynamicGridOption.FilterRows) ? 2 : 1);
|
|
|
- if (rowindex < 0 || rowindex >= Data.Rows.Count)
|
|
|
- return;
|
|
|
- var row = Data.Rows[rowindex];
|
|
|
+
|
|
|
var menu = column?.ContextMenu?.Invoke(SelectedRows);
|
|
|
if (menu != null && menu.Items.Count > 0)
|
|
|
{
|
|
@@ -1891,7 +1880,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
if (newcol != null)
|
|
|
{
|
|
|
- newcol.GetEntity = () => inplaceeditor;
|
|
|
+ newcol.GetEntity = () => _editingObject.Object;
|
|
|
newcol.EntityChanged += DoEntityChanged;
|
|
|
if (!newcol.VariableHeight)
|
|
|
gridRowResizingOptions.ExcludeColumns.Add(newcol.MappingName);
|
|
@@ -2001,10 +1990,14 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
private void DoEntityChanged(object column, DynamicColumnEntityChangedEventArgs args)
|
|
|
{
|
|
|
+ if(_editingObject is null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- OnAfterEditorValueChanged(null, new T[] { inplaceeditor }, new AfterEditorValueChangedArgs(args.ColumnName, args.Changes), args.Changes);
|
|
|
- SaveItem(inplaceeditor);
|
|
|
- UpdateRow(args.Changes);
|
|
|
+ OnAfterEditorValueChanged(null, new T[] { _editingObject.Object }, new AfterEditorValueChangedArgs(args.ColumnName, args.Changes), args.Changes);
|
|
|
+ SaveItem(_editingObject.Object);
|
|
|
+ UpdateRow(_editingObject.Row, _editingObject.DataRow, args.Changes);
|
|
|
//DataGrid.SelectionController.CurrentCellManager.EndEdit();
|
|
|
}
|
|
|
|
|
@@ -2517,114 +2510,6 @@ namespace InABox.DynamicGrid
|
|
|
DoEdit();
|
|
|
}
|
|
|
|
|
|
- /*private void MultiEdit_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- using (new WaitCursor())
|
|
|
- {
|
|
|
- var criteria = new Filters<T>();
|
|
|
- var columns = new Columns<T>();
|
|
|
- columns.Add("ID");
|
|
|
- var iprops = DatabaseSchema.Properties(typeof(T)).Where(x => x.Editor is not NullEditor);
|
|
|
- foreach (var iprop in iprops)
|
|
|
- columns.Add(iprop.Name);
|
|
|
- var sort = LookupFactory.DefineSort<T>();
|
|
|
- Reload(
|
|
|
- criteria,
|
|
|
- columns,
|
|
|
- ref sort,
|
|
|
- (table, exception) =>
|
|
|
- {
|
|
|
- if(table is not null)
|
|
|
- {
|
|
|
- Dispatcher.Invoke(() => { DirectEdit(table); });
|
|
|
- }
|
|
|
- else if(exception is not null)
|
|
|
- {
|
|
|
- Logger.Send(LogType.Error, "", $"Error in MultiEdit: {CoreUtils.FormatException(exception)}");
|
|
|
- MessageBox.Show(exception.Message);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
- /*public override bool DirectEdit(CoreTable data)
|
|
|
- {
|
|
|
- var window = new DynamicEditWindow<T>();
|
|
|
-
|
|
|
- window.OnCreateItem += () => CreateItem();
|
|
|
-
|
|
|
- window.OnCustomiseColumns += (o, c) =>
|
|
|
- {
|
|
|
- ConfigureColumns(MasterColumns);
|
|
|
- if (OnCustomiseColumns != null)
|
|
|
- return OnCustomiseColumns(this, MasterColumns);
|
|
|
- return MasterColumns;
|
|
|
- };
|
|
|
-
|
|
|
- window.OnGetEditor += c =>
|
|
|
- {
|
|
|
- var result = GetEditor(this, c)?.CloneEditor();
|
|
|
- if (result == null)
|
|
|
- return null;
|
|
|
- OnCustomiseEditor?.Invoke(window, null, c, result);
|
|
|
- return result;
|
|
|
- };
|
|
|
-
|
|
|
- window.OnGetSequence += c =>
|
|
|
- {
|
|
|
- decimal result = 0.0M;
|
|
|
- var customprop = DatabaseSchema.Property(typeof(T), c.ColumnName);
|
|
|
- if (customprop != null && customprop is CustomProperty)
|
|
|
- {
|
|
|
- result = customprop.Sequence;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var bits = c.ColumnName.Split('.');
|
|
|
- for (var i = 0; i < bits.Length; i++)
|
|
|
- {
|
|
|
- var sProp = string.Join(".", bits.Take(bits.Length - i));
|
|
|
- PropertyInfo? prop;
|
|
|
- try
|
|
|
- {
|
|
|
- prop = CoreUtils.GetProperty(typeof(T), sProp);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
|
|
|
- prop = null;
|
|
|
- }
|
|
|
-
|
|
|
- if (prop != null)
|
|
|
- {
|
|
|
- result = prop.GetSequence() + result / 1000.0M;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var cprop = DatabaseSchema.Property(typeof(T), sProp);
|
|
|
- if (cprop != null)
|
|
|
- result = cprop.Sequence;
|
|
|
- else
|
|
|
- result /= 1000.0M;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- };
|
|
|
-
|
|
|
- window.Load(data);
|
|
|
-
|
|
|
- if (window.ShowDialog() == true)
|
|
|
- {
|
|
|
- SaveItems(window.Updates);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }*/
|
|
|
-
|
|
|
protected virtual void DoAdd(bool OpenEditorOnDirectEdit = false)
|
|
|
{
|
|
|
//CoreRow row = (SelectedRow > -1) && (SelectedRow < Data.Rows.Count) ? Data.Rows[this.SelectedRow] : null;
|
|
@@ -2809,7 +2694,7 @@ namespace InABox.DynamicGrid
|
|
|
return changes;
|
|
|
}
|
|
|
|
|
|
- protected virtual void OnAfterEditorValueChanged(DynamicEditorGrid grid, T[] items, AfterEditorValueChangedArgs args, Dictionary<String, object?> changes)
|
|
|
+ protected virtual void OnAfterEditorValueChanged(DynamicEditorGrid? grid, T[] items, AfterEditorValueChangedArgs args, Dictionary<String, object?> changes)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -3623,262 +3508,18 @@ namespace InABox.DynamicGrid
|
|
|
private void RowDragDropController_DragStart(object? sender, GridRowDragStartEventArgs e)
|
|
|
{
|
|
|
Logger.Send(LogType.Information,"","RowDragDropController_DragStart");
|
|
|
- //e.Handled = true;
|
|
|
|
|
|
if (!HasOption(DynamicGridOption.DragSource))
|
|
|
return;
|
|
|
|
|
|
- var rows = new List<CoreRow>();
|
|
|
- foreach (var record in e.DraggingRecords)
|
|
|
+ var rows = e.DraggingRecords.Select(record =>
|
|
|
{
|
|
|
var rowIndex = DataGrid.ResolveToRowIndex(record);
|
|
|
- rows.Add(GetRowFromIndex(rowIndex));
|
|
|
- }
|
|
|
- var rowArr = rows.ToArray();
|
|
|
- OnRowsDragStart(rowArr);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
- /* Removed as appears unused; removed as of 19/12/2022
|
|
|
- #region CellRendering
|
|
|
-
|
|
|
- private void PopulateDynamicActionCell(DynamicActionColumn column, int rowIndex, int columnIndex, GridStyleInfo style)
|
|
|
- {
|
|
|
- style.CellType = "ImageCell";
|
|
|
- var bi = column.Image?.Invoke(rowIndex < 0 ? null : Data.Rows[rowIndex]);
|
|
|
- if (bi != null)
|
|
|
- {
|
|
|
- style.CellValue = bi;
|
|
|
- style.BorderMargins = new CellMarginsInfo(4.0F);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //bool rowstylehelperinitialised = false;
|
|
|
-
|
|
|
- //protected virtual void ProcessCellStyle(CoreRow row, int column, GridStyleInfo style)
|
|
|
- //{
|
|
|
-
|
|
|
- // if (!rowstylehelperinitialised)
|
|
|
- // {
|
|
|
- // Script stylescript = new Client<Script>().Load(new Filter<Script>(x => x.Section).IsEqualTo(typeof(T).EntityName()).And(x => x.ScriptType).IsEqualTo(ScriptType.RowStyle)).FirstOrDefault(); ;
|
|
|
- // if (stylescript != null)
|
|
|
- // {
|
|
|
-
|
|
|
- // rowstylehelper = new ScriptDocument(stylescript.Code);
|
|
|
- // if (!rowstylehelper.Compile())
|
|
|
- // {
|
|
|
- // MessageBox.Show("Unable to Load Row Style Helper!\r\n\r\n" + rowstylehelper.Result);
|
|
|
- // rowstylehelper = null;
|
|
|
- // }
|
|
|
-
|
|
|
- // }
|
|
|
- // rowstylehelperinitialised = true;
|
|
|
- // }
|
|
|
-
|
|
|
- // if (rowstylehelper != null)
|
|
|
- // {
|
|
|
- // try
|
|
|
- // {
|
|
|
- // rowstylehelper.SetValue("Row", row);
|
|
|
- // rowstylehelper.SetValue("Column", Data.Columns[column].ColumnName);
|
|
|
- // rowstylehelper.SetValue("Background", style.Background);
|
|
|
- // rowstylehelper.SetValue("Foreground", style.Foreground);
|
|
|
- // rowstylehelper.SetValue("Style", style.Font.FontStyle);
|
|
|
- // rowstylehelper.SetValue("Weight", style.Font.FontWeight);
|
|
|
- // if (rowstylehelper.Execute())
|
|
|
- // {
|
|
|
- // style.Background = (System.Windows.Media.Brush)rowstylehelper.GetValue("Background");
|
|
|
- // style.Foreground = (System.Windows.Media.Brush)rowstylehelper.GetValue("Foreground");
|
|
|
- // style.Font.FontStyle = (FontStyle)rowstylehelper.GetValue("Style");
|
|
|
- // style.Font.FontWeight = (FontWeight)rowstylehelper.GetValue("Weight");
|
|
|
- // }
|
|
|
- // }
|
|
|
- // catch (Exception e)
|
|
|
- // {
|
|
|
- // //MessageBox.Show("Unable to Invoke Row Style Helper!\r\n\r\n" + e.Message);
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- private readonly Dictionary<string, BaseEditor> editorcache = new();
|
|
|
-
|
|
|
- private void PopulateDataCell(int rowIndex, int columnIndex, GridStyleInfo style)
|
|
|
- {
|
|
|
- if (columnIndex > -1 && columnIndex < ColumnList.Count)
|
|
|
- {
|
|
|
- var o = ColumnList[columnIndex];
|
|
|
- if (o is DynamicActionColumn)
|
|
|
- {
|
|
|
- PopulateDynamicActionCell((DynamicActionColumn)o, rowIndex, columnIndex, style);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var dgc = (DynamicGridColumn)o;
|
|
|
-
|
|
|
- var dc = Data.Columns.FirstOrDefault(x => x.ColumnName.Equals(dgc.ColumnName));
|
|
|
-
|
|
|
- var fmt = string.IsNullOrWhiteSpace(dgc.Format) ? "{0}" : "{0:" + dgc.Format.Replace("\\:", ":").Replace(":", "\\:") + "}";
|
|
|
-
|
|
|
- object? val = null;
|
|
|
- if (rowIndex < Data.Rows.Count)
|
|
|
- val = Data.Rows[rowIndex][dgc.ColumnName];
|
|
|
-
|
|
|
- if (val != null && dgc.Lookups.ContainsKey(val))
|
|
|
- val = dgc.Lookups[val];
|
|
|
-
|
|
|
- if (dc != null)
|
|
|
- {
|
|
|
- if(!editorcache.TryGetValue(dc.ColumnName, out var editor))
|
|
|
- {
|
|
|
- var prop = DatabaseSchema.Property(typeof(T), dc.ColumnName);
|
|
|
- if (prop != null)
|
|
|
- editor = prop.Editor;
|
|
|
- else
|
|
|
- editor = EditorUtils.GetEditor(dc.DataType) ?? new NullEditor();
|
|
|
- editorcache[dc.ColumnName] = editor;
|
|
|
- }
|
|
|
-
|
|
|
- if (editor is CheckBoxEditor)
|
|
|
- {
|
|
|
- style.CellType = "CheckBox";
|
|
|
- style.CellValue = val;
|
|
|
-
|
|
|
- style.HorizontalAlignment = dc == null ? HorizontalAlignment.Left : dgc.HorizontalAlignment(dc.DataType);
|
|
|
- style.VerticalAlignment = dgc.VerticalAlignment();
|
|
|
- style.TextMargins = new CellMarginsInfo(2.0F);
|
|
|
- }
|
|
|
- else if (editor is ColorEditor)
|
|
|
- {
|
|
|
- style.CellType = "ImageCell";
|
|
|
- var str = val?.ToString();
|
|
|
- if (!string.IsNullOrWhiteSpace(str))
|
|
|
- {
|
|
|
- var color = ColorTranslator.FromHtml(str); // System.Drawing.Color.FromName(val.ToString());
|
|
|
- var bitmap = ImageUtils.BitmapFromColor(color, (int)style.GridModel.ColumnWidths[columnIndex],
|
|
|
- (int)style.GridModel.RowHeights[rowIndex], Color.Black);
|
|
|
- //bitmap.Save(val.ToString().Replace("#","") + ".png");
|
|
|
- style.CellValue = bitmap.AsBitmapImage(false);
|
|
|
- style.BorderMargins = new CellMarginsInfo(4.0F);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- string value;
|
|
|
- try
|
|
|
- {
|
|
|
- if(val is null)
|
|
|
- {
|
|
|
- value = "";
|
|
|
- }
|
|
|
- else if (val.GetType().IsEnum)
|
|
|
- {
|
|
|
- value = val.ToString()!;
|
|
|
- }
|
|
|
- else if (val.GetType().IsDefault(val))
|
|
|
- {
|
|
|
- value = "";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- value = string.Format(new TimeSpanFormatter(), fmt, val);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- Logger.Send(LogType.Error, "", string.Format("*** Unknown Error: {0}\n{1}", e.Message, e.StackTrace));
|
|
|
- value = val?.ToString() ?? "";
|
|
|
- }
|
|
|
-
|
|
|
- if (editor is PasswordEditor)
|
|
|
- style.CellValue = "".PadLeft(value.Length, '●');
|
|
|
- else
|
|
|
- style.CellValue = value;
|
|
|
- style.HorizontalAlignment = dc == null ? HorizontalAlignment.Left : dgc.HorizontalAlignment(dc.DataType);
|
|
|
- style.VerticalAlignment = dgc.VerticalAlignment();
|
|
|
- style.CellType = "Static";
|
|
|
- style.TextMargins = new CellMarginsInfo(2.0F);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void PopulateHeaderCell(int columnIndex, GridStyleInfo style)
|
|
|
- {
|
|
|
- if (columnIndex > -1 && columnIndex < ColumnList.Count)
|
|
|
- {
|
|
|
- var o = ColumnList[columnIndex];
|
|
|
- if (o is DynamicActionColumn)
|
|
|
- {
|
|
|
- PopulateDynamicActionCell((DynamicActionColumn)o, -1, columnIndex, style);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var dgc = (DynamicGridColumn)o;
|
|
|
- if (Data != null)
|
|
|
- {
|
|
|
- var dc = Data.Columns.FirstOrDefault(x => x.ColumnName.Equals(dgc.ColumnName));
|
|
|
- style.HorizontalAlignment = dc != null ? dgc.HorizontalAlignment(dc.DataType) : HorizontalAlignment.Left;
|
|
|
- }
|
|
|
-
|
|
|
- style.CellValue = string.IsNullOrWhiteSpace(dgc.Caption) ? dgc.ColumnName : dgc.Caption;
|
|
|
- style.VerticalAlignment = dgc.VerticalAlignment();
|
|
|
- style.CellType = "Static";
|
|
|
- style.TextMargins = new CellMarginsInfo(2.0F);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- #endregion
|
|
|
- */
|
|
|
- /* Removed as appears unused; removed as of 19/12/2022
|
|
|
- #region Drag and Drop
|
|
|
-
|
|
|
- private Point startpoint;
|
|
|
-
|
|
|
- private void CheckPreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|
|
- {
|
|
|
- if (!HasOption(DynamicGridOption.DragSource))
|
|
|
- return;
|
|
|
- if (e.LeftButton == MouseButtonState.Pressed)
|
|
|
- {
|
|
|
- Logger.Send(LogType.Information, GetType().EntityName(), "Initiating Start Point");
|
|
|
- startpoint = e.GetPosition(DataGrid);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //private void CheckPreviewMouseMove(object sender, MouseEventArgs e)
|
|
|
- //{
|
|
|
- // Logger.Send(LogType.Information, this.GetType().EntityName(), String.Format("Checking Mouse Move: StartPoint = {0},{1}", startpoint.X, startpoint.Y));
|
|
|
-
|
|
|
- // if (!_HasOption(DynamicGridOptions.DragSource))
|
|
|
- // return;
|
|
|
- // Vector diff = startpoint - e.GetPosition(null);
|
|
|
- // Logger.Send(LogType.Information, this.GetType().EntityName(), String.Format("Checking Mouse Move: StartPoint = {0},{1} Diff = {2},{3}", startpoint.X, startpoint.Y, diff.X, diff.Y));
|
|
|
-
|
|
|
- // if ( (startpoint.X != 0) && (startpoint.Y != 0))
|
|
|
- // {
|
|
|
- // if ((Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
|
|
|
- // {
|
|
|
- // Logger.Send(LogType.Information, this.GetType().EntityName(), "Starting Drag Drop Operation");
|
|
|
- // DataObject dragData = new DataObject(typeof(T).EntityName(), SelectedRows);
|
|
|
- // DragDrop.DoDragDrop(DataGrid, dragData, DragDropEffects.Copy);
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- private void CheckPreviewMouseUp(object sender, MouseButtonEventArgs e)
|
|
|
- {
|
|
|
- if (!HasOption(DynamicGridOption.DragSource))
|
|
|
- return;
|
|
|
-
|
|
|
- Logger.Send(LogType.Information, GetType().EntityName(), "Clearing Start Point");
|
|
|
- startpoint = new Point();
|
|
|
+ return GetRowFromIndex(rowIndex);
|
|
|
+ }).NotNull().ToArray();
|
|
|
+ OnRowsDragStart(rows);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
- */
|
|
|
}
|
|
|
}
|