using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Aitex.Core.Common.DeviceData;
using MECF.Framework.Common.DataCenter;
using MECF.Framework.Common.DBCore;
using MECF.Framework.Common.OperationCenter;
using Prism.Commands;
using Prism.Mvvm;
using Venus_Core;
using Venus_MainPages.Unity;
using Venus_MainPages.Views;

namespace Venus_MainPages.ViewModels
{
    public class MFCVerificationViewModel : BindableBase
    {
        #region 私有字段


        private AITMfcData m_MFCData;




        private Dictionary<string, object> m_RtDataValues;
        public string ModuleName;
        private ObservableCollection<int> m_MFCVerificationPoints = new ObservableCollection<int>();
        private int m_GasSelectedIndex;
        private int m_PointsSelectedIndex;
        DispatcherTimer timer = new DispatcherTimer();
        private ObservableCollection<MFCCalibrationData> m_MFCVerificationData=new ObservableCollection<MFCCalibrationData>();
        private ObservableCollection<MFCVerificationData> m_VerificationDataRecords = new ObservableCollection<MFCVerificationData>();
        private ObservableCollection<MFCVerificationOnePointData> m_VerificationOnePointDataRecords = new ObservableCollection<MFCVerificationOnePointData>();
        private ObservableCollection<MFCVerificationTenPointsData> m_VerificationTenPointsDataRecords = new ObservableCollection<MFCVerificationTenPointsData>();
        private ObservableCollection<MFCCalibrationTenPointsData> m_MFCCalibrationTenPointsData = new ObservableCollection<MFCCalibrationTenPointsData>();
        private ObservableCollection<MFCCalibrationTenPointsData> m_MFCCalibrationOnePointData = new ObservableCollection<MFCCalibrationTenPointsData>();

        private PMState m_PMCurrentState;
        private JetChamber ChamberType;
        private bool m_MFC7IsEnable;
        private bool m_MFC8IsEnable;
        private bool m_MFC9IsEnable;
        private bool m_MFC10IsEnable;
        private bool m_MFC11IsEnable;
        private bool m_MFC12IsEnable;

        private MFCVerificationView m_MFCVerificationView;

        #endregion


        #region 属性
        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<int> MFCVerificationPoints
        {
            get { return m_MFCVerificationPoints; }
            set
            {

                SetProperty(ref m_MFCVerificationPoints, value);
            }
        }
      
        public Dictionary<string, object> RtDataValues
        {
            get { return m_RtDataValues; }
            set { SetProperty(ref m_RtDataValues, value); }
        }
        public AITMfcData MFCData
        {
            get { return m_MFCData; }
            set { SetProperty(ref m_MFCData, value); }
        }

        public int GasSelectedIndex
        {
            get { return m_GasSelectedIndex; }
            set { SetProperty(ref m_GasSelectedIndex, value); }

        }
        public int PointsSelectedIndex
        {
            get { return m_PointsSelectedIndex; }
            set { SetProperty(ref m_PointsSelectedIndex, value); }

        }
        private DelegateCommand<object> _DataGridSelectionChangedCommand;
        public DelegateCommand<object> DataGridSelectionChangedCommand =>
           _DataGridSelectionChangedCommand ?? (_DataGridSelectionChangedCommand = new DelegateCommand<object>(OnDataGridSelectionChanged));
        public ObservableCollection<MFCCalibrationData> MFCCalibrationData
        {
            get { return m_MFCVerificationData; }
            set { SetProperty(ref m_MFCVerificationData, value); }
        }
        public ObservableCollection<MFCVerificationData> VerificationDataRecords
        {
            get { return m_VerificationDataRecords; }
            set { SetProperty(ref m_VerificationDataRecords, value); }
        }
        public ObservableCollection<MFCVerificationOnePointData> VerificationDataOnePointRecords
        {
            get { return m_VerificationOnePointDataRecords; }
            set { SetProperty(ref m_VerificationOnePointDataRecords, value); }
        }
        public ObservableCollection<MFCVerificationTenPointsData> VerificationDataTenPointsRecords
        {
            get { return m_VerificationTenPointsDataRecords; }
            set { SetProperty(ref m_VerificationTenPointsDataRecords, value); }
        }
        public ObservableCollection<MFCCalibrationTenPointsData> MFCCalibrationTenPointsDataRecords
        {
            get { return m_MFCCalibrationTenPointsData; }
            set { SetProperty(ref m_MFCCalibrationTenPointsData, value); }
        }
        public ObservableCollection<MFCCalibrationTenPointsData> MFCCalibrationOnePointDataRecords
        {
            get { return m_MFCCalibrationOnePointData; }
            set { SetProperty(ref m_MFCCalibrationOnePointData, value); }
        }
        public bool MFC7IsEnable
        {
            get { return m_MFC7IsEnable; }
            set { SetProperty(ref m_MFC7IsEnable, value); }
        }
        public bool MFC8IsEnable
        {
            get { return m_MFC8IsEnable; }
            set { SetProperty(ref m_MFC8IsEnable, value); }
        }
        public bool MFC9IsEnable
        {
            get { return m_MFC9IsEnable; }
            set { SetProperty(ref m_MFC9IsEnable, value); }
        }
        public bool MFC10IsEnable
        {
            get { return m_MFC10IsEnable; }
            set { SetProperty(ref m_MFC10IsEnable, value); }
        }
        public bool MFC11IsEnable
        {
            get { return m_MFC11IsEnable; }
            set { SetProperty(ref m_MFC11IsEnable, value); }
        }
        public bool MFC12IsEnable
        {
            get { return m_MFC12IsEnable; }
            set { SetProperty(ref m_MFC12IsEnable, value); }
        }
        #endregion

