FrmSequence.xaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using SecsGem.Core;
  2. using SecsGem.Core.ItemModel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. using System.Runtime.ConstrainedExecution;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Shapes;
  19. namespace EapClientSimulator
  20. {
  21. public class FrmSequenceModel : INotifyPropertyChanged
  22. {
  23. public event PropertyChangedEventHandler PropertyChanged;
  24. public ObservableCollection<Sequence> NotifiableSequenceList { get; set; }
  25. public ICommand SetClearCommand { get; set; }
  26. public FrmSequenceModel(string sequenceName)
  27. {
  28. SetClearCommand = new DelegateCommand<int>(Clear);
  29. NotifiableSequenceList = new ObservableCollection<Sequence>();
  30. if (sequenceName.Contains(";"))
  31. {
  32. string[] strAry = sequenceName.Split(';');
  33. for (int i = 0; i < 25; i++)
  34. {
  35. NotifiableSequenceList.Add(new Sequence() { Name = strAry[i], Index = i + 1 });
  36. }
  37. }
  38. else
  39. {
  40. for (int i = 0; i < 25; i++)
  41. {
  42. NotifiableSequenceList.Add(new Sequence() { Name = sequenceName, Index = i + 1 });
  43. }
  44. }
  45. }
  46. public void Clear(int index)
  47. {
  48. Sequence item = NotifiableSequenceList.First(x => x.Index == index);
  49. if (item != null)
  50. {
  51. item.Name = "";
  52. }
  53. }
  54. public void RaisePropertyChanged(string propertyName)
  55. {
  56. if (this.PropertyChanged != null)
  57. {
  58. this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  59. }
  60. }
  61. }
  62. /// <summary>
  63. /// FrmSequence.xaml 的交互逻辑
  64. /// </summary>
  65. public partial class FrmSequence : Window
  66. {
  67. public FrmSequenceModel viewModel;
  68. public event EventHandler<string> OnSendMessage;
  69. public event EventHandler<string> OnUpdateSequence;
  70. private string portId;
  71. private string jobId;
  72. private string lotId;
  73. public FrmSequence(string portId,string jobId,string lotId,string sequence)
  74. {
  75. InitializeComponent();
  76. this.portId = portId;
  77. this.jobId = jobId;
  78. this.lotId = lotId;
  79. this.viewModel = new FrmSequenceModel(sequence);
  80. this.DataContext= viewModel;
  81. }
  82. private void btnConfirm_Click(object sender, RoutedEventArgs e)
  83. {
  84. RemoteCommand remoteCommand = new RemoteCommand();
  85. remoteCommand.Command = "PP-SELECT";
  86. RemoteParameter portParameter = new RemoteParameter();
  87. portParameter.Name = "PortID";
  88. portParameter.Value = new StringItem(SecsGem.Core.DataFormat.Ascii, portId);
  89. remoteCommand.RemoteParameters.Add(portParameter);
  90. RemoteParameter jobParameter = new RemoteParameter();
  91. jobParameter.Name = "JobID";
  92. jobParameter.Value= new StringItem(SecsGem.Core.DataFormat.Ascii,jobId);
  93. remoteCommand.RemoteParameters.Add(jobParameter);
  94. RemoteParameter lotParameter = new RemoteParameter();
  95. lotParameter.Name = "LotID";
  96. lotParameter.Value = new StringItem(SecsGem.Core.DataFormat.Ascii, lotId);
  97. remoteCommand.RemoteParameters.Add(lotParameter);
  98. RemoteParameter sequenceParameter = new RemoteParameter();
  99. sequenceParameter.Name = "SequenceID";
  100. Item item = new SecsGem.Core.ItemModel.ListItem();
  101. string sequence = "";
  102. for(int i=0;i<25;i++)
  103. {
  104. Item slotItem = new StringItem(SecsGem.Core.DataFormat.Ascii, viewModel.NotifiableSequenceList.ElementAt(i).Name);
  105. item.AddItem(slotItem);
  106. sequence += viewModel.NotifiableSequenceList.ElementAt(i).Name+";";
  107. }
  108. sequence.Remove(sequence.Length - 2);
  109. sequenceParameter.Value = item;
  110. remoteCommand.RemoteParameters.Add(sequenceParameter);
  111. SecsGem.Core.SecsMessage secsMessage = SecsMessageSendUtil.CreateS2F49Message(remoteCommand);
  112. if (GlobalData.Client != null)
  113. {
  114. GlobalData.Client.SendMessage(secsMessage);
  115. }
  116. if (OnSendMessage != null)
  117. {
  118. OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
  119. }
  120. if(OnUpdateSequence!=null)
  121. {
  122. OnUpdateSequence(this,sequence);
  123. }
  124. this.Close();
  125. }
  126. private void Window_Loaded(object sender, RoutedEventArgs e)
  127. {
  128. }
  129. private void btnClose_Click(object sender, RoutedEventArgs e)
  130. {
  131. this.Close();
  132. }
  133. private void btnClear_Click(object sender, RoutedEventArgs e)
  134. {
  135. foreach (Sequence item in viewModel.NotifiableSequenceList)
  136. {
  137. item.Name = "";
  138. }
  139. }
  140. private void btnSetAll_Click(object sender, RoutedEventArgs e)
  141. {
  142. string name = "";
  143. foreach (Sequence item in viewModel.NotifiableSequenceList)
  144. {
  145. if(!string.IsNullOrEmpty(item.Name))
  146. {
  147. name = item.Name;
  148. break;
  149. }
  150. }
  151. foreach (Sequence item in viewModel.NotifiableSequenceList)
  152. {
  153. item.Name = name;
  154. }
  155. }
  156. }
  157. public class Sequence: INotifyPropertyChanged
  158. {
  159. public string Name { get { return name; } set { name = value; this.OnPropertyChanged("Name"); } }
  160. private string name;
  161. public int Index { get; set; }
  162. public event PropertyChangedEventHandler PropertyChanged;
  163. protected void OnPropertyChanged(string name)
  164. {
  165. if (null != this.PropertyChanged)
  166. {
  167. this.PropertyChanged(this, new PropertyChangedEventArgs(name));
  168. }
  169. }
  170. }
  171. public class DelegateCommand<T> : ICommand
  172. {
  173. readonly Action<T> _execute;
  174. readonly Predicate<T> _canExecute;
  175. public event EventHandler CanExecuteChanged;
  176. public DelegateCommand(Action<T> execute)
  177. : this(execute, null)
  178. {
  179. }
  180. public DelegateCommand(Action<T> execute, Predicate<T> canExecute)
  181. {
  182. if (execute == null)
  183. throw new ArgumentNullException("execute");
  184. _execute = execute;
  185. _canExecute = canExecute;
  186. }
  187. public bool CanExecute(object parameter)
  188. {
  189. return _canExecute == null ? true : _canExecute((T)parameter);
  190. }
  191. // The CanExecuteChanged is automatically registered by command binding, we can assume that it has some execution logic
  192. // to update the button's enabled\disabled state(though we cannot see). So raises this event will cause the button's state be updated.
  193. public void RaiseCanExecuteChanged()
  194. {
  195. if (CanExecuteChanged != null)
  196. CanExecuteChanged(this, EventArgs.Empty);
  197. }
  198. public void Execute(object parameter)
  199. {
  200. _execute((T)parameter);
  201. }
  202. }
  203. }