using System; using System.Diagnostics; using System.IO; using System.Linq; using System.Windows; using System.Windows.Media.Imaging; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; namespace PRSDesktop { internal class ConsignmentGrid : DynamicDataGrid { //Button receive = null; public ConsignmentGrid() { Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.FilterRows); ActionColumns.Add(new DynamicActionColumn(ConsignmentImage, ShowBillOfLading) { Position = DynamicActionColumnPosition.Start }); HiddenColumns.Add(x => x.BillOfLading.ID); HiddenColumns.Add(x => x.Closed); HiddenColumns.Add(x => x.Supplier.Code); } public bool ShowAll { get; set; } public Guid SelectedCategory { get; set; } public Guid SelectedType { get; set; } //private bool ReceiveConsignment(Button sender, CoreRow[] rows) //{ // if (!rows.Any()) // { // MessageBox.Show("Please select a row first"); // return false; // } // if (!rows.First().Get(x => x.Closed).IsEmpty()) // { // MessageBox.Show("Consignment is already closed!"); // return false; // } // Guid id = rows.First().Get(x => x.ID); // DateTime now = DateTime.Now; // using (new WaitCursor()) // { // PurchaseOrderItem[] items = new Client().Load(new Filter(x => x.Consignment.ID).IsEqualTo(id).And(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue)); // foreach (var item in items) // item.ReceivedDate = now; // new Client().Save(items, "Consignment Received"); // //Consignment consignment = LoadItem(rows.First()); // //consignment.Closed = now; // //new Client().Save(consignment, "Consignment Received"); // } // return true; //} //protected override void SelectItems(CoreRow[] rows) //{ // receive.IsEnabled = (rows != null) && rows.Any(r=>r.Get(c => c.Closed).IsEmpty()); // base.SelectItems(rows); //} protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { if (!ShowAll) criteria.Add(new Filter(x => x.ActualWarehouseArrival).IsEqualTo(DateTime.MinValue)); if (SelectedCategory != CoreUtils.FullGuid) criteria.Add(new Filter(x => x.Category.ID).IsEqualTo(SelectedCategory)); if (SelectedType != CoreUtils.FullGuid) criteria.Add(new Filter(x => x.Type.ID).IsEqualTo(SelectedType)); base.Reload(criteria, columns, ref sort, action); } private bool ShowBillOfLading(CoreRow arg) { var id = arg.Get(x => x.BillOfLading.ID); if (!Entity.IsEntityLinkValid(x => x.BillOfLading, arg)) return false; var doc = new Client().Load(new Filter(x => x.ID).IsEqualTo(id)).FirstOrDefault(); if (doc == null) { MessageBox.Show("Unable to Load Document"); return false; } var ext = Path.GetExtension(doc.FileName); var tmpfile = Path.ChangeExtension(Path.GetTempFileName(), ext); File.WriteAllBytes(tmpfile, doc.Data); var gsProcessInfo = new ProcessStartInfo(); gsProcessInfo.Verb = "open"; gsProcessInfo.WindowStyle = ProcessWindowStyle.Normal; gsProcessInfo.FileName = tmpfile; gsProcessInfo.UseShellExecute = true; Process.Start(gsProcessInfo); return false; } private BitmapImage? ConsignmentImage(CoreRow arg) { if (arg == null) return PRSDesktop.Resources.doc_pdf.AsBitmapImage(); var id = arg.Get(x => x.BillOfLading.ID); return !Entity.IsEntityLinkValid(x => x.BillOfLading, arg) ? null : PRSDesktop.Resources.doc_pdf.AsBitmapImage(); } } }