using Aitex.Core.Common.DeviceData; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.DBCore; using MECF.Framework.Common.Device.Bases; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.OperationCenter; using Prism.Commands; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Threading; using Venus_Core; using Venus_MainPages.Unity; namespace Venus_MainPages.ViewModels { public class GasVerificationViewModel : BindableBase { #region 私有变量 private ObservableCollection m_VerificationOnePointDataRecords; private ObservableCollection m_VerificationDataTenPointRecords; private DispatcherTimer timer = new DispatcherTimer(); private PMState m_PMCurrentState; private ObservableCollection m_MFCCalibrationOnePointData; private ObservableCollection m_MFCCalibrationTenPointsData; private ObservableCollection m_MFCVerificationPoints; private string OnePointIndex = "MfcGas1"; private int m_OnePointSetPoint; private bool m_firsflag = true; #endregion #region 公开变量 //private Dictionary m_RtDataValues; public string ModuleName; public ObservableCollection VerificationDataOnePointRecords { get { return m_VerificationOnePointDataRecords; } set { SetProperty(ref m_VerificationOnePointDataRecords, value); } } public ObservableCollection VerificationDataTenPointRecords { get { return m_VerificationDataTenPointRecords; } set { SetProperty(ref m_VerificationDataTenPointRecords, value); } } public int OnePointSetPoint { get { return m_OnePointSetPoint; } set { SetProperty(ref m_OnePointSetPoint, value); } } public PMState PMCurrentState { get { return m_PMCurrentState; } set { if ((m_PMCurrentState == PMState.MFCVerification || m_PMCurrentState == PMState.AllMFCVerification) && value == PMState.Idle) { InitTable(); } SetProperty(ref m_PMCurrentState, value); } } public ObservableCollection MFCCalibrationOnePointDataRecords { get { return m_MFCCalibrationOnePointData; } set { SetProperty(ref m_MFCCalibrationOnePointData, value); } } public ObservableCollection MFCCalibrationTenPointsDataRecords { get { return m_MFCCalibrationTenPointsData; } set { SetProperty(ref m_MFCCalibrationTenPointsData, value); } } public ObservableCollection MFCVerificationPoints { get { return m_MFCVerificationPoints; } set { SetProperty(ref m_MFCVerificationPoints, value); } } private DelegateCommand _SelectOneVerificaton; private DelegateCommand _LoadCommand; public DelegateCommand LoadCommand => _LoadCommand ?? (_LoadCommand = new DelegateCommand(OnLoad)); public DelegateCommand SelectOneVerificaton => _SelectOneVerificaton ?? (_SelectOneVerificaton = new DelegateCommand(OnSelectGas)); private DelegateCommand _StartOnePointVerificationCommand; public DelegateCommand StartOnePointVerificationCommand => _StartOnePointVerificationCommand ?? (_StartOnePointVerificationCommand = new DelegateCommand(OnStartOnePointVerification)); private DelegateCommand _StartTenPointVerificationCommand; public DelegateCommand StartTenPointVerificationCommand => _StartTenPointVerificationCommand ?? (_StartTenPointVerificationCommand = new DelegateCommand(OnStartTenPointVerification)); private DelegateCommand _AbortCommand; public DelegateCommand AbortCommand => _AbortCommand ?? (_AbortCommand = new DelegateCommand(OnAbort)); private DelegateCommand _FlashCommand; public DelegateCommand FlashCommand => _FlashCommand ?? (_FlashCommand = new DelegateCommand(OnFlash)); #endregion #region 初始函数 public GasVerificationViewModel() { timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += Timer_Tick; timer.Start(); MFCCalibrationOnePointDataRecords = new ObservableCollection(); MFCCalibrationTenPointsDataRecords = new ObservableCollection(); MFCVerificationPoints = new ObservableCollection(); for (int i = 0; i < 10; i++) { MFCCalibrationTenPointsDataRecords.Add(new MFCCalibrationTenPointsData()); } for (int i = 0; i < 1; i++) { MFCCalibrationOnePointDataRecords.Add(new MFCCalibrationTenPointsData()); } } public void Init() { //OnSelectGas(); } #endregion #region 私有方法 private void Timer_Tick(object sender, EventArgs e) { //InitTable(); PMCurrentState = (PMState)QueryDataClient.Instance.Service.GetData($"{ModuleName}.FsmState"); if (VerificationDataOnePointRecords!=null && OnePointIndex != VerificationDataOnePointRecords.First(x => x.IsCheckGas == true).GasIndex) { MFCVerificationPoints.Clear(); var MFCData = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.{VerificationDataOnePointRecords.First(x => x.IsCheckGas == true).GasIndex}"); if (MFCData != null) { int delta1 = (int)MFCData.Scale / 10; for (int i = 0; i < 10; i++) { MFCVerificationPoints.Add(delta1 + delta1 * i); } OnePointIndex = VerificationDataOnePointRecords.First(x => x.IsCheckGas == true).GasIndex; OnePointSetPoint = MFCVerificationPoints[0]; } } } private void OnLoad(object mFCVerificationView) { if (m_firsflag) { m_firsflag = false; InitTable(); } } private void OnStartOnePointVerification() { InvokeClient.Instance.Service.DoOperation($"{ModuleName}.{RtOperation.MFCVerification}", VerificationDataOnePointRecords.First(x => x.IsCheckGas == true).GasIndex.Replace("MfcGas",""), OnePointSetPoint, 1); } private void OnStartTenPointVerification() { InvokeClient.Instance.Service.DoOperation($"{ModuleName}.{RtOperation.MFCVerification}", VerificationDataTenPointRecords.First(x => x.IsCheckGas == true).GasIndex.Replace("MfcGas", ""), 2, 10); } public void OnAbort() { InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort"); } public void OnFlash() { InitTable(); } private void OnSelectGas(object gasindex) { if (gasindex != null) { } } private void InitTable() { var onePointData = QueryDataClient.Instance.Service.GetMFCVerificationOnePointData(); if (onePointData != null) { var _onePointData = onePointData.Where(x => x.Module == ModuleName); VerificationDataOnePointRecords = new ObservableCollection(); for (int i = 1; i <= 12; i++) { if ((bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas{i}.Enable")) { VerificationDataOnePointRecords.Add(new VerificationOneData() { GasIndex = $"MfcGas{i}", GasName = QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas{i}.GasName").ToString(), Setpoint = _onePointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _onePointData.FirstOrDefault(x=>x.Name== $"MfcGas{i}").Setpoint : 0f, Calculate = _onePointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _onePointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Calculate : 0f, OperateTime = _onePointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? DateTime.Parse(_onePointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").OperateTime.ToString()).ToString("yyyy/MM/dd HH:mm:ss") : "", FullRange = QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas{i}.MfcN2Scale").ToString(), IsCheckGas = false }); } } if(VerificationDataOnePointRecords.Count > 0) VerificationDataOnePointRecords[0].IsCheckGas = true; } var tenPointsData = QueryDataClient.Instance.Service.GetMFCVerificationTenPointsData(); if (tenPointsData != null) { var _tenPointData = tenPointsData.Where(x => x.Module == ModuleName); VerificationDataTenPointRecords = new ObservableCollection(); for (int i = 1; i <= 12; i++) { if ((bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas{i}.Enable")) { VerificationDataTenPointRecords.Add(new VerificationOneData() { GasIndex = $"MfcGas{i}", GasName = QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas{i}.GasName").ToString(), Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent10Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent10Calculate : 0f, OperateTime = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? DateTime.Parse(_tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").OperateTime.ToString()).ToString("yyyy/MM/dd HH:mm:ss") : "", FullRange = QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas{i}.MfcN2Scale").ToString(), IsCheckGas = false, ShowIndex = true }); ; VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent20Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent20Calculate : 0f, ShowIndex = false }); VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent30Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent30Calculate : 0f, ShowIndex = false }); VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent40Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent40Calculate : 0f, ShowIndex = false }); VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent50Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent50Calculate : 0f, ShowIndex = false }); VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent60Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent60Calculate : 0f, ShowIndex = false }); VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent70Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent70Calculate : 0f, ShowIndex = false }); VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent80Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent80Calculate : 0f, ShowIndex = false }); VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent90Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent90Calculate : 0f, ShowIndex = false }); VerificationDataTenPointRecords.Add(new VerificationOneData() { Setpoint = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent100Setpoint : 0f, Calculate = _tenPointData.Count(x => x.Name == $"MfcGas{i}") > 0 ? _tenPointData.FirstOrDefault(x => x.Name == $"MfcGas{i}").Percent100Calculate : 0f, ShowIndex = false }); } } } } #endregion } public class VerificationOneData { public string GasIndex { get; set; } public string GasName { get; set; } public string FullRange { get; set; } public float Setpoint { get; set; } public float Calculate { get; set; } public string OperateTime { get; set; } public bool IsCheckGas { get; set; } public bool ShowIndex { get;set; } } }