123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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<Consignment>
- {
- //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<Consignment, DateTime>(x => x.Closed).IsEmpty())
- // {
- // MessageBox.Show("Consignment is already closed!");
- // return false;
- // }
- // Guid id = rows.First().Get<Consignment, Guid>(x => x.ID);
- // DateTime now = DateTime.Now;
- // using (new WaitCursor())
- // {
- // PurchaseOrderItem[] items = new Client<PurchaseOrderItem>().Load(new Filter<PurchaseOrderItem>(x => x.Consignment.ID).IsEqualTo(id).And(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue));
- // foreach (var item in items)
- // item.ReceivedDate = now;
- // new Client<PurchaseOrderItem>().Save(items, "Consignment Received");
- // //Consignment consignment = LoadItem(rows.First());
- // //consignment.Closed = now;
- // //new Client<Consignment>().Save(consignment, "Consignment Received");
- // }
- // return true;
- //}
- //protected override void SelectItems(CoreRow[] rows)
- //{
- // receive.IsEnabled = (rows != null) && rows.Any(r=>r.Get<Consignment, DateTime>(c => c.Closed).IsEmpty());
- // base.SelectItems(rows);
- //}
- protected override void Reload(Filters<Consignment> criteria, Columns<Consignment> columns, ref SortOrder<Consignment> sort,
- Action<CoreTable, Exception> action)
- {
- if (!ShowAll)
- criteria.Add(new Filter<Consignment>(x => x.ActualWarehouseArrival).IsEqualTo(DateTime.MinValue));
- if (SelectedCategory != CoreUtils.FullGuid)
- criteria.Add(new Filter<Consignment>(x => x.Category.ID).IsEqualTo(SelectedCategory));
- if (SelectedType != CoreUtils.FullGuid)
- criteria.Add(new Filter<Consignment>(x => x.Type.ID).IsEqualTo(SelectedType));
- base.Reload(criteria, columns, ref sort, action);
- }
- private bool ShowBillOfLading(CoreRow arg)
- {
- var id = arg.Get<Consignment, Guid>(x => x.BillOfLading.ID);
- if (!Entity.IsEntityLinkValid<Consignment, PDFDocumentLink>(x => x.BillOfLading, arg))
- return false;
- var doc = new Client<Document>().Load(new Filter<Document>(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<Consignment, Guid>(x => x.BillOfLading.ID);
- return !Entity.IsEntityLinkValid<Consignment, PDFDocumentLink>(x => x.BillOfLading, arg) ? null : PRSDesktop.Resources.doc_pdf.AsBitmapImage();
- }
- }
- }
|