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

📄 stu_edit.frm

📁 这是一个非常 好的一个程序进行体会一下学生管理系统
💻 FRM
📖 第 1 页 / 共 4 页
字号:
        Else
          mrc1.Close
          Command1.Enabled = False '添加无效
          Command2.Enabled = False '修改无效
          Command3.Enabled = False '删除无效
          Command4.Enabled = True '保存有效
          Command5.Enabled = True '取消有效
          mrc.MoveFirst     '将所查到的记录置为控件的当前记录
          Do While Trim(mrc.Fields(0)) <> Trim(inno)
                mrc.MoveNext
          Loop
          Call Blank_all
          Call Show_record
        End If
     End If
End Sub

Private Sub Command3_Click() '删除按钮
    inno = InputBox("请输入你要删除的学生学号:(9位)", "注意") '输入需要删除的学生的学号
    If inno <> "" Then  '在输入非空的情况下,进行查询
        txtSQL1 = "select Stu_no from Stu_info where Stu_no=" & "'" & Trim(inno) & "'"
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then    '如果输入的学号不存在,给出提示
          MsgBox "该学号不存在!", 0 + 48, "注意"
          Command3.SetFocus
          SendKeys "{home}+{end}"
          mrc1.Close
          Exit Sub
        End If
          mrc1.Close
          mrc.MoveFirst
          Do While Trim(mrc.Fields(0)) <> Trim(inno)  '置需要删除的记录为当前记录
              mrc.MoveNext
          Loop
          Call Show_record
          Dim re As Integer
          re = MsgBox("真的要删除该记录吗?", 4 + 32 + 256, "询问!")
          If re = 6 Then
            mrc.Delete '如果返回“是”,删除记录
            mrc.Requery
            If mrc.EOF Then '删除的是最后一个记录的情况
                MsgBox "数据库内已无学生信息记录!", 0 + 48, "注意!"
                Call Blank_all
                Text1(0).Locked = True
                Command3.Enabled = False
                Command2.Enabled = False
                Command1.SetFocus
                Exit Sub
            Else:
                mrc.MoveFirst '置第一个记录为当前记录
                Call Show_record
            End If
          End If
    End If
End Sub

Private Sub Command4_Click()  '保存按钮
   If Text1(0).Text = "" Or Text1(1).Text = "" Then ' 学号或姓名字段未填
        MsgBox "学号和姓名字段必填", 0 + 48, "注意"
        If Text1(0).Text = "" Then
            Text1(0).SetFocus           '学号未填
        Else: Text1(1).SetFocus        '姓名未填
        End If
        Exit Sub
   End If
   If Text1(3).Text <> "" And IsDate(Text1(3).Text) = False Then
        MsgBox "输入的日期格式不对,请重新输入!", 0 + 48, "注意!"
        Text1(3).SetFocus
        SendKeys "{home}+{end}"
        Exit Sub
   End If
   If actiontype Then '如果之前执行的是添加操作,这判断学号是否重复
        txtSQL1 = "select Stu_no from Stu_info where Stu_no=" & "'" & Text1(0).Text & "'"
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If Not mrc1.EOF Then
            MsgBox "学号有重复,请重新输入!", 0 + 48 + 0, "注意"
            Text1(0).SetFocus
            SendKeys "{home}+{end}"
            mrc1.Close
            Exit Sub
        End If
        mrc1.Close
    End If
    For i = 5 To 12 '判断综合测评成绩格式是否正确
        If Text1(i).Text <> "" And IsNumeric(Text1(i).Text) = False Then
            MsgBox "综合测评成绩必须为数字!", 0 + 48, "注意!"
            Exit Sub
        End If
    Next i
    Dim re As Integer
    re = MsgBox("真的要保存修改/添加吗?", 4 + 32, "请确认")  '确认是否保存
    If re = 6 Then
        Call WriteRecord    '将窗体上的信息登录到记录上
        mrc.Update '更新数据库
        actiontype = 0
        Call Initial_command    '初始化按钮
    End If
End Sub

Private Sub Command5_Click() '取消按钮
    Call Initial_command
    If actiontype = 1 Then
        mrc.CancelUpdate
        actiontype = 0
    End If
    '数据库空的情况下无需做的操作
    If Not mrc.EOF Then
        mrc.Requery
        mrc.MoveFirst
        Call Show_record
    Else
        Command1.SetFocus
        Command2.Enabled = False
        Command3.Enabled = False
    End If
End Sub

