Browse Source

Fixing problems with new tree view and updating current tree view classes to use the new stuff.

Kenric Nugteren 1 năm trước cách đây
mục cha
commit
286f45700e

+ 3 - 3
prs.classes/Entities/Product/ProductGroup/ProductGroup.cs

@@ -28,10 +28,10 @@ namespace Comal.Classes
 
                 var data = Client.Query(
                     null,
-                    new Columns<ProductGroup>(x => x.ID).Add(x => x.Parent.ID).Add(x => x.Description));
+                    new Columns<ProductGroup>(x => x.ID).Add(x => x.Parent.ID));
 
                 var nodes = new CoreTreeNodes();
-                nodes.Load<ProductGroup>(data, x => x.ID, x => x.Parent.ID, x => x.Description);
+                nodes.Load<ProductGroup>(data, x => x.ID, x => x.Parent.ID);
 
                 var exclusions = items.SelectMany(x => nodes.GetChildren(x.ID)).ToArray();
 
@@ -39,7 +39,7 @@ namespace Comal.Classes
             }
 
             public override Columns<ProductGroup> DefineFilterColumns()
-                => new Columns<ProductGroup>(x => x.ID).Add(x => x.Parent.ID).Add(x => x.Code).Add(x => x.Description);
+                => new Columns<ProductGroup>(x => x.ID).Add(x => x.Parent.ID).Add(x => x.Code);
         }
         
         [LookupDefinition(typeof(ProductGroupLookup))]

+ 1 - 1
prs.desktop/DockPanels/Requisitions/MyRequisitionsList.cs

@@ -48,7 +48,7 @@ public class MyRequisitionsList : DynamicDataGrid<Requisition>
         base.Reload(criteria, columns, ref sort, action);
     }
 
-    protected override Requisition CreateItem()
+    public override Requisition CreateItem()
     {
         var result = base.CreateItem();
         result.RequestedBy.ID = App.EmployeeID;

+ 4 - 4
prs.desktop/Panels/Factory/FactoryPackGrid.cs

@@ -59,12 +59,12 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
         _holding = new DynamicTemplateColumn(PackTemplate) { Width = 0 };
         ActionColumns.Add(_holding);
     }
-    
-    public override void Reconfigure()
+
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
     {
-        base.Reconfigure();
+        base.DoReconfigure(options);
+        options.Clear();
         RowHeight = 85;
-        Options.Clear();
     }
     
     protected override DynamicGridColumns LoadColumns()

+ 13 - 5
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetFolderTree.cs

@@ -10,6 +10,7 @@ using InABox.DynamicGrid;
 using InABox.WPF;
 using InABox.Wpf;
 using System.Collections.Generic;
+using System.Windows.Forms;
 
 namespace PRSDesktop;
 
@@ -32,11 +33,11 @@ public class JobDocumentSetFolderTree : DynamicDataGrid<JobDocumentSetFolder>, I
             {
                 _uiComponent = new DynamicGridTreeUIComponent<JobDocumentSetFolder>(
                     x => x.ID,
-                    x => x.Parent.ID,
-                    x => x.Name)
+                    x => x.Parent.ID)
                 {
+                    Parent = this,
                     MaxRowHeight = 30,
-                    Parent = this
+                    ShowHeader = false
                 };
 
                 _uiComponent.OnContextMenuOpening += JobDocumentSetFolderTree_OnContextMenuOpening;
@@ -55,14 +56,21 @@ public class JobDocumentSetFolderTree : DynamicDataGrid<JobDocumentSetFolder>, I
         return UIComponent;
     }
 
+    protected override DynamicGridColumns LoadColumns()
+    {
+        var columns = new DynamicGridColumns();
+        columns.Add<JobDocumentSetFolder, string>(x => x.Name, 0, "Name", "", Alignment.MiddleLeft);
+        return columns;
+    }
+
     public IEnumerable<CoreRow> GetChildFolders(Guid folderID)
     {
         return UIComponent.GetChildren(folderID);
     }
 
