WaferIDReaderViewModel.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using Aitex.Core.RT.SCCore;
  2. using Aitex.Core.UI.MVVM;
  3. using Aitex.Core.Util;
  4. using Aitex.Sorter.Common;
  5. using Aitex.Sorter.UI.Controls.Common;
  6. using MECF.Framework.Common.OperationCenter;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Windows;
  12. using System.Windows.Forms;
  13. using System.Windows.Input;
  14. using MECF.Framework.Common.CommonData;
  15. using MECF.Framework.Common.DataCenter;
  16. namespace Aitex.Sorter.UI.ViewModel.Maintenance
  17. {
  18. public class WaferIDReaderViewModel : UIViewModelBase
  19. {
  20. public WaferIDReaderViewModel() : base("WaferIDReaderView")
  21. {
  22. Command = new DelegateCommand<DependencyObject>(DoCommand, x => !IsMaintenanceMode && !IsAutoMode);
  23. FileCommand = new DelegateCommand<DependencyObject>(DoFileCommand, x => !IsMaintenanceMode && !IsAutoMode);
  24. }
  25. public virtual WaferIDReaderItem[] WaferIDReaderItems
  26. {
  27. get;
  28. set;
  29. }
  30. [Subscription(ParamName.AlignerElapseTime, DeviceName.Aligner)]
  31. public string ElapseTime
  32. {
  33. get;
  34. set;
  35. }
  36. private double notch;
  37. [Subscription(ParamName.AlignerNotch, DeviceName.Aligner)]
  38. public double Notch
  39. {
  40. get
  41. {
  42. return notch;
  43. }
  44. set
  45. {
  46. notch = value / 1000;
  47. }
  48. }
  49. [Subscription(ParamName.WaferOnAligner, DeviceName.Aligner)]
  50. public bool WaferOnAligner
  51. {
  52. get;
  53. set;
  54. }
  55. [Subscription(ParamName.AlignerState, DeviceName.Aligner)]
  56. public string AlignerStatus
  57. {
  58. get;
  59. set;
  60. }
  61. [Subscription(ParamName.AlignerError, DeviceName.Aligner)]
  62. public string ErrorCode
  63. {
  64. get;
  65. set;
  66. }
  67. [Subscription(ParamName.RTStatus, SystemStateModule)]
  68. public int RoutManagerState
  69. {
  70. get;
  71. set;
  72. }
  73. public bool IsMaintenanceMode
  74. {
  75. get => RoutManagerState == (int)RtState.Maintenance;
  76. }
  77. [Subscription(ParamName.IsAutoMode, SystemStateModule)]
  78. public bool IsAutoMode { get; set; }
  79. public ICommand Command
  80. {
  81. get;
  82. private set;
  83. }
  84. public ICommand FileCommand
  85. {
  86. get;
  87. set;
  88. }
  89. private void DoCommand(DependencyObject sender)
  90. {
  91. var command = CommandHelper.GetCommandItem(sender);
  92. var lstParameter = new List<object>(command.Parameters);
  93. lstParameter.Insert(0, command.Target);
  94. lstParameter.Insert(1, command.CommandName);
  95. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, lstParameter.ToArray());
  96. }
  97. private void DoFileCommand(DependencyObject sender)
  98. {
  99. var command = CommandHelper.GetCommandItem(sender);
  100. KeyValuePair<string, string> item = new KeyValuePair<string, string>();
  101. var cmd = command.CommandName;
  102. var target = command.Target;
  103. var type = (string)command.Parameters[1];
  104. if (cmd != "Add")
  105. {
  106. item = (KeyValuePair<string, string>)command.Parameters[0];
  107. }
  108. if (type == "Laser")
  109. {
  110. if (cmd == DeviceOperationName.ReadWaferID)
  111. {
  112. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, new object[] { target, cmd, true, item.Value });
  113. }
  114. else
  115. {
  116. var reader = WaferIDReaderItems.First(x => x.Module == (string)command.Target);
  117. UpdateFile(reader.LaserFiles, cmd, item);
  118. SaveConfig(string.Join(";", reader.LaserFiles.Select(x => x.Value)), reader.SCLaser);
  119. }
  120. }
  121. else
  122. {
  123. if (cmd == DeviceOperationName.ReadWaferID)
  124. {
  125. InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, new object[] { target, cmd, false, item.Value });
  126. }
  127. else
  128. {
  129. var reader = WaferIDReaderItems.First(x => x.Module == (string)command.Target);
  130. UpdateFile(reader.T7Files, cmd, item);
  131. SaveConfig(string.Join(";", reader.T7Files.Select(x => x.Value)), reader.SCT7Code);
  132. }
  133. }
  134. }
  135. private void UpdateFile(ObservableCollection<KeyValuePair<string, string>> target, string cmd, KeyValuePair<string, string> item)
  136. {
  137. switch (cmd)
  138. {
  139. case "Add":
  140. var dlg = new OpenFileDialog();
  141. dlg.Filter = "*.*|*.*";
  142. dlg.Multiselect = true;
  143. if (dlg.ShowDialog() == DialogResult.OK)
  144. {
  145. var files = dlg.FileNames;
  146. foreach (var file in files)
  147. {
  148. target.Add(new KeyValuePair<string, string>(Path.GetFileNameWithoutExtension(file), file));
  149. }
  150. }
  151. break;
  152. case "Remove":
  153. target.Remove(item);
  154. break;
  155. case "Up":
  156. var pos = target.IndexOf(item);
  157. var newPos = pos - 1 >= 0 ? pos - 1 : 0;
  158. target.Remove(item);
  159. target.Insert(newPos, item);
  160. break;
  161. case "Down":
  162. var pos1 = target.IndexOf(item);
  163. var newPos1 = pos1 + 1 < target.Count ? pos1 + 1 : target.Count - 1;
  164. target.Remove(item);
  165. target.Insert(newPos1, item);
  166. break;
  167. default:
  168. break;
  169. }
  170. }
  171. private void SaveConfig(string config, string sc)
  172. {
  173. InvokeClient.Instance.Service.DoOperation("System.SetConfig", new object[] { sc, config });
  174. }
  175. }
  176. public class WaferIDReaderItem:NotifiableItem
  177. {
  178. public WaferIDReaderItem(string module, string name)
  179. {
  180. Module = module;
  181. Name = name;
  182. }
  183. public string Module
  184. {
  185. get;
  186. protected set;
  187. }
  188. public string Name
  189. {
  190. get;
  191. protected set;
  192. }
  193. public string SCLaser
  194. {
  195. get;
  196. set;
  197. }
  198. public string SCT7Code
  199. {
  200. get;
  201. set;
  202. }
  203. private string _laserMarker;
  204. [Subscription(ParamName.LaserMaker1)]
  205. public string LaserMaker
  206. {
  207. get { return _laserMarker;}
  208. set { _laserMarker = value; InvokePropertyChanged(nameof(LaserMaker)); }
  209. }
  210. private string _t7;
  211. [Subscription(ParamName.LaserMaker2)]
  212. public string T7Code
  213. {
  214. get { return _t7; }
  215. set { _t7 = value; InvokePropertyChanged(nameof(T7Code)); }
  216. }
  217. private string _status;
  218. [Subscription(ParamName.WRIDReaderState)]
  219. public string WRIDReaderStatus
  220. {
  221. get { return _status; }
  222. set { _status = value; InvokePropertyChanged(nameof(WRIDReaderStatus)); }
  223. }
  224. public ObservableCollection<KeyValuePair<string, string>> LaserFiles
  225. {
  226. get; set;
  227. }
  228. public ObservableCollection<KeyValuePair<string, string>> T7Files
  229. {
  230. get; set;
  231. }
  232. }
  233. }