frmaddteacher.frm
来自「数据库课程设计」· FRM 代码 · 共 304 行
FRM
304 行
VERSION 5.00
Begin VB.Form frmAddTeacher
Caption = "教师管理-添加"
ClientHeight = 3975
ClientLeft = 60
ClientTop = 345
ClientWidth = 6270
LinkTopic = "Form1"
ScaleHeight = 3975
ScaleWidth = 6270
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdCancel
Caption = "返回(&N)"
Height = 375
Left = 3120
TabIndex = 20
Top = 3480
Width = 1335
End
Begin VB.CommandButton cmdOK
Caption = "添加(&Y)"
Height = 375
Left = 1680
TabIndex = 19
Top = 3480
Width = 1335
End
Begin VB.Frame Frame1
Caption = "教师基本信息"
Height = 3135
Left = 240
TabIndex = 0
Top = 120
Width = 5775
Begin VB.TextBox txtTitle
Height = 285
Left = 960
TabIndex = 18
Text = "Text1"
Top = 1440
Width = 1815
End
Begin VB.ComboBox cboDept
Height = 315
Left = 3720
TabIndex = 16
Text = "Combo1"
Top = 720
Width = 1815
End
Begin VB.TextBox txtNo
Height = 285
Left = 3720
TabIndex = 7
Text = "Text1"
Top = 360
Width = 1815
End
Begin VB.TextBox txtName
Height = 285
Left = 960
TabIndex = 6
Text = "Text3"
Top = 360
Width = 1455
End
Begin VB.TextBox txtBirth
Height = 285
Left = 960
TabIndex = 5
Text = "Text2"
Top = 720
Width = 1815
End
Begin VB.ComboBox cboSex
Height = 315
Left = 960
TabIndex = 4
Text = "Combo2"
Top = 1080
Width = 1815
End
Begin VB.TextBox txtTel
Height = 285
Left = 3720
TabIndex = 3
Text = "Text4"
Top = 1080
Width = 1815
End
Begin VB.TextBox txtAddress
Height = 285
Left = 960
TabIndex = 2
Text = "Text5"
Top = 1800
Width = 4575
End
Begin VB.TextBox txtMemo
Height = 855
Left = 960
TabIndex = 1
Text = "Text6"
Top = 2160
Width = 4575
End
Begin VB.Label Label10
Caption = "职称:"
Height = 255
Left = 360
TabIndex = 17
Top = 1440
Width = 615
End
Begin VB.Label Label9
Caption = "部门:"
Height = 255
Left = 3120
TabIndex = 15
Top = 720
Width = 615
End
Begin VB.Label Label1
Caption = "编号:"
Height = 255
Left = 3120
TabIndex = 14
Top = 360
Width = 615
End
Begin VB.Label Label3
Caption = "姓名:"
Height = 255
Left = 360
TabIndex = 13
Top = 360
Width = 615
End
Begin VB.Label Label4
Caption = "生日:"
Height = 255
Left = 360
TabIndex = 12
Top = 720
Width = 615
End
Begin VB.Label Label5
Caption = "性别:"
Height = 255
Left = 360
TabIndex = 11
Top = 1080
Width = 615
End
Begin VB.Label Label6
Caption = "电话:"
Height = 255
Left = 3120
TabIndex = 10
Top = 1080
Width = 615
End
Begin VB.Label Label7
Caption = "地址:"
Height = 255
Left = 360
TabIndex = 9
Top = 1800
Width = 1095
End
Begin VB.Label Label8
Caption = "备注:"
Height = 255
Left = 360
TabIndex = 8
Top = 2160
Width = 855
End
End
End
Attribute VB_Name = "frmAddTeacher"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public sqlStr As String
Public msgText As String
Sub initDepartment()
Dim rstDept As ADODB.Recordset
'从数据库中读取所有部门名称并添加到组合列表框中
'方便录入时进行选择
sqlStr = "select dept_name from departmentInfo"
Set rstDept = ExecuteSQL(sqlStr, msgText)
cboDept.Clear
If Not rstDept.EOF Then
Do While Not rstDept.EOF
cboDept.AddItem Trim(rstDept.Fields(0))
rstDept.MoveNext
Loop
cboDept.ListIndex = 0
Else
MsgBox "没有部门信息,请添加部门!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstDept.Close
End Sub
Sub initForm()
txtName = ""
txtNo = ""
txtBirth = ""
txtTel = ""
txtTitle = ""
txtAddress = ""
txtMemo = ""
cboSex.Clear
cboSex.AddItem "男"
cboSex.AddItem "女"
cboSex.ListIndex = 0
'初始化部门信息
initDepartment
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim rstTeacher As ADODB.Recordset
Dim teacherNo As String
Dim teacherName As String
Dim birthdate As String
Dim sex As String
Dim department As String
Dim tel As String
Dim address As String
Dim memo As String
Dim title As String
'获取数据
teacherNo = Trim(txtNo.Text)
teacherName = Trim(txtName.Text)
birthdate = Trim(txtBirth.Text)
sex = cboSex.Text
department = cboDept.Text
tel = Trim(txtTel.Text)
address = Trim(txtAddress.Text)
memo = Trim(txtMemo.Text)
title = Trim(txtTitle.Text)
If teacherNo = "" Or teacherName = "" Then
MsgBox "请将信息补充完整", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
'添加新记录
sqlStr = "select * from teacherInfo"
Set rstTeacher = ExecuteSQL(sqlStr, msgText)
rstTeacher.AddNew
rstTeacher.Fields("teacher_no") = teacherNo
rstTeacher.Fields("name") = teacherName
rstTeacher.Fields("department") = department
rstTeacher.Fields("birthdate") = birthdate
rstTeacher.Fields("sex") = sex
rstTeacher.Fields("address") = address
rstTeacher.Fields("telno") = tel
rstTeacher.Fields("memo") = memo
rstTeacher.Fields("title") = title
rstTeacher.Update
rstTeacher.Close
MsgBox "教师信息添加完成!", vbOKOnly + vbExclamation, "警告"
initForm
End Sub
Private Sub Form_Load()
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
initForm
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?