123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438 |
- using Aitex.Core.Common.DeviceData;
- using ExcelLibrary.SpreadSheet;
- 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.IO;
- 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<VerificationOneData> m_VerificationOnePointDataRecords;
- private ObservableCollection<VerificationOneData> m_VerificationDataTenPointRecords;
- private DispatcherTimer timer = new DispatcherTimer();
- private PMState m_PMCurrentState;
- private ObservableCollection<MFCCalibrationTenPointsData> m_MFCCalibrationOnePointData;
- private ObservableCollection<MFCCalibrationTenPointsData> m_MFCCalibrationTenPointsData;
- private ObservableCollection<int> m_MFCVerificationPoints;
- private string OnePointIndex = "MfcGas1";
- private int m_OnePointSetPoint;
- private bool m_firsflag = true;
- #endregion
- #region 公开变量
- //private Dictionary<string, object> m_RtDataValues;
- public string ModuleName;
- public ObservableCollection<VerificationOneData> VerificationDataOnePointRecords
- {
- get { return m_VerificationOnePointDataRecords; }
- set { SetProperty(ref m_VerificationOnePointDataRecords, value); }
- }
- public ObservableCollection<VerificationOneData> 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<MFCCalibrationTenPointsData> MFCCalibrationOnePointDataRecords
- {
- get { return m_MFCCalibrationOnePointData; }
- set { SetProperty(ref m_MFCCalibrationOnePointData, value); }
- }
- public ObservableCollection<MFCCalibrationTenPointsData> MFCCalibrationTenPointsDataRecords
- {
- get { return m_MFCCalibrationTenPointsData; }
- set { SetProperty(ref m_MFCCalibrationTenPointsData, value); }
- }
- public ObservableCollection<int> MFCVerificationPoints
- {
- get { return m_MFCVerificationPoints; }
- set
- {
- SetProperty(ref m_MFCVerificationPoints, value);
- }
- }
- private DelegateCommand<object> _SelectOneVerificaton;
- private DelegateCommand<object> _LoadCommand;
- public DelegateCommand<object> LoadCommand =>
- _LoadCommand ?? (_LoadCommand = new DelegateCommand<object>(OnLoad));
- public DelegateCommand<object> SelectOneVerificaton =>
- _SelectOneVerificaton ?? (_SelectOneVerificaton = new DelegateCommand<object>(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));
- private DelegateCommand<object> _ExportCommand;
- public DelegateCommand<object> ExportCommand =>
- _ExportCommand ?? (_ExportCommand = new DelegateCommand<object>(OnExport));
- #endregion
- #region 初始函数
- public GasVerificationViewModel()
- {
- timer.Interval = TimeSpan.FromSeconds(1);
- timer.Tick += Timer_Tick;
- timer.Start();
- MFCCalibrationOnePointDataRecords = new ObservableCollection<MFCCalibrationTenPointsData>();
- MFCCalibrationTenPointsDataRecords = new ObservableCollection<MFCCalibrationTenPointsData>();
-
- MFCVerificationPoints = new ObservableCollection<int>();
- 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();
- if (VerificationDataOnePointRecords != null)
- {
- 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 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();
- }
- public void OnExport(object data)
- {
- int datatype = Convert.ToInt32(data);
- switch (datatype)
- {
- case 1:
- List2Excel(VerificationDataOnePointRecords);
- break;
- case 10:
- List2Excel(VerificationDataTenPointRecords);
- break;
- }
- }
- private void List2Excel(ObservableCollection<VerificationOneData> datas)
- {
- if (datas == null || datas.Count == 0) return;
- Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
- dlg.DefaultExt = ".xls"; // Default file extension
- dlg.Filter = "数据表格文件|*.xls"; // Filter files by extension
- dlg.FileName = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}";
- Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
- if (result != true) // open file dialog box results
- return;
- if (File.Exists(dlg.FileName))
- {
- File.Delete(dlg.FileName);
- }
- Workbook workbook = new Workbook();
- Worksheet worksheet = new Worksheet("Sheet1");
- //增加行名
- int col = 0;
- worksheet.Cells[0, col++] = new Cell("GasIndex");
- worksheet.Cells[0, col++] = new Cell("GasName");
- worksheet.Cells[0, col++] = new Cell("FullRange");
- worksheet.Cells[0, col++] = new Cell("Setpoint");
- worksheet.Cells[0, col++] = new Cell("Calculate");
- worksheet.Cells[0, col++] = new Cell("Error(%)");
- worksheet.Cells[0, col++] = new Cell("OperateTime");
- // 添加数据行
- for (int i = 0; i < datas.Count * 2; i++)
- {
- if (i < datas.Count)
- {
- int colidx = 0;
- worksheet.Cells[i + 1, colidx++] = new Cell(string.IsNullOrEmpty(datas[i].GasIndex) ? "" : datas[i].GasIndex);
- worksheet.Cells[i + 1, colidx++] = new Cell(string.IsNullOrEmpty(datas[i].GasName) ? "" : datas[i].GasName);
- worksheet.Cells[i + 1, colidx++] = new Cell(string.IsNullOrEmpty(datas[i].FullRange) ? "" : datas[i].FullRange);
- worksheet.Cells[i + 1, colidx++] = new Cell(datas[i].Setpoint.ToString());
- worksheet.Cells[i + 1, colidx++] = new Cell(datas[i].Calculate.ToString());
- worksheet.Cells[i + 1, colidx++] = new Cell(MFCError(datas[i].Setpoint, datas[i].Calculate).ToString());
- worksheet.Cells[i + 1, colidx++] = new Cell(string.IsNullOrEmpty(datas[i].OperateTime) ? "" : datas[i].OperateTime);
- }
- else
- {
- //增加empty cell 否则无法正常打开
- int colidx = 0;
- worksheet.Cells[i + 1, colidx++] = new Cell($"");
- worksheet.Cells[i + 2, colidx++] = new Cell($"");
- worksheet.Cells[i + 3, colidx++] = new Cell($"");
- worksheet.Cells[i + 4, colidx++] = new Cell($"");
- worksheet.Cells[i + 5, colidx++] = new Cell($"");
- worksheet.Cells[i + 6, colidx++] = new Cell($"");
- worksheet.Cells[i + 7, colidx++] = new Cell($"");
- }
- }
- // 保存文件
- workbook.Worksheets.Add(worksheet);
- workbook.Save(dlg.FileName);
- }
- private float MFCError(float v1, float v2)
- {
- float setPoint = v1;
- float calculate = v2;
- if (calculate == 0)
- {
- return 0;
- }
- return (Math.Abs(calculate) - Math.Abs(setPoint)) / Math.Abs(setPoint) * 100;
- }
- 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<VerificationOneData>();
- 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<VerificationOneData>();
- 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; }
- }
- }
|