| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 | using LiveCharts;using MECF.Framework.Common.DataCenter;using MECF.Framework.Common.OperationCenter;using Microsoft.Win32;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_Core;using Venus_MainPages.Unity;using Venus_Unity;namespace Venus_MainPages.ViewModels{    internal class PartialPressureViewModel : BindableBase    {        #region 私有字段               private Dictionary<int, object> m_GasFlows = new Dictionary<int, object>();        private object[] m_GasPressures = new object[10];        private string m_ModuleName = "PMA";        private int m_GasIndex;        ChartValues<double> m_CurrentLineSeries= new ChartValues<double>();        ChartValues<double> m_ReferenceLineSeries = new ChartValues<double>();        DispatcherTimer timer = new DispatcherTimer();        private int m_GasTime;        private string m_GasName;        private PartialPressureResult m_partialPressureResult;        string value;        int maxScale;        ObservableCollection<string> m_ReferenceFlow = new ObservableCollection<string>();        #endregion        #region 属性        public ObservableCollection<string> ReferenceFlow        {            get { return m_ReferenceFlow; }            set { SetProperty(ref m_ReferenceFlow, value); }        }        public string ModuleName        {            get { return m_ModuleName; }            set { SetProperty(ref m_ModuleName, value); }        }        public Dictionary<int, object> GasFlows        {            get { return m_GasFlows; }            set { SetProperty(ref m_GasFlows, value); }        }        public ChartValues<double> CurrentLineSeries        {            get { return m_CurrentLineSeries; }            set { SetProperty(ref m_CurrentLineSeries, value); }        }        public ChartValues<double> ReferenceLineSeries        {            get { return m_ReferenceLineSeries; }            set { SetProperty(ref m_ReferenceLineSeries, value); }        }        public int GasTime        {            get { return m_GasTime; }            set { SetProperty(ref m_GasTime, value); }        }        public string GasName        {            get { return m_GasName; }            set { SetProperty(ref m_GasName, value); }        }        #endregion        #region 命令        private DelegateCommand<object> _SelectGasCommand;        public DelegateCommand<object> SelectGasCommand =>            _SelectGasCommand ?? (_SelectGasCommand = new DelegateCommand<object>(OnSelectGas));        private DelegateCommand _StartCommand;        public DelegateCommand StartCommand =>            _StartCommand ?? (_StartCommand = new DelegateCommand(OnStart));        private DelegateCommand _SaveCommand;        public DelegateCommand SaveCommand =>            _SaveCommand ?? (_SaveCommand = new DelegateCommand(OnSave));        private DelegateCommand _LoadReferenceCommand;        public DelegateCommand LoadReferenceCommand =>            _LoadReferenceCommand ?? (_LoadReferenceCommand = new DelegateCommand(OnLoadReference));        private DelegateCommand _AbortCommand;        public DelegateCommand AbortCommand =>            _AbortCommand ?? (_AbortCommand = new DelegateCommand(OnAbort));        #endregion        #region 构造函数        public PartialPressureViewModel()        {            GasTime = 60;                                   timer.Interval = TimeSpan.FromSeconds(1);            timer.Tick += Timer_Tick;                   }               #endregion        #region 命令方法        private void OnSelectGas(object obj)        {            Dictionary<int, object> CurrentGasFlows = new Dictionary<int, object>();            value = $"MfcGas{obj.ToString()}";            maxScale= Convert.ToInt32(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.{value}.MfcN2Scale"));            var xishu = Convert.ToDouble(QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.{value}.MfcScaleFactor"));            GasName = QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.{value}.GasName").ToString();            for (int i = 1; i < 11; i++)            {                CurrentGasFlows.Add(i, (int)(maxScale *xishu / 10 * i));            }            GasFlows = CurrentGasFlows;            m_GasIndex = Convert.ToInt32(obj);        }        private  void OnStart()        {            timer.Start();            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.PartialPressureTest", m_GasIndex,1000* GasTime);                 }        private void OnSave()        {            SerializeHelper.Instance.WriteToJsonFile<PartialPressureResult>(m_partialPressureResult, $"PartialPressureResult/{m_partialPressureResult.GasName}/{DateTime.Now.ToString("yyyyMMddHHmm")}.json");        }        private void OnLoadReference()        {            OpenFileDialog dialog = new OpenFileDialog();            dialog.Filter = ".json|*.json";            dialog.InitialDirectory = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "PartialPressureResult");            if (dialog.ShowDialog() == true)            {                string SelectedPath = dialog.FileName;                var value = SerializeHelper.Instance.ReadFromJsonFile<PartialPressureResult>(SelectedPath);                ReferenceLineSeries.Clear();                ReferenceFlow.Clear();                value.ValuePairs.ForEach(x =>                {                    ReferenceFlow.Add(x.Flow);                    ReferenceLineSeries.Add(x.Pressure);                });            }            else            {                ReferenceLineSeries.Clear();                //ReferenceLineSeries.Insert(20, 0);                ReferenceLineSeries.Add(0);                ReferenceFlow.Clear();            }               }        private void OnAbort()        {            timer.Stop();            InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Abort");            CurrentLineSeries = new ChartValues<double>();        }        #endregion        #region 私有方法        private void Timer_Tick(object sender, EventArgs e)        {                       CurrentLineSeries.Clear();            var values = QueryDataClient.Instance.Service.GetData($"{ModuleName}.PartialPressureResult").ToString();            values.Split(',').ToList().ForEach(x =>            {                if (x != "")                {                    CurrentLineSeries.Add(Math.Round(Convert.ToDouble(x), 3));                }            });            if (CurrentLineSeries.Count == 10)            {                timer.Stop();            }        }        public void Init()        {                            OnSelectGas(1);        }        #endregion    }}
 |