vb.net 登录界面 源代码

来源:互联网 发布:淘编程 编辑:程序博客网 时间:2024/05/21 06:48

 

 

 

 

Imports System.IO
Imports System.Data
Imports System.Data.OleDb

Public Class form1
    Inherits System.Windows.Forms.Form
   Dim myconnection As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Application.StartupPath & "/student0.mdb")
    Dim mycommand As OleDbCommand
    Dim mydatareader As OleDbDataReader
    Private Sub Txt_Username_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txt_Username.LostFocus
        If Txt_Username.Text = "" Then
            MsgBox("请输入用户名", MsgBoxStyle.Information, "警告")
            Exit Sub
        End If
    End Sub

    Private Sub btn_ok_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_ok.Click
        If Txt_Username.Text = "" Then
            MsgBox("请输入用户名", MsgBoxStyle.Information, "警告")
            Exit Sub
        ElseIf Txt_pwd.Text = "" Then
            MsgBox("请输入密码", MsgBoxStyle.Information, "警告")
            Exit Sub
        End If
        'myconnection.Open()
        'Dim s As String = "select * from 管理员表 where username='" & Trim(Txt_Username.Text).Replace("'", "''") & "' and password='" & Trim(Txt_pwd.Text).Replace("'", "''") & "'"
        'mycommand = New OleDbCommand(s, myconnection)
        'mydatareader = mycommand.ExecuteReader()
        Dim tempPass As String
        myconnection.Open()
        mycommand = New OleDbCommand("SELECT * FROM 管理员表 where username='" & Trim(Txt_Username.Text) & "'and password='" & Trim(Txt_pwd.Text) & "'", myconnection)
        mydatareader = mycommand.ExecuteReader()
        While mydatareader.Read
            tempPass = mydatareader("password")
        End While
        myconnection.Close()
        mydatareader.Close()
        mycommand.Dispose()

        Dim n As Integer
        If checkuser(Txt_Username.Text) = False Then
            MsgBox("用户名错误或不存在", 0 + 48, "提示")
            Exit Sub
        ElseIf tempPass <> Txt_pwd.Text Then
           
            If n > 3 Then
                MsgBox("对不起,你无权使用本系统", 0 + 48, "警告")‘--------此功能暂不能用,但不影响程序的运行
                End
            Else

                MsgBox("输入密码错误,请重新输入", 0 + 48, "提示")
                n = n + 1
            End If
        Else
            Me.Hide()
            Form2.Show()
        End If
    End Sub
    Private Sub btn_cancel_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_cancel.Click
        End '或是Application.Exit()
    End Sub

    Private Sub LoginFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
    End Sub
    Function checkuser(ByVal user As String) As Boolean
        Dim tempuser As String
        myconnection.Open()
        mycommand = New OleDbCommand("SELECT * FROM 管理员表 where username='" & Trim(user) & "'", myconnection)
        mydatareader = mycommand.ExecuteReader()
        While mydatareader.Read
            tempuser = mydatareader("username")
        End While
        myconnection.Close()
        mydatareader.Close()
        mycommand.Dispose()

        Dim n As Integer = 0
        If tempuser <> user Then
            Return False
        Else
            Return True
        End If
    End Function
End Class

 

 

 

 

请问下谁实现了上面的功能(当输入密码错误3次时,退出程序),能给我个源码么?谢谢了

原创粉丝点击