|
|
|
|
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;
|
|
|
|
|
MainModel = parameters.GetValue<VpnInfo>("model");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private VpnInfo _mainModel = new VpnInfo();
|
|
|
|
|
public VpnInfo MainModel
|
|
|
|
|
{
|
|
|
|
|
get => _mainModel;
|
|
|
|
|
set { SetProperty(ref _mainModel, value); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DelegateCommand FilePathSaveCommand=> new(()=>
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
public ICommand ConfirmCommand
|
|
|
|
|
{
|
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
|
|
|
|
// 确认操作
|
|
|
|
|
// 数据校验(关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查(自定义特性检查)
|
|
|
|
|
if (string.IsNullOrEmpty(MainModel.VpnName) || string.IsNullOrEmpty(MainModel.VpnIP))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("内容不能为空", "提示", System.Windows.MessageBoxButton.OK);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel,
|
|
|
|
|
MessageBoxImage.Exclamation) == MessageBoxResult.OK)
|
|
|
|
|
{
|
|
|
|
|
//if (updateSysConfig)
|
|
|
|
|
//{
|
|
|
|
|
// JsonParser.WriteSystemConfigFile(fm.systemConfigPath, fsc);
|
|
|
|
|
//}
|
|
|
|
|
//if (updateJson)
|
|
|
|
|
//{
|
|
|
|
|
// JsonParser.UpdateRecvJson(fm.sc.proRecv.ProPath + fm.sc.proRecv.JsonPath, fm.sc.DataSavePath);
|
|
|
|
|
// JsonParser.UpdateApmsJson(fm.sc.proApms.ProPath + fm.sc.proApms.JsonPath, fm.sc.DataSavePath);
|
|
|
|
|
//}
|
|
|
|
|
//var device = _deviceInfoModel.deviceInfoModelList.Where(device => device.Index == MainModel.Index).FirstOrDefault();
|
|
|
|
|
//if (device != null)
|
|
|
|
|
//{
|
|
|
|
|
// _deviceInfoModel.deviceInfoModelList.Remove(device);
|
|
|
|
|
// _deviceInfoModel.deviceInfoModelList.Add(MainModel);
|
|
|
|
|
|
|
|
|
|
// _deviceInfoModel.Save();
|
|
|
|
|
//}
|
|
|
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public ICommand CancelCommand
|
|
|
|
|
{
|
|
|
|
|
get => new DelegateCommand(() =>
|
|
|
|
|
{
|
|
|
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|