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.Data.OleDb;
using System.Text;
public partial class BackCenter_User_UpdatePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 过期和权限

        PageFunc.IfLogin(this.Page);
        //PubPageFunc.PageHavePurview(this.Page, "2001");

        #endregion

    }

    //保存事件
    protected void btnSave_Click(object sender, EventArgs e)
    {
        #region 新密码确认
        if (txt_checknewPassword.Text.Trim().Equals(txt_newPassword.Text.Trim()) == false)
        {
            JavaScriptFunc.Alert(this.Page, "确认新密码不一致");
            return;
        }
        #endregion

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

        #region 操作数据库-判断原密码是否错误并修改密码
        string sql = "select count(*) from NT_User ";
        sql += "where [Account]='" + str_Account + "' ";
        sql += "and [Password]='" + PageFunc.GetMd5(this.txt_Password.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_User set");
            SqlUpdate.Append(" [Password]='" + PageFunc.GetMd5(this.txt_newPassword.Text.Trim()) + "'");
            SqlUpdate.Append(" where [Account]='" + str_Account + "'");
            DbHelperOleDb.ExecuteNonQuery(CommandType.Text, SqlUpdate.ToString(), null);

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

}
