123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- 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<DependencyObject>(DoCommand, x => !IsMaintenanceMode && !IsAutoMode);
- FileCommand = new DelegateCommand<DependencyObject>(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<object>(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<string, string> item = new KeyValuePair<string, string>();
- var cmd = command.CommandName;
- var target = command.Target;
- var type = (string)command.Parameters[1];
- if (cmd != "Add")
- {
- item = (KeyValuePair<string, string>)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<KeyValuePair<string, string>> target, string cmd, KeyValuePair<string, string> 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<string, string>(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<KeyValuePair<string, string>> LaserFiles
- {
- get; set;
- }
- public ObservableCollection<KeyValuePair<string, string>> T7Files
- {
- get; set;
- }
- }
- }
|