JobRequisitionPanel.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Imaging;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Windows.Controls;
  9. using com.healthmarketscience.jackcess.impl;
  10. using Comal.Classes;
  11. using InABox.Clients;
  12. using InABox.Configuration;
  13. using InABox.Core;
  14. using InABox.DynamicGrid;
  15. using InABox.Wpf;
  16. using Syncfusion.Pdf.Parsing;
  17. namespace PRSDesktop;
  18. public class JobRequisitionPanelSettings : IUserConfigurationSettings, ISplitPanelSettings
  19. {
  20. public DynamicSplitPanelView ViewType { get; set; } = DynamicSplitPanelView.Combined;
  21. public double AnchorWidth { get; set; } = 500;
  22. }
  23. /// <summary>
  24. /// Interaction logic for JobMaterialPanel.xaml
  25. /// </summary>
  26. public partial class JobRequisitionPanel : UserControl, IPanel<JobMaterial>, IMasterDetailControl<Job>
  27. {
  28. private JobRequisitionPanelSettings Settings;
  29. public JobRequisitionPanel()
  30. {
  31. InitializeComponent();
  32. }
  33. private void LoadSettings()
  34. {
  35. Settings = new UserConfiguration<JobRequisitionPanelSettings>().Load();
  36. SplitPanel.AnchorWidth = Settings.AnchorWidth;
  37. SplitPanel.View = Settings.ViewType;
  38. }
  39. protected void SaveSettings()
  40. {
  41. Settings.AnchorWidth = SplitPanel.AnchorWidth;
  42. Settings.ViewType = SplitPanel.View;
  43. Settings.SaveUser();
  44. }
  45. public Job? Master
  46. {
  47. get => Requisitions.Master;
  48. set => Requisitions.Master = value;
  49. }
  50. public bool IsReady { get; set; }
  51. public event DataModelUpdateEvent? OnUpdateDataModel;
  52. public void CreateToolbarButtons(IPanelHost host)
  53. {
  54. }
  55. public void Setup()
  56. {
  57. LoadSettings();
  58. Requisitions.Refresh(true, false);
  59. Items.Refresh(true, false);
  60. }
  61. public void Shutdown(CancelEventArgs? cancel)
  62. {
  63. }
  64. public void Refresh()
  65. {
  66. if(Settings.ViewType == DynamicSplitPanelView.Detail)
  67. {
  68. Items.Master = null;
  69. Items.Job = Master;
  70. Items.Refresh(false, true);
  71. }
  72. else
  73. {
  74. Requisitions.Refresh(false, true);
  75. }
  76. }
  77. public string SectionName => "Job Requisitions";
  78. public DataModel DataModel(Selection selection)
  79. {
  80. var ids = Requisitions.ExtractValues(x => x.ID, selection).ToArray();
  81. return new AutoDataModel<JobRequisition>(new Filter<JobRequisition>(c => c.ID).InList(ids));
  82. }
  83. public Dictionary<string, object[]> Selected()
  84. {
  85. return new Dictionary<string, object[]>
  86. {
  87. { typeof(JobRequisition).EntityName(), Requisitions.SelectedRows }
  88. };
  89. }
  90. public void Heartbeat(TimeSpan time)
  91. {
  92. }
  93. private void Requisitions_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  94. {
  95. Items.Master = e.Rows?.FirstOrDefault()?.ToObject<JobRequisition>();
  96. Items.Refresh(false, true);
  97. }
  98. private void SplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
  99. {
  100. var changedView = e.View != Settings.ViewType;
  101. SaveSettings();
  102. if (changedView)
  103. {
  104. Refresh();
  105. }
  106. }
  107. }