根据用户的不同登录不同的页面

在这里插入图片描述

//判断是什么用户  遍历数据库  查询这条数据  如果无数据 输出 密码错误!
if (DropDownList1.SelectedValue == "用户")
        {
    
    
        ///连接数据库查询数据
            string sqlstr;
            sqlstr = "select * from reader  where userName='" + this.txtUserID.Text.Trim() + "'";
            SqlConnection scon = new SqlConnection(SqlHelper.connstring);
            scon.Open();
            SqlDataAdapter myDataAdapter = new SqlDataAdapter(sqlstr, scon);
            DataSet myDataSet = new DataSet();
            myDataAdapter.Fill(myDataSet, "users");
            if (myDataSet.Tables[0].Rows.Count > 0)
            {
    
    
                string strPwd = myDataSet.Tables[0].Rows[0]["userPwd"].ToString();
                string UserName = myDataSet.Tables[0].Rows[0]["userName"].ToString();
                string PowerName = "用户";
                string UserId = myDataSet.Tables[0].Rows[0]["Userid"].ToString();
                scon.Close();

                if (strPwd != txtPwd.Text.Trim())
                {
    
    
                    Alert.AlertAndRedirect("密码错误", "Login.aspx");
                }
                else
                ///根据不同的用户名判断要进入哪个页面
                {
    
    
                    Session["Sysuser"] = UserName;
                    Session["PowerName"] = PowerName;
                    Session["UserId"] = UserId;
                    Session["userName"] = UserName;
                    Response.Redirect("main.aspx?Name=" + UserName + "&Power=" + PowerName);
                }
            }
            else
            {
    
    
                Alert.AlertAndRedirect("账号或密码错误", "Login.aspx");
                scon.Close();
            }

        }
        else
        {
    
    
            string sqlstr;
            sqlstr = "select * from users  where userName='" + this.txtUserID.Text.Trim() + "'";
            SqlConnection scon = new SqlConnection(SqlHelper.connstring);
            ///打开数据库 进行遍历
            scon.Open();
            SqlDataAdapter myDataAdapter = new SqlDataAdapter(sqlstr, scon);
            DataSet myDataSet = new DataSet();
            myDataAdapter.Fill(myDataSet, "users");
            if (myDataSet.Tables[0].Rows.Count > 0)
            {
    
    
                string strPwd = myDataSet.Tables[0].Rows[0]["userPwd"].ToString();
                string UserName = myDataSet.Tables[0].Rows[0]["userName"].ToString();
                string PowerName = myDataSet.Tables[0].Rows[0]["PowerName"].ToString();
                string UserId = myDataSet.Tables[0].Rows[0]["userId"].ToString();
                scon.Close();

                if (strPwd != txtPwd.Text.Trim())
                {
    
    
                    Alert.AlertAndRedirect("密码错误", "Login.aspx");
                }
                else
                ///同理  通过不同的数据  登入不同的页面
                {
    
    
                    Session["Sysuser"] = UserName;
                    Session["PowerName"] = PowerName;
                    Session["UserId"] = UserId;
                    Session["userName"] = UserName;
                    Response.Redirect("main.aspx?Name=" + UserName + "&Power=" + PowerName);
                }
            }
            else
            {
    
    
                Alert.AlertAndRedirect("账号或密码错误", "Login.aspx");
                scon.Close();
            }
        }
    }

///接受页面判断 获取不同的用户名与密码 切换不同的界面

if ( Session["UserId"] == null)
        {
            Alert.AlertAndRedirect("对不起您没有登陆", "Login.aspx");
        }
        else
        {
            Name = Request.QueryString["Name"].ToString() == null ? "" : Request.QueryString["Name"].ToString();

            Power = Request.QueryString["Power"].ToString() == null ? "" : Request.QueryString["Power"].ToString();
            this.txtStf.Text = Name;
        }

猜你喜欢

转载自blog.csdn.net/NYHongHong/article/details/109103397
今日推荐