机房收费系统之学生上机信息

前言

组合查询是机房三大难点之一,不过等做完之后会豁然开朗,原来就是一句话的事。虽然这样还是自己还是研究了好几天才弄明白。下面先来说一下我的思路。

思路

机房收费系统之学生上机信息

重点代码:

Private Sub ComboField2_Click()
    If ComboField2.Text = "上机日期" Or ComboField2.Text = "上机时间" Or ComboField2.Text = "下机日期" Or ComboField2.Text = "下机时间" Then
        txtContent2.Visible = False
        DTPicker2.Visible = True
    End If
        If ComboField2.Text = "上机日期" Or ComboField2.Text = "下机日期" Then
         DTPicker2.Format = dtpShortDate
         DTPicker2.Value = CDate(Format(DTPicker2.Value, "yyyy-mm-dd"))
        Else
        If ComboField2.Text = "上机时间" Or ComboField2.Text = "下机时间" Then
         DTPicker2.Format = dtpTime
         Else
        txtContent2.Visible = True
        DTPicker2.Visible = False
        End If
        End If
End Sub
Private Sub Command2_Click()
Dim mrc As ADODB.Recordset
Dim txtSQL, MsgText$
 txtSQL = "select*from Line_info "
    If Not testtxt(ComboField1.Text) Then
        MsgBox "请选择字段名", 48, "提示"
        Exit Sub
    Else
    If Not testtxt(ComboOpsign1.Text) Then
        MsgBox "请选择操作符", 48, "提示"
        Exit Sub
    Else
    If Not testtxt(txtContent1.Text) And Not testtxt(DTPicker1.Value) Then
        MsgBox "请输入要查询的内容", 48, "提示"
        Exit Sub
    Else
    If txtContent1.Visible = False Then
    txtSQL = "select*from Line_info where " & FiledName(ComboField1.Text) & ComboOpsign1.Text & "'" & DTPicker1.Value & " ' "
    Else
    txtSQL = "select*from Line_info where " & FiledName(ComboField1.Text) & ComboOpsign1.Text & "'" & txtContent1.Text & " ' "
        'txtSQL = txtSQL & FiledName(ComboField1.Text) & " " & ComboOpsign1.Text & " '" & Trim(txtContent1.Text) & "'"
    End If
    End If
    End If
    End If
        If Trim(ComboCombineRelation1.Text <> "") Then
            If Trim(ComboField2.Text) = "" Or Trim(ComboOpsign2.Text) = "" Or (Trim(txtContent2.Text) = "" And DTPicker2.Value = "") Then
                MsgBox "您选择了组合关系,请输入数据之后再查询", vbOKOnly, "提示信息"
                Exit Sub
            Else
            If txtContent2.Visible = False Then
                txtSQL = txtSQL & Connect(ComboCombineRelation1.Text) & FiledName(ComboField2.Text) & ComboOpsign2.Text & " '" & Trim(DTPicker2.Value) & "'"
             Else
                txtSQL = txtSQL & Connect(ComboCombineRelation1.Text) & FiledName(ComboField2.Text) & ComboOpsign2.Text & " '" & Trim(txtContent2.Text) & "'"
        '        txtSQL = "select*from Line_info where " & Connect(ComboCombineRelation1.Text) & FiledName(ComboField2.Text) & ComboOpsign2.Text & Trim(txtContent2.Text) & ""
            End If
            End If
        End If

总结

重点内容就这么点,理解了之后会感觉不是很难。三个组合查询窗体都是异曲同工,解决一个另外两个也就不难了。