📄 frm_addnewstudent.frm
字号:
Left = 0
Picture = "frm_addnewstudent.frx":0B0A
Top = 4785
Width = 450
End
Begin VB.Image imgrightbottom
Height = 450
Left = 8910
Picture = "frm_addnewstudent.frx":1614
Top = 4785
Width = 450
End
Begin VB.Image imgbottom
Height = 450
Left = 405
Picture = "frm_addnewstudent.frx":211E
Stretch = -1 'True
Top = 4785
Width = 8520
End
Begin VB.Image imgrightwindow
Height = 4290
Left = 8910
Picture = "frm_addnewstudent.frx":8A60
Stretch = -1 'True
Top = 510
Width = 450
End
Begin VB.Image imgleftwindow
Height = 4410
Left = 0
Picture = "frm_addnewstudent.frx":CD7A
Stretch = -1 'True
Top = 450
Width = 465
End
Begin VB.Image imgClose
Height = 240
Left = 8955
Picture = "frm_addnewstudent.frx":1032C
Top = 135
Width = 240
End
Begin VB.Image imgtop
Height = 450
Left = 315
Picture = "frm_addnewstudent.frx":1066E
Stretch = -1 'True
Top = 45
Width = 8730
End
Begin VB.Image imgrighttitle
Height = 525
Left = 9000
Picture = "frm_addnewstudent.frx":1B870
Top = 45
Width = 375
End
End
Attribute VB_Name = "frm_addnewstudent"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim myUser As Cls_user
Dim mystd As Cls_student
Dim myClass As Cls_Class
Private Sub Combo1_Click(Index As Integer)
Select Case Index
Case 4
If Text1(0) = "" Or Text1(1) = "" Or Text1(2) = "" Or Text1(3) = "" Or Text1(4) = "" Or Text1(7) = "" Or Text1(8) = "" Or Text1(9) = "" Or Text1(11) = "" And Text1(12) = "" Or Combo1(1) = "" Or Combo1(2) = "" And Combo1(3) = "" Or Combo1(4) = "" Then
command1(0).DragMode = 1
Else
command1(0).DragMode = 0
End If
End Select
End Sub
Private Sub Form_Load()
Set myUser = New Cls_user
Set mystd = New Cls_student
Set myClass = New Cls_Class
SetWindow Me
AlwaysOnTop Me, False
Move (frm_main.Width - Me.Width) / 2, (frm_main.Height - Me.Height) / 2 - 800
myUser.OpenUserMessageByUserID UserID
If myUser.GetUserMessageRs.EOF = False Then
If Trim(myUser.GetUserMessageRs.Fields(3)) = "教务主管" Then
State "JIAOWUZHUGUAN"
Exit Sub
End If
End If
Combo1(0).AddItem "男"
Combo1(0).AddItem "女"
Combo1(1).AddItem "报纸"
Combo1(1).AddItem "电视"
Combo1(1).AddItem "网上"
Combo1(2).AddItem "已交"
Combo1(2).AddItem "未交"
Combo1(3).AddItem "重修"
Combo1(3).AddItem "转班"
Combo1(3).AddItem "毕业"
myClass.OpenClass
If myClass.GetClassRs.EOF = False Then
Do Until myClass.GetClassRs.EOF
Combo1(4).AddItem Trim(myClass.GetClassRs.Fields(0))
myClass.GetClassRs.MoveNext
Loop
End If
State "cencel"
MonthView1.Visible = False
MonthView1.Value = "1977-1-1"
End Sub
Private Sub command1_Click(Index As Integer)
Dim i As Integer
Select Case Index
Case 0
'增加
If command1(0).Caption = "新生报到" Then
State "add"
Text1(0).SetFocus
'加载数据到combo1(3)中
'加载数据到combo1(4)中
Else
'写入记录
mystd.PrcStudentByID Trim(Text1(0))
If mystd.GetPrcStudentRs.EOF Then
frm_ProgressBar.Show 1
mystd.OpenStudent
mystd.GetStudentRs.AddNew
For i = 0 To 12
mystd.GetStudentRs.Fields(i) = Trim(Text1(i))
Next
For i = 0 To 4
mystd.GetStudentRs.Fields(i + 13) = Trim(Combo1(i))
Next
mystd.GetStudentRs.Update
mystd.GetStudentRs.Requery
State "cencel"
Else
MsgBox "该学生已存在,请重新输入!"
Exit Sub
End If
End If
Case 1
'查询
frm_querystudent.Show 1
myUser.OpenUserMessageByUserID UserID
If myUser.GetUserMessageRs.EOF = False Then
If Trim(myUser.GetUserMessageRs.Fields(3)) = "教务主管" Then
State "JIAOWUZHUGUAN"
Exit Sub
End If
End If
'如果找到记录则处于可修改状态,反之处于待查状态
If finded = True Then
State "query"
Else
State "cencel"
End If
Case 2
'修改
If command1(2).Caption = "修改" Then
State "edit"
Else
frm_ProgressBar.Show 1
mystd.QryStudentByID Trim(Text1(0))
For i = 0 To 12
mystd.GetQryStudentRs.Fields(i) = Trim(Text1(i))
Next
For i = 0 To 4
mystd.GetQryStudentRs.Fields(i + 13) = Trim(Combo1(i))
Next
mystd.GetQryStudentRs.Update
mystd.GetQryStudentRs.Requery
State "cencel"
End If
Case 3
'删除
Dim yn As String
yn = MsgBox("真的删除吗?", vbYesNo, "删除")
If yn = vbYes Then
frm_ProgressBar.Show 1
mystd.QryStudentByID Trim(Text1(0))
mystd.GetQryStudentRs.Delete
mystd.GetQryStudentRs.Requery
State "cencel"
End If
Case 4
'取消
State "cencel"
Case 5
'退出
Unload Me
End Select
End Sub
Public Sub State(kind As String)
'各种操作时各个控件的状态
Dim i As Integer
Select Case kind
Case "add"
For i = 0 To 12
Text1(i) = ""
Text1(i).Enabled = True
Next
For i = 0 To 4
Combo1(i) = ""
Combo1(i).Enabled = True
Next
command1(0).Caption = "提交"
command1(0).DragMode = 1
command1(1).DragMode = 1
command1(2).DragMode = 1
command1(3).DragMode = 1
command1(4).DragMode = 0
command1(5).DragMode = 1
Case "query"
For i = 0 To 12
Text1(i).Enabled = False
Next
For i = 0 To 4
Combo1(i).Enabled = False
Next
command1(0).DragMode = 1
command1(1).DragMode = 1
command1(2).DragMode = 0
command1(3).DragMode = 0
command1(4).DragMode = 0
command1(5).DragMode = 1
Case "edit"
For i = 1 To 12
Text1(i).Enabled = True
Next
For i = 0 To 4
Combo1(i).Enabled = True
Next
Text1(1).SetFocus
command1(2).Caption = "更新"
command1(0).DragMode = 1
command1(1).DragMode = 1
command1(2).DragMode = 0
command1(3).DragMode = 1
command1(4).DragMode = 0
command1(5).DragMode = 1
Case "cencel"
For i = 0 To 12
Text1(i) = ""
Text1(i).Enabled = False
Next
For i = 0 To 4
Combo1(i) = ""
Combo1(i).Enabled = False
Next
command1(0).Caption = "新生报到"
command1(2).Caption = "修改"
command1(0).DragMode = 0
command1(1).DragMode = 0
command1(2).DragMode = 1
command1(3).DragMode = 1
command1(4).DragMode = 1
command1(5).DragMode = 0
Case "JIAOWUZHUGUAN"
For i = 0 To 12
Text1(i).Enabled = False
Next
For i = 0 To 4
Combo1(i).Enabled = False
Next
command1(0).DragMode = 1
command1(1).DragMode = 0
command1(2).DragMode = 1
command1(3).DragMode = 1
command1(4).DragMode = 1
command1(5).DragMode = 0
End Select
End Sub
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Text1(2) = MonthView1.Value
MonthView1.Visible = False
Text1(3).SetFocus
End Sub
Private Sub Text1_Click(Index As Integer)
If Index = 2 Then
MonthView1.Top = Text1(2).Top + Text1(0).Height
MonthView1.Left = Text1(1).Left
MonthView1.Visible = True
End If
End Sub
Private Sub Text1_GotFocus(Index As Integer)
If Index = 2 Then
MonthView1.Top = Text1(2).Top + Text1(0).Height
MonthView1.Left = Text1(1).Left
MonthView1.Visible = True
End If
Text1(Index).SelLength = Len(Text1(Index).Text)
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
'传递焦点
If (KeyAscii = 13 And Index < 3 And Text1(Index) <> "") Or (KeyAscii = 13 And Index > 3 And Index < 8 And Text1(Index) <> "") Or (KeyAscii = 13 And Index > 8 And Index < 12 And Text1(Index) <> "") Then
Text1(Index + 1).SetFocus
ElseIf KeyAscii = 13 And Text1(Index) <> "" Then
Select Case Index
Case 3
Combo1(0).SetFocus
Case 8
Combo1(1).SetFocus
Case 12
Combo1(2).SetFocus
End Select
End If
'如果不是必填字段则可以为空
If (KeyAscii = 13 And Index = 5) Or (KeyAscii = 13 And Index = 6) Or (KeyAscii = 13 And Index = 10) Then
Text1(Index + 1).SetFocus
End If
If (KeyAscii = 13 And Index = 2 And Text1(2) <> "") Then
MonthView1.Visible = False
Text1(3).SetFocus
End If
End Sub
Private Sub Combo1_KeyPress(Index As Integer, KeyAscii As Integer)
'传递焦点
If KeyAscii = 13 And Index = 0 And Combo1(0) <> "" Then
Text1(4).SetFocus
End If
If KeyAscii = 13 And Index = 1 And Combo1(1) <> "" Then
Text1(9).SetFocus
End If
If KeyAscii = 13 And Index > 1 And Index < 4 And Combo1(Index) <> "" Then
Combo1(Index + 1).SetFocus
End If
If KeyAscii = 13 And Index = 4 And Combo1(4) <> "" And command1(0).Caption = "提交" Then
command1(0).DragMode = 0
End If
If KeyAscii <> 13 Then KeyAscii = 0
End Sub
Private Sub imgclose_Click()
Unload Me
End Sub
Private Sub imglefttitle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawForms Me
End Sub
Private Sub imgtop_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawForms Me
End Sub
Private Sub imgrighttitle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawForms Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -