SystemConfigViewModel2LP.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Windows;
  7. using System.Windows.Forms;
  8. using System.Windows.Input;
  9. using System.Xml;
  10. using Aitex.Core.RT.Log;
  11. using Aitex.Core.RT.SCCore;
  12. using Aitex.Core.UI.MVVM;
  13. using Aitex.Core.Utilities;
  14. using Aitex.Sorter.Common;
  15. using MECF.Framework.Common.DataCenter;
  16. using MECF.Framework.Common.OperationCenter;
  17. using MessageBox = System.Windows.MessageBox;
  18. namespace Aitex.Sorter.UI.ViewModel
  19. {
  20. public class PageSC2LP: PageSCValue
  21. {
  22. public int LoadPort_TimeLimitReadRFID { get; set; }
  23. public bool LoadPort_EnableAutoCarrierIdReadAfterLatch { get; set; }
  24. public bool Process_EnableAutoUndockAfterProcessComplete { get; set; }
  25. public int LoadPort_LP1_SlotsNumber { get; set; }
  26. public int LoadPort_LP2_SlotsNumber { get; set; }
  27. public int Robot_RobotSpeed { get; set; }
  28. public int Robot_TimeLimitRobotCommand { get; set; }
  29. public int Robot_TimeLimitRobotHome { get; set; }
  30. public int Robot_TimeLimitForPickWafer { get; set; }
  31. public int Robot_TimeLimitForPlaceWafer { get; set; }
  32. public int Robot_TimeLimitForExchangeWafer { get; set; }
  33. public bool Robot_Blade1Enable { get; set; }
  34. public bool Robot_Blade2Enable { get; set; }
  35. public bool Robot_DualBlade1TransferEnable { get; set; }
  36. public bool Process_CycleEnable { get; set; }
  37. public int Process_CycleCount { get; set; }
  38. public bool Process_CycleEnableAutoUnload { get; set; }
  39. public bool Process_TransferStopImmediately { get; set; }
  40. public bool Process_CycleSwapHand { get; set; }
  41. public string Process_CycleSource { get; set; }
  42. public string Process_CycleDestination { get; set; }
  43. public int System_FFUSpeedSet { get; set; }
  44. public bool System_StopIonizerWorkingEnable { get; set; }
  45. }
  46. public class SystemConfigViewModel2LP : UIViewModelBase
  47. {
  48. [IgnorePropertyChange]
  49. public PageSC2LP ConfigFeedback
  50. {
  51. get;
  52. set;
  53. }
  54. [IgnorePropertyChange]
  55. public PageSC2LP ConfigSetPoint
  56. {
  57. get;
  58. set;
  59. }
  60. [IgnorePropertyChange]
  61. public ICommand SetConfigCommand
  62. {
  63. get;
  64. private set;
  65. }
  66. [IgnorePropertyChange]
  67. public ICommand SetConfig2Command
  68. {
  69. get;
  70. private set;
  71. }
  72. [IgnorePropertyChange]
  73. public ICommand SaveAsConfigCommand
  74. {
  75. get;
  76. private set;
  77. }
  78. [IgnorePropertyChange]
  79. public ICommand LoadConfigCommand
  80. {
  81. get;
  82. private set;
  83. }
  84. [IgnorePropertyChange]
  85. public ICommand SetAllConfigCommand
  86. {
  87. get;
  88. private set;
  89. }
  90. public SystemConfigViewModel2LP()
  91. : base("SystemConfigViewModel3LP")
  92. {
  93. SetConfigCommand = new DelegateCommand<object>(SetConfig);
  94. SetConfig2Command = new DelegateCommand<object>(SetConfig2);
  95. SaveAsConfigCommand = new DelegateCommand<object>(SaveAsConfig);
  96. LoadConfigCommand = new DelegateCommand<object>(LoadConfig);
  97. SetAllConfigCommand = new DelegateCommand<object>(SetAllConfig);
  98. ConfigFeedback = new PageSC2LP();
  99. ConfigSetPoint = new PageSC2LP();
  100. ConfigFeedback.UpdateKeys(typeof(PageSC2LP).GetProperties());
  101. ConfigSetPoint.UpdateKeys(typeof(PageSC2LP).GetProperties());
  102. }
  103. void SetConfig(object param)
  104. {
  105. object[] sc = (object[])param ;
  106. InvokeClient.Instance.Service.DoOperation("System.SetConfig", sc[0].ToString(), sc[1].ToString());
  107. UpdateConfig();
  108. }
  109. void SetConfig2(object param)
  110. {
  111. string stringParam = param.ToString();
  112. string[] values = stringParam.Split(';');
  113. foreach (var value in values)
  114. {
  115. if (string.IsNullOrEmpty(value))
  116. continue;
  117. string[] props = value.Split('.');
  118. if (props.Length != 3)
  119. {
  120. LOG.Error("Error SetConfig parameter" + param);
  121. continue;
  122. }
  123. string scName = props[1] + "." + props[2];
  124. object scValue = null;
  125. PropertyInfo[] property = typeof(SCValue).GetProperties();
  126. foreach (PropertyInfo fiGroup in property)
  127. {
  128. if (fiGroup.Name == props[1])
  129. {
  130. object objGroup = fiGroup.GetValue(ConfigSetPoint, null);
  131. foreach (PropertyInfo fiItem in objGroup.GetType().GetProperties())
  132. {
  133. if (fiItem.Name == props[2])
  134. {
  135. scValue = fiItem.GetValue(objGroup, null);
  136. InvokeClient.Instance.Service.DoOperation(OperationName.SetConfig , scName, scValue);
  137. break;
  138. }
  139. }
  140. break;
  141. }
  142. }
  143. }
  144. UpdateConfig();
  145. }
  146. private void SaveAsConfig(object param)
  147. {
  148. SaveFileDialog sfd = new SaveFileDialog();
  149. sfd.DefaultExt = ".cfg";
  150. sfd.Filter = ".cfg|*.*";
  151. sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  152. sfd.FileName = string.Format("process_config_{0}.cfg", DateTime.Now.ToString("yyyyMMdd_HHmmssfff"));
  153. if (sfd.ShowDialog() != DialogResult.OK)
  154. return;
  155. XmlDocument xml = new XmlDocument();
  156. xml.LoadXml(@"<?xml version='1.0' encoding='utf-8'?><Aitex><ProcessConfigs></ProcessConfigs></Aitex>");
  157. Dictionary<string, object> items = ConfigFeedback.GetValue();
  158. foreach (var item in items)
  159. {
  160. CreateNode(xml, item.Key, item.Value.ToString());
  161. }
  162. try
  163. {
  164. xml.Save(sfd.FileName);
  165. }
  166. catch (Exception ex)
  167. {
  168. MessageBox.Show(ex.Message, "Save Error", MessageBoxButton.OK, MessageBoxImage.Warning);
  169. }
  170. }
  171. void CreateNode(XmlDocument xmlDoc, string name, string value)
  172. {
  173. XmlNode node = xmlDoc.CreateElement("ProcessConfig");
  174. XmlAttribute attrName = xmlDoc.CreateAttribute("Name");
  175. attrName.Value = name;
  176. node.Attributes.Append(attrName);
  177. XmlAttribute attrValue = xmlDoc.CreateAttribute("Value");
  178. attrValue.Value = value;
  179. node.Attributes.Append(attrValue);
  180. xmlDoc.SelectSingleNode("Aitex/ProcessConfigs").AppendChild(node);
  181. }
  182. private void LoadConfig(object param)
  183. {
  184. OpenFileDialog ofd = new OpenFileDialog();
  185. ofd.DefaultExt = ".cfg";
  186. ofd.Filter = ".cfg|*.*";
  187. ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  188. if (ofd.ShowDialog() != DialogResult.OK)
  189. return;
  190. XmlDocument xml = new XmlDocument();
  191. try
  192. {
  193. xml.Load(ofd.FileName);
  194. Dictionary<string, object> items = ConfigSetPoint.GetValue();
  195. foreach (var item in items)
  196. {
  197. ConfigSetPoint.Update(item.Key, GetNodeValue(xml, item.Key, item.Value.ToString()));
  198. }
  199. }
  200. catch (Exception ex)
  201. {
  202. MessageBox.Show(ex.Message, "Open Failed", MessageBoxButton.OK, MessageBoxImage.Warning);
  203. return;
  204. }
  205. InvokeAllPropertyChanged();
  206. }
  207. string GetNodeValue(XmlDocument xmlDoc, string configItem, string defaultValue)
  208. {
  209. try
  210. {
  211. XmlNode node = xmlDoc.SelectSingleNode(string.Format("Aitex/ProcessConfigs/ProcessConfig[@Name='{0}']", configItem));
  212. if (node != null)
  213. {
  214. return node.Attributes["Value"].InnerText;
  215. }
  216. }
  217. catch (Exception ex)
  218. {
  219. LOG.Write(ex);
  220. }
  221. return defaultValue;
  222. }
  223. private void SetAllConfig(object param)
  224. {
  225. Dictionary<string, object> items = ConfigSetPoint.GetValue();
  226. foreach (var item in items)
  227. {
  228. InvokeClient.Instance.Service.DoOperation(OperationName.SetConfig.ToString(), item.Key, item.Value.ToString());
  229. }
  230. UpdateConfig();
  231. }
  232. public void UpdateConfig()
  233. {
  234. ConfigFeedback.Update(QueryDataClient.Instance.Service.PollConfig(ConfigFeedback.GetKeys()));
  235. ConfigSetPoint.Update(QueryDataClient.Instance.Service.PollConfig(ConfigSetPoint.GetKeys()));
  236. InvokeAllPropertyChanged();
  237. }
  238. }
  239. }