home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
66.142.0.142
/
66.142.0.142.tar
/
66.142.0.142
/
ltgFixtureTypeedit.aspx.vb
< prev
next >
Wrap
Text File
|
2014-01-25
|
14KB
|
523 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 ltgFixtureTypeedit
Inherits AspNetMaker7_tfpssnet
' Page object
Public ltgFixtureType_edit As cltgFixtureType_edit
'
' Page Class
'
Class cltgFixtureType_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 ltgFixtureType.UseTokenInUrl Then Url = Url & "t=" & ltgFixtureType.TableVar & "&" ' Add page token
Return Url
End Get
End Property
' Validate page request
Public Function IsPageRequest() As Boolean
Dim Result As Boolean
If ltgFixtureType.UseTokenInUrl Then
Result = False
If ObjForm IsNot Nothing Then
Result = (ltgFixtureType.TableVar = ObjForm.GetValue("t"))
End If
If ew_Get("t") <> "" Then
Result = (ltgFixtureType.TableVar = ew_Get("t"))
End If
Return Result
End If
Return True
End Function
' ltgFixtureType
Public Property ltgFixtureType() As cltgFixtureType
Get
Return ParentPage.ltgFixtureType
End Get
Set(ByVal v As cltgFixtureType)
ParentPage.ltgFixtureType = v
End Set
End Property
' ltgFixtureType
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 = "ltgFixtureType_edit"
m_PageObjTypeName = "cltgFixtureType_edit"
' Table Name
m_TableName = "ltgFixtureType"
' Initialize table object
ltgFixtureType = New cltgFixtureType(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("ltgFixtureTypelist.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
ltgFixtureType.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("ftyID") <> "" Then
ltgFixtureType.ftyID.QueryStringValue = ew_Get("ftyID")
End If
' Create form object
ObjForm = New cFormObj
If ObjForm.GetValue("a_edit") <> "" Then
ltgFixtureType.CurrentAction = ObjForm.GetValue("a_edit") ' Get action code
LoadFormValues() ' Get form values
' Validate Form
If Not ValidateForm() Then
ltgFixtureType.CurrentAction = "" ' Form error, reset action
Message = ParentPage.gsFormError
LoadRow() ' Restore row
RestoreFormValues() ' Restore form values if validate failed
End If
Else
ltgFixtureType.CurrentAction = "I" ' Default action is display
End If
' Check if valid key
If ew_Empty(ltgFixtureType.ftyID.CurrentValue) Then Page_Terminate("ltgFixtureTypelist.aspx") ' Invalid key, return to list
Select Case ltgFixtureType.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("ltgFixtureTypelist.aspx") ' No matching record, return to list
End If
Case "U" ' Update
ltgFixtureType.SendEmail = True ' Send email on update success
If EditRow() Then ' Update Record based on key
Message = "Update succeeded" ' Update success
Dim sReturnUrl As String = ltgFixtureType.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
ltgFixtureType.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()
ltgFixtureType.ftyDescription.FormValue = ObjForm.GetValue("x_ftyDescription")
ltgFixtureType.ftyDescription.OldValue = ObjForm.GetValue("o_ftyDescription")
ltgFixtureType.ftyIsActive.FormValue = ObjForm.GetValue("x_ftyIsActive")
ltgFixtureType.ftyIsActive.OldValue = ObjForm.GetValue("o_ftyIsActive")
ltgFixtureType.ftyID.FormValue = ObjForm.GetValue("x_ftyID")
End Sub
'
' Restore form values
'
Sub RestoreFormValues()
ltgFixtureType.ftyDescription.CurrentValue = ltgFixtureType.ftyDescription.FormValue
ltgFixtureType.ftyIsActive.CurrentValue = ltgFixtureType.ftyIsActive.FormValue
ltgFixtureType.ftyID.CurrentValue = ltgFixtureType.ftyID.FormValue
End Sub
'
' Load row based on key values
'
Function LoadRow() As Boolean
Dim RsRow As OleDbDataReader
Dim sFilter As String = ltgFixtureType.KeyFilter
' Row Selecting event
ltgFixtureType.Row_Selecting(sFilter)
' Load SQL based on filter
ltgFixtureType.CurrentFilter = sFilter
Dim sSql As String = ltgFixtureType.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
ltgFixtureType.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)
ltgFixtureType.ftyID.DbValue = RsRow("ftyID")
ltgFixtureType.ftyDescription.DbValue = RsRow("ftyDescription")
ltgFixtureType.ftyIsActive.DbValue = IIf(ew_ConvertToBool(RsRow("ftyIsActive")), "1", "0")
End Sub
'
' Render row values based on field settings
'
Sub RenderRow()
' Row Rendering event
ltgFixtureType.Row_Rendering()
'
' Common render codes for all row types
'
' ftyDescription
ltgFixtureType.ftyDescription.CellCssStyle = ""
ltgFixtureType.ftyDescription.CellCssClass = ""
' ftyIsActive
ltgFixtureType.ftyIsActive.CellCssStyle = ""
ltgFixtureType.ftyIsActive.CellCssClass = ""
'
' View Row
'
If ltgFixtureType.RowType = EW_ROWTYPE_VIEW Then ' View row
' ftyID
ltgFixtureType.ftyID.ViewValue = ltgFixtureType.ftyID.CurrentValue
ltgFixtureType.ftyID.CssStyle = ""
ltgFixtureType.ftyID.CssClass = ""
ltgFixtureType.ftyID.ViewCustomAttributes = ""
' ftyDescription
ltgFixtureType.ftyDescription.ViewValue = ltgFixtureType.ftyDescription.CurrentValue
ltgFixtureType.ftyDescription.CssStyle = ""
ltgFixtureType.ftyDescription.CssClass = ""
ltgFixtureType.ftyDescription.ViewCustomAttributes = ""
' ftyIsActive
If Convert.ToString(ltgFixtureType.ftyIsActive.CurrentValue) = "1" Then
ltgFixtureType.ftyIsActive.ViewValue = "Yes"
Else
ltgFixtureType.ftyIsActive.ViewValue = "No"
End If
ltgFixtureType.ftyIsActive.CssStyle = ""
ltgFixtureType.ftyIsActive.CssClass = ""
ltgFixtureType.ftyIsActive.ViewCustomAttributes = ""
' View refer script
' ftyDescription
ltgFixtureType.ftyDescription.HrefValue = ""
' ftyIsActive
ltgFixtureType.ftyIsActive.HrefValue = ""
'
' Edit Row
'
ElseIf ltgFixtureType.RowType = EW_ROWTYPE_EDIT Then ' Edit row
' ftyDescription
ltgFixtureType.ftyDescription.EditCustomAttributes = ""
ltgFixtureType.ftyDescription.EditValue = ew_HtmlEncode(ltgFixtureType.ftyDescription.CurrentValue)
' ftyIsActive
ltgFixtureType.ftyIsActive.EditCustomAttributes = ""
' Edit refer script
' ftyDescription
ltgFixtureType.ftyDescription.HrefValue = ""
' ftyIsActive
ltgFixtureType.ftyIsActive.HrefValue = ""
End If
' Row Rendered event
ltgFixtureType.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 = "")
' 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 = ltgFixtureType.KeyFilter
ltgFixtureType.CurrentFilter = sFilter
sSql = ltgFixtureType.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()
' ftyDescription
ltgFixtureType.ftyDescription.SetDbValue(ltgFixtureType.ftyDescription.CurrentValue, System.DBNull.Value)
Rs("ftyDescription") = ltgFixtureType.ftyDescription.DbValue
' ftyIsActive
ltgFixtureType.ftyIsActive.SetDbValue((ltgFixtureType.ftyIsActive.CurrentValue <> "" And Not IsDBNull(ltgFixtureType.ftyIsActive.CurrentValue)), System.DBNull.Value)
Rs("ftyIsActive") = ltgFixtureType.ftyIsActive.DbValue
' Row Updating event
bUpdateRow = ltgFixtureType.Row_Updating(RsOld, Rs)
If bUpdateRow Then
Try
ltgFixtureType.Update(Rs)
EditRow = True
Catch e As Exception
If EW_DEBUG_ENABLED Then Throw
Message = e.Message
EditRow = False
End Try
Else
If ltgFixtureType.CancelMessage <> "" Then
Message = ltgFixtureType.CancelMessage
ltgFixtureType.CancelMessage = ""
Else
Message = "Update cancelled"
End If
EditRow = False
End If
End If
' Row Updated event
If EditRow Then
ltgFixtureType.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
ltgFixtureType_edit = New cltgFixtureType_edit(Me)
ltgFixtureType_edit.Page_Init()
' Page main processing
ltgFixtureType_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 ltgFixtureType_edit IsNot Nothing Then ltgFixtureType_edit.Dispose()
End Sub
End Class