OtherSettingWindowViewModel.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using Prism.Mvvm;
  3. using Prism.Events;
  4. using Prism.Commands;
  5. using Panuon.UI.Silver;
  6. using System.Windows.Forms;
  7. using SHJX.Service.Common.Event;
  8. using SHJX.Service.Common.Interface;
  9. using SHJX.Service.Control.Interface;
  10. namespace SHJX.Service.Shell.ViewModels.Setting
  11. {
  12. public class OtherSettingWindowViewModel : BindableBase
  13. {
  14. #region Fields
  15. private readonly ILogService _log;
  16. private readonly IEventAggregator _ea;
  17. private readonly ISettingService _service;
  18. #endregion
  19. #region Properties
  20. private string _templateFilePath;
  21. public string TemplateFilePath
  22. {
  23. get => _templateFilePath;
  24. set => SetProperty(ref _templateFilePath, value);
  25. }
  26. private string _templatePath;
  27. public string TemplatePath
  28. {
  29. get => _templatePath;
  30. set => SetProperty(ref _templatePath, value);
  31. }
  32. private string _sampleResultFilePath;
  33. public string SampleResultFilePath
  34. {
  35. get => _sampleResultFilePath;
  36. set => SetProperty(ref _sampleResultFilePath, value);
  37. }
  38. private string _resultFilePath;
  39. public string ResultPath
  40. {
  41. get => _resultFilePath;
  42. set => SetProperty(ref _resultFilePath, value);
  43. }
  44. private bool _automaticInLiquid;
  45. public bool AutomaticInLiquid
  46. {
  47. get { return _automaticInLiquid; }
  48. set { _automaticInLiquid = value; }
  49. }
  50. private double _manualTemperature;
  51. public double ManualTemperature
  52. {
  53. get => _manualTemperature;
  54. set => SetProperty(ref _manualTemperature, value);
  55. }
  56. private double _manualHumidity;
  57. public double ManualHumidity
  58. {
  59. get => _manualHumidity;
  60. set => SetProperty(ref _manualHumidity, value);
  61. }
  62. private double _finishTemprature;
  63. public double FinishTemprature
  64. {
  65. get => _finishTemprature;
  66. set => SetProperty(ref _finishTemprature, value);
  67. }
  68. private bool? _exportTypeByExcel;
  69. public bool? ExportTypeByExcel
  70. {
  71. get => _exportTypeByExcel;
  72. set => SetProperty(ref _exportTypeByExcel, value);
  73. }
  74. private bool? _exportTypeByWord;
  75. public bool? ExportTypeByWord
  76. {
  77. get => _exportTypeByWord;
  78. set => SetProperty(ref _exportTypeByWord, value);
  79. }
  80. private bool? _tongsFeedbackValue;
  81. public bool? TongsFeedbackValue
  82. {
  83. get => _tongsFeedbackValue;
  84. set => SetProperty(ref _tongsFeedbackValue, value);
  85. }
  86. #endregion
  87. public OtherSettingWindowViewModel(IEventAggregator ea, ILogService log, ISettingService service)
  88. {
  89. _ea = ea;
  90. _log = log;
  91. _service = service;
  92. AutomaticInLiquid = service.IsAutomaticInLiquid;
  93. FinishTemprature = service.TaskFinishTemprature;
  94. ExportTypeByExcel = service.IsExportTypeByExcel;
  95. ExportTypeByWord = service.IsExportTypeByWord;
  96. TongsFeedbackValue = service.TongsFeedback;
  97. TemplatePathDispalyValue(_service.GetConfigValue("template"));
  98. ResultPathDisplayValue(_service.GetConfigValue("result"));
  99. _ea.GetEvent<UpdateSettingEvent>().Subscribe(UpdateSetting);
  100. _ea.GetEvent<SettingClosingEvent>().Subscribe(() =>
  101. {
  102. _ea.GetEvent<UpdateSettingEvent>().Unsubscribe(UpdateSetting);
  103. });
  104. }
  105. #region Command
  106. private DelegateCommand<object> _optTemplatePathCommand;
  107. public DelegateCommand<object> OptTemplatePathCommand => _optTemplatePathCommand ??= new DelegateCommand<object>(ExecuteOptTemplatePathCommand);
  108. private DelegateCommand<object> _optSampleResultPathCommand;
  109. public DelegateCommand<object> OptSampleResultPathCommand => _optSampleResultPathCommand ??= new DelegateCommand<object>(ExecuteOptSampleResultPathCommand);
  110. private DelegateCommand _manualSetTemperatureCommand;
  111. public DelegateCommand ManualSetTemperatureCommand => _manualSetTemperatureCommand ??= new DelegateCommand(() =>
  112. {
  113. _ea.GetEvent<NoticeHumitureEvent>().Publish((Temperature: ManualTemperature, Humidity: ManualHumidity));
  114. });
  115. #endregion
  116. #region Execute
  117. private void ExecuteOptTemplatePathCommand(object obj)
  118. {
  119. FolderBrowserDialog dialog = new()
  120. {
  121. SelectedPath = string.IsNullOrWhiteSpace(string.Empty) ? AppDomain.CurrentDomain.BaseDirectory : string.Empty
  122. };
  123. if (dialog.ShowDialog().Equals(DialogResult.OK))
  124. {
  125. string folderName = dialog.SelectedPath;
  126. string folderPath = folderName + "\\SampleTemplate.xlsx";
  127. TemplatePathDispalyValue(folderPath);
  128. }
  129. }
  130. private void ExecuteOptSampleResultPathCommand(object obj)
  131. {
  132. FolderBrowserDialog dialog = new()
  133. {
  134. SelectedPath = string.IsNullOrWhiteSpace(string.Empty) ? AppDomain.CurrentDomain.BaseDirectory : string.Empty
  135. };
  136. if (dialog.ShowDialog().Equals(DialogResult.OK))
  137. {
  138. string folderName = dialog.SelectedPath;
  139. string folderPath = folderName + "\\";
  140. ResultPathDisplayValue(folderPath);
  141. }
  142. }
  143. #endregion
  144. #region Method
  145. public void UpdateSetting()
  146. {
  147. _service.UpdatePath("template", TemplatePath);
  148. _service.UpdatePath("result", ResultPath);
  149. _service.UpdatePath("automatic", AutomaticInLiquid);
  150. _service.UpdatePath("finish", FinishTemprature);
  151. _service.UpdatePath("excel", ExportTypeByExcel);
  152. _service.UpdatePath("word", ExportTypeByWord);
  153. _service.UpdatePath("tongs", TongsFeedbackValue);
  154. Notice.Show($"设备相关设置更新成功", "Info", 3, Panuon.UI.Silver.MessageBoxIcon.Info);
  155. }
  156. private void TemplatePathDispalyValue(string folderPath)
  157. {
  158. string showStr = folderPath.Length > 70 ? $"......{folderPath[(folderPath.Length - 70)..]}" : folderPath;
  159. TemplateFilePath = showStr;
  160. TemplatePath = folderPath;
  161. }
  162. private void ResultPathDisplayValue(string folderPath)
  163. {
  164. string showStr = folderPath.Length > 70 ? $"......{folderPath[(folderPath.Length - 70)..]}" : folderPath;
  165. SampleResultFilePath = showStr;
  166. ResultPath = folderPath;
  167. }
  168. #endregion
  169. }
  170. }