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

📄 宿舍管理.vb

📁 这是本人设计的一个软件
💻 VB
📖 第 1 页 / 共 2 页
字号:
        '
        Me.tb_level.Location = New System.Drawing.Point(312, 19)
        Me.tb_level.MaxLength = 4
        Me.tb_level.Name = "tb_level"
        Me.tb_level.Size = New System.Drawing.Size(120, 21)
        Me.tb_level.TabIndex = 2
        Me.tb_level.Text = ""
        '
        'tb_roomnum
        '
        Me.tb_roomnum.Location = New System.Drawing.Point(104, 50)
        Me.tb_roomnum.Name = "tb_roomnum"
        Me.tb_roomnum.Size = New System.Drawing.Size(120, 21)
        Me.tb_roomnum.TabIndex = 3
        Me.tb_roomnum.Text = ""
        '
        'tb_louname
        '
        Me.tb_louname.Location = New System.Drawing.Point(104, 19)
        Me.tb_louname.Name = "tb_louname"
        Me.tb_louname.Size = New System.Drawing.Size(120, 21)
        Me.tb_louname.TabIndex = 1
        Me.tb_louname.Text = ""
        '
        'tb_roommax
        '
        Me.tb_roommax.Location = New System.Drawing.Point(104, 81)
        Me.tb_roommax.MaxLength = 4
        Me.tb_roommax.Name = "tb_roommax"
        Me.tb_roommax.Size = New System.Drawing.Size(120, 21)
        Me.tb_roommax.TabIndex = 5
        Me.tb_roommax.Text = ""
        '
        'b_add
        '
        Me.b_add.Location = New System.Drawing.Point(232, 112)
        Me.b_add.Name = "b_add"
        Me.b_add.Size = New System.Drawing.Size(56, 23)
        Me.b_add.TabIndex = 8
        Me.b_add.Text = "加入"
        '
        'roomidbackup
        '
        Me.roomidbackup.Location = New System.Drawing.Point(8, 112)
        Me.roomidbackup.Name = "roomidbackup"
        Me.roomidbackup.Size = New System.Drawing.Size(24, 21)
        Me.roomidbackup.TabIndex = 21
        Me.roomidbackup.Text = ""
        Me.roomidbackup.Visible = False
        '
        '宿舍管理
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(480, 375)
        Me.Controls.Add(Me.DataGrid1)
        Me.Controls.Add(Me.GroupBox1)
        Me.Name = "宿舍管理"
        Me.Text = "宿舍管理"
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "判断输入是否为空的子程序"
    Sub kong()
        If tb_louname.Text = "" Then
            MsgBox("请输入楼名")
            Exit Sub
        End If

        If tb_roomnum.Text = "" Then
            MsgBox("请输入宿舍号")
            Exit Sub
        End If

        If tb_roomid.Text = "" Then
            MsgBox("请输入宿舍编号")
            Exit Sub
        End If
    End Sub

#End Region

#Region "点击加入按钮"

    Private Sub b_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b_add.Click

        Try

            kong()

            sqlstr = "select 房间id from 宿舍管理 where 房间id ='" & tb_roomid.Text & "'"
            Dim mycom As New SqlCommand(sqlstr, mycon)
            mycon.Open()

            If mycom.ExecuteScalar <> "" Then
                mycon.Close()
                MsgBox("宿舍编号重复!请重新输入。")
                Exit Sub
            End If

            sqlstr = "insert into 宿舍管理 values('" & tb_louname.Text & "','" & tb_level.Text & "','" & tb_roomnum.Text & "','" & _
                    tb_roommax.Text & "','" & tb_money.Text & "','" & tb_roomid.Text & "','" & tb_roomtel.Text & "')"
            mycom.CommandText = sqlstr
            mycom.ExecuteNonQuery()
            mycon.Close()

            tb_clear()  '清空所有文本框
            dbbd()  '数据绑定子程序
        Catch ex As Exception
            MsgBox("对不起,不能删除该用户")
        End Try

    End Sub

#End Region

#Region "数据网格被鼠标点击后的代码"

    Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
        tb_louname.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 0)

        tb_level.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 1)
        tb_roomnum.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 2)
        tb_roommax.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 3)
        tb_money.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 4)
        tb_roomid.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 5)
        roomidbackup.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 5)
        tb_roomtel.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 6)
        B_xg.Enabled = True   '开启修改按钮
        B_del.Enabled = True   '开启删除按钮

    End Sub
#End Region

#Region "清除全部文本框代码"

    Sub tb_clear()
        tb_louname.Text = ""
        tb_level.Text = ""
        tb_roomnum.Text = ""
        tb_roommax.Text = ""
        tb_money.Text = ""
        tb_roomid.Text = ""
        roomidbackup.Text = ""
        tb_roomtel.Text = ""
    End Sub

#End Region

#Region "删除按纽的代码"

    Private Sub B_del_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_del.Click

        If MsgBox("真的要删除吗?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then

            sqlstr = "delete from 宿舍管理 where 房间id='" & roomidbackup.Text & "'"
            Dim mycom As New SqlCommand(sqlstr, mycon)
            mycon.Open()
            mycom.ExecuteNonQuery()
            mycon.Close()
            tb_clear()
            B_xg.Enabled = False          '关闭修改按钮
            B_del.Enabled = False         '关闭删除按钮
            tb_roomid.ReadOnly = False    '让房间编号按钮不是只读

            dbbd()  '同样,还是数据绑定

        End If


    End Sub

#End Region

#Region "修改按纽的代码"
    Private Sub B_xg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B_xg.Click

        If MsgBox("真的要修改吗?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then

            Try

                sqlstr = "update 宿舍管理 set 住宿楼名称='" & tb_louname.Text & "',楼层='" & tb_level.Text & "',宿舍号='" & _
                tb_roomnum.Text & "',宿舍最大人数='" & tb_roommax.Text & "',宿舍费用='" & tb_money.Text & "',房间ID='" & _
                tb_roomid.Text & "',宿舍电话='" & tb_roomtel.Text & "' where 房间ID='" & roomidbackup.Text & "'"

                Dim mycom As New SqlCommand(sqlstr, mycon)
                mycon.Open()
                mycom.ExecuteNonQuery()
                mycon.Close()
                tb_clear()
                B_xg.Enabled = False
                B_del.Enabled = False
                tb_roomid.ReadOnly = False
                dbbd()

            Catch ex As Exception
                MsgBox("对不起,您输入的数据有误,不能修改")
            End Try


        End If

    End Sub
#End Region

#Region "窗口的LOAD事件代码"

    Private Sub 宿舍管理_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dbbd()
    End Sub

#End Region

#Region "关闭当前窗体"

    Private Sub b_close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b_close.Click
        Me.Close()
    End Sub

#End Region

#Region "数据绑定代码"

    Sub dbbd()
        sqlstr = "select * from 宿舍管理"
        Dim myt As New DataTable

        Dim myad As New SqlDataAdapter(sqlstr, mycon)

        mycon.Open()
        myad.Fill(myt)
        mycon.Close()
        DataGrid1.DataSource = myt

        B_xg.Enabled = False
        B_del.Enabled = False
    End Sub

#End Region

End Class

⌨️ 快捷键说明

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