using System; using System.Windows; using Comal.Classes; using InABox.Core; using InABox.DynamicGrid; namespace PRSDesktop { public class CustomerProductGrid : DynamicDataGrid, ICustomerGrid { protected override void DoReconfigure(FluentList options) { base.DoReconfigure(options); options.AddRange( DynamicGridOption.AddRows, DynamicGridOption.EditRows, DynamicGridOption.SelectColumns, DynamicGridOption.DeleteRows ); } public Customer Customer { get; set; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder? sort, Action action) { criteria.Add(new Filter(x => x.Customer).LinkValid(Customer.ID)); base.Reload(criteria, columns, ref sort, action); } protected override CustomerProduct CreateItem() { var result = base.CreateItem(); result.Customer.ID = Customer.ID; result.Customer.Synchronise(Customer); return result; } protected override BaseEditor? GetEditor(object item, DynamicGridColumn column) { if (column.ColumnName.Equals("Customer.ID")) return new NullEditor(); return base.GetEditor(item, column); } protected override void DoAdd(bool OpenEditorOnDirectEdit = false) { if (Customer.ID == Guid.Empty) MessageBox.Show("Please select a Customer first!"); else base.DoAdd(); } } }