LogikalSettings.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. using System;
  2. using System.Linq;
  3. using InABox.Configuration;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public enum LogikalProjectType
  8. {
  9. None,
  10. Quote,
  11. Project
  12. }
  13. public enum LogikalDesignType
  14. {
  15. None,
  16. Approved,
  17. NotApproved
  18. }
  19. // public enum LogikalMeasurement
  20. // {
  21. // Millimetres,
  22. // Metres
  23. // }
  24. public class LogikalMeasurementModel : IExpressionModel<double>
  25. {
  26. public double Value { get; set; }
  27. }
  28. public class LogikalCodeModel : IExpressionModel<string>
  29. {
  30. public string Code { get; set; }
  31. }
  32. public enum LogikalDrawingFormat
  33. {
  34. DXF,
  35. PNG
  36. }
  37. public enum LogikalDrawingView
  38. {
  39. Interior,
  40. Exterior
  41. }
  42. public enum LogikalDrawingType
  43. {
  44. Explosion,
  45. Section,
  46. Elevation,
  47. ElevationWithSectionLines,
  48. SectionLine,
  49. }
  50. public enum LogikalUpdateType
  51. {
  52. None,
  53. NewOnly,
  54. AlwaysUpdate,
  55. }
  56. public class LogikalSettings : BaseObject, IGlobalConfigurationSettings
  57. {
  58. [EnumLookupEditor(typeof(LogikalProjectType))]
  59. [EditorSequence(1)]
  60. [Caption("Import Projects")]
  61. public LogikalProjectType ImportProjects { get; set; }
  62. [CheckBoxEditor]
  63. [EditorSequence(2)]
  64. public bool UseLogikalProjectNumber { get; set; }
  65. [CodeEditor(Editable=Editable.Enabled)]
  66. [EditorSequence(3)]
  67. [Caption("Job Prefix")]
  68. public string ProjectPrefix { get; set; }
  69. [CheckBoxEditor]
  70. [EditorSequence(4)]
  71. [Caption("Import BOMs")]
  72. public bool ImportBoms { get; set; }
  73. [CheckBoxEditor]
  74. [EditorSequence(5)]
  75. [Caption("Import Requis")]
  76. public bool ImportRequis { get; set; }
  77. [EnumLookupEditor(typeof(LogikalDesignType))]
  78. [EditorSequence(6)]
  79. [Caption("Import Designs")]
  80. public LogikalDesignType ImportDesigns { get; set; }
  81. [EnumLookupEditor(typeof(LogikalDrawingFormat))]
  82. [EditorSequence(7)]
  83. [Caption("Drawing Format")]
  84. public LogikalDrawingFormat DrawingFormat { get; set; } = LogikalDrawingFormat.PNG;
  85. [EnumLookupEditor(typeof(LogikalDrawingView))]
  86. [EditorSequence(8)]
  87. [Caption("Drawing View")]
  88. public LogikalDrawingView DrawingView { get; set; } = LogikalDrawingView.Interior;
  89. [EnumLookupEditor(typeof(LogikalDrawingType))]
  90. [EditorSequence(9)]
  91. [Caption("Drawing Type")]
  92. public LogikalDrawingType DrawingType { get; set; } = LogikalDrawingType.Elevation;
  93. [ExpressionEditor(typeof(LogikalCodeModel))]
  94. [EditorSequence(10)]
  95. [Caption("Image URL")]
  96. public string ImageUrl { get; set; } = "";
  97. [CheckBoxEditor]
  98. [EditorSequence(11)]
  99. public bool SaveFiles { get; set; }
  100. [EnumLookupEditor(typeof(LogikalUpdateType))]
  101. [EditorSequence("0. Sections", 1)]
  102. [Caption("Finishes")]
  103. public LogikalUpdateType UpdateStyles { get; set; } = LogikalUpdateType.NewOnly;
  104. [EnumLookupEditor(typeof(LogikalUpdateType))]
  105. [EditorSequence("0. Sections", 2)]
  106. [Caption("Groups")]
  107. public LogikalUpdateType UpdateGroups { get; set; } = LogikalUpdateType.NewOnly;
  108. [EnumLookupEditor(typeof(LogikalUpdateType))]
  109. [EditorSequence("0. Sections", 3)]
  110. [Caption("Suppliers")]
  111. public LogikalUpdateType UpdateSuppliers { get; set; } = LogikalUpdateType.NewOnly;
  112. [EnumLookupEditor(typeof(LogikalUpdateType))]
  113. [EditorSequence("0. Sections", 4)]
  114. [Caption("Discounts")]
  115. public LogikalUpdateType UpdateDiscounts { get; set; } = LogikalUpdateType.NewOnly;
  116. [EnumLookupEditor(typeof(LogikalUpdateType))]
  117. [EditorSequence("0. Sections", 5)]
  118. [Caption("Profiles")]
  119. public LogikalUpdateType UpdateProfiles { get; set; } = LogikalUpdateType.NewOnly;
  120. [EnumLookupEditor(typeof(LogikalUpdateType))]
  121. [EditorSequence("0. Sections", 6)]
  122. [Caption("Gaskets")]
  123. public LogikalUpdateType UpdateGaskets { get; set; } = LogikalUpdateType.NewOnly;
  124. [EnumLookupEditor(typeof(LogikalUpdateType))]
  125. [EditorSequence("0. Sections", 7)]
  126. [Caption("Components")]
  127. public LogikalUpdateType UpdateComponents { get; set; } = LogikalUpdateType.NewOnly;
  128. [EnumLookupEditor(typeof(LogikalUpdateType))]
  129. [EditorSequence("0. Sections", 8)]
  130. [Caption("Glass")]
  131. public LogikalUpdateType UpdateGlass { get; set; } = LogikalUpdateType.NewOnly;
  132. [EnumLookupEditor(typeof(LogikalUpdateType))]
  133. [EditorSequence("0. Sections", 9)]
  134. [Caption("Labour")]
  135. public LogikalUpdateType UpdateLabour { get; set; } = LogikalUpdateType.NewOnly;
  136. [MemoEditor]
  137. [EditorSequence("1. Groups", 1)]
  138. [Caption("Query")]
  139. public String GroupSQL { get; set; }
  140. [MemoEditor(Height=400)]
  141. [EditorSequence("2. Finishes", 1)]
  142. [Caption("Query")]
  143. public String FinishSQL { get; set; }
  144. [TextBoxEditor]
  145. [EditorSequence("2. Finishes", 2)]
  146. [Caption("Ignore Styles")]
  147. public string IgnoredStyles { get; set; }
  148. public string IgnoreStyles(string value)
  149. {
  150. if (IgnoredStyles.Split(';', ',', '|').Select(x => x.Trim().ToUpper()).Contains(value.ToUpper()) == true)
  151. return "";
  152. return value;
  153. }
  154. private class TreatmentTypeLookup : LookupDefinitionGenerator<TreatmentType, LogikalSettings>
  155. {
  156. public override Filter<TreatmentType> DefineFilter(LogikalSettings[] items)
  157. => new Filter<TreatmentType>().All();
  158. }
  159. [LookupDefinition(typeof(TreatmentTypeLookup))]
  160. [EditorSequence("2. Finishes", 3)]
  161. [Caption("Powdercoated")]
  162. public TreatmentTypeLink PowdercoatedType { get; set; }
  163. [LookupDefinition(typeof(TreatmentTypeLookup))]
  164. [EditorSequence("2. Finishes", 4)]
  165. [Caption("Anodised")]
  166. public TreatmentTypeLink AnodisedType { get; set; }
  167. [LookupDefinition(typeof(TreatmentTypeLookup))]
  168. [EditorSequence("2. Finishes", 5)]
  169. [Caption("Varnished")]
  170. public TreatmentTypeLink VarnishedType { get; set; }
  171. [LookupDefinition(typeof(TreatmentTypeLookup))]
  172. [EditorSequence("2. Finishes", 6)]
  173. [Caption("Taped")]
  174. public TreatmentTypeLink TapedType { get; set; }
  175. private class ProfileUomLookup : LookupDefinitionGenerator<ProductDimensionUnit, LogikalSettings>
  176. {
  177. public override Filter<ProductDimensionUnit> DefineFilter(LogikalSettings[] items)
  178. {
  179. return new Filter<ProductDimensionUnit>(x => x.HasLength).IsEqualTo(true)
  180. .And(x=>x.HasWidth).IsEqualTo(false)
  181. .And(x=>x.HasHeight).IsEqualTo(false)
  182. .And(x=>x.HasQuantity).IsEqualTo(false);
  183. }
  184. }
  185. [EditorSequence("3. Profiles", 1)]
  186. [Caption("Unit")]
  187. [LookupDefinition(typeof(ProfileUomLookup))]
  188. public ProductDimensionUnitLink ProfileUom { get; set; }
  189. [EditorSequence("3. Profiles", 2)]
  190. [ExpressionEditor(typeof(LogikalMeasurementModel))]
  191. [Caption("Scale")]
  192. public string ProfileMeasurement { get; set; }
  193. [MemoEditor(Height=200)]
  194. [EditorSequence("3. Profiles", 3)]
  195. [Caption("BOM")]
  196. public String BillOfMaterialsProfileSQL { get; set; }
  197. [MemoEditor(Height=200)]
  198. [EditorSequence("3. Profiles", 4)]
  199. [Caption("Design")]
  200. public String DesignProfileSQL { get; set; }
  201. private class GasketUomLookup : LookupDefinitionGenerator<ProductDimensionUnit, LogikalSettings>
  202. {
  203. public override Filter<ProductDimensionUnit> DefineFilter(LogikalSettings[] items)
  204. {
  205. return new Filter<ProductDimensionUnit>(x => x.HasLength).IsEqualTo(true)
  206. .And(x=>x.HasWidth).IsEqualTo(false)
  207. .And(x=>x.HasHeight).IsEqualTo(false)
  208. .And(x=>x.HasQuantity).IsEqualTo(false);
  209. }
  210. }
  211. [EditorSequence("4. Gaskets", 1)]
  212. [LookupDefinition(typeof(GasketUomLookup))]
  213. [Caption("Unit")]
  214. public ProductDimensionUnitLink GasketUom { get; set; }
  215. [EditorSequence("4. Gaskets", 2)]
  216. [ExpressionEditor(typeof(LogikalMeasurementModel))]
  217. [Caption("Scale")]
  218. public string GasketMeasurement { get; set; }
  219. [MemoEditor]
  220. [EditorSequence("4. Gaskets", 3)]
  221. [Caption("Query")]
  222. public string GasketSQL { get; set; }
  223. private class ComponentUomLookup : LookupDefinitionGenerator<ProductDimensionUnit, LogikalSettings>
  224. {
  225. public override Filter<ProductDimensionUnit> DefineFilter(LogikalSettings[] items)
  226. {
  227. return new Filter<ProductDimensionUnit>(x=>x.HasQuantity).IsEqualTo(true)
  228. .And(x => x.HasLength).IsEqualTo(false)
  229. .And(x=>x.HasWidth).IsEqualTo(false)
  230. .And(x=>x.HasHeight).IsEqualTo(false);
  231. }
  232. }
  233. [EditorSequence("5. Components", 1)]
  234. [LookupDefinition(typeof(ComponentUomLookup))]
  235. [Caption("Unit")]
  236. public ProductDimensionUnitLink ComponentUom { get; set; }
  237. [MemoEditor]
  238. [EditorSequence("5. Components", 2)]
  239. [Caption("Query")]
  240. public String ComponentSQL { get; set; }
  241. private class GlassUomLookup : LookupDefinitionGenerator<ProductDimensionUnit, LogikalSettings>
  242. {
  243. public override Filter<ProductDimensionUnit> DefineFilter(LogikalSettings[] items)
  244. {
  245. return new Filter<ProductDimensionUnit>(x=>x.HasWidth).IsEqualTo(true)
  246. .And(x=>x.HasHeight).IsEqualTo(true)
  247. .And(x => x.HasLength).IsEqualTo(false)
  248. .And(x=>x.HasQuantity).IsEqualTo(false);
  249. }
  250. }
  251. [EditorSequence("6. Glass", 1)]
  252. [LookupDefinition(typeof(GlassUomLookup))]
  253. [Caption("Unit")]
  254. public ProductDimensionUnitLink GlassUom { get; set; }
  255. [EditorSequence("6. Glass", 2)]
  256. [ExpressionEditor(typeof(LogikalMeasurementModel))]
  257. [Caption("Scale")]
  258. public string GlassMeasurement { get; set; }
  259. [MemoEditor]
  260. [EditorSequence("6. Glass", 2)]
  261. [Caption("Query")]
  262. public String GlassSQL { get; set; }
  263. [MemoEditor]
  264. [EditorSequence("7. Labour", 1)]
  265. [Caption("Query")]
  266. public String LabourSQL { get; set; }
  267. public bool CanImport<TSecurity>(bool enabled, Job? job) where TSecurity : ISecurityDescriptor, new()
  268. {
  269. if (!enabled)
  270. return false;
  271. if (job is null)
  272. return false;
  273. if (!InABox.Core.Security.IsAllowed<TSecurity>())
  274. return false;
  275. if (UseLogikalProjectNumber)
  276. return (string.IsNullOrWhiteSpace(ProjectPrefix) || job.JobNumber.StartsWith(ProjectPrefix));
  277. return (string.IsNullOrWhiteSpace(job.SourceRef) || job.SourceRef.StartsWith("Logikal:"));
  278. }
  279. }
  280. }