📄 frminputstu.frm
字号:
Style = 2 'Dropdown List
TabIndex = 3
Top = 360
Width = 735
End
Begin VB.TextBox Text1
Height = 285
Index = 0
Left = 1200
TabIndex = 0
Top = 360
Width = 1335
End
Begin VB.Label Label8
Caption = "出生年月日"
Height = 255
Left = 6480
TabIndex = 49
Top = 840
Width = 1095
End
Begin VB.Label Label7
Caption = "年龄"
Height = 255
Left = 4920
TabIndex = 48
Top = 840
Width = 735
End
Begin VB.Label Label6
Caption = "籍贯"
Height = 255
Left = 2760
TabIndex = 47
Top = 840
Width = 615
End
Begin VB.Label Label5
Caption = "政治面貌"
Height = 255
Left = 360
TabIndex = 46
Top = 840
Width = 735
End
Begin VB.Label Label4
Caption = "户口所在地"
Height = 255
Left = 6480
TabIndex = 45
Top = 360
Width = 975
End
Begin VB.Label Label3
Caption = "性别"
Height = 255
Left = 4920
TabIndex = 44
Top = 360
Width = 735
End
Begin VB.Label Label2
Caption = "姓名"
Height = 255
Left = 2760
TabIndex = 43
Top = 360
Width = 615
End
Begin VB.Label Label1
Caption = "准考证号"
Height = 255
Left = 360
TabIndex = 42
Top = 360
Width = 855
End
End
Begin VB.Label Label10
Caption = "Label10"
Height = 255
Index = 2
Left = 6360
TabIndex = 61
Top = 3240
Width = 735
End
Begin VB.Label Label9
Caption = "Label9"
Height = 255
Index = 3
Left = 6240
TabIndex = 54
Top = 1920
Width = 495
End
End
Attribute VB_Name = "frmInputStu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'定义6个窗体范围内的ADODB.Recordset变量
Dim rs_Stu As New ADODB.Recordset
Dim rs_Grade As New ADODB.Recordset
Dim rs_Wish As New ADODB.Recordset
Dim rs_Study As New ADODB.Recordset
Dim rs_Relation As New ADODB.Recordset
Dim rs_check As New ADODB.Recordset '用于检测添加记录时是否有重复的准考证号
Private Sub cmdAdd_Click()
'先检测是否添了一些必要信息
Dim i As Integer
Dim j As Integer
'检测准考证号是否为数字,因为此项为主码,应填写正确
If IsNumeric(Text1(0).Text) = False Then
MsgBox "准考证号应该为数字!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
For i = 0 To 6
If Text1(i).Text = "" Then
MsgBox "考生基本信息不可为空!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
Next i
'检测年龄是否为数字
If IsNumeric(Text1(5).Text) = False Then
MsgBox "年龄必须为数字!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
'检测日期书写是否正确
If IsDate(Text1(6).Text) = False Then
MsgBox "出生日期书写不对,应为2000-1-1这样的格式!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
'检测考生成绩是否已输入并且是否为数字
For i = 0 To 3
If Text8(i).Text = "" Then
MsgBox "考生分数信息不可为空!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
If IsNumeric(Text8(i).Text) = False Then
MsgBox "考生分数应为数字!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
Next i
'检测考生第一志愿学校是否为空
If Text9(0).Text = "" Then
MsgBox "考生志愿信息不可为空!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
'检测考生个人简历是否为空
For i = 0 To 2
If Text10(i).Text = "" Then
MsgBox "考生个人简历信息不可为空!", vbOKOnly + vbInformation, "注意 "
Exit Sub
End If
Next i
'检测日期书写是否正确
If IsDate(Text10(2)) = False Then
MsgBox "毕业日期书写不对,应为2000-1-1这样的格式!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
'亲属信息可以不可为空,而且必须有两个
If Text11(0).Text = "" Or Text11(1).Text = "" Then
MsgBox "亲属信息不能为空!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
If Text11(7).Text = "" Or Text11(8).Text = "" Then
MsgBox "第二个亲属信息也不能为空!", vbOKOnly + vbInformation, "注意"
Exit Sub
End If
'计算总成绩
Dim sum As Integer
sum = 0
For i = 0 To 4
sum = sum + Val(Text8(i).Text)
Next i
'总分等于各科分数之和
Text8(5).Text = sum
'检测输入的准考证号是否已存在,如果存在则提示用户输入另一个
Dim sqlCheck As String
sqlCheck = "select * from 考生基本信息表 where 准考证号= " & Val(Text1(0).Text)
rs_check.Open sqlCheck, conn, adOpenStatic, adLockOptimistic
If Not rs_check.EOF Then
MsgBox "该准考证号已经存在,请重填一个!", vbOKOnly + vbInformation, "注意"
rs_check.Close
Exit Sub
End If
rs_check.Close
'把用户输入信息添加入各表
rs_Stu.AddNew
rs_Stu.Fields(0) = Val(Text1(0).Text)
rs_Stu.Fields(1) = Text1(1).Text
rs_Stu.Fields(2) = Combo1.Text
For i = 2 To 4
rs_Stu.Fields(i + 1) = (Text1(i).Text)
Next i
rs_Stu.Fields(6) = Val(Text1(5).Text)
rs_Stu.Fields(7) = Text1(6).Text
rs_Stu.Update
'下面的加入成绩表为了简约代码,分成3部分完成
rs_Grade.AddNew
rs_Grade.Fields(0) = Val(Text1(0).Text)
rs_Grade.Fields(1) = Text1(1).Text '准考证号的姓名使用考生基本信息表中的
For i = 0 To 5
rs_Grade.Fields(i + 2) = Val(Text8(i).Text)
Next i
rs_Grade.Fields(8) = Combo2.Text
rs_Grade.Fields(9) = Combo3.Text
rs_Grade.Update
rs_Wish.AddNew
rs_Wish.Fields(0) = Val(Text1(0).Text)
rs_Wish.Fields(1) = Text1(1).Text
For i = 0 To 5
rs_Wish.Fields(i + 2) = Text9(i).Text
Next i
rs_Wish.Update
rs_Study.AddNew
rs_Study.Fields(0) = Val(Text1(0).Text)
rs_Study.Fields(1) = Text1(1).Text
For i = 0 To 3
rs_Study.Fields(i + 2) = Text10(i).Text
Next i
rs_Study.Update
rs_Relation.AddNew
rs_Relation.Fields(0) = Val(Text1(0).Text)
rs_Relation.Fields(1) = Text1(1).Text
For i = 0 To 13
rs_Relation.Fields(i + 2) = Text11(i).Text
Next i
rs_Relation.Update
MsgBox "添加考生信息成功!", vbOKOnly + vbExclamation, "注意"
'置空所有textbox便于输入另一信息
For i = 0 To 6
Text1(i).Text = ""
Next i
For i = 0 To 4
Text8(i).Text = ""
Next i
For i = 0 To 5
Text9(i).Text = ""
Next i
For i = 0 To 3
Text10(i).Text = ""
Next i
For i = 0 To 12
Text11(i).Text = ""
Next i
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdReset_Click()
'置空所有textbox控件
For i = 0 To 6
Text1(i).Text = ""
Next i
For i = 0 To 4
Text8(i).Text = ""
Next i
For i = 0 To 5
Text9(i).Text = ""
Next i
For i = 0 To 3
Text10(i).Text = ""
Next i
For i = 0 To 13
Text11(i).Text = ""
Next i
End Sub
Private Sub Form_Load()
Dim X0 As Long
Dim Y0 As Long
'让窗体居中
X0 = Screen.Width
Y0 = Screen.Height
X0 = (X0 - Me.Width) / 2
Y0 = (Y0 - Me.Height) / 2
Me.Move X0, Y0
'先设置各个ComboBox的默认值
Combo1.ListIndex = 0
Combo2.ListIndex = 0
Combo3.ListIndex = 0
'设置总分一栏不可写
Text8(5).Enabled = False
Dim sql_Stu As String
Dim sql_Grade As String
Dim sql_Wish As String
Dim sql_Study As String
Dim sql_Relation As String
'在from_laod()方法中打开5个考生信息表
sql_Stu = "select * from 考生基本信息表"
rs_Stu.CursorLocation = adUseClient
rs_Stu.Open sql_Stu, conn, adOpenStatic, adLockOptimistic
sql_Grade = "select * from 考生成绩表"
rs_Grade.CursorLocation = adUseClient
rs_Grade.Open sql_Grade, conn, adOpenStatic, adLockOptimistic
sql_Wish = "select * from 考生志愿表"
rs_Wish.CursorLocation = adUseClient
rs_Wish.Open sql_Wish, conn, adOpenStatic, adLockOptimistic
sql_Study = "select * from 考生简历表"
rs_Study.CursorLocation = adUseClient
rs_Study.Open sql_Study, conn, adOpenStatic, adLockOptimistic
sql_Relation = "select * from 考生亲属表"
rs_Relation.CursorLocation = adUseClient
rs_Relation.Open sql_Relation, conn, adOpenStatic, adLockOptimistic
End Sub
Private Sub Form_Unload(Cancel As Integer)
rs_Stu.Close
rs_Grade.Close
rs_Wish.Close
rs_Study.Close
rs_Relation.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -