home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblLPRFixtureTypedelete.aspx.vb < prev    next >
Text File  |  2010-08-24  |  14KB  |  507 lines

  1. Imports System.Data
  2. Imports System.Data.Common
  3. Imports System.Xml
  4. Imports System.IO
  5. Imports System.Data.OleDb
  6.  
  7. '
  8. ' ASP.NET code-behind class (Page)
  9. '
  10.  
  11. Partial Class tblLPRFixtureTypedelete
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblLPRFixtureType_delete As ctblLPRFixtureType_delete
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblLPRFixtureType_delete
  21.         Inherits AspNetMakerPage
  22.         Implements IDisposable        
  23.  
  24.         ' Used by system generated functions
  25.         Private RsWrk As Object, sSqlWrk As String, sWhereWrk As String
  26.  
  27.         Private arwrk As Object
  28.  
  29.         Private armultiwrk() As String        
  30.  
  31.         ' Page URL
  32.         Public ReadOnly Property PageUrl() As String
  33.             Get
  34.                 Dim Url As String = ew_CurrentPage() & "?"
  35.                 If tblLPRFixtureType.UseTokenInUrl Then Url = Url & "t=" & tblLPRFixtureType.TableVar & "&" ' Add page token
  36.                 Return Url    
  37.             End Get
  38.         End Property
  39.  
  40.         ' Validate page request
  41.         Public Function IsPageRequest() As Boolean
  42.             Dim Result As Boolean
  43.             If tblLPRFixtureType.UseTokenInUrl Then
  44.                 Result = False
  45.                 If ObjForm IsNot Nothing Then
  46.                     Result = (tblLPRFixtureType.TableVar = ObjForm.GetValue("t"))
  47.                 End If
  48.                 If ew_Get("t") <> "" Then
  49.                     Result = (tblLPRFixtureType.TableVar = ew_Get("t"))
  50.                 End If
  51.                 Return Result
  52.             End If
  53.             Return True            
  54.         End Function    
  55.  
  56.         ' tblLPRFixtureType
  57.         Public Property tblLPRFixtureType() As ctblLPRFixtureType
  58.             Get                
  59.                 Return ParentPage.tblLPRFixtureType
  60.             End Get
  61.             Set(ByVal v As ctblLPRFixtureType)
  62.                 ParentPage.tblLPRFixtureType = v    
  63.             End Set    
  64.         End Property
  65.  
  66.         ' tblLPRFixtureType
  67.         Public Property tblEmployees() As ctblEmployees
  68.             Get                
  69.                 Return ParentPage.tblEmployees
  70.             End Get
  71.             Set(ByVal v As ctblEmployees)
  72.                 ParentPage.tblEmployees = v    
  73.             End Set    
  74.         End Property
  75.  
  76.         '
  77.         '  Constructor
  78.         '  - init objects
  79.         '  - open connection
  80.         '
  81.         Public Sub New(ByRef APage As AspNetMaker7_tfpssnet)                
  82.             m_ParentPage = APage
  83.             m_Page = Me    
  84.             m_PageID = "delete"
  85.             m_PageObjName = "tblLPRFixtureType_delete"
  86.             m_PageObjTypeName = "ctblLPRFixtureType_delete"
  87.  
  88.             ' Table Name
  89.             m_TableName = "tblLPRFixtureType"
  90.  
  91.             ' Initialize table object
  92.             tblLPRFixtureType = New ctblLPRFixtureType(Me)
  93.             tblEmployees = New ctblEmployees(Me)
  94.  
  95.             ' Connect to database
  96.             Conn = New cConnection()
  97.         End Sub
  98.  
  99.         '
  100.         '  Subroutine Page_Init
  101.         '  - called before page main
  102.         '  - check Security
  103.         '  - set up response header
  104.         '  - call page load events
  105.         '
  106.         Public Sub Page_Init()
  107.             Security = New cAdvancedSecurity(Me)
  108.             If Not Security.IsLoggedIn() Then Security.AutoLogin()
  109.             If Not Security.IsLoggedIn() Then
  110.                 Security.SaveLastUrl()
  111.                 Page_Terminate("login.aspx")
  112.             End If
  113.  
  114.             ' Table Permission loading event
  115.             Security.TablePermission_Loading()
  116.             Security.LoadCurrentUserLevel(TableName)
  117.  
  118.             ' Table Permission loaded event
  119.             Security.TablePermission_Loaded()
  120.             If Not Security.CanDelete Then
  121.                 Security.SaveLastUrl()
  122.                 Page_Terminate("tblLPRFixtureTypelist.aspx")
  123.             End If
  124.  
  125.             ' User ID loading event
  126.             Security.UserID_Loading()
  127.             If Security.IsLoggedIn() Then Call Security.LoadUserID()
  128.  
  129.             ' User ID loaded event
  130.             Security.UserID_Loaded()
  131.  
  132.             ' Global page loading event (in ewglobal*.vb)
  133.             ParentPage.Page_Loading()
  134.  
  135.             ' Page load event, used in current page
  136.             Page_Load()
  137.         End Sub
  138.  
  139.         '
  140.         '  Class terminate
  141.         '  - clean up page object
  142.         '
  143.         Public Sub Dispose() Implements IDisposable.Dispose
  144.             Page_Terminate("")
  145.         End Sub
  146.  
  147.         '
  148.         '  Sub Page_Terminate
  149.         '  - called when exit page
  150.         '  - clean up connection and objects
  151.         '  - if URL specified, redirect to URL
  152.         '
  153.         Sub Page_Terminate(url As String)
  154.  
  155.             ' Page unload event, used in current page
  156.             Page_Unload()
  157.  
  158.             ' Global page unloaded event (in ewglobal*.vb)
  159.             ParentPage.Page_Unloaded()
  160.  
  161.             ' Close connection
  162.             Conn.Dispose()
  163.             Security = Nothing
  164.             tblLPRFixtureType.Dispose()
  165.             tblEmployees.Dispose()
  166.  
  167.             ' Go to URL if specified
  168.             If url <> "" Then
  169.                 HttpContext.Current.Response.Clear()
  170.                 HttpContext.Current.Response.Redirect(url)
  171.             End If
  172.         End Sub
  173.  
  174.     Public lTotalRecs As Integer
  175.  
  176.     Public lRecCnt As Integer
  177.  
  178.     Public arRecKeys() As String
  179.  
  180.     '
  181.     ' Page main processing
  182.     '
  183.     Sub Page_Main()
  184.         Dim sKey As String = ""
  185.         Dim bSingleDelete As Boolean = True ' Initialize as single delete
  186.         Dim nKeySelected As Integer = 0 ' Initialize selected key count
  187.         Dim sKeyFld As String, arKeyFlds() As String
  188.         Dim sFilter As String        
  189.  
  190.         ' Load Key Parameters
  191.         If ew_Get("ftyID") <> "" Then
  192.             tblLPRFixtureType.ftyID.QueryStringValue = ew_Get("ftyID")
  193.             If Not IsNumeric(tblLPRFixtureType.ftyID.QueryStringValue) Then
  194.             Page_Terminate("tblLPRFixtureTypelist.aspx") ' Prevent SQL injection, return to list
  195.             End If
  196.             sKey = sKey & tblLPRFixtureType.ftyID.QueryStringValue
  197.         Else
  198.             bSingleDelete = False
  199.         End If
  200.         If bSingleDelete Then
  201.             nKeySelected = 1 ' Set up key selected count
  202.             Array.Resize(arRecKeys, 1) ' Set up key
  203.             arRecKeys(0) = sKey
  204.         Else
  205.             If HttpContext.Current.Request.Form("key_m") IsNot Nothing Then ' Key in form
  206.                 arRecKeys = HttpContext.Current.Request.Form.GetValues("key_m")
  207.                 nKeySelected = arRecKeys.Length                
  208.             End If
  209.         End If
  210.         If nKeySelected <= 0 Then Page_Terminate("tblLPRFixtureTypelist.aspx") ' No key specified, return to list
  211.  
  212.         ' Build filter
  213.         For i As Integer = 0 to arRecKeys.GetUpperBound(0)
  214.             sKey = arRecKeys(i).Trim()
  215.             sFilter = sFilter & "("
  216.  
  217.             ' Set up key field
  218.             sKeyFld = sKey
  219.             If Not IsNumeric(sKeyFld) Then Page_Terminate("tblLPRFixtureTypelist.aspx") ' Prevent SQL injection, return to list
  220.             sFilter = sFilter & "[ftyID]=" & ew_AdjustSql(sKeyFld) & " AND "
  221.             If sFilter.EndsWith(" AND ") Then sFilter = sFilter.Substring(0, sFilter.Length-5) & ") OR "
  222.         Next
  223.         If sFilter.EndsWith(" OR ") Then sFilter = sFilter.Substring(0, sFilter.Length-4)
  224.  
  225.         ' Set up filter (SQL WHERE clause)
  226.         ' SQL constructor in tblLPRFixtureType class, tblLPRFixtureTypeinfo.aspx
  227.  
  228.         tblLPRFixtureType.CurrentFilter = sFilter
  229.  
  230.         ' Get action
  231.         If ew_Post("a_delete") <> "" Then
  232.             tblLPRFixtureType.CurrentAction = ew_Post("a_delete")
  233.         Else
  234.             tblLPRFixtureType.CurrentAction = "I"    ' Display record
  235.         End If
  236.         Select Case tblLPRFixtureType.CurrentAction
  237.             Case "D" ' Delete
  238.                 tblLPRFixtureType.SendEmail = True ' Send email on delete success
  239.                 If DeleteRows() Then ' delete rows
  240.                     Message = "Delete succeeded" ' Set up success message
  241.                 Page_Terminate(tblLPRFixtureType.ReturnUrl) ' Return to caller
  242.                 End If
  243.         End Select
  244.     End Sub
  245.  
  246.     '
  247.     '  Function DeleteRows
  248.     '  - Delete Records based on current filter
  249.     '
  250.     Function DeleteRows() As Boolean
  251.             'Dim sKey As String, sThisKey As String, sKeyFld As String
  252.             'Dim arKeyFlds() As String
  253.             'Dim RsDelete As OleDbDataReader = Nothing
  254.             'Dim sSql As String, sWrkFilter As String 
  255.             'Dim RsOld As ArrayList
  256.             'DeleteRows = True
  257.             'sWrkFilter = tblLPRFixtureType.CurrentFilter
  258.  
  259.             '' Set up filter (SQL WHERE Clause)
  260.             '' SQL constructor in tblLPRFixtureType class, tblLPRFixtureTypeinfo.aspx
  261.  
  262.             'tblLPRFixtureType.CurrentFilter = sWrkFilter
  263.             'sSql = tblLPRFixtureType.SQL
  264.             'Conn.BeginTrans() ' Begin transaction
  265.             'Try
  266.             '    RsDelete = Conn.GetDataReader(sSql)
  267.             '    If Not RsDelete.HasRows Then
  268.             '        Message = "No records found" ' No record found
  269.             '        RsDelete.Close()
  270.             '        RsDelete.Dispose()                    
  271.             '        Return False
  272.             '    End If
  273.             'Catch e As Exception
  274.             '    If EW_DEBUG_ENABLED Then Throw
  275.             '    Message = e.Message
  276.             '    Return False
  277.             'End Try
  278.  
  279.             '' Clone old rows
  280.             'RsOld = Conn.GetRows(RsDelete)
  281.             'RsDelete.Close()
  282.             'RsDelete.Dispose()
  283.  
  284.             '' Call Row_Deleting event
  285.             'If DeleteRows Then
  286.             '    For Each Row As OrderedDictionary in RsOld
  287.             '        DeleteRows = tblLPRFixtureType.Row_Deleting(Row)
  288.             '        If Not DeleteRows Then Exit For
  289.             '    Next Row
  290.             'End If
  291.             'If DeleteRows Then
  292.             '    sKey = ""
  293.             '    For Each Row As OrderedDictionary in RsOld
  294.             '        sThisKey = ""
  295.             '        If sThisKey <> "" Then sThisKey = sThisKey & EW_COMPOSITE_KEY_SEPARATOR
  296.             '        sThisKey = sThisKey & Convert.ToString(Row("ftyID"))
  297.             '        Try
  298.             '            tblLPRFixtureType.Delete(Row)
  299.             '        Catch e As Exception
  300.             '            If EW_DEBUG_ENABLED Then Throw            
  301.             '            Message = e.Message ' Set up error message
  302.             '            DeleteRows = False
  303.             '            Exit For
  304.             '        End Try
  305.             '        If sKey <> "" Then sKey = sKey & ", "
  306.             '        sKey = sKey & sThisKey
  307.             '    Next Row
  308.             'Else
  309.  
  310.             '    ' Set up error message
  311.             '    If tblLPRFixtureType.CancelMessage <> "" Then
  312.             '        Message = tblLPRFixtureType.CancelMessage
  313.             '        tblLPRFixtureType.CancelMessage = ""
  314.             '    Else
  315.             '        Message = "Delete cancelled"
  316.             '    End If
  317.             'End If
  318.             'If DeleteRows Then
  319.  
  320.             '    ' Commit the changes
  321.             '    Conn.CommitTrans()                
  322.  
  323.             '    ' Row deleted event
  324.             '    For Each Row As OrderedDictionary in RsOld
  325.             '        tblLPRFixtureType.Row_Deleted(Row)
  326.             '    Next
  327.             'Else
  328.             '    Conn.RollbackTrans() ' Rollback transaction            
  329.             'End If
  330.             Dim tlcsub As New AspNetMaker7_tfpssnet
  331.             If tlcsub.tlcUpdateIsActive("tblLPRFixtureType", "ftyID", "ftyIsActive", tblLPRFixtureType.ftyID.CurrentValue, False) Then
  332.                 Message = "Delete succeeded"
  333.             End If
  334.         End Function
  335.  
  336.     '
  337.     ' Load default values
  338.     '
  339.     Sub LoadDefaultValues()
  340.     End Sub
  341.  
  342.     '
  343.     ' Load recordset
  344.     '
  345.     Function LoadRecordset() As OleDbDataReader
  346.  
  347.         ' Recordset Selecting event
  348.         tblLPRFixtureType.Recordset_Selecting(tblLPRFixtureType.CurrentFilter)
  349.  
  350.         ' Load list page SQL
  351.         Dim sSql As String = tblLPRFixtureType.ListSQL
  352.  
  353.         ' Write SQL for debug
  354.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  355.  
  356.         ' Count
  357.         lTotalRecs = -1        
  358.         Try            
  359.             If sSql.StartsWith("SELECT * FROM ", StringComparison.InvariantCultureIgnoreCase) AndAlso _                
  360.                 ew_Empty(tblLPRFixtureType.SqlGroupBy) AndAlso _
  361.                 ew_Empty(tblLPRFixtureType.SqlHaving) Then
  362.                 Dim sCntSql As String = tblLPRFixtureType.SelectCountSQL
  363.  
  364.                 ' Write SQL for debug
  365.                 If EW_DEBUG_ENABLED Then ew_Write("<br>" & sCntSql)
  366.                 lTotalRecs = Conn.ExecuteScalar(sCntSql)
  367.             End If            
  368.         Catch
  369.         End Try
  370.  
  371.         ' Load recordset
  372.         Dim Rs As OleDbDataReader = Conn.GetDataReader(sSql)
  373.         If lTotalRecs < 0 AndAlso Rs.HasRows Then
  374.             lTotalRecs = 0
  375.             While Rs.Read()
  376.                 lTotalRecs = lTotalRecs + 1
  377.             End While
  378.             Rs.Close()        
  379.             Rs = Conn.GetDataReader(sSql)
  380.         End If
  381.  
  382.         ' Recordset Selected event
  383.         tblLPRFixtureType.Recordset_Selected(Rs)
  384.         Return Rs
  385.     End Function
  386.  
  387.     '
  388.     ' Load row based on key values
  389.     '
  390.     Function LoadRow() As Boolean
  391.         Dim RsRow As OleDbDataReader
  392.         Dim sFilter As String = tblLPRFixtureType.KeyFilter
  393.  
  394.         ' Row Selecting event
  395.         tblLPRFixtureType.Row_Selecting(sFilter)
  396.  
  397.         ' Load SQL based on filter
  398.         tblLPRFixtureType.CurrentFilter = sFilter
  399.         Dim sSql As String = tblLPRFixtureType.SQL
  400.  
  401.         ' Write SQL for debug
  402.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  403.         Try
  404.             RsRow = Conn.GetTempDataReader(sSql)    
  405.             If Not RsRow.Read() Then
  406.                 Return False
  407.             Else                
  408.                 LoadRowValues(RsRow) ' Load row values
  409.  
  410.                 ' Row Selected event
  411.                 tblLPRFixtureType.Row_Selected(RsRow)
  412.                 Return True    
  413.             End If
  414.         Catch
  415.             If EW_DEBUG_ENABLED Then Throw
  416.             Return False
  417.         Finally
  418.             Conn.CloseTempDataReader()
  419.         End Try
  420.     End Function
  421.  
  422.     '
  423.     ' Load row values from recordset
  424.     '
  425.     Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
  426.         tblLPRFixtureType.ftyID.DbValue = RsRow("ftyID")
  427.         tblLPRFixtureType.ftyDescription.DbValue = RsRow("ftyDescription")
  428.     End Sub
  429.  
  430.     '
  431.     ' Render row values based on field settings
  432.     '
  433.     Sub RenderRow()
  434.  
  435.         ' Row Rendering event
  436.         tblLPRFixtureType.Row_Rendering()
  437.  
  438.         '
  439.         '  Common render codes for all row types
  440.         '
  441.         ' ftyDescription
  442.  
  443.         tblLPRFixtureType.ftyDescription.CellCssStyle = ""
  444.         tblLPRFixtureType.ftyDescription.CellCssClass = ""
  445.  
  446.         '
  447.         '  View  Row
  448.         '
  449.  
  450.         If tblLPRFixtureType.RowType = EW_ROWTYPE_VIEW Then ' View row
  451.  
  452.             ' ftyDescription
  453.             tblLPRFixtureType.ftyDescription.ViewValue = tblLPRFixtureType.ftyDescription.CurrentValue
  454.             tblLPRFixtureType.ftyDescription.CssStyle = ""
  455.             tblLPRFixtureType.ftyDescription.CssClass = ""
  456.             tblLPRFixtureType.ftyDescription.ViewCustomAttributes = ""
  457.  
  458.             ' View refer script
  459.             ' ftyDescription
  460.  
  461.             tblLPRFixtureType.ftyDescription.HrefValue = ""
  462.         End If
  463.  
  464.         ' Row Rendered event
  465.         tblLPRFixtureType.Row_Rendered()
  466.     End Sub
  467.  
  468.         ' Page Load event
  469.         Public Sub Page_Load()
  470.  
  471.             'HttpContext.Current.Response.Write("Page Load")
  472.         End Sub
  473.  
  474.         ' Page Unload event
  475.         Public Sub Page_Unload()
  476.  
  477.             'HttpContext.Current.Response.Write("Page Unload")
  478.         End Sub
  479.     End Class
  480.  
  481.     '
  482.     ' ASP.NET Page_Load event
  483.     '
  484.  
  485.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  486.         Response.Buffer = EW_RESPONSE_BUFFER
  487.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  488.  
  489.         ' Page init
  490.         tblLPRFixtureType_delete = New ctblLPRFixtureType_delete(Me)        
  491.         tblLPRFixtureType_delete.Page_Init()
  492.  
  493.         ' Page main processing
  494.         tblLPRFixtureType_delete.Page_Main()
  495.     End Sub
  496.  
  497.     '
  498.     ' ASP.NET Page_Unload event
  499.     '
  500.  
  501.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  502.  
  503.         ' Dispose page object
  504.         If tblLPRFixtureType_delete IsNot Nothing Then tblLPRFixtureType_delete.Dispose()
  505.     End Sub
  506. End Class
  507.