📄 frmaddstu.frm
字号:
VERSION 5.00
Begin VB.Form frmStuAdd
BackColor = &H80000005&
Caption = "学生信息录入"
ClientHeight = 5280
ClientLeft = 60
ClientTop = 240
ClientWidth = 8850
Icon = "frmAddStu.frx":0000
MDIChild = -1 'True
ScaleHeight = 5280
ScaleWidth = 8850
Begin VB.Frame Frame1
BackColor = &H80000005&
Caption = "添加学生信息(&T)"
Height = 4695
Left = 360
TabIndex = 0
Top = 240
Width = 8055
Begin VB.CommandButton CmdExit
BackColor = &H80000005&
Caption = "取消(&X)"
Height = 375
Left = 4080
Style = 1 'Graphical
TabIndex = 18
Top = 3720
Width = 1575
End
Begin VB.CommandButton cmdOK
BackColor = &H80000005&
Caption = "添加(&A)"
Height = 375
Left = 1680
Style = 1 'Graphical
TabIndex = 17
Top = 3720
Width = 1695
End
Begin VB.TextBox TxtZY
Height = 270
Left = 1440
MaxLength = 50
TabIndex = 7
Text = "TxtZY"
ToolTipText = "输入学生所在学院的名称"
Top = 2400
Width = 2055
End
Begin VB.TextBox TxtXM
Height = 270
Left = 1440
MaxLength = 10
TabIndex = 6
Text = "TxtXM"
ToolTipText = "输入学生的姓名"
Top = 960
Width = 1575
End
Begin VB.TextBox TxtXH
Height = 270
Left = 1440
MaxLength = 9
TabIndex = 5
Text = "TxtXH"
ToolTipText = "输入学生的学号"
Top = 480
Width = 1575
End
Begin VB.ComboBox cobNL
Height = 300
Left = 1440
TabIndex = 2
Text = "cobNL"
ToolTipText = "选择学生的年龄"
Top = 1920
Width = 1455
End
Begin VB.ComboBox cobXB
Height = 300
Left = 1440
TabIndex = 1
Text = "cobXB"
ToolTipText = "选择学生的性别"
Top = 1440
Width = 1455
End
Begin VB.Label Label4
BackColor = &H80000005&
Caption = "系别"
Height = 255
Left = 600
TabIndex = 16
Top = 2400
Width = 615
End
Begin VB.Label Label3
BackColor = &H80000005&
Caption = "年龄"
Height = 255
Left = 600
TabIndex = 15
Top = 1920
Width = 615
End
Begin VB.Label Label2
BackColor = &H80000005&
Caption = "性别"
Height = 255
Left = 600
TabIndex = 14
Top = 1440
Width = 615
End
Begin VB.Label Label8
BackColor = &H80000005&
Caption = "姓名"
Height = 255
Left = 600
TabIndex = 13
Top = 960
Width = 615
End
Begin VB.Label Label7
BackColor = &H80000005&
Caption = "学号"
Height = 255
Left = 600
TabIndex = 12
Top = 480
Width = 495
End
Begin VB.Label lbInfo
BackColor = &H80000005&
Caption = "注意:带星号( * )的必须选择或者输入"
ForeColor = &H8000000C&
Height = 495
Left = 600
TabIndex = 11
Top = 3000
Width = 7215
End
Begin VB.Label lbXB
BackColor = &H80000005&
Caption = "* 请选择学生的性别"
Height = 255
Left = 3720
TabIndex = 10
Top = 1440
Width = 3015
End
Begin VB.Label lbNL
BackColor = &H80000005&
Caption = "* 清选择学生的年龄"
Height = 255
Left = 3720
TabIndex = 9
Top = 1920
Width = 3015
End
Begin VB.Label lbZY
BackColor = &H80000005&
Caption = "* 学院必须输入,而且不能超过25个汉字"
Height = 255
Left = 3720
TabIndex = 8
Top = 2400
Width = 3495
End
Begin VB.Label lbXM
BackColor = &H80000005&
Caption = "* 姓名必须输入,而且不能多余5个汉字"
Height = 255
Left = 3720
TabIndex = 4
Top = 960
Width = 3495
End
Begin VB.Label LbXH
BackColor = &H80000005&
Caption = "* 学号必须是8位 "
Height = 255
Left = 3720
TabIndex = 3
Top = 480
Width = 3015
End
End
End
Attribute VB_Name = "frmStuAdd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim SQL As String
Dim xsjl As New ADODB.Recordset '学生表 jc_s中的学生记录
Private Sub cmdExit_Click()
mdiFrm.stb.SimpleText = "就绪"
Unload Me
End Sub
Private Sub cmdOk_Click()
'检查是否存在该学生生数据
If TxtXH.Text = "" Or TxtXM.Text = "" Then
Call showMsg("学号和姓名不能为空!", 1)
TxtXH.SetFocus
Exit Sub
End If
On Error GoTo sqlErr
SQL = "select sno from jc_s where sno='" & TxtXH.Text & "'"
Set xsjl = cnn.Execute(SQL)
If xsjl.BOF And xsjl.EOF Then
SQL = "insert into jc_s (sno,sname,sex,age,dept) "
SQL = SQL & "values ('" & TxtXH.Text & "','" & TxtXM.Text & "','" & cobXB.Text & "','" & cobNL.Text & "','" & TxtZY.Text & "')"
cnn.Execute (SQL)
Call showMsg("添加 " & TxtXM.Text & " 信息成功!", 1)
Exit Sub
Else
SQL = "update jc_s set sname='" & TxtXM.Text & "',sex='" & cobXB.Text & "',age='" & cobNL.Text & "',dept='" & TxtZY.Text & "' where sno='" & TxtXH.Text & "'"
Call showMsg("修改" & TxtXM.Text & " 信息成功!", 1)
Exit Sub
End If
sqlErr:
Call showMsg("无法保存,可能原因:" & vbCrLf & "-你选择信息已经存在。" & vbCrLf & "-您输入的信息为非法字符。", 0)
End Sub
Private Sub Form_Load()
Call Clear
cobXB.Text = ""
cobNL.Text = ""
cobXB.AddItem ("男")
cobXB.AddItem ("女")
cobNL.AddItem ("18")
cobNL.AddItem ("19")
cobNL.AddItem ("20")
cobNL.AddItem ("21")
cobNL.AddItem ("22")
cobNL.AddItem ("23")
cobNL.AddItem ("24")
cobNL.AddItem ("25")
lbInfo.Caption = lbInfo.Caption & vbCrLf & "要修改某个记录,输入对应的信息,确定即可."
End Sub
Private Sub Clear()
TxtXH.Text = ""
TxtXM.Text = ""
cobXB.Text = ""
cobNL.Text = ""
TxtZY.Text = ""
End Sub
Private Sub Form_Resize()
With Me
Frame1.Left = (.ScaleWidth - Frame1.Width) / 2
Frame1.Top = (.ScaleHeight - Frame1.Height) / 2
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
mdiFrm.stb.SimpleText = "就绪"
Unload Me
End Sub
Private Sub TxtXH_GotFocus()
TxtXH.SelStart = 0
TxtXH.SelLength = Len(TxtXH.Text)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -