|
@@ -191,6 +191,11 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public StockForecastOrderingGrid()
|
|
|
+ {
|
|
|
+ HiddenColumns.Add(x => x.Product.Image.ID);
|
|
|
+ }
|
|
|
+
|
|
|
#region UI Component
|
|
|
|
|
|
private Component? _uiComponent;
|
|
@@ -214,6 +219,8 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
{
|
|
|
Parent = grid;
|
|
|
Grid = grid;
|
|
|
+
|
|
|
+ DataGrid.FrozenColumnCount = 7;
|
|
|
}
|
|
|
|
|
|
protected override Brush? GetCellSelectionBackgroundBrush()
|
|
@@ -269,6 +276,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
options.Clear().Add(DynamicGridOption.FilterRows);
|
|
|
}
|
|
|
|
|
|
+ private bool _loadedData = false;
|
|
|
private void LoadData()
|
|
|
{
|
|
|
var supplierColumns = new Columns<SupplierProduct>(x => x.ID)
|
|
@@ -293,20 +301,27 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
var quantities = new StockForecastOrderingItemQuantity[Suppliers.Length];
|
|
|
for(int i = 0; i < Suppliers.Length; ++i)
|
|
|
{
|
|
|
- var qty = new StockForecastOrderingItemQuantity();
|
|
|
- quantities[i] = qty;
|
|
|
- qty.Changed += () =>
|
|
|
- {
|
|
|
- var row = Data.Rows[itemIdx];
|
|
|
- InvalidateRow(row);
|
|
|
- DoChanged();
|
|
|
- };
|
|
|
+ quantities[i] = CreateQuantity(itemIdx);
|
|
|
}
|
|
|
|
|
|
item.SetQuantities(quantities);
|
|
|
}
|
|
|
|
|
|
CalculateQuantities();
|
|
|
+
|
|
|
+ _loadedData = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private StockForecastOrderingItemQuantity CreateQuantity(int itemIdx)
|
|
|
+ {
|
|
|
+ var qty = new StockForecastOrderingItemQuantity();
|
|
|
+ qty.Changed += () =>
|
|
|
+ {
|
|
|
+ var row = Data.Rows[itemIdx];
|
|
|
+ InvalidateRow(row);
|
|
|
+ DoChanged();
|
|
|
+ };
|
|
|
+ return qty;
|
|
|
}
|
|
|
|
|
|
private void CalculateQuantities()
|
|
@@ -359,15 +374,21 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
|
|
|
protected override DynamicGridColumns LoadColumns()
|
|
|
{
|
|
|
- LoadData();
|
|
|
+ if (!_loadedData)
|
|
|
+ {
|
|
|
+ LoadData();
|
|
|
+ }
|
|
|
+ ActionColumns.Clear();
|
|
|
|
|
|
ActionColumns.Add(new DynamicImageColumn(Warning_Image) { Position = DynamicActionColumnPosition.Start });
|
|
|
+ ActionColumns.Add(new DynamicImagePreviewColumn<StockForecastOrderingItem>(x => x.Product.Image) { Position = DynamicActionColumnPosition.Start });
|
|
|
|
|
|
var columns = new DynamicGridColumns();
|
|
|
- columns.Add<StockForecastOrderingItem, string>(x => x.Product.Code, 120, "Product", "", Alignment.MiddleCenter);
|
|
|
- columns.Add<StockForecastOrderingItem, string>(x => x.Style.Code, 120, "Style", "", Alignment.MiddleCenter);
|
|
|
- columns.Add<StockForecastOrderingItem, string>(x => x.Dimensions.UnitSize, 0, "Size", "", Alignment.MiddleLeft);
|
|
|
- columns.Add<StockForecastOrderingItem, double>(x => x.RequiredQuantity, 0, "Required", "", Alignment.MiddleLeft);
|
|
|
+ columns.Add<StockForecastOrderingItem, string>(x => x.Product.Code, 120, "Product Code", "", Alignment.MiddleCenter);
|
|
|
+ columns.Add<StockForecastOrderingItem, string>(x => x.Product.Name, 200, "Product Name", "", Alignment.MiddleLeft);
|
|
|
+ columns.Add<StockForecastOrderingItem, string>(x => x.Style.Code, 80, "Style", "", Alignment.MiddleCenter);
|
|
|
+ columns.Add<StockForecastOrderingItem, string>(x => x.Dimensions.UnitSize, 80, "Size", "", Alignment.MiddleCenter);
|
|
|
+ columns.Add<StockForecastOrderingItem, double>(x => x.RequiredQuantity, 80, "Required", "", Alignment.MiddleCenter);
|
|
|
|
|
|
QuantityColumns = new DynamicActionColumn[Suppliers.Length];
|
|
|
CostColumns = new DynamicActionColumn[Suppliers.Length];
|
|
@@ -378,9 +399,96 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
InitialiseSupplierColumn(i);
|
|
|
}
|
|
|
|
|
|
+ ActionColumns.Add(new DynamicMenuColumn(BuildMenu));
|
|
|
+
|
|
|
return columns;
|
|
|
}
|
|
|
|
|
|
+ private void EditSupplierProductGrid(DynamicGrid<SupplierProduct> grid)
|
|
|
+ {
|
|
|
+ grid.OnCustomiseEditor += (sender, items, column, editor) =>
|
|
|
+ {
|
|
|
+ if(new Column<SupplierProduct>(x => x.SupplierLink.ID).IsEqualTo(column.ColumnName)
|
|
|
+ || new Column<SupplierProduct>(x => x.Product.ID).IsEqualTo(column.ColumnName)
|
|
|
+ || new Column<SupplierProduct>(x => x.Style.ID).IsEqualTo(column.ColumnName)
|
|
|
+ || new Column<SupplierProduct>(x => x.Job.ID).IsEqualTo(column.ColumnName)
|
|
|
+ || new Column<SupplierProduct>(x => x.Dimensions).IsEqualTo(column.ColumnName))
|
|
|
+ {
|
|
|
+ editor.Editable = editor.Editable.Combine(Editable.Disabled);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
|
|
|
+ {
|
|
|
+ if (row is null) return;
|
|
|
+
|
|
|
+ column.AddItem("New Supplier", null, row =>
|
|
|
+ {
|
|
|
+ if (row is null) return;
|
|
|
+
|
|
|
+ var selection = new MultiSelectDialog<Supplier>(
|
|
|
+ new Filter<Supplier>(x => x.ID).NotInList(Suppliers.Select(x => x.ID).ToArray()),
|
|
|
+ new Columns<Supplier>(x => x.ID).Add(x => x.Code), multiselect: false);
|
|
|
+ if (selection.ShowDialog() != true)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var supplier = selection.Data().Rows.First().ToObject<Supplier>();
|
|
|
+ var productInstance = LoadItem(row);
|
|
|
+
|
|
|
+ var supplierProduct = new SupplierProduct();
|
|
|
+ supplierProduct.Product.CopyFrom(productInstance.Product);
|
|
|
+ supplierProduct.Style.CopyFrom(productInstance.Style);
|
|
|
+ supplierProduct.Dimensions.CopyFrom(productInstance.Dimensions);
|
|
|
+ supplierProduct.SupplierLink.CopyFrom(supplier);
|
|
|
+
|
|
|
+ if (DynamicGridUtils.EditEntity(supplierProduct, customiseGrid: EditSupplierProductGrid))
|
|
|
+ {
|
|
|
+ SupplierProducts.Add(supplierProduct);
|
|
|
+ var newSuppliers = new SupplierLink[Suppliers.Length + 1];
|
|
|
+ var newIdx = Suppliers.Length;
|
|
|
+
|
|
|
+ for (int i = 0; i < Suppliers.Length; i++)
|
|
|
+ {
|
|
|
+ newSuppliers[i] = Suppliers[i];
|
|
|
+ }
|
|
|
+ newSuppliers[newIdx] = supplierProduct.SupplierLink;
|
|
|
+
|
|
|
+ foreach (var (itemIdx, item) in Items.WithIndex())
|
|
|
+ {
|
|
|
+ var populateSupplierProduct = GetSupplierProduct(item);
|
|
|
+
|
|
|
+ var quantities = new StockForecastOrderingItemQuantity[newSuppliers.Length];
|
|
|
+ for (int i = 0; i < Suppliers.Length; ++i)
|
|
|
+ {
|
|
|
+ quantities[i] = item.GetQuantity(i);
|
|
|
+ }
|
|
|
+ var newQty = CreateQuantity(itemIdx);
|
|
|
+
|
|
|
+ quantities[newIdx] = newQty;
|
|
|
+ if (OrderType == StockForecastOrderingType.StockOrder)
|
|
|
+ {
|
|
|
+ newQty.StockTotal = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (var id in item.GetJobRequiredQuantities().Keys)
|
|
|
+ {
|
|
|
+ newQty.JobTotals[id] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.SetQuantities(quantities);
|
|
|
+ }
|
|
|
+
|
|
|
+ Suppliers = newSuppliers;
|
|
|
+
|
|
|
+ Refresh(true, true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private BitmapImage? Warning_Image(CoreRow? row)
|
|
|
{
|
|
|
if (row is null) return _warning;
|
|
@@ -625,7 +733,7 @@ public class StockForecastOrderingGrid : DynamicItemsListGrid<StockForecastOrder
|
|
|
supplierProduct.Dimensions.CopyFrom(item.Dimensions);
|
|
|
supplierProduct.SupplierLink.CopyFrom(Suppliers[supplierIdx]);
|
|
|
|
|
|
- if (DynamicGridUtils.EditEntity(supplierProduct))
|
|
|
+ if (DynamicGridUtils.EditEntity(supplierProduct, customiseGrid: EditSupplierProductGrid))
|
|
|
{
|
|
|
SupplierProducts.Add(supplierProduct);
|
|
|
InvalidateGrid();
|