Public FldExpression As String ' Field expression (used in SQL)
Public FldType As Integer ' Field type (ADO data type)
Public FldDbType As OleDbType ' Field type (.NET data type)
Public FldDataType As Integer ' Field type (ASP.NET Maker data type)
Public Visible As Boolean ' Visible
Public FldDateTimeFormat As Integer ' Date time format
Public CssStyle As String ' CSS style
Public CssClass As String ' CSS class
Public ImageAlt As String ' Image alt
Public ImageWidth As Integer ' Image width
Public ImageHeight As Integer ' Image height
Public ViewCustomAttributes As String
Public EditCustomAttributes As String
Public CustomMsg As String ' Custom message
Public RowAttributes As String ' Row attributes
Public CellCssClass As String ' Cell CSS class
Public CellCssStyle As String ' Cell CSS style
Public CellCustomAttributes As String
Public MultiUpdate As Object ' Multi update
Public OldValue As Object ' Old Value
Public ConfirmValue As Object ' Confirm Value
Public CurrentValue As Object ' Current value
Public ViewValue As Object ' View value
Public EditValue As Object ' Edit value
Public EditValue2 As Object ' Edit value 2 (search)
Public HrefValue As Object ' Href value
Public HrefValue2 As Object
Private m_FormValue As Object ' Form value
Private m_QueryStringValue As Object ' QueryString value
Private m_DbValue As Object ' Database Value
' Create new field object
Public Sub New(atblvar As String, afldvar As String, afldname As String, afldexpression As String, afldtype As Integer, aflddbtype As OleDbType, aflddatatype As Integer, aflddtformat As Integer)
TblVar = atblvar
FldVar = afldvar
FldName = afldname
FldExpression = afldexpression
FldType = afldtype
FldDbType = aflddbtype
FldDataType = aflddatatype
FldDateTimeFormat = aflddtformat
ImageWidth = 0
ImageHeight = 0
Visible = True
End Sub
' View Attributes
Public ReadOnly Property ViewAttributes() As Object
Get
Dim sAtt As String = ""
If ew_NotEmpty(CssStyle) Then
sAtt = sAtt & " style=""" & CssStyle.Trim() & """"
End If
If ew_NotEmpty(CssClass) Then
sAtt = sAtt & " class=""" & CssClass.Trim() & """"
End If
If ew_NotEmpty(ImageAlt) Then
sAtt = sAtt & " alt=""" & ImageAlt.Trim() & """"
End If
If ImageWidth > 0 Then
sAtt = sAtt & " width=""" & ImageWidth & """"
End If
If ImageHeight > 0 Then
sAtt = sAtt & " height=""" & ImageHeight & """"
End If
If ew_NotEmpty(ViewCustomAttributes) Then
sAtt = sAtt & " " & ViewCustomAttributes.Trim()
End If
Return sAtt
End Get
End Property
' Edit Attributes
Public ReadOnly Property EditAttributes() As Object
Get
Dim sAtt As String = ""
If ew_NotEmpty(CssStyle) Then
sAtt = sAtt & " style=""" & CssStyle.Trim() & """"
End If
If ew_NotEmpty(CssClass) Then
sAtt = sAtt & " class=""" & CssClass.Trim() & """"
End If
If ew_NotEmpty(EditCustomAttributes) Then
sAtt = sAtt & " " & EditCustomAttributes.Trim()
End If
Return sAtt
End Get
End Property
' Cell Attributes
Public ReadOnly Property CellAttributes() As Object
Get
Dim sAtt As String = ""
If ew_NotEmpty(CellCssStyle) Then
sAtt = sAtt & " style=""" & CellCssStyle.Trim() & """"
End If
If ew_NotEmpty(CellCssClass) Then
sAtt = sAtt & " class=""" & CellCssClass.Trim() & """"
End If
If ew_NotEmpty(CellCustomAttributes) Then
sAtt = sAtt & " " & CellCustomAttributes.Trim() ' Cell custom attributes
' Resize and save uploaded data to file (Path relative to application root)
Public Function ResizeAndSaveToFile(Width As Integer, Height As Integer, Interpolation As Integer, Path As String, NewFileName As String, Overwrite As Boolean) As Boolean
If Not IsDbNull(m_Value) Then
Dim OldValue As Object = m_Value ' Save old values
Public Shared Function ew_GetMultiSearchSqlPart(ByRef Fld As Object, FldVal As String) As String
Return Fld.FldExpression & " LIKE '" & ew_AdjustSql(FldVal) & ",%' OR " & Fld.FldExpression & " LIKE '%," & FldVal & ",%' OR " & Fld.FldExpression & " LIKE '%," & FldVal & "'"
End Function
' Get search sql
Public Shared Function ew_GetSearchSql(ByRef Fld As Object, FldVal As String, FldOpr As String, FldCond As String, FldVal2 As String, FldOpr2 As String) As String
Public Shared Function ew_QuotedValue(Value As Object, FldType As Integer) As String
Value = Convert.ToString(Value)
Select Case FldType
Case EW_DATATYPE_STRING, EW_DATATYPE_MEMO
Return "'" & ew_AdjustSql(Value) & "'"
Case EW_DATATYPE_GUID
If EW_IS_MSACCESS Then
If Value.StartsWith("{") Then
Return Value
Else
Return "{" & ew_AdjustSql(Value) & "}"
End If
Else
Return "'" & ew_AdjustSql(Value) & "'"
End If
Case EW_DATATYPE_DATE, EW_DATATYPE_TIME
If EW_IS_MSACCESS Then
Return "#" & ew_AdjustSql(Value) & "#"
Else
Return "'" & ew_AdjustSql(Value) & "'"
End If
Case Else
Return Value
End Select
End Function
' Pad zeros before number
Public Shared Function ew_ZeroPad(m As Object, t As Integer) As String
Return Convert.ToString(m).PadLeft(t, "0"c)
End Function
' Convert numeric value
Public Shared Function ew_Conv(v As Object, t As Integer) As Object
If IsDbNull(v) Then Return System.DBNull.Value
Select Case t
Case 20 ' adBigInt
Return Convert.ToInt64(v)
Case 21 ' adUnsignedBigInt
Return Convert.ToUInt64(v)
Case 2, 16 ' adSmallInt/adTinyInt
Return Convert.ToInt16(v)
Case 3 ' adInteger
Return Convert.ToInt32(v)
Case 17, 18 ' adUnsignedTinyInt/adUnsignedSmallInt
Return Convert.ToUInt16(v)
Case 19 ' adUnsignedInt
Return Convert.ToUInt32(v)
Case 4 ' adSingle
Return Convert.ToSingle(v)
Case 5, 6, 131 ' adDouble/adCurrency/adNumeric
Return Convert.ToDouble(v)
Case Else
Return v
End Select
End Function
' Public Shared Function for debug
Public Shared Sub ew_Trace(Msg As Object)
Try
Dim FileName as String = HttpContext.Current.Server.MapPath("debug.txt")
Dim sw as StreamWriter = File.AppendText(FileName)
sw.WriteLine(Convert.ToString(Msg))
sw.Close()
Catch
If EW_DEBUG_ENABLED Then Throw
End Try
End Sub
' Compare values with special handling for null values
Public Shared Function ew_CompareValue(v1 As Object, v2 As Object) As Boolean
If IsDbNull(v1) AndAlso IsDbNull(v2) Then
Return True
ElseIf IsDbNull(v1) OrElse IsDbNull(v2) Then
Return False
Else
Return ew_SameStr(v1, v2)
End If
End Function
' Adjust SQL for special characters
Public Shared Function ew_AdjustSql(value As Object) As String
Dim sWrk As String = Convert.ToString(value).Trim()
sWrk = sWrk.Replace("'", "''") ' Adjust for Single Quote
sWrk = sWrk.Replace("[", "[[]") ' Adjust for Open Square Bracket
Return sWrk
End Function
' Build select SQL based on different SQL part
Public Shared Function ew_BuildSelectSql(sSelect As String, sWhere As String, sGroupBy As String, sHaving As String, sOrderBy As String, sFilter As String, sSort As String) As String
Dim sSql As String, sDbOrderBy As String
Dim sDbWhere As String = sWhere
If sDbWhere <> "" Then
If sFilter <> "" Then sDbWhere = "(" & sDbWhere & ") AND (" & sFilter & ")"
Else
sDbWhere = sFilter
End If
sDbOrderBy = sOrderBy
If sSort <> "" Then
sDbOrderBy = sSort
End If
sSql = sSelect
If sDbWhere <> "" Then
sSql = sSql & " WHERE " & sDbWhere
End If
If sGroupBy <> "" Then
sSql = sSql & " GROUP BY " & sGroupBy
End If
If sHaving <> "" Then
sSql = sSql & " HAVING " & sHaving
End If
If sDbOrderBy <> "" Then
sSql = sSql & " ORDER BY " & sDbOrderBy
End If
Return sSql
End Function
' Load a text file
Public Shared Function ew_LoadTxt(fn As String) As String
Dim sTxt As String = ""
If ew_NotEmpty(fn) Then
Dim sw as StreamReader = File.OpenText(fn)
sTxt = sw.ReadToEnd()
sw.Close()
End If
Return sTxt
End Function
' Write audit trail (login/logout)
Public Shared Sub ew_WriteAuditTrailOnLogInOut(logtype As String, username As String)
Try
Dim field As String = "", oldvalue As String = "", keyvalue As String = "", newvalue As String = ""
Dim filePfx As String = "log"
Dim dt As DateTime = DateTime.Now()
Dim curDate As String = dt.ToString("yyyy/MM/dd")
Dim curTime As String = dt.ToString("HH:mm:ss")
Dim table As String = logtype
Dim id As String = HttpContext.Current.Request.ServerVariables("SCRIPT_NAME")
Public Shared Sub ew_WriteAuditTrail(pfx As String, curDate As String, curTime As String, id As String, user As String, action As String, table As String, field As String, keyvalue As Object, oldvalue As Object, newvalue As Object)
Try
Dim userwrk As String = user
If userwrk = "" Then userwrk = "-1" ' assume Administrator if no user
Public Shared Function ew_FormatCurrency(Expression As Object, NumDigitsAfterDecimal As Integer, IncludeLeadingDigit As Integer, UseParensForNegativeNumbers As Integer, GroupDigits As Integer) As String
If Not Information.IsNumeric(Expression) Then Return Convert.ToString(Expression)
Public Shared Function ew_FormatNumber(Expression As Object, NumDigitsAfterDecimal As Integer, IncludeLeadingDigit As Integer, UseParensForNegativeNumbers As Integer, GroupDigits As Integer) As String
If Not Information.IsNumeric(Expression) Then Return Convert.ToString(Expression)
Public Shared Function ew_FormatPercent(Expression As Object, NumDigitsAfterDecimal As Integer, IncludeLeadingDigit As Integer, UseParensForNegativeNumbers As Integer, GroupDigits As Integer) As String
If Not Information.IsNumeric(Expression) Then Return Convert.ToString(Expression)
Public Shared Function ew_SendTemplateEmail(sTemplate As String, sSender As String, sRecipient As String, sCcEmail As String, sBccEmail As String, sSubject As String, arContent As String()) As Boolean
Public Shared Function ew_SendEmail(ByVal sFrEmail As String, ByVal sToEmail As String, ByVal sCcEmail As String, ByVal sBccEmail As String, ByVal sSubject As String, ByVal sMail As String, ByVal sFormat As String) As Boolean
Dim mail As New System.Net.Mail.MailMessage()
If sFrEmail <> "" Then
mail.From = New System.Net.Mail.MailAddress(sFrEmail)
End If
If sToEmail <> "" Then
sToEmail = sToEmail.Replace(","c, ";"c)
Dim arTo() As String = sToEmail.Split(New Char() {";"c})
For Each strTo As String In arTo
mail.To.Add(strTo)
Next
End If
If sCcEmail <> "" Then
sCcEmail = sCcEmail.Replace(","c, ";"c)
Dim arCC() As String = sCcEmail.Split(New Char() {";"c})
For Each strCC As String In arCC
mail.CC.Add(strCC)
Next
End If
If sBccEmail <> "" Then
sBccEmail = sBccEmail.Replace(","c, ";"c)
Dim arBcc() As String = sBccEmail.Split(New Char() {";"c})
For Each strBcc As String In arBcc
mail.Bcc.Add(strBcc)
Next
End If
mail.Subject = sSubject
mail.Body = sMail
mail.IsBodyHtml = ew_SameText(sFormat, "html")
Dim smtp As New System.Net.Mail.SmtpClient()
If EW_SMTP_SERVER <> "" Then
smtp.Host = EW_SMTP_SERVER
Else
smtp.Host = "localhost"
End If
If EW_SMTP_SERVER_PORT > 0 Then
smtp.Port = EW_SMTP_SERVER_PORT
End If
If EW_SMTP_SERVER_USERNAME <> "" AndAlso EW_SMTP_SERVER_PASSWORD <> "" Then
Dim smtpuser As New System.Net.NetworkCredential()
smtpuser.UserName = EW_SMTP_SERVER_USERNAME
smtpuser.Password = EW_SMTP_SERVER_PASSWORD
smtp.UseDefaultCredentials = False
smtp.Credentials = smtpuser
End If
Try
smtp.Send(mail)
Return True
Catch ex As Exception
ew_Session("ew_SendMail_result") = ex.Message
If EW_DEBUG_ENABLED Then Throw
Return False
End Try
End Function
' Return path of the uploaded file
' Parameter: If PhyPath is true(1), return physical path on the server
' If PhyPath is false(0), return relative URL
Public Shared Function ew_UploadPathEx(PhyPath As String, DestPath As String) As String
Dim pos As Integer, Path As String
If DestPath.StartsWith("~/") Then DestPath = DestPath.Substring(2)
Public Shared Function ew_CheckDay(checkYear As Integer, checkMonth As Integer, checkDay As Integer) As Boolean
Dim maxDay As Integer = 31
If checkMonth = 4 OrElse checkMonth = 6 OrElse checkMonth = 9 OrElse checkMonth = 11 Then
maxDay = 30
ElseIf checkMonth = 2 Then
If checkYear Mod 4 > 0 Then
maxDay = 28
ElseIf checkYear Mod 100 = 0 AndAlso checkYear Mod 400 > 0 Then
maxDay = 28
Else
maxDay = 29
End If
End If
Return ew_CheckRange(checkDay, 1, maxDay)
End Function
' Check integer
Public Shared Function ew_CheckInteger(value As String) As Boolean
If value = "" Then Return True
Dim re As New Regex("^\-?\+?[0-9]+")
Return re.IsMatch(value)
End Function
' Check number range
Public Shared Function ew_NumberRange(value As String, min As Object, max As Object) As Boolean
If (min IsNot Nothing AndAlso Convert.ToDouble(value) < Convert.ToDouble(min)) OrElse (max IsNot Nothing AndAlso Convert.ToDouble(value) > Convert.ToDouble(max)) Then
Return False
End If
Return True
End Function
' Check number
Public Shared Function ew_CheckNumber(value As String) As Boolean
If value = "" Then Return True
Return IsNumeric(Trim(value))
End Function
' Check range
Public Shared Function ew_CheckRange(value As String, min As Object, max As Object) As Boolean
If value = "" Then Return True
If Not ew_CheckNumber(value) Then Return False
Return ew_NumberRange(value, min, max)
End Function
' Check time
Public Shared Function ew_CheckTime(value As String) As Boolean
If value = "" Then Return True
' Dim re As New Regex("^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]")
Dim re As New Regex("^((([0]?[1-9]|1[0-2])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?( )?(AM|am|aM|Am|PM|pm|pM|Pm|a|A|p|P))|(([0]?[0-9]|1[0-9]|2[0-3])(:|\.)[0-5][0-9]((:|\.)[0-5][0-9])?))$")
Return re.IsMatch(value)
End Function
' Check US phone number
Public Shared Function ew_CheckPhone(value As String) As Boolean
If value = "" Then Return True
Dim re As New Regex("^\(\d{3}\) ?\d{3}( |-)?\d{4}|^\d{3}( |-)?\d{3}( |-)?\d{4}")
Return re.IsMatch(value)
End Function
' Check US zip code
Public Shared Function ew_CheckZip(value As String) As Boolean
If value = "" Then Return True
Dim re As New Regex("^\d{5}|^\d{5}-\d{4}")
Return re.IsMatch(value)
End Function
' Check credit card
Public Shared Function ew_CheckCreditCard(value As String) As Boolean