| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Linq;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using PRS.Shared;
- using PRSDesktop.Utils;
- namespace PRSDesktop
- {
- internal class InvoiceLineGrid : DynamicDataGrid<InvoiceLine>
- {
- protected override void Init()
- {
- base.Init();
- AddButton("Calculate", PRSDesktop.Resources.costcentre.AsBitmapImage(), CalculateLines);
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.RecordCount = true;
- options.AddRows = true;
- options.DeleteRows = true;
- options.EditRows = true;
- options.SelectColumns = true;
- options.MultiSelect = true;
- }
- public Invoice Invoice { get; set; }
- private bool CalculateLines(Button sender, CoreRow[] rows)
- {
- InvoiceCalculationSelector selector = new InvoiceCalculationSelector()
- {
- TimeCalculation = InvoiceTimeCalculation.Activity,
- MaterialCalculation = InvoiceMaterialCalculation.Product
- };
- if (selector.ShowDialog() == true)
- {
- var time = selector.TimeCalculation;
- var materials = selector.MaterialCalculation;
- Progress.ShowModal("Calculating Invoice", progress => InvoiceUtilities.GenerateInvoiceLines(Invoice.ID, time, materials, progress));
- return true;
- }
- MessageBox.Show("Please Select or Create an Invoice First!");
- return false;
- }
- protected override void Reload(
- Filters<InvoiceLine> criteria, Columns<InvoiceLine> columns, ref SortOrder<InvoiceLine>? sort,
- CancellationToken token, Action<CoreTable?, Exception?> action)
- {
- criteria.Add(new Filter<InvoiceLine>(x => x.InvoiceLink.ID).IsEqualTo(Invoice.ID));
- base.Reload(criteria, columns, ref sort, token, action);
- }
- public override InvoiceLine CreateItem()
- {
- var result = base.CreateItem();
- result.InvoiceLink.ID = Invoice.ID;
- result.InvoiceLink.Synchronise(Invoice.ID);
- result.SellGL.ID = Invoice.SellGL.ID;
- return result;
- }
- }
- }
|