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

📄 frmaddstudentinfo.frm

📁 员工培训系统
💻 FRM
📖 第 1 页 / 共 2 页
字号:



Private Sub cboClass_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    txtStudentId.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()
On Error Resume Next
   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
    myModiStudent.rsDK1 "select * from student_info"

    
    Set StudentGrid.DataSource = myModiStudent.rs1
    
    StudentGrid.FormatString = " | 编号|  姓名|性别| 出生日期 |部门| 联系电话| 就职时间|  家庭住址  |    注释"
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
On Error Resume Next
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 depart='" & 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!depart
   txtStudentId.Text = myModiStudent.rs1!student_id
   cboSex.Text = myModiStudent.rs1!student_sex
   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
   
   cmdAdd.Enabled = True
   cmdSave.Caption = "更新(&U)"
   cmdSave.Enabled = True
   cmdDel.Enabled = True
   myModiStudent.rsDK1 sql
   Set StudentGrid.DataSource = myModiStudent.rs1
    StudentGrid.FormatString = " | 编号|  姓名|性别| 出生日期 |部门| 联系电话| 就职时间|  家庭住址  |    注释"
End If
End Sub

Private Sub cmdReturn_Click()
On Error Resume Next
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()
On Error Resume Next
If txtstudentName.Text = Empty Then
    MsgBox "请输入姓名!", vbInformation, "提示"
    txtstudentName.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
myModiStudent.rsDK1 "select * from student_Info where student_id='" & txtStudentId.Text & "'"
 If Not myModiStudent.rs1.EOF Then
        MsgBox "id已存在,请重新输入!", vbOKOnly + vbInformation, "提示"
        txtStudentId.Text = ""
        Exit Sub
    End If
  With myModiStudent.rs1
       .AddNew
    
        !student_id = txtStudentId.Text
        !student_name = txtstudentName.Text
        !student_sex = cboSex.Text
        !Birth_date = txtBirth.Text
        !depart = 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
   myModiStudent.rsDK1 "select * from student_info where student_id='" & txtStudentId.Text & "'"
     With myModiStudent.rs1
        !student_id = txtStudentId.Text
        !student_name = txtstudentName.Text
        !student_sex = cboSex.Text
        !Birth_date = txtBirth.Text
        !depart = cboClass.Text
        !tele_number = txtTel.Text
        !in_date = txtInDate.Text
        !address = txtAdd.Text
        !comment = txtcomment.Text
        .Update
    End With
  
    MsgBox "信息已成功更新!", vbOKOnly + vbInformation, "员工信息添加"
    Frame2.Enabled = False
    cmdSave.Caption = "保存(&S)"
    cmdAdd.Caption = "添加(&A)"
    cmdSave.Enabled = False
    cmdDel.Enabled = False
    
End If




StudentGrid.FormatString = " | 编号|  姓名|性别| 出生日期 |部门| 联系电话| 就职时间|  家庭住址  |    注释"
myModiStudent.rsDK1 "SELECT * FROM student_info"

   Set StudentGrid.DataSource = myModiStudent.rs1
   

End Sub

Private Sub StudentGrid_Click()
On Error Resume Next
    myModiStudent.rsDK1 "SELECT * FROM student_info"
  
   If Not myModiStudent.rs1.EOF Then
    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)
    

    cmdSave.Caption = "更新(&U)"
    cmdAdd.Caption = "添加(&A)"
    cmdDel.Enabled = True
    cmdSave.Enabled = True
    
    End If
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 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 cboClass.Text = Empty Then
    MsgBox "请选择部门.", vbInformation, "提示"
    cboClass.SetFocus
    Exit Sub
End If


End Sub


Private Sub txtStudentId_KeyPress(KeyAscii As Integer)
If KeyAscii >= 33 Then
If KeyAscii <= vbKey9 And KeyAscii >= vbKey0 Then
Else
KeyAscii = 0
MsgBox "请输入数字!"
End If
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 cboClass.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 = ""
   
    cboClass.Text = ""
    txtStudentId.Text = ""
    txtBirth.Text = "____-__-__"
    txtTel.Text = ""
    txtInDate.Text = "____-__-__"
    txtAdd.Text = ""
    txtcomment.Text = ""
End Sub
Private Sub Form_Load()
On Error Resume Next

    Set myModiStudent = New OpenRs
    StudentGrid.FormatString = " | 编号|  姓名|性别| 出生日期 |部门| 联系电话| 就职时间|  家庭住址  |    注释"
    myModiStudent.rsDK1 "select * from student_info"
    
    Set StudentGrid.DataSource = myModiStudent.rs1
    
    StudentGrid.FormatString = " | 编号|  姓名|性别| 出生日期 |部门| 联系电话| 就职时间|  家庭住址  |    注释"
  Call ClearText
  txtstudentName.SetFocus
   
    cmdAdd.Enabled = True
  
End Sub

⌨️ 快捷键说明

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