Where zusammenstellen
[Visual Basic] Private Function get_where( _
ByVal nr As Integer _
) As String
[Visual Basic] Private Function get_where(ByVal nr As Integer) As String
Dim param As New ComboBox
Dim op As New ComboBox
Dim val As New ComboBox
Dim wertvalue As String = ""
Dim wertdbfeld As String = ""
Dim wertop As String = op.Text
CtrlList.Clear()
Me.GetControl(Me, "cbparam" + Trim(Str(nr)), CtrlList)
param = CtrlList.Item(0)
CtrlList.Clear()
Me.GetControl(Me, "cbop" + Trim(Str(nr)), CtrlList)
op = CtrlList.Item(0)
CtrlList.Clear()
Me.GetControl(Me, "cbvalue" + Trim(Str(nr)), CtrlList)
val = CtrlList.Item(0)
dr = Me.Findrow(param.Text)
wertop = op.Text
Dim paramtyp As String = ""
Dim paramsplit() As String = dr.Item("Paramtype").ToString.Split(";")
Dim dbfeldsplit() As String = dr.Item("dbfeldname").ToString.Split(";")
If dbfeldsplit.Length > 1 And val.SelectedIndex > -1 Then
wertvalue = val.SelectedValue
wertdbfeld = dbfeldsplit(0)
paramtyp = paramsplit(0)
Else
wertvalue = val.Text
If dbfeldsplit.Length > 1 Then
wertdbfeld = dbfeldsplit(1)
paramtyp = paramsplit(1)
Else
wertdbfeld = dbfeldsplit(0)
paramtyp = paramsplit(0)
End If
End If
Select Case UCase(paramtyp)
Case "VARCHAR", "STRING", "CHAR"
Return wertdbfeld + " " + wertop + " '" + wertvalue + "'"
Case "INTEGER", "INT"
Return wertdbfeld + " " + wertop + " " + wertvalue + ""
Case "DATEPART"
Select Case wertvalue
Case "letzte Woche"
Return "cast(datepart(week," & wertdbfeld & ") as int) " & wertop & " cast(datepart(week, getdate()) as int) - 1"
Case "letzer Monat"
Return "cast(datepart(month," & wertdbfeld & ") as int) " & wertop & " cast(datepart(month, getdate()) as int) - 1"
Case "letztes Quartal"
Return "cast(datepart(quarter," & wertdbfeld & ") as int) " & wertop & " cast(datepart(quarter, getdate()) as int) - 1"
Case "letztes Jahr"
Return "year(" & wertdbfeld & ") " & wertop & " year(getdate()) - 1"
Case "aktuelle Woche"
Return "cast(datepart(week," & wertdbfeld & ") as int) " & wertop & " cast(datepart(week, getdate()) as int)"
Case "aktueller Monat"
Return "cast(datepart(month," & wertdbfeld & ") as int) " & wertop & " cast(datepart(month, getdate()) as int)"
Case "aktuelles Quartal"
Return "cast(datepart(quarter," & wertdbfeld & ") as int) " & wertop & " cast(datepart(quarter, getdate()) as int)"
Case "aktuelles Jahr"
Return "year(" & wertdbfeld & ") " & wertop & " year(getdate())"
End Select
Case "DATUM"
Select Case wertop
Case "="
Return wertdbfeld + " > convert(datetime,'" + wertvalue + " 00:00:00',104) and " + wertdbfeld + " < convert(datetime,'" + wertvalue + " 23:59:59',104)"
Case "<>"
Return wertdbfeld + " < convert(datetime,'" + wertvalue + " 00:00:00',104) and " + wertdbfeld + " > convert(datetime,'" + wertvalue + " 23:59:59',104)"
Case ">="
Return wertdbfeld + " " + wertop + " convert(datetime,'" + wertvalue + " 00:00:00',104)"
Case ">"
Return wertdbfeld + " " + wertop + " convert(datetime,'" + wertvalue + " 23:59:59',104)"
Case "<"
Return wertdbfeld + " " + wertop + " convert(datetime,'" + wertvalue + " 00:00:00',104)"
Case "<="
Return wertdbfeld + " " + wertop + " convert(datetime,'" + wertvalue + " 23:59:59',104)"
Case Else
Return wertdbfeld + " " + wertop + " convert(datetime,'" + wertvalue + " 00:00:00',104)"
End Select
Case "DATUM+1"
Dim d As DateTime = wertvalue
d = DateAdd(DateInterval.Day, 1, d)
wertvalue = d.ToString
Return wertdbfeld + " " + wertop + " convert(datetime,'" + wertvalue + " 00:00:00',104)"
Case "BOOLEAN"
If UCase(wertvalue) = "TRUE" Or UCase(wertvalue) = "JA" Then
Return wertdbfeld + " " + wertop + " 1"
Else
Return wertdbfeld + " " + wertop + " 0"
End If
Case Else
End Select
End Function
Plattformen: Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition