📄 frmsdadd.frm
字号:
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 255
Left = 240
TabIndex = 13
Top = 1920
Width = 615
End
Begin VB.Label Label6
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = "应住人数"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 255
Left = 3120
TabIndex = 11
Top = 1440
Width = 1095
End
Begin VB.Label Label5
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = "居住性别"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 255
Left = 3120
TabIndex = 9
Top = 960
Width = 1095
End
Begin VB.Label Label4
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = "性别"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 255
Left = 240
TabIndex = 7
Top = 1440
Width = 615
End
Begin VB.Label Label3
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = "宿舍编号"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 255
Left = 3120
TabIndex = 5
Top = 480
Width = 1095
End
Begin VB.Label Label2
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = "姓名"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 255
Left = 240
TabIndex = 3
Top = 960
Width = 615
End
Begin VB.Label Label1
Appearance = 0 'Flat
BackColor = &H80000005&
BackStyle = 0 'Transparent
Caption = "学号"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 255
Left = 240
TabIndex = 1
Top = 480
Width = 615
End
End
End
Attribute VB_Name = "frmSDAdd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private dbStr As String
Private rst As New ADODB.Recordset
Private Sub cmbCancle_Click()
'取消操作
Unload Me
End Sub
Private Sub cmbDormIn_Click()
'入住操作
Me.Hide
'生成数据库查询语句
dbStr = "insert into Student_Dorm values('"
dbStr = dbStr & txtNo.Text & "','"
dbStr = dbStr & comDorm.Text & "','"
dbStr = dbStr & Format(Now, "YYYY-MM-DD") & "')"
ExecuteSQL dbStr, MsgString '执行插入新记录操作
dbStr = "select * from Dorm where Dor_Id='" & comDorm.Text & "'"
If rst.State = adStateOpen Then rst.Close '确保连接处于关闭状态
Set rst = ExecuteSQL(dbStr, MsgString) '执行查询
If rst.RecordCount > 0 Then
'修改宿舍表中相应记录的实住人数
rst.Fields("Dor_Fact").Value = rst.Fields("Dor_Fact").Value + 1
rst.Update
End If
rst.Close '关闭连接
Set rst = Nothing
MsgBox "分配成功!", vbOKOnly + vbExclamation, "宿舍分配"
Unload Me
End Sub
Private Sub comDorm_Click()
'点击宿舍编号控件时触发执行
dbStr = "select * from Dorm where Dor_Id='" & Trim(comDorm.Text) & "'" '数据查询语句
If rst.State = adStateOpen Then rst.Close '确保连接被关闭
Set rst = ExecuteSQL(dbStr, MsgString) '执行数据库查询
If rst.RecordCount > 0 Then
'显示查询结果(改变居住性别、应住人数、实住人数显示值)
txtDSex.Text = Trim(rst.Fields("Dor_Sex").Value)
txtNum.Text = Trim(rst.Fields("Dor_Num").Value)
txtFact.Text = Trim(rst.Fields("Dor_Fact").Value)
End If
rst.Close '关闭连接
End Sub
Private Sub Form_Load()
'设置背景控件颜色
txtName.BackColor = RGB(198, 229, 211)
txtSSex.BackColor = RGB(198, 229, 211)
txtClass.BackColor = RGB(198, 229, 211)
txtDSex.BackColor = RGB(198, 229, 211)
txtNum.BackColor = RGB(198, 229, 211)
txtFact.BackColor = RGB(198, 229, 211)
XPFrame1.BackColor = RGB(198, 229, 211)
Me.Left = frmMain.Left + (frmMain.Width - Me.Width) / 2 '设置窗体显示位置
Me.Top = frmMain.Top + (frmMain.Height - Me.Height) / 2 '设置窗体显示位置
End Sub
Private Sub txtNo_Change()
'学号内容改变时触发执行
Dim i As Integer
If Trim(txtNo.Text) = "" Then Exit Sub '学号为空时直接退出本过程
dbStr = "select * from student where Stu_Key='" & Trim(txtNo.Text) & "'"
Set rst = ExecuteSQL(dbStr, MsgString) '调用ado模块中的ExecuteSQL函数执行查询语句
If rst.RecordCount <= 0 Then Exit Sub '无记录时退出本过程
'显示查询结果(改变姓名、性别、班级显示值)
txtName.Text = Trim(rst.Fields("Stu_Name").Value) '姓名
txtSSex.Text = Trim(rst.Fields("Stu_Sex").Value) '性别
txtClass.Text = Trim(rst.Fields("Stu_Class").Value) '班级
rst.Close
'检查所输入的学号是否已分配宿舍
dbStr = "select * from Student_dorm where Stu_key='" & Trim(txtNo.Text) & "'"
Set rst = ExecuteSQL(dbStr, MsgString)
If rst.RecordCount > 0 Then '已分配宿舍
MsgBox "学号为" & Trim(txtNo.Text) & "的学生已被分配在" & Trim(rst.Fields("Dor_Id").Value) & "入住!", vbOKOnly + vbExclamation, "入住管理"
rst.Close
Exit Sub
End If
rst.Close
'判断学生性别,当性别不详时退出本过程
If txtSSex <> "男" And txtSSex <> "女" Then
MsgBox "该生性别不详,无法为其分配宿舍", vbOKOnly + vbExclamation, "宿舍分配"
Exit Sub
End If
'根据学生性别,在宿舍编号中列出可分配宿舍
dbStr = "select * from Dorm where Dor_Sex='" & txtSSex & "' and Dor_Num-Dor_Fact>0" '查找学生性别与宿舍居住性别一致,并且应住人数大于实住人数的宿舍
Set rst = ExecuteSQL(dbStr, MsgString) '调用ado模块中的ExecuteSQL函数执行查询语句
If rst.RecordCount > 0 Then
rst.MoveFirst
comDorm.Clear
Do While Not rst.EOF
'往宿舍控件(comDorm)中循环添加可供分配宿舍编号
comDorm.AddItem Trim(rst.Fields("Dor_Id").Value) '添加宿舍编号
rst.MoveNext '记录集指针后移
Loop
cmbDormIn.Enabled = True
rst.Close
Else '无可分配宿舍
MsgBox "对不起,无合适宿舍可分配!", vbOKOnly + vbExclamation, "宿舍分配"
rst.Close
Exit Sub
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -