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

📄 form4.vb

📁 一个功能强大的学生公寓管理系统 界面非常友好 十分强大
💻 VB
📖 第 1 页 / 共 3 页
字号:
            Me.TxtLocation.Text = (((Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString + _
                 "/") + Me.BindingContext(Ds21, "住宿登记").Count.ToString)
        Catch ex As Exception
            MsgBox("表中没有数据!")

        End Try
    End Sub

    Private Sub ComboBox2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox2.Validating
        If ComboBox2.Text = "" Then
            ComboBox3.Text = ""
            Exit Sub
        End If

        Dim Conn As New System.Data.OleDb.OleDbConnection
        Dim Cmd As New System.Data.OleDb.OleDbCommand
        Dim DataReader As System.Data.OleDb.OleDbDataReader
        Dim ComString As String
        ComString = "Select Distinct 房号 from 房源库 Where 栋号=" & "'" & ComboBox2.Text & "'" & "order by 房号"

        Try
            Conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=学生公寓管理系统.mdb"
            Conn.Open()

            Cmd.CommandText = ComString
            Cmd.Connection = Conn
            DataReader = Cmd.ExecuteReader
            DataReader.Read()
            ComboBox3.Items.Clear()
            While DataReader.Read()
                ComboBox3.Items.Add(DataReader.Item(0))
            End While
            DataReader.Close()
            Conn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.BindingContext(Ds21, "住宿登记").Count = 0 Then
            Exit Sub
        End If
        Me.DataGrid1.UnSelect(DataGrid1.CurrentRowIndex)
        Me.BindingContext(Ds21, "住宿登记").Position = 0
        Me.TxtLocation.Text = (((Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString + _
                                              "/") + Me.BindingContext(Ds21, "住宿登记").Count.ToString)
        Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Me.BindingContext(Ds21, "住宿登记").Count = 0 Then
            Exit Sub
        End If

        If Me.BindingContext(Ds21, "住宿登记").Position > 0 Then
            Me.BindingContext(Ds21, "住宿登记").Position -= 1
            TxtLocation.Text = (Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString & "/" & (Me.BindingContext(Ds21, "住宿登记").Count.ToString)
        End If
        Me.DataGrid1.UnSelect(DataGrid1.CurrentRowIndex + 1)
        Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Me.BindingContext(Ds21, "住宿登记").Count = 0 Then
            Exit Sub
        End If

        Dim i As Integer
        i = Me.BindingContext(Ds21, "住宿登记").Count - 1
        If Me.BindingContext(Ds21, "住宿登记").Position < i Then
            Me.BindingContext(Ds21, "住宿登记").Position += 1
            TxtLocation.Text = (Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString & "/" & (Me.BindingContext(Ds21, "住宿登记").Count).ToString
            DataGrid1.UnSelect(DataGrid1.CurrentRowIndex - 1)
        End If
        Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Me.BindingContext(Ds21, "住宿登记").Count = 0 Then
            Exit Sub
        End If

        Me.DataGrid1.UnSelect(DataGrid1.CurrentRowIndex)
        Me.BindingContext(Ds21, "住宿登记").Position = Me.BindingContext(Ds21, "住宿登记").Count - 1
        TxtLocation.Text = (Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString & "/" & (Me.BindingContext(Ds21, "住宿登记").Count).ToString
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Try
            If Button5.Text = "添加" Then
                Me.BindingContext(Ds21, "住宿登记").AddNew()
                Button5.Text = "确定"
                Button1.Enabled = False
                Button2.Enabled = False
                Button3.Enabled = False
                Button4.Enabled = False
                Button6.Enabled = False
                Button7.Enabled = False
                Button9.Enabled = False
                Button10.Enabled = False
            Else
                If Button5.Text <> "确定" Then
                    Exit Sub
                End If

                Me.BindingContext(Ds21, "住宿登记").EndCurrentEdit()
                OleDbDataAdapter1.Update(Ds21.住宿登记)
                MsgBox("添加成功!")
                Button5.Text = "添加"
                Button1.Enabled = True
                Button2.Enabled = True
                Button3.Enabled = True
                Button4.Enabled = True
                Button6.Enabled = True
                Button7.Enabled = True
                Button9.Enabled = True
                Button10.Enabled = True
                TxtLocation.Text = (Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString & "/" & (Me.BindingContext(Ds21, "住宿登记").Count).ToString
                Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
            End If
        Catch ex As Exception
            If Err.Number = 5 Then
                MsgBox("已有相同的记录存在!")
            Else
                MsgBox(ex.Message)
            End If

        End Try
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Try
            If MsgBox("您真的要删除此记录吗?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                Ds21.住宿登记.Rows(Me.BindingContext(Ds21, "住宿登记").Position).Delete()
                OleDbDataAdapter1.Update(Ds21)
                TxtLocation.Text = (Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString & "/" & (Me.BindingContext(Ds21, "住宿登记").Count).ToString
                Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)


        End Try
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Try
            Me.BindingContext(Ds21, "住宿登记").EndCurrentEdit()
            If Ds21.HasChanges(DataRowState.Modified) Then
                OleDbDataAdapter1.Update(Ds21)
                MsgBox("更改成功!")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Try
            Me.BindingContext(Ds21, "住宿登记").CancelCurrentEdit()
            Button5.Text = "添加"
            Button1.Enabled = True
            Button2.Enabled = True
            Button3.Enabled = True
            Button4.Enabled = True
            Button6.Enabled = True
            Button7.Enabled = True
            Button9.Enabled = True
            Button10.Enabled = True
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Try
            OleDbDataAdapter1.SelectCommand.CommandText = "Select * from 住宿登记"
            Ds21.Clear()
            OleDbDataAdapter1.Fill(Ds21)
            Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
            Me.TxtLocation.Text = (((Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString + _
                 "/") + Me.BindingContext(Ds21, "住宿登记").Count.ToString)
        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Me.Close()

    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox1.Text = "" Then
            ComboBox2.Text = ""
            Exit Sub
        End If

        Dim Conn As New System.Data.OleDb.OleDbConnection
        Dim Cmd As New System.Data.OleDb.OleDbCommand
        Dim DataReader As System.Data.OleDb.OleDbDataReader
        Dim ComString As String
        ComString = "Select Distinct 房号 from 房源库 Where 栋号=" & "'" & ComboBox1.Text & "'" & "order by 房号"

        Try
            Conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=学生公寓管理系统.mdb"
            Conn.Open()

            Cmd.CommandText = ComString
            Cmd.Connection = Conn
            DataReader = Cmd.ExecuteReader
            DataReader.Read()
            ComboBox2.Items.Clear()
            While DataReader.Read()
                ComboBox2.Items.Add(DataReader.Item(0))
            End While
            DataReader.Close()
            Conn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub DataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
        Try
            Me.DataGrid1.Select(DataGrid1.CurrentRowIndex)
            Me.TxtLocation.Text = (((Me.BindingContext(Ds21, "住宿登记").Position + 1).ToString + _
              "/") + Me.BindingContext(Ds21, "住宿登记").Count.ToString)

        Catch ex As Exception

        End Try
    End Sub
End Class

⌨️ 快捷键说明

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