using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.ComponentModel; using System.Windows.Input; using System.Windows.Documents; using System.Threading; using System.Diagnostics; using System.Collections.ObjectModel; using System.IO; using GummingCommon; using System.Reflection; using GummingEntity; using GummingBusiness; namespace Gumming { public class PasswordEditViewModule : ViewModelBase { #region base parameters public PasswordEditView View { get; set; } public bool IsConfirm { get; set; } #endregion #region constructor public PasswordEditViewModule(bool canCreateNewTargetField = true) { View = new PasswordEditView(); View.DataContext = this; InitializeCommands(); InitializeParameters(); LoadDefaultValue(); } public void ShowDialog() { IsConfirm = false; View.ShowDialog(); } private void InitializeCommands() { CancelCommand = new DelegateCommand(OnCancelCommand); SaveCommand = new DelegateCommand(OnSaveCommand); ClearCommand = new DelegateCommand(OnClearCommand); } public override void InitializeParameters(object content = null) { WindowTitle = ""; } ~PasswordEditViewModule() { } public void LoadDefaultValue() { } #endregion #region Binding Properties public string WindowTitle { get; private set; } public string UserId { get; set; } public string RoleId { get; set; } public string UserName { get; set; } private string _PasswordText; public string PasswordText { get { return _PasswordText; } set { _PasswordText = value; OnPropertyChanged("PasswordText"); } } private string _PasswordText2; public string PasswordText2 { get { return _PasswordText2; } set { _PasswordText2 = value; OnPropertyChanged("PasswordText2"); } } #endregion #region Binding Commands private ICommand _CancelCommand; public ICommand CancelCommand { get { return _CancelCommand; } set { _CancelCommand = value; OnPropertyChanged("CancelCommand"); } } private ICommand _SaveCommand; public ICommand SaveCommand { get { return _SaveCommand; } set { _SaveCommand = value; OnPropertyChanged("SaveCommand"); } } private ICommand _ClearCommand; public ICommand ClearCommand { get { return _ClearCommand; } set { _ClearCommand = value; OnPropertyChanged("ClearCommand"); } } #endregion #region Private Methods private void OnCancelCommand(object sender) { View.DialogResult = true; } private void OnSaveCommand(object sender) { if (string.IsNullOrWhiteSpace(UserName)) { ShowErrorBox("用户名不能为空"); return; } if (string.IsNullOrWhiteSpace(PasswordText)) { ShowErrorBox("密码不能为空"); return; } if (PasswordText2 != PasswordText) { ShowErrorBox("两次输入密码不一致"); return; } SysUserEntity user = new SysUserEntity(); user.RecId = UserId; user.UserCode = UserName; user.UserName = UserName; user.RoleId = RoleId; user.Password = Encryption.Encrypt(PasswordText); SysUserDA.Update(user); IsConfirm = true; View.DialogResult = true; } private void OnClearCommand(object sender) { Setting.Save("StyleDlg", "Password", ""); ShowErrorBox("密码已清空"); } #endregion } }