| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- 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<object> _clickSureCommand;
- public DelegateCommand<object> ClickSureCommand => _clickSureCommand ??= new DelegateCommand<object>(ExecuteClickSureCommand);
- private DelegateCommand _modeSelectionChangedCommand;
- public DelegateCommand ModeSelectionChangedCommand => _modeSelectionChangedCommand ??= new DelegateCommand(ExecuteModeSelectionChanged);
- private DelegateCommand<object> _cancelCommand;
- public DelegateCommand<object> CancelCommand => _cancelCommand ??= new DelegateCommand<object>(ExecuteCancel);
- private DelegateCommand _loadingCommand;
- public DelegateCommand LoadingCommand => _loadingCommand ??= new DelegateCommand(ExecuteLoadingCommand);
- private DelegateCommand<string> _sampleVolumeTextChangedCommand;
- public DelegateCommand<string> SampleVolumeTextChangedCommand => _sampleVolumeTextChangedCommand ??= new DelegateCommand<string>(ExecuteSampleVolumeTextChangedCommand);
- #endregion
- #region Execute
- void ExecuteLoadingCommand()
- {
- SampleDetail detail = _service.GetData<SampleDetail>().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<SampleDetail> list = new() { detailArgs };
- _ea.GetEvent<SampleDetailEvent>().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;
- }
- }
- }
|