123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- using SecsGem.Core;
- using SecsGem.Core.ItemModel;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.ConstrainedExecution;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- namespace EapClientSimulator
- {
- public class FrmSequenceModel : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public ObservableCollection<Sequence> NotifiableSequenceList { get; set; }
- public ICommand SetClearCommand { get; set; }
- public FrmSequenceModel(string sequenceName)
- {
- SetClearCommand = new DelegateCommand<int>(Clear);
- NotifiableSequenceList = new ObservableCollection<Sequence>();
- if (sequenceName.Contains(";"))
- {
- string[] strAry = sequenceName.Split(';');
- for (int i = 0; i < 25; i++)
- {
- NotifiableSequenceList.Add(new Sequence() { Name = strAry[i], Index = i + 1 });
- }
- }
- else
- {
- for (int i = 0; i < 25; i++)
- {
- NotifiableSequenceList.Add(new Sequence() { Name = sequenceName, Index = i + 1 });
- }
- }
- }
- public void Clear(int index)
- {
- Sequence item = NotifiableSequenceList.First(x => x.Index == index);
- if (item != null)
- {
- item.Name = "";
- }
- }
- public void RaisePropertyChanged(string propertyName)
- {
- if (this.PropertyChanged != null)
- {
- this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- }
- /// <summary>
- /// FrmSequence.xaml 的交互逻辑
- /// </summary>
- public partial class FrmSequence : Window
- {
- public FrmSequenceModel viewModel;
- public event EventHandler<string> OnSendMessage;
- public event EventHandler<string> OnUpdateSequence;
- private string portId;
- private string jobId;
- private string lotId;
- public FrmSequence(string portId,string jobId,string lotId,string sequence)
- {
- InitializeComponent();
- this.portId = portId;
- this.jobId = jobId;
- this.lotId = lotId;
- this.viewModel = new FrmSequenceModel(sequence);
- this.DataContext= viewModel;
- }
- private void btnConfirm_Click(object sender, RoutedEventArgs e)
- {
- RemoteCommand remoteCommand = new RemoteCommand();
- remoteCommand.Command = "PP-SELECT";
- RemoteParameter portParameter = new RemoteParameter();
- portParameter.Name = "PortID";
- portParameter.Value = new StringItem(SecsGem.Core.DataFormat.Ascii, portId);
- remoteCommand.RemoteParameters.Add(portParameter);
- RemoteParameter jobParameter = new RemoteParameter();
- jobParameter.Name = "JobID";
- jobParameter.Value= new StringItem(SecsGem.Core.DataFormat.Ascii,jobId);
- remoteCommand.RemoteParameters.Add(jobParameter);
- RemoteParameter lotParameter = new RemoteParameter();
- lotParameter.Name = "LotID";
- lotParameter.Value = new StringItem(SecsGem.Core.DataFormat.Ascii, lotId);
- remoteCommand.RemoteParameters.Add(lotParameter);
- RemoteParameter sequenceParameter = new RemoteParameter();
- sequenceParameter.Name = "SequenceID";
- Item item = new SecsGem.Core.ItemModel.ListItem();
- string sequence = "";
- for(int i=0;i<25;i++)
- {
- Item slotItem = new StringItem(SecsGem.Core.DataFormat.Ascii, viewModel.NotifiableSequenceList.ElementAt(i).Name);
- item.AddItem(slotItem);
- sequence += viewModel.NotifiableSequenceList.ElementAt(i).Name+";";
- }
- sequence.Remove(sequence.Length - 2);
- sequenceParameter.Value = item;
- remoteCommand.RemoteParameters.Add(sequenceParameter);
- SecsGem.Core.SecsMessage secsMessage = SecsMessageSendUtil.CreateS2F49Message(remoteCommand);
- if (GlobalData.Client != null)
- {
- GlobalData.Client.SendMessage(secsMessage);
- }
- if (OnSendMessage != null)
- {
- OnSendMessage(this, SmlSerializationUtil.SerializeItemToString(secsMessage));
- }
- if(OnUpdateSequence!=null)
- {
- OnUpdateSequence(this,sequence);
- }
- this.Close();
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- }
- private void btnClose_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
- }
- private void btnClear_Click(object sender, RoutedEventArgs e)
- {
- foreach (Sequence item in viewModel.NotifiableSequenceList)
- {
- item.Name = "";
- }
- }
- private void btnSetAll_Click(object sender, RoutedEventArgs e)
- {
- string name = "";
- foreach (Sequence item in viewModel.NotifiableSequenceList)
- {
- if(!string.IsNullOrEmpty(item.Name))
- {
- name = item.Name;
- break;
- }
- }
- foreach (Sequence item in viewModel.NotifiableSequenceList)
- {
- item.Name = name;
- }
- }
- }
- public class Sequence: INotifyPropertyChanged
- {
- public string Name { get { return name; } set { name = value; this.OnPropertyChanged("Name"); } }
- private string name;
- public int Index { get; set; }
- public event PropertyChangedEventHandler PropertyChanged;
- protected void OnPropertyChanged(string name)
- {
- if (null != this.PropertyChanged)
- {
- this.PropertyChanged(this, new PropertyChangedEventArgs(name));
- }
- }
- }
- public class DelegateCommand<T> : ICommand
- {
- readonly Action<T> _execute;
- readonly Predicate<T> _canExecute;
- public event EventHandler CanExecuteChanged;
- public DelegateCommand(Action<T> execute)
- : this(execute, null)
- {
- }
- public DelegateCommand(Action<T> execute, Predicate<T> canExecute)
- {
- if (execute == null)
- throw new ArgumentNullException("execute");
- _execute = execute;
- _canExecute = canExecute;
- }
- public bool CanExecute(object parameter)
- {
- return _canExecute == null ? true : _canExecute((T)parameter);
- }
- // The CanExecuteChanged is automatically registered by command binding, we can assume that it has some execution logic
- // to update the button's enabled\disabled state(though we cannot see). So raises this event will cause the button's state be updated.
- public void RaiseCanExecuteChanged()
- {
- if (CanExecuteChanged != null)
- CanExecuteChanged(this, EventArgs.Empty);
- }
- public void Execute(object parameter)
- {
- _execute((T)parameter);
- }
- }
- }
|