using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class system_password : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

        PageFunc.IfSystemLogin(this.Page);

        #endregion
        if (IsPostBack)
            return;
    }
    //修改密码
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txt_OldPwd.Text.Trim() == "" || txt_NewPwd1.Text.Trim() == "" || txt_NewPwd2.Text.Trim() == "")
        {
            JavaScriptFunc.Alert(this.Page, "不能为空");
            return;
        }

        #region 新密码确认
        if (txt_NewPwd1.Text.Trim().Equals(txt_NewPwd2.Text.Trim()) == false)
        {
            JavaScriptFunc.Alert(this.Page, "确认新密码不一致");
            return;
        }
        #endregion

        //取session
        string str_Account = Session["Account1"].ToString();//用户名

        #region 操作数据库-判断原密码是否错误并修改密码
        string sql = "select count(*) from NT_Member ";
        sql += "where [Account]='" + str_Account + "' ";
        sql += "and [Password]='" + PageFunc.GetMd5(this.txt_OldPwd.Text.Trim()) + "'";
        object count = DbHelperOleDb.ExecuteScalar(CommandType.Text, sql, null);
        if (count.ToString() == "0")
        {
            JavaScriptFunc.Alert(this.Page, "原密码错误");
            return;
        }
        else
        {
            #region 密码修改memberAccount
            StringBuilder SqlUpdate = new StringBuilder();
            SqlUpdate.Append("update NT_Member set");
            SqlUpdate.Append(" [Password]='" + PageFunc.GetMd5(this.txt_NewPwd1.Text.Trim()) + "'");
            SqlUpdate.Append(" where [Account]='" + str_Account + "'");
            DbHelperOleDb.ExecuteNonQuery(CommandType.Text, SqlUpdate.ToString(), null);

            JavaScriptFunc.Alert(this.Page, "修改成功");
            #endregion
        }
        #endregion
    }
}
