using System; using System.Collections.Generic; using System.Windows.Controls; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; namespace PRSDesktop { public class SupplierBillLineGrid : DynamicOneToManyGrid { public SupplierBillLineGrid() { Options .BeginUpdate() .Clear() .Add(DynamicGridOption.AddRows) .Add(DynamicGridOption.DeleteRows) .Add(DynamicGridOption.SelectColumns) .Add(DynamicGridOption.DirectEdit) .EndUpdate(); AddButton("Import", PRSDesktop.Resources.purchase.AsBitmapImage(), ImportPOLines); HiddenColumns.Add(x => x.TaxCode.ID); HiddenColumns.Add(x => x.TaxCode.Code); HiddenColumns.Add(x => x.TaxCode.Description); HiddenColumns.Add(x => x.TaxCode.Rate); HiddenColumns.Add(x => x.TaxRate); HiddenColumns.Add(x => x.ExTax); HiddenColumns.Add(x => x.Tax); HiddenColumns.Add(x => x.IncTax); HiddenColumns.Add(x => x.Description); } private bool ImportPOLines(Button arg1, CoreRow[] arg2) { MultiSelectDialog dlg = new MultiSelectDialog( new Filter(x => x.PurchaseOrderLink.SupplierLink.ID).IsEqualTo(Item.SupplierLink.ID).And(x => x.PurchaseOrderLink.ClosedDate).IsEqualTo(DateTime.MinValue), new Columns ( x => x.ID, x => x.Description, x => x.Product.Code, x => x.ReceivedDate, x => x.Consignment.Number, x => x.PurchaseOrderLink.PONumber )); if (dlg.ShowDialog() == true) { var items = new Client().Query( new Filter(x => x.ID).InList(dlg.IDs()), new Columns(x => x.ID) .Add(x => x.Description) .Add(x => x.TaxCode.ID) .Add(x => x.TaxCode.Code) .Add(x => x.TaxCode.Description) .Add(x => x.TaxCode.Rate) .Add(x => x.TaxRate) .Add(x => x.ExTax) .Add(x => x.Tax) .Add(x => x.IncTax) .Add(x => x.Created) .Add(x => x.PurchaseOrderLink.ID) .Add(x => x.PurchaseOrderLink.PONumber) .Add(x => x.Product.ID) .Add(x => x.Product.Code) .Add(x => x.Product.Name) ); foreach (var row in items.Rows) { var line = new BillLine(); line.OrderItem.ID = row.Get(x => x.ID); line.OrderItem.PurchaseOrderLink.ID = row.Get(x => x.PurchaseOrderLink.ID); line.OrderItem.PurchaseOrderLink.PONumber = row.Get(x => x.PurchaseOrderLink.PONumber); var description = new List(); if (row.Get(x => x.Product.ID) != Guid.Empty) description.Add(string.Format("{0} : {1}", row.Get(x => x.Product.Code), row.Get(x => x.Product.Name))); var Description = row.Get(x => x.Description); if (!string.IsNullOrEmpty(Description)) description.Add(Description); line.Description = string.Join("\n", description); line.ExTax = row.Get(x => x.ExTax); line.TaxCode.ID = row.Get(x => x.TaxCode.ID); line.TaxCode.Code = row.Get(x => x.TaxCode.Code); line.TaxCode.Description = row.Get(x => x.TaxCode.Description); line.TaxCode.Rate = row.Get(x => x.TaxCode.Rate); //line.TaxRate = row.Get(x => x.TaxRate); //line.Tax = row.Get(x => x.Tax); //line.IncTax = row.Get(x => x.IncTax); line.OrderItem.Product.ID = row.Get(x => x.Product.ID); line.OrderItem.Product.Code = row.Get(x => x.Product.Code); line.OrderItem.Product.Name = row.Get(x => x.Product.Name); Items.Add(line); } return true; } return false; } } }