ReadyToGoPanel.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.Options.PageSize = _globalSettings.PageSize;
  39. Items.Refresh(true, false);
  40. }
  41. public void Shutdown(CancelEventArgs? cancel)
  42. {
  43. }
  44. public void CreateToolbarButtons(IPanelHost host)
  45. {
  46. host.CreateSetupAction(new PanelAction() { Caption = "Delivered On Site Settings", Image = PRSDesktop.Resources.product, OnExecute =
  47. (obj) =>
  48. {
  49. var grid = new DynamicItemsListGrid<ReadyToGoGlobalSettings>();
  50. if (grid.EditItems(new ReadyToGoGlobalSettings[] { _globalSettings }))
  51. {
  52. new GlobalConfiguration<ReadyToGoGlobalSettings>().Save(_globalSettings);
  53. Items.Options.PageSize = _globalSettings.PageSize;
  54. Refresh();
  55. }
  56. }
  57. });
  58. }
  59. public void Refresh()
  60. {
  61. Items.Refresh(false, true);
  62. }
  63. public string SectionName => "Ready To Go";
  64. public DataModel DataModel(Selection selection)
  65. {
  66. var ids = Items.ExtractValues(x => x.ID, selection).ToArray();
  67. return new DeliveryItemDataModel(new Filter<DeliveryItem>(x => x.ID).InList(ids));
  68. }
  69. public void Heartbeat(TimeSpan time)
  70. {
  71. }
  72. public Type DataType()
  73. {
  74. return typeof(DeliveryItem);
  75. }
  76. private void SearchBox_KeyUp(object sender, KeyEventArgs e)
  77. {
  78. if (e.Key == Key.Enter)
  79. {
  80. Items.Search = SearchBox.Text;
  81. Items.Refresh(false, true);
  82. }
  83. }
  84. private void ClearSearchButton_Click(object sender, RoutedEventArgs e)
  85. {
  86. Items.Search = "";
  87. Items.Refresh(false, true);
  88. }
  89. }
  90. }