frmqueryscore.frm

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

FRM
340
字号
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "Msflxgrd.ocx"
Begin VB.Form frmQueryScore 
   Caption         =   "成绩查询"
   ClientHeight    =   3825
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4935
   LinkTopic       =   "Form1"
   ScaleHeight     =   3825
   ScaleWidth      =   4935
   StartUpPosition =   3  'Windows Default
   Begin MSFlexGridLib.MSFlexGrid fgScore 
      Height          =   1455
      Left            =   120
      TabIndex        =   10
      Top             =   2280
      Width           =   4695
      _ExtentX        =   8281
      _ExtentY        =   2566
      _Version        =   393216
   End
   Begin VB.CommandButton Command2 
      Caption         =   "取消(&N)"
      Height          =   375
      Left            =   2640
      TabIndex        =   9
      Top             =   1800
      Width           =   1095
   End
   Begin VB.CommandButton cmdOK 
      Caption         =   "查询(&Y)"
      Height          =   375
      Left            =   1320
      TabIndex        =   8
      Top             =   1800
      Width           =   1095
   End
   Begin VB.Frame Frame1 
      Caption         =   "查询方式"
      Height          =   1575
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   4695
      Begin VB.TextBox txtScore2 
         Height          =   285
         Left            =   3840
         TabIndex        =   12
         Text            =   "Text1"
         Top             =   1080
         Width           =   615
      End
      Begin VB.TextBox txtScore1 
         Height          =   285
         Left            =   3000
         TabIndex        =   7
         Text            =   "Text3"
         Top             =   1080
         Width           =   615
      End
      Begin VB.ComboBox cboOperator 
         Height          =   315
         Left            =   1680
         TabIndex        =   6
         Text            =   "Combo1"
         Top             =   1080
         Width           =   1095
      End
      Begin VB.TextBox txtCourseNo 
         Height          =   285
         Left            =   1680
         TabIndex        =   5
         Text            =   "Text2"
         Top             =   720
         Width           =   1695
      End
      Begin VB.TextBox txtStuNo 
         Height          =   285
         Left            =   1680
         TabIndex        =   4
         Text            =   "Text1"
         Top             =   360
         Width           =   1695
      End
      Begin VB.CheckBox chkOp 
         Caption         =   "按成绩"
         Height          =   255
         Index           =   2
         Left            =   360
         TabIndex        =   3
         Top             =   1080
         Width           =   1215
      End
      Begin VB.CheckBox chkOp 
         Caption         =   "按课程编号"
         Height          =   255
         Index           =   1
         Left            =   360
         TabIndex        =   2
         Top             =   720
         Width           =   1335
      End
      Begin VB.CheckBox chkOp 
         Caption         =   "按学号"
         Height          =   255
         Index           =   0
         Left            =   360
         TabIndex        =   1
         Top             =   360
         Width           =   1335
      End
      Begin VB.Label Label1 
         Caption         =   "----"
         Height          =   255
         Left            =   3600
         TabIndex        =   11
         Top             =   1080
         Width           =   255
      End
   End
End
Attribute VB_Name = "frmQueryScore"
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

Sub initForm()
  txtStuNo.Text = ""
  txtCourseNo.Text = ""
  txtScore1.Text = ""
  txtScore2.Text = ""
  txtScore2.Visible = False
  Label1.Visible = False
    
  cboOperator.Clear
  cboOperator.AddItem "="
  cboOperator.AddItem "<"
  cboOperator.AddItem ">"
  cboOperator.AddItem "between"
  cboOperator.ListIndex = 0
End Sub

Private Sub cboOperator_Click()
   If cboOperator.Text = "between" Then
         Label1.Visible = True
         txtScore2.Visible = True
   Else
         Label1.Visible = False
         txtScore2.Visible = False
   End If
End Sub

Private Sub chkOp_Click(Index As Integer)
   If Index = 2 Then
      If chkOp(2).Value = 1 Then
         cboOperator.Enabled = True
         txtScore1.Enabled = True
         txtScore2.Enabled = True
      Else
         cboOperator.Enabled = False
         txtScore1.Enabled = False
         txtScore2.Enabled = False
      End If
   End If
End Sub

Private Sub cmdOK_Click()
Dim rs As ADODB.Recordset
Dim i As Integer
Dim j As Integer

Dim sqlstr1 As String
Dim sqlcond1 As String
Dim sqlcond2 As String
Dim sqlcond3 As String
Dim sign As Boolean

sqlcond1 = ""
sqlcond2 = ""
sqlcond3 = ""
sign = False

sqlStr = "select studentInfo.stu_no as stuNo,studentInfo.name as stuName," _
    & "courseInfo.course_name as courseName,scoreInfo.course_score as score" _
    & " from studentInfo,courseInfo,scoreInfo WHERE "


'检查是否已选择了查询条件

If chkOp(0).Value <> 1 And chkOp(1).Value <> 1 And chkOp(2).Value <> 1 Then
   MsgBox "请选择查询条件!!!"
   Exit Sub
End If

'获得子查询条件

If chkOp(0).Value = 1 Then
    sqlcond1 = "studentInfo.stu_no='" & Trim(txtStuNo.Text) & "'"
End If

If chkOp(1).Value = 1 Then
    sqlcond2 = "scoreInfo.course_no='" & Trim(txtCourseNo.Text) & "'"
End If

If chkOp(2).Value = 1 Then
    If cboOperator.Text <> "between" Then
       sqlcond3 = "scoreInfo.course_score" & cboOperator.Text & Trim(txtScore1.Text)
    Else
       sqlcond3 = "scoreInfo.course_score " & cboOperator.Text & " " & Trim(txtScore1.Text) & "AND " & Trim(txtScore2.Text)
    End If
End If

If sqlcond1 <> "" Then
    sqlStr = sqlStr & sqlcond1
    sign = True
End If

If sqlcond2 <> "" Then
    If sign = True Then
       sqlStr = sqlStr & " AND " & sqlcond2
    Else
       sqlStr = sqlStr & sqlcond2
    End If
End If

If sqlcond3 <> "" Then
    If sign = True Then
       sqlStr = sqlStr & " AND " & sqlcond3
    Else
       sqlStr = sqlStr & sqlcond3
    End If
End If

sqlStr = sqlStr & " AND studentInfo.stu_no=scoreInfo.stu_no" _
    & " AND courseInfo.course_no = scoreInfo.course_no"


Set rs = ExecuteSQL(sqlStr, msgText)

If rs.RecordCount = 0 Then

    MsgBox "没有查找满足条件的数据!", vbExclamation, "提示"
    fgScore.Clear
   
Else
    fgScore.Rows = rs.RecordCount + 1
    
    fgScore.Cols = 5
    
    'Print fgScore.Rows
    
    '设定行高
    For i = 0 To fgScore.Rows - 1
       fgScore.RowHeight(i) = 280
    Next i
    
    '设定列的属性
    fgScore.Row = 0
    
    For i = 0 To fgScore.Cols - 1
       fgScore.Col = i  '指定当前列为第i列
       fgScore.FixedAlignment(i) = 4  '每列内容居中显示
       Select Case i
           Case 0
              fgScore.ColWidth(i) = 620  '设定列宽
              fgScore.Text = "序号"
           Case 1
              fgScore.ColWidth(i) = 920  '设定列宽
              fgScore.Text = "学号"
           Case 2
              fgScore.ColWidth(i) = 1000  '设定列宽
              fgScore.Text = "姓名"
           Case 3
              fgScore.ColWidth(i) = 1500  '设定列宽
              fgScore.Text = "课程"
           Case 4
              fgScore.ColWidth(i) = 700  '设定列宽
              fgScore.Text = "成绩"
        End Select
           
    Next i
       
       
    'rs.MoveFirst
    
    i = 1
    
    While (Not rs.EOF)
    
       fgScore.Row = i
       For j = 0 To fgScore.Cols - 1
       
        fgScore.Col = j '设置当前为列为第j列
        fgScore.CellAlignment = 4  '每列内容居中显示
    
        
        Select Case j
            Case 0
               fgScore.Text = "" & i
            Case 1
               fgScore.Text = rs.Fields("stuNo")
            Case 2
               fgScore.Text = rs.Fields("stuName")
            Case 3
               fgScore.Text = rs.Fields("courseName")
            Case 4
               fgScore.Text = rs.Fields("score")
        End Select
      Next j
    
        rs.MoveNext
        i = i + 1
    Wend
    fgScore.Visible = True

End If

rs.Close

End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()

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

initForm
End Sub

⌨️ 快捷键说明

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