frmaddcourse.frm

来自「数据库课程设计」· FRM 代码 · 共 244 行

FRM
244
字号
VERSION 5.00
Begin VB.Form frmAddCourse 
   Caption         =   "课程管理-添加"
   ClientHeight    =   2400
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6630
   LinkTopic       =   "Form1"
   ScaleHeight     =   2400
   ScaleWidth      =   6630
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdCancel 
      Caption         =   "返回(&C)"
      Height          =   375
      Left            =   3120
      TabIndex        =   14
      Top             =   1800
      Width           =   1215
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "添加(&Y)"
      Height          =   375
      Left            =   1680
      TabIndex        =   13
      Top             =   1800
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "课程基本信息"
      Height          =   1575
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6375
      Begin VB.TextBox txtNo 
         Height          =   285
         Left            =   4320
         TabIndex        =   6
         Text            =   "Text1"
         Top             =   360
         Width           =   1815
      End
      Begin VB.TextBox txtName 
         Height          =   285
         Left            =   1200
         TabIndex        =   5
         Text            =   "Text3"
         Top             =   360
         Width           =   1815
      End
      Begin VB.ComboBox cboTeacher 
         Height          =   315
         Left            =   4320
         TabIndex        =   4
         Text            =   "Combo1"
         Top             =   720
         Width           =   1815
      End
      Begin VB.TextBox txtHours 
         Height          =   285
         Left            =   1200
         TabIndex        =   3
         Text            =   "Text2"
         Top             =   1080
         Width           =   1815
      End
      Begin VB.ComboBox cboType 
         Height          =   315
         Left            =   1200
         TabIndex        =   2
         Text            =   "Combo2"
         Top             =   720
         Width           =   1815
      End
      Begin VB.TextBox txtScore 
         Height          =   285
         Left            =   4320
         TabIndex        =   1
         Text            =   "Text4"
         Top             =   1080
         Width           =   1815
      End
      Begin VB.Label Label1 
         Caption         =   "课程编号:"
         Height          =   255
         Left            =   3360
         TabIndex        =   12
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "任课教师:"
         Height          =   255
         Left            =   3360
         TabIndex        =   11
         Top             =   720
         Width           =   1095
      End
      Begin VB.Label Label3 
         Caption         =   "课  程  名:"
         Height          =   255
         Left            =   240
         TabIndex        =   10
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label4 
         Caption         =   "课程类型:"
         Height          =   255
         Left            =   240
         TabIndex        =   9
         Top             =   720
         Width           =   975
      End
      Begin VB.Label Label5 
         Caption         =   "学  时  数:"
         Height          =   255
         Left            =   240
         TabIndex        =   8
         Top             =   1080
         Width           =   1095
      End
      Begin VB.Label Label6 
         Caption         =   "学        分:"
         Height          =   255
         Left            =   3360
         TabIndex        =   7
         Top             =   1080
         Width           =   1095
      End
   End
End
Attribute VB_Name = "frmAddCourse"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public sqlStr As String
Public msgText As String

Private Sub cmdCancel_Click()
Unload Me

End Sub

Private Sub cmdOK_Click()
   Dim rstCourse As ADODB.Recordset
   Dim courseNo As String
   Dim courseName As String
   Dim courseType As String
   Dim courseHours As String
   Dim score As String
   Dim teacher As String
   
   '获取数据
   courseNo = Trim(txtNo.Text)
   courseName = Trim(txtName.Text)
   courseType = cboType.Text
   courseHours = Trim(txtHours.Text)
   score = Trim(txtScore.Text)
   teacher = cboTeacher.Text
   
   If courseNo = "" Or courseName = "" Then
   
      MsgBox "请将信息补充完整", vbOKOnly + vbExclamation, "警告"

      Exit Sub
   
   End If
     
   
    '添加新记录
    sqlStr = "select * from courseInfo"
    Set rstCourse = ExecuteSQL(sqlStr, msgText)
    rstCourse.AddNew
    rstCourse.Fields("course_no") = courseNo
    rstCourse.Fields("course_name") = courseName
    rstCourse.Fields("course_type") = courseType
    rstCourse.Fields("course_hours") = courseHours
    rstCourse.Fields("score") = score
    rstCourse.Fields("teacher") = teacher
    
    rstCourse.Update
    rstCourse.Close
        
    MsgBox "课程信息添加完成!", vbOKOnly + vbExclamation, "警告"
    
    initForm

End Sub

Private Sub Form_Load()

'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2

initForm
End Sub

Sub initTeacher()
Dim rstTeacher As ADODB.Recordset

    '从数据库中读取所有教师并添加到组合列表框中
    '方便录入时进行选择
    sqlStr = "select name from teacherInfo"
    Set rstTeacher = ExecuteSQL(sqlStr, msgText)
    cboTeacher.Clear
    
    If Not rstTeacher.EOF Then
        
            Do While Not rstTeacher.EOF
                cboTeacher.AddItem Trim(rstTeacher.Fields(0))
                rstTeacher.MoveNext
            Loop
            cboTeacher.ListIndex = 0
        
    Else
        MsgBox "没有教师信息,请添加教师!", vbOKOnly + vbExclamation, "警告"
        
        Exit Sub
    End If
    rstTeacher.Close

End Sub

Sub initForm()
txtName = ""
txtNo = ""
txtHours = ""
txtScore = ""

cboType.Clear
cboType.AddItem "选修课"
cboType.AddItem "必修课"
cboType.ListIndex = 0

'初始化教师信息
initTeacher
End Sub

⌨️ 快捷键说明

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