using Aitex.Core.RT.SCCore; using Aitex.Core.UI.MVVM; using Aitex.Core.Util; using Aitex.Sorter.Common; using Aitex.Sorter.UI.Controls.Common; using MECF.Framework.Common.OperationCenter; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Windows; using System.Windows.Forms; using System.Windows.Input; using MECF.Framework.Common.CommonData; using MECF.Framework.Common.DataCenter; namespace Aitex.Sorter.UI.ViewModel.Maintenance { public class WaferIDReaderViewModel : UIViewModelBase { public WaferIDReaderViewModel() : base("WaferIDReaderView") { Command = new DelegateCommand(DoCommand, x => !IsMaintenanceMode && !IsAutoMode); FileCommand = new DelegateCommand(DoFileCommand, x => !IsMaintenanceMode && !IsAutoMode); } public virtual WaferIDReaderItem[] WaferIDReaderItems { get; set; } [Subscription(ParamName.AlignerElapseTime, DeviceName.Aligner)] public string ElapseTime { get; set; } private double notch; [Subscription(ParamName.AlignerNotch, DeviceName.Aligner)] public double Notch { get { return notch; } set { notch = value / 1000; } } [Subscription(ParamName.WaferOnAligner, DeviceName.Aligner)] public bool WaferOnAligner { get; set; } [Subscription(ParamName.AlignerState, DeviceName.Aligner)] public string AlignerStatus { get; set; } [Subscription(ParamName.AlignerError, DeviceName.Aligner)] public string ErrorCode { get; set; } [Subscription(ParamName.RTStatus, SystemStateModule)] public int RoutManagerState { get; set; } public bool IsMaintenanceMode { get => RoutManagerState == (int)RtState.Maintenance; } [Subscription(ParamName.IsAutoMode, SystemStateModule)] public bool IsAutoMode { get; set; } public ICommand Command { get; private set; } public ICommand FileCommand { get; set; } private void DoCommand(DependencyObject sender) { var command = CommandHelper.GetCommandItem(sender); var lstParameter = new List(command.Parameters); lstParameter.Insert(0, command.Target); lstParameter.Insert(1, command.CommandName); InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, lstParameter.ToArray()); } private void DoFileCommand(DependencyObject sender) { var command = CommandHelper.GetCommandItem(sender); KeyValuePair item = new KeyValuePair(); var cmd = command.CommandName; var target = command.Target; var type = (string)command.Parameters[1]; if (cmd != "Add") { item = (KeyValuePair)command.Parameters[0]; } if (type == "Laser") { if (cmd == DeviceOperationName.ReadWaferID) { InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, new object[] { target, cmd, true, item.Value }); } else { var reader = WaferIDReaderItems.First(x => x.Module == (string)command.Target); UpdateFile(reader.LaserFiles, cmd, item); SaveConfig(string.Join(";", reader.LaserFiles.Select(x => x.Value)), reader.SCLaser); } } else { if (cmd == DeviceOperationName.ReadWaferID) { InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, new object[] { target, cmd, false, item.Value }); } else { var reader = WaferIDReaderItems.First(x => x.Module == (string)command.Target); UpdateFile(reader.T7Files, cmd, item); SaveConfig(string.Join(";", reader.T7Files.Select(x => x.Value)), reader.SCT7Code); } } } private void UpdateFile(ObservableCollection> target, string cmd, KeyValuePair item) { switch (cmd) { case "Add": var dlg = new OpenFileDialog(); dlg.Filter = "*.*|*.*"; dlg.Multiselect = true; if (dlg.ShowDialog() == DialogResult.OK) { var files = dlg.FileNames; foreach (var file in files) { target.Add(new KeyValuePair(Path.GetFileNameWithoutExtension(file), file)); } } break; case "Remove": target.Remove(item); break; case "Up": var pos = target.IndexOf(item); var newPos = pos - 1 >= 0 ? pos - 1 : 0; target.Remove(item); target.Insert(newPos, item); break; case "Down": var pos1 = target.IndexOf(item); var newPos1 = pos1 + 1 < target.Count ? pos1 + 1 : target.Count - 1; target.Remove(item); target.Insert(newPos1, item); break; default: break; } } private void SaveConfig(string config, string sc) { InvokeClient.Instance.Service.DoOperation("System.SetConfig", new object[] { sc, config }); } } public class WaferIDReaderItem:NotifiableItem { public WaferIDReaderItem(string module, string name) { Module = module; Name = name; } public string Module { get; protected set; } public string Name { get; protected set; } public string SCLaser { get; set; } public string SCT7Code { get; set; } private string _laserMarker; [Subscription(ParamName.LaserMaker1)] public string LaserMaker { get { return _laserMarker;} set { _laserMarker = value; InvokePropertyChanged(nameof(LaserMaker)); } } private string _t7; [Subscription(ParamName.LaserMaker2)] public string T7Code { get { return _t7; } set { _t7 = value; InvokePropertyChanged(nameof(T7Code)); } } private string _status; [Subscription(ParamName.WRIDReaderState)] public string WRIDReaderStatus { get { return _status; } set { _status = value; InvokePropertyChanged(nameof(WRIDReaderStatus)); } } public ObservableCollection> LaserFiles { get; set; } public ObservableCollection> T7Files { get; set; } } }