123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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<Shipment>
- {
- private bool bShowAll = true;
- private ReportTemplate template;
- public ShipmentGrid()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns);
- ActionColumns.Add(new DynamicMapColumn<Shipment>(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<Shipment, Guid>(x => x.ID) : Guid.Empty;
- base.SelectItems(rows);
- }
- protected override bool FilterRecord(CoreRow row)
- {
- if (bShowAll)
- return true;
- if (row.Get<Shipment, int>(x => x.ItemCount) > 0)
- return true;
- if (row.Get<Shipment, Guid>(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<Shipment> criteria, Columns<Shipment> columns, ref SortOrder<Shipment> sort,
- Action<CoreTable, Exception> action)
- {
- sort = new SortOrder<Shipment>(x => x.Code);
- base.Reload(criteria, columns, ref sort, action);
- }
- private bool DeliveryDocketClick(CoreRow row)
- {
- var id = row.Get<Shipment, Guid>(x => x.ID);
- var model = new ShipmentDataModel(new Filter<Shipment>(x => x.ID).IsEqualTo(id));
- var client = new Client<ReportTemplate>();
- template = client.Load(
- new Filter<ReportTemplate>(x => x.Section).IsEqualTo("Rack List").And(x => x.Name).IsEqualTo("Delivery Docket"),
- new SortOrder<ReportTemplate>(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<CanDesignReports>());
- 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<Shipment, Guid>(x => x.ID);
- // ShipmentDataModel model = new ShipmentDataModel(new Filter<Shipment>(x => x.ID).IsEqualTo(id));
- // Client<ReportTemplate> client = new Client<ReportTemplate>();
- // template = client.Load(
- // new Filter<ReportTemplate>(x => x.Section).IsEqualTo("Rack List").And(x => x.Name).IsEqualTo("Bar Code"),
- // new SortOrder<ReportTemplate>(x => x.Name)
- // ).FirstOrDefault();
- // if (template == null)
- // template = new ReportTemplate() { Section = "Rack List", Name = "Bar Code" };
- // ReportUtils.PreviewReport(template, model, false, Security.IsAllowed<CanDesignReports>());
- // return false;
- //}
- }
- }
|