123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- using System;
- using System.Collections.Generic;
- 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
- {
- public class DeliveredOnSiteGrid : DynamicDataGrid<DeliveryItem>, IJobControl, IDataModelSource
- {
- private readonly BitmapImage docs = PRSDesktop.Resources.doc_png.AsBitmapImage();
- private BitmapImage Lifter = PRSDesktop.Resources.lifter.AsBitmapImage();
- private readonly BitmapImage setout = PRSDesktop.Resources.design.AsBitmapImage();
- private BitmapImage Tick = PRSDesktop.Resources.tick.AsBitmapImage();
- //bool bTodayOnly = false;
- public DeliveredOnSiteGrid()
- {
- JobID = Guid.Empty;
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.EditRows, DynamicGridOption.FilterRows,
- DynamicGridOption.MultiSelect);
- HiddenColumns.Add(x => x.Delivery.ID);
- //HiddenColumns.Add(x => x.InstalledDate);
- //ActionColumns.Add(new DynamicActionColumn() { Image = InstalledImage, Action = InstalledClick });
- ActionColumns.Add(new DynamicMapColumn<DeliveryItem>(this, x => x.Location) { Position = DynamicActionColumnPosition.Start });
- ActionColumns.Add(new DynamicActionColumn(DocumentsImage, DocumentsClick) { Position = DynamicActionColumnPosition.Start });
- HiddenColumns.Add(x => x.Documents);
- ActionColumns.Add(new DynamicActionColumn(SetoutImage, SetoutClick) { Position = DynamicActionColumnPosition.Start });
- HiddenColumns.Add(x => x.ManufacturingPacketLink.ID);
- HiddenColumns.Add(x => x.ManufacturingPacketLink.WaterMark);
- HiddenColumns.Add(x => x.ManufacturingPacketLink.SetoutLink.ID);
- HiddenColumns.Add(x => x.ManufacturingPacketLink.SetoutLink.Deleted);
- }
- public DateTime StartDate { get; set; } = DateTime.MinValue;
- public DateTime EndDate { get; set; } = DateTime.MaxValue;
- public string Search { get; set; } = "";
- public CoreTable Items { get; private set; }
- public event DataModelUpdateEvent OnUpdateDataModel;
- public string SectionName => "Delivered On Site";
- public DataModel DataModel(Selection selection)
- {
- var ids = ExtractValues(x => x.ID, selection).ToArray();
- return new DeliveryItemDataModel(new Filter<DeliveryItem>(x => x.ID).InList(ids));
- }
- public Guid JobID { get; set; }
- private BitmapImage? SetoutImage(CoreRow arg)
- {
- if (arg == null)
- return null;
- return arg.IsEntityLinkValid<DeliveryItem, SetoutLink>(x => x.ManufacturingPacketLink.SetoutLink) ? setout : null;
- }
- private bool SetoutClick(CoreRow arg)
- {
- if (arg == null)
- return false;
- var setoutid = arg.EntityLinkID<DeliveryItem, SetoutLink>(x => x.ManufacturingPacketLink.SetoutLink) ?? Guid.Empty;
- if (setoutid != Guid.Empty)
- {
- var table = new Client<SetoutDocument>().Query(new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setoutid));
- IEntityDocument[] docs = table.Rows.Select(r => r.ToObject<SetoutDocument>()).ToArray();
- var viewer = new DocumentEditor(docs);
- viewer.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
- viewer.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
- viewer.Watermark = arg.Get<DeliveryItem, string>(x => x.ManufacturingPacketLink.WaterMark);
- viewer.ShowDialog();
- }
- return false;
- }
- private bool DocumentsClick(CoreRow arg)
- {
- if (arg == null)
- return false;
- var docs = new List<IEntityDocument>();
- using (new WaitCursor())
- {
- var deliveryid = arg.Get<DeliveryItem, Guid>(x => x.Delivery.ID);
- var table = new Client<DeliveryDocument>().Query(
- new Filter<DeliveryDocument>(x => x.EntityLink.ID).IsEqualTo(deliveryid)
- );
- foreach (var row in table.Rows)
- docs.Add(row.ToObject<DeliveryDocument>());
- }
- if (docs.Any())
- {
- var editor = new DocumentEditor(docs.ToArray());
- editor.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
- editor.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
- editor.ShowDialog();
- }
- else
- {
- MessageBox.Show("No Documents Available!");
- }
- return false;
- }
- private BitmapImage DocumentsImage(CoreRow arg)
- {
- if (arg == null)
- return docs;
- return arg.Get<Delivery, int>(x => x.Documents) > 0 ? docs : null;
- }
- //private bool InstalledClick(CoreRow arg)
- //{
- // Guid id = arg.Get<DeliveryItem, Guid>(x => x.ID);
- // DeliveryItem item = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
- // if (item != null)
- // {
- // item.InstalledDate = item.InstalledDate.IsEmpty() ? DateTime.Now : DateTime.MinValue;
- // new Client<DeliveryItem>().Save(item, item.InstalledDate.IsEmpty() ? "Installed Flag Cleared" : "Item Marked as Installed");
- // }
- // return true;
- //}
- //private BitmapImage InstalledImage(CoreRow arg)
- //{
- // if (arg == null)
- // return Lifter;
- // DateTime date = arg.Get<DeliveryItem, DateTime>(x => x.InstalledDate);
- // return date.IsEmpty() ? null : Tick;
- //}
- protected override void Reload(Filters<DeliveryItem> criteria, Columns<DeliveryItem> columns, ref SortOrder<DeliveryItem> sort,
- Action<CoreTable, Exception> action)
- {
- var filter = new Filter<DeliveryItem>(x => x.DeliveredDate).IsNotEqualTo(DateTime.MinValue);
- if (!string.IsNullOrWhiteSpace(Search))
- filter = filter.TextSearch(
- Search,
- x => x.Barcode,
- x => x.Description,
- x => x.JobLink.Name,
- x => x.JobLink.JobNumber,
- x => x.Location.Address,
- x => x.Reference,
- x => x.Title,
- x => x.ShipmentCode,
- x => x.ShipmentLink.Code
- );
- criteria.Add(filter);
- criteria.Add(new Filter<DeliveryItem>(x => x.DeliveredDate).IsGreaterThanOrEqualTo(StartDate.Date));
- criteria.Add(new Filter<DeliveryItem>(x => x.DeliveredDate).IsLessThan(EndDate == DateTime.MaxValue
- ? DateTime.MaxValue
- : EndDate.AddDays(1)));
- if (JobID != Guid.Empty)
- criteria.Add(new Filter<DeliveryItem>(x => x.JobLink.ID).IsEqualTo(JobID));
- sort = new SortOrder<DeliveryItem>(x => x.Barcode);
- base.Reload(criteria, columns, ref sort, action);
- }
- }
- }
|