-    private void JobDocumentSetFolderTree_OnContextMenuOpening(CoreTreeNode node, ContextMenu menu)
+    private void JobDocumentSetFolderTree_OnContextMenuOpening(CoreTreeNode? node, ContextMenu menu)
     {
-        if(node.ID != CoreUtils.FullGuid && Options.Contains(DynamicGridOption.AddRows))
+        if(node is not null && node.ID != CoreUtils.FullGuid && Options.Contains(DynamicGridOption.AddRows))
         {
             menu.AddItem("Add Child Folder", null, node, (n) =>
             {

+ 3 - 3
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetTree.xaml.cs

@@ -908,7 +908,7 @@ namespace PRSDesktop
                 return false;
 
             var folders = new CoreTreeNodes();
-            folders.Load<JobDocumentSetFolder>(data, x => x.ID, x => x.Parent.ID, x => x.Name);
+            folders.Load<JobDocumentSetFolder>(data, x => x.ID, x => x.Parent.ID);
 
             foreach (var folder in folders.Nodes)
                 DoPopulateFolder(menu, folder, documents);
@@ -918,7 +918,7 @@ namespace PRSDesktop
 
         private void DoPopulateFolder(MenuItem header, CoreTreeNode folder, IEnumerable<DocumentSetNode> documents)
         {
-            var menu = header.AddItem(folder.Description, null, () => MoveToFolder(documents, folder));
+            var menu = header.AddItem(folder.Row.Get<JobDocumentSetFolder, string>(x => x.Name), null, () => MoveToFolder(documents, folder));
             foreach (var childfolder in folder.Children)
                 DoPopulateFolder(menu, childfolder, documents);
         }
@@ -943,7 +943,7 @@ namespace PRSDesktop
                 }
 
                 if (updates.Any())
-                    new Client<JobDocumentSet>().Save(updates, "Moved to Folder: " + folder.Description);
+                    new Client<JobDocumentSet>().Save(updates, "Moved to Folder: " + folder.Row.Get<JobDocumentSetFolder, string>(x => x.Name));
                 else
                     MessageBox.Show("Nothing to Do!");
             }

+ 9 - 9
prs.desktop/Panels/Meeting/MeetingPanel.xaml.cs

@@ -165,22 +165,23 @@ public partial class MeetingPanel : UserControl, IPanel<Meeting>
         return new Dictionary<string, object?>();
     }
     
-    private void MeetingItemGrid_OnSelectItem(CoreTreeNode node)
+    private void MeetingItemGrid_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
     {
+        var nodeID = e.Rows?.FirstOrDefault()?.Get<MeetingItem, Guid>(x => x.ID) ?? Guid.Empty;
 
-        _meetingitemSelected = node != null;
+        _meetingitemSelected = nodeID != Guid.Empty;
 
-        MeetingItemMotions.MeetingItemID = node != null ? node.ID : Guid.Empty;
+        MeetingItemMotions.MeetingItemID = nodeID;
         MeetingItemMotions.Refresh(false,true);
         
-        MeetingItemDocuments.MeetingItemID = node != null ? node.ID : Guid.Empty;
+        MeetingItemDocuments.MeetingItemID = nodeID;
         MeetingItemDocuments.Refresh(false, true);
         
-        MeetingItemTasks.MeetingItemID = node != null ? node.ID : Guid.Empty;
+        MeetingItemTasks.MeetingItemID = nodeID;
         MeetingItemTasks.Refresh(false, true);
-        
-        var row = node != null
-            ? MeetingItems.Data?.Rows.FirstOrDefault(r => r.Get<MeetingItem, Guid>(x => x.ID) == node.ID)
+
+        var row = nodeID != Guid.Empty
+            ? MeetingItems.Data?.Rows.FirstOrDefault(r => r.Get<MeetingItem, Guid>(x => x.ID) == nodeID)
             : null;
         
         var meetingitem = row != null ? row.ToObject<MeetingItem>() : new MeetingItem();
@@ -281,5 +282,4 @@ public partial class MeetingPanel : UserControl, IPanel<Meeting>
 
 
     #endregion
-    
 }

+ 13 - 5
prs.desktop/Panels/Meeting/MeetingTreeView.cs

@@ -3,6 +3,7 @@ using System.Linq;
 using System.Linq.Expressions;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Forms;
 using Comal.Classes;
 using InABox.Clients;
 using InABox.Core;
@@ -18,11 +19,11 @@ public class MeetingItemTree : DynamicDataGrid<MeetingItem>
     {
         var component = new DynamicGridTreeUIComponent<MeetingItem>(
             x => x.ID,
-            x => x.Parent.ID,
-            x => x.Title)
+            x => x.Parent.ID)
         {
-            MaxRowHeight = 30,
             Parent = this,
+            ShowHeader = false,
+            MaxRowHeight = 30,
             ShowNumbers = true
         };
 
@@ -31,11 +32,18 @@ public class MeetingItemTree : DynamicDataGrid<MeetingItem>
         return component;
     }
 
