LogikalSettings.cs 12 KB

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