ReadyToGoPanel.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Input;
  8. using Comal.Classes;
  9. using InABox.Configuration;
  10. using InABox.Core;
  11. using InABox.DynamicGrid;
  12. using InABox.Wpf;
  13. namespace PRSDesktop
  14. {
  15. public class ReadyToGoGlobalSettings : BaseObject, IGlobalConfigurationSettings
  16. {
  17. public int PageSize { get; set; } = 5000;
  18. }
  19. /// <summary>
  20. /// Interaction logic for ItemsPanel.xaml
  21. /// </summary>
  22. public partial class ReadyToGoPanel : UserControl, IPanel<DeliveryItem>
  23. {
  24. private ReadyToGoGlobalSettings _globalSettings = new();
  25. public ReadyToGoPanel()
  26. {
  27. _globalSettings = new GlobalConfiguration<ReadyToGoGlobalSettings>().Load();
  28. InitializeComponent();
  29. }
  30. public bool IsReady { get; set; }
  31. public event DataModelUpdateEvent? OnUpdateDataModel;
  32. public Dictionary<string, object[]> Selected()
  33. {
  34. return new Dictionary<string, object[]>(); // { { typeof(DeliveryItem).EntityName(), Items.SelectedRows } };
  35. }
  36. public void Setup()
  37. {
  38. Items.Reconfigure();
  39. Items.Refresh(true, false);
  40. }
  41. private void Items_OnReconfigure(DynamicGridOptions options)
  42. {
  43. options.PageSize = _globalSettings.PageSize;
  44. }
  45. public void Shutdown(CancelEventArgs? cancel)
  46. {
  47. Items.Shutdown();
  48. }
  49. public void CreateToolbarButtons(IPanelHost host)
  50. {
  51. host.CreateSetupAction(new PanelAction() { Caption = "Delivered On Site Settings", Image = PRSDesktop.Resources.product, OnExecute =
  52. (obj) =>
  53. {
  54. var grid = new DynamicItemsListGrid<ReadyToGoGlobalSettings>();
  55. if (grid.EditItems(new ReadyToGoGlobalSettings[] { _globalSettings }))
  56. {
  57. new GlobalConfiguration<ReadyToGoGlobalSettings>().Save(_globalSettings);
  58. Items.Reconfigure();
  59. Refresh();
  60. }
  61. }
  62. });
  63. }
  64. public void Refresh()
  65. {
  66. Items.Refresh(false, true);
  67. }
  68. public string SectionName => "Ready To Go";
  69. public DataModel DataModel(Selection selection)
  70. {
  71. var ids = Items.ExtractValues(x => x.ID, selection).ToArray();
  72. return new DeliveryItemDataModel(new Filter<DeliveryItem>(x => x.ID).InList(ids));
  73. }
  74. public void Heartbeat(TimeSpan time)
  75. {
  76. }
  77. public Type DataType()
  78. {
  79. return typeof(DeliveryItem);
  80. }
  81. private void SearchBox_KeyUp(object sender, KeyEventArgs e)
  82. {
  83. if (e.Key == Key.Enter)
  84. {
  85. Items.Search = SearchBox.Text;
  86. Items.Refresh(false, true);
  87. }
  88. }
  89. private void ClearSearchButton_Click(object sender, RoutedEventArgs e)
  90. {
  91. Items.Search = "";
  92. Items.Refresh(false, true);
  93. }
  94. }
  95. }