KitGrid.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using Comal.Classes;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. using InABox.WPF;
  10. namespace PRSDesktop
  11. {
  12. public class KitGrid : DynamicDataGrid<Kit>
  13. {
  14. private bool bShowAll;
  15. private Task<Kit[]> result;
  16. public KitGrid()
  17. {
  18. Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.FilterRows, DynamicGridOption.SelectColumns,
  19. DynamicGridOption.MultiSelect);
  20. AddButton("Clone", PRSDesktop.Resources.clone.AsBitmapImage(), CloneKit);
  21. AddButton("Show All", null, ToggleVisible);
  22. AddButton("Cost Sheets", PRSDesktop.Resources.kit.AsBitmapImage(), ShowCostSheets);
  23. HiddenColumns.Add(x => x.LastUpdate);
  24. HiddenColumns.Add(x => x.Code);
  25. }
  26. private bool CloneKit(Button sender, CoreRow[] rows)
  27. {
  28. if (rows == null || rows.Length != 1)
  29. {
  30. MessageBox.Show("Please select a single kit to duplicate!");
  31. return false;
  32. }
  33. return Duplicate(rows.First(), x => x.Code, new[] { typeof(KitProduct) });
  34. }
  35. private bool ShowCostSheets(Button sender, CoreRow[] rows)
  36. {
  37. if (rows == null || rows.Length != 1)
  38. {
  39. MessageBox.Show("Please select a single row!");
  40. return false;
  41. }
  42. var kitid = rows.First().Get<Kit, Guid>(x => x.ID);
  43. var msd = new MultiSelectDialog<CostSheetKit>(
  44. new Filter<CostSheetKit>(x => x.Kit.ID).IsEqualTo(kitid),
  45. new Columns<CostSheetKit>()
  46. );
  47. msd.ShowDialog();
  48. return false;
  49. }
  50. private bool ToggleVisible(Button arg1, CoreRow[] arg2)
  51. {
  52. bShowAll = !bShowAll;
  53. arg1.Content = bShowAll ? "Active Only" : "Show All";
  54. return true;
  55. }
  56. protected override void Reload(Filters<Kit> criteria, Columns<Kit> columns, ref SortOrder<Kit> sort, Action<CoreTable, Exception> action)
  57. {
  58. if (!bShowAll)
  59. criteria.Add(new Filter<Kit>(x => x.Active).IsEqualTo(true));
  60. base.Reload(criteria, columns, ref sort, action);
  61. }
  62. }
  63. }