Private Sub Form_Load()
    actiontype = 0 '初始化类型变量
    Call Initial_command
    '初始化学历选择框
    txtSQL1 = "select Xl_name from Xl_info order by Xl_value"
    Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
    mrc1.MoveFirst
    While Not mrc1.EOF
        Combo1(1).AddItem mrc1.Fields(0)
        mrc1.MoveNext
    Wend
    mrc1.Close
    '初始化生源选择框
    txtSQL1 = "select Province_name from Province_info order by Province_value"
    Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
    mrc1.MoveFirst
    While Not mrc1.EOF
        Combo1(3).AddItem mrc1.Fields(0)
        mrc1.MoveNext
    Wend
    mrc1.Close
    '初始化籍贯选择框
    txtSQL1 = "select Province_name from Province_info order by Province_value"
    Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
    mrc1.MoveFirst
    While Not mrc1.EOF
        Combo1(4).AddItem mrc1.Fields(0)
        mrc1.MoveNext
    Wend
    mrc1.Close
    '初始化民族选择框
    txtSQL1 = "select Ration_name from Ration_info order by Ration_value"
    Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
    mrc1.MoveFirst
    While Not mrc1.EOF
        Combo1(6).AddItem mrc1.Fields(0)
        mrc1.MoveNext
    Wend
    mrc1.Close
    '初始化职务选择框
    txtSQL1 = "select Szw_name from Szw_info order by Szw_value"
    Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
    mrc1.MoveFirst
    While Not mrc1.EOF
        Combo1(7).AddItem mrc1.Fields(0)
        mrc1.MoveNext
    Wend
    mrc1.Close
    '初始化政治面貌选择框
    txtSQL1 = "select Mm_name from Mm_info order by Mm_value"
    Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
    mrc1.MoveFirst
    While Not mrc1.EOF
        Combo1(8).AddItem mrc1.Fields(0)
        mrc1.MoveNext
    Wend
    mrc1.Close
    
    txtSQL = "select * from Stu_info"
    Set mrc = ExecuteSQL(txtSQL, MsgText)
    If mrc.EOF Then
        MsgBox "数据库内无学生信息记录!", 0 + 48, "注意!"
        Text1(0).Locked = True '在无数据的情况下,必须先输入学号!
        Command3.Enabled = False
        Command2.Enabled = False
        Command1.TabIndex = 0
        Exit Sub
    End If
    mrc.MoveFirst
    Call Show_record
 End Sub

Public Sub WriteRecord()  '定义过程将控件的内容写入记录
    If Text1(0).Text <> "" Then mrc.Fields(0) = Trim(Text1(0).Text)
    If Text1(1).Text <> "" Then mrc.Fields(1) = Trim(Text1(1).Text)
    If Combo1(0).ListIndex = 0 Then
       mrc.Fields(2) = True
    Else:
       If Combo1(0).ListIndex = 1 Then
       mrc.Fields(2) = False
       End If
    End If
    If Text1(2).Text <> "" Then mrc.Fields(3) = Trim(Text1(2).Text)
    If Combo1(1).Text <> "" Then '记录学历
        txtSQL1 = "select Xl_value from Xl_info where Xl_name = " & "'" & Trim(Combo1(1).Text) & "'"
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "所填学历名非法!", 0 + 48, "注意!"
            Call Command5_Click
            Exit Sub
        End If
        mrc.Fields(4) = mrc1.Fields(0)
        mrc1.Close
    End If
    If Combo1(2).Text <> "" Then mrc.Fields(5) = Val(Combo1(2).Text)
    If Combo1(3).Text <> "" Then '记录生源
        txtSQL1 = "select Province_value from Province_info where Province_name = " & "'" & Trim(Combo1(3).Text) & "'"
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "所填省份名非法!", 0 + 48, "注意!"
            Call Command5_Click
            Exit Sub
        End If
        mrc.Fields(6) = mrc1.Fields(0)
        mrc1.Close
    End If
    If Combo1(4).Text <> "" Then '记录籍贯
        txtSQL1 = "select Province_value from Province_info where Province_name = " & "'" & Trim(Combo1(4).Text) & "'"
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "所填省份名非法!", 0 + 48, "注意!"
            Call Command5_Click
            Exit Sub
        End If
        mrc.Fields(7) = mrc1.Fields(0)
        mrc1.Close
    End If
    If Combo1(5).Text <> "" Then mrc.Fields(9) = Trim(Combo1(5).Text)
    If Combo1(6).Text <> "" Then '记录民族
        txtSQL1 = "select Ration_value from Ration_info where Ration_name = " & "'" & Trim(Combo1(6).Text) & "'"
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "所填民族名非法!", 0 + 48, "注意!"
            Call Command5_Click
            Exit Sub
        End If
        mrc.Fields(12) = mrc1.Fields(0)
        mrc1.Close
    End If
    If Combo1(7).Text <> "" Then '记录职务
        txtSQL1 = "select Szw_value from Szw_info where Szw_name = " & "'" & Trim(Combo1(7).Text) & "'"
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "所填职务名非法!", 0 + 48, "注意!"
            Call Command5_Click
            Exit Sub
        End If
        mrc.Fields(11) = mrc1.Fields(0)
        mrc1.Close
    End If
    If Combo1(8).Text <> "" Then '记录政治面貌
        txtSQL1 = "select Mm_value from Mm_info where Mm_name = " & "'" & Trim(Combo1(8).Text) & "'"
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "所填政治面貌名非法!", 0 + 48, "注意!"
            Call Command5_Click
            Exit Sub
        End If
        mrc.Fields(10) = mrc1.Fields(0)
        mrc1.Close
    End If
    If Text1(3).Text <> "" Then mrc.Fields(8) = Trim(Format(Text1(3).Text, "yy-m-d"))
    If Text1(4).Text <> "" Then mrc.Fields(13) = Text1(4).Text
    For i = 5 To 12
        If Text1(i).Text <> "" Then mrc.Fields(i + 9) = Text1(i).Text
    Next i
