12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop
- {
- public class InvoicePartsGrid : DynamicDataGrid<DeliveryItem>
- {
- private readonly BitmapImage gray = PRSDesktop.Resources.tick.AsGrayScale().AsBitmapImage();
- private readonly BitmapImage green = PRSDesktop.Resources.tick.AsBitmapImage();
- public InvoicePartsGrid()
- {
- ColumnsTag = "InvoiceParts";
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect);
- HiddenColumns.Add(x => x.InvoiceLink.ID);
- HiddenColumns.Add(x => x.InvoiceLink.Deleted);
- ActionColumns.Add(new DynamicActionColumn(InvoicedImage, InvoiceOne));
- AddButton("Select All", green, InvoiceAll);
- AddButton("Clear All", gray, InvoiceAll);
- }
- public Guid JobID { get; set; }
- public Guid InvoiceID { get; set; }
- private bool InvoiceAll(Button sender, CoreRow[] rows)
- {
- if (InvoiceID != Guid.Empty)
- {
- Progress.Show("Please wait..");
- var bAdd = sender.Content.Equals("Select All");
- var filter = new Filter<DeliveryItem>(x => x.JobLink.ID).IsEqualTo(JobID);
- if (bAdd)
- filter = filter.And(x => x.InvoiceLink).NotLinkValid();
- else
- filter = filter.And(x => x.InvoiceLink).LinkValid(InvoiceID);
- var items = new Client<DeliveryItem>().Load(filter);
- foreach (var item in items)
- item.InvoiceLink.ID = bAdd ? InvoiceID : Guid.Empty;
- new Client<DeliveryItem>().Save(items, bAdd ? "Added to Invoice" : "Removed From Invoice");
- Progress.Close();
- return true;
- }
- MessageBox.Show("Please Select or Create an Invoice First!");
- return false;
- }
- private bool InvoiceOne(CoreRow arg)
- {
- if (InvoiceID != Guid.Empty)
- {
- if (arg == null)
- return false;
- var id = arg.Get<TimeSheet, Guid>(x => x.ID);
- var item = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
- if (item != null)
- {
- item.InvoiceLink.ID = InvoiceID;
- new Client<DeliveryItem>().Save(item, "Added to Invoice");
- return true;
- }
- }
- MessageBox.Show("Please Select or Create an Invoice First!");
- return false;
- }
- private BitmapImage InvoicedImage(CoreRow arg)
- {
- if (arg == null)
- return green;
- if (!Entity.IsEntityLinkValid<TimeSheet, InvoiceLink>(x => x.InvoiceLink, arg))
- return gray;
- return green;
- }
- 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.JobLink.ID).IsEqualTo(JobID); //.And(x => x.DeliveredDate).IsNotEqualTo(DateTime.MinValue);
- filter.Ands.Add(new Filter<DeliveryItem>(x => x.InvoiceLink.ID).IsEqualTo(InvoiceID).Or(x => x.InvoiceLink.ID).IsEqualTo(Guid.Empty));
- criteria.Add(filter);
- base.Reload(criteria, columns, ref sort, action);
- }
- }
- }
|