/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_SYS_0209.cs
* 2.功能描述:修改密码页面
* 编辑履历:
* 作者 日期 版本 修改内容
* 张国印 2014/08/27 1.00 新建
*******************************************************************************/
using System;
using System.Reflection;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client
{
///
/// 修改密码页面
///
public partial class F_SYS_0210 : FormBase
{
#region 成员变量
// 窗体的单例模式
private static F_SYS_0210 _instance;
#endregion
#region 构造函数
///
/// 构造函数
///
private F_SYS_0210()
{
InitializeComponent();
this.SetFromTitleInfo();
}
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_SYS_0210 Instance
{
get
{
if (_instance == null)
{
_instance = new F_SYS_0210();
}
return _instance;
}
}
#endregion
#region 事件处理
///
/// 窗体加载事件
///
///
///
private void F_SYS_0209_Load(object sender, EventArgs e)
{
try
{
FormPermissionManager.FormPermissionControl(this.Name, this,
LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 保存按钮
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (this.CheckPassWord())
{
string userCode = LogInUserInfo.CurrentUser.CurrentUserEntity.UserCode;
string userName = LogInUserInfo.CurrentUser.CurrentUserEntity.UserName;
string passWord = this.txtPassword.Text.Trim();
string returenPassWord = (string)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.SaveUserPassWord(passWord, userCode, userName);
}));
// 修改成功
if (!string.IsNullOrEmpty(returenPassWord))
{
LogInUserInfo.CurrentUser.SetUserInfoPassWord(returenPassWord);
ProxySettings.LoginUserInfo.Password = returenPassWord;
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "密码", "修改"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "密码", "修改"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 取消按钮
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 关闭窗体
///
///
///
private void F_SYS_0209_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
#endregion
#region 私有方法
///
/// 设置窗体按钮的文本信息
///
private void SetFromTitleInfo()
{
// 窗口标题
this.Text = FormTitles.F_SYS_0210;
// 设置窗口按钮文本
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CANCEL;
}
///
/// 验证密码
///
///
private bool CheckPassWord()
{
string strPassword = this.txtPassword.Text.Trim();
string strPasswordCheck = this.txtPasswordCheck.Text.Trim();
string strOldPassword = this.txtOldPassword.Text.Trim();
// 判断原密码是否为空,如果为空提示
if (string.IsNullOrEmpty(strOldPassword))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "原密码"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtOldPassword.Focus();
return false;
}
// 判断原密码是否正确,不正确给提示
if (!LogInUserInfo.CurrentUser.CurrentUserEntity.Password.ToUpper().Equals(Encryption.GetMD5String(strOldPassword)))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W003, "原密码"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtOldPassword.Clear();
this.txtOldPassword.Focus();
return false;
}
// 判断新密码是否为空,如果为空提示
if (string.IsNullOrEmpty(strPassword))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "新密码"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtPassword.Focus();
return false;
}
// 判断确认密码是否为空,如果为空提示
if (string.IsNullOrEmpty(strPasswordCheck))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "确认密码"), this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtPasswordCheck.Focus();
return false;
}
// 判断两次输入的密码是否一致,不一致提示
if (!strPasswordCheck.Equals(strPassword))
{
MessageBox.Show(Messages.MSG_SYS_W021, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtPassword.Clear();
this.txtPasswordCheck.Clear();
this.txtPassword.Focus();
return false;
}
return true;
}
#endregion
}
}