End Sub

Public Sub Show_record() '定义过程将记录内容显示在控件上
    If IsNull(mrc.Fields(0)) = False Then Text1(0).Text = mrc.Fields(0)
    If IsNull(mrc.Fields(1)) = False Then Text1(1).Text = mrc.Fields(1)
    If Not mrc.Fields(2) Then
        Combo1(0).Text = "女"
    Else:
        If mrc.Fields(2) Then
             Combo1(0).Text = "男"
        End If
    End If
    If IsNull(mrc.Fields(3)) = False Then Text1(2).Text = mrc.Fields(3)
    If IsNull(mrc.Fields(4)) = False Then '显示学历
        txtSQL1 = "select Xl_name from Xl_info where Xl_value = " & mrc.Fields(4)
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "学历信息有错!", 0 + 48, "注意!"
            Exit Sub
        End If
        Combo1(1).Text = mrc1.Fields(0)
        mrc1.Close
    End If
    If IsNull(mrc.Fields(5)) = False Then Combo1(2).Text = mrc.Fields(5)
    If IsNull(mrc.Fields(6)) = False Then '显示生源
        txtSQL1 = "select Province_name from Province_info where Province_value = " & mrc.Fields(6)
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "生源信息有错!", 0 + 48, "注意!"
            Exit Sub
        End If
        Combo1(3).Text = mrc1.Fields(0)
        mrc1.Close
    End If
    If IsNull(mrc.Fields(7)) = False Then '显示籍贯
        txtSQL1 = "select Province_name from Province_info where Province_value = " & mrc.Fields(7)
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "籍贯信息有错!", 0 + 48, "注意!"
            Exit Sub
        End If
        Combo1(4).Text = mrc1.Fields(0)
        mrc1.Close
    End If
    If IsNull(mrc.Fields(9)) = False Then Combo1(5).Text = mrc.Fields(9)
    If IsNull(mrc.Fields(12)) = False Then '显示民族
        txtSQL1 = "select Ration_name from Ration_info where Ration_value = " & mrc.Fields(12)
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "民族信息有错!", 0 + 48, "注意!"
            Exit Sub
        End If
        Combo1(6).Text = mrc1.Fields(0)
        mrc1.Close
    End If
    If IsNull(mrc.Fields(11)) = False Then '显示职务
        txtSQL1 = "select Szw_name from Szw_info where Szw_value = " & mrc.Fields(11)
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "职务信息有错!", 0 + 48, "注意!"
            Exit Sub
        End If
        Combo1(7).Text = mrc1.Fields(0)
        mrc1.Close
    End If
    If IsNull(mrc.Fields(10)) = False Then '显示政治面貌
        txtSQL1 = "select Mm_name from Mm_info where Mm_value = " & mrc.Fields(10)
        Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
        If mrc1.EOF Then
            MsgBox "政治面貌信息有错!", 0 + 48, "注意!"
            Exit Sub
        End If
        Combo1(8).Text = mrc1.Fields(0)
        mrc1.Close
    End If
    If IsNull(mrc.Fields(8)) = False Then Text1(3).Text = mrc.Fields(8)
    If IsNull(mrc.Fields(13)) = False Then Text1(4).Text = mrc.Fields(13)
    For i = 5 To 12
        If IsNull(mrc.Fields(i + 9)) = False Then Text1(i).Text = mrc.Fields(i + 9)
    Next i
End Sub

Public Sub Initial_command() '定义过程初始化按钮
    Command1.Enabled = True
    Command2.Enabled = True
    Command3.Enabled = True
    Command4.Enabled = False
    Command5.Enabled = False
End Sub

Public Sub Blank_all() '定义过程使所有控件为空白
    For i = 0 To 12
        Text1(i).Text = ""
    Next i
    For i = 0 To 8
        Combo1(i).Text = ""
    Next i
End Sub


⌨️ 快捷键说明

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