home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
66.142.0.142
/
66.142.0.142.tar
/
66.142.0.142
/
tblEventsaddopt.aspx.vb
< prev
next >
Wrap
Text File
|
2010-08-24
|
12KB
|
471 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 tblEventsaddopt
Inherits AspNetMaker7_tfpssnet
' Page object
Public tblEvents_addopt As ctblEvents_addopt
'
' Page Class
'
Class ctblEvents_addopt
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 tblEvents.UseTokenInUrl Then Url = Url & "t=" & tblEvents.TableVar & "&" ' Add page token
Return Url
End Get
End Property
' Validate page request
Public Function IsPageRequest() As Boolean
Dim Result As Boolean
If tblEvents.UseTokenInUrl Then
Result = False
If ObjForm IsNot Nothing Then
Result = (tblEvents.TableVar = ObjForm.GetValue("t"))
End If
If ew_Get("t") <> "" Then
Result = (tblEvents.TableVar = ew_Get("t"))
End If
Return Result
End If
Return True
End Function
' tblEvents
Public Property tblEvents() As ctblEvents
Get
Return ParentPage.tblEvents
End Get
Set(ByVal v As ctblEvents)
ParentPage.tblEvents = v
End Set
End Property
' tblEvents
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 = "addopt"
m_PageObjName = "tblEvents_addopt"
m_PageObjTypeName = "ctblEvents_addopt"
' Table Name
m_TableName = "tblEvents"
' Initialize table object
tblEvents = New ctblEvents(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.CanAdd Then
Security.SaveLastUrl()
Page_Terminate("tblEventslist.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
tblEvents.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()
' Create form object
ObjForm = New cFormObj
' Process form if post back
If ObjForm.GetValue("a_addopt") <> "" Then
tblEvents.CurrentAction = ObjForm.GetValue("a_addopt") ' Get form action
LoadFormValues() ' Load form values
' Validate Form
If Not ValidateForm() Then
tblEvents.CurrentAction = "I" ' Form error, reset action
Message = ParentPage.gsFormError
End If
' Not post back
Else
tblEvents.CurrentAction = "I" ' Display Blank Record
LoadDefaultValues() ' Load default values
End If
' Perform action based on action code
Select Case tblEvents.CurrentAction
Case "I" ' Blank record, no action required
Case "A" ' Add new record
tblEvents.SendEmail = True ' Send email on add success
If AddRow() Then ' Add successful
Dim XMLDoc As Object, XMLRoot As Object, Element As Object
XMLDoc = New XmlDocument()
XMLRoot = XMLDoc.CreateElement("result")
XMLDoc.AppendChild(XMLRoot)
Element = XMLDoc.CreateElement("x_evtID")
XMLRoot.AppendChild(Element)
Element.AppendChild(XMLDoc.CreateTextNode(Convert.ToString(tblEvents.evtID.DbValue)))
Element = XMLDoc.CreateElement("x_evtDescription")
XMLRoot.AppendChild(Element)
Element.AppendChild(XMLDoc.CreateTextNode(Convert.ToString(tblEvents.evtDescription.FormValue)))
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ContentType = "text/xml"
ew_Write("<?xml version=""1.0"" encoding=""utf-8"" ?>")
ew_Write(XMLDoc.OuterXml)
Page_Terminate("")
ew_End()
Else
RestoreFormValues() ' Add failed, restore form values
End If
End Select
' Render row
tblEvents.RowType = EW_ROWTYPE_ADD ' Render add type
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()
tblEvents.evtDescription.FormValue = ObjForm.GetValue("x_evtDescription")
tblEvents.evtDescription.OldValue = ObjForm.GetValue("o_evtDescription")
tblEvents.evtID.FormValue = ObjForm.GetValue("x_evtID")
End Sub
'
' Restore form values
'
Sub RestoreFormValues()
tblEvents.evtDescription.CurrentValue = tblEvents.evtDescription.FormValue
tblEvents.evtID.CurrentValue = tblEvents.evtID.FormValue
End Sub
'
' Load row based on key values
'
Function LoadRow() As Boolean
Dim RsRow As OleDbDataReader
Dim sFilter As String = tblEvents.KeyFilter
' Row Selecting event
tblEvents.Row_Selecting(sFilter)
' Load SQL based on filter
tblEvents.CurrentFilter = sFilter
Dim sSql As String = tblEvents.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
tblEvents.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)
tblEvents.evtID.DbValue = RsRow("evtID")
tblEvents.evtDescription.DbValue = RsRow("evtDescription")
End Sub
'
' Render row values based on field settings
'
Sub RenderRow()
' Row Rendering event
tblEvents.Row_Rendering()
'
' Common render codes for all row types
'
' evtDescription
tblEvents.evtDescription.CellCssStyle = ""
tblEvents.evtDescription.CellCssClass = ""
'
' View Row
'
If tblEvents.RowType = EW_ROWTYPE_VIEW Then ' View row
' evtID
tblEvents.evtID.ViewValue = tblEvents.evtID.CurrentValue
tblEvents.evtID.CssStyle = ""
tblEvents.evtID.CssClass = ""
tblEvents.evtID.ViewCustomAttributes = ""
' evtDescription
tblEvents.evtDescription.ViewValue = tblEvents.evtDescription.CurrentValue
tblEvents.evtDescription.CssStyle = ""
tblEvents.evtDescription.CssClass = ""
tblEvents.evtDescription.ViewCustomAttributes = ""
' View refer script
' evtDescription
tblEvents.evtDescription.HrefValue = ""
'
' Add Row
'
ElseIf tblEvents.RowType = EW_ROWTYPE_ADD Then ' Add row
' evtDescription
tblEvents.evtDescription.EditCustomAttributes = ""
tblEvents.evtDescription.EditValue = ew_HtmlEncode(tblEvents.evtDescription.CurrentValue)
End If
' Row Rendered event
tblEvents.Row_Rendered()
End Sub
'
' Validate form
'
Function ValidateForm() As Boolean
' Initialize
ParentPage.gsFormError = ""
' 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
'
' Add record
'
Function AddRow() As Boolean
Dim Rs As New OrderedDictionary
Dim sSql As String, sFilter As String
Dim bInsertRow As Boolean
Dim RsChk As OleDbDataReader
Dim sIdxErrMsg As String
Dim LastInsertId As Object
' evtDescription
tblEvents.evtDescription.SetDbValue(tblEvents.evtDescription.CurrentValue, System.DBNull.Value)
Rs("evtDescription") = tblEvents.evtDescription.DbValue
' Row Inserting event
bInsertRow = tblEvents.Row_Inserting(Rs)
If bInsertRow Then
Try
tblEvents.Insert(Rs)
AddRow = True
Catch e As Exception
If EW_DEBUG_ENABLED Then Throw
Message = e.Message
AddRow = False
End Try
Else
If tblEvents.CancelMessage <> "" Then
Message = tblEvents.CancelMessage
tblEvents.CancelMessage = ""
Else
Message = "Insert cancelled"
End If
AddRow = False
End If
If AddRow Then
LastInsertId = Conn.GetLastInsertId()
tblEvents.evtID.DbValue = LastInsertId
Rs("evtID") = tblEvents.evtID.DbValue
' Row Inserted event
tblEvents.Row_Inserted(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
tblEvents_addopt = New ctblEvents_addopt(Me)
tblEvents_addopt.Page_Init()
' Page main processing
tblEvents_addopt.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 tblEvents_addopt IsNot Nothing Then tblEvents_addopt.Dispose()
End Sub
End Class