Files
ADP/TestingModule/ViewModels/ParametersManagerViewModel.cs
2026-06-05 10:57:09 +08:00

166 lines
4.9 KiB
C#

using UIShare.UIViewModel;
using UIShare.GlobalVariable;
using UIShare.PubEvent;
using Logger;
using MaterialDesignThemes.Wpf;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Xml;
using UIShare.ViewModelBase;
using Prism.Events;
namespace TestingModule.ViewModels
{
public class ParametersManagerViewModel:NavigateViewModelBase
{
#region
//private ObservableCollection<DeviceConfigModel> _DeviceList;
//public ObservableCollection<DeviceConfigModel> DeviceList
//{
// get { return _DeviceList; }
// set { SetProperty(ref _DeviceList,value); }
//}
private ObservableCollection<DeviceInfoModel> _DeviceInfoModel;
public ObservableCollection<DeviceInfoModel> DeviceInfoModel
{
get { return _DeviceInfoModel; }
set { SetProperty(ref _DeviceInfoModel, value); }
}
public ProgramModel Program
{
get => _ScopedContext.Program;
set
{
if (_ScopedContext.Program != value)
{
_ScopedContext.Program = value;
RaisePropertyChanged();
}
}
}
private ParameterModel _SelectedParameter;
public ParameterModel SelectedParameter
{
get => _SelectedParameter;
set
{
if (SetProperty(ref _SelectedParameter, value))
{
_ScopedContext.SelectedParameter = value;
}
}
}
private DeviceInfoModel _SelectedDevice;
public DeviceInfoModel SelectedDevice
{
get { return _SelectedDevice; }
set { SetProperty(ref _SelectedDevice, value); }
}
#endregion
private ScopedContext _ScopedContext { get; set; }
private readonly SystemConfig _systemConfig;
private readonly GlobalInfo _globalInfo;
#region
public ICommand ParameterAddCommand { get; set; }
public ICommand ParameterEditCommand { get; set; }
public ICommand ParameterDeleteCommand { get; set; }
public ICommand DeviceEditCommand { get; set; }
public ICommand ReconnnectCommand { get; set; }
public ICommand CloseCommand { get; set; }
#endregion
public ParametersManagerViewModel(IContainerProvider containerProvider, ScopedContext scopedContext, SystemConfig systemConfig, GlobalInfo globalInfo) : base(containerProvider)
{
_ScopedContext = scopedContext;
_systemConfig = systemConfig;
_globalInfo = globalInfo;
Program = _ScopedContext.Program;
ParameterAddCommand = new DelegateCommand(ParameterAdd);
ParameterEditCommand = new DelegateCommand(ParameterEdit);
ParameterDeleteCommand = new DelegateCommand(ParameterDelete);
DeviceEditCommand = new DelegateCommand(DeviceEdit);
}
#region
private void DeviceEdit()
{
if (!_globalInfo.IsAdmin) return;
if (SelectedDevice==null)
{
return;
}
var type = SelectedDevice.DeviceType.Split('.').Last();
if(type=="E36233A"|| type == "IT6724CReverse")
{
_dialogService.Show("Backfeed");
}
else
{
_dialogService.Show(type);
}
}
private void ParameterDelete()
{
if (!_globalInfo.IsAdmin) return;
Program.Parameters.Remove(SelectedParameter);
}
private void ParameterEdit()
{
if (!_globalInfo.IsAdmin) return;
var param = new DialogParameters
{
{ "Mode",SelectedParameter==null?"ADD":"Edit" },
{ "ScopedContext",_ScopedContext }
};
_dialogService.ShowDialog("ParameterSetting", param, (r) =>
{
if (r.Result == ButtonResult.OK)
{
_eventAggregator.GetEvent<ParamsChangedEvent>().Publish();
}
else
{
}
});
}
private void ParameterAdd()
{
if (!_globalInfo.IsAdmin) return;
var param = new DialogParameters
{
{ "Mode", "ADD" },
{ "ScopedContext",_ScopedContext }
};
_dialogService.ShowDialog("ParameterSetting", param, (r) =>
{
if (r.Result == ButtonResult.OK)
{
_eventAggregator.GetEvent<ParamsChangedEvent>().Publish();
}
else
{
}
});
}
#endregion
}
}