架构B/S四 WEB 表示层 EditPassword.aspx.cs 页

来源:互联网 发布:表白扣字软件 编辑:程序博客网 时间:2024/06/06 02:33

2008-04-10 10:55

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CoalTraffic.Common;
using CoalTraffic.DBUtility;

public partial class UserManage_EditPassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string strError = string.Empty;
        //原始密码
        if (txtYsPassword.Text == "")
        {
            strError += "原始密码不能为空!//n";
        }
        else
        {
            if ((PageValidate.IsLengther(txtPassword.Text, 16)) || (PageValidate.IsShorter(txtPassword.Text, 4)))
            {
                strError += "用户密码为4-16位的数字或英文字母!//n";
            }
        }
        //新密码
        if (txtPassword.Text == "")
        {
            strError += "用户密码不能为空!//n";
        }
        else
        {
            if ((PageValidate.IsLengther(txtPassword.Text, 16)) || (PageValidate.IsShorter(txtPassword.Text, 4)))
            {
                strError += "用户密码为4-16位的数字或英文字母!//n";
            }
        }
        //确认密码
        if (txtRePassword.Text == "")
        {
            strError += "确认密码不能为空!//n";
        }
        else
        {
            if (String.Compare(txtPassword.Text, txtRePassword.Text) != 0)
            {
                strError += "确认密码必须与密码完全一致!//n";
            }
        }
        CoalTraffic.BLL.T_User userBLL = new CoalTraffic.BLL.T_User();
        CoalTraffic.Model.T_User userModel = new CoalTraffic.Model.T_User();

        userModel = userBLL.GetModel(System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["UserCode"].Value));
        hfUserCode.Value = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["UserCode"].Value);
        hfPasswd.Value = userModel.Passwd;
        if (userModel == null)
        {
            MessageBox.Show(this.Page, "该用户不存在!");           
            return;
        }
        else
        {
            if (strError == string.Empty)
            {
                if (userModel.Passwd != Crypt.MD5hash(txtYsPassword.Text).ToString())
                {
                    MessageBox.Show(this.Page, "密码错误!");
                    return;
                }
                else
                {
                    userModel.UserCode = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["UserCode"].Value);
                    userModel.Passwd = Crypt.MD5hash(txtPassword.Text).ToString();

                    if (userBLL.UpdatePW(userModel))
                    {
                        CoalTraffic.BLL.TDY_LogEditDate bllDate = new CoalTraffic.BLL.TDY_LogEditDate();
                        CoalTraffic.Model.TDY_LogEditDate modelDate = new CoalTraffic.Model.TDY_LogEditDate();
                        modelDate.EditType = "修改";
                        modelDate.DataCode = hfUserCode.Value;
                        modelDate.Operator = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["UserCode"].Value);
                        modelDate.WorkDataTable = "用户密码表";
                        modelDate.WorkTime = System.DateTime.Now;
                        int iResult = bllDate.Add(modelDate);
                        MessageBox.ShowAndRedirect(this.Page, "用户密码修改成功!", "ListUserEdit.aspx");
                    }
                    else
                    {
                        MessageBox.Show(this.Page, "用户密码修改失败!");
                    }
                }
            }
            else
            {
                MessageBox.Show(this.Page, strError);
            }
        }
    }
    ///


    /// 清空TextBox
    ///

    ///
    ///
    protected void btnCancel_Click(object sender, EventArgs e)
    {       
        txtYsPassword.Text = "";
        txtPassword.Text = "";
        txtRePassword.Text = "";
    }
}

原创粉丝点击