📄 ute_class.inc
字号:
End Function
''--------------------------------------------------------------------------
'' Name: AddWhere
'' ========
''
'' Adds WHERE clause to SQL Statement
''
'' Parameter:
'' sName name of field
'' nType type of field
'' sValue value of field, if empty the value is taken from the field object
'' sCompare comparison like "=" or ">"
'' sCombine combinition of clauses like "AND" or "OR"
'' bFirst is the the first where clause ?
''
'' return value:
'' string
''
''--------------------------------------------------------------------------
Private Function AddWhere ( sName, nType, sValue, sCompare, sCombine, bFirst )
Dim sReturn, sSepChar
sSepChar = ""
select case nType
case adBSTR, adVariant, adChar, adVarChar, adLongVarChar, adWChar, adVarWChar, adLongVarWChar
sSepChar = "'"
case adDate, adDBDate, adDBTime, adDBTimeStamp
sSepChar = "#"
case else
sSepChar = ""
end select
if bFirst then
sReturn = " WHERE "
else
sReturn = " " & sCombine & " "
end if
select case nType
case adSingle, adDouble, adCurrency
sValue = Replace(sValue, ",", ".")
case adBSTR, adVariant, adChar, adVarChar, adLongVarChar, adWChar, adVarWChar, adLongVarWChar
sValue = Replace(sValue, "'", "''")
end select
AddWhere = sReturn & sName & " " & sCompare & " " & sSepChar & sValue & sSepChar
End Function
''----------------------------------------------------------------------
'' Name: getFieldType
'' ============
''
'' Returns the type of the given field
''
'' Parameter:
'' sName Name of the field
''
'' return value:
'' Inbteger
''
''----------------------------------------------------------------------
Private Function getFieldType ( sName )
Dim i, bFound
Dim nReturn
nReturn = 0
i = 0
while (not bFound) and (i < UBound(m_PrimaryKeyFields))
i = i + 1
if m_PrimaryKeyFields(i) = sName then
nReturn = m_PrimaryKeyTypes(i)
bFound = True
end if
wend
i = 0
while (not bFound) and (i < UBound(m_StandardFields))
i = i + 1
if m_StandardFields(i) = sName then
nReturn = m_StandardTypes(i)
bFound = True
end if
wend
getFieldType = nReturn
End Function
''----------------------------------------------------------------------
'' Name: getFilter
'' =========
''
'' Returns complete Filter SQL statement
''
'' Parameter:
'' none
''
'' return value:
'' string
''
''----------------------------------------------------------------------
Private Function getFilter ()
Dim sReturn, sCombine
Dim i, bFirst
bFirst = True
sReturn = ""
sCombine = ""
for i = 1 to m_nNumberOfFilters
if i > 1 then sCombine = m_FilterCombines(i-1)
sReturn = sReturn & AddWhere( _
m_FilterFields(i), _
getFieldType(m_FilterFields(i)), _
m_FilterValues(i), _
m_FilterCompares(i), _
sCombine, _
bFirst)
bFirst = False
next
GetFilter = sReturn
End Function
''----------------------------------------------------------------------
'' Name: getAllRecordsFromDB
'' ===================
''
'' Creates SQL statement to get all records from table, opens
'' and configures recordset.
''
'' Parameter:
'' none
''
'' return value:
'' none
''
''----------------------------------------------------------------------
Private Sub getAllRecordsFromDB ()
Dim i
Dim s
m_sSQL = "SELECT * FROM " & m_sTable
' if no sort field is given select one
if UBound(m_SortFields) = 0 then
if UBound(m_PrimaryKeyFields) <> 0 then
AddSortField m_PrimaryKeyFields(1)
AddSortOrder SORT_ASC
elseif UBound(m_StandardFields) <> 0 then
AddSortField m_StandardFields(1)
AddSortOrder SORT_ASC
end if
end if
' add WHERE clause
if UBound(m_FilterFields) >= m_nNumberOfFilters then
m_sSQL = m_sSQL & getFilter
end if
' add ORDER BY clause
if UBound(m_SortFields) <> 0 then
s = " ORDER BY "
for i = 1 to UBound(m_SortFields)
s = s & m_SortFields(i)
if m_SortFieldsOrder(i) = SORT_DESC then s = s & " DESC"
s = s & ", "
next
' cut trailing ", "
s = Left(s, Len(s)-2)
m_sSQL = m_sSQL & s
end if
on error resume next
m_RS.Open m_sSQL, m_DB, adOpenStatic
if Err <> 0 then
if UBound(m_FilterCompares) <> 0 then
' redirect to filter page and display original error message
s = Request.QueryString
s = getLink(m_sUTEScript, s, sParamMode, MD_FILTER)
s = getLink(m_sUTEScript, s, sParamSubmitted, "0")
s = getLink(m_sUTEScript, s, sParamFilterError, Server.URLEncode(Err.description))
Response.Redirect s
else
Response.Write CStr(Hex(Err)) & ": " & Err.Description
Response.End
end if
end if
m_RS.PageSize = m_nPageSize
if m_nPage > m_RS.PageCount then
m_nPage = m_RS.PageCount
end if
if m_nPage <> 0 then
m_RS.AbsolutePage = m_nPage
end if
End Sub
'-----------------------------------------------------------------------
' Inlcude all mode specific private class functions
'
%>
<!--#include file ="ute_class_database.inc"-->
<!--#include file ="ute_class_table.inc"-->
<!--#include file ="ute_class_form.inc"-->
<!--#include file ="ute_class_export.inc"-->
<!--#include file ="ute_class_filter.inc"-->
<%
'-----------------------------------------------------------------------
' Public Member Functions
'
''----------------------------------------------------------------------
'' Name: Init
'' ====
''
'' Read all paramters, analyze table and prepares HTML output.
''
'' Parameter:
'' sDSN ODBC connection string
'' bReadOnly Display table in readonly mode
''
'' return value:
'' none
''
''----------------------------------------------------------------------
Public Sub Init( sDSN )
m_sDSN = sDSN
' read all other parameters from URL
GetParameter()
' are there filters to be set ?
if m_nMode = MD_FILTER then
if m_bSubmitted then
' set filter and redirect to table
UpdateFilter
end if
end if
' calculate headline
select case m_nMode
case MD_DATABASE
m_sHeadLine = m_sDBName
case MD_TABLE
m_sHeadLine = m_sTable
case MD_FILTER
m_sHeadLine = STR_DEF_FILTER
case MD_FORM
select case m_nFormMode
case MD_INSERT
m_sHeadLine = STR_INSERT
case MD_EDIT
m_sHeadLine = STR_EDIT
case MD_DELETE
m_sHeadLine = STR_DELETE
end select
end select
' open database connection
m_DB.Open m_sDSN
if m_nMode <> MD_DATABASE then
' get all fields from table
AnalyzeTable
if m_nMode <> MD_FILTER then
' load all records from db
getAllRecordsFromDB
end if
if m_nMode = MD_EXPORT then
' create csv data and send it to the response stream
ExportToStream
end if
if m_nMode = MD_FORM then
' update record and redirect to table
Update
end if
end if
End Sub
''----------------------------------------------------------------------
'' Name: Draw
'' ====
''
'' Writes entire HTML code directly to stream.
''
'' Parameter:
'' none
''
'' return value:
'' none
''
''----------------------------------------------------------------------
Public Sub Draw()
select case m_nMode
case MD_DATABASE
Response.Write buildHTML_Database
case MD_TABLE
Response.Write buildHTML_Table
case MD_FORM
Response.Write buildHTML_Form
case MD_FILTER
Response.Write buildHTML_Filter
end select
End Sub
''----------------------------------------------------------------------
'' Name: getHTML
'' =======
''
'' Returns entire HTML code as string.
''
'' Parameter:
'' none
''
'' return value:
'' string entire UTE HTML code
''
''----------------------------------------------------------------------
Public Function getHTML()
select case m_nMode
case MD_DATABASE
getHTML = buildHTML_Database
case MD_TABLE
getHTML = buildHTML_Table
case MD_FORM
getHTML = buildHTML_Form
case MD_FILTER
getHTML = buildHTML_Filter
end select
End Function
End Class
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -