home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblTypesedit.aspx.vb < prev    next >
Text File  |  2010-08-24  |  12KB  |  486 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 tblTypesedit
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblTypes_edit As ctblTypes_edit
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblTypes_edit
  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 tblTypes.UseTokenInUrl Then Url = Url & "t=" & tblTypes.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 tblTypes.UseTokenInUrl Then
  44.                 Result = False
  45.                 If ObjForm IsNot Nothing Then
  46.                     Result = (tblTypes.TableVar = ObjForm.GetValue("t"))
  47.                 End If
  48.                 If ew_Get("t") <> "" Then
  49.                     Result = (tblTypes.TableVar = ew_Get("t"))
  50.                 End If
  51.                 Return Result
  52.             End If
  53.             Return True            
  54.         End Function    
  55.  
  56.         ' tblTypes
  57.         Public Property tblTypes() As ctblTypes
  58.             Get                
  59.                 Return ParentPage.tblTypes
  60.             End Get
  61.             Set(ByVal v As ctblTypes)
  62.                 ParentPage.tblTypes = v    
  63.             End Set    
  64.         End Property
  65.  
  66.         ' tblTypes
  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 = "edit"
  85.             m_PageObjName = "tblTypes_edit"
  86.             m_PageObjTypeName = "ctblTypes_edit"
  87.  
  88.             ' Table Name
  89.             m_TableName = "tblTypes"
  90.  
  91.             ' Initialize table object
  92.             tblTypes = New ctblTypes(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.CanEdit Then
  121.                 Security.SaveLastUrl()
  122.                 Page_Terminate("tblTypeslist.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.             tblTypes.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.     '
  175.     ' Page main processing
  176.     '
  177.     Sub Page_Main()
  178.  
  179.         ' Load key from QueryString
  180.         If ew_Get("typID") <> "" Then
  181.             tblTypes.typID.QueryStringValue = ew_Get("typID")
  182.         End If
  183.  
  184.         ' Create form object
  185.         ObjForm = New cFormObj
  186.         If ObjForm.GetValue("a_edit") <> "" Then
  187.             tblTypes.CurrentAction = ObjForm.GetValue("a_edit") ' Get action code
  188.             LoadFormValues() ' Get form values
  189.  
  190.             ' Validate Form
  191.             If Not ValidateForm() Then
  192.                 tblTypes.CurrentAction = "" ' Form error, reset action
  193.                 Message = ParentPage.gsFormError
  194.                 LoadRow() ' Restore row
  195.                 RestoreFormValues() ' Restore form values if validate failed
  196.             End If
  197.         Else
  198.             tblTypes.CurrentAction = "I" ' Default action is display
  199.         End If
  200.  
  201.         ' Check if valid key
  202.         If ew_Empty(tblTypes.typID.CurrentValue) Then Page_Terminate("tblTypeslist.aspx") ' Invalid key, return to list
  203.         Select Case tblTypes.CurrentAction
  204.             Case "I" ' Get a record to display
  205.                 If Not LoadRow() Then ' Load Record based on key
  206.                     Message = "No records found" ' No record found
  207.                     Page_Terminate("tblTypeslist.aspx") ' No matching record, return to list
  208.                 End If
  209.             Case "U" ' Update
  210.                 tblTypes.SendEmail = True ' Send email on update success
  211.                 If EditRow() Then ' Update Record based on key
  212.                     Message = "Update succeeded" ' Update success
  213.                     Dim sReturnUrl As String = tblTypes.ReturnUrl
  214.                     Page_Terminate(sReturnUrl) ' Return to caller
  215.                 Else
  216.                     LoadRow() ' Restore row
  217.                     RestoreFormValues() ' Restore form values if update failed
  218.                 End If
  219.         End Select
  220.  
  221.         ' Render the record
  222.         tblTypes.RowType = EW_ROWTYPE_EDIT ' Render as edit
  223.  
  224.         ' Render row
  225.         RenderRow()
  226.     End Sub
  227.  
  228.     '
  229.     ' Get upload file
  230.     '
  231.     Sub GetUploadFiles()
  232.  
  233.         ' Get upload data
  234.     End Sub
  235.  
  236.     '
  237.     ' Load default values
  238.     '
  239.     Sub LoadDefaultValues()
  240.     End Sub
  241.  
  242.     '
  243.     ' Load form values
  244.     '
  245.     Sub LoadFormValues()
  246.         tblTypes.typDescription.FormValue = ObjForm.GetValue("x_typDescription")
  247.         tblTypes.typDescription.OldValue = ObjForm.GetValue("o_typDescription")
  248.         tblTypes.typID.FormValue = ObjForm.GetValue("x_typID")
  249.     End Sub
  250.  
  251.     '
  252.     ' Restore form values
  253.     '
  254.     Sub RestoreFormValues()
  255.         tblTypes.typDescription.CurrentValue = tblTypes.typDescription.FormValue
  256.         tblTypes.typID.CurrentValue = tblTypes.typID.FormValue
  257.     End Sub
  258.  
  259.     '
  260.     ' Load row based on key values
  261.     '
  262.     Function LoadRow() As Boolean
  263.         Dim RsRow As OleDbDataReader
  264.         Dim sFilter As String = tblTypes.KeyFilter
  265.  
  266.         ' Row Selecting event
  267.         tblTypes.Row_Selecting(sFilter)
  268.  
  269.         ' Load SQL based on filter
  270.         tblTypes.CurrentFilter = sFilter
  271.         Dim sSql As String = tblTypes.SQL
  272.  
  273.         ' Write SQL for debug
  274.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  275.         Try
  276.             RsRow = Conn.GetTempDataReader(sSql)    
  277.             If Not RsRow.Read() Then
  278.                 Return False
  279.             Else                
  280.                 LoadRowValues(RsRow) ' Load row values
  281.  
  282.                 ' Row Selected event
  283.                 tblTypes.Row_Selected(RsRow)
  284.                 Return True    
  285.             End If
  286.         Catch
  287.             If EW_DEBUG_ENABLED Then Throw
  288.             Return False
  289.         Finally
  290.             Conn.CloseTempDataReader()
  291.         End Try
  292.     End Function
  293.  
  294.     '
  295.     ' Load row values from recordset
  296.     '
  297.     Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
  298.         tblTypes.typID.DbValue = RsRow("typID")
  299.         tblTypes.typDescription.DbValue = RsRow("typDescription")
  300.     End Sub
  301.  
  302.     '
  303.     ' Render row values based on field settings
  304.     '
  305.     Sub RenderRow()
  306.  
  307.         ' Row Rendering event
  308.         tblTypes.Row_Rendering()
  309.  
  310.         '
  311.         '  Common render codes for all row types
  312.         '
  313.         ' typDescription
  314.  
  315.         tblTypes.typDescription.CellCssStyle = ""
  316.         tblTypes.typDescription.CellCssClass = ""
  317.  
  318.         '
  319.         '  View  Row
  320.         '
  321.  
  322.         If tblTypes.RowType = EW_ROWTYPE_VIEW Then ' View row
  323.  
  324.             ' typDescription
  325.             tblTypes.typDescription.ViewValue = tblTypes.typDescription.CurrentValue
  326.             tblTypes.typDescription.CssStyle = ""
  327.             tblTypes.typDescription.CssClass = ""
  328.             tblTypes.typDescription.ViewCustomAttributes = ""
  329.  
  330.             ' View refer script
  331.             ' typDescription
  332.  
  333.             tblTypes.typDescription.HrefValue = ""
  334.  
  335.         '
  336.         '  Edit Row
  337.         '
  338.  
  339.         ElseIf tblTypes.RowType = EW_ROWTYPE_EDIT Then ' Edit row
  340.  
  341.             ' typDescription
  342.             tblTypes.typDescription.EditCustomAttributes = ""
  343.             tblTypes.typDescription.EditValue = ew_HtmlEncode(tblTypes.typDescription.CurrentValue)
  344.  
  345.             ' Edit refer script
  346.             ' typDescription
  347.  
  348.             tblTypes.typDescription.HrefValue = ""
  349.         End If
  350.  
  351.         ' Row Rendered event
  352.         tblTypes.Row_Rendered()
  353.     End Sub
  354.  
  355.     '
  356.     ' Validate form
  357.     '
  358.     Function ValidateForm() As Boolean
  359.  
  360.         ' Initialize
  361.         ParentPage.gsFormError = ""
  362.  
  363.         ' Check if validation required
  364.         If Not EW_SERVER_VALIDATE Then Return (ParentPage.gsFormError = "")
  365.  
  366.         ' Return validate result
  367.         Dim Valid As Boolean = (ParentPage.gsFormError = "")
  368.  
  369.         ' Form_CustomValidate event
  370.         Dim sFormCustomError As String = ""
  371.         Valid = Valid And Form_CustomValidate(sFormCustomError)
  372.         If sFormCustomError <> "" Then
  373.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  374.             ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  375.         End If
  376.         Return Valid
  377.     End Function
  378.  
  379.     '
  380.     ' Update record based on key values
  381.     '
  382.     Function EditRow() As Boolean
  383.         Dim RsEdit As OleDbDataReader, RsChk As OleDbDataReader
  384.         Dim sSql As String, sFilter As String
  385.         Dim sSqlChk As String, sFilterChk As String
  386.         Dim bUpdateRow As Boolean
  387.         Dim RsOld As OrderedDictionary
  388.         Dim sIdxErrMsg As String
  389.         Dim Rs As New OrderedDictionary
  390.         sFilter = tblTypes.KeyFilter
  391.         tblTypes.CurrentFilter  = sFilter
  392.         sSql = tblTypes.SQL
  393.         Try
  394.             RsEdit = Conn.GetDataReader(sSql) 
  395.         Catch e As Exception
  396.             If EW_DEBUG_ENABLED Then Throw
  397.             Message = e.Message
  398.             RsEdit.Close()
  399.             EditRow = False
  400.         End Try
  401.         If Not RsEdit.Read() Then
  402.             RsEdit.Close()
  403.             EditRow = False ' Update Failed
  404.         Else
  405.             RsOld = Conn.GetRow(RsEdit)
  406.             RsEdit.Close()
  407.  
  408.             ' typDescription
  409.             tblTypes.typDescription.SetDbValue(tblTypes.typDescription.CurrentValue, System.DBNull.Value)
  410.             Rs("typDescription") = tblTypes.typDescription.DbValue
  411.  
  412.             ' Row Updating event
  413.             bUpdateRow = tblTypes.Row_Updating(RsOld, Rs)
  414.             If bUpdateRow Then
  415.                 Try
  416.                     tblTypes.Update(Rs)
  417.                     EditRow = True
  418.                 Catch e As Exception
  419.                     If EW_DEBUG_ENABLED Then Throw
  420.                     Message = e.Message
  421.                     EditRow = False
  422.                 End Try
  423.             Else
  424.                 If tblTypes.CancelMessage <> "" Then
  425.                     Message = tblTypes.CancelMessage
  426.                     tblTypes.CancelMessage = ""
  427.                 Else
  428.                     Message = "Update cancelled"
  429.                 End If
  430.                 EditRow = False
  431.             End If
  432.         End If
  433.  
  434.         ' Row Updated event
  435.         If EditRow Then
  436.             tblTypes.Row_Updated(RsOld, Rs)
  437.         End If
  438.     End Function
  439.  
  440.         ' Page Load event
  441.         Public Sub Page_Load()
  442.  
  443.             'HttpContext.Current.Response.Write("Page Load")
  444.         End Sub
  445.  
  446.         ' Page Unload event
  447.         Public Sub Page_Unload()
  448.  
  449.             'HttpContext.Current.Response.Write("Page Unload")
  450.         End Sub
  451.  
  452.     ' Form Custom Validate event
  453.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  454.  
  455.         'Return error message in CustomError
  456.         Return True
  457.     End Function
  458.     End Class
  459.  
  460.     '
  461.     ' ASP.NET Page_Load event
  462.     '
  463.  
  464.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  465.         Response.Buffer = EW_RESPONSE_BUFFER
  466.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  467.  
  468.         ' Page init
  469.         tblTypes_edit = New ctblTypes_edit(Me)        
  470.         tblTypes_edit.Page_Init()
  471.  
  472.         ' Page main processing
  473.         tblTypes_edit.Page_Main()
  474.     End Sub
  475.  
  476.     '
  477.     ' ASP.NET Page_Unload event
  478.     '
  479.  
  480.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  481.  
  482.         ' Dispose page object
  483.         If tblTypes_edit IsNot Nothing Then tblTypes_edit.Dispose()
  484.     End Sub
  485. End Class
  486.