FactoryGroupsGrid.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Comal.Classes;
  5. using InABox.Clients;
  6. using InABox.Core;
  7. using InABox.DynamicGrid;
  8. namespace PRSDesktop
  9. {
  10. internal class FactoryGroupsGrid : DynamicGrid<FactoryGroup>
  11. {
  12. public FactoryGroupsGrid()
  13. {
  14. Options.AddRange(DynamicGridOption.RecordCount);
  15. }
  16. public List<FactoryGroup> Groups { get; set; }
  17. //public DynamicGridColumns DefineColumns()
  18. //{
  19. // return LoadColumns();
  20. //}
  21. protected override DynamicGridColumns LoadColumns()
  22. {
  23. ActionColumns.Clear();
  24. ActionColumns.Add(new DynamicRowMovementColumn(DynamicRowMovement.Up, SwapRows));
  25. ActionColumns.Add(new DynamicRowMovementColumn(DynamicRowMovement.Down, SwapRows));
  26. var columns = new DynamicGridColumns
  27. {
  28. new() { ColumnName = "Group", Width = 0 },
  29. new() { ColumnName = "QAChecker", Width = 0 }
  30. };
  31. return columns;
  32. }
  33. private bool SwapRows(int arg1, int arg2)
  34. {
  35. var item = Groups[arg1];
  36. Groups.Remove(item);
  37. Groups.Insert(arg2, item);
  38. return true;
  39. }
  40. #region Save / Load
  41. //protected override DataTable Reload(Dictionary<String, Object> criteria, List<String> columnnames, String sort)
  42. //{
  43. // DataTable result = new DataTable();
  44. // result.LoadColumns(typeof(FactoryGroup));
  45. // result.LoadRows(Groups);
  46. // return result;
  47. //}
  48. protected override void Reload(Filters<FactoryGroup> criteria, Columns<FactoryGroup> columns, ref SortOrder<FactoryGroup> sort,
  49. Action<CoreTable, Exception> action)
  50. {
  51. var result = new CoreTable();
  52. result.LoadColumns(typeof(FactoryGroup));
  53. result.LoadRows(Groups);
  54. action.Invoke(result, null);
  55. }
  56. protected override FactoryGroup LoadItem(CoreRow row)
  57. {
  58. var index = Data.Rows.IndexOf(row);
  59. return Groups[index];
  60. }
  61. protected override void SaveItem(FactoryGroup item)
  62. {
  63. if (!Groups.Contains(item))
  64. Groups.Add(item);
  65. }
  66. protected override void DeleteItems(params CoreRow[] rows)
  67. {
  68. foreach (var row in rows)
  69. {
  70. var index = Data.Rows.IndexOf(row);
  71. Groups.RemoveAt(index);
  72. }
  73. }
  74. protected override FactoryGroup CreateItem()
  75. {
  76. return base.CreateItem();
  77. }
  78. protected override Document LoadDocument(Guid id)
  79. {
  80. return new Client<Document>().Load(new Filter<Document>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
  81. }
  82. protected override Document FindDocument(string filename)
  83. {
  84. return new Client<Document>().Load(new Filter<Document>(x => x.FileName).IsEqualTo(filename)).FirstOrDefault();
  85. }
  86. protected override void SaveDocument(Document document)
  87. {
  88. new Client<Document>().Save(document, "Added from Factory Groups Screen");
  89. }
  90. #endregion
  91. }
  92. }