        #region 命令
        private DelegateCommand<object> _StartOnePointVerificationCommand;
        public DelegateCommand<object> StartOnePointVerificationCommand =>
            _StartOnePointVerificationCommand ?? (_StartOnePointVerificationCommand = new DelegateCommand<object>(OnStartOnePointVerification));

        private DelegateCommand<object> _StartTenPointVerificationCommand;
        public DelegateCommand<object> StartTenPointVerificationCommand =>
            _StartTenPointVerificationCommand ?? (_StartTenPointVerificationCommand = new DelegateCommand<object>(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 _SelectGasCommand;
        public DelegateCommand SelectGasCommand =>
            _SelectGasCommand ?? (_SelectGasCommand = new DelegateCommand(OnSelectGas));


        private DelegateCommand<object> _LoadCommand;
        public DelegateCommand<object> LoadCommand =>
            _LoadCommand ?? (_LoadCommand = new DelegateCommand<object>(OnLoad));


        #endregion
        public MFCVerificationViewModel()
        {         
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += Timer_Tick;
            timer.Start();
            for (int i = 0; i < 10; i++)
            {
                MFCCalibrationTenPointsDataRecords.Add(new MFCCalibrationTenPointsData());
            }
            for (int i = 0; i < 1; i++)
            {
                MFCCalibrationOnePointDataRecords.Add(new MFCCalibrationTenPointsData());
            }
        }

        #region 命令方法
        private void OnStartOnePointVerification(object obj)
        {
            var values = (object[])obj;
            string gasName = values[0].ToString();
            float flow = float.Parse(values[1].ToString());
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.{RtOperation.MFCVerification}", gasName, flow, 1);
        }

        private void OnStartTenPointVerification(object obj)
        {
            var values = (object[])obj;
            string gasName = values[0].ToString();
            float flow = float.Parse(values[1].ToString());
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.{RtOperation.MFCVerification}", gasName, flow, 10);
        }

        public void OnAbort()
        {
            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort");
        }
        public void OnFlash()
        {
            InitTable();
        }
        private void OnSelectGas()
        {
            MFCVerificationPoints.Clear();
            MFCData = (AITMfcData)QueryDataClient.Instance.Service.GetData($"{ModuleName}.MfcGas{(GasSelectedIndex + 1).ToString()}");
            if ( MFCData != null ) 
            {
                int delta1 = (int)MFCData.Scale / 10;
                for (int i = 0; i < 10; i++)
                {
                    MFCVerificationPoints.Add(delta1 + delta1 * i);
                }
                PointsSelectedIndex = 0;
            }         
        }
        //private void OnQuery()
        //{
        //    var AllLeakCheckDa = QueryDataClient.Instance.Service.GetMFCVerificationData(this.view.wfTimeFrom.Value, this.view.wfTimeTo.Value);
        //    if (AllLeakCheckDa != null)
        //    {
        //        VerificationDataRecords = new ObservableCollection<MFCVerificationData>(AllLeakCheckDa);
        //    }
        //}
        private void OnLoad(object mFCVerificationView)
        {
            ChamberType = (JetChamber)Enum.Parse(typeof(JetChamber), QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.ChamberType").ToString());
            InitTable();
         
            if (ChamberType != JetChamber.Kepler2200A && ChamberType != JetChamber.Kepler2200B)
            {
                MFC7IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas7.Enable");
                MFC8IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas8.Enable");
            }
            if (ChamberType == JetChamber.VenusSE || ChamberType == JetChamber.VenusDE || ChamberType == JetChamber.Kepler2300)
            {
                MFC7IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas7.Enable");
                MFC8IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas8.Enable");
            }
            if (ChamberType==JetChamber.VenusSE || ChamberType == JetChamber.VenusDE)
            {
                MFC9IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas9.Enable");
                MFC10IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas10.Enable");
                MFC11IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas11.Enable");
                MFC12IsEnable = (bool)QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.MfcGas12.Enable");
            }
            m_MFCVerificationView = mFCVerificationView as MFCVerificationView;
            if ( m_MFCVerificationView == null ) { return; }
            if (MFC7IsEnable == false)
            {
                m_MFCVerificationView.DataGridTemplateColumn7.Visibility = Visibility.Hidden;
                m_MFCVerificationView.OnePointDataGridTemplateColumn7.Visibility = Visibility.Hidden;
            }
            else
            {
                m_MFCVerificationView.DataGridTemplateColumn7.Visibility = Visibility.Visible;
                m_MFCVerificationView.OnePointDataGridTemplateColumn7.Visibility = Visibility.Visible;

            }
            if (MFC8IsEnable == false)
            {
                m_MFCVerificationView.DataGridTemplateColumn8.Visibility = Visibility.Hidden;
                m_MFCVerificationView.OnePointDataGridTemplateColumn8.Visibility = Visibility.Hidden;

            }
            else
            {
                m_MFCVerificationView.DataGridTemplateColumn8.Visibility = Visibility.Visible;
                m_MFCVerificationView.OnePointDataGridTemplateColumn8.Visibility = Visibility.Visible;

            }
        }
        #endregion

        #region 私有方法

        private void Timer_Tick(object sender, EventArgs e)
        {
            PMCurrentState = (PMState)QueryDataClient.Instance.Service.GetData($"{ModuleName}.FsmState");
        }

        public void Init()
        {
            OnSelectGas();
        }
        public void OnDataGridSelectionChanged(object obj)
        {
            if (obj == null)
            {
                return;
            }
            else 
            { 
                MFCVerificationOnePointData item = obj as MFCVerificationOnePointData;
                string name=item.Name.Substring(6,1);
                switch (name)
                {
                case "1":
                    MFCCalibrationOnePointDataRecords[0] = new MFCCalibrationTenPointsData { Gas1Calculate = item.Calculate, Gas1SetPoint = item.Setpoint };
                    break;
                case "2":
                    MFCCalibrationOnePointDataRecords[0] = new MFCCalibrationTenPointsData { Gas2Calculate = item.Calculate, Gas2SetPoint = item.Setpoint };
                    break;
                case "3":
                    MFCCalibrationOnePointDataRecords[0] = new MFCCalibrationTenPointsData { Gas3Calculate = item.Calculate, Gas3SetPoint = item.Setpoint };
                    break;
                case "4":
                    MFCCalibrationOnePointDataRecords[0] = new MFCCalibrationTenPointsData { Gas4Calculate = item.Calculate, Gas4SetPoint = item.Setpoint };
                    break;
                case "5":
                    MFCCalibrationOnePointDataRecords[0] = new MFCCalibrationTenPointsData { Gas5Calculate = item.Calculate, Gas5SetPoint = item.Setpoint };
                    break;
                case "6":
                    MFCCalibrationOnePointDataRecords[0] = new MFCCalibrationTenPointsData { Gas6Calculate = item.Calculate, Gas6SetPoint = item.Setpoint };
                    break;
                case "7":
                    MFCCalibrationOnePointDataRecords[0] = new MFCCalibrationTenPointsData { Gas7Calculate = item.Calculate, Gas7SetPoint = item.Setpoint };
                    break;
                case "8":
                    MFCCalibrationOnePointDataRecords[0] = new MFCCalibrationTenPointsData { Gas8Calculate = item.Calculate, Gas8SetPoint = item.Setpoint };
                    break;
                }
            }
        }
        private void InitTable()
        {
            var onePointData = QueryDataClient.Instance.Service.GetMFCVerificationOnePointData();
            if (onePointData != null)
            {
                var _onePointData = onePointData.Where(x => x.Module == ModuleName);
                VerificationDataOnePointRecords = new ObservableCollection<MFCVerificationOnePointData>(_onePointData);
            }
            var tenPointsData = QueryDataClient.Instance.Service.GetMFCVerificationTenPointsData();
            if (tenPointsData != null)
            {
                var _tenPointsData = tenPointsData.Where(x => x.Module == ModuleName);
                VerificationDataTenPointsRecords = new ObservableCollection<MFCVerificationTenPointsData>(_tenPointsData);
            }

            var data1 = VerificationDataTenPointsRecords.Where(x => x.Name == $"MfcGas1").FirstOrDefault();
            if (data1 != null)
            {
                MFCCalibrationTenPointsDataRecords[0].Gas1SetPoint = data1.Percent10Setpoint;
                MFCCalibrationTenPointsDataRecords[0].Gas1Calculate = data1.Percent10Calculate;

                MFCCalibrationTenPointsDataRecords[1].Gas1SetPoint = data1.Percent20Setpoint;
                MFCCalibrationTenPointsDataRecords[1].Gas1Calculate = data1.Percent20Calculate;

                MFCCalibrationTenPointsDataRecords[2].Gas1SetPoint = data1.Percent30Setpoint;
                MFCCalibrationTenPointsDataRecords[2].Gas1Calculate = data1.Percent30Calculate;

                MFCCalibrationTenPointsDataRecords[3].Gas1SetPoint = data1.Percent40Setpoint;
                MFCCalibrationTenPointsDataRecords[3].Gas1Calculate = data1.Percent40Calculate;

                MFCCalibrationTenPointsDataRecords[4].Gas1SetPoint = data1.Percent50Setpoint;
                MFCCalibrationTenPointsDataRecords[4].Gas1Calculate = data1.Percent50Calculate;

                MFCCalibrationTenPointsDataRecords[5].Gas1SetPoint = data1.Percent60Setpoint;
                MFCCalibrationTenPointsDataRecords[5].Gas1Calculate = data1.Percent60Calculate;

                MFCCalibrationTenPointsDataRecords[6].Gas1SetPoint = data1.Percent70Setpoint;
                MFCCalibrationTenPointsDataRecords[6].Gas1Calculate = data1.Percent70Calculate;

                MFCCalibrationTenPointsDataRecords[7].Gas1SetPoint = data1.Percent80Setpoint;
                MFCCalibrationTenPointsDataRecords[7].Gas1Calculate = data1.Percent80Calculate;

                MFCCalibrationTenPointsDataRecords[8].Gas1SetPoint = data1.Percent90Setpoint;
                MFCCalibrationTenPointsDataRecords[8].Gas1Calculate = data1.Percent90Calculate;

                MFCCalibrationTenPointsDataRecords[9].Gas1SetPoint = data1.Percent100Setpoint;
                MFCCalibrationTenPointsDataRecords[9].Gas1Calculate = data1.Percent100Calculate;
            }
            var data2 = VerificationDataTenPointsRecords.Where(x => x.Name == $"MfcGas2").FirstOrDefault();
            if (data2 != null)
            {
                MFCCalibrationTenPointsDataRecords[0].Gas2SetPoint = data2.Percent10Setpoint;
                MFCCalibrationTenPointsDataRecords[0].Gas2Calculate = data2.Percent10Calculate;

                MFCCalibrationTenPointsDataRecords[1].Gas2SetPoint = data2.Percent20Setpoint;
                MFCCalibrationTenPointsDataRecords[1].Gas2Calculate = data2.Percent20Calculate;

                MFCCalibrationTenPointsDataRecords[2].Gas2SetPoint = data2.Percent30Setpoint;
                MFCCalibrationTenPointsDataRecords[2].Gas2Calculate = data2.Percent30Calculate;

                MFCCalibrationTenPointsDataRecords[3].Gas2SetPoint = data2.Percent40Setpoint;
                MFCCalibrationTenPointsDataRecords[3].Gas2Calculate = data2.Percent40Calculate;

                MFCCalibrationTenPointsDataRecords[4].Gas2SetPoint = data2.Percent50Setpoint;
                MFCCalibrationTenPointsDataRecords[4].Gas2Calculate = data2.Percent50Calculate;

                MFCCalibrationTenPointsDataRecords[5].Gas2SetPoint = data2.Percent60Setpoint;
                MFCCalibrationTenPointsDataRecords[5].Gas2Calculate = data2.Percent60Calculate;

                MFCCalibrationTenPointsDataRecords[6].Gas2SetPoint = data2.Percent70Setpoint;
                MFCCalibrationTenPointsDataRecords[6].Gas2Calculate = data2.Percent70Calculate;

                MFCCalibrationTenPointsDataRecords[7].Gas2SetPoint = data2.Percent80Setpoint;
                MFCCalibrationTenPointsDataRecords[7].Gas2Calculate = data2.Percent80Calculate;

                MFCCalibrationTenPointsDataRecords[8].Gas2SetPoint = data2.Percent90Setpoint;
                MFCCalibrationTenPointsDataRecords[8].Gas2Calculate = data2.Percent90Calculate;

                MFCCalibrationTenPointsDataRecords[9].Gas2SetPoint = data2.Percent100Setpoint;
                MFCCalibrationTenPointsDataRecords[9].Gas2Calculate = data2.Percent100Calculate;
            }
            var data3 = VerificationDataTenPointsRecords.Where(x => x.Name == $"MfcGas3").FirstOrDefault();
            if (data3 != null)
            {
                MFCCalibrationTenPointsDataRecords[0].Gas3SetPoint = data3.Percent10Setpoint;
                MFCCalibrationTenPointsDataRecords[0].Gas3Calculate = data3.Percent10Calculate;

                MFCCalibrationTenPointsDataRecords[1].Gas3SetPoint = data3.Percent20Setpoint;
                MFCCalibrationTenPointsDataRecords[1].Gas3Calculate = data3.Percent20Calculate;

                MFCCalibrationTenPointsDataRecords[2].Gas3SetPoint = data3.Percent30Setpoint;
                MFCCalibrationTenPointsDataRecords[2].Gas3Calculate = data3.Percent30Calculate;

                MFCCalibrationTenPointsDataRecords[3].Gas3SetPoint = data3.Percent40Setpoint;
                MFCCalibrationTenPointsDataRecords[3].Gas3Calculate = data3.Percent40Calculate;

                MFCCalibrationTenPointsDataRecords[4].Gas3SetPoint = data3.Percent50Setpoint;
                MFCCalibrationTenPointsDataRecords[4].Gas3Calculate = data3.Percent50Calculate;

                MFCCalibrationTenPointsDataRecords[5].Gas3SetPoint = data3.Percent60Setpoint;
                MFCCalibrationTenPointsDataRecords[5].Gas3Calculate = data3.Percent60Calculate;

                MFCCalibrationTenPointsDataRecords[6].Gas3SetPoint = data3.Percent70Setpoint;
                MFCCalibrationTenPointsDataRecords[6].Gas3Calculate = data3.Percent70Calculate;

                MFCCalibrationTenPointsDataRecords[7].Gas3SetPoint = data3.Percent80Setpoint;
                MFCCalibrationTenPointsDataRecords[7].Gas3Calculate = data3.Percent80Calculate;

                MFCCalibrationTenPointsDataRecords[8].Gas3SetPoint = data3.Percent90Setpoint;
                MFCCalibrationTenPointsDataRecords[8].Gas3Calculate = data3.Percent90Calculate;

                MFCCalibrationTenPointsDataRecords[9].Gas3SetPoint = data3.Percent100Setpoint;
                MFCCalibrationTenPointsDataRecords[9].Gas3Calculate = data3.Percent100Calculate;
            }
            var data4 = VerificationDataTenPointsRecords.Where(x => x.Name == $"MfcGas4").FirstOrDefault();
            if (data4 != null)
            {
                MFCCalibrationTenPointsDataRecords[0].Gas4SetPoint = data4.Percent10Setpoint;
                MFCCalibrationTenPointsDataRecords[0].Gas4Calculate = data4.Percent10Calculate;

                MFCCalibrationTenPointsDataRecords[1].Gas4SetPoint = data4.Percent20Setpoint;
                MFCCalibrationTenPointsDataRecords[1].Gas4Calculate = data4.Percent20Calculate;

                MFCCalibrationTenPointsDataRecords[2].Gas4SetPoint = data4.Percent30Setpoint;
                MFCCalibrationTenPointsDataRecords[2].Gas4Calculate = data4.Percent30Calculate;

                MFCCalibrationTenPointsDataRecords[3].Gas4SetPoint = data4.Percent40Setpoint;
                MFCCalibrationTenPointsDataRecords[3].Gas4Calculate = data4.Percent40Calculate;

                MFCCalibrationTenPointsDataRecords[4].Gas4SetPoint = data4.Percent50Setpoint;
                MFCCalibrationTenPointsDataRecords[4].Gas4Calculate = data4.Percent50Calculate;

                MFCCalibrationTenPointsDataRecords[5].Gas4SetPoint = data4.Percent60Setpoint;
                MFCCalibrationTenPointsDataRecords[5].Gas4Calculate = data4.Percent60Calculate;

                MFCCalibrationTenPointsDataRecords[6].Gas4SetPoint = data4.Percent70Setpoint;
                MFCCalibrationTenPointsDataRecords[6].Gas4Calculate = data4.Percent70Calculate;

                MFCCalibrationTenPointsDataRecords[7].Gas4SetPoint = data4.Percent80Setpoint;
                MFCCalibrationTenPointsDataRecords[7].Gas4Calculate = data4.Percent80Calculate;

                MFCCalibrationTenPointsDataRecords[8].Gas4SetPoint = data4.Percent90Setpoint;
                MFCCalibrationTenPointsDataRecords[8].Gas4Calculate = data4.Percent90Calculate;

                MFCCalibrationTenPointsDataRecords[9].Gas4SetPoint = data4.Percent100Setpoint;
                MFCCalibrationTenPointsDataRecords[9].Gas4Calculate = data4.Percent100Calculate;
            }
            var data5= VerificationDataTenPointsRecords.Where(x => x.Name == $"MfcGas5").FirstOrDefault();
            if (data5 != null)
            {
                MFCCalibrationTenPointsDataRecords[0].Gas5SetPoint = data5.Percent10Setpoint;
                MFCCalibrationTenPointsDataRecords[0].Gas5Calculate = data5.Percent10Calculate;

                MFCCalibrationTenPointsDataRecords[1].Gas5SetPoint = data5.Percent20Setpoint;
                MFCCalibrationTenPointsDataRecords[1].Gas5Calculate = data5.Percent20Calculate;

                MFCCalibrationTenPointsDataRecords[2].Gas5SetPoint = data5.Percent30Setpoint;
                MFCCalibrationTenPointsDataRecords[2].Gas5Calculate = data5.Percent30Calculate;

                MFCCalibrationTenPointsDataRecords[3].Gas5SetPoint = data5.Percent40Setpoint;
                MFCCalibrationTenPointsDataRecords[3].Gas5Calculate = data5.Percent40Calculate;

                MFCCalibrationTenPointsDataRecords[4].Gas5SetPoint = data5.Percent50Setpoint;
                MFCCalibrationTenPointsDataRecords[4].Gas5Calculate = data5.Percent50Calculate;

                MFCCalibrationTenPointsDataRecords[5].Gas5SetPoint = data5.Percent60Setpoint;
                MFCCalibrationTenPointsDataRecords[5].Gas5Calculate = data5.Percent60Calculate;

                MFCCalibrationTenPointsDataRecords[6].Gas5SetPoint = data5.Percent70Setpoint;
                MFCCalibrationTenPointsDataRecords[6].Gas5Calculate = data5.Percent70Calculate;

                MFCCalibrationTenPointsDataRecords[7].Gas5SetPoint = data5.Percent80Setpoint;
                MFCCalibrationTenPointsDataRecords[7].Gas5Calculate = data5.Percent80Calculate;

                MFCCalibrationTenPointsDataRecords[8].Gas5SetPoint = data5.Percent90Setpoint;
                MFCCalibrationTenPointsDataRecords[8].Gas5Calculate = data5.Percent90Calculate;

                MFCCalibrationTenPointsDataRecords[9].Gas5SetPoint = data5.Percent100Setpoint;
                MFCCalibrationTenPointsDataRecords[9].Gas5Calculate = data5.Percent100Calculate;
            }
            var data6 = VerificationDataTenPointsRecords.Where(x => x.Name == $"MfcGas6").FirstOrDefault();
            if (data6 != null)
            {
                MFCCalibrationTenPointsDataRecords[0].Gas6SetPoint = data6.Percent10Setpoint;
                MFCCalibrationTenPointsDataRecords[0].Gas6Calculate = data6.Percent10Calculate;

                MFCCalibrationTenPointsDataRecords[1].Gas6SetPoint = data6.Percent20Setpoint;
                MFCCalibrationTenPointsDataRecords[1].Gas6Calculate = data6.Percent20Calculate;

                MFCCalibrationTenPointsDataRecords[2].Gas6SetPoint = data6.Percent30Setpoint;
                MFCCalibrationTenPointsDataRecords[2].Gas6Calculate = data6.Percent30Calculate;

                MFCCalibrationTenPointsDataRecords[3].Gas6SetPoint = data6.Percent40Setpoint;
                MFCCalibrationTenPointsDataRecords[3].Gas6Calculate = data6.Percent40Calculate;

                MFCCalibrationTenPointsDataRecords[4].Gas6SetPoint = data6.Percent50Setpoint;
                MFCCalibrationTenPointsDataRecords[4].Gas6Calculate = data6.Percent50Calculate;

                MFCCalibrationTenPointsDataRecords[5].Gas6SetPoint = data6.Percent60Setpoint;
                MFCCalibrationTenPointsDataRecords[5].Gas6Calculate = data6.Percent60Calculate;

                MFCCalibrationTenPointsDataRecords[6].Gas6SetPoint = data6.Percent70Setpoint;
                MFCCalibrationTenPointsDataRecords[6].Gas6Calculate = data6.Percent70Calculate;

                MFCCalibrationTenPointsDataRecords[7].Gas6SetPoint = data6.Percent80Setpoint;
                MFCCalibrationTenPointsDataRecords[7].Gas6Calculate = data6.Percent80Calculate;

                MFCCalibrationTenPointsDataRecords[8].Gas6SetPoint = data6.Percent90Setpoint;
                MFCCalibrationTenPointsDataRecords[8].Gas6Calculate = data6.Percent90Calculate;

                MFCCalibrationTenPointsDataRecords[9].Gas6SetPoint = data6.Percent100Setpoint;
                MFCCalibrationTenPointsDataRecords[9].Gas6Calculate = data6.Percent100Calculate;
            }
            var data7 = VerificationDataTenPointsRecords.Where(x => x.Name == $"MfcGas7").FirstOrDefault();
            if (data7 != null)
            {
                MFCCalibrationTenPointsDataRecords[0].Gas7SetPoint = data7.Percent10Setpoint;
                MFCCalibrationTenPointsDataRecords[0].Gas7Calculate = data7.Percent10Calculate;

                MFCCalibrationTenPointsDataRecords[1].Gas7SetPoint = data7.Percent20Setpoint;
                MFCCalibrationTenPointsDataRecords[1].Gas7Calculate = data7.Percent20Calculate;

                MFCCalibrationTenPointsDataRecords[2].Gas7SetPoint = data7.Percent30Setpoint;
                MFCCalibrationTenPointsDataRecords[2].Gas7Calculate = data7.Percent30Calculate;

                MFCCalibrationTenPointsDataRecords[3].Gas7SetPoint = data7.Percent40Setpoint;
                MFCCalibrationTenPointsDataRecords[3].Gas7Calculate = data7.Percent40Calculate;

                MFCCalibrationTenPointsDataRecords[4].Gas7SetPoint = data7.Percent50Setpoint;
                MFCCalibrationTenPointsDataRecords[4].Gas7Calculate = data7.Percent50Calculate;

                MFCCalibrationTenPointsDataRecords[5].Gas7SetPoint = data7.Percent60Setpoint;
                MFCCalibrationTenPointsDataRecords[5].Gas7Calculate = data7.Percent60Calculate;

                MFCCalibrationTenPointsDataRecords[6].Gas7SetPoint = data7.Percent70Setpoint;
                MFCCalibrationTenPointsDataRecords[6].Gas7Calculate = data7.Percent70Calculate;

                MFCCalibrationTenPointsDataRecords[7].Gas7SetPoint = data7.Percent80Setpoint;
                MFCCalibrationTenPointsDataRecords[7].Gas7Calculate = data7.Percent80Calculate;

                MFCCalibrationTenPointsDataRecords[8].Gas7SetPoint = data7.Percent90Setpoint;
                MFCCalibrationTenPointsDataRecords[8].Gas7Calculate = data7.Percent90Calculate;

                MFCCalibrationTenPointsDataRecords[9].Gas7SetPoint = data7.Percent100Setpoint;
                MFCCalibrationTenPointsDataRecords[9].Gas7Calculate = data7.Percent100Calculate;
            }
            var data8 = VerificationDataTenPointsRecords.Where(x => x.Name == $"MfcGas8").FirstOrDefault();
            if (data8 != null)
            {
                MFCCalibrationTenPointsDataRecords[0].Gas8SetPoint = data8.Percent10Setpoint;
                MFCCalibrationTenPointsDataRecords[0].Gas8Calculate = data8.Percent10Calculate;

                MFCCalibrationTenPointsDataRecords[1].Gas8SetPoint = data8.Percent20Setpoint;
                MFCCalibrationTenPointsDataRecords[1].Gas8Calculate = data8.Percent20Calculate;

                MFCCalibrationTenPointsDataRecords[2].Gas8SetPoint = data8.Percent30Setpoint;
                MFCCalibrationTenPointsDataRecords[2].Gas8Calculate = data8.Percent30Calculate;

                MFCCalibrationTenPointsDataRecords[3].Gas8SetPoint = data8.Percent40Setpoint;
                MFCCalibrationTenPointsDataRecords[3].Gas8Calculate = data8.Percent40Calculate;

                MFCCalibrationTenPointsDataRecords[4].Gas8SetPoint = data8.Percent50Setpoint;
                MFCCalibrationTenPointsDataRecords[4].Gas8Calculate = data8.Percent50Calculate;

                MFCCalibrationTenPointsDataRecords[5].Gas8SetPoint = data8.Percent60Setpoint;
                MFCCalibrationTenPointsDataRecords[5].Gas8Calculate = data8.Percent60Calculate;

                MFCCalibrationTenPointsDataRecords[6].Gas8SetPoint = data8.Percent70Setpoint;
                MFCCalibrationTenPointsDataRecords[6].Gas8Calculate = data8.Percent70Calculate;

                MFCCalibrationTenPointsDataRecords[7].Gas8SetPoint = data8.Percent80Setpoint;
                MFCCalibrationTenPointsDataRecords[7].Gas8Calculate = data8.Percent80Calculate;

                MFCCalibrationTenPointsDataRecords[8].Gas8SetPoint = data8.Percent90Setpoint;
                MFCCalibrationTenPointsDataRecords[8].Gas8Calculate = data8.Percent90Calculate;

                MFCCalibrationTenPointsDataRecords[9].Gas8SetPoint = data8.Percent100Setpoint;
                MFCCalibrationTenPointsDataRecords[9].Gas8Calculate = data8.Percent100Calculate;
            }


            var onePointdata1 = VerificationDataOnePointRecords.Where(x => x.Name == $"MfcGas1").FirstOrDefault();
            if (onePointdata1 != null)
            {
                MFCCalibrationOnePointDataRecords[0].Gas1SetPoint = onePointdata1.Setpoint;
                MFCCalibrationOnePointDataRecords[0].Gas1Calculate = onePointdata1.Calculate;
            }

            var onePointdata2 = VerificationDataOnePointRecords.Where(x => x.Name == $"MfcGas2").FirstOrDefault();
            if (onePointdata2 != null)
            {
                MFCCalibrationOnePointDataRecords[0].Gas2SetPoint = onePointdata2.Setpoint;
                MFCCalibrationOnePointDataRecords[0].Gas2Calculate = onePointdata2.Calculate;
            }

            var onePointdata3 = VerificationDataOnePointRecords.Where(x => x.Name == $"MfcGas3").FirstOrDefault();
            if (onePointdata3 != null)
            {
                MFCCalibrationOnePointDataRecords[0].Gas3SetPoint = onePointdata3.Setpoint;
                MFCCalibrationOnePointDataRecords[0].Gas3Calculate = onePointdata3.Calculate;
            }

            var onePointdata4 = VerificationDataOnePointRecords.Where(x => x.Name == $"MfcGas4").FirstOrDefault();
            if (onePointdata4 != null)
            {
                MFCCalibrationOnePointDataRecords[0].Gas4SetPoint = onePointdata4.Setpoint;
                MFCCalibrationOnePointDataRecords[0].Gas4Calculate = onePointdata4.Calculate;
            }

            var onePointdata5 = VerificationDataOnePointRecords.Where(x => x.Name == $"MfcGas5").FirstOrDefault();
            if (onePointdata5 != null)
            {
                MFCCalibrationOnePointDataRecords[0].Gas5SetPoint = onePointdata5.Setpoint;
                MFCCalibrationOnePointDataRecords[0].Gas5Calculate = onePointdata5.Calculate;
            }

            var onePointdata6 = VerificationDataOnePointRecords.Where(x => x.Name == $"MfcGas6").FirstOrDefault();
            if (onePointdata6 != null)
            {
                MFCCalibrationOnePointDataRecords[0].Gas6SetPoint = onePointdata6.Setpoint;
                MFCCalibrationOnePointDataRecords[0].Gas6Calculate = onePointdata6.Calculate;
            }

            var onePointdata7 = VerificationDataOnePointRecords.Where(x => x.Name == $"MfcGas7").FirstOrDefault();
            if (onePointdata7 != null)
            {
                MFCCalibrationOnePointDataRecords[0].Gas7SetPoint = onePointdata7.Setpoint;
                MFCCalibrationOnePointDataRecords[0].Gas7Calculate = onePointdata7.Calculate;
            }

            var onePointdata8 = VerificationDataOnePointRecords.Where(x => x.Name == $"MfcGas8").FirstOrDefault();
            if (onePointdata8 != null)
            {
                MFCCalibrationOnePointDataRecords[0].Gas8SetPoint = onePointdata8.Setpoint;
                MFCCalibrationOnePointDataRecords[0].Gas8Calculate = onePointdata8.Calculate;
            }
        }
        #endregion
    }
}