home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
66.142.0.142
/
66.142.0.142.tar
/
66.142.0.142
/
tblPartsedit.aspx.vb
< prev
next >
Wrap
Text File
|
2010-08-24
|
13KB
|
508 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 tblPartsedit
Inherits AspNetMaker7_tfpssnet
' Page object
Public tblParts_edit As ctblParts_edit
'
' Page Class
'
Class ctblParts_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 tblParts.UseTokenInUrl Then Url = Url & "t=" & tblParts.TableVar & "&" ' Add page token
Return Url
End Get
End Property
' Validate page request
Public Function IsPageRequest() As Boolean
Dim Result As Boolean
If tblParts.UseTokenInUrl Then
Result = False
If ObjForm IsNot Nothing Then
Result = (tblParts.TableVar = ObjForm.GetValue("t"))
End If
If ew_Get("t") <> "" Then
Result = (tblParts.TableVar = ew_Get("t"))
End If
Return Result
End If
Return True
End Function
' tblParts
Public Property tblParts() As ctblParts
Get
Return ParentPage.tblParts
End Get
Set(ByVal v As ctblParts)
ParentPage.tblParts = v
End Set
End Property
' tblParts
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 = "tblParts_edit"
m_PageObjTypeName = "ctblParts_edit"
' Table Name
m_TableName = "tblParts"
' Initialize table object
tblParts = New ctblParts(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("tblPartslist.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
tblParts.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("prtID") <> "" Then
tblParts.prtID.QueryStringValue = ew_Get("prtID")
End If
' Create form object
ObjForm = New cFormObj
If ObjForm.GetValue("a_edit") <> "" Then
tblParts.CurrentAction = ObjForm.GetValue("a_edit") ' Get action code
LoadFormValues() ' Get form values
' Validate Form
If Not ValidateForm() Then
tblParts.CurrentAction = "" ' Form error, reset action
Message = ParentPage.gsFormError
LoadRow() ' Restore row
RestoreFormValues() ' Restore form values if validate failed
End If
Else
tblParts.CurrentAction = "I" ' Default action is display
End If
' Check if valid key
If ew_Empty(tblParts.prtID.CurrentValue) Then Page_Terminate("tblPartslist.aspx") ' Invalid key, return to list
Select Case tblParts.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("tblPartslist.aspx") ' No matching record, return to list
End If
Case "U" ' Update
tblParts.SendEmail = True ' Send email on update success
If EditRow() Then ' Update Record based on key
Message = "Update succeeded" ' Update success
Dim sReturnUrl As String = tblParts.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
tblParts.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()
tblParts.prtDescription.FormValue = ObjForm.GetValue("x_prtDescription")
tblParts.prtDescription.OldValue = ObjForm.GetValue("o_prtDescription")
tblParts.prtID.FormValue = ObjForm.GetValue("x_prtID")
End Sub
'
' Restore form values
'
Sub RestoreFormValues()
tblParts.prtDescription.CurrentValue = tblParts.prtDescription.FormValue
tblParts.prtID.CurrentValue = tblParts.prtID.FormValue
End Sub
'
' Load row based on key values
'
Function LoadRow() As Boolean
Dim RsRow As OleDbDataReader
Dim sFilter As String = tblParts.KeyFilter
' Row Selecting event
tblParts.Row_Selecting(sFilter)
' Load SQL based on filter
tblParts.CurrentFilter = sFilter
Dim sSql As String = tblParts.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
tblParts.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)
tblParts.prtID.DbValue = RsRow("prtID")
tblParts.prtDescription.DbValue = RsRow("prtDescription")
End Sub
'
' Render row values based on field settings
'
Sub RenderRow()
' Row Rendering event
tblParts.Row_Rendering()
'
' Common render codes for all row types
'
' prtDescription
tblParts.prtDescription.CellCssStyle = ""
tblParts.prtDescription.CellCssClass = ""
'
' View Row
'
If tblParts.RowType = EW_ROWTYPE_VIEW Then ' View row
' prtDescription
tblParts.prtDescription.ViewValue = tblParts.prtDescription.CurrentValue
tblParts.prtDescription.CssStyle = ""
tblParts.prtDescription.CssClass = ""
tblParts.prtDescription.ViewCustomAttributes = ""
' View refer script
' prtDescription
tblParts.prtDescription.HrefValue = ""
'
' Edit Row
'
ElseIf tblParts.RowType = EW_ROWTYPE_EDIT Then ' Edit row
' prtDescription
tblParts.prtDescription.EditCustomAttributes = ""
tblParts.prtDescription.EditValue = ew_HtmlEncode(tblParts.prtDescription.CurrentValue)
' Edit refer script
' prtDescription
tblParts.prtDescription.HrefValue = ""
End If
' Row Rendered event
tblParts.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 = tblParts.KeyFilter
If tblParts.prtDescription.CurrentValue <> "" Then ' Check field with unique index
sFilterChk = "(prtDescription = '" & ew_AdjustSql(tblParts.prtDescription.CurrentValue) & "')"
sFilterChk = sFilterChk & " AND NOT (" & sFilter & ")"
tblParts.CurrentFilter = sFilterChk
sSqlChk = tblParts.SQL
Try
RsChk = Conn.GetDataReader(sSqlChk)
If RsChk.Read() Then
sIdxErrMsg = "Duplicate value '%v' for unique index '%f'".Replace("%f", "prtDescription")
sIdxErrMsg = sIdxErrMsg.Replace("%v", tblParts.prtDescription.CurrentValue)
Message = sIdxErrMsg
Return False
End If
Catch e As Exception
If EW_DEBUG_ENABLED Then Throw
Message = e.Message
Return False
Finally
RsChk.Close()
RsChk.Dispose()
End Try
End If
tblParts.CurrentFilter = sFilter
sSql = tblParts.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()
' prtDescription
tblParts.prtDescription.SetDbValue(tblParts.prtDescription.CurrentValue, System.DBNull.Value)
Rs("prtDescription") = tblParts.prtDescription.DbValue
' Row Updating event
bUpdateRow = tblParts.Row_Updating(RsOld, Rs)
If bUpdateRow Then
Try
tblParts.Update(Rs)
EditRow = True
Catch e As Exception
If EW_DEBUG_ENABLED Then Throw
Message = e.Message
EditRow = False
End Try
Else
If tblParts.CancelMessage <> "" Then
Message = tblParts.CancelMessage
tblParts.CancelMessage = ""
Else
Message = "Update cancelled"
End If
EditRow = False
End If
End If
' Row Updated event
If EditRow Then
tblParts.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
tblParts_edit = New ctblParts_edit(Me)
tblParts_edit.Page_Init()
' Page main processing
tblParts_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 tblParts_edit IsNot Nothing Then tblParts_edit.Dispose()
End Sub
End Class