123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 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;
- /// <summary>
- /// Interaction logic for JobBillOfMaterialsPanel.xaml
- /// </summary>
- 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<JobBillOfMaterials> model = null;
- if (selection == Selection.Selected)
- {
- var bomid = BillsOfMaterials.SelectedRows.Any()
- ? BillsOfMaterials.SelectedRows.First().Get<JobBillOfMaterials, Guid>(x => x.ID)
- : CoreUtils.FullGuid;
- model = new BaseDataModel<JobBillOfMaterials>(new Filter<JobBillOfMaterials>(x => x.ID).IsEqualTo(bomid));
- }
- else
- model = new BaseDataModel<JobBillOfMaterials>(new Filter<JobBillOfMaterials>(x => x.Job.ID).IsEqualTo(ParentID));
- var jobfilter = ((ParentID == Guid.Empty) || (ParentID == CoreUtils.FullGuid))
- ? new Filter<Job>().None()
- : new Filter<Job>(x => x.ID).IsEqualTo(ParentID);
- model.AddTable<Job>(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<string, object[]> Selected()
- {
-
- var jobfilter = ((ParentID == Guid.Empty) || (ParentID == CoreUtils.FullGuid))
- ? new Filter<Job>().None()
- : new Filter<Job>(x => x.ID).IsEqualTo(ParentID);
- return new Dictionary<string, object[]>
- {
- { typeof(Job).EntityName(), new Client<Job>().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<JobBillOfMaterials, Guid>(x => x.ID) : CoreUtils.FullGuid;
- BillOfMaterialsItems.Refresh(false, true);
- }
- }
|