SequenceData.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Text;
  5. using System.Xml;
  6. using Caliburn.Micro.Core;
  7. using RecipeEditorLib.DGExtension.CustomColumn;
  8. using RecipeEditorLib.RecipeModel.Params;
  9. namespace MECF.Framework.UI.Client.CenterViews.Editors.Sequence
  10. {
  11. public class SequenceData : PropertyChangedBase
  12. {
  13. public SequenceData()
  14. {
  15. this.Steps = new ObservableCollection<ObservableCollection<Param>>();
  16. }
  17. public ObservableCollection<ObservableCollection<Param>> Steps { get; set; }
  18. public ObservableCollection<Param> CreateStep(ObservableCollection<EditorDataGridTemplateColumnBase> _columns, XmlNode step = null)
  19. {
  20. PositionParam posParam = null;
  21. string posValue = string.Empty;
  22. ObservableCollection<Param> Params = new ObservableCollection<Param>();
  23. foreach (EditorDataGridTemplateColumnBase col in _columns)
  24. {
  25. Param parm = null;
  26. string value = string.Empty;
  27. if (!(col is ExpanderColumn) && step != null && !(col is StepColumn))
  28. {
  29. if (step.Attributes[col.ControlName] != null)
  30. value = step.Attributes[col.ControlName].Value;
  31. }
  32. if (col is StepColumn)
  33. {
  34. parm = new StepParam()
  35. {
  36. Name = col.ControlName
  37. };
  38. }
  39. else if (col is TextBoxColumn)
  40. {
  41. parm = new StringParam()
  42. {
  43. Name = col.ControlName,
  44. Value = value,
  45. IsEnabled = !col.IsReadOnly
  46. };
  47. }
  48. else if (col is NumColumn)
  49. {
  50. if (!string.IsNullOrEmpty(value))
  51. parm = new IntParam() { Name = col.ControlName, Value = int.Parse(value), IsEnabled = !col.IsReadOnly };
  52. else
  53. parm = new IntParam() { Name = col.ControlName, Value = 0, IsEnabled = !col.IsReadOnly };
  54. }
  55. else if (col is ComboxColumn)
  56. {
  57. parm = new ComboxParam() { Name = col.ControlName,
  58. Value = value, Options = ((ComboxColumn)col).Options, IsEnabled = !col.IsReadOnly };
  59. }
  60. else if (col is PositionColumn)
  61. {
  62. posParam = new PositionParam() { Name = col.ControlName, Options = ((PositionColumn)col).Options, IsEnabled = !col.IsReadOnly };
  63. parm = posParam;
  64. posValue = value;
  65. }
  66. else if (col is ExpanderColumn)
  67. {
  68. parm = new ExpanderParam() { };
  69. }
  70. else if (col is RecipeSelectColumn)
  71. {
  72. //string path = ((RecipeSelectColumn) col).RecipeProcessType;
  73. //if (!string.IsNullOrEmpty(path) && value.StartsWith(path))
  74. //{
  75. // value = value.Substring(path.Length + 1);
  76. //}
  77. parm = new PathFileParam()
  78. {
  79. Name = col.ControlName,
  80. Value = value,
  81. IsEnabled = !col.IsReadOnly,
  82. PrefixPath = ((RecipeSelectColumn)col).RecipeProcessType
  83. };
  84. }
  85. else if (col is MultipleSelectColumn)
  86. {
  87. parm = new MultipleSelectParam((MultipleSelectColumn)col) { Name = col.ControlName, IsEnabled = !col.IsReadOnly };
  88. string[] opts = value.Split(',');
  89. ((MultipleSelectParam)parm).Options.Apply(opt => {
  90. for(var index = 0; index < opts.Length; index++)
  91. {
  92. if (opt.ControlName == opts[index])
  93. {
  94. opt.IsChecked = true;
  95. break;
  96. }
  97. }
  98. });
  99. parm.IsSaved = true;
  100. }
  101. parm.Parent = Params;
  102. Params.Add(parm);
  103. }
  104. posParam.Value = posValue;
  105. return Params;
  106. }
  107. public ObservableCollection<Param> CloneStep(ObservableCollection<EditorDataGridTemplateColumnBase> _columns, ObservableCollection<Param> _sourceParams)
  108. {
  109. ObservableCollection<Param> targetParams = this.CreateStep(_columns);
  110. PositionParam posParam = null;
  111. string posValue = string.Empty;
  112. for (var index = 0; index < _sourceParams.Count; index++)
  113. {
  114. if (_sourceParams[index] is PositionParam)
  115. {
  116. posParam = (PositionParam)targetParams[index];
  117. posValue = ((PositionParam)_sourceParams[index]).Value;
  118. }
  119. else if (_sourceParams[index] is StringParam)
  120. {
  121. ((StringParam)targetParams[index]).Value = ((StringParam)_sourceParams[index]).Value;
  122. }
  123. else if (_sourceParams[index] is PathFileParam)
  124. {
  125. ((PathFileParam)targetParams[index]).Value = ((PathFileParam)_sourceParams[index]).Value;
  126. ((PathFileParam)targetParams[index]).PrefixPath = ((PathFileParam)_sourceParams[index]).PrefixPath;
  127. }
  128. else if (_sourceParams[index] is IntParam)
  129. {
  130. ((IntParam)targetParams[index]).Value = ((IntParam)_sourceParams[index]).Value;
  131. }
  132. else if (_sourceParams[index] is ComboxParam)
  133. {
  134. ((ComboxParam)targetParams[index]).Value = ((ComboxParam)_sourceParams[index]).Value;
  135. }
  136. else if (_sourceParams[index] is BoolParam)
  137. {
  138. ((BoolParam)targetParams[index]).Value = ((BoolParam)_sourceParams[index]).Value;
  139. }
  140. else if (_sourceParams[index] is IntParam)
  141. {
  142. ((IntParam)targetParams[index]).Value = ((IntParam)_sourceParams[index]).Value;
  143. }
  144. else if (_sourceParams[index] is DoubleParam)
  145. {
  146. ((DoubleParam)targetParams[index]).Value = ((DoubleParam)_sourceParams[index]).Value;
  147. }
  148. targetParams[index].Parent = targetParams;
  149. }
  150. posParam.Value = posValue;
  151. return targetParams;
  152. }
  153. public void LoadSteps(ObservableCollection<EditorDataGridTemplateColumnBase> _columns, XmlNodeList _steps)
  154. {
  155. foreach (XmlNode _step in _steps)
  156. {
  157. this.Steps.Add(this.CreateStep(_columns, _step));
  158. }
  159. }
  160. public void Load(ObservableCollection<EditorDataGridTemplateColumnBase> _columns, XmlDocument doc)
  161. {
  162. XmlNode node = doc.SelectSingleNode("Aitex/TableSequenceData");
  163. if (node.Attributes["CreatedBy"] != null)
  164. this.Creator = node.Attributes["CreatedBy"].Value;
  165. if (node.Attributes["CreationTime"] != null)
  166. this.CreateTime = DateTime.Parse(node.Attributes["CreationTime"].Value);
  167. if (node.Attributes["LastRevisedBy"] != null)
  168. this.Revisor = node.Attributes["LastRevisedBy"].Value;
  169. if (node.Attributes["LastRevisionTime"] != null)
  170. this.ReviseTime = DateTime.Parse(node.Attributes["LastRevisionTime"].Value);
  171. if (node.Attributes["Description"] != null)
  172. this.Description = node.Attributes["Description"].Value;
  173. foreach (XmlNode _step in doc.SelectNodes("Aitex/TableSequenceData/Step"))
  174. {
  175. this.Steps.Add(this.CreateStep(_columns, _step));
  176. }
  177. }
  178. public string ToXml()
  179. {
  180. StringBuilder builder = new StringBuilder();
  181. builder.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
  182. builder.Append(string.Format("<Aitex><TableSequenceData CreatedBy=\"{0}\" CreationTime=\"{1}\" LastRevisedBy=\"{2}\" LastRevisionTime=\"{3}\" Description=\"{4}\" >", this.Creator, this.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"), this.Revisor, this.ReviseTime.ToString("yyyy-MM-dd HH:mm:ss"), this.Description));
  183. foreach (ObservableCollection<Param> parameters in Steps)
  184. {
  185. builder.Append("<Step ");
  186. foreach (Param parameter in parameters)
  187. {
  188. if (parameter.Visible == System.Windows.Visibility.Visible)
  189. {
  190. if (parameter is IntParam)
  191. builder.Append(parameter.Name + "=\"" + ((IntParam)parameter).Value + "\" ");
  192. else if (parameter is DoubleParam)
  193. builder.Append(parameter.Name + "=\"" + ((DoubleParam)parameter).Value + "\" ");
  194. else if (parameter is StringParam)
  195. builder.Append(parameter.Name + "=\"" + ((StringParam)parameter).Value + "\" ");
  196. else if (parameter is PathFileParam)
  197. builder.Append(parameter.Name + "=\"" + ((PathFileParam)parameter).Value + "\" ");
  198. else if (parameter is ComboxParam)
  199. builder.Append(parameter.Name + "=\"" + ((ComboxParam)parameter).Value + "\" ");
  200. else if (parameter is PositionParam)
  201. builder.Append(parameter.Name + "=\"" + ((PositionParam)parameter).Value + "\" ");
  202. else if (parameter is BoolParam)
  203. builder.Append(parameter.Name + "=\"" + ((BoolParam)parameter).Value + "\" ");
  204. else if (parameter is MultipleSelectParam)
  205. {
  206. List<string> selected = new List<string>();
  207. ((MultipleSelectParam)parameter).Options.Apply(
  208. opt =>
  209. {
  210. if (opt.IsChecked)
  211. selected.Add(opt.ControlName);
  212. }
  213. );
  214. builder.Append(parameter.Name + "=\"" + string.Join(",", selected) + "\" ");
  215. }
  216. }
  217. }
  218. builder.Append("/>");
  219. }
  220. builder.Append("</TableSequenceData></Aitex>");
  221. return builder.ToString();
  222. }
  223. private string name;
  224. public string Name
  225. {
  226. get { return this.name; }
  227. set
  228. {
  229. this.name = value;
  230. this.NotifyOfPropertyChange("Name");
  231. }
  232. }
  233. private string creator;
  234. public string Creator
  235. {
  236. get { return this.creator; }
  237. set
  238. {
  239. this.creator = value;
  240. this.NotifyOfPropertyChange("Creator");
  241. }
  242. }
  243. private DateTime createTime;
  244. public DateTime CreateTime
  245. {
  246. get { return this.createTime; }
  247. set
  248. {
  249. this.createTime = value;
  250. this.NotifyOfPropertyChange("CreateTime");
  251. }
  252. }
  253. private string description;
  254. public string Description
  255. {
  256. get { return this.description; }
  257. set
  258. {
  259. this.description = value;
  260. this.NotifyOfPropertyChange("Description");
  261. }
  262. }
  263. private string devisor;
  264. public string Revisor
  265. {
  266. get { return this.devisor; }
  267. set
  268. {
  269. this.devisor = value;
  270. this.NotifyOfPropertyChange("Revisor");
  271. }
  272. }
  273. private DateTime deviseTime;
  274. public DateTime ReviseTime
  275. {
  276. get { return this.deviseTime; }
  277. set
  278. {
  279. this.deviseTime = value;
  280. this.NotifyOfPropertyChange("ReviseTime");
  281. }
  282. }
  283. }
  284. }