using System; using System.Linq; using System.Windows; using System.Windows.Controls; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; namespace PRSDesktop { internal class InvoiceLineGrid : DynamicDataGrid { public InvoiceLineGrid() { Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.EditRows, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect); AddButton("Calculate", PRSDesktop.Resources.costcentre.AsBitmapImage(), CalculateLines); } public Guid InvoiceID { get; set; } private bool CalculateLines(Button sender, CoreRow[] rows) { var res = MessageBox.Show("Summarise Time and Materials?", "Confirm Action", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes, MessageBoxOptions.None); if (res == MessageBoxResult.Cancel) return false; var invoice = new Client().Load(new Filter(x => x.ID).IsEqualTo(InvoiceID)).FirstOrDefault(); if (invoice != null) { Utility.CalculateInvoice(invoice, res == MessageBoxResult.Yes); return true; } MessageBox.Show("Please Select or Create an Invoice First!"); return false; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { criteria.Add(new Filter(x => x.InvoiceLink.ID).IsEqualTo(InvoiceID)); base.Reload(criteria, columns, ref sort, action); } protected override InvoiceLine CreateItem() { var result = base.CreateItem(); result.InvoiceLink.ID = InvoiceID; return result; } } }