home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblEmployeeStatusedit.aspx.vb < prev    next >
Text File  |  2010-08-24  |  12KB  |  492 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 tblEmployeeStatusedit
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblEmployeeStatus_edit As ctblEmployeeStatus_edit
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblEmployeeStatus_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 tblEmployeeStatus.UseTokenInUrl Then Url = Url & "t=" & tblEmployeeStatus.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 tblEmployeeStatus.UseTokenInUrl Then
  44.                 Result = False
  45.                 If ObjForm IsNot Nothing Then
  46.                     Result = (tblEmployeeStatus.TableVar = ObjForm.GetValue("t"))
  47.                 End If
  48.                 If ew_Get("t") <> "" Then
  49.                     Result = (tblEmployeeStatus.TableVar = ew_Get("t"))
  50.                 End If
  51.                 Return Result
  52.             End If
  53.             Return True            
  54.         End Function    
  55.  
  56.         ' tblEmployeeStatus
  57.         Public Property tblEmployeeStatus() As ctblEmployeeStatus
  58.             Get                
  59.                 Return ParentPage.tblEmployeeStatus
  60.             End Get
  61.             Set(ByVal v As ctblEmployeeStatus)
  62.                 ParentPage.tblEmployeeStatus = v    
  63.             End Set    
  64.         End Property
  65.  
  66.         ' tblEmployeeStatus
  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 = "tblEmployeeStatus_edit"
  86.             m_PageObjTypeName = "ctblEmployeeStatus_edit"
  87.  
  88.             ' Table Name
  89.             m_TableName = "tblEmployeeStatus"
  90.  
  91.             ' Initialize table object
  92.             tblEmployeeStatus = New ctblEmployeeStatus(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("tblEmployeeStatuslist.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.             tblEmployeeStatus.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("ID") <> "" Then
  181.             tblEmployeeStatus.ID.QueryStringValue = ew_Get("ID")
  182.         End If
  183.  
  184.         ' Create form object
  185.         ObjForm = New cFormObj
  186.         If ObjForm.GetValue("a_edit") <> "" Then
  187.             tblEmployeeStatus.CurrentAction = ObjForm.GetValue("a_edit") ' Get action code
  188.             LoadFormValues() ' Get form values
  189.  
  190.             ' Validate Form
  191.             If Not ValidateForm() Then
  192.                 tblEmployeeStatus.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.             tblEmployeeStatus.CurrentAction = "I" ' Default action is display
  199.         End If
  200.  
  201.         ' Check if valid key
  202.         If ew_Empty(tblEmployeeStatus.ID.CurrentValue) Then Page_Terminate("tblEmployeeStatuslist.aspx") ' Invalid key, return to list
  203.         Select Case tblEmployeeStatus.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("tblEmployeeStatuslist.aspx") ' No matching record, return to list
  208.                 End If
  209.             Case "U" ' Update
  210.                 tblEmployeeStatus.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 = tblEmployeeStatus.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.         tblEmployeeStatus.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.         tblEmployeeStatus.tscStatus.FormValue = ObjForm.GetValue("x_tscStatus")
  247.         tblEmployeeStatus.tscStatus.OldValue = ObjForm.GetValue("o_tscStatus")
  248.         tblEmployeeStatus.ID.FormValue = ObjForm.GetValue("x_ID")
  249.     End Sub
  250.  
  251.     '
  252.     ' Restore form values
  253.     '
  254.     Sub RestoreFormValues()
  255.         tblEmployeeStatus.tscStatus.CurrentValue = tblEmployeeStatus.tscStatus.FormValue
  256.         tblEmployeeStatus.ID.CurrentValue = tblEmployeeStatus.ID.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 = tblEmployeeStatus.KeyFilter
  265.  
  266.         ' Row Selecting event
  267.         tblEmployeeStatus.Row_Selecting(sFilter)
  268.  
  269.         ' Load SQL based on filter
  270.         tblEmployeeStatus.CurrentFilter = sFilter
  271.         Dim sSql As String = tblEmployeeStatus.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.                 tblEmployeeStatus.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.         tblEmployeeStatus.ID.DbValue = RsRow("ID")
  299.         tblEmployeeStatus.tscStatus.DbValue = RsRow("tscStatus")
  300.     End Sub
  301.  
  302.     '
  303.     ' Render row values based on field settings
  304.     '
  305.     Sub RenderRow()
  306.  
  307.         ' Row Rendering event
  308.         tblEmployeeStatus.Row_Rendering()
  309.  
  310.         '
  311.         '  Common render codes for all row types
  312.         '
  313.         ' tscStatus
  314.  
  315.         tblEmployeeStatus.tscStatus.CellCssStyle = ""
  316.         tblEmployeeStatus.tscStatus.CellCssClass = ""
  317.  
  318.         '
  319.         '  View  Row
  320.         '
  321.  
  322.         If tblEmployeeStatus.RowType = EW_ROWTYPE_VIEW Then ' View row
  323.  
  324.             ' ID
  325.             tblEmployeeStatus.ID.ViewValue = tblEmployeeStatus.ID.CurrentValue
  326.             tblEmployeeStatus.ID.CssStyle = ""
  327.             tblEmployeeStatus.ID.CssClass = ""
  328.             tblEmployeeStatus.ID.ViewCustomAttributes = ""
  329.  
  330.             ' tscStatus
  331.             tblEmployeeStatus.tscStatus.ViewValue = tblEmployeeStatus.tscStatus.CurrentValue
  332.             tblEmployeeStatus.tscStatus.CssStyle = ""
  333.             tblEmployeeStatus.tscStatus.CssClass = ""
  334.             tblEmployeeStatus.tscStatus.ViewCustomAttributes = ""
  335.  
  336.             ' View refer script
  337.             ' tscStatus
  338.  
  339.             tblEmployeeStatus.tscStatus.HrefValue = ""
  340.  
  341.         '
  342.         '  Edit Row
  343.         '
  344.  
  345.         ElseIf tblEmployeeStatus.RowType = EW_ROWTYPE_EDIT Then ' Edit row
  346.  
  347.             ' tscStatus
  348.             tblEmployeeStatus.tscStatus.EditCustomAttributes = ""
  349.             tblEmployeeStatus.tscStatus.EditValue = ew_HtmlEncode(tblEmployeeStatus.tscStatus.CurrentValue)
  350.  
  351.             ' Edit refer script
  352.             ' tscStatus
  353.  
  354.             tblEmployeeStatus.tscStatus.HrefValue = ""
  355.         End If
  356.  
  357.         ' Row Rendered event
  358.         tblEmployeeStatus.Row_Rendered()
  359.     End Sub
  360.  
  361.     '
  362.     ' Validate form
  363.     '
  364.     Function ValidateForm() As Boolean
  365.  
  366.         ' Initialize
  367.         ParentPage.gsFormError = ""
  368.  
  369.         ' Check if validation required
  370.         If Not EW_SERVER_VALIDATE Then Return (ParentPage.gsFormError = "")
  371.  
  372.         ' Return validate result
  373.         Dim Valid As Boolean = (ParentPage.gsFormError = "")
  374.  
  375.         ' Form_CustomValidate event
  376.         Dim sFormCustomError As String = ""
  377.         Valid = Valid And Form_CustomValidate(sFormCustomError)
  378.         If sFormCustomError <> "" Then
  379.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  380.             ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  381.         End If
  382.         Return Valid
  383.     End Function
  384.  
  385.     '
  386.     ' Update record based on key values
  387.     '
  388.     Function EditRow() As Boolean
  389.         Dim RsEdit As OleDbDataReader, RsChk As OleDbDataReader
  390.         Dim sSql As String, sFilter As String
  391.         Dim sSqlChk As String, sFilterChk As String
  392.         Dim bUpdateRow As Boolean
  393.         Dim RsOld As OrderedDictionary
  394.         Dim sIdxErrMsg As String
  395.         Dim Rs As New OrderedDictionary
  396.         sFilter = tblEmployeeStatus.KeyFilter
  397.         tblEmployeeStatus.CurrentFilter  = sFilter
  398.         sSql = tblEmployeeStatus.SQL
  399.         Try
  400.             RsEdit = Conn.GetDataReader(sSql) 
  401.         Catch e As Exception
  402.             If EW_DEBUG_ENABLED Then Throw
  403.             Message = e.Message
  404.             RsEdit.Close()
  405.             EditRow = False
  406.         End Try
  407.         If Not RsEdit.Read() Then
  408.             RsEdit.Close()
  409.             EditRow = False ' Update Failed
  410.         Else
  411.             RsOld = Conn.GetRow(RsEdit)
  412.             RsEdit.Close()
  413.  
  414.             ' tscStatus
  415.             tblEmployeeStatus.tscStatus.SetDbValue(tblEmployeeStatus.tscStatus.CurrentValue, System.DBNull.Value)
  416.             Rs("tscStatus") = tblEmployeeStatus.tscStatus.DbValue
  417.  
  418.             ' Row Updating event
  419.             bUpdateRow = tblEmployeeStatus.Row_Updating(RsOld, Rs)
  420.             If bUpdateRow Then
  421.                 Try
  422.                     tblEmployeeStatus.Update(Rs)
  423.                     EditRow = True
  424.                 Catch e As Exception
  425.                     If EW_DEBUG_ENABLED Then Throw
  426.                     Message = e.Message
  427.                     EditRow = False
  428.                 End Try
  429.             Else
  430.                 If tblEmployeeStatus.CancelMessage <> "" Then
  431.                     Message = tblEmployeeStatus.CancelMessage
  432.                     tblEmployeeStatus.CancelMessage = ""
  433.                 Else
  434.                     Message = "Update cancelled"
  435.                 End If
  436.                 EditRow = False
  437.             End If
  438.         End If
  439.  
  440.         ' Row Updated event
  441.         If EditRow Then
  442.             tblEmployeeStatus.Row_Updated(RsOld, Rs)
  443.         End If
  444.     End Function
  445.  
  446.         ' Page Load event
  447.         Public Sub Page_Load()
  448.  
  449.             'HttpContext.Current.Response.Write("Page Load")
  450.         End Sub
  451.  
  452.         ' Page Unload event
  453.         Public Sub Page_Unload()
  454.  
  455.             'HttpContext.Current.Response.Write("Page Unload")
  456.         End Sub
  457.  
  458.     ' Form Custom Validate event
  459.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  460.  
  461.         'Return error message in CustomError
  462.         Return True
  463.     End Function
  464.     End Class
  465.  
  466.     '
  467.     ' ASP.NET Page_Load event
  468.     '
  469.  
  470.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  471.         Response.Buffer = EW_RESPONSE_BUFFER
  472.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  473.  
  474.         ' Page init
  475.         tblEmployeeStatus_edit = New ctblEmployeeStatus_edit(Me)        
  476.         tblEmployeeStatus_edit.Page_Init()
  477.  
  478.         ' Page main processing
  479.         tblEmployeeStatus_edit.Page_Main()
  480.     End Sub
  481.  
  482.     '
  483.     ' ASP.NET Page_Unload event
  484.     '
  485.  
  486.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  487.  
  488.         ' Dispose page object
  489.         If tblEmployeeStatus_edit IsNot Nothing Then tblEmployeeStatus_edit.Dispose()
  490.     End Sub
  491. End Class
  492.