帮忙看看哪有错,登陆不进去

Public Class DBUser
    Private _UserName As String
    Private _Password As String
    Private _RealName As String
    Private _Memo As String
    Property UserName() As String
        Get
            Return _UserName
        End Get
        Set(ByVal value As String)
            _UserName = value
        End Set
    End Property
    Property Password() As String
        Get
            Return _Password
        End Get
        Set(ByVal value As String)
            _Password = value

        End Set
    End Property
    Property RealName() As String
        Get
            Return _RealName
        End Get
        Set(ByVal value As String)
            _RealName = value

        End Set
    End Property
    Property Memo() As String
        Get
            Return _Memo
        End Get
        Set(ByVal value As String)
            _Memo = value
        End Set
    End Property
    Sub New(ByVal Name As String, ByVal PWD As String)
        _UserName = Name
        _Password = PWD

    End Sub
    Function LoginConfirm() As Boolean
        Dim SQLString As String

        SQLString = "SELECT * FROM tbUser WHERE UserName = ' " & _UserName & " ' AND Password ='" & _Password & "'"
        'SQL查询语句

        Dim UserTable As DataTable = DBOperation.DBOperate(SQLString)

        If UserTable.Rows.Count < 1 Then   '判断用户是否存在

            MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Exclamation, "信息框")

            Return False
        Else
            '判断用户密码是否正确
            ' _RealName = UserTable.Rows(0)("RealName")
            ' _Memo = UserTable.Rows(0)("Memo")
            Return True
        End If

 

    End Function
    Function AddUser(ByVal User As DBUser) As Boolean
        Dim SQLString As String

        SQLString = "SELECT * tbUser WHERE UserName='" & User.UserName & "'AND Password='" & User.Password & "'"
        Dim UserTable As DataTable = DBOperation.DBOperate(SQLString)
        If UserTable.Rows.Count >= 1 Then       '判断用户是否存在
            MsgBox("输入的用户名已存在,请重试", MsgBoxStyle.Exclamation, "信息框")
            Return False
        Else
            SQLString = "INSERT INTO tbUser VALUES('" & User.UserName & "','" & User.Password & "','" & User.RealName & "','" & User.Memo & "')"
            DBOperation.DBOperate(SQLString)
            Return True

        End If

    End Function
    Sub DelUser(ByVal DeleteUserName As String)
        Dim SQLString As String

        SQLString = "DELETE FROM tbUser WHERE UserNAME='" & DeleteUserName & "'"
        DBOperation.DBOperate(SQLString)

    End Sub
    Function PasswordModify(ByVal NewPassword As String) As Boolean
        Dim SQLString As String

        SQLString = "UPDATE tbUser SET[Password]='" & NewPassword & "' WHERE UserName='" & _UserName & "'"
        DBOperation.DBOperate(SQLString)

    End Function
    Shared Function AttachCode() As String
        Dim TempCode As String = ""
        Dim randomvalue As Integer
        Dim i As Integer
        Randomize()
        For i = 1 To 5
            randomvalue = CInt(Int((90 - 65 + 1) * Rnd() + 65))
            TempCode = TempCode + Chr(randomvalue)

        Next
        Return TempCode
    End Function
End Class

 

 

Public Class DBOperation
    Shared Function DBOperate(ByVal SQLString As String) As DataTable
        Try
            'Dim path As String = Application.StartupPath

            Dim CONN As String = "provider=microsoft.jet.oledb.4.0;data source=" + Application.StartupPath + "/app_data/db.mdb"

            Dim oleconn As New OleDb.OleDbConnection(CONN)
            Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(SQLString, oleconn)
            cmd.CommandType = CommandType.Text
            Dim sTokens() As String
            sTokens = SQLString.Split(" ")
            If Strings.InStr("INSERT,DELETE,UPDATE", sTokens(0).ToUpper) Then
                If oleconn.State <> ConnectionState.Open Then
                    oleconn.Open()
                End If
                cmd.ExecuteNonQuery()
                If oleconn.State <> ConnectionState.Closed Then
                    oleconn.Close()
                End If
                If sTokens(0).ToUpper = "INSERT" Then
                    'MsgBox("插入记录成功!", MsgBoxStyle.Exclamation, "信息框")
                End If
                If sTokens(0).ToUpper = "DELETE" Then
                    MsgBox("删除记录成功!", MsgBoxStyle.Exclamation, "信息框")
                End If
                If sTokens(0).ToUpper = "UPDATE" Then
                    'MsgBox("更新记录成功!", MsgBoxStyle.Exclamation, "信息框")
                End If
                Return Nothing
            Else
                Dim ObjectdsDataSet As New DataSet
                Dim adapter As New OleDb.OleDbDataAdapter()
                adapter.TableMappings.Add("Table", "TEMP")
                adapter.SelectCommand = cmd
                If oleconn.State <> ConnectionState.Open Then
                    oleconn.Open()
                End If
                cmd.ExecuteNonQuery()
                If oleconn.State <> ConnectionState.Closed Then
                    oleconn.Close()
                End If
                adapter.Fill(ObjectdsDataSet)
                Return ObjectdsDataSet.Tables("TEMP")
            End If

        Catch
            MsgBox(Err.Description)
        End Try
    End Function

End Class

 

 

 

 

Option Strict Off
Option Explicit On
Imports System.Data.OleDb
Imports System.Xml
Friend Class login
    Inherits System.Windows.Forms.Form
    Private Sub txtname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ErrorProvider1.SetError(TextBox1, "")
        ErrorProvider1.SetError(TextBox2, "")
        If TextBox1.Text = "" Then
            ErrorProvider1.SetError(TextBox1, "必须输入用户名!")
            TextBox1.Focus()
            Exit Sub
        End If
        If TextBox2.Text = "" Then
            ErrorProvider1.SetError(TextBox2, "必须输入密码!")
            TextBox2.Focus()
            Exit Sub
        End If
        Dim user As New DBUser(Trim(TextBox1.Text), TextBox2.Text)

        If user.LoginConfirm = True Then
            main.Show()
        Else
            MsgBox("输入错误,请重试", MsgBoxStyle.Exclamation, "信息框")
            Exit Sub
        End If
        Me.Hide()
     

    End Sub
    Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim user As New DBUser(Trim(TextBox1.Text), TextBox2.Text)
            If user.LoginConfirm Then
                main.Show()
            Else
                MsgBox("输入错误,请重试", MsgBoxStyle.Exclamation, "信息框")
                Exit Sub
            End If
            Me.Hide()
        Else
            Exit Sub
        End If
    End Sub
    Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If (Me.Visible) Then
            Me.Visible = False
        Else
            Me.Visible = True
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub

    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Focus()
    End Sub
End Class

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值