using Aitex.Core.Common.DeviceData; using Aitex.Core.RT.Log; using Aitex.Core.Util; using MECF.Framework.Common.CommonData; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using OpenSEMI.ClientBase; using SciChart.Charting.Model.DataSeries; using SciChart.Charting.Visuals.Axes; using SciChart.Charting.Visuals.RenderableSeries; using SciChart.Data.Model; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; using VirgoUI.Client.Models.Sys; namespace VirgoUI.Client.Models.PMs { public class MFCVerificationDataListItem : NotifiableItem { private float _Setpoint; public float Setpoint { get { return _Setpoint; } set { _Setpoint = value; InvokePropertyChanged("Setpoint"); } } private float _CalculateValue; public float CalculateValue { get { return _CalculateValue; } set { _CalculateValue = value; InvokePropertyChanged("CalculateValue"); } } private float _ElapseTime; public float ElapseTime { get { return _ElapseTime; } set { _ElapseTime = value; InvokePropertyChanged("ElapseTime"); } } private float _deviation; public float Deviation { get { return _deviation; } set { _deviation = value; InvokePropertyChanged("Deviation"); } } private string _result; public string Result { get { return Convert.ToBoolean(_result) ? "OK" : "Failed"; } set { _result = value; InvokePropertyChanged("Result"); } } private string _resultBackground; public string ResultBackground { get { return _resultBackground; } set { _resultBackground = value; InvokePropertyChanged("ResultBackground"); } } private float _pressure; public float Pressure { get { return _pressure; } set { _pressure = value; InvokePropertyChanged("Pressure"); } } } public class MFCVerificationErrorRateListItem : NotifiableItem { public float Setpoint { get; set; } public float CalculateValue { get; set; } public float ErrorRate { get; set; } public float ElapsedTime { get; set; } public float Deviation { get; set; } public string Result { get; set; } } public class MFCVerificationData : NotifiableItem { public string Module { get; set; } public string Name { get; set; } public string Time { get; set; } public float Percent10Setpoint { get; set; } public float Percent10Calculate { get; set; } public float Percent20Setpoint { get; set; } public float Percent20Calculate { get; set; } public float Percent30Setpoint { get; set; } public float Percent30Calculate { get; set; } public float Percent40Setpoint { get; set; } public float Percent40Calculate { get; set; } public float Percent50Setpoint { get; set; } public float Percent50Calculate { get; set; } public float Percent60Setpoint { get; set; } public float Percent60Calculate { get; set; } public float Percent70Setpoint { get; set; } public float Percent70Calculate { get; set; } public float Percent80Setpoint { get; set; } public float Percent80Calculate { get; set; } public float Percent90Setpoint { get; set; } public float Percent90Calculate { get; set; } public float Percent100Setpoint { get; set; } public float Percent100Calculate { get; set; } public float Setpoint { get; set; } public float Calculate { get; set; } } public class MFCVerificationViewModel : ModuleUiViewModelBase, ISupportMultipleSystem { public MFCVerificationViewModel() { var now = DateTime.Today; SearchBeginTime = now; SearchEndTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999); } #region MFCs #region MFCData private AITMfcData _mfc1DeviceData; [Subscription("MfcGas1")] public AITMfcData MFC1DeviceData { get { return _mfc1DeviceData; } set { if (_mfc1DeviceData == null || _mfc1DeviceData.Scale != value.Scale) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { int delta = (int)value.Scale / 10; if (MFC1VerificationPoints != null) MFC1VerificationPoints.Clear(); else MFC1VerificationPoints = new ObservableCollection(); //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range for (int i = 0; i < 10; i++) { MFC1VerificationPoints.Add(delta + delta * i); } })); } _mfc1DeviceData = value; } } private AITMfcData _mfc2DeviceData; [Subscription("MfcGas2")] public AITMfcData MFC2DeviceData { get { return _mfc2DeviceData; } set { if (_mfc2DeviceData == null || _mfc2DeviceData.Scale != value.Scale) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { int delta = (int)value.Scale / 10; if (MFC2VerificationPoints != null) MFC2VerificationPoints.Clear(); else MFC2VerificationPoints = new ObservableCollection(); //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range for (int i = 0; i < 10; i++) { MFC2VerificationPoints.Add(delta + delta * i); } })); } _mfc2DeviceData = value; } } private AITMfcData _mfc3DeviceData; [Subscription("MfcGas3")] public AITMfcData MFC3DeviceData { get { return _mfc3DeviceData; } set { if (_mfc3DeviceData == null || _mfc3DeviceData.Scale != value.Scale) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { int delta = (int)value.Scale / 10; if (MFC3VerificationPoints != null) MFC3VerificationPoints.Clear(); else MFC3VerificationPoints = new ObservableCollection(); //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range for (int i = 0; i < 10; i++) { MFC3VerificationPoints.Add(delta + delta * i); } })); } _mfc3DeviceData = value; } } private AITMfcData _mfc4DeviceData; [Subscription("MfcGas4")] public AITMfcData MFC4DeviceData { get { return _mfc4DeviceData; } set { if (_mfc4DeviceData == null || _mfc4DeviceData.Scale != value.Scale) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { int delta = (int)value.Scale / 10; if (MFC4VerificationPoints != null) MFC4VerificationPoints.Clear(); else MFC4VerificationPoints = new ObservableCollection(); //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range for (int i = 0; i < 10; i++) { MFC4VerificationPoints.Add(delta + delta * i); } })); } _mfc4DeviceData = value; } } private AITMfcData _mfc5DeviceData; [Subscription("MfcGas5")] public AITMfcData MFC5DeviceData { get { return _mfc5DeviceData; } set { if (_mfc5DeviceData == null || _mfc5DeviceData.Scale != value.Scale) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { int delta = (int)value.Scale / 10; if (MFC5VerificationPoints != null) MFC5VerificationPoints.Clear(); else MFC5VerificationPoints = new ObservableCollection(); //ten points: 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% of range for (int i = 0; i < 10; i++) { MFC5VerificationPoints.Add(delta + delta * i); } })); } _mfc5DeviceData = value; } } #endregion #region MFCVerificationResult private string _MFC1VerificationResult; [Subscription("MfcGas1.VerificationResult")] public string MFC1VerificationResult { get { return _MFC1VerificationResult; } set { if(_MFC1VerificationResult != value) { var results = value.Split(';'); if(results != null && results.Length > 0) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { MFC1VerificationData.Clear(); foreach (var item in results) { var onePoint = item.Split(','); if (onePoint != null && onePoint.Length >= 5) { MFC1VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), ElapseTime = Convert.ToSingle(onePoint[2]), Deviation = Convert.ToSingle(onePoint[3]), Result = onePoint[4], ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green":"Red", }); } else { if (onePoint != null && onePoint.Length >= 2) { MFC1VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), }); } } } })); } } _MFC1VerificationResult = value; } } private string _MFC2VerificationResult; [Subscription("MfcGas2.VerificationResult")] public string MFC2VerificationResult { get { return _MFC2VerificationResult; } set { if (_MFC2VerificationResult != value) { var results = value.Split(';'); if (results != null && results.Length > 0) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { MFC2VerificationData.Clear(); foreach (var item in results) { var onePoint = item.Split(','); if (onePoint != null && onePoint.Length >= 5) { MFC2VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), ElapseTime = Convert.ToSingle(onePoint[2]), Deviation = Convert.ToSingle(onePoint[3]), Result = onePoint[4], ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green" : "Red", }); } else { if (onePoint != null && onePoint.Length >= 2) { MFC2VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), }); } } } })); } } _MFC2VerificationResult = value; } } private string _MFC3VerificationResult; [Subscription("MfcGas3.VerificationResult")] public string MFC3VerificationResult { get { return _MFC3VerificationResult; } set { if (_MFC3VerificationResult != value) { var results = value.Split(';'); if (results != null && results.Length > 0) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { MFC3VerificationData.Clear(); foreach (var item in results) { var onePoint = item.Split(','); if (onePoint != null && onePoint.Length >= 5) { MFC3VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), ElapseTime = Convert.ToSingle(onePoint[2]), Deviation = Convert.ToSingle(onePoint[3]), Result = onePoint[4], ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green" : "Red", }); } else { if (onePoint != null && onePoint.Length >= 2) { MFC3VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), }); } } } })); } } _MFC3VerificationResult = value; } } private string _MFC4VerificationResult; [Subscription("MfcGas4.VerificationResult")] public string MFC4VerificationResult { get { return _MFC4VerificationResult; } set { if (_MFC4VerificationResult != value) { var results = value.Split(';'); if (results != null && results.Length > 0) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { MFC4VerificationData.Clear(); foreach (var item in results) { var onePoint = item.Split(','); if (onePoint != null && onePoint.Length >= 5) { MFC4VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), ElapseTime = Convert.ToSingle(onePoint[2]), Deviation = Convert.ToSingle(onePoint[3]), Result = onePoint[4], ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green" : "Red", }); } else { if (onePoint != null && onePoint.Length >= 2) { MFC4VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), }); } } } })); } } _MFC4VerificationResult = value; } } private string _MFC5VerificationResult; [Subscription("MfcGas5.VerificationResult")] public string MFC5VerificationResult { get { return _MFC5VerificationResult; } set { if (_MFC5VerificationResult != value) { var results = value.Split(';'); if (results != null && results.Length > 0) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { MFC5VerificationData.Clear(); foreach (var item in results) { var onePoint = item.Split(','); if (onePoint != null && onePoint.Length >= 5) { MFC5VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), ElapseTime = Convert.ToSingle(onePoint[2]), Deviation = Convert.ToSingle(onePoint[3]), Result = onePoint[4], ResultBackground = Convert.ToBoolean(onePoint[4]) ? "Green" : "Red", }); } else { if (onePoint != null && onePoint.Length >= 2) { MFC5VerificationData.Add(new MFCVerificationDataListItem() { Setpoint = Convert.ToSingle(onePoint[0]), CalculateValue = Convert.ToSingle(onePoint[1]), }); } } } })); } } _MFC5VerificationResult = value; } } #endregion public bool MFC1IsEnable { get; set; } public bool MFC2IsEnable { get; set; } public bool MFC3IsEnable { get; set; } public bool MFC4IsEnable { get; set; } public bool MFC5IsEnable { get; set; } public bool IsMfc1Checked { get; set; } public bool IsMfc2Checked { get; set; } public bool IsMfc3Checked { get; set; } public bool IsMfc4Checked { get; set; } public bool IsMfc5Checked { get; set; } public bool[] IsMfcChecked { get { bool[] isMfcCheck = new bool[] { IsMfc1Checked, IsMfc2Checked, IsMfc3Checked, IsMfc4Checked, }; return isMfcCheck; } } #endregion private string _pmStatus; [Subscription("FsmState")] public string PMStatus { get { return _pmStatus; } set { if (_pmStatus != value) Query(); _pmStatus = value; } } [Subscription("IsOnline")] public bool IsOnline { get; set; } public string Setpoint { get; set; } public bool IsVerificationButtonEnable => PMStatus == "Idle" && !IsOnline; public bool IsPermission { get => this.Permission == 3; } public Visibility MFCQueryVisibility { get; set; } public ObservableCollection SelectedData { get; set; } private IRange _xValueRange; public IRange XValueRange { get { return _xValueRange; } set { _xValueRange = value; NotifyOfPropertyChange("XValueRange"); } } private IRange _yValueRange; public IRange YValueRange { get { return _yValueRange; } set { _yValueRange = value; NotifyOfPropertyChange("YValueRange"); } } public AutoRange ChartAutoRange { get { return EnableAutoZoom ? AutoRange.Always : AutoRange.Never; } } private bool _enableAutoZoom = true; public bool EnableAutoZoom { get { return _enableAutoZoom; } set { _enableAutoZoom = value; NotifyOfPropertyChange(nameof(EnableAutoZoom)); NotifyOfPropertyChange(nameof(ChartAutoRange)); } } private AutoRange _autoRangeX; public AutoRange AutoRangeX { get => _autoRangeX; set { _autoRangeX = value; NotifyOfPropertyChange(nameof(AutoRangeX)); } } private AutoRange _autoRangeY; public AutoRange AutoRangeY { get => _autoRangeY; set { _autoRangeY = value; NotifyOfPropertyChange(nameof(AutoRangeY)); } } public ObservableCollection MFC1VerificationData { get; set; } public ObservableCollection MFC2VerificationData { get; set; } public ObservableCollection MFC3VerificationData { get; set; } public ObservableCollection MFC4VerificationData { get; set; } public ObservableCollection MFC5VerificationData { get; set; } public ObservableCollection VerificationErrorRate { get; set; } public ObservableCollection MFC1VerificationPoints { get; set; } public ObservableCollection MFC2VerificationPoints { get; set; } public ObservableCollection MFC3VerificationPoints { get; set; } public ObservableCollection MFC4VerificationPoints { get; set; } public ObservableCollection MFC5VerificationPoints { get; set; } public ObservableCollection VerificationDataRecords { get; set; }//read form db private MFCVerificationData selectedVerificationData; public MFCVerificationData SelectedVerificationData { get { return this.selectedVerificationData; } set { this.selectedVerificationData = value; } } public DateTime SearchBeginTime { get; set; } public DateTime SearchEndTime { get; set; } private MFCVerificationView view; public Visibility MFC1Visibility => MFC1IsEnable ? Visibility.Visible : Visibility.Collapsed; public Visibility MFC2Visibility => MFC2IsEnable ? Visibility.Visible : Visibility.Collapsed; public Visibility MFC3Visibility => MFC3IsEnable ? Visibility.Visible : Visibility.Collapsed; public Visibility MFC4Visibility => MFC4IsEnable ? Visibility.Visible : Visibility.Collapsed; public string MFC1BackGround => !MFC1IsEnable ? "Gold" : "White"; public string MFC2BackGround => !MFC2IsEnable ? "Gold" : "White"; public string MFC3BackGround => !MFC3IsEnable ? "Gold" : "White"; public string MFC4BackGround => !MFC4IsEnable ? "Gold" : "White"; protected override void OnInitialize() { MFC1VerificationData = new ObservableCollection(); MFC2VerificationData = new ObservableCollection(); MFC3VerificationData = new ObservableCollection(); MFC4VerificationData = new ObservableCollection(); MFC5VerificationData = new ObservableCollection(); MFC1VerificationPoints = new ObservableCollection(); MFC2VerificationPoints = new ObservableCollection(); MFC3VerificationPoints = new ObservableCollection(); MFC4VerificationPoints = new ObservableCollection(); MFC5VerificationPoints = new ObservableCollection(); MFCQueryVisibility = Visibility.Collapsed; base.OnInitialize(); YValueRange = new DoubleRange(0, 100); SelectedData = new ObservableCollection(); AutoRangeX = AutoRange.Always; AutoRangeY = AutoRange.Always;//(bool)QueryDataClient.Instance.Service.GetConfig("System.IsCycleMode"); } protected override void OnActivate() { XValueRange = new DoubleRange(0, MFC1DeviceData != null ? MFC1DeviceData.Scale : 100); base.OnActivate(); Query(); MFC1IsEnable = true; MFC2IsEnable = true; MFC3IsEnable = true; MFC4IsEnable = true; MFC5IsEnable = true; } protected override void OnViewLoaded(object _view) { base.OnViewLoaded(_view); this.view = (MFCVerificationView)_view; this.view.wfTimeFrom.Value = this.SearchBeginTime; this.view.wfTimeTo.Value = this.SearchEndTime; Query(); } protected override void OnDeactivate(bool close) { base.OnDeactivate(close); } public void StartVerification(object oj1, object oj2, object oj3) { string gasName = oj1.ToString(); float.TryParse(oj2.ToString(), out float flow); int.TryParse(oj3.ToString(), out int flowCount); InvokeClient.Instance.Service.DoOperation($"{SystemName}.MFCVerification", gasName, flow, flowCount); } public void StartAllCali() { bool IsSelectedMFC = false; foreach (bool IsCheck in IsMfcChecked) { if (IsCheck) IsSelectedMFC = true; } if (!IsSelectedMFC) { MessageBox.Show("Please select at least one Gas.", "Calibration", MessageBoxButton.OK, MessageBoxImage.Warning); return; } string[] gasName = new string[] { "MFC1", "MFC2", "MFC3", "MFC4" }; InvokeClient.Instance.Service.DoOperation($"{SystemName}.AllMFCVerification", gasName, IsMfcChecked); } public void AcceptAll(object o) { string gasName = o.ToString(); InvokeClient.Instance.Service.DoOperation($"{SystemName}.{gasName}.AcceptAllMFCVerification", gasName); } public void Back() { MFCQueryVisibility = Visibility.Collapsed; NotifyOfPropertyChange("RFCalVisibility"); NotifyOfPropertyChange("MFCQueryVisibility"); } public void SelectHistory() { if (SelectedVerificationData != null) { try { if (SelectedVerificationData.Name.Contains("Gas1")) XValueRange = new DoubleRange(0, MFC1DeviceData.Scale); else if (SelectedVerificationData.Name.Contains("Gas2")) XValueRange = new DoubleRange(0, MFC2DeviceData.Scale); else if (SelectedVerificationData.Name.Contains("Gas3")) XValueRange = new DoubleRange(0, MFC3DeviceData.Scale); else XValueRange = new DoubleRange(0, MFC4DeviceData.Scale); MFCQueryVisibility = Visibility.Visible; NotifyOfPropertyChange("MFCQueryVisibility"); VerificationErrorRate = new ObservableCollection(); MFCVerificationErrorRateListItem errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent10Setpoint, CalculateValue = SelectedVerificationData.Percent10Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent10Setpoint - SelectedVerificationData.Percent10Calculate) / SelectedVerificationData.Percent10Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent20Setpoint, CalculateValue = SelectedVerificationData.Percent20Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent20Setpoint - SelectedVerificationData.Percent20Calculate) / SelectedVerificationData.Percent20Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent30Setpoint, CalculateValue = SelectedVerificationData.Percent30Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent30Setpoint - SelectedVerificationData.Percent30Calculate) / SelectedVerificationData.Percent30Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent40Setpoint, CalculateValue = SelectedVerificationData.Percent40Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent40Setpoint - SelectedVerificationData.Percent40Calculate) / SelectedVerificationData.Percent40Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent50Setpoint, CalculateValue = SelectedVerificationData.Percent50Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent50Setpoint - SelectedVerificationData.Percent50Calculate) / SelectedVerificationData.Percent50Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent60Setpoint, CalculateValue = SelectedVerificationData.Percent60Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent60Setpoint - SelectedVerificationData.Percent60Calculate) / SelectedVerificationData.Percent60Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent70Setpoint, CalculateValue = SelectedVerificationData.Percent70Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent70Setpoint - SelectedVerificationData.Percent70Calculate) / SelectedVerificationData.Percent70Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent80Setpoint, CalculateValue = SelectedVerificationData.Percent80Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent80Setpoint - SelectedVerificationData.Percent80Calculate) / SelectedVerificationData.Percent80Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent90Setpoint, CalculateValue = SelectedVerificationData.Percent90Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent90Setpoint - SelectedVerificationData.Percent90Calculate) / SelectedVerificationData.Percent90Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate); errorRate = new MFCVerificationErrorRateListItem() { Setpoint = SelectedVerificationData.Percent100Setpoint, CalculateValue = SelectedVerificationData.Percent100Calculate, ErrorRate = Math.Abs((float)Math.Round((SelectedVerificationData.Percent100Setpoint - SelectedVerificationData.Percent100Calculate) / SelectedVerificationData.Percent100Setpoint * 100, 3)) }; VerificationErrorRate.Add(errorRate);//SelectedData ChartDataLine line = new ChartDataLine("MFCCalibration"); VerificationErrorRate.ToList().ForEach(x => line.Append(x.Setpoint, x.ErrorRate)); //foreach(var item in VerificationErrorRate) //{ // line.Append(item.Setpoint,item.ErrorRate); //} SelectedData.Clear(); SelectedData.Add(line); } catch (Exception ex) { LOG.Write(ex); } } } /// /// 查询 /// public void Query() { if (view == null || view.wfTimeFrom == null || view.wfTimeFrom == null) return; try { this.SearchBeginTime = (System.DateTime)this.view.wfTimeFrom.Value; this.SearchEndTime = (System.DateTime)this.view.wfTimeTo.Value; if (SearchBeginTime > SearchEndTime) { MessageBox.Show("Time range invalid, start time should be early than end time"); return; } string sql = string.Format( "SELECT * FROM \"mfc_verification_data\" where \"operate_time\" >= '{0}' and \"operate_time\" <= '{1}' and \"module\" = '{2}' order by \"operate_time\" ASC;", SearchBeginTime.ToString("yyyyMMdd HHmmss"), SearchEndTime.ToString("yyyyMMdd HHmmss"), SystemName); var result = QueryDataClient.Instance.Service.QueryData(sql); Application.Current.Dispatcher.BeginInvoke(new Action(() => { VerificationDataRecords = new ObservableCollection(); for (int i = 0; i < result.Rows.Count; i++) { MFCVerificationData data = new MFCVerificationData() { Module = result.Rows[i]["module"].ToString(), Name = result.Rows[i]["name"].ToString(), Time = ((DateTime)result.Rows[i]["operate_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff"), Percent10Setpoint = float.Parse(result.Rows[i]["percent10_setpoint"].ToString()), Percent10Calculate = float.Parse(result.Rows[i]["percent10_calculate"].ToString()), Percent20Setpoint = float.Parse(result.Rows[i]["percent20_setpoint"].ToString()), Percent20Calculate = float.Parse(result.Rows[i]["percent20_calculate"].ToString()), Percent30Setpoint = float.Parse(result.Rows[i]["percent30_setpoint"].ToString()), Percent30Calculate = float.Parse(result.Rows[i]["percent30_calculate"].ToString()), Percent40Setpoint = float.Parse(result.Rows[i]["percent40_setpoint"].ToString()), Percent40Calculate = float.Parse(result.Rows[i]["percent40_calculate"].ToString()), Percent50Setpoint = float.Parse(result.Rows[i]["percent50_setpoint"].ToString()), Percent50Calculate = float.Parse(result.Rows[i]["percent50_calculate"].ToString()), Percent60Setpoint = float.Parse(result.Rows[i]["percent60_setpoint"].ToString()), Percent60Calculate = float.Parse(result.Rows[i]["percent60_calculate"].ToString()), Percent70Setpoint = float.Parse(result.Rows[i]["percent70_setpoint"].ToString()), Percent70Calculate = float.Parse(result.Rows[i]["percent70_calculate"].ToString()), Percent80Setpoint = float.Parse(result.Rows[i]["percent80_setpoint"].ToString()), Percent80Calculate = float.Parse(result.Rows[i]["percent80_calculate"].ToString()), Percent90Setpoint = float.Parse(result.Rows[i]["percent90_setpoint"].ToString()), Percent90Calculate = float.Parse(result.Rows[i]["percent90_calculate"].ToString()), Percent100Setpoint = float.Parse(result.Rows[i]["percent100_setpoint"].ToString()), Percent100Calculate = float.Parse(result.Rows[i]["percent100_calculate"].ToString()), Setpoint = float.Parse(result.Rows[i]["setpoint"].ToString()), Calculate = float.Parse(result.Rows[i]["calculate"].ToString()), }; VerificationDataRecords.Add(data); } NotifyOfPropertyChange("VerificationDataRecords"); })); } catch (Exception ex) { LOG.Write(ex); } } public void SetAsCurrent(object o) { int.TryParse(o.ToString(), out int selectIndex); if (selectIndex < 0 || selectIndex >= VerificationDataRecords.Count) { MessageBox.Show("Please select a row to set.", "Calibration", MessageBoxButton.OK, MessageBoxImage.Warning); return; } InvokeClient.Instance.Service.DoOperation($"{SystemName}.{VerificationDataRecords[selectIndex].Name}.UpdateCalibrationInfo", VerificationDataRecords[selectIndex].Percent10Calculate, VerificationDataRecords[selectIndex].Percent20Calculate, VerificationDataRecords[selectIndex].Percent30Calculate, VerificationDataRecords[selectIndex].Percent40Calculate, VerificationDataRecords[selectIndex].Percent50Calculate, VerificationDataRecords[selectIndex].Percent60Calculate, VerificationDataRecords[selectIndex].Percent70Calculate, VerificationDataRecords[selectIndex].Percent80Calculate, VerificationDataRecords[selectIndex].Percent90Calculate, VerificationDataRecords[selectIndex].Percent100Calculate); } public void Abort() { InvokeClient.Instance.Service.DoOperation($"{SystemName}.Abort"); } } public class ChartDataLine : FastLineRenderableSeries, INotifyPropertyChanged { #region PropertyChanged public event PropertyChangedEventHandler PropertyChanged; public void InvokePropertyChanged(string propertyName) { PropertyChangedEventArgs eventArgs = new PropertyChangedEventArgs(propertyName); PropertyChangedEventHandler changed = PropertyChanged; if (changed != null) { changed(this, eventArgs); } } public void InvokePropertyChanged() { Type t = this.GetType(); var ps = t.GetProperties(); foreach (var p in ps) { InvokePropertyChanged(p.Name); } } #endregion public string UniqueId { get; set; } public List> Points { get { lock (_lockData) { return _queueRawData.ToList(); } } } public string DataSource { get; set; } public string DataName { get; set; } public string DisplayName { get { return DataSeries.SeriesName; } set { DataSeries.SeriesName = value; } } public double LineThickness { get { return StrokeThickness; } set { var i = Convert.ToInt32(value); if (i < 1) i = 1; if (i > 100) i = 100; StrokeThickness = i; InvokePropertyChanged("LineThickness"); } } private double _dataFactor = 1.0; public double DataFactor { get => _dataFactor; set { if (Math.Abs(_dataFactor - value) > 0.001) { _dataFactor = value; InvokePropertyChanged(nameof(DataFactor)); UpdateChartSeriesValue(); } } } private double _dataOffset = 0; public double DataOffset { get => _dataOffset; set { if (Math.Abs(_dataOffset - value) > 0.001) { _dataOffset = value; InvokePropertyChanged(nameof(DataFactor)); UpdateChartSeriesValue(); } } } private int _capacity = 10000; public int Capacity { get { return _capacity; } set { _capacity = value; DataSeries.FifoCapacity = value; } } private object _lockData = new object(); private FixSizeQueue> _queueRawData; public ChartDataLine(string dataName) : this(dataName, dataName, Colors.Blue) { } public ChartDataLine(string dataName, string displayName, Color seriesColor) { UniqueId = Guid.NewGuid().ToString(); _queueRawData = new FixSizeQueue>(_capacity); XAxisId = "DefaultAxisId"; YAxisId = "DefaultAxisId"; DataSeries = new XyDataSeries(_capacity); DisplayName = displayName; DataName = dataName; Stroke = seriesColor; IsVisible = true; DataOffset = 0; LineThickness = 1; DataFactor = 1; } public void Append(double dt, double value) { lock (_lockData) { _queueRawData.Enqueue(Tuple.Create(dt, value)); (DataSeries as XyDataSeries)?.Append(dt, value * _dataFactor + _dataOffset); } } public void UpdateChartSeriesValue() { lock (_lockData) { using (DataSeries.SuspendUpdates()) { XyDataSeries s = DataSeries as XyDataSeries; for (int i = 0; i < s.Count; i++) { s.Update(i, _queueRawData.ElementAt(i).Item2 * _dataFactor + _dataOffset); } } } } public void ClearData() { lock (_lockData) { _queueRawData.Clear(); (DataSeries as XyDataSeries)?.Clear(); } } } }