visual studio basic

前端

用户名:<asp:TextBox ID=“txtName” runat=“server”></asp:TextBox>
密码:<asp:TextBox ID=“txtPwd” runat=“server”></asp:TextBox>
<asp:Button ID=“btnOK” runat=“server” Text=“Button” OnClick=“Button1_Click” />
<asp:RadioButtonList ID=“rdiListType” runat=“server” OnSelectedIndexChanged=“RadioButtonList1_SelectedIndexChanged” Height=“16px” Width=“95px”>
asp:ListItem管理员</asp:ListItem> asp:ListItemreader</asp:ListItem>

        </asp:RadioButtonList>

CS

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

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnOK_Click(object sender, EventArgs e)
{
    string userName = txtName.Text;    //用户名
    string pwd = txtPwd.Text;     //密码
    Session["entryType"] = rdiListType.SelectedValue;    //记录登录用户的类型
    string cs = Session["entryType"].ToString();
    string sql;
    if (Session["entryType"] == "reader")   //用户类型为读者,到读者信息表查询指定用户名和密码的记录
    {
        sql = "select count(*) from tb_readerInfo where readerBarCode=@name and  readerPass=@pass ";
    }
    else    //用户类型为管理员,到管理员信息表查询指定用户名和密码的记录
    {
        sql = "select count(*) from tb_user where userName=@name  and  userPwd=@pass ";
    }
    //调用用户名和密码验证函数
    if (checkPwd(sql, userName, pwd))     //验证成功
    {
        Session["userName"] = userName;  //记录登录用户名
        Response.Redirect("index.aspx");   //导航到系统首页
    }
    else    //验证失败
    {
        RegisterStartupScript("", "<script>alert(‘登录失败!’)</script>");   //提示登录失败
    }
}
public static bool checkPwd(string sql, string name, string pass)
{
    SqlConnection con = DATAoperation.createCon();         //创建数据库连接
    con.Open();         //打开数据库连接
    SqlCommand com = new SqlCommand(sql, con);        //创建SqlCommand对象
    com.Parameters.Add(new SqlParameter("name", SqlDbType.VarChar, 50));        //设置参数类型
    com.Parameters["name"].Value = name;        //设置参数值
    com.Parameters.Add(new SqlParameter("pass", SqlDbType.VarChar, 50));       //设置参数类型
    com.Parameters["pass"].Value = pass;        //设置参数值
    //判断验证用户名和密码是否正确,并返回布尔值
    if (Convert.ToInt32(com.ExecuteScalar()) > 0)   //返回指定用户名和密码的记录数大于0,此用户名和密码正确。
    {
        con.Close();
        return true;
    }
    else
    {
        con.Close();
        return false;
    }
}




protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值