using System; using CustomUI; using Prism.Mvvm; using System.Linq; using Prism.Events; using Prism.Commands; using SHJX.Service.Model.Enums; using SHJX.Service.Common.Event; using SHJX.Service.Common.Utils; using System.Collections.Generic; using SHJX.Service.Model.CRUDModules; using SHJX.Service.Control.Interface; namespace SHJX.Service.Library.ViewModels { public class ModeSettingViewModel : BindableBase { #region Field private readonly IEventAggregator _ea; private readonly IMainService _service; #endregion #region Property public string _detailKey; public string DetailKey { get => _detailKey; set => SetProperty(ref _detailKey, value); } public string _sampleDetail; public string SampleDetail { get { if (string.IsNullOrWhiteSpace(_sampleDetail)) { _sampleDetail = DateTime.Now.ToString("MMddmmss"); } return _sampleDetail; } set => SetProperty(ref _sampleDetail, value); } public string _sampleVolume; public string SampleVolume { get => _sampleVolume; set => SetProperty(ref _sampleVolume, value); } public string _sampleMultiple; public string SampleMultiple { get => _sampleMultiple; set => SetProperty(ref _sampleMultiple, value); } public int _segmentIndex; public int SegmentIndex { get => _segmentIndex; set => SetProperty(ref _segmentIndex, value); } public SegmentItem _sampleType; public SegmentItem SampleType { get => _sampleType; set => SetProperty(ref _sampleType, value); } public bool _isSend; public bool IsSend { get => _isSend; set => SetProperty(ref _isSend, value); } private bool _acidChecked; public bool AcidChecked { get => _acidChecked; set => SetProperty(ref _acidChecked, value); } private bool _alkaliChecked; public bool AlkaliChecked { get => _alkaliChecked; set => SetProperty(ref _alkaliChecked, value); } private bool? _dialogResult; public bool? DialogResult { get { return _dialogResult; } set => SetProperty(ref _dialogResult, value); } private bool? _calibrationEnable; public bool? CalibrationEnable { get { return _calibrationEnable; } set => SetProperty(ref _calibrationEnable, value); } private bool _calibrationChecked; public bool CalibrationChecked { get { return _calibrationChecked; } set => SetProperty(ref _calibrationChecked, value); } #endregion #region Command private DelegateCommand _clickSureCommand; public DelegateCommand ClickSureCommand => _clickSureCommand ??= new DelegateCommand(ExecuteClickSureCommand); private DelegateCommand _modeSelectionChangedCommand; public DelegateCommand ModeSelectionChangedCommand => _modeSelectionChangedCommand ??= new DelegateCommand(ExecuteModeSelectionChanged); private DelegateCommand _cancelCommand; public DelegateCommand CancelCommand => _cancelCommand ??= new DelegateCommand(ExecuteCancel); private DelegateCommand _loadingCommand; public DelegateCommand LoadingCommand => _loadingCommand ??= new DelegateCommand(ExecuteLoadingCommand); private DelegateCommand _sampleVolumeTextChangedCommand; public DelegateCommand SampleVolumeTextChangedCommand => _sampleVolumeTextChangedCommand ??= new DelegateCommand(ExecuteSampleVolumeTextChangedCommand); #endregion #region Execute void ExecuteLoadingCommand() { SampleDetail detail = _service.GetData().FirstOrDefault(item => item.NodeName.Equals(DetailKey)); if (detail.TaskStatus.BeIn(DetailState.New, DetailState.Doing)) { switch (detail.AcidBaseProp) { case AcidBase.Acid: AcidChecked = true; break; case AcidBase.Alkali: AlkaliChecked = true; break; } SampleDetail = detail.DetailInfo; CalibrationChecked = detail.IsCalibration; SampleVolume = detail.SampleVolume.ToString(); SampleMultiple = detail.SampleMultiple.ToString(); int index = detail.SampleType switch { "样品" => 0, "空白" => 1, _ => 0, }; SegmentIndex = index; } else { AcidChecked = true; SegmentIndex = 0; SampleVolume = "100"; SampleMultiple = "0"; CalibrationChecked = false; } if (SegmentIndex.Equals(0)) { CalibrationChecked = false; } CalibrationEnable = SegmentIndex.Equals(0) ? false : true; IsSend = true; } void ExecuteCancel(object obj) { DialogResult = true; } void ExecuteModeSelectionChanged() { SampleDetail = SampleType.Content.ToString() switch { "样品" => DateTime.Now.ToString("MMddmmss"), _ => SampleType.Content.ToString(), }; if (SampleType.Content.ToString().Equals("样品")) { CalibrationChecked = false; } CalibrationEnable = SampleType.Content.ToString().Equals("样品") ? false : true; } public void ExecuteClickSureCommand(object parameter) { SampleDetail detailArgs = new() { NodeName = DetailKey, DetailInfo = SampleDetail, SampleVolume = Convert.ToDouble(SampleVolume), SampleMultiple = Convert.ToDouble(SampleMultiple), SampleType = SampleType.Content.ToString(), IsCalibration = CalibrationChecked, AcidBaseProp = AcidChecked ? AcidBase.Acid : AcidBase.Alkali, TaskStatus = IsSend ? DetailState.New : DetailState.Init }; List list = new() { detailArgs }; _ea.GetEvent().Publish(list);//发布消息 DialogResult = true; } private void ExecuteSampleVolumeTextChangedCommand(string value) { if (string.IsNullOrWhiteSpace(value)) { return; } double volume = Convert.ToDouble(value); SampleMultiple = ((100 - volume) / 100).ToString("F3"); } #endregion public ModeSettingViewModel(IEventAggregator ea, IMainService service) { _ea = ea; _service = service; } } }