home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblPositionsadd.aspx.vb < prev    next >
Text File  |  2015-04-14  |  15KB  |  533 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 tblPositionsadd
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblPositions_add As ctblPositions_add
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblPositions_add
  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 = "add"
  85.             m_PageObjName = "tblPositions_add"
  86.             m_PageObjTypeName = "ctblPositions_add"
  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.CanAdd 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.     Public x_ewPriv As Integer
  175.  
  176.     '
  177.     ' Page main processing
  178.     '
  179.     Sub Page_Main()
  180.  
  181.         ' Load key values from QueryString
  182.         Dim bCopy As Boolean = True
  183.         If ew_Get("posID") <> "" Then
  184.             tblPositions.posID.QueryStringValue = ew_Get("posID")
  185.         Else
  186.             bCopy = False
  187.         End If
  188.  
  189.         ' Create form object
  190.         ObjForm = New cFormObj
  191.  
  192.         ' Process form if post back
  193.         If ObjForm.GetValue("a_add") <> "" Then
  194.             tblPositions.CurrentAction = ObjForm.GetValue("a_add") ' Get form action
  195.             LoadFormValues() ' Load form values
  196.  
  197.             ' Validate Form
  198.             If Not ValidateForm() Then
  199.                 tblPositions.CurrentAction = "I" ' Form error, reset action
  200.                 Message = ParentPage.gsFormError
  201.             End If
  202.  
  203.         ' Not post back
  204.         Else
  205.             If bCopy Then
  206.                 tblPositions.CurrentAction = "C" ' Copy Record
  207.             Else
  208.                 tblPositions.CurrentAction = "I" ' Display Blank Record
  209.                 LoadDefaultValues() ' Load default values
  210.             End If
  211.         End If
  212.  
  213.         ' Perform action based on action code
  214.         Select Case tblPositions.CurrentAction
  215.             Case "I" ' Blank record, no action required
  216.             Case "C" ' Copy an existing record
  217.                 If Not LoadRow() Then ' Load record based on key
  218.                     Message = "No records found" ' No record found
  219.                     Page_Terminate("tblPositionslist.aspx") ' No matching record, return to list
  220.                 End If
  221.             Case "A" ' Add new record
  222.                 tblPositions.SendEmail = True ' Send email on add success
  223.                 If AddRow() Then ' Add successful
  224.                     Message = "Add succeeded" ' Set up success message
  225.                     Dim sReturnUrl As String = tblPositions.ReturnUrl
  226.                     Page_Terminate(sReturnUrl) ' Clean up and return
  227.                 Else
  228.                     RestoreFormValues() ' Add failed, restore form values
  229.                 End If
  230.         End Select
  231.  
  232.         ' Render row based on row type
  233.         tblPositions.RowType = EW_ROWTYPE_ADD ' Render add type
  234.  
  235.         ' Render row
  236.         RenderRow()
  237.     End Sub
  238.  
  239.     '
  240.     ' Get upload file
  241.     '
  242.     Sub GetUploadFiles()
  243.  
  244.         ' Get upload data
  245.     End Sub
  246.  
  247.     '
  248.     ' Load default values
  249.     '
  250.     Sub LoadDefaultValues()
  251.     End Sub
  252.  
  253.     '
  254.     ' Load form values
  255.     '
  256.     Sub LoadFormValues()
  257.             tblPositions.posDescription.FormValue = ObjForm.GetValue("x_posDescription")
  258.             tblPositions.posDescription.OldValue = ObjForm.GetValue("o_posDescription")
  259.             tblPositions.posInDepartment.FormValue = ObjForm.GetValue("x_posInDepartment")
  260.             tblPositions.posInDepartment.OldValue = ObjForm.GetValue("o_posInDepartment")
  261.             tblPositions.posIsActive.FormValue = ObjForm.GetValue("x_posIsActive")
  262.             tblPositions.posIsActive.OldValue = ObjForm.GetValue("o_posIsActive")
  263.             tblPositions.posID.FormValue = ObjForm.GetValue("x_posID")
  264.     End Sub
  265.  
  266.     '
  267.     ' Restore form values
  268.     '
  269.     Sub RestoreFormValues()
  270.             tblPositions.posDescription.CurrentValue = tblPositions.posDescription.FormValue
  271.             tblPositions.posInDepartment.CurrentValue = tblPositions.posInDepartment.FormValue
  272.             tblPositions.posID.CurrentValue = tblPositions.posID.FormValue
  273.             tblPositions.posIsActive.CurrentValue = tblPositions.posIsActive.FormValue
  274.         End Sub
  275.  
  276.     '
  277.     ' Load row based on key values
  278.     '
  279.     Function LoadRow() As Boolean
  280.         Dim RsRow As OleDbDataReader
  281.         Dim sFilter As String = tblPositions.KeyFilter
  282.  
  283.         ' Row Selecting event
  284.         tblPositions.Row_Selecting(sFilter)
  285.  
  286.         ' Load SQL based on filter
  287.         tblPositions.CurrentFilter = sFilter
  288.         Dim sSql As String = tblPositions.SQL
  289.  
  290.         ' Write SQL for debug
  291.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  292.         Try
  293.             RsRow = Conn.GetTempDataReader(sSql)    
  294.             If Not RsRow.Read() Then
  295.                 Return False
  296.             Else                
  297.                 LoadRowValues(RsRow) ' Load row values
  298.  
  299.                 ' Row Selected event
  300.                 tblPositions.Row_Selected(RsRow)
  301.                 Return True    
  302.             End If
  303.         Catch
  304.             If EW_DEBUG_ENABLED Then Throw
  305.             Return False
  306.         Finally
  307.             Conn.CloseTempDataReader()
  308.         End Try
  309.     End Function
  310.  
  311.     '
  312.     ' Load row values from recordset
  313.     '
  314.     Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
  315.         tblPositions.posID.DbValue = RsRow("posID")
  316.             tblPositions.posDescription.DbValue = RsRow("posDescription")
  317.             tblPositions.posInDepartment.DbValue = RsRow("posInDepartment")
  318.             tblPositions.posIsActive.DbValue = IIf(ew_ConvertToBool(RsRow("posIsActive")), "1", "0")
  319.         End Sub
  320.  
  321.     '
  322.     ' Render row values based on field settings
  323.     '
  324.     Sub RenderRow()
  325.  
  326.         ' Row Rendering event
  327.         tblPositions.Row_Rendering()
  328.  
  329.         '
  330.         '  Common render codes for all row types
  331.         '
  332.             ' posDescription
  333.  
  334.             tblPositions.posDescription.CellCssStyle = ""
  335.             tblPositions.posDescription.CellCssClass = ""
  336.  
  337.             ' posInDepartment
  338.  
  339.             tblPositions.posInDepartment.CellCssStyle = ""
  340.             tblPositions.posInDepartment.CellCssClass = ""
  341.  
  342.             ' prtIsActive
  343.  
  344.             tblPositions.posIsActive.CellCssStyle = ""
  345.             tblPositions.posIsActive.CellCssClass = ""
  346.  
  347.             '
  348.         '  View  Row
  349.         '
  350.  
  351.         If tblPositions.RowType = EW_ROWTYPE_VIEW Then ' View row
  352.  
  353.                 ' posDescription
  354.                 tblPositions.posDescription.ViewValue = tblPositions.posDescription.CurrentValue
  355.                 tblPositions.posDescription.CssStyle = ""
  356.                 tblPositions.posDescription.CssClass = ""
  357.                 tblPositions.posDescription.ViewCustomAttributes = ""
  358.  
  359.                 ' posInDepartment
  360.                 tblPositions.posInDepartment.ViewValue = tblPositions.posInDepartment.CurrentValue
  361.                 tblPositions.posInDepartment.CssStyle = ""
  362.                 tblPositions.posInDepartment.CssClass = ""
  363.                 tblPositions.posInDepartment.ViewCustomAttributes = ""
  364.  
  365.                 ' posIsActive
  366.                 If Convert.ToString(tblPositions.posIsActive.CurrentValue) = "1" Then
  367.                     tblPositions.posIsActive.ViewValue = "Yes"
  368.                 Else
  369.                     tblPositions.posIsActive.ViewValue = "No"
  370.                 End If
  371.                 tblPositions.posIsActive.CssStyle = ""
  372.                 tblPositions.posIsActive.CssClass = ""
  373.                 tblPositions.posIsActive.ViewCustomAttributes = ""
  374.  
  375.                 ' View refer script
  376.                 ' posDescription
  377.  
  378.                 tblPositions.posDescription.HrefValue = ""
  379.  
  380.                 ' posInDepartment
  381.  
  382.                 tblPositions.posInDepartment.HrefValue = ""
  383.  
  384.                 ' posIsActive
  385.  
  386.                 tblPositions.posIsActive.HrefValue = ""
  387.  
  388.                 '
  389.         '  Add Row
  390.         '
  391.  
  392.         ElseIf tblPositions.RowType = EW_ROWTYPE_ADD Then ' Add row
  393.  
  394.                 ' posDescription
  395.                 tblPositions.posDescription.EditCustomAttributes = ""
  396.                 tblPositions.posDescription.EditValue = ew_HtmlEncode(tblPositions.posDescription.CurrentValue)
  397.  
  398.                 ' posInDepartment
  399.                 tblPositions.posInDepartment.EditCustomAttributes = ""
  400.                 tblPositions.posInDepartment.EditValue = ew_HtmlEncode(tblPositions.posInDepartment.CurrentValue)
  401.  
  402.                 ' posIsActive   
  403.                 tblPositions.posIsActive.EditCustomAttributes = ""
  404.  
  405.             End If
  406.  
  407.         ' Row Rendered event
  408.         tblPositions.Row_Rendered()
  409.     End Sub
  410.  
  411.     '
  412.     ' Validate form
  413.     '
  414.     Function ValidateForm() As Boolean
  415.  
  416.         ' Initialize
  417.         ParentPage.gsFormError = ""
  418.  
  419.         ' Check if validation required
  420.         If Not EW_SERVER_VALIDATE Then Return (ParentPage.gsFormError = "")
  421.  
  422.         ' Return validate result
  423.         Dim Valid As Boolean = (ParentPage.gsFormError = "")
  424.  
  425.         ' Form_CustomValidate event
  426.         Dim sFormCustomError As String = ""
  427.         Valid = Valid And Form_CustomValidate(sFormCustomError)
  428.         If sFormCustomError <> "" Then
  429.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  430.             ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  431.         End If
  432.         Return Valid
  433.     End Function
  434.  
  435.     '
  436.     ' Add record
  437.     '
  438.     Function AddRow() As Boolean
  439.         Dim Rs As New OrderedDictionary
  440.         Dim sSql As String, sFilter As String
  441.         Dim bInsertRow As Boolean
  442.         Dim RsChk As OleDbDataReader
  443.         Dim sIdxErrMsg As String
  444.         Dim LastInsertId As Object
  445.  
  446.             ' posDescription
  447.             tblPositions.posDescription.SetDbValue(tblPositions.posDescription.CurrentValue, System.DBNull.Value)
  448.             Rs("posDescription") = tblPositions.posDescription.DbValue
  449.  
  450.             ' posInDepartment
  451.             tblPositions.posInDepartment.SetDbValue(tblPositions.posInDepartment.CurrentValue, System.DBNull.Value)
  452.             Rs("posInDepartment") = tblPositions.posInDepartment.DbValue
  453.  
  454.             ' posIsActive
  455.             Rs("posIsActive") = True
  456.  
  457.             ' Row Inserting event
  458.         bInsertRow = tblPositions.Row_Inserting(Rs)
  459.         If bInsertRow Then
  460.             Try    
  461.                 tblPositions.Insert(Rs)
  462.                 AddRow = True
  463.             Catch e As Exception
  464.                 If EW_DEBUG_ENABLED Then Throw
  465.                 Message = e.Message                
  466.                 AddRow = False
  467.             End Try
  468.         Else
  469.             If tblPositions.CancelMessage <> "" Then
  470.                 Message = tblPositions.CancelMessage
  471.                 tblPositions.CancelMessage = ""
  472.             Else
  473.                 Message = "Insert cancelled"
  474.             End If
  475.             AddRow = False
  476.         End If
  477.         If AddRow Then
  478.             LastInsertId = Conn.GetLastInsertId()
  479.             tblPositions.posID.DbValue = LastInsertId
  480.             Rs("posID") = tblPositions.posID.DbValue        
  481.  
  482.             ' Row Inserted event
  483.             tblPositions.Row_Inserted(Rs)
  484.         End If
  485.     End Function
  486.  
  487.         ' Page Load event
  488.         Public Sub Page_Load()
  489.  
  490.             'HttpContext.Current.Response.Write("Page Load")
  491.         End Sub
  492.  
  493.         ' Page Unload event
  494.         Public Sub Page_Unload()
  495.  
  496.             'HttpContext.Current.Response.Write("Page Unload")
  497.         End Sub
  498.  
  499.     ' Form Custom Validate event
  500.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  501.  
  502.         'Return error message in CustomError
  503.         Return True
  504.     End Function
  505.     End Class
  506.  
  507.     '
  508.     ' ASP.NET Page_Load event
  509.     '
  510.  
  511.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  512.         Response.Buffer = EW_RESPONSE_BUFFER
  513.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  514.  
  515.         ' Page init
  516.         tblPositions_add = New ctblPositions_add(Me)        
  517.         tblPositions_add.Page_Init()
  518.  
  519.         ' Page main processing
  520.         tblPositions_add.Page_Main()
  521.     End Sub
  522.  
  523.     '
  524.     ' ASP.NET Page_Unload event
  525.     '
  526.  
  527.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  528.  
  529.         ' Dispose page object
  530.         If tblPositions_add IsNot Nothing Then tblPositions_add.Dispose()
  531.     End Sub
  532. End Class
  533.