using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using UIShare.GlobalVariable; using UIShare.UIViewModel; using UIShare.ViewModelBase; namespace MonitorModule.ViewModels.Dialogs { public class ValueLimitViewModel : DialogViewModelBase { #region 属性 private string _Title = "报警设置"; public string Title { get { return _Title; } set { SetProperty(ref _Title, value); } } private ValueLimitVM _SelectValueLimitVM; public ValueLimitVM SelectValueLimitVM { get => _SelectValueLimitVM; set => SetProperty(ref _SelectValueLimitVM, value); } private ObservableCollection _ValueLimitList; public ObservableCollection ValueLimitList { get => _ValueLimitList; set => SetProperty(ref _ValueLimitList, value); } private ObservableCollection _DeviceSingleList = new(); public ObservableCollection DeviceSingleList { get => _DeviceSingleList; set => SetProperty(ref _DeviceSingleList, value); } private string _SelectCurve; public string SelectCurve { get => _SelectCurve; set => SetProperty(ref _SelectCurve, value); } #endregion #region 命令 public ICommand SaveCommand { get; set; } public ICommand CloseCommand { get; set; } public ICommand SelectSignalCommand { get; set; } public ICommand DeleteCommand { get; set; } #endregion private GlobalInfo _globalInfo { get; set; } private SystemConfig _systemConfig { get; set; } private IScopedProvider _scope { get; set; } public ValueLimitViewModel(IContainerProvider containerProvider) : base(containerProvider) { _globalInfo = containerProvider.Resolve(); _eventAggregator = containerProvider.Resolve(); SaveCommand = new DelegateCommand(OnSave); CloseCommand = new DelegateCommand(OnClose); SelectSignalCommand = new DelegateCommand(SelectSignal); DeleteCommand = new DelegateCommand(Deletel); InitData(); } #region 命令处理 private void Deletel() { if (SelectValueLimitVM == null) { return; } else { ValueLimitList.Remove(SelectValueLimitVM); SelectValueLimitVM = null; } } private void InitData() { //ValueLimitList = new(_systemConfig.ValueLimitList); //foreach (var _PollingRead in _devices.PollingReadDic) //{ // string deviceName = _PollingRead.Key; // PollingRead pollingRead = _PollingRead.Value; // var props = pollingRead.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) // .Where(p => p.PropertyType == typeof(double)); // foreach (var prop in props) // { // DeviceSingleList.Add(deviceName + "." + prop.Name); // } //} //foreach (var Signal in _systemConfig.ConfigurationList) //{ // DeviceSingleList.Add($"{Signal.Channel}/{Signal.MessageName}/{Signal.SignalName}"); //} } private void SelectSignal() { if (ValueLimitList.Where(x => x.SignalName == SelectCurve).Count() > 0) { return; } ValueLimitList.Add(new ValueLimitVM { SignalName = SelectCurve, Upper = 9999, Lower = -9999, UpperExtreme = 9999, LowerExtreme = -9999, }); } private void OnClose() { RequestClose.Invoke(); } private void OnSave() { _systemConfig.ValueLimitList = ValueLimitList; ConfigService.Save(_systemConfig); } #endregion public override void OnDialogOpened(IDialogParameters parameters) { // 1. 优先执行基类的打开逻辑(如果基类有需要初始化的通用事务) base.OnDialogOpened(parameters); // 2. 解析参数 if (parameters != null && parameters.ContainsKey("Scope")) // 修复:Prism 中应使用 ContainsKey { _scope = parameters.GetValue("Scope"); _systemConfig= _scope.Resolve(); } } } }