📄 tea_edit.frm
字号:
End Sub
Private Sub Command4_Click() '保存按钮
If Text1(0).Text = "" Or Text1(1).Text = "" Then ' 职工号或姓名字段未填
MsgBox "职工号和姓名字段必填", 0 + 48, "注意"
If Text1(0).Text = "" Then
Text1(0).SetFocus '职工号未填
Else: Text1(1).SetFocus '姓名未填
End If
Exit Sub
End If
If Text1(2).Text <> "" And IsDate(Text1(2).Text) = False Then
MsgBox "输入的出生年月格式不对,请重新输入!", 0 + 48, "注意!"
Text1(2).SetFocus
SendKeys "{home}+{end}"
Exit Sub
End If
If Text1(3).Text <> "" And IsDate(Text1(3).Text) = False Then
MsgBox "输入的工作日期格式不对,请重新输入!", 0 + 48, "注意!"
Text1(3).SetFocus
SendKeys "{home}+{end}"
Exit Sub
End If
If Text1(6).Text <> "" And IsDate(Text1(6).Text) = False Then
MsgBox "输入的毕业日期格式不对,请重新输入!", 0 + 48, "注意!"
Text1(6).SetFocus
SendKeys "{home}+{end}"
Exit Sub
End If
If Text1(13).Text <> "" And IsDate(Text1(13).Text) = False Then
MsgBox "输入的入党日期格式不对,请重新输入!", 0 + 48, "注意!"
Text1(13).SetFocus
SendKeys "{home}+{end}"
Exit Sub
End If
If actiontype Then '如果之前执行的是添加操作,这判断职工号是否重复
txtSQL1 = "select Tea_id from Tea_info where Tea_id=" & "'" & Text1(0).Text & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If Not mrc1.EOF Then
MsgBox "职工号有重复,请重新输入!", 0 + 48 + 0, "注意"
Text1(0).SetFocus
SendKeys "{home}+{end}"
mrc1.Close
Exit Sub
End If
mrc1.Close
End If
Dim re As Integer
re = MsgBox("真的要保存修改/添加吗?", 4 + 32, "请确认") '确认是否保存
If re = 6 Then
Call WriteRecord '将窗体上的信息登录到记录上
mrc.Update '更新数据库
actiontype = 0
Call Initial_command '初始化按钮
End If
End Sub
Private Sub Command5_Click() '取消按钮
Call Initial_command
If actiontype = 1 Then
mrc.CancelUpdate
actiontype = 0
End If
'数据库空的情况下无需做的操作
If Not mrc.EOF Then
mrc.Requery
mrc.MoveFirst
Call Show_record
Else
Command1.SetFocus
Command2.Enabled = False
Command3.Enabled = False
End If
End Sub
'##ModelId=41FF01F80216
Private Sub Form_Load()
actiontype = 0 '初始化类型变量
Call Initial_command
'初始化学历选择框
Set mrc1 = New ADODB.Recordset
txtSQL1 = "select Xl_name from Xl_info order by Xl_value"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
mrc1.MoveFirst
While Not mrc1.EOF
Combo1(1).AddItem mrc1.Fields(0)
mrc1.MoveNext
Wend
mrc1.Close
Set mrc1 = Nothing
'初始化职称选择框
txtSQL1 = "select Prof_name from Prof_info order by Prof_value"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
mrc1.MoveFirst
While Not mrc1.EOF
Combo1(2).AddItem mrc1.Fields(0)
mrc1.MoveNext
Wend
mrc1.Close
'初始化所属系部选择框
txtSQL1 = "select Depart_name from Depart_info order by Depart_value"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
mrc1.MoveFirst
While Not mrc1.EOF
Combo1(3).AddItem mrc1.Fields(0)
mrc1.MoveNext
Wend
mrc1.Close
'初始化职务选择框
txtSQL1 = "select Tzw_name from Tzw_info order by Tzw_value"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
mrc1.MoveFirst
While Not mrc1.EOF
Combo1(4).AddItem mrc1.Fields(0)
mrc1.MoveNext
Wend
mrc1.Close
'初始化籍贯选择框
txtSQL1 = "select Province_name from Province_info order by Province_value"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
mrc1.MoveFirst
While Not mrc1.EOF
Combo1(7).AddItem mrc1.Fields(0)
mrc1.MoveNext
Wend
mrc1.Close
'初始化民族选择框
txtSQL1 = "select Ration_name from Ration_info order by Ration_value"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
mrc1.MoveFirst
While Not mrc1.EOF
Combo1(8).AddItem mrc1.Fields(0)
mrc1.MoveNext
Wend
mrc1.Close
'初始化政治面貌选择框
txtSQL1 = "select Mm_name from Mm_info order by Mm_value"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
mrc1.MoveFirst
While Not mrc1.EOF
Combo1(9).AddItem mrc1.Fields(0)
mrc1.MoveNext
Wend
mrc1.Close
txtSQL = "select * from Tea_info "
Set mrc = ExecuteSQL(txtSQL, MsgText)
If mrc.EOF Then
MsgBox "数据库内无教师信息记录!", 0 + 48, "注意!"
Text1(0).Locked = True
Command3.Enabled = False
Command2.Enabled = False
Command1.TabIndex = 0
Exit Sub
End If
mrc.MoveFirst
Call Show_record
End Sub
Public Sub Initial_command() '定义过程初始化按钮
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = False
Command5.Enabled = False
End Sub
Public Sub WriteRecord() '定义过程将控件的内容写入记录
If Text1(0).Text <> "" Then mrc.Fields(0) = Trim(Text1(0).Text)
If Text1(1).Text <> "" Then mrc.Fields(1) = Trim(Text1(1).Text)
If Combo1(0).Text = "男" Then
mrc.Fields(2) = True
Else:
If Combo1(0).Text = "女" Then
mrc.Fields(2) = False
End If
End If
If Combo1(1).Text <> "" Then '记录学历
txtSQL1 = "select Xl_value from Xl_info where Xl_name = " & "'" & Trim(Combo1(1).Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "所填学历名非法!", 0 + 48, "注意!"
Call Command5_Click
Exit Sub
End If
mrc.Fields(3) = mrc1.Fields(0)
mrc1.Close
End If
If Combo1(2).Text <> "" Then '记录职称
txtSQL1 = "select Prof_value from Prof_info where Prof_name = " & "'" & Trim(Combo1(2).Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "所填职称名非法!", 0 + 48, "注意!"
Call Command5_Click
Exit Sub
End If
mrc.Fields(4) = mrc1.Fields(0)
mrc1.Close
End If
If Combo1(7).Text <> "" Then '记录籍贯
txtSQL1 = "select Province_value from Province_info where Province_name = " & "'" & Trim(Combo1(7).Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "所填籍贯名非法!", 0 + 48, "注意!"
Call Command5_Click
Exit Sub
End If
mrc.Fields(19) = mrc1.Fields(0)
mrc1.Close
End If
If Combo1(8).Text <> "" Then '记录民族
txtSQL1 = "select Ration_value from Ration_info where Ration_name = " & "'" & Trim(Combo1(8).Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "所填民族名非法!", 0 + 48, "注意!"
Call Command5_Click
Exit Sub
End If
mrc.Fields(20) = mrc1.Fields(0)
mrc1.Close
End If
If Combo1(9).Text <> "" Then '记录政治面貌
txtSQL1 = "select Mm_value from Mm_info where Mm_name = " & "'" & Trim(Combo1(9).Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "所填职称名非法!", 0 + 48, "注意!"
Call Command5_Click
Exit Sub
End If
mrc.Fields(22) = mrc1.Fields(0)
mrc1.Close
End If
If Combo1(3).Text <> "" Then '记录所属系部
txtSQL1 = "select Depart_value from Depart_info where Depart_name = " & "'" & Trim(Combo1(3).Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "所填系部名非法!", 0 + 48, "注意!"
Call Command5_Click
Exit Sub
End If
mrc.Fields(5) = mrc1.Fields(0)
mrc1.Close
End If
If Combo1(4).Text <> "" Then '记录职务
txtSQL1 = "select Tzw_value from Tzw_info where Tzw_name = " & "'" & Trim(Combo1(4).Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "所填职务名非法!", 0 + 48, "注意!"
Call Command5_Click
Exit Sub
End If
mrc.Fields(6) = mrc1.Fields(0)
mrc1.Close
End If
If Combo1(5).Text <> "" Then mrc.Fields(7) = Val(Combo1(5).Text)
If Combo1(6).Text = "否" Then
mrc.Fields(8) = False
Else:
If Combo1(0).Text = "是" Then
mrc.Fields(8) = True
If Text1(4).Text <> "" Then mrc.Fields(9) = Trim(Text1(4).Text) '在是班导师的情况下记录所带班级
End If
End If
If Text1(2).Text <> "" Then mrc.Fields(10) = Trim(Format(Text1(2).Text, "yy-m-d"))
If Text1(3).Text <> "" Then mrc.Fields(11) = Trim(Format(Text1(3).Text, "yy-m-d"))
If Text1(5).Text <> "" Then mrc.Fields(12) = Trim(Text1(5).Text)
If Text1(6).Text <> "" Then mrc.Fields(13) = Trim(Format(Text1(6).Text, "yy-m-d"))
For i = 7 To 11
If Text1(i).Text <> "" Then
mrc.Fields(i + 7) = Trim(Text1(i).Text)
End If
Next i
If Text1(12).Text <> "" Then mrc.Fields(21) = Trim(Text1(12).Text)
If Text1(13).Text <> "" Then mrc.Fields(23) = Trim(Format(Text1(13).Text, "yy-m-d"))
If Text1(14).Text <> "" Then mrc.Fields(24) = Trim(Text1(14).Text)
End Sub
Public Sub Show_record() '定义过程将记录内容显示在控件上
If IsNull(mrc.Fields(0)) = False Then Text1(0).Text = mrc.Fields(0)
If IsNull(mrc.Fields(1)) = False Then Text1(1).Text = mrc.Fields(1)
If Not mrc.Fields(2) Then
Combo1(0).Text = "女"
Else:
If mrc.Fields(2) Then
Combo1(0).Text = "男"
End If
End If
If IsNull(mrc.Fields(3)) = False Then '显示学历
txtSQL1 = "select Xl_name from Xl_info where Xl_value = " & mrc.Fields(3)
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "学历信息有错!", 0 + 48, "注意!"
Exit Sub
End If
Combo1(1).Text = mrc1.Fields(0)
mrc1.Close
End If
If IsNull(mrc.Fields(4)) = False Then '显示职称
txtSQL1 = "select Prof_name from Prof_info where Prof_value = " & mrc.Fields(4)
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "职称信息有错!", 0 + 48, "注意!"
Exit Sub
End If
Combo1(2).Text = mrc1.Fields(0)
mrc1.Close
End If
If IsNull(mrc.Fields(19)) = False Then '显示籍贯
txtSQL1 = "select Province_name from Province_info where Province_value = " & mrc.Fields(19)
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "籍贯信息有错!", 0 + 48, "注意!"
Exit Sub
End If
Combo1(7).Text = mrc1.Fields(0)
mrc1.Close
End If
If IsNull(mrc.Fields(20)) = False Then '显示民族
txtSQL1 = "select Ration_name from Ration_info where Ration_value = " & mrc.Fields(20)
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "民族信息有错!", 0 + 48, "注意!"
Exit Sub
End If
Combo1(8).Text = mrc1.Fields(0)
mrc1.Close
End If
If IsNull(mrc.Fields(22)) = False Then '显示政治面貌
txtSQL1 = "select Mm_name from Mm_info where Mm_value = " & mrc.Fields(22)
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "政治面貌信息有错!", 0 + 48, "注意!"
Exit Sub
End If
Combo1(9).Text = mrc1.Fields(0)
mrc1.Close
End If
If IsNull(mrc.Fields(5)) = False Then '显示所属系部
txtSQL1 = "select Depart_name from Depart_info where Depart_value = " & mrc.Fields(5)
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "所属系部信息有错!", 0 + 48, "注意!"
Exit Sub
End If
Combo1(3).Text = mrc1.Fields(0)
mrc1.Close
End If
If IsNull(mrc.Fields(6)) = False Then '显示职务
txtSQL1 = "select Tzw_name from Tzw_info where Tzw_value = " & mrc.Fields(6)
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF Then
MsgBox "教师职务信息有错!", 0 + 48, "注意!"
Exit Sub
End If
Combo1(4).Text = mrc1.Fields(0)
mrc1.Close
End If
If IsNull(mrc.Fields(7)) = False Then Combo1(5).Text = mrc.Fields(7)
If Not mrc.Fields(8) Then
Combo1(6).ListIndex = 0
Label13.Visible = False
Text1(4).Visible = False
Else
Combo1(6).ListIndex = 1
Label13.Visible = True
Text1(4).Visible = True '在是班导师的情况下才有必要显示所带班级
If IsNull(mrc.Fields(9)) = False Then Text1(4).Text = mrc.Fields(9)
End If
If IsNull(mrc.Fields(10)) = False Then Text1(2).Text = mrc.Fields(10)
If IsNull(mrc.Fields(11)) = False Then Text1(3).Text = mrc.Fields(11)
For i = 5 To 11
If IsNull(mrc.Fields(i + 7)) = False Then Text1(i).Text = mrc.Fields(i + 7)
Next i
If IsNull(mrc.Fields(21)) = False Then Text1(12).Text = mrc.Fields(21)
If IsNull(mrc.Fields(23)) = False Then Text1(13).Text = mrc.Fields(23)
If IsNull(mrc.Fields(24)) = False Then Text1(14).Text = mrc.Fields(24)
End Sub
Public Sub Blank_all() '定义过程使所有控件为空白
For i = 0 To 14
Text1(i).Text = ""
Next i
For i = 0 To 9
Combo1(i).Text = ""
Next i
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -