123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using NPOI.SS.Formula.Functions;
- using Column = InABox.Core.Column;
- namespace PRSDesktop;
- public class StockLocationGrid : DynamicDataGrid<StockLocation>
- {
- public Button StockTakeBtn;
- private BitmapImage _stocktakeheader = PRSDesktop.Resources.schedule_enabled.AsBitmapImage();
- private BitmapImage _stocktakedisabled = PRSDesktop.Resources.schedule_disabled.AsBitmapImage();
- private BitmapImage _stocktakeinprogress = PRSDesktop.Resources.notification.AsBitmapImage();
- private BitmapImage _stocktakenotyetdue = PRSDesktop.Resources.schedule_enabled.AsBitmapImage();
- private BitmapImage _stocktakeoverdue = PRSDesktop.Resources.schedule_overdue.AsBitmapImage();
-
- protected override void Init()
- {
- base.Init();
- HiddenColumns.Add(x => x.Job.ID);
- HiddenColumns.Add(x => x.StocktakeFrequency);
- HiddenColumns.Add(x => x.LastStocktake);
- HiddenColumns.Add(x => x.CurrentStocktake);
- HiddenColumns.Add(x => x.NextStocktake);
-
- ActionColumns.Add(new DynamicImageColumn(StockTakeStatusImage) { ToolTip = StockTakeStatusToolTip, Position = DynamicActionColumnPosition.Start });
-
- if (Security.CanEdit<StockMovement>())
- StockTakeBtn = AddButton("Stock Take", PRSDesktop.Resources.rack.AsBitmapImage(Color.White), DoStockTake);
- OnCustomiseEditor += CustomiseEditor;
- }
- private FrameworkElement? StockTakeStatusToolTip(DynamicActionColumn column, CoreRow? row)
- {
- return row == null
- ? column.TextToolTip("Indicates the Stocktake status of this location")
- : !row.Get<StockLocation, DateTime>(x => x.CurrentStocktake).IsEmpty()
- ? column.TextToolTip("Stocktake in progress")
- : !row.Get<StockLocation, DateTime>(x => x.NextStocktake).IsEmpty()
- ? column.TextToolTip(
- $"Stocktake due on {row.Get<StockLocation, DateTime>(x => x.NextStocktake).Date:dd MMM yy}")
- : column.TextToolTip("No Stocktake scheduled");
- }
- private BitmapImage? StockTakeStatusImage(CoreRow? row)
- {
- return row == null
- ? _stocktakeheader
- : !row.Get<StockLocation, DateTime>(x => x.CurrentStocktake).IsEmpty()
- ? _stocktakeinprogress
- : !row.Get<StockLocation, DateTime>(x => x.NextStocktake).IsEmpty()
- ? row.Get<StockLocation, DateTime>(x => x.NextStocktake).Date > DateTime.Today
- ? _stocktakenotyetdue
- : _stocktakeoverdue
- : _stocktakedisabled;
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.MultiSelect = true;
- options.FilterRows = true;
- options.SelectColumns = true;
- options.RecordCount = true;
- }
- private bool DoStockTake(Button sender, CoreRow[] rows)
- {
- if (!rows.Any())
- {
- MessageBox.Show("Please select at least one row for Stocktake!");
- return false;
- }
- var page = new StockTakeWindow(rows);
- page.Show();
- return true;
- }
-
-
- protected override void DoValidate(StockLocation[] items, List<string> errors)
- {
- base.DoValidate(items, errors);
- var bHoldings = false;
- var bDefault = false;
- var bTransient = false;
- foreach (var item in items)
- {
- bHoldings = bHoldings;
- bDefault = bDefault || (item.Default && !item.Active);
- bTransient = bTransient || (item.Default && item.Type.Equals(StockLocationType.Transient));
- }
- if (bHoldings)
- errors.Add("Non-Empty locations must always be [Active]!");
- if (bDefault)
- errors.Add("Default locations must always be [Active]!");
- if (bTransient)
- errors.Add("Default locations must always be [Permanent]!");
- }
- private void CustomiseEditor(IDynamicEditorForm sender, StockLocation[]? items, DynamicGridColumn column, BaseEditor editor)
- {
- if (string.Equals(column.ColumnName, "Active"))
- {
- //var bHasHoldings = items.FirstOrDefault().Holdings != 0;
- //editor.Editable = bHasHoldings ? Editable.Disabled : Editable.Enabled;
- //if (bHasHoldings)
- // var item = items?.FirstOrDefault();
- // if (item is not null)
- // item.Active = true;
- }
- }
- }
|