using System; using LiveCharts; using Prism.Mvvm; using Prism.Commands; using System.Linq; using SHJX.Service.Common.ReadXML; using SHJX.Service.Common.Logging; using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Windows.Controls; using SHJX.Service.Control.Route.RouteController; using SHJX.Service.Common.UserDelegate; using System.Windows; using Prism.Events; using System.Threading; namespace SHJX.Service.ModelView { public class DropMonitorViewModel : BindableBase { private static readonly ILogger logger = LogFactory.BuildLogger(typeof(DropMonitorViewModel)); public ChartValues SeriesCollection { get; set; } public readonly static List GraberValues = new(); public IEventAggregator eventAggregator; public DropMonitorViewModel( ReadConfigUtil config) { eventAggregator = new EventAggregator(); PublicMessage(); SeriesCollection = new ChartValues(); YuZhiValue = "30"; DengDaiTimeValue = "15"; CheckTimeValue = "30"; MaxTiJiValue = "28"; DropAmount1Value = "0.0668"; FastDidingValue = "10"; BrightData = "100"; IfFastDidingValue = false; ExcuteEnable = true; NongDuChoose = new List(); NongDuChoose.Add( new ComboBoxItem() { Content = "低" } ); NongDuChoose.Add( new ComboBoxItem() { Content = "高" } ); NongDuValue = NongDuChoose.FirstOrDefault(); eventAggregator.GetEvent().Subscribe((lists) => { SeriesCollection.Clear(); SeriesCollection.AddRange(lists); }); eventAggregator.GetEvent().Subscribe((value) => { DropCountValue = value.ToString(); }); } public void PublicMessage() { Messager.Register("DropValue", DropValueExecute); Messager.Register("DropDoing", DropDoingExecute); Messager.Register("DropEnd", DropEndExecute); Messager.Register("DropEndWindows", DropEndWindowsExecute); } public void DropValueExecute(object obj) { if (obj is null) return; var dropValue = obj as Dictionary; Application.Current.Dispatcher.Invoke(() => { DropCountValue = dropValue["Count"].ToString(); DropAmountValue = dropValue["Amount"].ToString("F3"); DropBlueValue = dropValue["BlueValue"].ToString("F3"); }); } public void DropDoingExecute(object obj) { ExcuteEnable = false; GraberValues.Add(Convert.ToDouble(obj)); eventAggregator.GetEvent().Publish(GraberValues); //if (obj is null) return; //var value = Convert.ToDouble(obj); //SeriesCollection.Add(value); } public void DropEndExecute(object obj) { ExcuteEnable = true; SeriesCollection.Clear(); } public void DropEndWindowsExecute(object obj) { MessageBox.Show("手动滴定结束!"); } #region Command private DelegateCommand _manualDiding_Click; public DelegateCommand ManualDiding_Click => _manualDiding_Click ?? new DelegateCommand(ManualDidingAsync); private DelegateCommand _checkCamera_Click; public DelegateCommand CheckCamera_Click => _checkCamera_Click ?? new DelegateCommand(CheckCameraAsync); private void ManualDidingAsync(object sender) { try { ExcuteEnable = false; Dictionary myDictionary = new Dictionary(); myDictionary.Add("YuZhiValue", YuZhiValue); myDictionary.Add("DengDaiTimeValue", DengDaiTimeValue); myDictionary.Add("CheckTimeValue", CheckTimeValue); myDictionary.Add("MaxTiJiValue", MaxTiJiValue); myDictionary.Add("DropAmountValue", DropAmount1Value); myDictionary.Add("FastDidingValue", FastDidingValue); myDictionary.Add("IfFastDiding", IfFastDidingValue.ToString()); myDictionary.Add("NongDuValue", NongDuValue.Content.ToString()); Thread thread = new Thread(new ParameterizedThreadStart(threadFunction)); thread.Start((object)myDictionary); } catch (Exception ex) { logger.LogError(ex.ToString()); } } private void CheckCameraAsync(object sender) { try { TitrationOperate manual = new TitrationOperate(); manual.CheckCamera(NongDuValue.Content.ToString(), BrightData.ToString()); } catch (Exception ex) { logger.LogError(ex.ToString()); } } private void threadFunction(object myDictionary) { TitrationOperate manual = new TitrationOperate(); manual.ManualSampleDropLiquid((Dictionary)myDictionary); } public List NongDuChoose { get; set; } private string _dropCountValue; public string DropCountValue { get => _dropCountValue; set { _dropCountValue = value; RaisePropertyChanged(nameof(DropCountValue)); } } private string _dropAmountValue; public string DropAmountValue { get => _dropAmountValue; set { _dropAmountValue = value; RaisePropertyChanged(nameof(DropAmountValue)); } } private string _dropBlueValue; public string DropBlueValue { get => _dropBlueValue; set { _dropBlueValue = value; RaisePropertyChanged(nameof(DropBlueValue)); } } private string _yuZhiValue; public string YuZhiValue { get => _yuZhiValue; set { _yuZhiValue = value; RaisePropertyChanged(nameof(YuZhiValue)); } } private string _dengDaiTimeValue; public string DengDaiTimeValue { get => _dengDaiTimeValue; set { _dengDaiTimeValue = value; RaisePropertyChanged(nameof(DengDaiTimeValue)); } } private string _checkTimeValue; public string CheckTimeValue { get => _checkTimeValue; set { _checkTimeValue = value; RaisePropertyChanged(nameof(CheckTimeValue)); } } private string _maxTiJiValue; public string MaxTiJiValue { get => _maxTiJiValue; set { _maxTiJiValue = value; RaisePropertyChanged(nameof(MaxTiJiValue)); } } private string _dropAmount1Value; public string DropAmount1Value { get => _dropAmount1Value; set { _dropAmount1Value = value; RaisePropertyChanged(nameof(DropAmount1Value)); } } private string _fastDidingValue; public string FastDidingValue { get => _fastDidingValue; set { _fastDidingValue = value; RaisePropertyChanged(nameof(FastDidingValue)); } } private string _brightData; public string BrightData { get => _brightData; set { _brightData = value; RaisePropertyChanged(nameof(BrightData)); } } private ComboBoxItem _nongDuValue; public ComboBoxItem NongDuValue { get => _nongDuValue; set { _nongDuValue = value; RaisePropertyChanged(nameof(NongDuValue)); } } private bool _excuteEnable; public bool ExcuteEnable { get => _excuteEnable; set { _excuteEnable = value; RaisePropertyChanged(nameof(ExcuteEnable)); } } private bool _ifFastDidingValue; public bool IfFastDidingValue { get => _ifFastDidingValue; set { _ifFastDidingValue = value; RaisePropertyChanged(nameof(IfFastDidingValue)); } } #endregion } public class GraberValueEvent : PubSubEvent> { } public class TitrationValueEvent : PubSubEvent> { } }