|
@@ -1,110 +1,157 @@
|
|
|
-using System;
|
|
|
-using System.Linq;
|
|
|
-using System.Linq.Expressions;
|
|
|
-using System.Windows;
|
|
|
-using System.Windows.Controls;
|
|
|
-using Comal.Classes;
|
|
|
+using Comal.Classes;
|
|
|
using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
-using InABox.WPF;
|
|
|
+using InABox.Wpf;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Linq.Expressions;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
|
|
|
namespace PRSDesktop;
|
|
|
|
|
|
-public class ProductGroupTree: DynamicTreeView<ProductGroup>
|
|
|
+public class ProductGroupTree : DynamicDataGrid<ProductGroup>
|
|
|
{
|
|
|
- protected override Expression<Func<ProductGroup, Guid>> ID => x => x.ID;
|
|
|
- protected override Expression<Func<ProductGroup, Guid>> ParentID => x => x.Parent.ID;
|
|
|
- protected override Expression<Func<ProductGroup, string>> Description => x => x.Description;
|
|
|
-
|
|
|
- public ProductGroupTree() : base()
|
|
|
+ public Guid SelectedID { get; private set; }
|
|
|
+
|
|
|
+ protected override void Init()
|
|
|
{
|
|
|
- Options.AddRange(DynamicTreeOption.Add, DynamicTreeOption.Edit, DynamicTreeOption.Delete);
|
|
|
- MaxRowHeight = 30D;
|
|
|
- ExpandMode = DynamicTreeGridExpandMode.All;
|
|
|
- //OnContextMenuOpening += ProductTree_OnContextMenuOpening;
|
|
|
+ base.Init();
|
|
|
}
|
|
|
|
|
|
- // private void ProductTree_OnContextMenuOpening(CoreTreeNode node, ContextMenu menu)
|
|
|
- // {
|
|
|
- // menu.AddItem("Add Child Group", null, node, (n) => DoAddItem(n.ID,true));
|
|
|
- //
|
|
|
- // }
|
|
|
+ protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
|
+ {
|
|
|
+ base.DoReconfigure(options);
|
|
|
+
|
|
|
+ options.RemoveRange(DynamicGridOption.SelectColumns, DynamicGridOption.ImportData, DynamicGridOption.ExportData);
|
|
|
+ }
|
|
|
|
|
|
- protected override ProductGroup DoCreateItem(Guid parent)
|
|
|
+ protected override DynamicGridColumns LoadColumns()
|
|
|
{
|
|
|
- var selectedid = SelectedID == CoreUtils.FullGuid ? Guid.Empty : SelectedID;
|
|
|
- var result = base.DoCreateItem(selectedid);
|
|
|
- return result;
|
|
|
+ var columns = new DynamicGridColumns();
|
|
|
+ columns.Add<ProductGroup, string>(x => x.Description, 0, "Description", "", Alignment.MiddleLeft);
|
|
|
+ return columns;
|
|
|
}
|
|
|
|
|
|
- protected override ProductGroup? DoLoadItem(Guid id)
|
|
|
+ private DynamicGridTreeUIComponent<ProductGroup>? _uiComponent;
|
|
|
+ private DynamicGridTreeUIComponent<ProductGroup> UIComponent
|
|
|
{
|
|
|
- if (id == CoreUtils.FullGuid)
|
|
|
+ get
|
|
|
{
|
|
|
- MessageBox.Show("This item cannot be edited.");
|
|
|
- return null;
|
|
|
+ if(_uiComponent is null)
|
|
|
+ {
|
|
|
+ _uiComponent = new DynamicGridTreeUIComponent<ProductGroup>(
|
|
|
+ x => x.ID,
|
|
|
+ x => x.Parent.ID)
|
|
|
+ {
|
|
|
+ Parent = this,
|
|
|
+ MaxRowHeight = 30D,
|
|
|
+ ExpandMode = DynamicTreeGridExpandMode.All,
|
|
|
+ ShowHeader = false
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return _uiComponent;
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ public DynamicTreeGridLines GridLines
|
|
|
+ {
|
|
|
+ get => UIComponent.GridLines;
|
|
|
+ set => UIComponent.GridLines = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override IDynamicGridUIComponent<ProductGroup> CreateUIComponent()
|
|
|
+ {
|
|
|
+ return UIComponent;
|
|
|
+ }
|
|
|
|
|
|
- return new Client<ProductGroup>()
|
|
|
- .Query(new Filter<ProductGroup>(x => x.ID).IsEqualTo(id))
|
|
|
- .Rows
|
|
|
- .FirstOrDefault()?
|
|
|
- .ToObject<ProductGroup>();
|
|
|
+ public IEnumerable<CoreRow> GetChildren(Guid groupID)
|
|
|
+ {
|
|
|
+ return UIComponent.GetChildren(groupID);
|
|
|
}
|
|
|
|
|
|
- protected override void DoSaveItem(ProductGroup item)
|
|
|
+ protected override void SelectItems(CoreRow[]? rows)
|
|
|
{
|
|
|
- if (item.ID != CoreUtils.FullGuid)
|
|
|
- new Client<ProductGroup>().Save(item, "Edited by User");
|
|
|
+ base.SelectItems(rows);
|
|
|
+
|
|
|
+ SelectedID = rows?.FirstOrDefault()?.Get<ProductGroup, Guid>(x => x.ID) ?? Guid.Empty;
|
|
|
}
|
|
|
|
|
|
- protected override bool DoDeleteItem(Guid id)
|
|
|
+ public override ProductGroup CreateItem()
|
|
|
{
|
|
|
- if(id == CoreUtils.FullGuid)
|
|
|
+ var group = base.CreateItem();
|
|
|
+ var id = SelectedID;
|
|
|
+ group.Parent.ID = id == CoreUtils.FullGuid ? Guid.Empty : SelectedID;
|
|
|
+ return group;
|
|
|
+ }
|
|
|
+ public override ProductGroup LoadItem(CoreRow row)
|
|
|
+ {
|
|
|
+ if(row.Get<ProductGroup, Guid>(x => x.ID) == CoreUtils.FullGuid)
|
|
|
{
|
|
|
- MessageBox.Show("This group cannot be deleted.");
|
|
|
- return false;
|
|
|
+ return row.ToObject<ProductGroup>();
|
|
|
}
|
|
|
+ return base.LoadItem(row);
|
|
|
+ }
|
|
|
|
|
|
- CoreRow? row = Data.Rows.FirstOrDefault(r=>r.Get<ProductGroup, Guid>(x => x.ID) == id);
|
|
|
- if(row == null)
|
|
|
+ public override ProductGroup[] LoadItems(CoreRow[] rows)
|
|
|
+ {
|
|
|
+ var all = rows.FirstOrDefault(x => x.Get<ProductGroup, Guid>(x => x.ID) == CoreUtils.FullGuid);
|
|
|
+ if(all is not null)
|
|
|
{
|
|
|
- MessageBox.Show("Error: Row does not exist!");
|
|
|
- Logger.Send(LogType.Error, ClientFactory.UserID, $"Error: Product Group {id} does not exist or is not loaded");
|
|
|
- return false;
|
|
|
+ return new ProductGroup[] { all.ToObject<ProductGroup>() };
|
|
|
}
|
|
|
-
|
|
|
- new Client<ProductGroup>().Delete(new ProductGroup() { ID = id }, "Deleted by User");
|
|
|
- return true;
|
|
|
+ return base.LoadItems(rows);
|
|
|
}
|
|
|
|
|
|
- protected override void DoRefresh(Action<CoreTable?, Exception?> action)
|
|
|
+ public override bool EditItems(ProductGroup[] items, Func<Type, CoreTable?>? PageDataHandler = null, bool PreloadPages = false)
|
|
|
{
|
|
|
- try
|
|
|
+ if (items.Any(x => x.ID == CoreUtils.FullGuid))
|
|
|
{
|
|
|
- var data = new Client<ProductGroup>().Query(
|
|
|
- LookupFactory.DefineFilter<ProductGroup>(),
|
|
|
- null
|
|
|
- );
|
|
|
-
|
|
|
- foreach (var row in data.Rows)
|
|
|
- {
|
|
|
- if (row.Get<ProductGroup,Guid>(x=>x.Parent.ID) == Guid.Empty)
|
|
|
- row.Set<ProductGroup, Guid>(x => x.Parent.ID, CoreUtils.FullGuid);
|
|
|
- }
|
|
|
+ MessageWindow.ShowMessage("This item cannot be edited.", "Cannot edit");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return base.EditItems(items, PageDataHandler, PreloadPages);
|
|
|
+ }
|
|
|
|
|
|
- var newRow = data.NewRow();
|
|
|
- newRow.Set<ProductGroup, Guid>(x => x.ID, CoreUtils.FullGuid);
|
|
|
- newRow.Set<ProductGroup, Guid>(x => x.Parent.ID, Guid.Empty );
|
|
|
- newRow.Set<ProductGroup, string>(x => x.Description, "All Groups");
|
|
|
- data.Rows.Insert(0, newRow);
|
|
|
+ public override void SaveItem(ProductGroup folder)
|
|
|
+ {
|
|
|
+ if (folder.ID != CoreUtils.FullGuid)
|
|
|
+ {
|
|
|
+ Client.Save(folder, "Edited by User");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- action(data, null);
|
|
|
+ protected override bool CanDeleteItems(params CoreRow[] rows)
|
|
|
+ {
|
|
|
+ if(rows.Any(x => x.Get<ProductGroup, Guid>(x => x.ID) == CoreUtils.FullGuid))
|
|
|
+ {
|
|
|
+ MessageWindow.ShowMessage("This folder cannot be deleted.", "Cannot delete");
|
|
|
+ return false;
|
|
|
}
|
|
|
- catch (Exception e)
|
|
|
+ else
|
|
|
{
|
|
|
- action(null, e);
|
|
|
+ return base.CanDeleteItems();
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ protected override void Reload(Filters<ProductGroup> criteria, Columns<ProductGroup> columns, ref SortOrder<ProductGroup>? sort, Action<CoreTable?, Exception?> action)
|
|
|
+ {
|
|
|
+ criteria.Add(LookupFactory.DefineFilter<ProductGroup>());
|
|
|
+ base.Reload(criteria, columns, ref sort, (table, exception) =>
|
|
|
+ {
|
|
|
+ if(table != null)
|
|
|
+ {
|
|
|
+ var newRow = table.NewRow();
|
|
|
+ newRow.Set<ProductGroup, Guid>(x => x.ID, CoreUtils.FullGuid);
|
|
|
+ newRow.Set<ProductGroup, Guid>(x => x.Parent.ID, Guid.Empty);
|
|
|
+ newRow.Set<ProductGroup, string>(x => x.Description, "All Groups");
|
|
|
+
|
|
|
+ table.Rows.Insert(0, newRow);
|
|
|
+
|
|
|
+ }
|
|
|
+ action(table, exception);
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|