using System; using System.Drawing; using System.Linq; using System.Windows.Controls; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using InABox.Reports; using InABox.Core.Reports; using InABox.Wpf.Reports; using InABox.WPF; namespace PRSDesktop { public class ShipmentGrid : DynamicDataGrid { private bool bShowAll = true; private ReportTemplate template; public ShipmentGrid() { Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns); ActionColumns.Add(new DynamicMapColumn(this, x => x.TrackerLink.Location)); HiddenColumns.Add(x => x.BarCode); HiddenColumns.Add(x => x.ItemCount); HiddenColumns.Add(x => x.Delivery.ID); //ActionColumns.Add(new DynamicImageColumn() { Action = DeliveryDocketClick, Image = (o) => PRSDesktop.Resources.printer.AsBitmapImage() }); AddButton("Hide Empty", PRSDesktop.Resources.target.AsBitmapImage(Color.White), ToggleVisible); //AddButton("", PRSDesktop.Resources.barcode.AsBitmapImage(), PrintBarcodeClick); } public Guid CurrentShipmentID { get; set; } protected override void SelectItems(CoreRow[] rows) { CurrentShipmentID = rows.Any() ? rows.First().Get(x => x.ID) : Guid.Empty; base.SelectItems(rows); } protected override bool FilterRecord(CoreRow row) { if (bShowAll) return true; if (row.Get(x => x.ItemCount) > 0) return true; if (row.Get(x => x.ID) == CurrentShipmentID) return true; return false; } private bool ToggleVisible(Button sender, CoreRow[] rows) { if (bShowAll) { UpdateButton(sender, PRSDesktop.Resources.target.AsBitmapImage(Color.White), "Show All"); bShowAll = false; } else { UpdateButton(sender, PRSDesktop.Resources.target.AsBitmapImage(Color.White), "Hide Empty"); bShowAll = true; } return true; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { sort = new SortOrder(x => x.Code); base.Reload(criteria, columns, ref sort, action); } private bool DeliveryDocketClick(CoreRow row) { var id = row.Get(x => x.ID); var model = new ShipmentDataModel(new Filter(x => x.ID).IsEqualTo(id)); var client = new Client(); template = client.Load( new Filter(x => x.Section).IsEqualTo("Rack List").And(x => x.Name).IsEqualTo("Delivery Docket"), new SortOrder(x => x.Name) ).FirstOrDefault(); if (template == null) template = new ReportTemplate { DataModel = model.Name, Section = "Rack List", Name = "Delivery Docket" }; ReportUtils.PreviewReport(template, model, false, Security.IsAllowed()); return false; } //private bool PrintBarcodeClick(Button btn, CoreRow[] rows) //{ // if (rows.Length != 1) // { // MessageBox.Show("Please select a Rack first!"); // return false; // } // CoreRow row = rows.First(); // Guid id = row.Get(x => x.ID); // ShipmentDataModel model = new ShipmentDataModel(new Filter(x => x.ID).IsEqualTo(id)); // Client client = new Client(); // template = client.Load( // new Filter(x => x.Section).IsEqualTo("Rack List").And(x => x.Name).IsEqualTo("Bar Code"), // new SortOrder(x => x.Name) // ).FirstOrDefault(); // if (template == null) // template = new ReportTemplate() { Section = "Rack List", Name = "Bar Code" }; // ReportUtils.PreviewReport(template, model, false, Security.IsAllowed()); // return false; //} } }