V6SettingsGrid.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. using PRSDesktop.Integrations.V6;
  9. namespace PRSDesktop.Integrations.V6.Grids;
  10. public class V6SettingsGrid : DynamicItemsListGrid<V6Settings>
  11. {
  12. private void Validate<T>(string sql, List<string> errors) where T : V6Object, new()
  13. {
  14. var t = new T();
  15. List<string> _e = new();
  16. t.ValidateQuery(sql.Replace('\n', ' '), _e);
  17. if (_e.Any())
  18. {
  19. errors.Add($"The query for {typeof(T).Name} has some errors:");
  20. errors.AddRange(_e);
  21. }
  22. }
  23. protected override void DoValidate(V6Settings[] items, List<string> errors)
  24. {
  25. base.DoValidate(items, errors);
  26. var _item = items.FirstOrDefault();
  27. if (_item == null)
  28. return;
  29. if (Guid.Equals(_item.ProfileUom.ID, Guid.Empty))
  30. errors.Add("Profile UOM may not be blank");
  31. if (Guid.Equals(_item.GasketUom.ID, Guid.Empty))
  32. errors.Add("Gasket UOM may not be blank");
  33. if (Guid.Equals(_item.ComponentUom.ID, Guid.Empty))
  34. errors.Add("Component UOM may not be blank");
  35. if (Guid.Equals(_item.GlassUom.ID, Guid.Empty))
  36. errors.Add("Glass UOM may not be blank");
  37. if (_item.ImportDesigns == V6DesignType.Approved)
  38. {
  39. if (String.IsNullOrWhiteSpace(_item.PacketTemplate))
  40. errors.Add("Packet Template my not be blank!");
  41. else
  42. {
  43. var _found = Client
  44. .Query(new InABox.Core.Filter<ManufacturingTemplate>(x => x.Code).IsEqualTo(_item.PacketTemplate),
  45. Columns.None<ManufacturingTemplate>()).Rows.Any();
  46. if (!_found)
  47. errors.Add($"Packet Template [{_item.PacketTemplate}] does not exist!");
  48. }
  49. }
  50. CheckV6Queries(_item);
  51. Validate<V6Project>(_item.QuoteSQL, errors);
  52. Validate<V6Elevation>(_item.ElevationSQL, errors);
  53. Validate<V6Drawings>(_item.DrawingsSQL, errors);
  54. Validate<V6Profile>(_item.ProfileSQL, errors);
  55. Validate<V6Component>(_item.ComponentSQL, errors);
  56. Validate<V6Labour>(_item.LabourSQL, errors);
  57. Validate<V6Glass>(_item.GlassSQL, errors);
  58. }
  59. public void CheckV6Queries(V6Settings item)
  60. {
  61. item.QuoteSQL = string.IsNullOrWhiteSpace(item.QuoteSQL) ? V6Project.SQL : item.QuoteSQL;
  62. item.ElevationSQL = string.IsNullOrWhiteSpace(item.ElevationSQL) ? V6Elevation.SQL : item.ElevationSQL;
  63. item.DrawingsSQL = string.IsNullOrWhiteSpace(item.DrawingsSQL) ? V6Drawings.SQL : item.DrawingsSQL;
  64. item.FinishSQL = string.IsNullOrWhiteSpace(item.FinishSQL) ? V6Finish.SQL : item.FinishSQL;
  65. item.ProfileSQL = string.IsNullOrWhiteSpace(item.ProfileSQL) ? V6Profile.SQL : item.ProfileSQL;
  66. item.GasketSQL = string.IsNullOrWhiteSpace(item.GasketSQL) ? V6Gasket.SQL : item.GasketSQL;
  67. item.ComponentSQL = string.IsNullOrWhiteSpace(item.ComponentSQL) ? V6Component.SQL : item.ComponentSQL;
  68. item.GlassSQL = string.IsNullOrWhiteSpace(item.GlassSQL) ? V6Glass.SQL : item.GlassSQL;
  69. item.LabourSQL = string.IsNullOrWhiteSpace(item.LabourSQL) ? V6Labour.SQL : item.LabourSQL;
  70. }
  71. }