V6Project.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System.Collections.Generic;
  2. using InABox.Core;
  3. using InABox.Integration.V6;
  4. namespace PRSDesktop.Integrations.V6
  5. {
  6. public class V6Project : V6Object
  7. {
  8. [NullEditor]
  9. public int ID { get; set; }
  10. [NullEditor]
  11. public int Revision { get; set; }
  12. [IntegerEditor(Width=80)]
  13. [Caption("Quote")]
  14. [EditorSequence(1)]
  15. public int Number { get; set; }
  16. [TextBoxEditor(Width=60)]
  17. [EditorSequence(2)]
  18. public string Variation { get; set; }
  19. [TextBoxEditor(Width = 100)]
  20. [EditorSequence(3)]
  21. public string ClientID { get; set; }
  22. [TextBoxEditor(Visible = Visible.Hidden)]
  23. [EditorSequence(4)]
  24. public string ClientName { get; set; }
  25. [TextBoxEditor]
  26. [EditorSequence(5)]
  27. public string Title { get; set; }
  28. [MemoEditor(Visible = Visible.Hidden)]
  29. [EditorSequence(6)]
  30. public string Street { get; set; }
  31. [TextBoxEditor]
  32. [EditorSequence(7)]
  33. public string City { get; set; }
  34. [TextBoxEditor]
  35. [EditorSequence(8)]
  36. public string State { get; set; }
  37. [TextBoxEditor]
  38. [EditorSequence(9)]
  39. public string PostCode { get; set; }
  40. [CurrencyEditor]
  41. [EditorSequence(10)]
  42. public double SellPrice {get; set; }
  43. public override void ValidateQuery(string sql, List<string> errors)
  44. {
  45. ValidateField(sql, nameof(ID), errors);
  46. ValidateField(sql, nameof(Revision), errors);
  47. ValidateField(sql, nameof(Number), errors);
  48. ValidateField(sql, nameof(Variation), errors);
  49. ValidateField(sql, nameof(ClientID), errors);
  50. ValidateField(sql, nameof(ClientName), errors);
  51. ValidateField(sql, nameof(Title), errors);
  52. ValidateField(sql, nameof(Street), errors);
  53. ValidateField(sql, nameof(City), errors);
  54. ValidateField(sql, nameof(State), errors);
  55. ValidateField(sql, nameof(PostCode), errors);
  56. ValidateField(sql, nameof(SellPrice), errors);
  57. }
  58. public string GetReference()
  59. {
  60. var result = $"V6:{Number}";
  61. if (!string.IsNullOrWhiteSpace(Variation))
  62. result += $":{Variation}";
  63. return result;
  64. }
  65. public static bool ParseReference(string? reference, out int quotenumber, out string variation)
  66. {
  67. quotenumber = 0;
  68. variation = "";
  69. if (reference?.StartsWith("V6:") != true)
  70. return false;
  71. var comps = reference.Split(':');
  72. if (comps.Length < 2)
  73. return false;
  74. if (!int.TryParse(comps[1], out quotenumber))
  75. return false;
  76. if (comps.Length > 2)
  77. variation = comps[2];
  78. return true;
  79. }
  80. public static string SQL = $@"select distinct
  81. q.quote_id as {nameof(ID)},
  82. q.quote_vers as {nameof(Revision)},
  83. q.quote_num as {nameof(Number)},
  84. q.quote_num_suff as {nameof(Variation)},
  85. c.cust_code as {nameof(ClientID)},
  86. c.cust_name as {nameof(ClientName)},
  87. coalesce(a.addr_1,'') + coalesce(char(13)+char(10)+a.addr_2,'') as {nameof(Street)},
  88. a.addr_3 as {nameof(City)},
  89. a.addr_4 as {nameof(State)},
  90. a.addr_5 as {nameof(PostCode)},
  91. q.quote_title as {nameof(Title)},
  92. q.nett_sell_price + q.nett_sell_prc_lab as {nameof(SellPrice)}
  93. from quote q
  94. left outer join customer c on q.cust_id = c.cust_id
  95. left outer join addr a on q.del_addr_id = a.addr_id
  96. where
  97. q.quote_vers = (select max(quote_vers) from quote where quote_id = q.quote_id)
  98. order by
  99. q.quote_num,
  100. q.quote_num_suff";
  101. }
  102. }