home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
66.142.0.142
/
66.142.0.142.tar
/
66.142.0.142
/
ltgFixtureMasterdelete.aspx.vb
< prev
next >
Wrap
Text File
|
2014-01-25
|
20KB
|
674 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 ltgFixtureMasterdelete
Inherits AspNetMaker7_tfpssnet
' Page object
Public ltgFixtureMaster_delete As cltgFixtureMaster_delete
'
' Page Class
'
Class cltgFixtureMaster_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 ltgFixtureMaster.UseTokenInUrl Then Url = Url & "t=" & ltgFixtureMaster.TableVar & "&" ' Add page token
Return Url
End Get
End Property
' Validate page request
Public Function IsPageRequest() As Boolean
Dim Result As Boolean
If ltgFixtureMaster.UseTokenInUrl Then
Result = False
If ObjForm IsNot Nothing Then
Result = (ltgFixtureMaster.TableVar = ObjForm.GetValue("t"))
End If
If ew_Get("t") <> "" Then
Result = (ltgFixtureMaster.TableVar = ew_Get("t"))
End If
Return Result
End If
Return True
End Function
' ltgFixtureMaster
Public Property ltgFixtureMaster() As cltgFixtureMaster
Get
Return ParentPage.ltgFixtureMaster
End Get
Set(ByVal v As cltgFixtureMaster)
ParentPage.ltgFixtureMaster = v
End Set
End Property
' ltgFixtureMaster
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 = "ltgFixtureMaster_delete"
m_PageObjTypeName = "cltgFixtureMaster_delete"
' Table Name
m_TableName = "ltgFixtureMaster"
' Initialize table object
ltgFixtureMaster = New cltgFixtureMaster(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("ltgFixtureMasterlist.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
ltgFixtureMaster.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
ltgFixtureMaster.lfxID.QueryStringValue = ew_Get("lfxID")
If Not IsNumeric(ltgFixtureMaster.lfxID.QueryStringValue) Then
Page_Terminate("ltgFixtureMasterlist.aspx") ' Prevent SQL injection, return to list
End If
sKey = sKey & ltgFixtureMaster.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("ltgFixtureMasterlist.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("ltgFixtureMasterlist.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 ltgFixtureMaster class, ltgFixtureMasterinfo.aspx
ltgFixtureMaster.CurrentFilter = sFilter
' Get action
If ew_Post("a_delete") <> "" Then
ltgFixtureMaster.CurrentAction = ew_Post("a_delete")
Else
ltgFixtureMaster.CurrentAction = "I" ' Display record
End If
Select Case ltgFixtureMaster.CurrentAction
Case "D" ' Delete
ltgFixtureMaster.SendEmail = True ' Send email on delete success
If DeleteRows() Then ' delete rows
Message = "Delete succeeded" ' Set up success message
Page_Terminate(ltgFixtureMaster.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 = ltgFixtureMaster.CurrentFilter
' Set up filter (SQL WHERE Clause)
' SQL constructor in ltgFixtureMaster class, ltgFixtureMasterinfo.aspx
ltgFixtureMaster.CurrentFilter = sWrkFilter
sSql = ltgFixtureMaster.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 = ltgFixtureMaster.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
ltgFixtureMaster.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 ltgFixtureMaster.CancelMessage <> "" Then
Message = ltgFixtureMaster.CancelMessage
ltgFixtureMaster.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
ltgFixtureMaster.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
ltgFixtureMaster.Recordset_Selecting(ltgFixtureMaster.CurrentFilter)
' Load list page SQL
Dim sSql As String = ltgFixtureMaster.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(ltgFixtureMaster.SqlGroupBy) AndAlso _
ew_Empty(ltgFixtureMaster.SqlHaving) Then
Dim sCntSql As String = ltgFixtureMaster.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
ltgFixtureMaster.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 = ltgFixtureMaster.KeyFilter
' Row Selecting event
ltgFixtureMaster.Row_Selecting(sFilter)
' Load SQL based on filter
ltgFixtureMaster.CurrentFilter = sFilter
Dim sSql As String = ltgFixtureMaster.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
ltgFixtureMaster.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)
ltgFixtureMaster.lfxID.DbValue = RsRow("lfxID")
ltgFixtureMaster.lfxCode.DbValue = RsRow("lfxCode")
ltgFixtureMaster.lfxDescription.DbValue = RsRow("lfxDescription")
ltgFixtureMaster.lfxMFG.DbValue = RsRow("lfxMFG")
ltgFixtureMaster.lfxModel.DbValue = RsRow("lfxModel")
ltgFixtureMaster.lfxSerialNumber.DbValue = RsRow("lfxSerialNumber")
ltgFixtureMaster.lfxLamp.DbValue = RsRow("lfxLamp")
ltgFixtureMaster.lfxFixtureTypeID.DbValue = RsRow("lfxFixtureTypeID")
ltgFixtureMaster.lfxLocationID.DbValue = RsRow("lfxLocationID")
ltgFixtureMaster.lfxChannel.DbValue = RsRow("lfxChannel")
ltgFixtureMaster.lfxIsActive.DbValue = IIf(ew_ConvertToBool(RsRow("lfxIsActive")), "1", "0")
ltgFixtureMaster.lfxCreatedBy.DbValue = RsRow("lfxCreatedBy")
ltgFixtureMaster.lfxCreatedOn.DbValue = RsRow("lfxCreatedOn")
ltgFixtureMaster.lfxModifiedBy.DbValue = RsRow("lfxModifiedBy")
ltgFixtureMaster.lfxModifiedOn.DbValue = RsRow("lfxModifiedOn")
End Sub
'
' Render row values based on field settings
'
Sub RenderRow()
' Row Rendering event
ltgFixtureMaster.Row_Rendering()
'
' Common render codes for all row types
'
' lfxCode
ltgFixtureMaster.lfxCode.CellCssStyle = ""
ltgFixtureMaster.lfxCode.CellCssClass = ""
' lfxDescription
ltgFixtureMaster.lfxDescription.CellCssStyle = ""
ltgFixtureMaster.lfxDescription.CellCssClass = ""
' lfxMFG
ltgFixtureMaster.lfxMFG.CellCssStyle = ""
ltgFixtureMaster.lfxMFG.CellCssClass = ""
' lfxModel
ltgFixtureMaster.lfxModel.CellCssStyle = ""
ltgFixtureMaster.lfxModel.CellCssClass = ""
' lfxSerialNumber
ltgFixtureMaster.lfxSerialNumber.CellCssStyle = ""
ltgFixtureMaster.lfxSerialNumber.CellCssClass = ""
' lfxFixtureTypeID
ltgFixtureMaster.lfxFixtureTypeID.CellCssStyle = ""
ltgFixtureMaster.lfxFixtureTypeID.CellCssClass = ""
' lfxLocationID
ltgFixtureMaster.lfxLocationID.CellCssStyle = ""
ltgFixtureMaster.lfxLocationID.CellCssClass = ""
'
' View Row
'
If ltgFixtureMaster.RowType = EW_ROWTYPE_VIEW Then ' View row
' lfxID
ltgFixtureMaster.lfxID.ViewValue = ltgFixtureMaster.lfxID.CurrentValue
ltgFixtureMaster.lfxID.CssStyle = ""
ltgFixtureMaster.lfxID.CssClass = ""
ltgFixtureMaster.lfxID.ViewCustomAttributes = ""
' lfxCode
ltgFixtureMaster.lfxCode.ViewValue = ltgFixtureMaster.lfxCode.CurrentValue
ltgFixtureMaster.lfxCode.CssStyle = ""
ltgFixtureMaster.lfxCode.CssClass = ""
ltgFixtureMaster.lfxCode.ViewCustomAttributes = ""
' lfxDescription
ltgFixtureMaster.lfxDescription.ViewValue = ltgFixtureMaster.lfxDescription.CurrentValue
ltgFixtureMaster.lfxDescription.CssStyle = ""
ltgFixtureMaster.lfxDescription.CssClass = ""
ltgFixtureMaster.lfxDescription.ViewCustomAttributes = ""
' lfxMFG
ltgFixtureMaster.lfxMFG.ViewValue = ltgFixtureMaster.lfxMFG.CurrentValue
ltgFixtureMaster.lfxMFG.CssStyle = ""
ltgFixtureMaster.lfxMFG.CssClass = ""
ltgFixtureMaster.lfxMFG.ViewCustomAttributes = ""
' lfxModel
ltgFixtureMaster.lfxModel.ViewValue = ltgFixtureMaster.lfxModel.CurrentValue
ltgFixtureMaster.lfxModel.CssStyle = ""
ltgFixtureMaster.lfxModel.CssClass = ""
ltgFixtureMaster.lfxModel.ViewCustomAttributes = ""
' lfxSerialNumber
ltgFixtureMaster.lfxSerialNumber.ViewValue = ltgFixtureMaster.lfxSerialNumber.CurrentValue
ltgFixtureMaster.lfxSerialNumber.CssStyle = ""
ltgFixtureMaster.lfxSerialNumber.CssClass = ""
ltgFixtureMaster.lfxSerialNumber.ViewCustomAttributes = ""
' lfxLamp
ltgFixtureMaster.lfxLamp.ViewValue = ltgFixtureMaster.lfxLamp.CurrentValue
ltgFixtureMaster.lfxLamp.CssStyle = ""
ltgFixtureMaster.lfxLamp.CssClass = ""
ltgFixtureMaster.lfxLamp.ViewCustomAttributes = ""
' lfxFixtureTypeID
If ew_NotEmpty(ltgFixtureMaster.lfxFixtureTypeID.CurrentValue) Then
sSqlWrk = "SELECT [ftyDescription] FROM [ltgFixtureType] WHERE [ftyID] = " & ew_AdjustSql(ltgFixtureMaster.lfxFixtureTypeID.CurrentValue) & ""
sSqlWrk = sSqlWrk & " AND (" & "[ftyIsActive] = True" & ")"
sSqlWrk = sSqlWrk & " ORDER BY [ftyDescription] "
RsWrk = Conn.GetTempDataReader(sSqlWrk)
If RsWrk.Read() Then
ltgFixtureMaster.lfxFixtureTypeID.ViewValue = RsWrk("ftyDescription")
Else
ltgFixtureMaster.lfxFixtureTypeID.ViewValue = ltgFixtureMaster.lfxFixtureTypeID.CurrentValue
End If
Conn.CloseTempDataReader()
Else
ltgFixtureMaster.lfxFixtureTypeID.ViewValue = System.DBNull.Value
End If
ltgFixtureMaster.lfxFixtureTypeID.CssStyle = ""
ltgFixtureMaster.lfxFixtureTypeID.CssClass = ""
ltgFixtureMaster.lfxFixtureTypeID.ViewCustomAttributes = ""
' lfxLocationID
If ew_NotEmpty(ltgFixtureMaster.lfxLocationID.CurrentValue) Then
sSqlWrk = "SELECT [floDescription] FROM [ltgFixtureLocation] WHERE [floID] = " & ew_AdjustSql(ltgFixtureMaster.lfxLocationID.CurrentValue) & ""
sSqlWrk = sSqlWrk & " AND (" & "[floIsActive]=True" & ")"
sSqlWrk = sSqlWrk & " ORDER BY [floDescription] "
RsWrk = Conn.GetTempDataReader(sSqlWrk)
If RsWrk.Read() Then
ltgFixtureMaster.lfxLocationID.ViewValue = RsWrk("floDescription")
Else
ltgFixtureMaster.lfxLocationID.ViewValue = ltgFixtureMaster.lfxLocationID.CurrentValue
End If
Conn.CloseTempDataReader()
Else
ltgFixtureMaster.lfxLocationID.ViewValue = System.DBNull.Value
End If
ltgFixtureMaster.lfxLocationID.CssStyle = ""
ltgFixtureMaster.lfxLocationID.CssClass = ""
ltgFixtureMaster.lfxLocationID.ViewCustomAttributes = ""
' lfxChannel
ltgFixtureMaster.lfxChannel.ViewValue = ltgFixtureMaster.lfxChannel.CurrentValue
ltgFixtureMaster.lfxChannel.CssStyle = ""
ltgFixtureMaster.lfxChannel.CssClass = ""
ltgFixtureMaster.lfxChannel.ViewCustomAttributes = ""
' lfxIsActive
If Convert.ToString(ltgFixtureMaster.lfxIsActive.CurrentValue) = "1" Then
ltgFixtureMaster.lfxIsActive.ViewValue = "Yes"
Else
ltgFixtureMaster.lfxIsActive.ViewValue = "No"
End If
ltgFixtureMaster.lfxIsActive.CssStyle = ""
ltgFixtureMaster.lfxIsActive.CssClass = ""
ltgFixtureMaster.lfxIsActive.ViewCustomAttributes = ""
' lfxCreatedBy
ltgFixtureMaster.lfxCreatedBy.ViewValue = ltgFixtureMaster.lfxCreatedBy.CurrentValue
ltgFixtureMaster.lfxCreatedBy.CssStyle = ""
ltgFixtureMaster.lfxCreatedBy.CssClass = ""
ltgFixtureMaster.lfxCreatedBy.ViewCustomAttributes = ""
' lfxCreatedOn
ltgFixtureMaster.lfxCreatedOn.ViewValue = ltgFixtureMaster.lfxCreatedOn.CurrentValue
ltgFixtureMaster.lfxCreatedOn.ViewValue = ew_FormatDateTime(ltgFixtureMaster.lfxCreatedOn.ViewValue, 6)
ltgFixtureMaster.lfxCreatedOn.CssStyle = ""
ltgFixtureMaster.lfxCreatedOn.CssClass = ""
ltgFixtureMaster.lfxCreatedOn.ViewCustomAttributes = ""
' lfxModifiedBy
ltgFixtureMaster.lfxModifiedBy.ViewValue = ltgFixtureMaster.lfxModifiedBy.CurrentValue
ltgFixtureMaster.lfxModifiedBy.CssStyle = ""
ltgFixtureMaster.lfxModifiedBy.CssClass = ""
ltgFixtureMaster.lfxModifiedBy.ViewCustomAttributes = ""
' lfxModifiedOn
ltgFixtureMaster.lfxModifiedOn.ViewValue = ltgFixtureMaster.lfxModifiedOn.CurrentValue
ltgFixtureMaster.lfxModifiedOn.ViewValue = ew_FormatDateTime(ltgFixtureMaster.lfxModifiedOn.ViewValue, 6)
ltgFixtureMaster.lfxModifiedOn.CssStyle = ""
ltgFixtureMaster.lfxModifiedOn.CssClass = ""
ltgFixtureMaster.lfxModifiedOn.ViewCustomAttributes = ""
' View refer script
' lfxCode
ltgFixtureMaster.lfxCode.HrefValue = ""
' lfxDescription
ltgFixtureMaster.lfxDescription.HrefValue = ""
' lfxMFG
ltgFixtureMaster.lfxMFG.HrefValue = ""
' lfxModel
ltgFixtureMaster.lfxModel.HrefValue = ""
' lfxSerialNumber
ltgFixtureMaster.lfxSerialNumber.HrefValue = ""
' lfxFixtureTypeID
ltgFixtureMaster.lfxFixtureTypeID.HrefValue = ""
' lfxLocationID
ltgFixtureMaster.lfxLocationID.HrefValue = ""
End If
' Row Rendered event
ltgFixtureMaster.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
ltgFixtureMaster_delete = New cltgFixtureMaster_delete(Me)
ltgFixtureMaster_delete.Page_Init()
' Page main processing
ltgFixtureMaster_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 ltgFixtureMaster_delete IsNot Nothing Then ltgFixtureMaster_delete.Dispose()
End Sub
End Class