RecipeFormatBuilder.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Xml;
  8. using Aitex.Core.RT.Log;
  9. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  10. using RecipeEditorLib.DGExtension.CustomColumn;
  11. using RecipeEditorLib.RecipeModel.Params;
  12. namespace MECF.Framework.UI.Client.CenterViews.Editors.Recipe
  13. {
  14. public class RecipeFormatBuilder
  15. {
  16. public ObservableCollection<EditorDataGridTemplateColumnBase> Columns
  17. {
  18. get;
  19. set;
  20. }
  21. public ObservableCollection<Param> Configs
  22. {
  23. get;
  24. set;
  25. }
  26. public ObservableCollection<Param> OesConfig
  27. {
  28. get;
  29. set;
  30. }
  31. public ObservableCollection<Param> VatConfig
  32. {
  33. get;
  34. set;
  35. }
  36. public ObservableCollection<Param> BrandConfig
  37. {
  38. get;
  39. set;
  40. }
  41. public ObservableCollection<Param> FineTuningConfig
  42. {
  43. get;
  44. set;
  45. }
  46. public string RecipeChamberType
  47. {
  48. get;
  49. set;
  50. }
  51. public string RecipeVersion
  52. {
  53. get;
  54. set;
  55. }
  56. private RecipeProvider recipeProvider = new RecipeProvider();
  57. public ObservableCollection<EditorDataGridTemplateColumnBase> Build(string path)
  58. {
  59. var str = recipeProvider.GetRecipeFormatXml(path);
  60. string configstr = "";
  61. if (path == "PM1")
  62. {
  63. configstr = "Process";
  64. }
  65. else
  66. {
  67. configstr = path;
  68. }
  69. XmlDocument doc = new XmlDocument();
  70. try
  71. {
  72. doc.LoadXml(str);
  73. XmlNode nodeRoot = doc.SelectSingleNode("TableRecipeFormat");
  74. RecipeChamberType = nodeRoot.Attributes["RecipeChamberType"].Value;
  75. RecipeVersion = nodeRoot.Attributes["RecipeVersion"].Value;
  76. }
  77. catch (Exception ex)
  78. {
  79. LOG.Write(ex);
  80. return null;
  81. }
  82. var columns = new ObservableCollection<EditorDataGridTemplateColumnBase>();
  83. EditorDataGridTemplateColumnBase col = null;
  84. XmlNodeList nodes = doc.SelectNodes("TableRecipeFormat/Catalog/Group");
  85. foreach (XmlNode node in nodes)
  86. {
  87. columns.Add(new ExpanderColumn()
  88. {
  89. DisplayName = node.Attributes["DisplayName"].Value,
  90. StringCellTemplate = "TemplateExpander",
  91. StringHeaderTemplate = "ParamExpander"
  92. });
  93. XmlNodeList childNodes = node.SelectNodes("Step");
  94. foreach (XmlNode step in childNodes)
  95. {
  96. //step number
  97. if (step.Attributes["ControlName"].Value == "StepNo")
  98. {
  99. col = new StepColumn()
  100. {
  101. DisplayName = "Step",
  102. ControlName = "StepNo",
  103. StringCellTemplate = "TemplateStep",
  104. StringHeaderTemplate = "ParamTemplate"
  105. };
  106. columns.Add(col);
  107. continue;
  108. }
  109. switch (step.Attributes["InputType"].Value)
  110. {
  111. case "TextInput":
  112. col = new TextBoxColumn()
  113. {
  114. ModuleName = step.Attributes["ModuleName"].Value,
  115. ControlName = step.Attributes["ControlName"].Value,
  116. DisplayName = step.Attributes["DisplayName"].Value,
  117. StringCellTemplate = "TemplateText",
  118. StringHeaderTemplate = "ParamTemplate",
  119. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  120. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  121. };
  122. columns.Add(col);
  123. break;
  124. case "ReadOnly":
  125. col = new TextBoxColumn()
  126. {
  127. ModuleName = step.Attributes["ModuleName"].Value,
  128. ControlName = step.Attributes["ControlName"].Value,
  129. DisplayName = step.Attributes["DisplayName"].Value,
  130. StringCellTemplate = "TemplateText",
  131. StringHeaderTemplate = "ParamTemplate",
  132. IsReadOnly = true,
  133. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  134. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  135. };
  136. columns.Add(col);
  137. break;
  138. case "NumInput":
  139. col = new NumColumn()
  140. {
  141. ModuleName = step.Attributes["ModuleName"].Value,
  142. ControlName = step.Attributes["ControlName"].Value,
  143. DisplayName = step.Attributes["DisplayName"].Value,
  144. InputMode = step.Attributes["InputMode"].Value,
  145. Minimun = double.Parse(step.Attributes["Min"].Value),
  146. Maximun = double.Parse(step.Attributes["Max"].Value),
  147. StringCellTemplate = "TemplateNumber",
  148. StringHeaderTemplate = "ParamTemplate",
  149. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  150. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  151. };
  152. columns.Add(col);
  153. break;
  154. case "DoubleInput":
  155. col = new DoubleColumn()
  156. {
  157. ModuleName = step.Attributes["ModuleName"].Value,
  158. ControlName = step.Attributes["ControlName"].Value,
  159. DisplayName = step.Attributes["DisplayName"].Value,
  160. InputMode = step.Attributes["InputMode"].Value,
  161. Minimun = double.Parse(step.Attributes["Min"].Value),
  162. Maximun = double.Parse(step.Attributes["Max"].Value),
  163. StringCellTemplate = "TemplateNumber",
  164. StringHeaderTemplate = "ParamTemplate",
  165. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  166. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  167. };
  168. columns.Add(col);
  169. break;
  170. case "EditableSelection":
  171. case "ReadOnlySelection":
  172. col = new ComboxColumn()
  173. {
  174. IsReadOnly = step.Attributes["InputType"].Value == "ReadOnlySelection",
  175. ModuleName = step.Attributes["ModuleName"].Value,
  176. Default = step.Attributes["Default"] != null ? step.Attributes["Default"].Value : "",
  177. ControlName = step.Attributes["ControlName"].Value,
  178. DisplayName = step.Attributes["DisplayName"].Value,
  179. StringCellTemplate = "TemplateCombox",
  180. StringHeaderTemplate = "ParamTemplate",
  181. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  182. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  183. };
  184. XmlNodeList items = step.SelectNodes("Item");
  185. foreach (XmlNode item in items)
  186. {
  187. ComboxColumn.Option opt = new ComboxColumn.Option();
  188. opt.ControlName = item.Attributes["ControlName"].Value;
  189. opt.DisplayName = item.Attributes["DisplayName"].Value;
  190. ((ComboxColumn)col).Options.Add(opt);
  191. }
  192. columns.Add(col);
  193. break;
  194. case "LoopSelection":
  195. col = new LoopComboxColumn()
  196. {
  197. IsReadOnly = false,
  198. ModuleName = step.Attributes["ModuleName"].Value,
  199. ControlName = step.Attributes["ControlName"].Value,
  200. DisplayName = step.Attributes["DisplayName"].Value,
  201. StringCellTemplate = "TemplateCombox",
  202. StringHeaderTemplate = "ParamTemplate",
  203. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  204. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  205. };
  206. XmlNodeList options = step.SelectNodes("Item");
  207. foreach (XmlNode item in options)
  208. {
  209. LoopComboxColumn.Option opt = new LoopComboxColumn.Option();
  210. opt.ControlName = item.Attributes["ControlName"].Value;
  211. opt.DisplayName = item.Attributes["DisplayName"].Value;
  212. ((LoopComboxColumn)col).Options.Add(opt);
  213. }
  214. columns.Add(col);
  215. break;
  216. case "PopSetting":
  217. col = new PopSettingColumn()
  218. {
  219. ModuleName = step.Attributes["ModuleName"].Value,
  220. ControlName = step.Attributes["ControlName"].Value,
  221. DisplayName = step.Attributes["DisplayName"].Value,
  222. StringCellTemplate = "TemplatePopSetting",
  223. StringHeaderTemplate = "ParamTemplate",
  224. EnableConfig = step.Attributes["EnableConfig"] != null && Convert.ToBoolean(step.Attributes["EnableConfig"].Value),
  225. EnableTolerance = step.Attributes["EnableTolerance"] != null && Convert.ToBoolean(step.Attributes["EnableTolerance"].Value),
  226. };
  227. columns.Add(col);
  228. break;
  229. }
  230. }
  231. }
  232. Columns = columns;
  233. var configs = new ObservableCollection<Param>();
  234. nodes = doc.SelectNodes($"TableRecipeFormat/{configstr}Config/Configs");
  235. foreach (XmlNode node in nodes)
  236. {
  237. XmlNodeList childNodes = node.SelectNodes("Config");
  238. foreach (XmlNode configNode in childNodes)
  239. {
  240. switch (configNode.Attributes["InputType"].Value)
  241. {
  242. case "DoubleInput":
  243. var config = new DoubleParam()
  244. {
  245. Name = configNode.Attributes["ControlName"].Value,
  246. Value = configNode.Attributes["Default"].Value,
  247. DisplayName = configNode.Attributes["DisplayName"].Value,
  248. EnableConfig = configNode.Attributes["EnableConfig"] != null && Convert.ToBoolean(configNode.Attributes["EnableConfig"].Value),
  249. EnableTolerance = configNode.Attributes["EnableTolerance"] != null && Convert.ToBoolean(configNode.Attributes["EnableTolerance"].Value),
  250. };
  251. if (double.TryParse(configNode.Attributes["Max"].Value, out double max))
  252. {
  253. (config as DoubleParam).Maximun = max;
  254. }
  255. if (double.TryParse(configNode.Attributes["Min"].Value, out double min))
  256. {
  257. (config as DoubleParam).Minimun = min;
  258. }
  259. configs.Add(config);
  260. break;
  261. case "NumInput":
  262. var numConfig = new NumParam()
  263. {
  264. Name = configNode.Attributes["ControlName"].Value,
  265. Value = int.Parse(configNode.Attributes["Default"].Value),
  266. DisplayName = configNode.Attributes["DisplayName"].Value,
  267. EnableConfig = configNode.Attributes["EnableConfig"] != null && Convert.ToBoolean(configNode.Attributes["EnableConfig"].Value),
  268. EnableTolerance = configNode.Attributes["EnableTolerance"] != null && Convert.ToBoolean(configNode.Attributes["EnableTolerance"].Value),
  269. };
  270. if (double.TryParse(configNode.Attributes["Max"].Value, out max))
  271. {
  272. (numConfig as NumParam).Maximun = max;
  273. }
  274. if (double.TryParse(configNode.Attributes["Min"].Value, out min))
  275. {
  276. (numConfig as NumParam).Minimun = min;
  277. }
  278. configs.Add(numConfig);
  279. break;
  280. case "TextInput":
  281. var strConfig = new StringParam()
  282. {
  283. Name = configNode.Attributes["ControlName"].Value,
  284. Value = configNode.Attributes["Default"].Value,
  285. DisplayName = configNode.Attributes["DisplayName"].Value,
  286. EnableConfig = configNode.Attributes["EnableConfig"] != null && Convert.ToBoolean(configNode.Attributes["EnableConfig"].Value),
  287. EnableTolerance = configNode.Attributes["EnableTolerance"] != null && Convert.ToBoolean(configNode.Attributes["EnableTolerance"].Value),
  288. };
  289. configs.Add(strConfig);
  290. break;
  291. }
  292. }
  293. }
  294. Configs = configs;
  295. BrandConfig = GetConfig(doc.SelectNodes("TableRecipeFormat/BrandConfig/Configs"));
  296. OesConfig = GetConfig(doc.SelectNodes("TableRecipeFormat/OesConfig/Configs"));
  297. VatConfig = GetConfig(doc.SelectNodes("TableRecipeFormat/VatConfig/Configs"));
  298. FineTuningConfig = GetConfig(doc.SelectNodes("TableRecipeFormat/FineTuningConfig/Configs"));
  299. return Columns;
  300. }
  301. private ObservableCollection<Param> GetConfig(XmlNodeList nodes)
  302. {
  303. var configs = new ObservableCollection<Param>();
  304. foreach (XmlNode node in nodes)
  305. {
  306. XmlNodeList childNodes = node.SelectNodes("Config");
  307. foreach (XmlNode configNode in childNodes)
  308. {
  309. switch (configNode.Attributes["InputType"].Value)
  310. {
  311. case "TextInput":
  312. var text = new StringParam()
  313. {
  314. Name = configNode.Attributes["ControlName"].Value,
  315. Value = configNode.Attributes["Default"].Value,
  316. DisplayName = configNode.Attributes["DisplayName"].Value,
  317. };
  318. configs.Add(text);
  319. break;
  320. case "DoubleInput":
  321. var config = new DoubleParam()
  322. {
  323. Name = configNode.Attributes["ControlName"].Value,
  324. Value = configNode.Attributes["Default"].Value,
  325. DisplayName = configNode.Attributes["DisplayName"].Value,
  326. };
  327. if (double.TryParse(configNode.Attributes["Max"].Value, out double max))
  328. {
  329. (config as DoubleParam).Maximun = max;
  330. }
  331. if (double.TryParse(configNode.Attributes["Min"].Value, out double min))
  332. {
  333. (config as DoubleParam).Minimun = min;
  334. }
  335. configs.Add(config);
  336. break;
  337. case "ReadOnlySelection":
  338. var col = new ComboxParam()
  339. {
  340. Name = configNode.Attributes["ControlName"].Value,
  341. DisplayName = configNode.Attributes["DisplayName"].Value,
  342. Value = configNode.Attributes["Default"] != null ? configNode.Attributes["Default"].Value : "",
  343. Options = new ObservableCollection<ComboxColumn.Option>(),
  344. IsEditable = configNode.Attributes["InputType"].Value == "ReadOnlySelection",
  345. EnableTolerance = configNode.Attributes["EnableTolerance"] != null && Convert.ToBoolean(configNode.Attributes["EnableTolerance"].Value),
  346. };
  347. XmlNodeList items = configNode.SelectNodes("Item");
  348. foreach (XmlNode item in items)
  349. {
  350. ComboxColumn.Option opt = new ComboxColumn.Option();
  351. opt.ControlName = item.Attributes["ControlName"].Value;
  352. opt.DisplayName = item.Attributes["DisplayName"].Value;
  353. col.Options.Add(opt);
  354. }
  355. col.Value = !string.IsNullOrEmpty(col.Value) ? col.Value : (col.Options.Count > 0 ? col.Options[0].ControlName : "");
  356. configs.Add(col);
  357. break;
  358. }
  359. }
  360. }
  361. return configs;
  362. }
  363. public static void ApplyTemplate(UserControl uc, ObservableCollection<EditorDataGridTemplateColumnBase> columns)
  364. {
  365. columns.ToList().ForEach(col =>
  366. {
  367. col.CellTemplate = (DataTemplate)uc.FindResource(col.StringCellTemplate);
  368. col.HeaderTemplate = (DataTemplate)uc.FindResource(col.StringHeaderTemplate);
  369. });
  370. }
  371. }
  372. }