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

📄 frmbasiccourse.frm

📁 学生信息管理系统
💻 FRM
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.ocx"
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form frmBasicCourse 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "基本课程设置"
   ClientHeight    =   4695
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   3525
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   4695
   ScaleWidth      =   3525
   Begin VB.TextBox txtBooks 
      BackColor       =   &H80000018&
      Enabled         =   0   'False
      Height          =   350
      Left            =   960
      TabIndex        =   5
      Top             =   3720
      Width           =   2415
   End
   Begin VB.TextBox txtCourseName 
      BackColor       =   &H80000018&
      Enabled         =   0   'False
      Height          =   350
      Left            =   960
      TabIndex        =   4
      Top             =   3240
      Width           =   2415
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "增加"
      Height          =   375
      Left            =   1200
      TabIndex        =   2
      Top             =   4200
      Width           =   1095
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "删除"
      Height          =   375
      Left            =   2280
      TabIndex        =   1
      Top             =   4200
      Width           =   1095
   End
   Begin VB.CommandButton cmdModify 
      Caption         =   "修改"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   4200
      Width           =   1095
   End
   Begin MSFlexGridLib.MSFlexGrid flgCourse 
      Height          =   3015
      Left            =   120
      TabIndex        =   3
      Top             =   120
      Width           =   3285
      _ExtentX        =   5794
      _ExtentY        =   5318
      _Version        =   393216
      BackColor       =   -2147483624
      BackColorFixed  =   12632256
      ForeColorFixed  =   0
      BackColorSel    =   16777215
      ForeColorSel    =   255
      BackColorBkg    =   -2147483624
      AllowBigSelection=   -1  'True
      SelectionMode   =   1
      AllowUserResizing=   3
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin MSAdodcLib.Adodc adoCourse 
      Height          =   375
      Left            =   120
      Top             =   5400
      Visible         =   0   'False
      Width           =   2160
      _ExtentX        =   3810
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      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.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "教材"
      Height          =   180
      Index           =   1
      Left            =   120
      TabIndex        =   7
      Top             =   3810
      Width           =   360
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "课程名称"
      Height          =   180
      Index           =   0
      Left            =   120
      TabIndex        =   6
      Top             =   3325
      Width           =   720
   End
End
Attribute VB_Name = "frmBasicCourse"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'----------------------------------frmBasicCourse.frm----------------------------------
Option Explicit

'在表格中显示标题
Public Sub kechengshowtitle()
    flgCourse.Clear
    Dim i As Integer
    With flgCourse
        .Cols = 3
        .TextMatrix(0, 1) = "课程名称"
        .TextMatrix(0, 2) = "教材"
        
        .ColWidth(0) = 0
        .ColWidth(1) = 1000
        .ColWidth(2) = 2000
        
        .FixedRows = 1
        
        .FillStyle = flexFillSingle
        .Col = 0
        .Row = 0
        .RowSel = 1
        .ColSel = .Cols - 1
        .CellAlignment = 4
        .Row = 1
    End With
End Sub

'添加课程
Private Sub cmdAdd_Click()
    strUserManage = UserManage(4)
    If strUserManage = "ReadOnly" Then
        MsgBox "对不起,你是只读用户不能添加记录,请与管理员联系!", vbInformation + vbOKOnly, " 警告"
        Exit Sub
    End If
    
    '添加课程
    If cmdADD.Caption = "确定" Then
        If txtCourseName.Text = "" Then
            MsgBox "课程名称不能为空!", vbOKOnly + vbExclamation, "警告"
            txtCourseName.SetFocus
            Exit Sub
        End If
        
        If txtBooks.Text = "" Then
            MsgBox "教材不能为空!", vbOKOnly + vbExclamation, "警告"
            txtBooks.SetFocus
            Exit Sub
        End If
        
        '使用Adodc控件连接数据库
        adoCourse.RecordSource = "select * from Courses where 课程名称='" & Trim(txtCourseName.Text) & "'"
        adoCourse.Refresh
        '如果不存在数据记录
        If adoCourse.Recordset.EOF = False Then
            MsgBox "已经存在该课程名称!", vbOKOnly + vbExclamation, "警告"
            txtCourseName.SetFocus
            txtCourseName.SelStart = 0
            txtCourseName.SelLength = Len(txtCourseName.Text)
            Exit Sub
        '添加新课程
        Else
            adoCourse.Recordset.AddNew
            adoCourse.Recordset.Fields(0) = txtCourseName.Text
            adoCourse.Recordset.Fields(1) = txtBooks.Text
            adoCourse.Recordset.Update
            cmdADD.Caption = "增加"
            cmdDelete.Enabled = True
            cmdModify.Enabled = True
            txtCourseName.Text = ""
            txtBooks.Text = ""
            txtCourseName.Enabled = False
            txtBooks.Enabled = False
            kechengshowtitle
            ShowCourseData
        End If
    '进入添加状态
    Else
        txtCourseName.Enabled = True
        txtBooks.Enabled = True
        txtCourseName.Text = ""
        txtBooks.Text = ""
        txtCourseName.SetFocus
        kechengshowtitle
        ShowCourseData
        cmdADD.Caption = "确定"
        cmdDelete.Enabled = False
        cmdModify.Enabled = False
    End If
End Sub

'删除选中的课程
Private Sub cmdDelete_Click()
    strUserManage = UserManage(4)
    If strUserManage = "ReadOnly" Then
        MsgBox "对不起,你是只读用户不能添加记录,请与管理员联系!", vbInformation + vbOKOnly, " 警告"
        Exit Sub
    End If
    
    If Trim(flgCourse.TextMatrix(flgCourse.Row, 1)) = "" Then
        MsgBox "你还没有选择记录!", vbOKOnly + vbExclamation, "警告"
    '删除选中的课程
    Else
        If MsgBox("确定要删除 课程名称 为 " & Trim(Me.flgCourse.TextMatrix(flgCourse.Row, 1)) & " 的记录吗?", vbOKCancel + vbExclamation, "警告") = vbOK Then
            adoCourse.RecordSource = "select * from Courses where 课程名称='" & Trim(Me.flgCourse.TextMatrix(flgCourse.Row, 1)) & "'"
            adoCourse.Refresh
            adoCourse.Recordset.Delete
            txtCourseName.Text = ""
            txtBooks.Text = ""
            kechengshowtitle
            ShowCourseData
        End If
    End If
End Sub

'修改课程
Private Sub cmdModify_Click()
    strUserManage = UserManage(4)
    If strUserManage = "ReadOnly" Then
        MsgBox "对不起,你是只读用户不能修改记录,请与管理员联系!", vbInformation + vbOKOnly, " 警告"
        Exit Sub
    End If
    
    If Trim(Me.flgCourse.TextMatrix(flgCourse.Row, 1)) = "" Then
        MsgBox "你还没有选择记录!", vbOKOnly + vbExclamation, "警告"
    '修改课程
    Else
        '修改课程,并保存到数据库
        If cmdModify.Caption = "确定" Then
            '判断输入条件
            If txtCourseName.Text = "" Then
                MsgBox "课程名称不能为空!", vbOKOnly + vbExclamation, "警告"
                txtCourseName.SetFocus
                Exit Sub
            End If
            
            If txtBooks.Text = "" Then
                MsgBox "教材不能为空!", vbOKOnly + vbExclamation, "警告"
                txtBooks.SetFocus
                Exit Sub
            End If
            
            '将修改好的数据保存到数据库
            adoCourse.RecordSource = "select * from Courses where 课程名称='" & Trim(Me.flgCourse.TextMatrix(flgCourse.Row, 1)) & "'"
            adoCourse.Refresh
            adoCourse.Recordset.Fields(0) = txtCourseName.Text
            adoCourse.Recordset.Fields(1) = txtBooks.Text
            adoCourse.Recordset.Update
            txtCourseName.Text = ""
            txtBooks.Text = ""
            kechengshowtitle
            ShowCourseData
            cmdModify.Caption = "修改"
            cmdADD.Enabled = True
            cmdDelete.Enabled = True
            txtCourseName.Enabled = False
            txtBooks.Enabled = False
        '进入修改状态
        Else
            txtCourseName.Enabled = True
            txtBooks.Enabled = True
            txtCourseName.SetFocus
            cmdModify.Caption = "确定"
            cmdADD.Enabled = False
            cmdDelete.Enabled = False
        End If
    End If
End Sub

Private Sub Form_Load()
    adoCourse.ConnectionString = ConnectString
    kechengshowtitle
    ShowCourseData
End Sub

'将课程数据显示到数据表中
Public Sub ShowCourseData()
    Dim i As Integer
    Dim objRecordset As ADODB.Recordset
    
    adoCourse.RecordSource = "select * from Courses order by 课程名称"
    adoCourse.Refresh
    If adoCourse.Recordset.EOF = False Then
        adoCourse.Recordset.MoveFirst
        With flgCourse
            .Rows = 15
            .Row = 2
            
            Do While Not adoCourse.Recordset.EOF
                .Rows = .Rows + 1
                For i = 1 To adoCourse.Recordset.Fields.Count
                    .TextMatrix(.Row - 1, i) = adoCourse.Recordset.Fields(i - 1)
                Next i
                .Row = .Row + 1
                adoCourse.Recordset.MoveNext
            Loop
        End With
    End If
End Sub

'单击表格中的数据,将其显示到TextBox控件中
Private Sub flgCourse_Click()
    If Trim(flgCourse.TextMatrix(flgCourse.Row, 1)) = "" Then
        txtCourseName.Text = ""
        txtBooks.Text = ""
    Else
        adoCourse.RecordSource = "select * from Courses where 课程名称='" & Trim(flgCourse.TextMatrix(flgCourse.Row, 1)) & "'"
        adoCourse.Refresh
        txtCourseName.Text = adoCourse.Recordset.Fields(0)
        txtBooks.Text = adoCourse.Recordset.Fields(1)
    End If
End Sub

⌨️ 快捷键说明

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