home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
66.142.0.142
/
66.142.0.142.tar
/
66.142.0.142
/
tblFixtureMasterdelete.aspx.vb
< prev
next >
Wrap
Text File
|
2010-08-24
|
17KB
|
601 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 tblFixtureMasterdelete
Inherits AspNetMaker7_tfpssnet
' Page object
Public tblFixtureMaster_delete As ctblFixtureMaster_delete
'
' Page Class
'
Class ctblFixtureMaster_delete
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 tblFixtureMaster.UseTokenInUrl Then Url = Url & "t=" & tblFixtureMaster.TableVar & "&" ' Add page token
Return Url
End Get
End Property
' Validate page request
Public Function IsPageRequest() As Boolean
Dim Result As Boolean
If tblFixtureMaster.UseTokenInUrl Then
Result = False
If ObjForm IsNot Nothing Then
Result = (tblFixtureMaster.TableVar = ObjForm.GetValue("t"))
End If
If ew_Get("t") <> "" Then
Result = (tblFixtureMaster.TableVar = ew_Get("t"))
End If
Return Result
End If
Return True
End Function
' tblFixtureMaster
Public Property tblFixtureMaster() As ctblFixtureMaster
Get
Return ParentPage.tblFixtureMaster
End Get
Set(ByVal v As ctblFixtureMaster)
ParentPage.tblFixtureMaster = v
End Set
End Property
' tblFixtureMaster
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 = "delete"
m_PageObjName = "tblFixtureMaster_delete"
m_PageObjTypeName = "ctblFixtureMaster_delete"
' Table Name
m_TableName = "tblFixtureMaster"
' Initialize table object
tblFixtureMaster = New ctblFixtureMaster(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.CanDelete Then
Security.SaveLastUrl()
Page_Terminate("tblFixtureMasterlist.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
tblFixtureMaster.Dispose()
tblEmployees.Dispose()
' Go to URL if specified
If url <> "" Then
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Redirect(url)
End If
End Sub
Public lTotalRecs As Integer
Public lRecCnt As Integer
Public arRecKeys() As String
'
' Page main processing
'
Sub Page_Main()
Dim sKey As String = ""
Dim bSingleDelete As Boolean = True ' Initialize as single delete
Dim nKeySelected As Integer = 0 ' Initialize selected key count
Dim sKeyFld As String, arKeyFlds() As String
Dim sFilter As String
' Load Key Parameters
If ew_Get("lfxID") <> "" Then
tblFixtureMaster.lfxID.QueryStringValue = ew_Get("lfxID")
If Not IsNumeric(tblFixtureMaster.lfxID.QueryStringValue) Then
Page_Terminate("tblFixtureMasterlist.aspx") ' Prevent SQL injection, return to list
End If
sKey = sKey & tblFixtureMaster.lfxID.QueryStringValue
Else
bSingleDelete = False
End If
If bSingleDelete Then
nKeySelected = 1 ' Set up key selected count
Array.Resize(arRecKeys, 1) ' Set up key
arRecKeys(0) = sKey
Else
If HttpContext.Current.Request.Form("key_m") IsNot Nothing Then ' Key in form
arRecKeys = HttpContext.Current.Request.Form.GetValues("key_m")
nKeySelected = arRecKeys.Length
End If
End If
If nKeySelected <= 0 Then Page_Terminate("tblFixtureMasterlist.aspx") ' No key specified, return to list
' Build filter
For i As Integer = 0 to arRecKeys.GetUpperBound(0)
sKey = arRecKeys(i).Trim()
sFilter = sFilter & "("
' Set up key field
sKeyFld = sKey
If Not IsNumeric(sKeyFld) Then Page_Terminate("tblFixtureMasterlist.aspx") ' Prevent SQL injection, return to list
sFilter = sFilter & "[lfxID]=" & ew_AdjustSql(sKeyFld) & " AND "
If sFilter.EndsWith(" AND ") Then sFilter = sFilter.Substring(0, sFilter.Length-5) & ") OR "
Next
If sFilter.EndsWith(" OR ") Then sFilter = sFilter.Substring(0, sFilter.Length-4)
' Set up filter (SQL WHERE clause)
' SQL constructor in tblFixtureMaster class, tblFixtureMasterinfo.aspx
tblFixtureMaster.CurrentFilter = sFilter
' Get action
If ew_Post("a_delete") <> "" Then
tblFixtureMaster.CurrentAction = ew_Post("a_delete")
Else
tblFixtureMaster.CurrentAction = "I" ' Display record
End If
Select Case tblFixtureMaster.CurrentAction
Case "D" ' Delete
tblFixtureMaster.SendEmail = True ' Send email on delete success
If DeleteRows() Then ' delete rows
Message = "Delete succeeded" ' Set up success message
Page_Terminate(tblFixtureMaster.ReturnUrl) ' Return to caller
End If
End Select
End Sub
'
' Function DeleteRows
' - Delete Records based on current filter
'
Function DeleteRows() As Boolean
Dim sKey As String, sThisKey As String, sKeyFld As String
Dim arKeyFlds() As String
Dim RsDelete As OleDbDataReader = Nothing
Dim sSql As String, sWrkFilter As String
Dim RsOld As ArrayList
DeleteRows = True
sWrkFilter = tblFixtureMaster.CurrentFilter
' Set up filter (SQL WHERE Clause)
' SQL constructor in tblFixtureMaster class, tblFixtureMasterinfo.aspx
tblFixtureMaster.CurrentFilter = sWrkFilter
sSql = tblFixtureMaster.SQL
Conn.BeginTrans() ' Begin transaction
Try
RsDelete = Conn.GetDataReader(sSql)
If Not RsDelete.HasRows Then
Message = "No records found" ' No record found
RsDelete.Close()
RsDelete.Dispose()
Return False
End If
Catch e As Exception
If EW_DEBUG_ENABLED Then Throw
Message = e.Message
Return False
End Try
' Clone old rows
RsOld = Conn.GetRows(RsDelete)
RsDelete.Close()
RsDelete.Dispose()
' Call Row_Deleting event
If DeleteRows Then
For Each Row As OrderedDictionary in RsOld
DeleteRows = tblFixtureMaster.Row_Deleting(Row)
If Not DeleteRows Then Exit For
Next Row
End If
If DeleteRows Then
sKey = ""
For Each Row As OrderedDictionary in RsOld
sThisKey = ""
If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR
sThisKey = sThisKey & Convert.ToString(Row("lfxID"))
Try
tblFixtureMaster.Delete(Row)
Catch e As Exception
If EW_DEBUG_ENABLED Then Throw
Message = e.Message ' Set up error message
DeleteRows = False
Exit For
End Try
If sKey <> "" Then sKey = sKey & ", "
sKey = sKey & sThisKey
Next Row
Else
' Set up error message
If tblFixtureMaster.CancelMessage <> "" Then
Message = tblFixtureMaster.CancelMessage
tblFixtureMaster.CancelMessage = ""
Else
Message = "Delete cancelled"
End If
End If
If DeleteRows Then
' Commit the changes
Conn.CommitTrans()
' Row deleted event
For Each Row As OrderedDictionary in RsOld
tblFixtureMaster.Row_Deleted(Row)
Next
Else
Conn.RollbackTrans() ' Rollback transaction
End If
End Function
'
' Load default values
'
Sub LoadDefaultValues()
End Sub
'
' Load recordset
'
Function LoadRecordset() As OleDbDataReader
' Recordset Selecting event
tblFixtureMaster.Recordset_Selecting(tblFixtureMaster.CurrentFilter)
' Load list page SQL
Dim sSql As String = tblFixtureMaster.ListSQL
' Write SQL for debug
If EW_DEBUG_ENABLED Then ew_Write(sSql)
' Count
lTotalRecs = -1
Try
If sSql.StartsWith("SELECT * FROM ", StringComparison.InvariantCultureIgnoreCase) AndAlso _
ew_Empty(tblFixtureMaster.SqlGroupBy) AndAlso _
ew_Empty(tblFixtureMaster.SqlHaving) Then
Dim sCntSql As String = tblFixtureMaster.SelectCountSQL
' Write SQL for debug
If EW_DEBUG_ENABLED Then ew_Write("<br>" & sCntSql)
lTotalRecs = Conn.ExecuteScalar(sCntSql)
End If
Catch
End Try
' Load recordset
Dim Rs As OleDbDataReader = Conn.GetDataReader(sSql)
If lTotalRecs < 0 AndAlso Rs.HasRows Then
lTotalRecs = 0
While Rs.Read()
lTotalRecs = lTotalRecs + 1
End While
Rs.Close()
Rs = Conn.GetDataReader(sSql)
End If
' Recordset Selected event
tblFixtureMaster.Recordset_Selected(Rs)
Return Rs
End Function
'
' Load row based on key values
'
Function LoadRow() As Boolean
Dim RsRow As OleDbDataReader
Dim sFilter As String = tblFixtureMaster.KeyFilter
' Row Selecting event
tblFixtureMaster.Row_Selecting(sFilter)
' Load SQL based on filter
tblFixtureMaster.CurrentFilter = sFilter
Dim sSql As String = tblFixtureMaster.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
tblFixtureMaster.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)
tblFixtureMaster.lfxID.DbValue = RsRow("lfxID")
tblFixtureMaster.lfxMFG.DbValue = RsRow("lfxMFG")
tblFixtureMaster.lfxModelType.DbValue = RsRow("lfxModelType")
tblFixtureMaster.lfxSerialNumber.DbValue = RsRow("lfxSerialNumber")
tblFixtureMaster.lfxLamp.DbValue = RsRow("lfxLamp")
tblFixtureMaster.lfxLocationID.DbValue = RsRow("lfxLocationID")
tblFixtureMaster.lfxHangPos.DbValue = RsRow("lfxHangPos")
tblFixtureMaster.lfxChannel.DbValue = RsRow("lfxChannel")
tblFixtureMaster.lfxNotes.DbValue = RsRow("lfxNotes")
End Sub
'
' Render row values based on field settings
'
Sub RenderRow()
' Row Rendering event
tblFixtureMaster.Row_Rendering()
'
' Common render codes for all row types
'
' lfxMFG
tblFixtureMaster.lfxMFG.CellCssStyle = ""
tblFixtureMaster.lfxMFG.CellCssClass = ""
' lfxModelType
tblFixtureMaster.lfxModelType.CellCssStyle = ""
tblFixtureMaster.lfxModelType.CellCssClass = ""
' lfxSerialNumber
tblFixtureMaster.lfxSerialNumber.CellCssStyle = ""
tblFixtureMaster.lfxSerialNumber.CellCssClass = ""
' lfxLamp
tblFixtureMaster.lfxLamp.CellCssStyle = ""
tblFixtureMaster.lfxLamp.CellCssClass = ""
' lfxLocationID
tblFixtureMaster.lfxLocationID.CellCssStyle = ""
tblFixtureMaster.lfxLocationID.CellCssClass = ""
' lfxHangPos
tblFixtureMaster.lfxHangPos.CellCssStyle = ""
tblFixtureMaster.lfxHangPos.CellCssClass = ""
' lfxChannel
tblFixtureMaster.lfxChannel.CellCssStyle = ""
tblFixtureMaster.lfxChannel.CellCssClass = ""
'
' View Row
'
If tblFixtureMaster.RowType = EW_ROWTYPE_VIEW Then ' View row
' lfxMFG
tblFixtureMaster.lfxMFG.ViewValue = tblFixtureMaster.lfxMFG.CurrentValue
tblFixtureMaster.lfxMFG.CssStyle = ""
tblFixtureMaster.lfxMFG.CssClass = ""
tblFixtureMaster.lfxMFG.ViewCustomAttributes = ""
' lfxModelType
tblFixtureMaster.lfxModelType.ViewValue = tblFixtureMaster.lfxModelType.CurrentValue
tblFixtureMaster.lfxModelType.CssStyle = ""
tblFixtureMaster.lfxModelType.CssClass = ""
tblFixtureMaster.lfxModelType.ViewCustomAttributes = ""
' lfxSerialNumber
tblFixtureMaster.lfxSerialNumber.ViewValue = tblFixtureMaster.lfxSerialNumber.CurrentValue
tblFixtureMaster.lfxSerialNumber.CssStyle = ""
tblFixtureMaster.lfxSerialNumber.CssClass = ""
tblFixtureMaster.lfxSerialNumber.ViewCustomAttributes = ""
' lfxLamp
tblFixtureMaster.lfxLamp.ViewValue = tblFixtureMaster.lfxLamp.CurrentValue
tblFixtureMaster.lfxLamp.CssStyle = ""
tblFixtureMaster.lfxLamp.CssClass = ""
tblFixtureMaster.lfxLamp.ViewCustomAttributes = ""
' lfxLocationID
If ew_NotEmpty(tblFixtureMaster.lfxLocationID.CurrentValue) Then
sSqlWrk = "SELECT [locDescription] FROM [tblLocations] WHERE [locID] = " & ew_AdjustSql(tblFixtureMaster.lfxLocationID.CurrentValue) & ""
sSqlWrk = sSqlWrk & " AND (" & "[locLighting]=True" & ")"
sSqlWrk = sSqlWrk & " ORDER BY [locDescription] "
RsWrk = Conn.GetTempDataReader(sSqlWrk)
If RsWrk.Read() Then
tblFixtureMaster.lfxLocationID.ViewValue = RsWrk("locDescription")
Else
tblFixtureMaster.lfxLocationID.ViewValue = tblFixtureMaster.lfxLocationID.CurrentValue
End If
Conn.CloseTempDataReader()
Else
tblFixtureMaster.lfxLocationID.ViewValue = System.DBNull.Value
End If
tblFixtureMaster.lfxLocationID.CssStyle = ""
tblFixtureMaster.lfxLocationID.CssClass = ""
tblFixtureMaster.lfxLocationID.ViewCustomAttributes = ""
' lfxHangPos
tblFixtureMaster.lfxHangPos.ViewValue = tblFixtureMaster.lfxHangPos.CurrentValue
tblFixtureMaster.lfxHangPos.CssStyle = ""
tblFixtureMaster.lfxHangPos.CssClass = ""
tblFixtureMaster.lfxHangPos.ViewCustomAttributes = ""
' lfxChannel
tblFixtureMaster.lfxChannel.ViewValue = tblFixtureMaster.lfxChannel.CurrentValue
tblFixtureMaster.lfxChannel.CssStyle = ""
tblFixtureMaster.lfxChannel.CssClass = ""
tblFixtureMaster.lfxChannel.ViewCustomAttributes = ""
' View refer script
' lfxMFG
tblFixtureMaster.lfxMFG.HrefValue = ""
' lfxModelType
tblFixtureMaster.lfxModelType.HrefValue = ""
' lfxSerialNumber
tblFixtureMaster.lfxSerialNumber.HrefValue = ""
' lfxLamp
tblFixtureMaster.lfxLamp.HrefValue = ""
' lfxLocationID
tblFixtureMaster.lfxLocationID.HrefValue = ""
' lfxHangPos
tblFixtureMaster.lfxHangPos.HrefValue = ""
' lfxChannel
tblFixtureMaster.lfxChannel.HrefValue = ""
End If
' Row Rendered event
tblFixtureMaster.Row_Rendered()
End Sub
' 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
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
tblFixtureMaster_delete = New ctblFixtureMaster_delete(Me)
tblFixtureMaster_delete.Page_Init()
' Page main processing
tblFixtureMaster_delete.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 tblFixtureMaster_delete IsNot Nothing Then tblFixtureMaster_delete.Dispose()
End Sub
End Class