You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.0 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Txgy.EWS.Client.Entity;
using Txgy.EWS.Client.IBLL;
using Txgy.EWS.Client.Models;
namespace BaseModule.ViewModels
{
public class AddUserDialogViewModel : BindableBase, IDialogAware
{
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;
this.RaisePropertyChanged("Title");
// 编辑状态
// 当编辑状态用户Name不可以修改在新增的时候是可以输入的
if (_type == 1)
{
IsReadOnlyUserName = true;
MainModel = parameters.GetValue<UserInfoModel>("model");
}
}
private UserInfoModel _mainModel = new UserInfoModel();
public UserInfoModel MainModel
{
get => _mainModel;
set { SetProperty<UserInfoModel>(ref _mainModel, value); }
}
private bool _isReadOnlyUserName = false;
public bool IsReadOnlyUserName
{
get => _isReadOnlyUserName;
set { SetProperty<bool>(ref _isReadOnlyUserName, value); }
}
public ICommand ConfirmCommand
{
get => new DelegateCommand(() =>
{
// 确认操作
// 数据校验关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查自定义特性检查
// 校验通过
// 保存数据到数据库 新增和修改
_userBLL.SaveUser(new UserEntity
{
UserId = MainModel.UserId,
UserName = MainModel.UserName,
RealName = MainModel.RealName,
UserIcon = MainModel.UserIcon?.Replace(System.Configuration.ConfigurationManager.AppSettings["CadSettingsFileName"].ToString(), ""),
Password = MainModel.Password,
Age = MainModel.Age
});
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
});
}
public ICommand CancelCommand
{
get => new DelegateCommand(() =>
{
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
});
}
IUserBLL _userBLL;
public AddUserDialogViewModel(IUserBLL userBLL)
{
_userBLL = userBLL;
}
}
}