#region
|
|
using System;
|
using System.Windows.Forms;
|
using CSFrameworkV5.Business;
|
using CSFrameworkV5.Business.BLL_Permission;
|
using CSFrameworkV5.Common;
|
using CSFrameworkV5.Core;
|
using CSFrameworkV5.Core.Common;
|
using CSFrameworkV5.Library.CommonClass;
|
using CSFrameworkV5.Models;
|
|
#endregion
|
|
namespace CSFrameworkV5.Library.PermissionForms
|
{
|
/// <summary>
|
/// 修改密码
|
/// </summary>
|
public partial class frmModifyPwd : frmBaseDialog
|
{
|
private ModifyPwdType _type;
|
private LoginUser _user;
|
|
//私有构造器
|
private frmModifyPwd()
|
{
|
InitializeComponent();
|
}
|
|
private void BindingDataSet()
|
{
|
var data = CommonData.GetSystemDataSet();
|
DataBinder.BindingLookupEditDataSource(txtDataset, data,
|
"DataSetName", "DataSetID");
|
txtDataset.EditValue = _user.DBID;
|
}
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
{
|
Close();
|
}
|
|
private void btnOk_Click(object sender, EventArgs e)
|
{
|
if (txtAccount.Text.Trim() == string.Empty)
|
{
|
Msg.Warning("请输入登录帐号!");
|
txtAccount.Focus();
|
return;
|
}
|
|
if (txtOldPwd.EditValue == null ||
|
txtOldPwd.EditValue.ToStringEx().Trim() == string.Empty)
|
{
|
Msg.Warning("请输入旧密码!");
|
txtOldPwd.Focus();
|
return;
|
}
|
|
//取用户的资料
|
var dt = new bllUser().GetUser(txtAccount.Text);
|
if (dt.Rows.Count > 0)
|
{
|
var pwd = dt.Rows[0][tb_MyUser.Password].ToStringEx();
|
pwd = KeyProvider.Default.Decrypt(pwd);
|
|
//管理员修改用户密码不需要验证旧密码
|
if (Loginer.CurrentUser.IsAdmin())
|
{
|
txtOldPwd.Text = pwd;
|
}
|
else
|
{
|
if (pwd != txtOldPwd.Text.Trim())
|
{
|
Msg.Warning("所输入旧密码不正确!");
|
txtOldPwd.Focus();
|
return;
|
}
|
}
|
}
|
else
|
{
|
Msg.Warning("登录帐号'" + txtAccount.Text + "'不存在!");
|
return;
|
}
|
|
if (txtPwdF.EditValue == null ||
|
txtPwdF.EditValue.ToStringEx().Trim() == string.Empty)
|
{
|
Msg.Warning("请输入新密码!");
|
txtPwdF.Focus();
|
return;
|
}
|
|
if (txtPwdF.Text.Trim().Length < 3)
|
{
|
Msg.Warning("密码长度必须大于2位!");
|
txtPwdF.Focus();
|
return;
|
}
|
|
if (txtPwdS.EditValue == null ||
|
txtPwdS.EditValue.ToStringEx().Trim() == string.Empty)
|
{
|
Msg.Warning("请确认新密码!");
|
txtPwdS.Focus();
|
return;
|
}
|
|
if (txtPwdF.EditValue.ToStringEx() !=
|
txtPwdS.EditValue.ToStringEx())
|
{
|
Msg.Warning("两次新密码不相同!");
|
txtPwdF.Focus();
|
return;
|
}
|
|
if (Msg.AskQuestion("要修改密码?"))
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
|
var pwd1 = KeyProvider.Default.Encrypt(txtOldPwd.Text);
|
var pwd2 = KeyProvider.Default.Encrypt(txtPwdF.Text);
|
|
var success =
|
new bllUser().ModifyPassword(txtAccount.Text, pwd1,
|
pwd2);
|
if (success)
|
{
|
_user.Password = txtPwdF.Text;
|
Msg.ShowInformation("修改成功!");
|
Close();
|
}
|
else
|
{
|
Msg.Warning("修改出错!");
|
}
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
}
|
|
/// <summary>
|
/// 执行窗体.参数:loginInfo为登录对象ss
|
/// </summary>
|
public static void Execute(LoginUser user, ModifyPwdType type,
|
Form owner)
|
{
|
var form = new frmModifyPwd();
|
form.txtAccount.Text = user.Account;
|
form._user = user;
|
form._type = type;
|
form.Owner = owner;
|
form.ShowDialog();
|
}
|
|
private void frmModifyPwd_Activated(object sender, EventArgs e)
|
{
|
if (txtAccount.CanFocus)
|
txtAccount.Focus();
|
else
|
txtOldPwd.Focus();
|
}
|
|
private void frmModifyPwd_KeyDown(object sender, KeyEventArgs e)
|
{
|
if (e.KeyCode == Keys.Enter) SendKeys.Send("{Tab}"); //发送Tab键
|
}
|
|
private void frmModifyPwd_Load(object sender, EventArgs e)
|
{
|
BindingDataSet();
|
|
//此段代码仅用户管理窗体修改密码有效
|
if (ModifyPwdType.UserManage == _type)
|
{
|
if (Loginer.CurrentUser.IsAdmin())
|
{
|
txtOldPwd.Text = "************"; //仅用于显示
|
txtOldPwd.Enabled = false;
|
}
|
|
//普通用户仅修改本人的密码
|
if (false == Loginer.CurrentUser.IsAdmin())
|
//如果已经登录,修改当前用户的密码
|
if (Loginer.CurrentUser.Account != string.Empty)
|
{
|
txtAccount.Text = Loginer.CurrentUser.Account;
|
txtAccount.Enabled = false;
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 修改密码类型
|
/// </summary>
|
public enum ModifyPwdType
|
{
|
/// <summary>
|
/// 登录窗体直接修改密码
|
/// </summary>
|
LoginWindowDirect,
|
|
/// <summary>
|
/// 用户管理窗体修改密码
|
/// </summary>
|
UserManage
|
}
|
}
|