|  | @@ -8,88 +8,87 @@ using InABox.Core;
 | 
	
		
			
				|  |  |  using InABox.DynamicGrid;
 | 
	
		
			
				|  |  |  using InABox.WPF;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -namespace PRSDesktop
 | 
	
		
			
				|  |  | +namespace PRSDesktop;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +public class CustomerContactGrid : DynamicDataGrid<CustomerContact>, ICustomerGrid
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    public class CustomerContactGrid : DynamicDataGrid<CustomerContact>, ICustomerGrid
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    public CustomerContactGrid()
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        public CustomerContactGrid()
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            HiddenColumns.Add(x=>x.Customer.DefaultContact.ID);
 | 
	
		
			
				|  |  | -            HiddenColumns.Add(x=>x.Contact.ID);
 | 
	
		
			
				|  |  | -            HiddenColumns.Add(x=>x.Customer.ID);
 | 
	
		
			
				|  |  | -            ActionColumns.Add(new DynamicImageColumn(IsDefaultImage, SelectDefaultAction) { Position = DynamicActionColumnPosition.Start });
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        protected override void DoReconfigure(DynamicGridOptions options)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            base.DoReconfigure(options);
 | 
	
		
			
				|  |  | -            options.AddRows = true;
 | 
	
		
			
				|  |  | -            options.EditRows = true;
 | 
	
		
			
				|  |  | -            options.SelectColumns = true;
 | 
	
		
			
				|  |  | -            options.DeleteRows = true;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        
 | 
	
		
			
				|  |  | -        private BitmapImage? IsDefaultImage(CoreRow? row)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            return row == null
 | 
	
		
			
				|  |  | +        HiddenColumns.Add(x=>x.Customer.DefaultContact.ID);
 | 
	
		
			
				|  |  | +        HiddenColumns.Add(x=>x.Contact.ID);
 | 
	
		
			
				|  |  | +        HiddenColumns.Add(x=>x.Customer.ID);
 | 
	
		
			
				|  |  | +        ActionColumns.Add(new DynamicImageColumn(IsDefaultImage, SelectDefaultAction) { Position = DynamicActionColumnPosition.Start });
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    protected override void DoReconfigure(DynamicGridOptions options)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        base.DoReconfigure(options);
 | 
	
		
			
				|  |  | +        options.AddRows = true;
 | 
	
		
			
				|  |  | +        options.EditRows = true;
 | 
	
		
			
				|  |  | +        options.SelectColumns = true;
 | 
	
		
			
				|  |  | +        options.DeleteRows = true;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    private BitmapImage? IsDefaultImage(CoreRow? row)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        return row == null
 | 
	
		
			
				|  |  | +            ? tick
 | 
	
		
			
				|  |  | +            : row.Get<CustomerContact, Guid>(x => x.Customer.DefaultContact.ID) == row.Get<CustomerContact, Guid>(x => x.Contact.ID)
 | 
	
		
			
				|  |  |                  ? tick
 | 
	
		
			
				|  |  | -                : row.Get<CustomerContact, Guid>(x => x.Customer.DefaultContact.ID) == row.Get<CustomerContact, Guid>(x => x.Contact.ID)
 | 
	
		
			
				|  |  | -                    ? tick
 | 
	
		
			
				|  |  | -                    : null;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +                : null;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        private bool SelectDefaultAction(CoreRow? row)
 | 
	
		
			
				|  |  | +    private bool SelectDefaultAction(CoreRow? row)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if ((row == null) ||row.Get<CustomerContact, Guid>(x => x.Customer.DefaultContact.ID) == row.Get<CustomerContact, Guid>(x => x.Contact.ID))
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        using (new WaitCursor())
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | -            if ((row == null) ||row.Get<CustomerContact, Guid>(x => x.Customer.DefaultContact.ID) == row.Get<CustomerContact, Guid>(x => x.Contact.ID))
 | 
	
		
			
				|  |  | -                return false;
 | 
	
		
			
				|  |  | -            using (new WaitCursor())
 | 
	
		
			
				|  |  | +            var customer = new Client<Customer>().Query(
 | 
	
		
			
				|  |  | +                new Filter<Customer>(x => x.ID).IsEqualTo(row.Get<CustomerContact, Guid>(x => x.Customer.ID)),
 | 
	
		
			
				|  |  | +                Columns.Required<Customer>().Add(x => x.ID).Add(x => x.DefaultContact.ID)
 | 
	
		
			
				|  |  | +            ).Rows.FirstOrDefault()?.ToObject<Customer>();
 | 
	
		
			
				|  |  | +            if (customer != null)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | -                var customer = new Client<Customer>().Query(
 | 
	
		
			
				|  |  | -                    new Filter<Customer>(x => x.ID).IsEqualTo(row.Get<CustomerContact, Guid>(x => x.Customer.ID)),
 | 
	
		
			
				|  |  | -                    Columns.Required<Customer>().Add(x => x.ID).Add(x => x.DefaultContact.ID)
 | 
	
		
			
				|  |  | -                ).Rows.FirstOrDefault()?.ToObject<Customer>();
 | 
	
		
			
				|  |  | -                if (customer != null)
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    customer.DefaultContact.ID = row.Get<CustomerContact, Guid>(x => x.Contact.ID);
 | 
	
		
			
				|  |  | -                    new Client<Customer>().Save(customer, "Updated Default Contact");
 | 
	
		
			
				|  |  | -                    return true;
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +                customer.DefaultContact.ID = row.Get<CustomerContact, Guid>(x => x.Contact.ID);
 | 
	
		
			
				|  |  | +                new Client<Customer>().Save(customer, "Updated Default Contact");
 | 
	
		
			
				|  |  | +                return true;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            return false;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        return false;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public Customer Customer { get; set; }
 | 
	
		
			
				|  |  | +    public Customer Customer { get; set; }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        protected override void Reload(Filters<CustomerContact> criteria, Columns<CustomerContact> columns, ref SortOrder<CustomerContact>? sort, Action<CoreTable?, Exception?> action)
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            criteria.Add(new Filter<CustomerContact>(x => x.Customer).LinkValid(Customer.ID));
 | 
	
		
			
				|  |  | -            base.Reload(criteria, columns, ref sort, action);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    protected override void Reload(Filters<CustomerContact> criteria, Columns<CustomerContact> columns, ref SortOrder<CustomerContact>? sort, Action<CoreTable?, Exception?> action)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        criteria.Add(new Filter<CustomerContact>(x => x.Customer).LinkValid(Customer.ID));
 | 
	
		
			
				|  |  | +        base.Reload(criteria, columns, ref sort, action);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public override CustomerContact CreateItem()
 | 
	
		
			
				|  |  | -        {
 | 
	
		
			
				|  |  | -            var result = base.CreateItem();
 | 
	
		
			
				|  |  | -            result.Customer.ID = Customer.ID;
 | 
	
		
			
				|  |  | -            result.Customer.Synchronise(Customer);
 | 
	
		
			
				|  |  | -            return result;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    public override CustomerContact 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 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();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +    protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        if (Customer.ID == Guid.Empty)
 | 
	
		
			
				|  |  | +            MessageBox.Show("Please select a Customer first!");
 | 
	
		
			
				|  |  | +        else
 | 
	
		
			
				|  |  | +            base.DoAdd();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |