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_Home_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //登录
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string str_Account = StringFunc.DataFilter(this.txt_Account.Text.Trim());
        string str_Password = StringFunc.DataFilter(PageFunc.GetMd5(this.txt_Password.Text.Trim()));

        #region 操作数据库
        //SQL语句-判断是否有该管理员
        string str_sql = string.Empty;
        str_sql += " select [ID],[Account],[Password],[RealName],[RoleId],[DepartmentId],";
        str_sql += " (select top 1 Name from NT_Role where [RoleId]=NT_Role.ID) as RoleName,";
        str_sql += " (select top 1 Name from NT_Department where [DepartmentId]=NT_Department.ID) as DepartmentName,";
        str_sql += " [CreateUserId] ";
        str_sql += " from NT_User";
        str_sql += " where 1=1";
        str_sql += " and Account='" + str_Account + "'";
        str_sql += " and Password='" + str_Password + "'";

        OleDbDataReader sdr = DbHelperOleDb.ExecuteDataReader(CommandType.Text, str_sql, null);
        if (sdr.HasRows)
        {
            while (sdr.Read())
            {
                //Account
                Session["ID"] = sdr["ID"].ToString();
                Session["Account"] = sdr["Account"].ToString();
                Session["RoleId"] = sdr["RoleId"].ToString();
                Session["RoleName"] = sdr["RoleName"].ToString();
                Session["DepartmentId"] = sdr["DepartmentId"].ToString();
                Session["DepartmentName"] = sdr["DepartmentName"].ToString();
                //权限字符串
                //Session["purviewCodes"] = getPurviews(sdr["roleIDs"].ToString());

            }
            sdr.Close();


            //登陆成功跳转至Default.aspx
            JavaScriptFunc.Redirect("Index.aspx");
        }
        else
        {
            sdr.Close();
            //登陆失败
            JavaScriptFunc.Alert(this.Page, "没有该管理员");
        }
        #endregion
    }
}
