📄 webform1.aspx.vb
字号:
Imports System.data.SqlClient
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents t1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents t2 As System.Web.UI.WebControls.TextBox
Protected WithEvents zc As System.Web.UI.WebControls.Button
Protected WithEvents cz As System.Web.UI.WebControls.Button
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
'注意: 以下占位符声明是 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
Dim SQLStr As String = "server=cs007;uid=sa;pwd=;database=tt"
Dim Username As String
Dim Userpwd As String
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
usercheck()
End Sub
Sub usercheck()
Dim Comm As SqlCommand
Dim comm1 As SqlCommand
Dim comm2 As SqlCommand
Dim comm3 As SqlCommand
Dim Conn As New SqlConnection(SQLStr)
Conn.Open()
Comm = New SqlCommand("select * from admin where username='" & t1.Text & "'", Conn) '验证是否存在该用户
Dim sqlread As SqlDataReader
sqlread = Comm.ExecuteReader
If sqlread.Read Then
Conn.Close()
Conn.Open()
comm1 = New SqlCommand("select * from admin where username='" & t1.Text & "' and userpws = '" & t2.Text & "'", Conn) '验证用户密码是否正确
Dim sqlread1 As SqlDataReader = comm1.ExecuteReader
If sqlread1.Read Then
Session("username") = t1.Text
Session("userpwd") = t2.Text
Conn.Close()
Conn.Open()
comm2 = New SqlCommand("select * from admin where username='" & t1.Text & "' and userpws='" & t2.Text & "'and tingliu=1", Conn) '验证该用户是否已经登陆
Dim sql2read As SqlDataReader = comm2.ExecuteReader
If sql2read.Read Then
Conn.Close()
Me.Response.Redirect("alreadyland.aspx") '如果该用户重复登陆,提示处理
Else
Conn.Close()
Conn.Open()
comm3 = New SqlCommand("update admin set tingliu=1 where username='" & t1.Text & "'", Conn) '如果该用户为合法用户,允许登陆并更新信息
comm3.ExecuteNonQuery()
Button1.Visible = False
Me.Response.Redirect("successed.aspx")
Conn.Close()
End If
Else
Me.Response.Redirect("error.aspx") '如果该用户输入密码错误,给出提示信息
End If
Else
Conn.Close()
Conn = Nothing
Me.Response.Redirect("nouser.aspx") '如果该用户不存在,给出提示信息
End If
End Sub
Private Sub cz_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cz.Click
t1.Text = ""
t2.Text = ""
End Sub
Private Sub zc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zc.Click
Me.Response.Redirect("loginlaw.aspx")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Response.Redirect("findpwd.aspx")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Session("username") = t1.Text
Session("Userpwd") = t2.Text
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -