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

📄 readermaintenance.vb

📁 图书管理系统
💻 VB
📖 第 1 页 / 共 2 页
字号:
        '
        Me.Button4.Location = New System.Drawing.Point(280, 368)
        Me.Button4.Name = "Button4"
        Me.Button4.TabIndex = 4
        Me.Button4.Text = "退出"
        '
        'ReaderMaintenance
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.ActiveBorder
        Me.ClientSize = New System.Drawing.Size(434, 415)
        Me.Controls.Add(Me.Button4)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.Name = "ReaderMaintenance"
        Me.Text = "读者信息维护"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim MaxNumber As Integer
    Private Sub ClearData()
        TextBox3.Text = ""
        RadioButton1.Checked = True
        TextBox4.Text = ""
        TextBox5.Text = ""
    End Sub
    Private Function IsNull() As Boolean
        If TextBox3.Text = "" Then
            MessageBox.Show("姓名输入选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return False
            Exit Function
        End If
        If TextBox4.Text = "" Then
            MessageBox.Show("最大借阅册数选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return False
            Exit Function
        Else
            If IsNumeric(TextBox4.Text) = False Then
                MessageBox.Show("最大借阅册数选项的数值不合法!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TextBox4.Text = ""
                TextBox4.Focus()
                Return False
                Exit Function
            End If
        End If
        If TextBox5.Text = "" Then
            MessageBox.Show("最大借阅天数选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Return False
            Exit Function
        Else
            If IsNumeric(TextBox5.Text) = False Then
                MessageBox.Show("最大借阅天数选项的数值不合法!", " 提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TextBox5.Text = ""
                TextBox5.Focus()
                Return False
                Exit Function
            End If
        End If
        Return True
    End Function

    Private Function CheckData() As Boolean
        '检验学号的合法性
        Try
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim sqlstr As String = "Select *from Students Where Sno='" & TextBox2.Text & "'"
            Dim mycom1 As New SqlCommand(sqlstr, mycon)
            If mycom1.ExecuteScalar <> 1 Then
                mycon.Close()
                Return False
                Exit Function
            End If
            mycon.Close()
            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Function
    Private Function IsCheckSno() As Boolean
        Try
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim mycom1 As New SqlCommand("select * From Students Where Sno='" & TextBox1.Text & "'", mycon)
            Dim myreader1 As SqlDataReader
            myreader1 = mycom1.ExecuteReader
            Dim Sex As String = "男"
            While myreader1.Read
                If TextBox1.Text = myreader1("Sno") Then
                    TextBox2.Text = myreader1("Sno")
                    TextBox3.Text = myreader1("SName")
                    If Sex = myreader1("Sex") Then
                        RadioButton1.Checked = True
                    Else
                        RadioButton2.Checked = True
                    End If
                    TextBox4.Text = myreader1("MaxNumber")
                    MaxNumber = myreader1("MaxNumber")
                    TextBox5.Text = myreader1("MaxDays")
                    myreader1.Close()
                    Return True
                    Exit Function
                End If
            End While
            myreader1.Close()
            mycon.Close()
            Return False
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '查询按钮的功能
        If TextBox1.Text = "" Then
            MessageBox.Show("学号输入选项不能为空!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If
        Try
            If IsCheckSno() = False Then
                MessageBox.Show("该学生的学号输入值不正确", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                TextBox1.Text = ""
                Exit Sub
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        '更新按钮的代码
        '检验数据是否为空!
        If IsNull() = False Then
            Exit Sub
        End If
        '  If CheckData() = False Then
        ' MessageBox.Show("该学生的学号输入值不正确!数据库中存在该值!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        ' Exit Sub
        ' End If
        Try
            If mycon.State = ConnectionState.Closed Then
                mycon.Open()
            End If
            Dim Sex1 As String
            If RadioButton1.Checked = True Then
                Sex1 = "男"
            Else
                Sex1 = "女"
            End If
            Dim Sex As New SqlParameter("@Sex", SqlDbType.VarChar, 2)
            Sex.Value = Sex1
            Dim sqlstr As String = "update Students set SName='" & TextBox3.Text & "',Sex=@Sex,MaxNumber='" & TextBox4.Text & "',MaxDays='" & TextBox5.Text & "' Where Sno='" & TextBox2.Text & "'"
            Dim mycom1 As New SqlCommand(sqlstr, mycon)
            mycom1.Parameters.Add(Sex)
            mycom1.ExecuteNonQuery()
            MessageBox.Show("该学生信息更新成功!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information)
            '            Call ClearData()
            '更新过后在将数据读入到控件中
            mycon.Close()
            '这个问题我好郁闷哦,真的太郁闷了,哈哈
            '同时更新其相关的MaxNumber和RemainNumber的数据
            '      mycon.Open()
            '     sqlstr = "Exec MaxNumber_Update @MaxNumber=@a,@Sno=@b"
            '    Dim a As New SqlParameter("@a", SqlDbType.Int)
            '   Dim b As New SqlParameter("@b", SqlDbType.VarChar, 15)
            '  a.Value = TextBox4.Text
            ' b.Value = TextBox1.Text
            ' mycom1 = New SqlCommand(sqlstr, mycon)
            ' mycom1.Parameters.Add(a)
            ' mycom1.Parameters.Add(b)
            ' mycom1.ExecuteNonQuery()
            ' MessageBox.Show("呵呵,成功了!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        '删除按钮的代码
        '先写判断条件。。。。
        If MessageBox.Show("确认要删除该学生的信息吗", "提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) = DialogResult.Cancel Then
            Exit Sub
        End If
        If mycon.State = ConnectionState.Closed Then
            mycon.Open()
        End If
        Dim sqlstr As String = "delete from Students Where Sno='" & TextBox2.Text & "'"
        Dim mycom1 As New SqlCommand(sqlstr, mycon)
        mycom1.ExecuteNonQuery()
        MessageBox.Show("该学生的信息已被删除!", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information)
        mycon.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        '退出按钮的代码
        Me.Close()
    End Sub

    Private Sub ReaderMaintenance_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'load事件的代码
        RadioButton1.Checked = True
        RadioButton2.Checked = False
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) = System.Windows.Forms.Keys.Enter Then
            Button1.PerformClick()
        End If
    End Sub

    Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
        Call ClearData()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        '很有趣的事件代码,呵呵
        Call ClearData()
    End Sub
End Class

⌨️ 快捷键说明

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