SequenceColumnBuilder.cs 7.8 KB

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