| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- using System;
- using Prism.Mvvm;
- using Prism.Events;
- using Prism.Commands;
- using Panuon.UI.Silver;
- using System.Windows.Forms;
- using SHJX.Service.Common.Event;
- using SHJX.Service.Common.Interface;
- using SHJX.Service.Control.Interface;
- namespace SHJX.Service.Shell.ViewModels.Setting
- {
- public class OtherSettingWindowViewModel : BindableBase
- {
- #region Fields
- private readonly ILogService _log;
- private readonly IEventAggregator _ea;
- private readonly ISettingService _service;
- #endregion
- #region Properties
- private string _templateFilePath;
- public string TemplateFilePath
- {
- get => _templateFilePath;
- set => SetProperty(ref _templateFilePath, value);
- }
- private string _templatePath;
- public string TemplatePath
- {
- get => _templatePath;
- set => SetProperty(ref _templatePath, value);
- }
- private string _sampleResultFilePath;
- public string SampleResultFilePath
- {
- get => _sampleResultFilePath;
- set => SetProperty(ref _sampleResultFilePath, value);
- }
- private string _resultFilePath;
- public string ResultPath
- {
- get => _resultFilePath;
- set => SetProperty(ref _resultFilePath, value);
- }
- private bool _automaticInLiquid;
- public bool AutomaticInLiquid
- {
- get { return _automaticInLiquid; }
- set { _automaticInLiquid = value; }
- }
- private double _manualTemperature;
- public double ManualTemperature
- {
- get => _manualTemperature;
- set => SetProperty(ref _manualTemperature, value);
- }
- private double _manualHumidity;
- public double ManualHumidity
- {
- get => _manualHumidity;
- set => SetProperty(ref _manualHumidity, value);
- }
- private double _finishTemprature;
- public double FinishTemprature
- {
- get => _finishTemprature;
- set => SetProperty(ref _finishTemprature, value);
- }
- private bool? _exportTypeByExcel;
- public bool? ExportTypeByExcel
- {
- get => _exportTypeByExcel;
- set => SetProperty(ref _exportTypeByExcel, value);
- }
- private bool? _exportTypeByWord;
- public bool? ExportTypeByWord
- {
- get => _exportTypeByWord;
- set => SetProperty(ref _exportTypeByWord, value);
- }
- private bool? _tongsFeedbackValue;
- public bool? TongsFeedbackValue
- {
- get => _tongsFeedbackValue;
- set => SetProperty(ref _tongsFeedbackValue, value);
- }
-
- #endregion
- public OtherSettingWindowViewModel(IEventAggregator ea, ILogService log, ISettingService service)
- {
- _ea = ea;
- _log = log;
- _service = service;
- AutomaticInLiquid = service.IsAutomaticInLiquid;
- FinishTemprature = service.TaskFinishTemprature;
- ExportTypeByExcel = service.IsExportTypeByExcel;
- ExportTypeByWord = service.IsExportTypeByWord;
- TongsFeedbackValue = service.TongsFeedback;
- TemplatePathDispalyValue(_service.GetConfigValue("template"));
- ResultPathDisplayValue(_service.GetConfigValue("result"));
- _ea.GetEvent<UpdateSettingEvent>().Subscribe(UpdateSetting);
- _ea.GetEvent<SettingClosingEvent>().Subscribe(() =>
- {
- _ea.GetEvent<UpdateSettingEvent>().Unsubscribe(UpdateSetting);
- });
- }
- #region Command
- private DelegateCommand<object> _optTemplatePathCommand;
- public DelegateCommand<object> OptTemplatePathCommand => _optTemplatePathCommand ??= new DelegateCommand<object>(ExecuteOptTemplatePathCommand);
- private DelegateCommand<object> _optSampleResultPathCommand;
- public DelegateCommand<object> OptSampleResultPathCommand => _optSampleResultPathCommand ??= new DelegateCommand<object>(ExecuteOptSampleResultPathCommand);
- private DelegateCommand _manualSetTemperatureCommand;
- public DelegateCommand ManualSetTemperatureCommand => _manualSetTemperatureCommand ??= new DelegateCommand(() =>
- {
- _ea.GetEvent<NoticeHumitureEvent>().Publish((Temperature: ManualTemperature, Humidity: ManualHumidity));
- });
- #endregion
- #region Execute
- private void ExecuteOptTemplatePathCommand(object obj)
- {
- FolderBrowserDialog dialog = new()
- {
- SelectedPath = string.IsNullOrWhiteSpace(string.Empty) ? AppDomain.CurrentDomain.BaseDirectory : string.Empty
- };
- if (dialog.ShowDialog().Equals(DialogResult.OK))
- {
- string folderName = dialog.SelectedPath;
- string folderPath = folderName + "\\SampleTemplate.xlsx";
- TemplatePathDispalyValue(folderPath);
- }
- }
- private void ExecuteOptSampleResultPathCommand(object obj)
- {
- FolderBrowserDialog dialog = new()
- {
- SelectedPath = string.IsNullOrWhiteSpace(string.Empty) ? AppDomain.CurrentDomain.BaseDirectory : string.Empty
- };
- if (dialog.ShowDialog().Equals(DialogResult.OK))
- {
- string folderName = dialog.SelectedPath;
- string folderPath = folderName + "\\";
- ResultPathDisplayValue(folderPath);
- }
- }
- #endregion
- #region Method
- public void UpdateSetting()
- {
- _service.UpdatePath("template", TemplatePath);
- _service.UpdatePath("result", ResultPath);
- _service.UpdatePath("automatic", AutomaticInLiquid);
- _service.UpdatePath("finish", FinishTemprature);
- _service.UpdatePath("excel", ExportTypeByExcel);
- _service.UpdatePath("word", ExportTypeByWord);
- _service.UpdatePath("tongs", TongsFeedbackValue);
- Notice.Show($"设备相关设置更新成功", "Info", 3, Panuon.UI.Silver.MessageBoxIcon.Info);
- }
- private void TemplatePathDispalyValue(string folderPath)
- {
- string showStr = folderPath.Length > 70 ? $"......{folderPath[(folderPath.Length - 70)..]}" : folderPath;
- TemplateFilePath = showStr;
- TemplatePath = folderPath;
- }
- private void ResultPathDisplayValue(string folderPath)
- {
- string showStr = folderPath.Length > 70 ? $"......{folderPath[(folderPath.Length - 70)..]}" : folderPath;
- SampleResultFilePath = showStr;
- ResultPath = folderPath;
- }
- #endregion
- }
- }
|