SequenceData.cs 13 KB

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