📄 人员管理.vb
字号:
'Button1
'
Me.Button1.Location = New System.Drawing.Point(248, 152)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 23)
Me.Button1.TabIndex = 11
Me.Button1.Text = "加入"
'
'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(0, 0)
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(448, 192)
Me.DataGrid1.TabIndex = 22
'
'人员管理
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(448, 391)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.DataGrid1)
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
Dim mycom As New SqlCommand("select 房间id from 宿舍管理", mycon)
Dim myr As SqlDataReader
cb_louname.Items.Clear()
mycon.Open()
myr = mycom.ExecuteReader
While myr.Read
cb_louname.Items.Add(myr(0))
End While
mycon.Close()
dataDB("")
End Sub
#End Region
#Region "数据网格被鼠标点击后的代码"
Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
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)
cb_louname.SelectedItem = DataGrid1.Item(DataGrid1.CurrentRowIndex, 7)
End Sub
#End Region
#Region "不能为空"
Sub kong()
If tb_peopname.Text = "" Then
MsgBox("请输入人名")
Exit Sub
End If
If tb_peopid.Text = "" Then
MsgBox("请输入学生号")
Exit Sub
End If
End Sub
#End Region
#Region "未完成的检验代码"
Sub ii(ByVal id As String)
sqlstr = "select count(*) from 人员管理"
If id <> "" Then
sqlstr = "select count(*) from 人员管理 where 房间id = '" & id & "'"
End If
Dim mycom As New SqlCommand(sqlstr, mycon)
Dim rs As Integer
mycon.Open()
rs = mycom.ExecuteScalar
mycon.Close()
If rs > sqlstr Then
MsgBox("!!!!!!!!!")
Exit Sub
End If
End Sub
#End Region
#Region "加入按钮"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
kong()
'' 这个子程序不完善 注销掉 ii(cb_louname.SelectedItem)
'本段代码稍后完善,需要考虑:1.在数字的地方输入了字母 2.判断学号重复否 3.如果该宿舍最大人数已上限如何处理
'2、存入数据库
'--------因为radiobutton不能返回值,所以定义一个变量让他能够返回值--------------------
Dim xb As String
If peop_man.Checked Then
xb = "男"
Else
xb = "女"
End If
'------------------------定义变量结束----------------
'---------------下面开始加入信息-----------------------
sqlstr = "insert into 人员管理 values('" & tb_peopname.Text & "','" & _
tb_peopage.Text & "','" & xb & "','" & tb_peopjiguan.Text & "','" & _
tb_zhuanye.Text & "','" & cb_pay.SelectedItem & "','" & _
tb_peopid.Text & "','" & cb_louname.SelectedItem & "')"
'-------------------加入语句解决,下面就是向数据库添加了----------------------
Dim mycom As New SqlCommand(sqlstr, mycon)
mycon.Open() '--打开数据库连接---------
mycom.ExecuteNonQuery() '----加入------
mycon.Close() '--------关闭数据库链接---------
clear()
'改变显示人数和数据网格
dataDB(cb_louname.SelectedItem)
Catch ex As Exception
MsgBox("对不起,您输入的数据有误,不能添加")
End Try
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 = ""
End Sub
#End Region
#Region "一个子程序,用于数据库检查的,本段代码还有不明白的地方,需要查找一下原来的上机笔记"
Sub dataDB(ByVal id As String)
sqlstr = "select count(*) from 人员管理"
If id <> "" Then
sqlstr = "select count(*) from 人员管理 where 房间id = '" & id & "'"
End If
Dim mycom As New SqlCommand(sqlstr, mycon)
Dim rs As Integer
mycon.Open()
rs = mycom.ExecuteScalar
mycon.Close()
l_num.Text = cb_louname.SelectedItem & "宿舍人数:" & rs
'-----------上面是计数用的-----------------
sqlstr = "select * from 人员管理"
If id <> "" Then
sqlstr = "select * from 人员管理 where 房间id = '" & id & "'"
End If
Dim myt As New DataTable
Dim myad As New SqlDataAdapter(sqlstr, mycon)
mycon.Open()
myad.Fill(myt)
mycon.Close()
DataGrid1.DataSource = myt
End Sub
#End Region
#Region "选择了列表中不同的宿舍编号的同时,宿舍信息在数据网格中变化"
Private Sub cb_louname_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb_louname.SelectedIndexChanged
dataDB(cb_louname.SelectedItem)
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
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -