⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmaddstudentinfo.frm

📁 学生信息管理系统用vb做的 学生信息管理系统用vb做的
💻 FRM
📖 第 1 页 / 共 2 页
字号:
End Sub

Private Sub cboClass_GotFocus()
cboClass.Clear
myModiStudent.rsDK2 ("select * from class_info inner join schoolgrade_info on schoolgrade_info.grade_no=class_info.grade_no where grade_name='" & cboGrade.Text & "'")
While myModiStudent.rs2.EOF = False
    cboClass.AddItem (myModiStudent.rs2!Class_no)
    myModiStudent.rs2.MoveNext
Wend
End Sub

Private Sub cboClass_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    txtStudentId.SetFocus
Else
    KeyAscii = 0
End If
End Sub

Private Sub cboGrade_Click()
cboClass.Text = ""
txtStudentId.Text = ""
Change = True
End Sub

Private Sub cboGrade_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    cboClass.SetFocus
Else
    KeyAscii = 0
End If
End Sub

Private Sub cboSex_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    txtBirth.SetFocus
Else
    KeyAscii = 0
End If
End Sub

Private Sub cmdAdd_Click()
If cmdAdd.Caption = "添加(&A)" Then
    Call ClearText
    cmdAdd.Caption = "取消(&C)"
    Frame2.Enabled = True
    Change = True
    txtstudentName.SetFocus
    cmdSave.Caption = "保存(&S)"
    cmdSave.Enabled = True
    cmdDel.Enabled = False
Else
    Call ClearText
    cmdAdd.Caption = "添加(&A)"
    Frame2.Enabled = False
    cmdSave.Caption = "保存(&S)"
    cmdSave.Enabled = False
    cmdDel.Enabled = False
End If
End Sub

Private Sub cmdDel_Click()
myModiStudent.rsDK1 "SELECT * FROM student_info where student_id='" & txtStudentId.Text & "'"
If MsgBox("确认要删除该记录吗?", vbQuestion + vbOKCancel, "删除记录") = vbOK Then
    myModiStudent.rs1.Delete
Else
    Exit Sub
End If

Call ClearText
cmdSave.Caption = "保存(&S)"
cmdSave.Enabled = False
cmdDel.Enabled = False
myModiStudent.rsDK1 "SELECT * FROM student_info"
If myModiStudent.rs1.EOF Then
    StudentGrid.Clear
    StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
Else
    Set StudentGrid.DataSource = myModiStudent.rs1
    StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
End If
End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub Cmdfind_Click()
Dim sql As String
Dim sql1 As String
Dim sql2 As String

If txtName.Text = Empty And txtClass.Text = Empty Then
MsgBox "请输入查询条件!", vbOKOnly + vbInformation, "学籍信息设置"
Exit Sub
End If

If txtName.Text <> "" Then
    sql1 = "and student_name='" & txtName.Text & "'"
Else
    sql1 = " "
End If

If txtClass.Text <> "" Then
    sql2 = "and class_no='" & txtClass.Text & "'"
Else
    sql2 = " "
End If

sql = "SELECT * FROM student_info where 1=1" & sql1 & sql2

myModiStudent.rsDK1 sql
If myModiStudent.rs1.EOF Then
    StudentGrid.Clear
    StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
    MsgBox "没有找到符合条件的记录!", vbOKOnly + vbInformation, "提示"
    txtName.Text = ""
Else
    Set StudentGrid.DataSource = myModiStudent.rs1
    StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
   Frame2.Enabled = True
   Change = False
   txtstudentName.Text = myModiStudent.rs1!student_name
   cboClass.Text = myModiStudent.rs1!Class_no
   txtStudentId.Text = myModiStudent.rs1!student_id
   cboSex.Text = myModiStudent.rs1!student_gender
   txtBirth.Text = Format(myModiStudent.rs1!birth_date, "yyyy-mm-dd")
   txtTel.Text = myModiStudent.rs1!tele_number
   txtInDate.Text = Format(myModiStudent.rs1!in_date, "yyyy-mm-dd")
   txtAdd.Text = myModiStudent.rs1!address
   txtcomment.Text = myModiStudent.rs1!comment
   cboGrade.Text = Mid(txtStudentId.Text, 5, 2)
   cmdAdd.Enabled = True
   cmdSave.Caption = "更新(&U)"
   cmdSave.Enabled = True
   cmdDel.Enabled = True
End If
End Sub

Private Sub cmdReturn_Click()
myModiStudent.rsDK1 "SELECT * FROM student_info"
If Not myModiStudent.rs1.EOF Then
   Set StudentGrid.DataSource = myModiStudent.rs1
   StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
End If
End Sub

Private Sub Cmdsave_Click()
If txtstudentName.Text = Empty Then
    MsgBox "请输入学生姓名!", vbInformation, "提示"
    txtstudentName.SetFocus
    Exit Sub
End If
If cboGrade.Text = Empty Then
    MsgBox "请选择年级!", vbInformation, "提示"
    cboGrade.SetFocus
    Exit Sub
End If
If cboClass.Text = Empty Then
    MsgBox "请选择班级!", vbInformation, "提示"
    cboClass.SetFocus
    Exit Sub
End If
If cboSex.Text = Empty Then
    MsgBox "请选择性别!", vbInformation, "提示"
    cboSex.SetFocus
    Exit Sub
End If
If txtStudentId.Text = Empty Then
    MsgBox "请输入学号!", vbInformation, "提示"
    txtStudentId.SetFocus
    Exit Sub
End If
If txtBirth.Text = Empty Then
    MsgBox "请输入出生日期!", vbInformation, "提示"
    txtBirth.SetFocus
    Exit Sub
ElseIf Not IsDate(txtBirth) Then
    MsgBox "出生日期不是有效日期,请重新输入.", vbInformation, "提示"
    txtBirth.SetFocus
    txtBirth.Text = "____-__-__"
    Exit Sub
ElseIf Format(txtBirth.Text, "yyyy/mm/dd") > Format(Date, "yyyy/mm/dd") Then
    MsgBox "出生日期不能大于今日,请重新输入!", vbInformation, "提示"
    txtBirth.SetFocus
    Exit Sub
ElseIf Format(txtBirth.Text, "yyyy/mm/dd") < Format(#1/1/1900#, "yyyy/mm/dd") Then
    MsgBox "生出日期不能小于1900年,请重新输入!", vbInformation, "提示"
    txtBirth.SetFocus
    txtBirth.Text = "____-__-__"
    Exit Sub
End If
If txtInDate.Text = Empty Then
    MsgBox "请输入入校时间!", vbInformation, "提示"
    txtInDate.SetFocus
    Exit Sub
End If
If Not IsDate(txtInDate) Then
    MsgBox "入校时间不是有效日期,请重新输入!", vbInformation, "提示"
    txtInDate.SetFocus
    txtInDate.Text = "____-__-__"
    Exit Sub
ElseIf Format(txtBirth.Text, "yyyy/mm/dd") > Format(Date, "yyyy/mm/dd") Then
    MsgBox "入校日期不能大于今日,请重新输入!", vbInformation, "提示"
    txtInDate.SetFocus
    txtInDate.Text = "____-__-__"
    Exit Sub
ElseIf Format(txtInDate.Text, "yyyy/mm/dd") < Format(#1/1/1900#, "yyyy/mm/dd") Then
    MsgBox "入校日期不能小于1900年,请重新输入!", vbInformation, "提示"
    txtInDate.SetFocus
    txtInDate.Text = "____-__-__"
    Exit Sub
End If

If txtTel.Text = Empty Then
    If MsgBox("联系电话是否为空?", vbYesNo + vbQuestion, "提示") = vbNo Then
        txtTel.SetFocus
        Exit Sub
    Else
        txtTel.Text = "无"
    End If
End If
If txtAdd.Text = Empty Then
    MsgBox "请输入家庭地址!", vbInformation, "提示"
    txtAdd.SetFocus
    Exit Sub
End If
If txtcomment.Text = Empty Then
    txtcomment.Text = "无"
End If

If cmdSave.Caption = "保存(&S)" Then
    With myModiStudent.rs1
        .AddNew
        !student_id = txtStudentId.Text
        !student_name = txtstudentName.Text
        !student_gender = cboSex.Text
        !birth_date = txtBirth.Text
        !Class_no = cboClass.Text
        !tele_number = txtTel.Text
        !in_date = txtInDate.Text
        !address = txtAdd.Text
        !comment = txtcomment.Text
        .Update
    End With
    Set StudentGrid.DataSource = myModiStudent.rs1
    StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
    MsgBox "学籍信息已成功添加!", vbOKOnly + vbInformation, "学籍信息添加"
    Frame2.Enabled = False
    cmdAdd.Caption = "添加(&A)"
    cmdSave.Caption = "保存(&S)"
    cmdSave.Enabled = False
    cmdDel.Enabled = False
Else
    With myModiStudent.rs1
        !student_id = txtStudentId.Text
        !student_name = txtstudentName.Text
        !student_gender = cboSex.Text
        !birth_date = txtBirth.Text
        !Class_no = cboClass.Text
        !tele_number = txtTel.Text
        !in_date = txtInDate.Text
        !address = txtAdd.Text
        !comment = txtcomment.Text
        .Update
    End With
    Set StudentGrid.DataSource = myModiStudent.rs1
    StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
    MsgBox "学籍信息已成功更新!", vbOKOnly + vbInformation, "学籍信息添加"
    Frame2.Enabled = False
    cmdSave.Caption = "保存(&S)"
    cmdAdd.Caption = "添加(&A)"
    cmdSave.Enabled = False
    cmdDel.Enabled = False

End If
End Sub

Private Sub Form_Load()
Set myModiStudent = New OpenRs
myModiStudent.rsDK2 ("select * from schoolgrade_info") '生成年级信息记录集
While myModiStudent.rs2.EOF = False
    cboGrade.AddItem (myModiStudent.rs2!grade_name)
    myModiStudent.rs2.MoveNext
Wend
cboSex.AddItem ("男")
cboSex.AddItem ("女")

StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
myModiStudent.rsDK1 "SELECT * FROM student_info"
If Not myModiStudent.rs1.EOF Then
   Set StudentGrid.DataSource = myModiStudent.rs1
   StudentGrid.FormatString = " |         学号|   姓名|性别|   出生日期|班号|    联系电话|   入校时间|      家庭住址    |    注释"
End If

End Sub

Private Sub StudentGrid_Click()
    myModiStudent.rsDK1 "SELECT * FROM student_info"
    If myModiStudent.rs1.EOF Then
        Exit Sub
    End If
    Frame2.Enabled = True
    Change = False
    txtstudentName.Text = StudentGrid.TextMatrix(StudentGrid.Row, 2)
    cboClass.Text = StudentGrid.TextMatrix(StudentGrid.Row, 5)
    txtStudentId.Text = StudentGrid.TextMatrix(StudentGrid.Row, 1)
    cboSex.Text = StudentGrid.TextMatrix(StudentGrid.Row, 3)
    txtBirth.Text = Format(StudentGrid.TextMatrix(StudentGrid.Row, 4), "yyyy-mm-dd")
    txtTel.Text = StudentGrid.TextMatrix(StudentGrid.Row, 6)
    txtInDate.Text = Format(StudentGrid.TextMatrix(StudentGrid.Row, 7), "yyyy-mm-dd")
    txtAdd.Text = StudentGrid.TextMatrix(StudentGrid.Row, 8)
    txtcomment.Text = StudentGrid.TextMatrix(StudentGrid.Row, 9)
    cboGrade.Text = Mid(txtStudentId.Text, 5, 2)

    cmdSave.Caption = "更新(&U)"
    cmdAdd.Caption = "添加(&A)"
    cmdDel.Enabled = True
    cmdSave.Enabled = True
    myModiStudent.rsDK1 "SELECT * FROM student_info where student_id='" & txtStudentId.Text & "'"
End Sub

Private Sub txtAdd_KeyPress(KeyAscii As Integer)
If KeyAscii = 39 Then KeyAscii = 0
If KeyAscii = 13 Then txtcomment.SetFocus
End Sub

Private Sub txtBirth_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtTel.SetFocus
End Sub

Private Sub txtBirth_LostFocus()
txtBirth.Text = Format(txtBirth.Text, "yyyy/mm/dd")
End Sub

Private Sub txtClass_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If Not ((Chr(KeyAscii) <= "Z" And Chr(KeyAscii) >= "A") Or (Chr(KeyAscii) <= "9" And Chr(KeyAscii) >= "0") Or KeyAscii = 8) Then
    KeyAscii = 0
End If
End Sub

Private Sub txtcomment_KeyPress(KeyAscii As Integer)
If KeyAscii = 39 Then
    KeyAscii = 0
ElseIf KeyAscii = 13 Then
    Call Cmdsave_Click
End If
End Sub

Private Sub txtInDate_GotFocus()
If cmdSave.Caption = "保存(&S)" Then
txtInDate.Text = Format(Date, "yyyy/mm/dd")
End If
End Sub

Private Sub txtInDate_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then txtAdd.SetFocus
End Sub

Private Sub txtInDate_LostFocus()
txtInDate.Text = Format(txtInDate.Text, "yyyy/mm/dd")
End Sub

Private Sub txtName_KeyPress(KeyAscii As Integer)
If KeyAscii = 39 Then KeyAscii = 0
End Sub

Private Sub txtStudentId_GotFocus()
If cboGrade.Text = Empty Then
    MsgBox "请选择年级.", vbInformation, "提示"
    cboGrade.SetFocus
    Exit Sub
ElseIf cboClass.Text = Empty Then
    MsgBox "请选择班级.", vbInformation, "提示"
    cboClass.SetFocus
    Exit Sub
End If

If Change = True Then
    Dim id As String
    Dim i As Integer
    myModiStudent.rsDK2 ("select * from student_info where class_no='" & cboClass.Text & "'")
    If myModiStudent.rs2.EOF Then
        id = "01"
    Else
        myModiStudent.rs2.MoveLast
        i = Val(Right(myModiStudent.rs2!student_id, 2))
        i = i + 1
        If i > 99 Then
            MsgBox "超过最大学号界限,不能再添加学号.", vbInformation, "提示"
            Exit Sub
        End If
        id = Trim(Str(i))
        If Len(id) < 2 Then
            id = "0" & id
        End If
    End If
    txtStudentId.Text = Format(Now, "yy") & Format(Now, "mm") & Trim(cboGrade.Text) & Trim(cboClass.Text) & id
End If
End Sub

Private Sub txtStudentId_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    cboSex.SetFocus
Else
    KeyAscii = 0
End If
End Sub

Private Sub txtstudentName_Change()
cmdDel.Enabled = False
End Sub

Private Sub txtstudentName_KeyPress(KeyAscii As Integer)
If (KeyAscii >= 33 And KeyAscii <= 64) Or (KeyAscii >= 91 And KeyAscii <= 96) Or (KeyAscii >= 123 And KeyAscii <= 127) Then KeyAscii = 0
If KeyAscii = 13 Then cboGrade.SetFocus
End Sub

Private Sub txtTel_KeyPress(KeyAscii As Integer)
If KeyAscii >= 32 And KeyAscii <= 34 Or KeyAscii >= 36 And KeyAscii <= 44 Or KeyAscii > 45 And KeyAscii < 48 Or KeyAscii >= 58 And KeyAscii <= 127 Then KeyAscii = 0
If KeyAscii = 13 Then txtInDate.SetFocus

End Sub

Public Sub ClearText()
    txtstudentName.Text = ""
    cboGrade.Text = ""
    cboClass.Text = ""
    txtStudentId.Text = ""
    txtBirth.Text = "____-__-__"
    txtTel.Text = ""
    txtInDate.Text = "____-__-__"
    txtAdd.Text = ""
    txtcomment.Text = ""
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -