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

📄 addclass.frm

📁 这是一个我帮师妹做的软件的大作业
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Width           =   2415
      End
      Begin VB.TextBox Text1 
         Appearance      =   0  'Flat
         BackColor       =   &H80000018&
         BeginProperty Font 
            Name            =   "宋体"
            Size            =   14.25
            Charset         =   134
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   345
         Index           =   4
         Left            =   3240
         MaxLength       =   9
         TabIndex        =   29
         Top             =   480
         Width           =   2415
      End
      Begin VB.Frame Frame2 
         Height          =   855
         Left            =   0
         TabIndex        =   21
         Top             =   3840
         Width           =   8175
         Begin VB.CommandButton okCom 
            Caption         =   "确定"
            Height          =   375
            Left            =   2520
            TabIndex        =   23
            Top             =   240
            Width           =   975
         End
         Begin VB.CommandButton reCom 
            Caption         =   "重填"
            Height          =   375
            Left            =   4920
            TabIndex        =   22
            Top             =   240
            Width           =   975
         End
      End
      Begin VB.Label Label4 
         Alignment       =   2  'Center
         Caption         =   "重要系数:"
         Height          =   375
         Left            =   1920
         TabIndex        =   4
         Top             =   2400
         Width           =   975
      End
      Begin VB.Label Label3 
         Alignment       =   2  'Center
         Caption         =   "学  时:"
         Height          =   375
         Left            =   1920
         TabIndex        =   3
         Top             =   1800
         Width           =   975
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Caption         =   "学  分:"
         Height          =   375
         Left            =   1920
         TabIndex        =   2
         Top             =   1200
         Width           =   975
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         Caption         =   "课程名称:"
         Height          =   375
         Left            =   1920
         TabIndex        =   1
         Top             =   600
         Width           =   975
      End
   End
   Begin VB.Image Image1 
      Height          =   4695
      Left            =   0
      Picture         =   "addclass.frx":252B
      Stretch         =   -1  'True
      Top             =   840
      Width           =   8175
   End
End
Attribute VB_Name = "addclass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim mrc As ADODB.Recordset
'记录当前记录的位置
Dim mybookmark As Variant
'判断是否修改记录
Dim mcclean As Boolean

Private Sub cancelCommand_Click(Index As Integer)
If Not mcclean Then
firstCommand(0).Enabled = True
previousCommand(3).Enabled = True
nextCommand(2).Enabled = True
lastCommand(1).Enabled = True
Text1(0).Enabled = False
Text1(1).Enabled = False
Text1(2).Enabled = False
Text1(3).Enabled = False
mrc.Bookmark = mybookmark
Call viewData
Else
MsgBox "没有监测到修改的信息,您必须对记录修改以后才可以取消!", vbOKOnly + vbExclamation, "警告"
End If
End Sub

Private Sub Command1_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
txtSQL = "select * from course"
Set mrc = ExecuteSQL(txtSQL)
With myflexgrid
.Rows = 2
.CellAlignment = 4
.TextMatrix(1, 1) = "课程名称"
.TextMatrix(1, 2) = "学分"
.TextMatrix(1, 3) = "学时"
.TextMatrix(1, 4) = "重要系数"
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)
mrc.MoveNext
Loop
End With
mrc.Close
End Sub

Private Sub deletCommand_Click(Index As Integer)
mybookmark = mrc.Bookmark
    str2$ = MsgBox("是否删除当前记录?", vbOKCancel, "删除当前记录")
    If str2$ = vbOK Then
            mrc.MoveNext
            If mrc.EOF Then
                mrc.MoveFirst
                mybookmark = mrc.Bookmark
                mrc.MoveLast
                mrc.Delete
                mrc.Bookmark = mybookmark
                Call viewData
            Else
                mybookmark = mrc.Bookmark
                mrc.MovePrevious
                mrc.Delete
                mrc.Bookmark = mybookmark
                Call viewData
            End If
    Else
        mrc.Bookmark = mybookmark
        Call viewData
    End If
End Sub

Private Sub editCommand_Click(Index As Integer)
 mcclean = False
firstCommand(0).Enabled = False
previousCommand(3).Enabled = False
nextCommand(2).Enabled = False
lastCommand(1).Enabled = False
Text1(0).Enabled = True
Text1(1).Enabled = True
Text1(2).Enabled = True
Text1(3).Enabled = True
mybookmark = mrc.Bookmark
End Sub

Private Sub firstCommand_Click(Index As Integer)
mrc.MoveFirst
Call viewData

End Sub

Private Sub Form_Load()
Dim txtSQL As String
   txtSQL1 = "select * from course"
Set mrc = ExecuteSQL(txtSQL1)
mrc.MoveFirst
   '显示数据
    Call viewData
    mcbookmark = mrc.Bookmark
    mcclean = True
End Sub

Private Sub Text1_GotFocus(Index As Integer)
Text1(Index).SelStart = 0
Text1(Index).SelLength = Len(Text1(Index).Text)
End Sub
Private Sub Form_Unload(Cancel As Integer)
    frmMain.Enabled = True
    Unload Me
End Sub

Private Sub lastCommand_Click(Index As Integer)
mrc.MoveLast
Call viewData
End Sub

Private Sub nextCommand_Click(Index As Integer)
mrc.MoveNext
If mrc.EOF Then
mrc.MoveFirst
End If
Call viewData
End Sub

Private Sub okCom_Click()
Dim mrc As ADODB.Recordset
If Not Testtxt(Text1(4).Text) Then
MsgBox "请输入课程名称!", vbOKOnly + vbExclamation, "警告"
Text1(4).SetFocus
Exit Sub
End If
If Not Testtxt(Text1(5).Text) Then
MsgBox "请输入学分!", vbOKOnly + vbExclamation, "警告"
Text1(5).SetFocus
Exit Sub
End If
If Not IsNumeric(Text1(5).Text) Then
MsgBox "学分必须输入数字!", vbOKOnly + vbExclamation, "警告"
Text1(5).Text = ""
Text1(5).SetFocus
Exit Sub
End If
If Not Testtxt(Text1(6).Text) Then
MsgBox "请输入学时!", vbOKOnly + vbExclamation, "警告"
Text1(6).SetFocus
Exit Sub
End If
If Not IsNumeric(Text1(6).Text) Then
MsgBox "学时必须输入数字!", vbOKOnly + vbExclamation, "警告"
Text1(6).Text = ""
Text1(6).SetFocus
Exit Sub
End If
If Not Testtxt(Text1(7).Text) Then
MsgBox "请输入重要系数!", vbOKOnly + vbExclamation, "警告"
Text1(7).SetFocus
Exit Sub
End If
If Not IsNumeric(Text1(7).Text) Then
MsgBox "重要系数必须输入数字!", vbOKOnly + vbExclamation, "警告"
Text1(7).Text = ""
Text1(7).SetFocus
Exit Sub
End If
txtSQL1 = "select * from course where 课程名称='" & Trim(Text1(4).Text) & "'"
Set mrc = ExecuteSQL(txtSQL1)
If modi = False Then
If mrc.EOF = False Then
sss = MsgBox("已经存在该课程的记录,课程名称不能重复!", vbExclamation + vbOKOnly, "警告")
Text1(4).SetFocus
Text1(4).SelStart = 0
Text1(4).SelLength = Len(Text1(4).Text)
mrc.Close
Exit Sub
End If
End If
If modi = True Then

txtSQL1 = "update  course  set 课程名称='" & Trim(Text1(4).Text) & "',学分='" & Trim(Text1(5).Text) & "',学时='" & Trim(Text1(6).Text) & "',重要系数='" & Trim(Text1(7).Text) & "''"

