📄 ute_class.inc
字号:
<%
'---------------------------------------------------------------------------
'
' Project: UTE - (U)niversal ASP (T)able (E)ditor
'
' Module: UTE class
'
' Version: 3.01
'
' Comments: This module does the following things:
' 1. Defines the class "clsUTE" with all it's
' properties and functions.
'
'---------------------------------------------------------------------------
'
' (c) in 2000-2003 by Tom Wellige
' http://www.wellige.com mailto:tom@wellige.com
'
' This project is released under the "GNU General Public License (GPL)"
' http://www.gnu.org/licenses/gpl.html
'
' and is maintained on SourceForge at
' http://sourceforge.net/projects/ute-asp/
'
' and can also be found on CodeProject at
' http://www.codeproject.com/asp/ute.asp
'
'---------------------------------------------------------------------------
'
' Public Properties (R = read, W = write)
'
' DBName R/W Name of Database. For display purpose only.
'
' HeadLine R Headline of page (e.g. to be used as <title>)
' TableName R Name of current table
'
' ReadOnly W display table in readonly mode (default: false)
'
' ListTables W display toolbutton to list all tables (default: true)
' Filters W display toolbutton to define and activate filters (default: true)
' Export W display toolbutton to export all data to CSV file (default: true)
' SQL W display toolbutton to show current sql statement (default: true)
' Definitions W display toolbutton to show field defintions (default: true)
'
' ImageDir R/W name of image directory, must end with "/" (default: images/ )
'
' Public Functions
' Init (sDSN) must be called *before* any other HTML output
' Draw () writes complete HTML code
' getHTML () returns complete HTML code
'
'---------------------------------------------------------------------------
Class clsUTE
'-----------------------------------------------------------------------
' Private Member Variables
'
Private m_DB ' database connection object
Private m_RS ' recordset object
Private m_RSForm ' recordset object for form view
Private m_sSQL ' SQL statement being used to read data from db
Private m_nMode ' View mode: mdTable, mdForm, mdExport
Private m_nFormMode ' Form mode: mdEdit, mdInsert, mdDelete
Private m_sDSN ' odbc connect string
Private m_sDBName ' database name (for display purpose only)
Private m_sTable ' table name
Private m_nPage ' current page
Private m_nPageSize ' size of current page
Private m_bSortFields ' sort fields alphabetically (columns) ?
Private m_bViewDefinitions ' show field definitions ?
Private m_bViewSQL ' show sql statement ?
Private m_bAutoPKDetection ' detect primary key fields ?
Private m_bSubmitted ' form was submitted
Private m_bReadOnly ' display table in readonly mode
Private m_bListTables ' display toolbutton to list all tables within db
Private m_bFilters ' display toolbutton to define and activate filters
Private m_bShowExportLink ' display toolbutton to export all data to CSV file
Private m_bShowSQL ' display toolbutton to show current sql statement
Private m_bShowDefLink ' display toolbutton to show field defintions
Private m_PrimaryKeyFields() ' array holding names of all primary key fields
Private m_PrimaryKeyTypes() ' array holding types of all primary key fields
Private m_StandardFields() ' array holding names of all other fields
Private m_StandardTypes() ' array holding types of all other fields
Private m_SortFields() ' array holding names of the fields for the ORDER BY clause
Private m_SortFieldsOrder() ' array holding the directions for the ORDER BY clause
Private m_nNumberOfFilters ' number of filters
Private m_FilterFields() ' array holding names of fields of the filters
Private m_FilterCompares() ' array holding the comparisons for the filters
Private m_FilterValues() ' array holding the values of the filters
Private m_FilterCombines() ' array holding the combinitions of the filters
Private m_sHeadLine ' Headline
Private m_sUTEScript ' name of UTE script file
Private m_sIMAGEDir ' name of image directory
Private m_nRecord ' number of record to be edited/deleted
Private m_ErrorField()
Private m_ErrorMessage()
'-----------------------------------------------------------------------
' Property Functions
'
' ---- HeadLine (read) ----
Property Get HeadLine()
HeadLine = m_sHeadLine
End Property
' ---- DBName (read/write) ----
Property Let DBName(s)
m_sDBName = s
End Property
Property Get DBName()
DBName = m_sDBName
End Property
' ---- TableName (read) ----
Property Get TableName()
TableName = m_sTable
End Property
' ---- ReadOnly (write) ----
Property Let ReadOnly(b)
m_bReadOnly = b
End Property
' ---- ListTables (write) ----
Property Let ListTables(b)
m_bListTables = b
End Property
' ---- Definitions (write) ----
Property Let Definitions(b)
m_bShowDefLink = b
End Property
' ---- SQL (write) ----
Property Let SQL(b)
m_bShowSQL = b
End Property
' ---- Filter (write) ----
Property Let Filters(b)
m_bFilters = b
End Property
' ---- Export (write) ----
Property Let Export(b)
m_bShowExportLink = b
End Property
' ---- ImageDir (read/write)----
Property Let ImageDir(s)
m_sIMAGEDir = s
End Property
Property Get ImageDir()
ImageDir = m_sIMAGEDir
End Property
'-----------------------------------------------------------------------
' Private Member Functions
'
''----------------------------------------------------------------------
'' Name: Class_Initialize
'' ================
''
'' Constructor.
''
''----------------------------------------------------------------------
Private Sub Class_Initialize()
Set m_DB = Server.CreateObject("ADODB.Connection")
Set m_RS = Server.CreateObject("ADODB.Recordset")
m_nMode = DEF_MODE
m_nFormMode = DEF_FORM_MODE
m_sDSN = ""
m_sDBName = ""
m_sTable = ""
m_sSQL = ""
m_nPage = DEF_PAGE
m_nPageSize = DEF_PAGE_SIZE
m_bSortFields = DEF_SORT_FIELDS
m_bViewDefinitions = DEF_VIEW_DEFINITIONS
m_bViewSQL = DEF_VIEW_SQL
m_bAutoPKDetection = DEF_PK_DETECTION
m_bSubmitted = False
m_bReadOnly = DEF_READONLY
m_bListTables = DEF_LIST_TABLES
m_bShowDefLink = DEF_SHOW_DEF_LINK
m_bShowExportLink = DEF_EXPORT_LINK
m_bShowSQL = DEF_SQL_LINK
m_bFilters = DEF_FILTERS
m_nNumberOfFilters = DEF_NUM_FILTER
m_sUTEScript = Request.ServerVariables("SCRIPT_NAME")
m_sIMAGEDir = DEF_IMAGE_DIR
Redim m_PrimaryKeyFields(0)
Redim m_PrimaryKeyTypes(0)
Redim m_StandardFields(0)
Redim m_StandardTypes(0)
Redim m_SortFields(0)
Redim m_SortFieldsOrder(0)
Redim m_FilterFields(0)
Redim m_FilterCompares(0)
Redim m_FilterValues(0)
Redim m_FilterCombines(0)
Redim m_ErrorField(0)
Redim m_ErrorMessage(0)
End Sub
''----------------------------------------------------------------------
'' Name: Class_Terminate
'' ===============
''
'' Destructor.
''
''----------------------------------------------------------------------
Private Sub Class_Terminate()
Redim m_PrimaryKeyFields(0)
Redim m_StandardFields(0)
Set m_RS = Nothing
Set m_DB = Nothing
if IsObject(m_RSForm) then
Set m_RSForm = Nothing
end if
End Sub
''----------------------------------------------------------------------
'' Name: SetURLParameter
'' ===============
''
'' Sets a given parameter to a URL parameter string. If the parameter is
'' already present in the URL string it will be updated, otherwise it will
'' simply be added.
''
'' Parameter:
'' sURL URL string to set/update the parameter in
'' sName name of parameter to be set
'' sValue value of parameter to be set
''
'' return value:
'' string new URL parameter string
''
''----------------------------------------------------------------------
Private Function SetURLParameter (sURL, sName, sValue)
Dim iPos
Dim sLink, sReturn, sLeft, sRight
sLink = sURL
sReturn = ""
if InStr(sLink, sName & "=") <> 0 then
' update exisiting parameter
iPos = InStr(sLink, sName & "=")
sLeft = Left(sLink, iPos+Len(sName))
sRight = Right(sLink, Len(sLink) - (iPos + Len(sName)))
if InStr(sRight, "&") <> 0 then
' at least one following parameter
iPos = InStr(sRight, "&")
sRight = Right(sRight, Len(sRight)-iPos+1)
sReturn = sReturn & sLeft & sValue & sRight
else
' no following parameter
sReturn = sReturn & sLeft & sValue
end if
else
' add parameter
if Len(sLink) <> 0 then
sReturn = sReturn & sLink & "&" & sName & "=" & sValue
else
sReturn = sReturn & sName & "=" & sValue
end if
end if
SetURLParameter = sReturn
End Function
''----------------------------------------------------------------------
'' Name: buildLink
'' =========
''
'' Returns a string containing all UTE relevant URL parameters, such
'' as tablename, page or primary key fields.
''
'' Parameter:
'' sCurrent current URL string
''
'' return value:
'' string link
''
''----------------------------------------------------------------------
Private Function buildLink (sCurrent)
Dim i
Dim sReturn, sDefs, sSQL, sSort, sSubmitted
' preserve current URL string
sReturn = sCurrent
sSQL = "0"
if m_bViewSQL then sSQL = "1"
sDefs = "0"
if m_bViewDefinitions then sDefs = "1"
sSort = "0"
if m_bSortFields then sSort = "1"
sSubmitted = "0"
if m_bSubmitted then sSubmitted = "1"
' set all UTE URL params
sReturn = SetURLParameter(sReturn, sParamTable, m_sTable)
sReturn = SetURLParameter(sReturn, sParamMode, CStr(m_nMode))
sReturn = SetURLParameter(sReturn, sParamFormMode, CStr(m_nFormMode))
sReturn = SetURLParameter(sReturn, sParamPage, CStr(m_nPage))
sReturn = SetURLParameter(sReturn, sParamPageSize, CStr(m_nPageSize))
sReturn = SetURLParameter(sReturn, sParamSQL, sSQL)
sReturn = SetURLParameter(sReturn, sParamDefs, sDefs)
sReturn = SetURLParameter(sReturn, sParamSortFields, sSort)
sReturn = SetURLParameter(sReturn, sParamSubmitted, sSubmitted)
sReturn = SetURLParameter(sReturn, sParamRecord, CStr(m_nRecord))
' add primary key fields
for i = 1 to UBound(m_PrimaryKeyFields)
sReturn = SetURLParameter(sReturn, sParamPKey & CStr(i), m_PrimaryKeyFields(i))
next
' add sort fields
for i = 1 to UBound(m_SortFields)
sReturn = SetURLParameter(sReturn, sParamSort & CStr(i), m_SortFields(i))
sReturn = SetURLParameter(sReturn, sParamSortDir & CStr(i), m_SortFieldsOrder(i))
next
buildLink = sReturn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -