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

📄 课程信息管理.frm

📁 初学vb,做的第一个系统.一个星期内看vb并做完这个系统的.
💻 FRM
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form sub_manage 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "课程信息管理"
   ClientHeight    =   3075
   ClientLeft      =   4800
   ClientTop       =   4125
   ClientWidth     =   5520
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   3075
   ScaleWidth      =   5520
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   120
      Top             =   2640
      Visible         =   0   'False
      Width           =   1305
      _ExtentX        =   2302
      _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         =   "Provider=MSDASQL.1;Persist Security Info=False;Data Source=stu_manage"
      OLEDBString     =   "Provider=MSDASQL.1;Persist Security Info=False;Data Source=stu_manage"
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   "sa"
      Password        =   "manager"
      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 Command3 
      Caption         =   "删除"
      Height          =   375
      Left            =   4320
      TabIndex        =   12
      Top             =   2400
      Width           =   855
   End
   Begin VB.CommandButton Command2 
      Caption         =   "修改"
      Height          =   375
      Left            =   3060
      TabIndex        =   11
      Top             =   2400
      Width           =   855
   End
   Begin VB.CommandButton Command1 
      Caption         =   "添加"
      Height          =   375
      Left            =   1800
      TabIndex        =   10
      Top             =   2400
      Width           =   855
   End
   Begin VB.TextBox Text4 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1440
      TabIndex        =   9
      Top             =   1680
      Width           =   3735
   End
   Begin VB.TextBox Text3 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   3600
      TabIndex        =   7
      Top             =   915
      Width           =   1575
   End
   Begin VB.ComboBox Combo1 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   1440
      Style           =   2  'Dropdown List
      TabIndex        =   5
      Top             =   960
      Width           =   1095
   End
   Begin VB.TextBox Text2 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   3600
      TabIndex        =   3
      Top             =   120
      Width           =   1575
   End
   Begin VB.TextBox Text1 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   1440
      TabIndex        =   1
      Top             =   120
      Width           =   1095
   End
   Begin VB.Label Label5 
      Caption         =   "上课地点"
      Height          =   375
      Left            =   480
      TabIndex        =   8
      Top             =   1800
      Width           =   855
   End
   Begin VB.Label Label4 
      Caption         =   "授课教师"
      Height          =   375
      Left            =   2760
      TabIndex        =   6
      Top             =   1020
      Width           =   735
   End
   Begin VB.Label Label3 
      Caption         =   "课程类别"
      Height          =   375
      Left            =   480
      TabIndex        =   4
      Top             =   1020
      Width           =   855
   End
   Begin VB.Label Label2 
      Caption         =   "课程名称"
      Height          =   375
      Left            =   2760
      TabIndex        =   2
      Top             =   240
      Width           =   735
   End
   Begin VB.Label Label1 
      Caption         =   "课程编码"
      Height          =   375
      Left            =   480
      TabIndex        =   0
      Top             =   240
      Width           =   855
   End
End
Attribute VB_Name = "sub_manage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
    Public sub_id As String
    Public sub_name As String
    Public sub_type As String
    Public type_id As Integer
    Public teach_name As String
    Public address As String
    Public strS As String '定义一变量
    Public rs As New ADODB.Recordset
    Public adoconn As New ADODB.Connection 'Connection 对象代表了打开与数据源的连接。
    Public adocomm As New ADODB.Command 'Command 对象定义了将对数据源执行的指定命令。
    Public ReturnValue As Integer '调用存储过程的返回值
    
Public Sub connect()
    adoconn.ConnectionString = Adodc1.ConnectionString 'Adodc1为窗体中的ADO控件,并已成功连接数据库
    'adoconn.Open
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenKeyset
    rs.LockType = adLockOptimistic
End Sub

Private Sub fetch()
    Dim i As Integer
    sub_id = Val(Text1.Text)
    sub_name = Text2.Text
    sub_type = Combo1.Text
    teach_name = Text3.Text
    address = Text4.Text

    adoconn.Open
    rs.Open "select * from type", adoconn
    rs.MoveFirst
    For i = 0 To rs.RecordCount - 1
        If sub_type = rs.Fields("name") Then
            type_id = rs.Fields("id")
        End If
        rs.MoveNext
    Next i
    rs.Close
    adoconn.Close
End Sub

Private Sub clear()
    Text1.Text = ""
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
End Sub

Private Sub add()
    adoconn.Open
    rs.Open "select * from subject", adoconn
    rs.AddNew
    rs.Fields("id") = Trim(sub_id)
    rs.Fields("name") = sub_name
    rs.Fields("type") = type_id
    rs.Fields("teacher") = teach_name
    rs.Fields("addr") = address
    rs.Update
    rs.Close
    adoconn.Close
    MsgBox "课程添加成功!"
    Call clear
    Text1.SetFocus
End Sub

       
Private Sub Command1_Click()
    Call fetch
    If sub_id = 0 Then
        MsgBox "请输入课程编号!"
        Text1.SetFocus
        Exit Sub
    ElseIf Len(sub_name) = 0 Then
        MsgBox "请输入课程名称!"
        Text2.SetFocus
        Exit Sub
    ElseIf Len(sub_type) = 0 Then
        MsgBox "请选择课程类别!"
        Combo1.SetFocus
        Exit Sub
    ElseIf Len(teach_name) = 0 Then
        MsgBox "请输入授课教师姓名!"
        Text3.SetFocus
        Exit Sub
    ElseIf Len(address) = 0 Then
        MsgBox "请输入上课地点!"
        Text4.SetFocus
        Exit Sub
    End If
    
    Dim i As Integer
    
    '数据库中没有用户信息时
    adoconn.Open
    rs.Open "select * from subject", adoconn
    If rs.RecordCount <> 0 Then
        '数据库中至少存在一个用户信息,判断新输入的用户是否已经存在
        For i = 0 To rs.RecordCount - 1
            If sub_id = rs.Fields("id") Then
                MsgBox "该编号已经存在!"
                Call clear
                rs.Close
                adoconn.Close
                Exit Sub
            End If
            rs.MoveNext
        Next i
        '新输入的用户名在数据库中找不到,且输入不为空值,则添加进数据库
        rs.Close
    End If
    
    

    adoconn.Close
    Call add
        
    
    
    
End Sub

Private Sub Command2_Click()
    Unload Me
    sub_cd.Show
End Sub

Private Sub Command3_Click()
    Unload Me
    sub_cd.Show
End Sub

Private Sub Form_Load()
    Call connect
    adoconn.Open
    rs.Open "select * from type", adoconn
    Dim i As Integer
    rs.MoveFirst
    For i = 0 To rs.RecordCount - 1
        Combo1.AddItem rs.Fields("name")
        rs.MoveNext
    Next i
    rs.Close
    adoconn.Close
End Sub

⌨️ 快捷键说明

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