Set mrc = ExecuteSQL(txtSQL1)
Unload Me
Exit Sub
End If
txtSQL1 = "select * from course"
Set mrc = ExecuteSQL(txtSQL1)
mrc.AddNew
mrc.Fields(1) = Trim(Text1(4).Text)
mrc.Fields(2) = Trim(Val(Text1(5).Text))
mrc.Fields(3) = Trim(Val(Text1(6).Text))
mrc.Fields(4) = Trim(Val(Text1(7).Text))
mrc.Update
Set mrc = Nothing
For j = 4 To 7
Text1(j).Text = ""
Next
End Sub

Private Sub previousCommand_Click(Index As Integer)
mrc.MovePrevious
If mrc.BOF Then
mrc.MoveLast
End If
Call viewData
End Sub

Private Sub reCom_Click()
  Text1(4).Text = ""
  Text1(5).Text = ""
  Text1(6).Text = ""
  Text1(7).Text = ""
End Sub

Private Sub seeCom_Click()
    
Dim txtSQL As String

Dim mrc As ADODB.Recordset
txtSQL = "select * from course"
Set mrc = ExecuteSQL(txtSQL)
With MSFlexGrid1
.Rows = 2
.CellAlignment = 4
.TextMatrix(0, 1) = "序号"
.TextMatrix(0, 2) = "课程名称"
.TextMatrix(0, 3) = "学分"
.TextMatrix(0, 4) = "学时"
.TextMatrix(0, 5) = "重要系数"
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)

    mrc.MoveNext
Loop
End With
    mrc.Close
End Sub

Public Sub viewData()
Text1(0).Text = mrc.Fields(1)
Text1(1).Text = mrc.Fields(2)
Text1(2).Text = mrc.Fields(3)
Text1(3).Text = mrc.Fields(4)
End Sub


Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Index
Case 1
  seeFra.Visible = False
    chaFra.Visible = False
    addFra.Visible = True
Case 2
seeFra.Visible = False
    addFra.Visible = False
    chaFra.Visible = True
Case 3
addFra.Visible = False
    chaFra.Visible = False
    seeFra.Visible = True
Case 4
seeFra.Visible = False
    addFra.Visible = False
    chaFra.Visible = True

End Select

End Sub

Private Sub updateCommand_Click(Index As Integer)
 Dim txtSQL As String
    Dim MsgText As String
    Dim mrcc As ADODB.Recordset
    
    If mcclean Then
        MsgBox "请先修改课程信息", vbOKOnly + vbExclamation, "警告"
        Exit Sub
    End If
    
    If Not Testtxt(Text1(0)) Then
        MsgBox "请输入课程名称!", vbOKOnly + vbExclamation, "警告"
        Text1(0).SetFocus
        Exit Sub
    End If
    
    If Not Testtxt(Text1(1)) Then
        MsgBox "请输入课程学分!", vbOKOnly + vbExclamation, "警告"
        Text1(1).SetFocus
        Exit Sub
    End If
    
   If Not Testtxt(Text1(2).Text) Then
        MsgBox "请输入学时!", vbOKOnly + vbExclamation, "警告"
       Text1(2).SetFocus
        Exit Sub
    End If
    
    If Not Testtxt(Text1(3).Text) Then
        MsgBox "请输入重要系数!", vbOKOnly + vbExclamation, "警告"
       Text1(3).SetFocus
        Exit Sub
    End If
mrc.Delete
mrc.AddNew
mrc.Fields(1) = Trim(Text1(0).Text)
mrc.Fields(2) = Trim(Val(Text1(1).Text))
mrc.Fields(3) = Trim(Val(Text1(2).Text))
mrc.Fields(4) = Trim(Val(Text1(3).Text))
mrc.Update
MsgBox "修改信息成功!", vbOKOnly + vbExclamation, "警告"

Call viewData

firstCommand(0).Enabled = True
previousCommand(3).Enabled = True
nextCommand(2).Enabled = True
lastCommand(1).Enabled = True
Text1(0).Enabled = False
Text1(1).Enabled = False
Text1(2).Enabled = False
Text1(3).Enabled = False
mcclean = True
End Sub

⌨️ 快捷键说明

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