CostSheetGrid.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Media.Imaging;
  7. using Comal.Classes;
  8. using InABox.Clients;
  9. using InABox.Core;
  10. using InABox.DynamicGrid;
  11. using InABox.WPF;
  12. namespace PRSDesktop;
  13. internal class CostSheetGrid : DynamicDataGrid<CostSheet>
  14. {
  15. private bool bShowAll;
  16. private readonly BitmapImage docs = PRSDesktop.Resources.doc_png.AsBitmapImage();
  17. public CostSheetGrid()
  18. {
  19. Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.EditRows,
  20. DynamicGridOption.FilterRows, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect);
  21. HiddenColumns.Add(x => x.Code);
  22. HiddenColumns.Add(x => x.LastUpdate);
  23. HiddenColumns.Add(x => x.Documents);
  24. ActionColumns.Add(new DynamicImageColumn(DocumentsImage, DocumentsClick) { Position = DynamicActionColumnPosition.Start });
  25. AddButton("Clone", PRSDesktop.Resources.clone.AsBitmapImage(), CloneCostSheet);
  26. AddButton("Show All", null, ToggleVisible);
  27. }
  28. private bool CloneCostSheet(Button sender, CoreRow[] rows)
  29. {
  30. if (rows == null || rows.Length != 1)
  31. {
  32. MessageBox.Show("Please select a single cost sheet to duplicate!");
  33. return false;
  34. }
  35. return Duplicate(rows.First(), x => x.Code, new[] { typeof(CostSheetKit), typeof(CostSheetDocument) });
  36. }
  37. private bool DocumentsClick(CoreRow arg)
  38. {
  39. if (arg == null)
  40. return false;
  41. var docs = new List<IEntityDocument>();
  42. using (new WaitCursor())
  43. {
  44. var deliveryid = arg.Get<CostSheet, Guid>(x => x.ID);
  45. var table = new Client<CostSheetDocument>().Query(
  46. new Filter<CostSheetDocument>(x => x.EntityLink.ID).IsEqualTo(deliveryid)
  47. );
  48. foreach (var row in table.Rows)
  49. docs.Add(row.ToObject<CostSheetDocument>());
  50. }
  51. if (docs.Any())
  52. {
  53. var editor = new DocumentEditor(docs.ToArray());
  54. //editor.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  55. editor.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  56. editor.ShowDialog();
  57. }
  58. else
  59. {
  60. MessageBox.Show("No Documents Available!");
  61. }
  62. return false;
  63. }
  64. private BitmapImage DocumentsImage(CoreRow arg)
  65. {
  66. if (arg == null)
  67. return docs;
  68. return arg.Get<CostSheet, int>(x => x.Documents) > 0 ? docs : null;
  69. }
  70. private bool ToggleVisible(Button arg1, CoreRow[] arg2)
  71. {
  72. bShowAll = !bShowAll;
  73. arg1.Content = bShowAll ? "Active Only" : "Show All";
  74. return true;
  75. }
  76. protected override void Reload(Filters<CostSheet> criteria, Columns<CostSheet> columns, ref SortOrder<CostSheet> sort,
  77. Action<CoreTable, Exception> action)
  78. {
  79. if (!bShowAll)
  80. criteria.Add(new Filter<CostSheet>(x => x.Active).IsEqualTo(true));
  81. base.Reload(criteria, columns, ref sort, action);
  82. }
  83. }