📄 ute_class_form.inc
字号:
<%
'---------------------------------------------------------------------------
'
' Project: UTE - (U)niversal ASP (T)able (E)ditor
'
' Module: UTE class - Form Functions
'
' Version: 3.00
'
' Comments: This module does the following things:
' 1. defines all functions being needed in
' form view mode
'
'---------------------------------------------------------------------------
'
' (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
'
'---------------------------------------------------------------------------
''--------------------------------------------------------------------------
'' Name: getSQLStatement
'' ==================
''
'' Returns SQL Statement to select/delete specific record. The statement is
'' compiled by the hidden form "ident" fields.
''
'' Parameter:
'' sCmd "select *" or "delete"
''
'' return value:
'' string
''
''--------------------------------------------------------------------------
Private Function getSQLStatement ( sCmd )
Dim i
Dim bFirst
Dim sSQL, sField, nType, sValue
Dim curField
i = 1
bFirst = True
sSQL = sCmd & " FROM " & m_sTable
while Request.Form(sFormUTEFieldPrefix & sFormIdentField & CStr(i)) <> ""
sField = Request.Form(sFormUTEFieldPrefix & sFormIdentField & CStr(i))
nType = CInt(Request.Form(sFormUTEFieldPrefix & sFormIdentType & CStr(i)))
sValue = Request.Form(sFormUTEFieldPrefix & sFormIdentValue & CStr(i))
Set curField = m_RS(sField)
sSQL = sSQL & AddWhere (sField, nType, sValue, "=", "AND", bFirst)
bFirst = False
i = i + 1
wend
getSQLStatement = sSQL
End Function
''--------------------------------------------------------------------------
'' Name: IsErrorField
'' ============
''
'' Is this an Error Field ?
''
'' Parameter:
'' sName name of field to be checked
''
'' return value:
'' boolean
''
''--------------------------------------------------------------------------
Private Function IsErrorField ( sName )
Dim i, bReturn
bReturn = False
for i = 1 to UBound(m_ErrorField)
if m_ErrorField(i) = sName then bReturn = True
next
IsErrorField = bReturn
End Function
''--------------------------------------------------------------------------
'' Name: GetErrorNumber
'' ==============
''
'' Returns the Error Description
''
'' Parameter:
'' sName name of field the err descr. should be returned
''
'' return value:
'' string
''
''--------------------------------------------------------------------------
Private Function GetErrorDescription ( sName )
Dim i, sReturn
sReturn = ""
for i = 1 to UBound(m_ErrorField)
if m_ErrorField(i) = sName then sReturn = sReturn & m_ErrorMessage(i) & "<br>"
next
' cut traling <br>
if sReturn <> "" then sReturn = Left(sReturn, Len(sReturn)-4)
GetErrorDescription = sReturn
End Function
''--------------------------------------------------------------------------
'' Name: PutError
'' ========
''
'' Put Error into Error Management
''
'' Parameter:
'' errField name of field that returns an error
'' errNumber error number
'' errMessage error description
''
'' return value:
'' none
''
''--------------------------------------------------------------------------
Private Sub PutError ( errField )
Dim e
Dim nError
' the errors collections of the connection object contains all occured errors
For Each e In m_DB.Errors
nError = UBound(m_ErrorField) + 1
Redim Preserve m_ErrorField(nError)
m_ErrorField(nError) = errField
Redim Preserve m_ErrorMessage(nError)
m_ErrorMessage(nError) = e.Description
Next
Err.Clear
m_DB.Errors.Clear
End Sub
''--------------------------------------------------------------------------
'' Name: InsertFieldForm
'' ===============
''
'' Return HTML code for a single field (incl, heading, form element and definitions
''
'' Parameter:
'' field field object
'' bPrimaryKey this is a primary key field
''
'' return value:
'' string HTML code
''
''--------------------------------------------------------------------------
Private Function InsertFieldForm ( field, bPrimaryKey )
Dim sReturn, sValue
Dim sStyle, sStyleForm
Dim nSize, nMaxLength
Dim nMemoCols, nMemoRows
Dim sChecked
sStyle = "ute_header"
if bPrimaryKey then sStyle = sStyle & "_pk"
sStyleForm = "ute_form_value"
if IsErrorField (field.name) then sStyleForm = "ute_form_error"
' field value
if m_bSubmitted then
if bPrimaryKey then
if IsNull(field.value) then
sValue = ""
else
select case field.type
case else
sValue = CStr(field.value)
end select
end if
else
sValue = Trim(Request.Form(field.name))
end if
else
if IsNull(field.value) then
sValue = ""
else
select case field.type
case else
sValue = CStr(field.value)
end select
end if
end if
' html endcode field value
sValue = Server.HTMLEncode(sValue)
sReturn = _
"<tr>" & _
"<td class=""" & sStyle & """>" & field.name & "</td>" & _
"<td class=""" & sStyleForm & """>"
if (NotAttrib(field.Attributes, adFldUpdatable) and NotAttrib(field.Attributes, adFldUnknownUpdatable)) or _
((NotAttrib(field.Attributes, adFldUpdatable) and bPrimaryKey)) or _
(m_nFormMode = MD_DELETE) then
' this field is not editable
if IsExcluded(field.type) then
' this field is not editable by ute
sReturn = sReturn & _
"<img src=""" & m_sIMAGEDir & "exclude.gif"" border=""0"" alt=""" & STR_NON_VIEW & """ " & _
"width=""16"" height=""16"">"
else
' display field value
sReturn = sReturn & sValue
end if
else
' this field is editable
select case field.type
' VARCHAR
case adBSTR, adVariant, adChar, adVarChar, adWChar, adVarWChar
nMaxLength = field.DefinedSize
if nMaxLength > DEF_MAX_INPUT_LENGTH then
nSize = DEF_MAX_INPUT_LENGTH
else
nSize = nMaxLength
end if
' MEMO
case adLongVarChar, adLongVarWChar
nMemoCols = DEF_MEMO_COLS
nMemoRows = DEF_MEMO_ROWS
' ELSE
case else
nMaxLength = field.Precision
if nMaxLength > DEF_MAX_INPUT_LENGTH then
nSize = DEF_MAX_INPUT_LENGTH
else
nSize = nMaxLength
end if
end select
if IsExcluded(field.type) then
sReturn = sReturn & _
"<img src=""" & m_sIMAGEDir & "exclude.gif"" border=""0"" alt=""" & STR_NON_VIEW & """ " & _
"width=""16"" height=""16"">"
else
if (field.type = adLongVarChar) or (field.type = adLongVarWChar) then
' MEMO -> TEXTAREA
sReturn = sReturn & "<textarea name=""" & field.name & """ cols=" & CStr(nMemoCols) & _
" rows=" & CStr(nMemoRows) & ">" & sValue & "</textarea>"
elseif (field.type = adBoolean) then
' -> CHECKBOX
sChecked = ""
if CBool(field.value) then sChecked = " checked"
sReturn = sReturn & "<input type=""checkbox"" name=""" & field.name & """" & sChecked & ">"
else
' -> INPUT
sReturn = sReturn & "<input type=""text"" name=""" & field.name & """ maxlength=" & _
CStr(nMaxLength) & " size=" & CStr(nSize) & " value=""" & sValue & """>"
end if
' put error message into form
if IsErrorField(field.name) then
sReturn = sReturn & " " & GetErrorDescription(field.name)
end if
end if
end if
sReturn = sReturn & "</td>" & vbCrLf
if m_bViewDefinitions then
sReturn = sReturn & _
"<td class=""ute_form_def"">" & GetTypeString(field.type) & "</td>" & _
"<td class=""ute_form_def"">" & GetAttributesString(field.attributes) & "</td>"
end if
sReturn = sReturn & "</tr>" & vbCrLf
InsertFieldForm = sReturn
End Function
''--------------------------------------------------------------------------
'' Name: InsertIdentFields
'' =================
''
'' Return HTML code for hidden form fields. These fields contain the field
'' names and values to identify the current record.
''
'' Parameter:
'' none
''
'' return value:
'' string
''
''--------------------------------------------------------------------------
Private Function InsertIdentFields ()
Dim i
Dim nCount
Dim curField
Dim sField, sType, sValue
Dim sReturn
sReturn = ""
if m_nFormMode <> MD_INSERT then
' do we already have some ident fields in form ?
if Request.Form(sFormUTEFieldPrefix & sFormIdentField & "1") <> "" then
' yes, so use these values
i = 1
while Request.Form(sFormUTEFieldPrefix & sFormIdentField & CStr(i)) <> ""
sField = Request.Form(sFormUTEFieldPrefix & sFormIdentField & CStr(i))
sType = Request.Form(sFormUTEFieldPrefix & sFormIdentType & CStr(i))
sValue = Request.Form(sFormUTEFieldPrefix & sFormIdentValue & CStr(i))
sReturn = sReturn & _
"<input type=""hidden"" name=""" & sFormUTEFieldPrefix & sFormIdentField & CStr(i) & """ " & _
"value=""" & sField & """>" & vbCrLf & _
"<input type=""hidden"" name=""" & sFormUTEFieldPrefix & sFormIdentType & CStr(i) & """ " & _
"value=""" & sType & """>" & vbCrLf & _
"<input type=""hidden"" name=""" & sFormUTEFieldPrefix & sFormIdentValue & CStr(i) & """ " & _
"value=""" & sValue & """>" & vbCrLf
i = i + 1
wend
else
' no, create ident fields from primary key fields or all fields
nCount = 0
if UBound(m_PrimaryKeyFields) > 0 then
' use Primary Keys for identification
for i = 1 to UBound(m_PrimaryKeyFields)
set curField = m_RS(m_PrimaryKeyFields(i))
if (not IsExcluded(curField.Type)) and not (IsNull(curField.Value)) then
nCount = nCount + 1
if (curField.Type = adBoolean) then
if curField.value then
sValue = CStr(True)
else
sValue = CStr(False)
end if
else
sValue = CStr(curField.Value)
end if
sReturn = sReturn & _
"<input type=""hidden"" name=""" & sFormUTEFieldPrefix & sFormIdentField & CStr(nCount) & _
""" value=""" & m_PrimaryKeyFields(i) & """>" & vbCrLf & _
"<input type=""hidden"" name=""" & sFormUTEFieldPrefix & sFormIdentType & CStr(nCount) & _
""" value=""" & m_PrimaryKeyTypes(i) & """>" & vbCrLf & _
"<input type=""hidden"" name=""" & sFormUTEFieldPrefix & sFormIdentValue & CStr(nCount) & _
""" value=""" & sValue & """>" & vbCrLf
end if
next
else
' use all fields for identification
for i = 1 to UBound(m_StandardFields)
set curField = m_RS(m_StandardFields(i))
if (not IsExcluded(curField.Type)) and not (IsNull(curField.Value)) then
nCount = nCount + 1
if (curField.Type = adBoolean) then
if curField.value then
sValue = CStr(True)
else
sValue = CStr(False)
end if
else
sValue = CStr(curField.Value)
end if
sReturn = sReturn & _
"<input type=""hidden"" name=""" & sFormUTEFieldPrefix & sFormIdentField & CStr(nCount) & _
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -