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

📄 修改.vb

📁 这是本人设计的一个软件
💻 VB
📖 第 1 页 / 共 2 页
字号:
        'btt_xg
        '
        Me.btt_xg.Location = New System.Drawing.Point(16, 288)
        Me.btt_xg.Name = "btt_xg"
        Me.btt_xg.Size = New System.Drawing.Size(56, 23)
        Me.btt_xg.TabIndex = 12
        Me.btt_xg.Text = "修改"
        '
        'Label11
        '
        Me.Label11.Location = New System.Drawing.Point(8, 8)
        Me.Label11.Name = "Label11"
        Me.Label11.Size = New System.Drawing.Size(104, 16)
        Me.Label11.TabIndex = 23
        Me.Label11.Text = "请选择房间编号:"
        '
        'cb_louname
        '
        Me.cb_louname.Location = New System.Drawing.Point(112, 4)
        Me.cb_louname.Name = "cb_louname"
        Me.cb_louname.Size = New System.Drawing.Size(121, 20)
        Me.cb_louname.TabIndex = 24
        '
        'DataGrid1
        '
        Me.DataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender
        Me.DataGrid1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.DataGrid1.BackColor = System.Drawing.Color.WhiteSmoke
        Me.DataGrid1.BackgroundColor = System.Drawing.Color.LightGray
        Me.DataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.DataGrid1.CaptionBackColor = System.Drawing.Color.LightSteelBlue
        Me.DataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.FlatMode = True
        Me.DataGrid1.Font = New System.Drawing.Font("Tahoma", 8.0!)
        Me.DataGrid1.ForeColor = System.Drawing.Color.MidnightBlue
        Me.DataGrid1.GridLineColor = System.Drawing.Color.Gainsboro
        Me.DataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None
        Me.DataGrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue
        Me.DataGrid1.HeaderFont = New System.Drawing.Font("Tahoma", 8.0!, System.Drawing.FontStyle.Bold)
        Me.DataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke
        Me.DataGrid1.LinkColor = System.Drawing.Color.Teal
        Me.DataGrid1.Location = New System.Drawing.Point(8, 32)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro
        Me.DataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue
        Me.DataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue
        Me.DataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke
        Me.DataGrid1.Size = New System.Drawing.Size(272, 296)
        Me.DataGrid1.TabIndex = 25
        '
        'TextBox1
        '
        Me.TextBox1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.TextBox1.Location = New System.Drawing.Point(288, 328)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.TabIndex = 42
        Me.TextBox1.Text = ""
        Me.TextBox1.Visible = False
        '
        '修改
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(528, 351)
        Me.Controls.Add(Me.DataGrid1)
        Me.Controls.Add(Me.cb_louname)
        Me.Controls.Add(Me.Label11)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.TextBox1)
        Me.Name = "修改"
        Me.Text = "修改"
        Me.GroupBox1.ResumeLayout(False)
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "窗体读入事件"

    Private Sub 修改_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        addcb()
        adddata("")

    End Sub

#End Region


    '下面两个子程序为窗体读入事件服务,和前面的人员管理不大一样,值得研究一下
#Region "为房间下拉框加入房间名称的子程序"
    Sub addcb()
        Dim mycom As New SqlCommand("select 房间id from 人员管理", mycon)
        Dim myr As SqlDataReader
        mycon.Open()
        myr = mycom.ExecuteReader
        While myr.Read
            cb_roomid.Items.Add(myr(0))   '住宿人员信息里的房间编号
            cb_louname.Items.Add(myr(0))  '上面的房间编号
        End While
        cb_louname.Items.Add("全部")
        mycon.Close()
    End Sub
#End Region

#Region "为数据网格加入数据的子程序,参照老师的做的,需要研究一下"

    Sub adddata(ByVal id As String)
        Dim sda As SqlDataAdapter
        Dim str As String = "select * from 人员管理 where 房间id='" & id & "'"
        If id = "" Or id = "全部" Then str = "select * from 人员管理"
        mycon.Open()
        sda = New SqlDataAdapter(str, mycon)
        mytab.Clear()
        sda.Fill(mytab)
        mycon.Close()
        DataGrid1.DataSource = mytab
    End Sub

#End Region
    '子程序结束

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

    Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click

        Try

            Dim a As String
            If a = "男" Then
                peop_wom.Checked = True
            Else
                peop_man.Checked = True
            End If

            tb_peopname.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 0)
            tb_peopage.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 1)
            a = DataGrid1.Item(DataGrid1.CurrentRowIndex, 2)
            tb_peopjiguan.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 3)
            tb_zhuanye.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 4)
            cb_pay.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 5)
            tb_peopid.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 6)
            TextBox1.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 6)
            cb_louname.SelectedItem = DataGrid1.Item(DataGrid1.CurrentRowIndex, 7)
            cb_roomid.SelectedItem = DataGrid1.Item(DataGrid1.CurrentRowIndex, 7)

        Catch ex As Exception
            MsgBox("对不起,请重新操作")
        End Try

    End Sub
#End Region

#Region "关闭按钮"
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.Close()
    End Sub
#End Region

#Region "清空用的子程序"

    Sub clear()
        tb_peopname.Text = ""
        tb_peopage.Text = ""
        tb_peopjiguan.Text = ""
        peop_man.Checked = False
        peop_wom.Checked = False
        tb_zhuanye.Text = ""
        cb_pay.Text = ""
        tb_peopid.Text = ""
        cb_louname.Text = ""
        cb_roomid.Text = ""
    End Sub

#End Region

#Region "当选择不同的宿舍编号时显示在数据网格中"

    Private Sub cb_louname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_louname.SelectedIndexChanged
        adddata(cb_louname.SelectedItem)
    End Sub

#End Region

#Region "点击修改产生的代码"

    Private Sub btt_xg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btt_xg.Click

        If MsgBox("您确认要修改吗?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            Try

                Dim xb As String
                If peop_man.Checked Then
                    xb = "男"
                Else
                    xb = "女"
                End If

                sqlstr = "update 人员管理 set 姓名='" & tb_peopname.Text & "',年龄='" & _
                tb_peopage.Text & "',性别='" & xb & "',籍贯='" & tb_peopjiguan.Text & "',专业='" & _
                tb_zhuanye.Text & "',是否交住宿费='" & cb_pay.Text & "',学号='" & _
                tb_peopid.Text & "',房间id='" & cb_roomid.Text & "' where 学号='" & TextBox1.Text & "'"

                Dim mycom As New SqlCommand(sqlstr, mycon)
                mycon.Open()
                mycom.ExecuteNonQuery()
                mycon.Close()
                clear()
                'btt_xg.Enabled = False
                'btt_del.Enabled = False
                dbbd()

            Catch ex As Exception
                MsgBox("对不起,更改数据有误,请您检查。")
            End Try

        End If

    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

        'btt_xg.Enabled = False
        'btt_del.Enabled = False

    End Sub
#End Region

#Region "删除按钮"
    Private Sub btt_del_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btt_del.Click

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

            sqlstr = "delete from 人员管理  where 学号='" & TextBox1.Text & "'"

            Dim mycom As New SqlCommand(sqlstr, mycon)
            mycon.Open()
            mycom.ExecuteNonQuery()
            mycon.Close()
            clear()
            adddata(cb_roomid.SelectedItem)


        End If



    End Sub
#End Region
End Class




⌨️ 快捷键说明

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