/// <summary> /// 注销帐号 /// </summary> /// <param name="nAccountId"></param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public bool CancelAccount(long nAccountId, long nOpStaffId, string strOpStaffName, out string strErrText) { try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (AuthenticateDAO dao = new AuthenticateDAO()) { Account data = dao.LoadAccount(nAccountId, nOpStaffId, strOpStaffName, out strErrText); if (data == null) { return(false); } data.IsCancel = true; if (!dao.UpdateAccount(data, nOpStaffId, strOpStaffName, out strErrText)) { return(false); } } transScope.Complete(); } return(true); } catch (Exception e) { strErrText = e.Message; return(false); } }
/// <summary> /// 初始化帐号密码 /// </summary> /// <param name="nAccountId">帐号编码</param> /// <param name="strNewPassword">新密码</param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public bool ResetPassword(long nAccountId, string strNewPassword, long nOpStaffId, string strOpStaffName, out string strErrText) { try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (AuthenticateDAO dao = new AuthenticateDAO()) { //读取登录帐号数据 Account data = dao.LoadAccount(nAccountId, nOpStaffId, strOpStaffName, out strErrText); if (data == null) { return(false); } //生成登录密码MD5码 data.Password = Utils.GetMD5Hash(data.Name + "@" + strNewPassword); if (!dao.UpdateAccount(data, nOpStaffId, strOpStaffName, out strErrText)) { return(false); } } transScope.Complete(); } strErrText = String.Empty; return(true); } catch (Exception e) { strErrText = e.Message; return(false); } }
/// <summary> /// 修改帐号密码 /// </summary> /// <param name="strOldPassword">原密码</param> /// <param name="strNewPassword">新密码</param> /// <param name="nOpStaffId">操作员工编码</param> /// <param name="strOpStaffName">操作员工姓名</param> /// <param name="strErrText">出错信息</param> /// <returns>成功返回True,否则返回False</returns> public bool UpdatePassword(string strOldPassword, string strNewPassword, long nOpStaffId, string strOpStaffName, out string strErrText) { try { using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (AuthenticateDAO dao = new AuthenticateDAO()) { //读取登录帐号数据 Account data = dao.LoadAccount(nOpStaffId, nOpStaffId, strOpStaffName, out strErrText); if (data == null) { return(false); } //生成登录密码MD5码 string strHash = Utils.GetMD5Hash(data.Name + "@" + strOldPassword); StringComparer comparer = StringComparer.OrdinalIgnoreCase; if (comparer.Compare(strHash, data.Password) == 0) { data.Password = Utils.GetMD5Hash(data.Name + "@" + strNewPassword); if (!dao.UpdateAccount(data, nOpStaffId, strOpStaffName, out strErrText)) { return(false); } } else { strErrText = InnoSoft.LS.Resources.Strings.OldPasswordIsIncorrect; return(false); } } transScope.Complete(); } strErrText = String.Empty; return(true); } catch (Exception e) { strErrText = e.Message; return(false); } }
/// <summary> /// 读取指定帐号数据 /// </summary> /// <param name="nId"></param> /// <param name="nOpStaffId"></param> /// <param name="strOpStaffName"></param> /// <param name="strErrText"></param> /// <returns></returns> public Account LoadAccount(long nId, long nOpStaffId, string strOpStaffName, out string strErrText) { try { Account dataResult = null; strErrText = String.Empty; using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0))) { using (AuthenticateDAO dao = new AuthenticateDAO()) { dataResult = dao.LoadAccount(nId, nOpStaffId, strOpStaffName, out strErrText); } transScope.Complete(); } return(dataResult); } catch (Exception e) { strErrText = e.Message; return(null); } }