⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.aspx.vb

📁 利用简单框架结构vb+asp+sql,实现小型考试系统
💻 VB
字号:
Imports System.Data
Imports System.Data.SqlClient
Imports Exam.Module1
Public Class Index
    Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents txtid As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtname As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtpass As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnlogin As System.Web.UI.WebControls.ImageButton
    Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RegularExpressionValidator1 As System.Web.UI.WebControls.RegularExpressionValidator

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        Session("AdminName") = Nothing
        Session("StuName") = Nothing
        If Request("exit") = "yes" Then
            Response.Redirect("Index.aspx")
        End If
    End Sub
    '
    '验证管理员登录(用户名、密码)
    Public Function find(ByVal username As String, ByVal userpass As String)
        strsql = "select name,pass from " & tbl & " Where name='" & username & "' and pass='" & userpass & "'"
        Dim stradp As New SqlDataAdapter(strsql, appconn)
        Dim ds As New DataSet
        stradp.Fill(ds, tbl)
        If ds.Tables(0).Rows.Count > 0 Then
            Session("AdminName") = ds.Tables(0).Rows(0)("name")
            Response.Redirect("admin/ClassIntro.aspx")
        Else
            Response.Write("<script language='javascript'>alert('用户名或者密码错误!');history.go(-1);</script>")
        End If
    End Function
    '
    '验证学生登录(学号、姓名、密码)
    Public Function Find(ByVal id As Integer, ByVal name As String, ByVal pass As String)
        strsql = "select * from student Where studentorder=" & id & "  and studentname='" & name & "' and studentpwd='" & pass & "'"
        Dim stradp As New SqlDataAdapter(strsql, appconn)
        Dim ds As New DataSet
        stradp.Fill(ds, tbl)
        If ds.Tables(0).Rows.Count > 0 Then
            Session("StuName") = ds.Tables(0).Rows(0)("studentname")
            Response.Redirect("Know.aspx")
        Else
            Response.Write("<script language='javascript'>alert('考生用户名或者密码错误!');history.go(-1);</script>")
        End If
    End Function
    '
    '登录按钮
    Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnlogin.Click
        Dim username As String      '姓名
        Dim userpass As String      '密码
        Dim id As String            '学号
        id = txtid.Text
        username = txtname.Text
        userpass = txtpass.Text
        '如果输入学号则验证学生登录
        If txtid.Text <> Nothing Then
            find(CInt(id), username, userpass)
        End If
        find(username, userpass)
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -