1. 程式人生 > >機房流程圖-組合查詢

機房流程圖-組合查詢

變數名 含義
c(2) 判斷條件框中是否為空
CField 欄位名函式變數
CSymbol 操作符函式變數
CContent 組合關係變數

在這裡插入圖片描述
程式碼部分:

Private Sub cmdInquiry_Click()
    Dim c(2) As Boolean   '判斷條件中的格子中是否有資料
    '查詢內容變數的例項化
    Set ctt = frmInquiryLineSumInfo
    
    '如果時間框顯示,將時間框的值賦給txtContent框
    If DTPicker1.Visible = True Then
        txtContent1.Text = DTPicker1.Value
    End If
    '如果時間框顯示,將時間框的值賦給txtContent框
    If DTPicker2.Visible = True Then
        txtContent2.Text = DTPicker2.Value
    End If
    '如果時間框顯示,將時間框的值賦給txtContent框
    If DTPicker3.Visible = True Then
        txtContent3.Text = DTPicker3.Value
    End If
    
        '判斷三個條件對應的框中是否為空
         If cobField1.Text = "" Or cobSymbol1.Text = "" Or txtContent1.Text = "" Then
             
         Else
            c(0) = True
         
         
             If cobField2.Text = "" Or cobSymbol2.Text = "" Or txtContent2.Text = "" Then
                
             Else
                c(1) = True
         
             
                 If cobField3.Text = "" Or cobSymbol3.Text = "" Or txtContent3.Text = "" Then
                    
                 Else
                    c(2) = True
                 End If
             End If
         End If
             
             txtSQL = "select * from line_Info where "
            
          
            
             '組合查詢所有的情況

   
        '第一行資料查詢
        If cobRelation1.Text = "" And cobRelation2.Text = "" Then
            If c(0) Then
                 '0
                txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'"
                Set mrc = ExecuteSQL(txtSQL, MsgText)
    
                Call add
                mrc.Close
    
            Else
                MsgBox "請輸入必要條件"
            End If
       End If
        
        '兩行資料查詢
    If cobRelation1.Text <> "" And cobRelation2.Text = "" Then
        If c(1) Then
            If cobRelation1.Text = "或" Then
                '0 or 1
                txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'" & "or " & CField(cobField2.Text) & CSymbol(cobSymbol2.Text) & " '" & CContent(txtContent2.Text) & "'"
                Set mrc = ExecuteSQL(txtSQL, MsgText)
    
                Call add
                mrc.Close
            Else
    
    
                If cobRelation1.Text = "與" Then
                    '0 and 1
                    txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'" & "and " & CField(cobField2.Text) & CSymbol(cobSymbol2.Text) & " '" & CContent(txtContent2.Text) & "'"
                    Set mrc = ExecuteSQL(txtSQL, MsgText)
        
                    Call add
                    mrc.Close
                Else
                    MsgBox "請選擇組合關係"
                End If
    
            End If
       Else
            MsgBox "請輸入必要條件"
        End If
    End If
        
        '3行資料查詢
    If cobRelation1.Text <> "" And cobRelation2.Text <> "" Then
        If c(2) Then
            If cobRelation2.Text = "或" Then
                    '0 or 1 or 2
                    txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'" & "or " & CField(cobField2.Text) & CSymbol(cobSymbol2.Text) & " '" & CContent(txtContent2.Text) & "'" & "or " & CField(cobField3.Text) & CSymbol(cobSymbol3.Text) & " '" & CContent(txtContent3.Text) & "'"
                    Set mrc = ExecuteSQL(txtSQL, MsgText)
    
                    Call add
                    mrc.Close
    
            Else
    
                If cobRelation2.Text = "與" Then
                        '0 and 1 and 2
                        txtSQL = txtSQL & CField(cobField1.Text) & CSymbol(cobSymbol1.Text) & "'" & CContent(txtContent1.Text) & "'" & "and " & CField(cobField2.Text) & CSymbol(cobSymbol2.Text) & " '" & CContent(txtContent2.Text) & "'" & "and " & CField(cobField3.Text) & CSymbol(cobSymbol3.Text) & " '" & CContent(txtContent3.Text) & "'"
                        Set mrc = ExecuteSQL(txtSQL, MsgText)
    
                        Call add
                        mrc.Close
                        Exit Sub
                Else
                        MsgBox "請輸入第二個組合條件"
                End If
    
            End If
    Else
            MsgBox "請輸入必要條件"
        End If
    End If
        '避免發生邏輯錯誤
    If cobRelation1.Text = "" And cobRelation2.Text <> "" Then
        MsgBox "請輸入必要條件"
    End If
              
End Sub