|
|
using Prism.Commands;
|
|
|
using Prism.Mvvm;
|
|
|
using Prism.Services.Dialogs;
|
|
|
using StartServerWPF.Modules.Main.Model;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
namespace StartServerWPF.Modules.Main.ViewModels
|
|
|
{
|
|
|
public class SetParamDialogViewModel : BindableBase, IDialogAware
|
|
|
{
|
|
|
public SetParamDialogViewModel()
|
|
|
{
|
|
|
}
|
|
|
private string _title = "参数设置";
|
|
|
public string Title => _title;
|
|
|
|
|
|
public event Action<IDialogResult> RequestClose;
|
|
|
|
|
|
public bool CanCloseDialog()
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public void OnDialogClosed() { }
|
|
|
|
|
|
public void OnDialogOpened(IDialogParameters parameters)
|
|
|
{
|
|
|
// _title = "编辑" + _title;
|
|
|
var _type = parameters.GetValue<int>("type");
|
|
|
// _title = (_type == 0 ? "新增" : "修改") + _title;
|
|
|
_systemConfig = parameters.GetValue<SystemConfig>("model");
|
|
|
MainModel= _systemConfig.vpnInfo;
|
|
|
MoniTime= parameters.GetValue<DateTime>("moniTime");
|
|
|
}
|
|
|
|
|
|
private SystemConfig _systemConfig;
|
|
|
private VpnInfo _mainModel = new VpnInfo();
|
|
|
public VpnInfo MainModel
|
|
|
{
|
|
|
get => _mainModel;
|
|
|
set { SetProperty(ref _mainModel, value); }
|
|
|
}
|
|
|
private DateTime _moniTime ;
|
|
|
public DateTime MoniTime
|
|
|
{
|
|
|
get => _moniTime;
|
|
|
set { SetProperty(ref _moniTime, value); }
|
|
|
}
|
|
|
|
|
|
public DelegateCommand FilePathSaveCommand=> new(()=>
|
|
|
{
|
|
|
updateJson = false;
|
|
|
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
fbd.SelectedPath = MainModel.DataSavePath;
|
|
|
fbd.ShowNewFolderButton = true;
|
|
|
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
{
|
|
|
MainModel.DataSavePath = fbd.SelectedPath;
|
|
|
if (MainModel.DataSavePath != _systemConfig.vpnInfo.DataSavePath)
|
|
|
{
|
|
|
updateJson = true;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
public DelegateCommand LogPathSaveCommand=> new(() =>
|
|
|
{
|
|
|
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
|
|
|
fbd.SelectedPath = System.Environment.CurrentDirectory + "\\" + MainModel.SystemLogPath;
|
|
|
fbd.ShowNewFolderButton = true;
|
|
|
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
{
|
|
|
//if (fbd.SelectedPath != textBoxLogPath.Text)
|
|
|
//{
|
|
|
// textBoxLogPath.Text = fbd.SelectedPath;
|
|
|
//}
|
|
|
MainModel.SystemLogPath = fbd.SelectedPath;
|
|
|
}
|
|
|
});
|
|
|
bool updateJson = false;
|
|
|
public ICommand ConfirmCommand
|
|
|
{
|
|
|
get => new DelegateCommand(() =>
|
|
|
{
|
|
|
// 确认操作
|
|
|
// 数据校验(关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查(自定义特性检查)
|
|
|
if (string.IsNullOrEmpty(MainModel.VpnName) || string.IsNullOrEmpty(MainModel.VpnIP))
|
|
|
{
|
|
|
MessageBox.Show("内容不能为空", "提示", MessageBoxButton.OK);
|
|
|
return;
|
|
|
}
|
|
|
if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel,
|
|
|
MessageBoxImage.Exclamation) == MessageBoxResult.OK)
|
|
|
{
|
|
|
|
|
|
|
|
|
JsonParser.WriteSystemConfigFile(JsonParser.systemConfigPath, _systemConfig);
|
|
|
if (updateJson)
|
|
|
{
|
|
|
JsonParser.UpdateRecvJson(_systemConfig.proRecv.ProPath + _systemConfig.proRecv.JsonPath, _systemConfig.vpnInfo.DataSavePath);
|
|
|
JsonParser.UpdateApmsJson(_systemConfig.proApms.ProPath + _systemConfig.proApms.JsonPath, _systemConfig.vpnInfo.DataSavePath);
|
|
|
}
|
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
public ICommand CancelCommand
|
|
|
{
|
|
|
get => new DelegateCommand(() =>
|
|
|
{
|
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|