SequenceColumnBuilder.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections.ObjectModel;
  7. using System.Reflection;
  8. using System.Xml;
  9. using System.IO;
  10. using System.Windows.Controls;
  11. using System.Windows;
  12. using MECF.Framework.Common.RecipeCenter;
  13. using RecipeEditorLib.DGExtension.CustomColumn;
  14. namespace VirgoUI.Client.Models.Recipe.Sequence
  15. {
  16. public class SequenceColumnBuilder
  17. {
  18. public ObservableCollection<ColumnBase> Build()
  19. {
  20. string temp = RecipeClient.Instance.Service.GetSequenceFormatXml();
  21. XmlDocument doc = new XmlDocument();
  22. doc.LoadXml(temp);
  23. ObservableCollection<ColumnBase> columns = new ObservableCollection<ColumnBase>();
  24. ColumnBase col;
  25. //step number
  26. col = new StepColumn()
  27. {
  28. DisplayName = "Step",
  29. ControlName = "Step",
  30. StringCellTemplate = "TemplateStep",
  31. StringHeaderTemplate = "ParamTemplate"
  32. };
  33. columns.Add(col);
  34. XmlNodeList nodes = doc.SelectNodes("TableSequenceFormat/Catalog/Item");
  35. foreach (XmlNode node in nodes)
  36. {
  37. switch (node.Attributes["InputType"].Value)
  38. {
  39. case "TextInput":
  40. col = new TextBoxColumn()
  41. {
  42. ControlName = node.Attributes["Name"].Value,
  43. DisplayName = node.Attributes["DisplayName"].Value,
  44. StringCellTemplate = "TemplateText",
  45. StringHeaderTemplate = "ParamTemplate"
  46. };
  47. columns.Add(col);
  48. break;
  49. case "ReadOnly":
  50. col = new TextBoxColumn()
  51. {
  52. ControlName = node.Attributes["Name"].Value,
  53. DisplayName = node.Attributes["DisplayName"].Value,
  54. StringCellTemplate = "TemplateText",
  55. StringHeaderTemplate = "ParamTemplate"
  56. };
  57. columns.Add(col);
  58. break;
  59. case "NumInput":
  60. col = new NumColumn()
  61. {
  62. ControlName = node.Attributes["Name"].Value,
  63. DisplayName = node.Attributes["DisplayName"].Value,
  64. //Minimun = int.Parse(node.Attributes["Min"].Value),
  65. //Maximun = int.Parse(node.Attributes["Max"].Value),
  66. StringCellTemplate = "TemplateSignInteger",
  67. StringHeaderTemplate = "ParamTemplate"
  68. };
  69. columns.Add(col);
  70. break;
  71. case "CleanRecipeSelection":
  72. col = new RecipeSelectColumn()
  73. {
  74. ControlName = node.Attributes["Name"].Value,
  75. DisplayName = node.Attributes["DisplayName"].Value,
  76. StringCellTemplate = "TemplateRecipeSelection",
  77. StringHeaderTemplate = "ParamTemplate",
  78. Type = RecipeSelectColumn.RecipeType.Clean
  79. };
  80. columns.Add(col);
  81. break;
  82. case "RecipeSelection":
  83. col = new RecipeSelectColumn()
  84. {
  85. ControlName = node.Attributes["Name"].Value,
  86. DisplayName = node.Attributes["DisplayName"].Value,
  87. RecipeFilePath = node.Attributes["RecipeFilePath"].Value,
  88. StringCellTemplate = "TemplateRecipeSelection",
  89. StringHeaderTemplate = "ParamTemplate",
  90. Type = RecipeSelectColumn.RecipeType.Process
  91. };
  92. columns.Add(col);
  93. break;
  94. case "EditableSelection":
  95. case "ReadOnlySelection":
  96. if (node.Attributes["Name"].Value == "Position")
  97. {
  98. col = new PositionColumn()
  99. {
  100. ControlName = node.Attributes["Name"].Value,
  101. DisplayName = node.Attributes["DisplayName"].Value,
  102. StringCellTemplate = "TemplateCombox",
  103. StringHeaderTemplate = "ParamTemplate"
  104. };
  105. XmlNodeList items = node.SelectNodes("Selection");
  106. foreach (XmlNode item in items)
  107. {
  108. ComboxColumn.Option opt = new ComboxColumn.Option();
  109. opt.ControlName = item.Attributes["Name"].Value;
  110. opt.DisplayName = item.Attributes["DisplayName"].Value;
  111. if (item.Attributes["Parameter"] != null)
  112. opt.RelatedParameters = item.Attributes["Parameter"].Value;
  113. ((PositionColumn)col).Options.Add(opt);
  114. }
  115. }
  116. else
  117. {
  118. col = new ComboxColumn()
  119. {
  120. ControlName = node.Attributes["Name"].Value,
  121. DisplayName = node.Attributes["DisplayName"].Value,
  122. StringCellTemplate = "TemplateCombox",
  123. StringHeaderTemplate = "ParamTemplate"
  124. };
  125. XmlNodeList items = node.SelectNodes("Selection");
  126. foreach (XmlNode item in items)
  127. {
  128. ComboxColumn.Option opt = new ComboxColumn.Option();
  129. opt.ControlName = item.Attributes["Name"].Value;
  130. opt.DisplayName = item.Attributes["DisplayName"].Value;
  131. if (item.Attributes["Parameter"] != null)
  132. opt.RelatedParameters = item.Attributes["Parameter"].Value;
  133. ((ComboxColumn)col).Options.Add(opt);
  134. }
  135. }
  136. columns.Add(col);
  137. break;
  138. case "MultiSelection":
  139. col = new MultipleSelectColumn()
  140. {
  141. ControlName = node.Attributes["Name"].Value,
  142. DisplayName = node.Attributes["DisplayName"].Value,
  143. StringCellTemplate = "TemplateMultiSelection",
  144. StringHeaderTemplate = "ParamTemplate"
  145. };
  146. XmlNodeList multiitems = node.SelectNodes("Selection");
  147. foreach (XmlNode item in multiitems)
  148. {
  149. MultipleSelectColumn.Option opt = new MultipleSelectColumn.Option();
  150. opt.IsChecked = false;
  151. opt.ControlName = item.Attributes["Name"].Value;
  152. opt.DisplayName = item.Attributes["DisplayName"].Value;
  153. if (item.Attributes["Parameter"] != null)
  154. opt.RelatedParameters = item.Attributes["Parameter"].Value;
  155. ((MultipleSelectColumn)col).Options.Add(opt);
  156. }
  157. columns.Add(col);
  158. break;
  159. }
  160. }
  161. return columns;
  162. }
  163. public static void ApplyTemplate(UserControl uc, ObservableCollection<ColumnBase> columns)
  164. {
  165. columns.ToList().ForEach(col =>
  166. {
  167. col.CellTemplate = (DataTemplate)uc.FindResource(col.StringCellTemplate);
  168. col.HeaderTemplate = (DataTemplate)uc.FindResource(col.StringHeaderTemplate);
  169. });
  170. }
  171. }
  172. }