using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using Comal.Classes;
using InABox.Core;
using InABox.DynamicGrid;
namespace PRSDesktop
{
///
/// Interaction logic for InvoiceGrid.xaml
///
public partial class InvoicePanel : UserControl, IPanel, IJobControl
{
public InvoicePanel()
{
InitializeComponent();
Invoices.OnSelectItem += Invoices_OnSelectItem;
}
public Guid ParentID
{
get => Invoices.JobID;
set
{
Invoices.JobID = value;
Parts.JobID = value;
Time.JobID = value;
}
}
public JobPanelSettings Settings { get; set; }
public bool IsReady { get; set; }
public event DataModelUpdateEvent OnUpdateDataModel;
public Dictionary Selected()
{
return new Dictionary { { typeof(Invoice).EntityName(), Invoices.SelectedRows } };
}
public void CreateToolbarButtons(IPanelHost host)
{
}
public void Setup()
{
Invoices.Refresh(true, false);
Parts.Refresh(true, false);
Time.Refresh(true, false);
Lines.Refresh(true, false);
}
public void Shutdown()
{
}
public void Refresh()
{
Invoices.Refresh(false, true);
var bData = Invoices.SelectedRows.Any();
Parts.Refresh(false, bData);
Time.Refresh(false, bData);
Lines.Refresh(false, bData);
}
public string SectionName => "Invoice Grid";
public DataModel DataModel(Selection selection)
{
var ids = Invoices.ExtractValues(x => x.ID, selection).ToArray();
return new InvoiceDataModel(new Filter(x => x.ID).InList(ids));
}
public void Heartbeat(TimeSpan time)
{
}
private void Invoices_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
{
if (!IsReady)
return;
var row = e.Rows?.FirstOrDefault();
var jobid = row != null ? row.Get(x => x.JobLink.ID) : CoreUtils.FullGuid;
var invoiceid = row != null ? row.Get(x => x.ID) : CoreUtils.FullGuid;
Parts.JobID = jobid;
Parts.InvoiceID = invoiceid;
Parts.Refresh(false, true);
Time.JobID = jobid;
Time.InvoiceID = invoiceid;
Time.Refresh(false, true);
Lines.InvoiceID = invoiceid;
Lines.Refresh(false, true);
}
}
}