| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 966 人关注过本帖
标题:刚学VB的新人,请高手指点下这个登录的问题
取消只看楼主 加入收藏
strong-fish
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-5-28
收藏
 问题点数:0 回复次数:0 
刚学VB的新人,请高手指点下这个登录的问题
每当程序执行时,登录时就会提示:"你的账号已冻结,请与系统管理员联系",本是刚学的菜了,请高手指点,谢谢了!

代码如下:
Imports System.Data.SqlClient

Public Class frm_login
    Inherits System.Windows.Forms.Form
    Dim MyCommand As SqlCommand

    Dim Myconnection As New SqlConnection("Server=Localhost;Database=library;integrated security=true")


    Dim MyReader As SqlDataReader
    Dim UserStatus As String
    Dim LibStatus As String
    Dim AdminStatus As String
    Dim ReaderStatus As String
    Dim passTry As Integer = 0



#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TxtUserID As System.Windows.Forms.TextBox
    Friend WithEvents TxtPassword As System.Windows.Forms.TextBox
    Friend WithEvents BtnLogin As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As = New (GetType(frm_login))
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.TxtPassword = New System.Windows.Forms.TextBox
        Me.TxtUserID = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.BtnLogin = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.TextBox3 = New System.Windows.Forms.TextBox
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.TxtPassword)
        Me.GroupBox1.Controls.Add(Me.TxtUserID)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(16, 9)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(315, 94)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "登录信息"
        '
        'TxtPassword
        '
        Me.TxtPassword.Location = New System.Drawing.Point(114, 60)
        Me.TxtPassword.Name = "TxtPassword"
        Me.TxtPassword.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.TxtPassword.Size = New System.Drawing.Size(172, 21)
        Me.TxtPassword.TabIndex = 3
        '
        'TxtUserID
        '
        Me.TxtUserID.Location = New System.Drawing.Point(114, 23)
        Me.TxtUserID.Name = "TxtUserID"
        Me.TxtUserID.Size = New System.Drawing.Size(172, 21)
        Me.TxtUserID.TabIndex = 2
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(42, 60)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(120, 25)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "密码:"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(18, 26)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(120, 25)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "用户账号:"
        '
        'BtnLogin
        '
        Me.BtnLogin.Location = New System.Drawing.Point(78, 121)
        Me.BtnLogin.Name = "BtnLogin"
        Me.BtnLogin.Size = New System.Drawing.Size(63, 24)
        Me.BtnLogin.TabIndex = 1
        Me.BtnLogin.Text = "登录"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(202, 121)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(73, 24)
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "退出"
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(557, 60)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(120, 21)
        Me.TextBox3.TabIndex = 3
        Me.TextBox3.Visible = False
        '
        'frm_login
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(346, 160)
        Me.Controls.Add(Me.TextBox3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.BtnLogin)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frm_login"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "登录"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Application.Exit()
    End Sub
    Private Sub frm_login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.BringToFront()
        Me.Focus()
    End Sub
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtUserID.KeyPress
        Dim strChar As String
        strChar = e.KeyChar

        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If TxtUserID.Text = "" Then
                    MsgBox("Please Enter a User Name!", MsgBoxStyle.Information, "图书馆管理系统")
                Else
                    If TxtUserID.Text <> "" Then
                        TxtPassword.Focus()
                    End If
                End If
            Case Else
        End Select
    End Sub
    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtPassword.KeyPress
        Dim strChar As String
        strChar = e.KeyChar

        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                If TxtUserID.Text = "" Then
                    MsgBox("Please Enter Your Password!", MsgBoxStyle.Information, "图书馆管理系统")
                Else
                    If TxtUserID.Text <> "" Then
                        BtnLogin.Focus()
                    End If
                End If
            Case Else
        End Select
    End Sub
    Function verifyUser() As Boolean
        MyConnection.Open()
        MyCommand = New SqlCommand("SELECT * FROM SystemUsers WHERE UserID = '" & TxtUserID.Text & "'", Myconnection)
        MyReader = MyCommand.ExecuteReader()
        Dim TempString As String
        While MyReader.Read
            TempString = MyReader("Password")
        End While
        MyConnection.Close()
        MyReader.Close()
        MyCommand.dispose()
        If TxtPassword.Text = TempString Then
            Return True
        Else
            If TxtPassword.Text <> TempString Then
                Return False
            End If
        End If
    End Function
    Function getStatus() As String
        MyConnection.Open()
        MyCommand = New SqlCommand("SELECT * FROM SystemUsers WHERE UserID = '" & TxtUserID.Text & "'", Myconnection)
        MyReader = MyCommand.ExecuteReader()
        While MyReader.Read
            UserStatus = MyReader("Status")
        End While
        MyConnection.Close()
        MyReader.Close()
        MyCommand.dispose()
        Return UserStatus
    End Function
    Sub display_MsgBox(ByVal myMsg As String)
        MsgBox(myMsg, MsgBoxStyle.Information, "图书馆管理系统")
    End Sub
    '  Function checkIfSuperAdmin() As Boolean
    '     If TxtUserID.Text = "admin" And TxtPassword.Text = "admin" Then
    '       Return True
    '    Else
    '     If TxtUserID.Text <> "admin" Or TxtPassword.Text <> "admin" Then
    '        Return False
    '    End If
    '  End If
    '  End Function
    Sub getUserRights()
        Myconnection.Open()
        MyCommand = New SqlCommand("SELECT * FROM SystemUsers WHERE UserID = '" & TxtUserID.Text & "'", Myconnection)
        MyReader = MyCommand.ExecuteReader()
        While MyReader.Read
            AdminStatus = MyReader("AdminRights")
            LibStatus = MyReader("LibRights")
            ReaderStatus = MyReader("ReaderRights")
        End While
        Myconnection.Close()
        MyReader.Close()
        MyCommand.Dispose()
    End Sub
    Sub updatestatus()
        Dim okstatus As String
        okstatus = "冻结"
        Myconnection.Open()
        MyCommand = New SqlCommand("UPDATE SystemUsers SET Status ='" & okstatus & "' WHERE UserID = '" & TxtUserID.Text & "'", Myconnection)
        Try
            MyCommand.ExecuteNonQuery()
        Catch c As Exception
            MsgBox(c.ToString)
        End Try
        Myconnection.Close()
        MyCommand.Dispose()
    End Sub

    Private Sub BtnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnLogin.Click
        Dim main_frm As New frm_MainInterface
        getUserRights()
        If verifyUser() = True And getStatus() = "正常" And passTry < 3 Then
            If AdminStatus <> "是" Then
                main_frm.disAdminLogin()
            End If
            If LibStatus <> "是" Then
                main_frm.disLibLogin()
            End If
            If ReaderStatus <> "是" Then
                main_frm.disReaderLogin()
            End If
            clearfields()
            main_frm.Show()
            Me.Finalize()
        Else
            If verifyUser() = False And passTry < 3 And getStatus() = "正常" Then
                passTry = passTry + 1
                display_MsgBox("请输入正确的密码!")
            Else
                If passTry = 3 Then
                    updatestatus()
                    passTry = 0
                    display_MsgBox("三次尝试之后,你们的账号将被冻结,请与系统管理员联系")
                Else
                    If getStatus() <> "正常" Then
                        display_MsgBox("你的账号已被冻结,请与系统管理员联系")
                    End If
                End If
            End If
        End If
    End Sub
    Sub clearfields()
        TxtUserID.Text = ""
        TxtPassword.Text = ""
    End Sub
   


End Class
搜索更多相关主题的帖子: Dim String 新人 
2008-07-09 10:40
快速回复:刚学VB的新人,请高手指点下这个登录的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017409 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved