using System; using System.Collections.Generic; using System.Linq; using System.Windows.Controls; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; namespace PRSDesktop; /// /// Interaction logic for JobBillOfMaterialsPanel.xaml /// public partial class JobBillOfMaterialsPanel : UserControl, IBasePanel, IJobControl, IDataModelSource { private Guid _jobid = Guid.Empty; public JobBillOfMaterialsPanel() { InitializeComponent(); } public CoreRow[] SelectedRows => BillsOfMaterials.SelectedRows; public event DataModelUpdateEvent OnUpdateDataModel; public string SectionName => "Job Bill of Materials"; public DataModel DataModel(Selection selection) { BaseDataModel model = null; if (selection == Selection.Selected) { var bomid = BillsOfMaterials.SelectedRows.Any() ? BillsOfMaterials.SelectedRows.First().Get(x => x.ID) : CoreUtils.FullGuid; model = new BaseDataModel(new Filter(x => x.ID).IsEqualTo(bomid)); } else model = new BaseDataModel(new Filter(x => x.Job.ID).IsEqualTo(ParentID)); var jobfilter = ((ParentID == Guid.Empty) || (ParentID == CoreUtils.FullGuid)) ? new Filter().None() : new Filter(x => x.ID).IsEqualTo(ParentID); model.AddTable(jobfilter, null, true, "Job", true); return model; } public void CreateToolbarButtons(IPanelHost host) { } public void Setup() { BillsOfMaterials.Refresh(true, false); BillOfMaterialsItems.Refresh(true, false); } public void Shutdown() { } public void Refresh() { BillsOfMaterials.Refresh(false, true); } public Dictionary Selected() { var jobfilter = ((ParentID == Guid.Empty) || (ParentID == CoreUtils.FullGuid)) ? new Filter().None() : new Filter(x => x.ID).IsEqualTo(ParentID); return new Dictionary { { typeof(Job).EntityName(), new Client().Query(jobfilter).Rows.ToArray() }, { typeof(JobBillOfMaterials).EntityName(), BillsOfMaterials.SelectedRows }, { typeof(JobBillOfMaterialsItem).EntityName(), BillOfMaterialsItems.SelectedRows } }; } public void Heartbeat(TimeSpan time) { } public bool IsReady { get; set; } public Guid ParentID { get => _jobid; set { _jobid = value; BillsOfMaterials.ParentID = value; BillOfMaterialsItems.JobID = value; } } public JobPanelSettings Settings { get; set; } private void BillsOfMaterials_OnSelectItem(object sender, DynamicGridSelectionEventArgs e) { BillOfMaterialsItems.JobID = ParentID; BillOfMaterialsItems.BillOfMaterialsID = e.Rows?.Any() == true ? e.Rows.First().Get(x => x.ID) : CoreUtils.FullGuid; BillOfMaterialsItems.Refresh(false, true); } }