ModeSettingViewModel.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using System;
  2. using CustomUI;
  3. using Prism.Mvvm;
  4. using System.Linq;
  5. using Prism.Events;
  6. using Prism.Commands;
  7. using SHJX.Service.Model.Enums;
  8. using SHJX.Service.Common.Event;
  9. using SHJX.Service.Common.Utils;
  10. using System.Collections.Generic;
  11. using SHJX.Service.Model.CRUDModules;
  12. using SHJX.Service.Control.Interface;
  13. namespace SHJX.Service.Library.ViewModels
  14. {
  15. public class ModeSettingViewModel : BindableBase
  16. {
  17. #region Field
  18. private readonly IEventAggregator _ea;
  19. private readonly IMainService _service;
  20. #endregion
  21. #region Property
  22. public string _detailKey;
  23. public string DetailKey
  24. {
  25. get => _detailKey;
  26. set => SetProperty(ref _detailKey, value);
  27. }
  28. public string _sampleDetail;
  29. public string SampleDetail
  30. {
  31. get
  32. {
  33. if (string.IsNullOrWhiteSpace(_sampleDetail))
  34. {
  35. _sampleDetail = DateTime.Now.ToString("MMddmmss");
  36. }
  37. return _sampleDetail;
  38. }
  39. set => SetProperty(ref _sampleDetail, value);
  40. }
  41. public string _sampleVolume;
  42. public string SampleVolume
  43. {
  44. get => _sampleVolume;
  45. set => SetProperty(ref _sampleVolume, value);
  46. }
  47. public string _sampleMultiple;
  48. public string SampleMultiple
  49. {
  50. get => _sampleMultiple;
  51. set => SetProperty(ref _sampleMultiple, value);
  52. }
  53. public int _segmentIndex;
  54. public int SegmentIndex
  55. {
  56. get => _segmentIndex;
  57. set => SetProperty(ref _segmentIndex, value);
  58. }
  59. public SegmentItem _sampleType;
  60. public SegmentItem SampleType
  61. {
  62. get => _sampleType;
  63. set => SetProperty(ref _sampleType, value);
  64. }
  65. public bool _isSend;
  66. public bool IsSend
  67. {
  68. get => _isSend;
  69. set => SetProperty(ref _isSend, value);
  70. }
  71. private bool _acidChecked;
  72. public bool AcidChecked
  73. {
  74. get => _acidChecked;
  75. set => SetProperty(ref _acidChecked, value);
  76. }
  77. private bool _alkaliChecked;
  78. public bool AlkaliChecked
  79. {
  80. get => _alkaliChecked;
  81. set => SetProperty(ref _alkaliChecked, value);
  82. }
  83. private bool? _dialogResult;
  84. public bool? DialogResult
  85. {
  86. get { return _dialogResult; }
  87. set => SetProperty(ref _dialogResult, value);
  88. }
  89. private bool? _calibrationEnable;
  90. public bool? CalibrationEnable
  91. {
  92. get { return _calibrationEnable; }
  93. set => SetProperty(ref _calibrationEnable, value);
  94. }
  95. private bool _calibrationChecked;
  96. public bool CalibrationChecked
  97. {
  98. get { return _calibrationChecked; }
  99. set => SetProperty(ref _calibrationChecked, value);
  100. }
  101. #endregion
  102. #region Command
  103. private DelegateCommand<object> _clickSureCommand;
  104. public DelegateCommand<object> ClickSureCommand => _clickSureCommand ??= new DelegateCommand<object>(ExecuteClickSureCommand);
  105. private DelegateCommand _modeSelectionChangedCommand;
  106. public DelegateCommand ModeSelectionChangedCommand => _modeSelectionChangedCommand ??= new DelegateCommand(ExecuteModeSelectionChanged);
  107. private DelegateCommand<object> _cancelCommand;
  108. public DelegateCommand<object> CancelCommand => _cancelCommand ??= new DelegateCommand<object>(ExecuteCancel);
  109. private DelegateCommand _loadingCommand;
  110. public DelegateCommand LoadingCommand => _loadingCommand ??= new DelegateCommand(ExecuteLoadingCommand);
  111. private DelegateCommand<string> _sampleVolumeTextChangedCommand;
  112. public DelegateCommand<string> SampleVolumeTextChangedCommand => _sampleVolumeTextChangedCommand ??= new DelegateCommand<string>(ExecuteSampleVolumeTextChangedCommand);
  113. #endregion
  114. #region Execute
  115. void ExecuteLoadingCommand()
  116. {
  117. SampleDetail detail = _service.GetData<SampleDetail>().FirstOrDefault(item => item.NodeName.Equals(DetailKey));
  118. if (detail.TaskStatus.BeIn(DetailState.New, DetailState.Doing))
  119. {
  120. switch (detail.AcidBaseProp)
  121. {
  122. case AcidBase.Acid:
  123. AcidChecked = true;
  124. break;
  125. case AcidBase.Alkali:
  126. AlkaliChecked = true;
  127. break;
  128. }
  129. SampleDetail = detail.DetailInfo;
  130. CalibrationChecked = detail.IsCalibration;
  131. SampleVolume = detail.SampleVolume.ToString();
  132. SampleMultiple = detail.SampleMultiple.ToString();
  133. int index = detail.SampleType switch
  134. {
  135. "样品" => 0,
  136. "空白" => 1,
  137. _ => 0,
  138. };
  139. SegmentIndex = index;
  140. }
  141. else
  142. {
  143. AcidChecked = true;
  144. SegmentIndex = 0;
  145. SampleVolume = "100";
  146. SampleMultiple = "0";
  147. CalibrationChecked = false;
  148. }
  149. if (SegmentIndex.Equals(0))
  150. {
  151. CalibrationChecked = false;
  152. }
  153. CalibrationEnable = SegmentIndex.Equals(0) ? false : true;
  154. IsSend = true;
  155. }
  156. void ExecuteCancel(object obj)
  157. {
  158. DialogResult = true;
  159. }
  160. void ExecuteModeSelectionChanged()
  161. {
  162. SampleDetail = SampleType.Content.ToString() switch
  163. {
  164. "样品" => DateTime.Now.ToString("MMddmmss"),
  165. _ => SampleType.Content.ToString(),
  166. };
  167. if (SampleType.Content.ToString().Equals("样品"))
  168. {
  169. CalibrationChecked = false;
  170. }
  171. CalibrationEnable = SampleType.Content.ToString().Equals("样品") ? false : true;
  172. }
  173. public void ExecuteClickSureCommand(object parameter)
  174. {
  175. SampleDetail detailArgs = new()
  176. {
  177. NodeName = DetailKey,
  178. DetailInfo = SampleDetail,
  179. SampleVolume = Convert.ToDouble(SampleVolume),
  180. SampleMultiple = Convert.ToDouble(SampleMultiple),
  181. SampleType = SampleType.Content.ToString(),
  182. IsCalibration = CalibrationChecked,
  183. AcidBaseProp = AcidChecked ? AcidBase.Acid : AcidBase.Alkali,
  184. TaskStatus = IsSend ? DetailState.New : DetailState.Init
  185. };
  186. List<SampleDetail> list = new() { detailArgs };
  187. _ea.GetEvent<SampleDetailEvent>().Publish(list);//发布消息
  188. DialogResult = true;
  189. }
  190. private void ExecuteSampleVolumeTextChangedCommand(string value)
  191. {
  192. if (string.IsNullOrWhiteSpace(value))
  193. {
  194. return;
  195. }
  196. double volume = Convert.ToDouble(value);
  197. SampleMultiple = ((100 - volume) / 100).ToString("F3");
  198. }
  199. #endregion
  200. public ModeSettingViewModel(IEventAggregator ea, IMainService service)
  201. {
  202. _ea = ea;
  203. _service = service;
  204. }
  205. }
  206. }