| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows.Forms;
- using Prism.Commands;
- using Prism.Mvvm;
- using SHJX.Service.Common.ExtendElement;
- using SHJX.Service.Common.ReadXML;
- using SHJX.Service.Common.UserDelegate;
- using SHJX.Service.Control.ServiceController;
- using SHJX.Service.Model.Control;
- using SHJX.Service.Model.Dao;
- using SHJX.Service.Model.MvvmCommon;
- namespace SHJX.Service.ModelView
- {
- public class SettingViewModel : BindableBase
- {
- private readonly ReadConfigUtil _config;
- private readonly SettingController _controller;
- public SettingViewModel(ReadConfigUtil config)
- {
- _config = config;
- _controller = new SettingController(_config);
- InitData();
- }
- #region DataBind
- /// <summary>
- /// 加热阶段信息
- /// </summary>
- public ObservableCollection<HeatingSetting> HeatData { get; set; }
- /// <summary>
- /// 冷却
- /// </summary>
- public ObservableCollection<CoolingSetting> CoolingData { get; set; }
- /// <summary>
- /// PID
- /// </summary>
- public ObservableCollection<PID> PIDs { get; set; }
- /// <summary>
- /// 速度
- /// </summary>
- public ObservableCollection<MotorSpeed> SpeedInfos { get; set; }
- /// <summary>
- /// 液体
- /// </summary>
- public ObservableCollection<DropLiquid> LiquidWashes { get; set; }
- public ObservableCollection<LiquidTotal> LiquidTotals { get; set; }
- public ObservableCollection<DropAmount> LiquidAmount { get; set; }
- /// <summary>
- /// 滴定值
- /// </summary>
- public ObservableCollection<TitrationValue> TitrationValue { get; set; }
- public ObservableCollection<string> Wavekeys { get; set; }
- public void InitData()
- {
- PortName = _config.Port;
- AutoFindPort = _config.IsAutoGetPort;
- AutoWriteSpeed = _config.SpeedWrite;
- isStartHeat = _config.OpenAppStartHeat;
- TemplateFilePath = _config.TemplateFilePath;
- PreheatTemperature = _config.PreheatTemperature;
- AddWaterTemperature = _config.AddWaterTemperature;
- SampleResultFilePath = _config.ResultWordFilePath;
- CoolingPipeWatingTime = _config.CoolingPipeWatingTime;
- DissolveMoveDistance = _config.DissolveMoveDistance;
- ManiGrabFeedback = _config.ManiGrabFeedBack;
- DripNozzleFeedBack = _config.DripNozzleFeedBack;
- IsAddCupFeedBack = _config.IsAddCupFeedBack;
- ExportTypeByExcel=_config.ExportTypeByExcel;
- ExportTypeByWord = _config.ExportTypeByWord;
- IsAddCupBiaoDingBubei = _config.IsAddCupBiaoDingBubei;
- SpeedInfos = new ObservableCollection<MotorSpeed>(_config.GetSpeed);
- PIDs = new ObservableCollection<PID>(_controller.GetData<PID>());
- LiquidAmount = new ObservableCollection<DropAmount>(_config.DropOnceAmounts);
- LiquidWashes = new ObservableCollection<DropLiquid>(_controller.GetData<DropLiquid>());
- LiquidTotals = new ObservableCollection<LiquidTotal>(_controller.GetData<LiquidTotal>());
- HeatData = new ObservableCollection<HeatingSetting>(_controller.GetData<HeatingSetting>());
- CoolingData = new ObservableCollection<CoolingSetting>(_controller.GetData<CoolingSetting>());
- TitrationValue = new ObservableCollection<TitrationValue>(_controller.GetData<TitrationValue>());
- Wavekeys = new ObservableCollection<string>((from wave in _controller.GetWavekeys() select wave.WaveKey).ToList());
- WavekeysCurrentShow = Wavekeys.FirstOrDefault();
- lowCalibrationValue = _controller.GetBlankCalibrationValue(Wavekeys.FirstOrDefault(),"Low","标定");
- lowBlankValue = _controller.GetBlankCalibrationValue(Wavekeys.FirstOrDefault(), "Low","空白");
- highCalibrationValue = _controller.GetBlankCalibrationValue(Wavekeys.FirstOrDefault(), "High","标定");
- highBlankValue = _controller.GetBlankCalibrationValue(Wavekeys.FirstOrDefault(), "High", "空白");
- }
- #region titration
- public TitrationValue Titration
- {
- get => TitrationValue.FirstOrDefault();
- set
- {
- TitrationValue.ToArray()[0] = value;
- RaisePropertyChanged(nameof(Titration));
- }
- }
- #endregion
- #region
- private string _portName;
- public string PortName
- {
- get => _portName;
- set => SetProperty(ref _portName, value);
- }
- private bool _autoFindPort;
- public bool AutoFindPort
- {
- get => _autoFindPort;
- set => SetProperty(ref _autoFindPort, value);
- }
-
- private string wavekeysCurrentShow;
- public string WavekeysCurrentShow
- {
- get => wavekeysCurrentShow;
- set => SetProperty(ref wavekeysCurrentShow, value);
- }
- private double lowCalibrationValue;
- public double LowCalibrationValue
- {
- get => lowCalibrationValue;
- set => SetProperty(ref lowCalibrationValue, value);
- }
- private double lowBlankValue;
- public double LowBlankValue
- {
- get => lowBlankValue;
- set => SetProperty(ref lowBlankValue, value);
- }
- private double highCalibrationValue;
- public double HighCalibrationValue
- {
- get => highCalibrationValue;
- set => SetProperty(ref highCalibrationValue, value);
- }
- private double highBlankValue;
- public double HighBlankValue
- {
- get => highBlankValue;
- set => SetProperty(ref highBlankValue, value);
- }
- #endregion
- private bool _maniGrabFeedback;
- public bool ManiGrabFeedback
- {
- get => _maniGrabFeedback;
- set => SetProperty(ref _maniGrabFeedback, value);
- }
- private bool _dripNozzleFeedBack;
- public bool DripNozzleFeedBack
- {
- get => _dripNozzleFeedBack;
- set => SetProperty(ref _dripNozzleFeedBack, value);
- }
- private bool _IsAddCupFeedBack;
- public bool IsAddCupFeedBack
- {
- get => _IsAddCupFeedBack;
- set => SetProperty(ref _IsAddCupFeedBack, value);
- }
- private bool _IsAddCupBiaoDingBubei;
- public bool IsAddCupBiaoDingBubei
- {
- get => _IsAddCupBiaoDingBubei;
- set => SetProperty(ref _IsAddCupBiaoDingBubei, value);
- }
- private bool _IsExportTypeByExcel;
- public bool ExportTypeByExcel
- {
- get => _IsExportTypeByExcel;
- set => SetProperty(ref _IsExportTypeByExcel, value);
- }
- private bool _IsExportTypeByWord;
- public bool ExportTypeByWord
- {
- get => _IsExportTypeByWord;
- set => SetProperty(ref _IsExportTypeByWord, value);
- }
- private bool _autoWriteSpeed;
- public bool AutoWriteSpeed
- {
- get => _autoWriteSpeed;
- set => SetProperty(ref _autoWriteSpeed, value);
- }
- public string templateFilePath;
- public string TemplateFilePath
- {
- get => templateFilePath;
- set => SetProperty(ref templateFilePath, value);
- }
- public string sampleResultFilePath;
- public string SampleResultFilePath
- {
- get => sampleResultFilePath;
- set => SetProperty(ref sampleResultFilePath, value);
- }
- /// <summary>
- /// 是否开机自动加热
- /// </summary>
- private bool isStartHeat;
- public bool IsStartHeat
- {
- get => isStartHeat;
- set => SetProperty(ref isStartHeat, value);
- }
- private double _preheatTemperature;
- public double PreheatTemperature
- {
- get => _preheatTemperature;
- set => SetProperty(ref _preheatTemperature, value);
- }
- private double _addWaterTemperature;
- public double AddWaterTemperature
- {
- get => _addWaterTemperature;
- set => SetProperty(ref _addWaterTemperature, value);
- }
- private double _coolingPipeWatingTime;
- public double CoolingPipeWatingTime
- {
- get => _coolingPipeWatingTime;
- set => SetProperty(ref _coolingPipeWatingTime, value);
- }
- private double _dissolveMoveDistance;
- public double DissolveMoveDistance
- {
- get => _dissolveMoveDistance;
- set => SetProperty(ref _dissolveMoveDistance, value);
- }
- #endregion
- #region Command
- /// <summary>
- /// 更新配置
- /// </summary>
- public DelegateCommand<object> _updateSettingInfoCommand;
- public DelegateCommand<object> UpdateSettingInfoCommand => _updateSettingInfoCommand ?? new DelegateCommand<object>(UpdateSettingInfo);
- public DelegateCommand<object> _optTemplatePathCommand;
- public DelegateCommand<object> OptTemplatePathCommand => _optTemplatePathCommand ?? new DelegateCommand<object>(OptTemplatePath);
- public DelegateCommand<object> _optSampleResultPathCommand;
- public DelegateCommand<object> OptSampleResultPathCommand => _optSampleResultPathCommand ?? new DelegateCommand<object>(OptSampleResultPath);
- public DelegateCommand<object> _settingSpeedCommand;
- public DelegateCommand<object> SettingSpeedCommand => _settingSpeedCommand ?? new DelegateCommand<object>(SettingSpeed);
- public DelegateCommand<object> _lowValueUpdateCommand;
- public DelegateCommand<object> LowValueUpdateCommand => _lowValueUpdateCommand ?? new DelegateCommand<object>(LowValueUpdate);
- public DelegateCommand<object> _highValueUpdateCommand;
- public DelegateCommand<object> HighValueUpdateCommand => _highValueUpdateCommand ?? new DelegateCommand<object>(HighValueUpdate);
- /// <summary>
- /// 低浓度阈值更新
- /// </summary>
- /// <param name="obj"></param>
- private void LowValueUpdate(object obj)
- {
- Dictionary<string, object> values = new()
- {
- { "valuetype", "Low" },
- { "bd", lowCalibrationValue },
- { "kb", lowBlankValue },
- { "waveKey", wavekeysCurrentShow }
- };
- Messager.Send("UpdateResultValue", values);
- }
- /// <summary>
- /// 高浓度阈值更新
- /// </summary>
- /// <param name="obj"></param>
- private void HighValueUpdate(object obj)
- {
- Dictionary<string, object> values = new()
- {
- { "valuetype", "High" },
- { "bd", highCalibrationValue },
- { "kb", highBlankValue },
- { "waveKey", wavekeysCurrentShow }
- };
- Messager.Send("UpdateResultValue", values);
- }
- /// <summary>
- /// 设置速度
- /// </summary>
- /// <param name="obj"></param>
- private void SettingSpeed(object obj)
- {
- var speed = SpeedInfos.FirstOrDefault(item => item.NodeId.Equals(obj.ToString()));
- var res = _controller.SetSpeed(speed);
- UMessageBox.InfoTip($"{speed.Description}速度设置{(res ? "成功" : "失败")}");
- }
- private void OptSampleResultPath(object obj)
- {
- var dialog = new FolderBrowserDialog
- {
- SelectedPath = string.IsNullOrWhiteSpace(_config.ResultWordFilePath) ? System.AppDomain.CurrentDomain.BaseDirectory : _config.ResultWordFilePath
- };
- if (dialog.ShowDialog().Equals(DialogResult.OK))
- {
- var folderName = dialog.SelectedPath;
- SampleResultFilePath = folderName ;
- }
- }
- /// <summary>
- /// 更新配置信息
- /// </summary>
- /// <param name="obj"></param>
- private void UpdateSettingInfo(object obj)
- {
- var pidRes = _controller.UpdateValues(PIDs.ToList());
- var heatRes = _controller.UpdateValues(HeatData.ToList());
- var washRes = _controller.UpdateValues(LiquidWashes.ToList());
- var liquidTotal = _controller.UpdateValues(LiquidTotals.ToList());
- var coolingRes = _controller.UpdateValues(CoolingData.ToList());
- var titrationRes = _controller.UpdateValues(TitrationValue.ToList());
- _config.UpdateAmount(LiquidAmount.ToList());
- _config.UpdateTemplateFilePath(TemplateFilePath);
- _config.UpdateAppStartHeat(IsStartHeat.ToString());
- _config.UpdatePreheatTemperature(PreheatTemperature);
- _config.UpdateResultWordFilePath(SampleResultFilePath);
- _config.UpdateExportTypeByExcel(ExportTypeByExcel);
- _config.UpdateExportTypeByWord(ExportTypeByWord);
- _config.UpdateAddWaterTemperature(AddWaterTemperature);
- _config.UpdateCoolingPipeWatingTime(CoolingPipeWatingTime);
- _config.UpdateDissolveMoveDistance(DissolveMoveDistance);
- _config.UpdateManiGrabFeedBack(ManiGrabFeedback);
- _config.UpdateDripNozzleFeedBack(DripNozzleFeedBack);
- _config.UpdateIsAddCupFeedBack(IsAddCupFeedBack);
- _config.UpdateIsAddCupBiaoDingBubei(IsAddCupBiaoDingBubei);
- _config.UpdatePort(PortName);
- _config.UpdateAutoFindPort(AutoFindPort);
- foreach (var item in SpeedInfos)
- {
- _config.UpdateSpeed(item.NodeId, item.Speed);
- _config.UpdateAcSpeed(item.NodeId, item.AcSpeed);
- _config.UpdateDeSpeed(item.NodeId, item.DeSpeed);
- }
- _config.UpdateSpeedWrite(AutoWriteSpeed);
- if (heatRes && coolingRes && pidRes && washRes && liquidTotal && titrationRes)
- {
- UMessageBox.SuccessTip("配置更新成功!");
- }
- }
- public void OptTemplatePath(object obj)
- {
- var dialog = new FolderBrowserDialog
- {
- SelectedPath = string.IsNullOrWhiteSpace(_config.TemplateFilePath) ? System.AppDomain.CurrentDomain.BaseDirectory : _config.TemplateFilePath
- };
- if (dialog.ShowDialog().Equals(DialogResult.OK))
- {
- var folderName = dialog.SelectedPath;
- TemplateFilePath = folderName + "\\WaterTemplate.xlsx";
- }
- }
- #endregion
- }
- }
|