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

namespace HySoft.BaseCallCenter.Web.sysmanage
{
    public partial class userResetPasswod : System.Web.UI.Page
    {
        string resetPassId = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                resetPassId = Request.QueryString["ResetPass"];
                initistration(resetPassId);//初始化方法
            }
        }
        #region
        /// <summary>
        /// 初始化重新设置密码的信息
        /// </summary>
        /// <param name="resetPassWord"></param>
        public void initistration(string resetPassWord)
        {
            string sql = "";
            string userId = HySoft.Common.CookieUtil.GetCookie("BaseCallCenter_T_User", "F_UserID");
            if (!string.IsNullOrEmpty(resetPassWord))
            {
                sql = "select * from t_sys_userAccount where F_UserId ='" + resetPassWord + "'";
            }
            else
            {
                sql = "select * from t_sys_userAccount where F_UserId ='" + userId + "'";
            }
            DataTable dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                txtWorkingCode.Text = dt.Rows[0]["F_UserCode"].ToString();
                txtRealName.Text = dt.Rows[0]["F_UserName"].ToString();
            }
        }
        #endregion

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = "";
                string sqlstr = "";
                int reslust = 0;
                if (!string.IsNullOrEmpty(txtone_password.Text))
                {
                    string userId = HySoft.Common.CookieUtil.GetCookie("BaseCallCenter_T_User", "F_UserID");
                    //根据用户id和原密码确定用户是否存在
                    if (!string.IsNullOrEmpty(Request.QueryString["ResetPass"]))
                    {
                        sqlstr = "select * from t_sys_userAccount where F_Password='" + txtone_password.Text + "' and F_UserId='" + Request.QueryString["ResetPass"] + "'";
                    }
                    else
                    {
                        sqlstr = "select * from t_sys_userAccount where F_Password='" + txtone_password.Text + "' and F_UserId='" + userId + "'";
                    }
                    DataTable dt = DBUtility.DbHelperSQL.Query(sqlstr).Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(Request.QueryString["ResetPass"]))
                        {
                            sql = "update t_sys_userAccount set F_Password='" + txtone_passwodnew.Text + "' where F_UserId ='" + Request.QueryString["ResetPass"] + "'";
                        }
                        else
                        {
                            sql = "update t_sys_userAccount set F_Password='" + txtone_passwodnew.Text + "' where  F_UserId='" + userId + "'";
                        }

                        reslust = DBUtility.DbHelperSQL.ExecuteSql(sql);
                        if (reslust > 0)
                        {
                            MessageBoxToWindow("重设密码成功", "提示！", "success");
                        }
                        else
                        {
                            MessageBoxToWindow("重设密码失败", "提示！", "error");
                        }
                    }
                    else
                    {
                        MessageBoxToWindow("没有找到输入原密码的人员", "提示！", "error");
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }


        #region 弹出对话框
        /// <summary>
        /// 弹出对话框
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="type"></param>
        public void MessageBoxToWindow(string title, string content, string type)
        {
            string script = "";
            switch (type)
            {
                case "error"://失败
                    type = "error";
                    script = "<script type='text/javascript'>  $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
                    break;
                case "success"://成功
                    type = "info";
                    script = "<script type='text/javascript'> $.ligerDialog.alert('" + title + "','" + content + "','" + type + "',CloseThis);</script>";
                    break;
                case "catch"://异常
                    type = "warning";
                    script = "<script type='text/javascript'>  $.ligerDialog.alert('" + title + "','" + content + "','" + type + "');</script>";
                    break;
                default:
                    type = "question";
                    break;
            }
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", script);
        }
        #endregion
    }
}