+    protected override DynamicGridColumns LoadColumns()
+    {
+        var columns = new DynamicGridColumns();
+        columns.Add<MeetingItem, string>(x => x.Title, 0, "Title", "", Alignment.MiddleLeft);
+        return columns;
+    }
+
     public MeetingModel? Model { get; set; }
     
-    private void MeetingItemTree_OnContextMenuOpening(CoreTreeNode node, ContextMenu menu)
+    private void MeetingItemTree_OnContextMenuOpening(CoreTreeNode? node, ContextMenu menu)
     {
-        if(node.ID != CoreUtils.FullGuid && Options.Contains(DynamicGridOption.AddRows))
+        if(node is not null && node.ID != CoreUtils.FullGuid && Options.Contains(DynamicGridOption.AddRows))
         {
             menu.AddItem("Add Child Item", null, node, (n) =>
             {

+ 118 - 71
prs.desktop/Panels/Products/Master List/ProductGroupTree.cs

@@ -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);
+        });
+    }
+}

+ 24 - 6
prs.desktop/Panels/Products/Master List/ProductsPanel.xaml.cs

@@ -19,6 +19,7 @@ using InABox.WPF;
 using InABox.Wpf;
 using Microsoft.Win32;
 using Image = System.Drawing.Image;
+using System.Windows.Markup.Localizer;
 
 namespace PRSDesktop
 {
@@ -62,6 +63,8 @@ namespace PRSDesktop
             Products.Refresh(true, false);
             Products.OnSelectItem += Products_OnSelectItem;
 
+            Groups.Refresh(true, false);
+
             if (settings.SelectedDetailsGrid >= 0 && settings.SelectedDetailsGrid < ProductDetails.Items.Count)
                 ProductDetails.SelectedIndex = settings.SelectedDetailsGrid;
         }
@@ -88,7 +91,7 @@ namespace PRSDesktop
 
         public void Refresh()
         {
-            Groups.Refresh();
+            Groups.Refresh(false, true);
             //ProductDetails.IsEnabled = false;
             //Products.Refresh(false, true);
         }
@@ -404,13 +407,28 @@ namespace PRSDesktop
             MessageBox.Show(string.Format("Cleared image from [{0}]", string.Join(", ", SelectedProducts())));
         }
 
-        private void Groups_OnOnSelectItem(CoreTreeNode node)
+        private void Groups_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
         {
-            if (node != null)
+            if(e.Rows is null)
+            {
+                Products.Groups = null;
+                Products.Refresh(false, true);
+            }
+            else
             {
-                Products.Groups = node.ID == CoreUtils.FullGuid
-                    ? null
-                    : Groups.Nodes.GetThisAndAllChildren(node.ID).ToArray();
+                var groups = new List<Guid>();
+                var all = false;
+                foreach(var g in e.Rows)
+                {
+                    var nodeID = g.Get<ProductGroup, Guid>(x => x.ID);
+                    if(nodeID == CoreUtils.FullGuid)
+                    {
+                        all = true;
+                        break;
+                    }
+                    groups.AddRange(Groups.GetChildren(nodeID).Select(x => x.Get<ProductGroup, Guid>(x => x.ID)));
+                }
+                Products.Groups = all ? null : groups.ToArray();
                 Products.Refresh(false, true);
             }
         }

+ 0 - 25
prs.desktop/Panels/StockSummary/ProductGroupTreeView.cs

@@ -1,25 +0,0 @@
-using Comal.Classes;
-using InABox.Clients;
-using InABox.Core;
-using InABox.DynamicGrid;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace PRSDesktop;
-public class ProductGroupTreeView : DynamicDataGrid<ProductGroup>
-{
-    protected override IDynamicGridUIComponent<ProductGroup> CreateUIComponent()
-    {
-        return new DynamicGridTreeUIComponent<ProductGroup>(
-            x => x.ID,
-            x => x.Parent.ID,
-            x => x.Description)
-        {
-            Parent = this
-        };
-    }
-}

+ 1 - 1
prs.desktop/Panels/StockSummary/StockSummaryControl.xaml

@@ -20,7 +20,7 @@
         </dynamicGrid:DynamicSplitPanel.Header>
 
         <dynamicGrid:DynamicSplitPanel.Master>
-            <local:ProductGroupTreeView x:Name="ProductGroups"/>
+            <local:ProductGroupTree x:Name="ProductGroups"/>
         </dynamicGrid:DynamicSplitPanel.Master>
     
         <dynamicGrid:DynamicSplitPanel.Detail>