機房收費系統之學生上機資訊
阿新 • • 發佈:2018-12-17
前言
組合查詢是機房三大難點之一,不過等做完之後會豁然開朗,原來就是一句話的事。雖然這樣還是自己還是研究了好幾天才弄明白。下面先來說一下我的思路。
思路
重點程式碼:
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