using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Comal.Classes;
using InABox.Clients;
using InABox.Configuration;
using InABox.Core;
using InABox.Core.Postable;
using InABox.DynamicGrid;
using InABox.Wpf;
namespace PRSDesktop
{
///
/// Interaction logic for InvoiceGrid.xaml
///
public partial class InvoicePanel : UserControl, IPanel, IMasterDetailControl
{
public InvoicePanel()
{
InitializeComponent();
Invoices.OnSelectItem += Invoices_OnSelectItem;
}
public Job? Master
{
get => Invoices.Master;
set => Invoices.Master = value;
}
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)
{
AccountsSetupActions.Standard(host);
PostUtils.CreateToolbarButtons(
host,
() => (DataModel(Selection.Selected) as IDataModel)!,
() => Invoices.Refresh(false, true),
true);
}
public void Setup()
{
Invoices.Refresh(true, false);
Parts.Refresh(true, false);
Time.Refresh(true, false);
Lines.Refresh(true, false);
}
public void Shutdown(CancelEventArgs? cancel)
{
}
public void Refresh()
{
Invoices.Refresh(false, true);
}
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)
{
var _invoice = e.Rows?.FirstOrDefault()?.ToObject() ?? new Invoice();
Parts.Invoice = _invoice;
Parts.Refresh(false, true);
Time.Invoice = _invoice;
Time.Refresh(false, true);
Lines.Invoice = _invoice;
Lines.Refresh(false, true);
}
}
}