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

📄 form2.frm

📁 模拟学生选课系统
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form frmAddGrade 
   BackColor       =   &H00C0C0C0&
   Caption         =   "Form2"
   ClientHeight    =   3165
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5385
   LinkTopic       =   "Form2"
   ScaleHeight     =   3165
   ScaleWidth      =   5385
   StartUpPosition =   3  '窗口缺省
   Begin VB.ComboBox Combo1 
      BackColor       =   &H00C0FFFF&
      Height          =   300
      Left            =   1200
      TabIndex        =   7
      Top             =   480
      Width           =   2175
   End
   Begin VB.ComboBox Combo2 
      BackColor       =   &H00C0FFFF&
      Height          =   300
      ItemData        =   "Form2.frx":0000
      Left            =   1200
      List            =   "Form2.frx":0002
      TabIndex        =   6
      Top             =   960
      Width           =   2175
   End
   Begin VB.TextBox Text2 
      BackColor       =   &H00C0FFFF&
      Height          =   300
      Left            =   1200
      TabIndex        =   5
      Top             =   1440
      Width           =   2175
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   480
      Top             =   2400
      Visible         =   0   'False
      Width           =   1935
      _ExtentX        =   3413
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   2
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db5.mdb;Persist Security Info=False"
      OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db5.mdb;Persist Security Info=False"
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "学生与课程"
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton Command4 
      Caption         =   "退出"
      Height          =   375
      Left            =   3960
      TabIndex        =   4
      Top             =   2280
      Width           =   1335
   End
   Begin VB.CommandButton Command3 
      Caption         =   "删除"
      Height          =   375
      Left            =   3960
      TabIndex        =   3
      Top             =   1200
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "添加"
      Height          =   375
      Left            =   3960
      TabIndex        =   2
      Top             =   360
      Width           =   1335
   End
   Begin VB.Label Label7 
      BackColor       =   &H00C0C0C0&
      Caption         =   "课程号:"
      Height          =   255
      Left            =   240
      TabIndex        =   9
      Top             =   480
      Width           =   735
   End
   Begin VB.Label Label6 
      Caption         =   "Label6"
      Height          =   15
      Left            =   2040
      TabIndex        =   8
      Top             =   1560
      Width           =   1215
   End
   Begin VB.Label Label2 
      BackColor       =   &H00C0C0C0&
      Caption         =   "课程名称:"
      ForeColor       =   &H00000000&
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Top             =   960
      Width           =   975
   End
   Begin VB.Label Label1 
      BackColor       =   &H00C0C0C0&
      Caption         =   "学号:"
      ForeColor       =   &H00000000&
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   1440
      Width           =   855
   End
End
Attribute VB_Name = "frmAddGrade"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim rs As New ADODB.Recordset



Private Sub Command1_Click()
'On Error GoTo errh
If Combo1.Text <> "" Then
 If Combo2.Text <> "" Then
   If Text2.Text <> "" Then
      'If Text3.Text <> "" Then
       'If Combo3.Text <> "" Then
        If checkclass Then
          If checkcourse Then
            ' If match = True Then
               With Adodc1.Recordset
               .AddNew
                .Fields("课程号").Value = Combo1.Text
                .Fields("学号").Value = Text2.Text
                      
                .Fields("课程名称").Value = Combo2.Text
                .Update
                End With
                  MsgBox "添加成功!"
                  Combo1.Text = ""
                  Combo2.Text = ""
                  'Combo3.Text = ""
                  Text2.Text = ""
                 ' Text3.Text = ""
             
           Else
               MsgBox "没有这个课程,不能添加!"
              ' Combo3.Text = ""
               Text2.Text = ""
              ' Text3.Text = ""
               Combo1.Text = ""
               Combo2.Text = ""
               Combo1.SetFocus
         ' End If
       ' "
        ' Text3.SetFocus
      End If
     'Else
          'MsgBox "备注不能为空,请输入备注!"
     End If
    Else
      MsgBox "学号不能为空,请输入学号!"
      Text2.SetFocus
    End If
  Else
    MsgBox "课程名称不能为空,请输入课程名称!"
    Combo2.SetFocus
  End If
 Else
   MsgBox "课程号不能为空,请输入课程号!"
   Combo1.SetFocus
 End If
  Exit Sub
'errh:
    'MsgBox Err.Description
End Sub



Private Sub Command3_Click()
On Error GoTo errh
    
    If MsgBox("你的操作将会删除当前的纪录,你确信吗?", vbOKCancel, "警告") = vbOK Then
    'Combo1.DataSource = Adodc2
    'Combo2.DataSource = Adodc2
    'Combo3.DataSource = Adodc2
    'Text2.DataSource = Adodc2
    'Text3.DataSource = Adodc2
        'SD = True
        'Adodc1.Recordset.Delete
       ' Adodc1.Recordset.MoveFirst
'       Dim str As String
'       str = " delete from 学生与课程 " 'where  课程号='" & Trim(Combo1.Text) & "' and  课程名称= '" & Trim(Combo2.Text) & "' and 学号= '" & Trim(Text2.Text) & "' and 成绩= '" & Trim(Text3.Text) & "' "
'       Dim cmd As New ADODB.Command
'       cmd.ActiveConnection = cn
'
'       cmd.CommandText = str
'       cmd.CommandType = adCmdText
'
'        cmd.Execute
        'rs.Open
      '  Dim rs1 As New ADODB.Recordset
        'Set rs1 = Nothing
        'rs1.CursorType = adOpenDynamic
        'rs1.LockType = adLockOptimistic
        rs.Open "SELECT * FROM 学生与课程 WHERE 课程名称='" & Trim(Combo2.Text) & "'AND 课程号='" & Trim(Combo1.Text) & "' and  学号='" & Trim(Text2.Text) & "'", cn, adOpenDynamic, adLockOptimistic, adCmdText
       'Set rs1 = cn.Execute("SELECT * FROM 学生与课程 WHERE 课程名称='" & Trim(Combo2.Text) & "'AND 课程号='" & Trim(Combo1.Text) & "' and  学号='" & Trim(Text2.Text) & "' And 成绩 = '" & Trim(Text3.Text) & "' ")
       'If Adodc2.Recordset.EOF Then
       If rs.EOF Then
          'Adodc2.Recordset.Close
          rs.Close
          MsgBox "没有这条记录,无法删除!"
          Exit Sub
       End If
       'Adodc2.Recordset.Delete
       'Adodc2.Recordset.Update
       'Adodc2.Recordset.Close
       rs.Delete
       rs.Update
       rs.Close
       MsgBox "删除成功!"
       Text2.Text = ""
      ' Text3.Text = ""
       Combo1.Text = ""
       Combo2.Text = ""
      ' Combo3.Text = ""
    End If
    Exit Sub
errh:
    rs.Close
    MsgBox Err.Description
End Sub

Private Sub Command4_Click()
Unload Me
End Sub

Private Sub Form_Load()
On Error GoTo errh
    MakeCenter frmAddGrade
    Set rs = cn.Execute("SELECT 课程名称,课程号 FROM 课程")
    rs.MoveFirst
    Do
        Combo1.AddItem rs.Fields(1).Value
        Combo2.AddItem rs.Fields(0).Value
        rs.MoveNext
    Loop Until rs.EOF
    '///////////////////////////////////
   
    Exit Sub
errh:
    rs.Close
    MsgBox Err.Description
End Sub

Private Function checkcourse() As Boolean
On Error GoTo errh
 Set rs = cn.Execute("select * from 课程 where 课程号='" & Trim(Combo1.Text) & "' and 课程名称='" & Trim(Combo2.Text) & "'")
 'If Adodc2.Recordset.EOF Then
    'Adodc2.Recordset.Close
    If rs.EOF Then
       rs.Close
       checkcourse = False
    Exit Function
End If
checkcourse = True
rs.Close
Exit Function
errh:
    rs.Close
    MsgBox Err.Description
End Function
Private Function checkclass() As Boolean '检测添加的课程是否重复
On Error GoTo errh
     ' Adodc2.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
                   "DBQ=db5.MDB;" & _
                   "DefaultDir=" & CheckPath(App.path) & ";" & _
                   "UID=;PWD=;"
    Set rs = cn.Execute("SELECT 课程名称 FROM 学生与课程 WHERE 课程名称='" & Trim(Combo2.Text) & "'AND 课程号='" & Trim(Combo1.Text) & "' and  学号='" & Trim(Text2.Text) & "' And 成绩 Is Not Null ")
    ' Adodc2.RecordSource = "select * from 课程 where 课程号='" & Trim(Text1.Text) & "' and 课程名称='" & Trim(Text2.Text) & "' "
        If rs.EOF Then
            rs.Close
            checkclass = True
            Exit Function
        End If
    checkclass = False
    rs.Close
    Exit Function
errh:
    rs.Close
    MsgBox Err.Description
End Function

⌨️ 快捷键说明

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