home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
66.142.0.142
/
66.142.0.142.tar
/
66.142.0.142
/
tblMessageedit.aspx.vb
< prev
next >
Wrap
Text File
|
2010-08-24
|
15KB
|
556 lines
Imports System.Data
Imports System.Data.Common
Imports System.Xml
Imports System.IO
Imports System.Data.OleDb
'
' ASP.NET code-behind class (Page)
'
Partial Class tblMessageedit
Inherits AspNetMaker7_tfpssnet
' Page object
Public tblMessage_edit As ctblMessage_edit
'
' Page Class
'
Class ctblMessage_edit
Inherits AspNetMakerPage
Implements IDisposable
' Used by system generated functions
Private RsWrk As Object, sSqlWrk As String, sWhereWrk As String
Private arwrk As Object
Private armultiwrk() As String
' Page URL
Public ReadOnly Property PageUrl() As String
Get
Dim Url As String = ew_CurrentPage() & "?"
If tblMessage.UseTokenInUrl Then Url = Url & "t=" & tblMessage.TableVar & "&" ' Add page token
Return Url
End Get
End Property
' Validate page request
Public Function IsPageRequest() As Boolean
Dim Result As Boolean
If tblMessage.UseTokenInUrl Then
Result = False
If ObjForm IsNot Nothing Then
Result = (tblMessage.TableVar = ObjForm.GetValue("t"))
End If
If ew_Get("t") <> "" Then
Result = (tblMessage.TableVar = ew_Get("t"))
End If
Return Result
End If
Return True
End Function
' tblMessage
Public Property tblMessage() As ctblMessage
Get
Return ParentPage.tblMessage
End Get
Set(ByVal v As ctblMessage)
ParentPage.tblMessage = v
End Set
End Property
' tblMessage
Public Property tblEmployees() As ctblEmployees
Get
Return ParentPage.tblEmployees
End Get
Set(ByVal v As ctblEmployees)
ParentPage.tblEmployees = v
End Set
End Property
'
' Constructor
' - init objects
' - open connection
'
Public Sub New(ByRef APage As AspNetMaker7_tfpssnet)
m_ParentPage = APage
m_Page = Me
m_PageID = "edit"
m_PageObjName = "tblMessage_edit"
m_PageObjTypeName = "ctblMessage_edit"
' Table Name
m_TableName = "tblMessage"
' Initialize table object
tblMessage = New ctblMessage(Me)
tblEmployees = New ctblEmployees(Me)
' Connect to database
Conn = New cConnection()
End Sub
'
' Subroutine Page_Init
' - called before page main
' - check Security
' - set up response header
' - call page load events
'
Public Sub Page_Init()
Security = New cAdvancedSecurity(Me)
If Not Security.IsLoggedIn() Then Security.AutoLogin()
If Not Security.IsLoggedIn() Then
Security.SaveLastUrl()
Page_Terminate("login.aspx")
End If
' Table Permission loading event
Security.TablePermission_Loading()
Security.LoadCurrentUserLevel(TableName)
' Table Permission loaded event
Security.TablePermission_Loaded()
If Not Security.CanEdit Then
Security.SaveLastUrl()
Page_Terminate("tblMessagelist.aspx")
End If
' User ID loading event
Security.UserID_Loading()
If Security.IsLoggedIn() Then Call Security.LoadUserID()
' User ID loaded event
Security.UserID_Loaded()
' Global page loading event (in ewglobal*.vb)
ParentPage.Page_Loading()
' Page load event, used in current page
Page_Load()
End Sub
'
' Class terminate
' - clean up page object
'
Public Sub Dispose() Implements IDisposable.Dispose
Page_Terminate("")
End Sub
'
' Sub Page_Terminate
' - called when exit page
' - clean up connection and objects
' - if URL specified, redirect to URL
'
Sub Page_Terminate(url As String)
' Page unload event, used in current page
Page_Unload()
' Global page unloaded event (in ewglobal*.vb)
ParentPage.Page_Unloaded()
' Close connection
Conn.Dispose()
Security = Nothing
tblMessage.Dispose()
tblEmployees.Dispose()
' Go to URL if specified
If url <> "" Then
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Redirect(url)
End If
End Sub
'
' Page main processing
'
Sub Page_Main()
' Load key from QueryString
If ew_Get("msgID") <> "" Then
tblMessage.msgID.QueryStringValue = ew_Get("msgID")
End If
' Create form object
ObjForm = New cFormObj
If ObjForm.GetValue("a_edit") <> "" Then
tblMessage.CurrentAction = ObjForm.GetValue("a_edit") ' Get action code
LoadFormValues() ' Get form values
' Validate Form
If Not ValidateForm() Then
tblMessage.CurrentAction = "" ' Form error, reset action
Message = ParentPage.gsFormError
LoadRow() ' Restore row
RestoreFormValues() ' Restore form values if validate failed
End If
Else
tblMessage.CurrentAction = "I" ' Default action is display
End If
' Check if valid key
If ew_Empty(tblMessage.msgID.CurrentValue) Then Page_Terminate("tblMessagelist.aspx") ' Invalid key, return to list
Select Case tblMessage.CurrentAction
Case "I" ' Get a record to display
If Not LoadRow() Then ' Load Record based on key
Message = "No records found" ' No record found
Page_Terminate("tblMessagelist.aspx") ' No matching record, return to list
End If
Case "U" ' Update
tblMessage.SendEmail = True ' Send email on update success
If EditRow() Then ' Update Record based on key
Message = "Update succeeded" ' Update success
Dim sReturnUrl As String = tblMessage.ReturnUrl
Page_Terminate(sReturnUrl) ' Return to caller
Else
LoadRow() ' Restore row
RestoreFormValues() ' Restore form values if update failed
End If
End Select
' Render the record
tblMessage.RowType = EW_ROWTYPE_EDIT ' Render as edit
' Render row
RenderRow()
End Sub
'
' Get upload file
'
Sub GetUploadFiles()
' Get upload data
End Sub
'
' Load default values
'
Sub LoadDefaultValues()
End Sub
'
' Load form values
'
Sub LoadFormValues()
tblMessage.msgText.FormValue = ObjForm.GetValue("x_msgText")
tblMessage.msgText.OldValue = ObjForm.GetValue("o_msgText")
tblMessage.msgStartDate.FormValue = ObjForm.GetValue("x_msgStartDate")
tblMessage.msgStartDate.CurrentValue = ew_UnFormatDateTime(tblMessage.msgStartDate.CurrentValue, 6)
tblMessage.msgStartDate.OldValue = ObjForm.GetValue("o_msgStartDate")
tblMessage.msgEndDate.FormValue = ObjForm.GetValue("x_msgEndDate")
tblMessage.msgEndDate.CurrentValue = ew_UnFormatDateTime(tblMessage.msgEndDate.CurrentValue, 6)
tblMessage.msgEndDate.OldValue = ObjForm.GetValue("o_msgEndDate")
tblMessage.msgID.FormValue = ObjForm.GetValue("x_msgID")
End Sub
'
' Restore form values
'
Sub RestoreFormValues()
tblMessage.msgText.CurrentValue = tblMessage.msgText.FormValue
tblMessage.msgStartDate.CurrentValue = tblMessage.msgStartDate.FormValue
tblMessage.msgStartDate.CurrentValue = ew_UnFormatDateTime(tblMessage.msgStartDate.CurrentValue, 6)
tblMessage.msgEndDate.CurrentValue = tblMessage.msgEndDate.FormValue
tblMessage.msgEndDate.CurrentValue = ew_UnFormatDateTime(tblMessage.msgEndDate.CurrentValue, 6)
tblMessage.msgID.CurrentValue = tblMessage.msgID.FormValue
End Sub
'
' Load row based on key values
'
Function LoadRow() As Boolean
Dim RsRow As OleDbDataReader
Dim sFilter As String = tblMessage.KeyFilter
' Row Selecting event
tblMessage.Row_Selecting(sFilter)
' Load SQL based on filter
tblMessage.CurrentFilter = sFilter
Dim sSql As String = tblMessage.SQL
' Write SQL for debug
If EW_DEBUG_ENABLED Then ew_Write(sSql)
Try
RsRow = Conn.GetTempDataReader(sSql)
If Not RsRow.Read() Then
Return False
Else
LoadRowValues(RsRow) ' Load row values
' Row Selected event
tblMessage.Row_Selected(RsRow)
Return True
End If
Catch
If EW_DEBUG_ENABLED Then Throw
Return False
Finally
Conn.CloseTempDataReader()
End Try
End Function
'
' Load row values from recordset
'
Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
tblMessage.msgID.DbValue = RsRow("msgID")
tblMessage.msgText.DbValue = RsRow("msgText")
tblMessage.msgStartDate.DbValue = RsRow("msgStartDate")
tblMessage.msgEndDate.DbValue = RsRow("msgEndDate")
End Sub
'
' Render row values based on field settings
'
Sub RenderRow()
' Row Rendering event
tblMessage.Row_Rendering()
'
' Common render codes for all row types
'
' msgText
tblMessage.msgText.CellCssStyle = ""
tblMessage.msgText.CellCssClass = ""
' msgStartDate
tblMessage.msgStartDate.CellCssStyle = ""
tblMessage.msgStartDate.CellCssClass = ""
' msgEndDate
tblMessage.msgEndDate.CellCssStyle = ""
tblMessage.msgEndDate.CellCssClass = ""
'
' View Row
'
If tblMessage.RowType = EW_ROWTYPE_VIEW Then ' View row
' msgText
tblMessage.msgText.ViewValue = tblMessage.msgText.CurrentValue
tblMessage.msgText.CssStyle = ""
tblMessage.msgText.CssClass = ""
tblMessage.msgText.ViewCustomAttributes = ""
' msgStartDate
tblMessage.msgStartDate.ViewValue = tblMessage.msgStartDate.CurrentValue
tblMessage.msgStartDate.ViewValue = ew_FormatDateTime(tblMessage.msgStartDate.ViewValue, 6)
tblMessage.msgStartDate.CssStyle = ""
tblMessage.msgStartDate.CssClass = ""
tblMessage.msgStartDate.ViewCustomAttributes = ""
' msgEndDate
tblMessage.msgEndDate.ViewValue = tblMessage.msgEndDate.CurrentValue
tblMessage.msgEndDate.ViewValue = ew_FormatDateTime(tblMessage.msgEndDate.ViewValue, 6)
tblMessage.msgEndDate.CssStyle = ""
tblMessage.msgEndDate.CssClass = ""
tblMessage.msgEndDate.ViewCustomAttributes = ""
' View refer script
' msgText
tblMessage.msgText.HrefValue = ""
' msgStartDate
tblMessage.msgStartDate.HrefValue = ""
' msgEndDate
tblMessage.msgEndDate.HrefValue = ""
'
' Edit Row
'
ElseIf tblMessage.RowType = EW_ROWTYPE_EDIT Then ' Edit row
' msgText
tblMessage.msgText.EditCustomAttributes = ""
tblMessage.msgText.EditValue = ew_HtmlEncode(tblMessage.msgText.CurrentValue)
' msgStartDate
tblMessage.msgStartDate.EditCustomAttributes = ""
tblMessage.msgStartDate.EditValue = ew_FormatDateTime(tblMessage.msgStartDate.CurrentValue, 6)
' msgEndDate
tblMessage.msgEndDate.EditCustomAttributes = ""
tblMessage.msgEndDate.EditValue = ew_FormatDateTime(tblMessage.msgEndDate.CurrentValue, 6)
' Edit refer script
' msgText
tblMessage.msgText.HrefValue = ""
' msgStartDate
tblMessage.msgStartDate.HrefValue = ""
' msgEndDate
tblMessage.msgEndDate.HrefValue = ""
End If
' Row Rendered event
tblMessage.Row_Rendered()
End Sub
'
' Validate form
'
Function ValidateForm() As Boolean
' Initialize
ParentPage.gsFormError = ""
' Check if validation required
If Not EW_SERVER_VALIDATE Then Return (ParentPage.gsFormError = "")
If Not ew_CheckUSDate(tblMessage.msgStartDate.FormValue) Then
If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect date, format = mm/dd/yyyy - Start Date"
End If
If Not ew_CheckUSDate(tblMessage.msgEndDate.FormValue) Then
If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect date, format = mm/dd/yyyy - End Date"
End If
' Return validate result
Dim Valid As Boolean = (ParentPage.gsFormError = "")
' Form_CustomValidate event
Dim sFormCustomError As String = ""
Valid = Valid And Form_CustomValidate(sFormCustomError)
If sFormCustomError <> "" Then
If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
End If
Return Valid
End Function
'
' Update record based on key values
'
Function EditRow() As Boolean
Dim RsEdit As OleDbDataReader, RsChk As OleDbDataReader
Dim sSql As String, sFilter As String
Dim sSqlChk As String, sFilterChk As String
Dim bUpdateRow As Boolean
Dim RsOld As OrderedDictionary
Dim sIdxErrMsg As String
Dim Rs As New OrderedDictionary
sFilter = tblMessage.KeyFilter
tblMessage.CurrentFilter = sFilter
sSql = tblMessage.SQL
Try
RsEdit = Conn.GetDataReader(sSql)
Catch e As Exception
If EW_DEBUG_ENABLED Then Throw
Message = e.Message
RsEdit.Close()
EditRow = False
End Try
If Not RsEdit.Read() Then
RsEdit.Close()
EditRow = False ' Update Failed
Else
RsOld = Conn.GetRow(RsEdit)
RsEdit.Close()
' msgText
tblMessage.msgText.SetDbValue(tblMessage.msgText.CurrentValue, System.DBNull.Value)
Rs("msgText") = tblMessage.msgText.DbValue
' msgStartDate
tblMessage.msgStartDate.SetDbValue(ew_UnFormatDateTime(tblMessage.msgStartDate.CurrentValue, 6), System.DBNull.Value)
Rs("msgStartDate") = tblMessage.msgStartDate.DbValue
' msgEndDate
tblMessage.msgEndDate.SetDbValue(ew_UnFormatDateTime(tblMessage.msgEndDate.CurrentValue, 6), System.DBNull.Value)
Rs("msgEndDate") = tblMessage.msgEndDate.DbValue
' Row Updating event
bUpdateRow = tblMessage.Row_Updating(RsOld, Rs)
If bUpdateRow Then
Try
tblMessage.Update(Rs)
EditRow = True
Catch e As Exception
If EW_DEBUG_ENABLED Then Throw
Message = e.Message
EditRow = False
End Try
Else
If tblMessage.CancelMessage <> "" Then
Message = tblMessage.CancelMessage
tblMessage.CancelMessage = ""
Else
Message = "Update cancelled"
End If
EditRow = False
End If
End If
' Row Updated event
If EditRow Then
tblMessage.Row_Updated(RsOld, Rs)
End If
End Function
' Page Load event
Public Sub Page_Load()
'HttpContext.Current.Response.Write("Page Load")
End Sub
' Page Unload event
Public Sub Page_Unload()
'HttpContext.Current.Response.Write("Page Unload")
End Sub
' Form Custom Validate event
Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
'Return error message in CustomError
Return True
End Function
End Class
'
' ASP.NET Page_Load event
'
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Buffer = EW_RESPONSE_BUFFER
Response.Cache.SetCacheability(HttpCacheability.NoCache)
' Page init
tblMessage_edit = New ctblMessage_edit(Me)
tblMessage_edit.Page_Init()
' Page main processing
tblMessage_edit.Page_Main()
End Sub
'
' ASP.NET Page_Unload event
'
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
' Dispose page object
If tblMessage_edit IsNot Nothing Then tblMessage_edit.Dispose()
End Sub
End Class