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