123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using FastReport;
- using InABox.Core;
- using InABox.Database;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace PRSServer.Forms;
- class DeletedEntityGrid<T> : DynamicGrid<T>, ISpecificGrid where T : Entity, new()
- {
- private CoreTable Table { get; set; }
- public DeletedEntityGrid(CoreTable table)
- {
- Table = table;
- HiddenColumns.Add(x => x.ID);
- ActionColumns.Add(new DynamicImageColumn(Properties.Resources.view.AsBitmapImage(), ViewClick));
- }
- protected override void Init()
- {
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- options.Clear();
- options.EditRows = true;
- }
- protected override DynamicGridColumns LoadColumns()
- {
- var result = base.LoadColumns();
- var deletionColumns = DeletionData.DeletionColumns<T>();
- var columns = new DynamicGridColumns();
- foreach(var column in deletionColumns)
- {
- var resultColumn = result.FirstOrDefault(x => x.ColumnName == column.Property);
- if(resultColumn is not null)
- {
- columns.Add(resultColumn);
- }
- }
- if(columns.Count == 0)
- {
- columns.Add<T>(x => x.ID, 0, "ID", "", Alignment.MiddleLeft);
- }
- return columns;
- }
- protected override void Reload(
- Filters<T> criteria, Columns<T> columns, ref SortOrder<T>? sort,
- CancellationToken token, Action<CoreTable?, Exception?> action)
- {
- try
- {
- action(Table, null);
- }
- catch(Exception e)
- {
- action(null, e);
- }
- }
- public override T LoadItem(CoreRow row)
- {
- return Table.Rows[row.Index].ToObject<T>();
- }
- private bool ViewClick(CoreRow? row)
- {
- if(row is null) return false;
- ViewItem(LoadItem(row));
- return false;
- }
- private void ViewItem(T item)
- {
- var editor = new DynamicEditorForm(typeof(T))
- {
- ReadOnly = true
- };
- editor.OnFormCustomiseEditor += Editor_OnFormCustomiseEditor;
- editor.OnDefineLookups += sender => DefineLookups(sender, Array.Empty<T>());
- editor.Items = new BaseObject[] { item };
- editor.ShowDialog();
- }
- private Columns<T>? _deletionColumns;
- private void Editor_OnFormCustomiseEditor(IDynamicEditorForm sender, object[] items, DynamicGridColumn column, BaseEditor editor)
- {
- _deletionColumns ??= DeletionData.DeletionColumns<T>();
- if(!_deletionColumns.Any(y => y.Property == column.ColumnName))
- {
- editor.Editable = Editable.Hidden;
- }
- }
- protected override void DoEdit()
- {
- if (!SelectedRows.Any())
- return;
- ViewItem(LoadItem(SelectedRows.First()));
- }
- public override void SaveItem(T item)
- {
- // No saving allowed
- }
- public override void DeleteItems(params CoreRow[] rows)
- {
- // No deleting allowed
- }
- }
|