Exemplo n.º 1
0
    protected void btn_Login_Click(object sender, ImageClickEventArgs e)
    {
        if (txt_UserName.Text.Trim() != "user")
        {
            if (SSOHelper.CheckOnline(txt_UserName.Text.Trim()))
            {
                string   strSql = "select DepartID,UserID,t_R_UserInfo.RoleID,PWDModifyTime,Name,LevelID,ReadRight,WriteRight,RefreshRight,FileRight,id,ManageRight,dataflag from t_R_UserInfo inner join t_R_Role on t_R_Role.RoleID=t_R_UserInfo.RoleID where  t_R_UserInfo.flag=0 and UserID='" + txt_UserName.Text.Trim() + "' and PWD='" + txt_Pwd.Text.Trim() + "'";
                MyDataOp mdo    = new MyDataOp(strSql);
                DataSet  ds     = mdo.CreateDataSet();

                if (ds.Tables[0].Rows.Count == 0)
                {
                    Response.Write("<script language='javascript'>alert('帐户或密码输入错误!请重新输入!');</script>");
                }
                else
                {
                    HttpCookie Cookie = new HttpCookie("Cookies");

                    DateTime dt = DateTime.Now;
                    TimeSpan ts = new TimeSpan(0, 10, 0, 0); //有效期10小时;
                    Cookie.Expires = dt.Add(ts);
                    Cookie.Values.Add("uid", ds.Tables[0].Rows[0]["id"].ToString());
                    Cookie.Values.Add("u_id", ds.Tables[0].Rows[0]["UserID"].ToString());
                    Cookie.Values.Add("u_role", ds.Tables[0].Rows[0]["RoleID"].ToString());
                    Cookie.Values.Add("u_flag", ds.Tables[0].Rows[0]["dataflag"].ToString());
                    Cookie.Values.Add("u_pswdtime", ds.Tables[0].Rows[0]["PWDModifyTime"].ToString());
                    Cookie.Values.Add("Name", HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["Name"].ToString()));
                    //Cookie.Values.Add("u_Name",ds.Tables[0].Rows[0]["Name"].ToString());//用户名
                    // Cookie.Values.Add("RealName", HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["RealName"].ToString()));

                    Cookie.Values.Add("u_level", ds.Tables[0].Rows[0]["LevelID"].ToString());
                    Cookie.Values.Add("u_purview", ds.Tables[0].Rows[0]["ReadRight"].ToString() + //读权限
                                      ds.Tables[0].Rows[0]["WriteRight"].ToString() +             //写权限
                                      ds.Tables[0].Rows[0]["ManageRight"].ToString() +
                                      ds.Tables[0].Rows[0]["FileRight"].ToString());              //刷新权限;
                    Cookie.Values.Add("departid", ds.Tables[0].Rows[0]["DepartID"].ToString());
                    Response.AppendCookie(Cookie);
                    SSOHelper sso = new SSOHelper();
                    sso.LoginRegister(txt_UserName.Text.Trim());

                    Response.Redirect("~/main.htm");
                }
            }
            else
            {
                Response.Write("<script language='javascript'>alert('您的帐户已在别处登陆!');</script>");
            }
        }
    }