home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblLocationsadd.aspx.vb < prev    next >
Text File  |  2010-08-24  |  14KB  |  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 tblLocationsadd
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblLocations_add As ctblLocations_add
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblLocations_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 tblLocations.UseTokenInUrl Then Url = Url & "t=" & tblLocations.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 tblLocations.UseTokenInUrl Then
  44.                 Result = False
  45.                 If ObjForm IsNot Nothing Then
  46.                     Result = (tblLocations.TableVar = ObjForm.GetValue("t"))
  47.                 End If
  48.                 If ew_Get("t") <> "" Then
  49.                     Result = (tblLocations.TableVar = ew_Get("t"))
  50.                 End If
  51.                 Return Result
  52.             End If
  53.             Return True            
  54.         End Function    
  55.  
  56.         ' tblLocations
  57.         Public Property tblLocations() As ctblLocations
  58.             Get                
  59.                 Return ParentPage.tblLocations
  60.             End Get
  61.             Set(ByVal v As ctblLocations)
  62.                 ParentPage.tblLocations = v    
  63.             End Set    
  64.         End Property
  65.  
  66.         ' tblLocations
  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 = "tblLocations_add"
  86.             m_PageObjTypeName = "ctblLocations_add"
  87.  
  88.             ' Table Name
  89.             m_TableName = "tblLocations"
  90.  
  91.             ' Initialize table object
  92.             tblLocations = New ctblLocations(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("tblLocationslist.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.             tblLocations.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("locID") <> "" Then
  184.             tblLocations.locID.QueryStringValue = ew_Get("locID")
  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.             tblLocations.CurrentAction = ObjForm.GetValue("a_add") ' Get form action
  195.             LoadFormValues() ' Load form values
  196.  
  197.             ' Validate Form
  198.             If Not ValidateForm() Then
  199.                 tblLocations.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.                 tblLocations.CurrentAction = "C" ' Copy Record
  207.             Else
  208.                 tblLocations.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 tblLocations.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("tblLocationslist.aspx") ' No matching record, return to list
  220.                 End If
  221.             Case "A" ' Add new record
  222.                 tblLocations.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 = tblLocations.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.         tblLocations.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.         tblLocations.locLighting.CurrentValue = 0
  252.     End Sub
  253.  
  254.     '
  255.     ' Load form values
  256.     '
  257.     Sub LoadFormValues()
  258.         tblLocations.locDescription.FormValue = ObjForm.GetValue("x_locDescription")
  259.         tblLocations.locDescription.OldValue = ObjForm.GetValue("o_locDescription")
  260.             tblLocations.locLighting.FormValue = ObjForm.GetValue("x_locLighting")
  261.             tblLocations.locLighting.OldValue = ObjForm.GetValue("o_locLighting")
  262.             tblLocations.locIsActive.FormValue = ObjForm.GetValue("x_locIsActive")
  263.             tblLocations.locIsActive.OldValue = ObjForm.GetValue("o_locIsActive")
  264.             tblLocations.locID.FormValue = ObjForm.GetValue("x_locID")
  265.     End Sub
  266.  
  267.     '
  268.     ' Restore form values
  269.     '
  270.     Sub RestoreFormValues()
  271.         tblLocations.locDescription.CurrentValue = tblLocations.locDescription.FormValue
  272.             tblLocations.locLighting.CurrentValue = tblLocations.locLighting.FormValue
  273.             tblLocations.locIsActive.CurrentValue = tblLocations.locIsActive.FormValue
  274.             tblLocations.locID.CurrentValue = tblLocations.locID.FormValue
  275.     End Sub
  276.  
  277.     '
  278.     ' Load row based on key values
  279.     '
  280.     Function LoadRow() As Boolean
  281.         Dim RsRow As OleDbDataReader
  282.         Dim sFilter As String = tblLocations.KeyFilter
  283.  
  284.         ' Row Selecting event
  285.         tblLocations.Row_Selecting(sFilter)
  286.  
  287.         ' Load SQL based on filter
  288.         tblLocations.CurrentFilter = sFilter
  289.         Dim sSql As String = tblLocations.SQL
  290.  
  291.         ' Write SQL for debug
  292.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  293.         Try
  294.             RsRow = Conn.GetTempDataReader(sSql)    
  295.             If Not RsRow.Read() Then
  296.                 Return False
  297.             Else                
  298.                 LoadRowValues(RsRow) ' Load row values
  299.  
  300.                 ' Row Selected event
  301.                 tblLocations.Row_Selected(RsRow)
  302.                 Return True    
  303.             End If
  304.         Catch
  305.             If EW_DEBUG_ENABLED Then Throw
  306.             Return False
  307.         Finally
  308.             Conn.CloseTempDataReader()
  309.         End Try
  310.     End Function
  311.  
  312.     '
  313.     ' Load row values from recordset
  314.     '
  315.     Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
  316.         tblLocations.locID.DbValue = RsRow("locID")
  317.         tblLocations.locDescription.DbValue = RsRow("locDescription")
  318.             tblLocations.locLighting.DbValue = IIf(ew_ConvertToBool(RsRow("locLighting")), "1", "0")
  319.             tblLocations.locIsActive.DbValue = IIf(ew_ConvertToBool(RsRow("locIsActive")), "1", "0")
  320.         End Sub
  321.  
  322.     '
  323.     ' Render row values based on field settings
  324.     '
  325.     Sub RenderRow()
  326.  
  327.         ' Row Rendering event
  328.         tblLocations.Row_Rendering()
  329.  
  330.         '
  331.         '  Common render codes for all row types
  332.         '
  333.         ' locDescription
  334.  
  335.         tblLocations.locDescription.CellCssStyle = ""
  336.         tblLocations.locDescription.CellCssClass = ""
  337.  
  338.             ' locLighting
  339.             tblLocations.locLighting.CellCssStyle = ""
  340.             tblLocations.locLighting.CellCssClass = ""
  341.  
  342.             ' locIsActive
  343.             tblLocations.locIsActive.CellCssStyle = ""
  344.             tblLocations.locIsActive.CellCssClass = ""
  345.  
  346.             '
  347.         '  View  Row
  348.         '
  349.  
  350.         If tblLocations.RowType = EW_ROWTYPE_VIEW Then ' View row
  351.  
  352.             ' locDescription
  353.             tblLocations.locDescription.ViewValue = tblLocations.locDescription.CurrentValue
  354.             tblLocations.locDescription.CssStyle = ""
  355.             tblLocations.locDescription.CssClass = ""
  356.             tblLocations.locDescription.ViewCustomAttributes = ""
  357.  
  358.                 ' locLighting
  359.                 If Convert.ToString(tblLocations.locLighting.CurrentValue) = "1" Then
  360.                     tblLocations.locLighting.ViewValue = "Yes"
  361.                 Else
  362.                     tblLocations.locLighting.ViewValue = "No"
  363.                 End If
  364.                 tblLocations.locLighting.CssStyle = ""
  365.                 tblLocations.locLighting.CssClass = ""
  366.                 tblLocations.locLighting.ViewCustomAttributes = ""
  367.  
  368.                 ' locIsActive
  369.                 If Convert.ToString(tblLocations.locIsActive.CurrentValue) = "1" Then
  370.                     tblLocations.locIsActive.ViewValue = "Yes"
  371.                 Else
  372.                     tblLocations.locIsActive.ViewValue = "No"
  373.                 End If
  374.                 tblLocations.locIsActive.CssStyle = ""
  375.                 tblLocations.locIsActive.CssClass = ""
  376.                 tblLocations.locIsActive.ViewCustomAttributes = ""
  377.  
  378.                 ' View refer script
  379.             ' locDescription
  380.  
  381.             tblLocations.locDescription.HrefValue = ""
  382.  
  383.             ' locLighting
  384.             tblLocations.locLighting.HrefValue = ""
  385.  
  386.                 ' locIsActive
  387.                 tblLocations.locIsActive.HrefValue = ""
  388.  
  389.  
  390.                 '
  391.         '  Add Row
  392.         '
  393.  
  394.         ElseIf tblLocations.RowType = EW_ROWTYPE_ADD Then ' Add row
  395.  
  396.             ' locDescription
  397.             tblLocations.locDescription.EditCustomAttributes = ""
  398.             tblLocations.locDescription.EditValue = ew_HtmlEncode(tblLocations.locDescription.CurrentValue)
  399.  
  400.                 ' locLighting
  401.                 tblLocations.locLighting.EditCustomAttributes = ""
  402.  
  403.                 ' locIsActive
  404.                 tblLocations.locIsActive.EditCustomAttributes = ""
  405.             End If
  406.  
  407.         ' Row Rendered event
  408.         tblLocations.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.         ' locDescription
  447.         tblLocations.locDescription.SetDbValue(tblLocations.locDescription.CurrentValue, System.DBNull.Value)
  448.         Rs("locDescription") = tblLocations.locDescription.DbValue
  449.  
  450.         ' locLighting
  451.         tblLocations.locLighting.SetDbValue((tblLocations.locLighting.CurrentValue <> "" And Not IsDBNull(tblLocations.locLighting.CurrentValue)), System.DBNull.Value)
  452.         Rs("locLighting") = tblLocations.locLighting.DbValue
  453.  
  454.             ' locIsActive
  455.             Rs("locIsActive") = True
  456.  
  457.             ' Row Inserting event
  458.         bInsertRow = tblLocations.Row_Inserting(Rs)
  459.         If bInsertRow Then
  460.             Try    
  461.                 tblLocations.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 tblLocations.CancelMessage <> "" Then
  470.                 Message = tblLocations.CancelMessage
  471.                 tblLocations.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.             tblLocations.locID.DbValue = LastInsertId
  480.             Rs("locID") = tblLocations.locID.DbValue        
  481.  
  482.             ' Row Inserted event
  483.             tblLocations.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.         tblLocations_add = New ctblLocations_add(Me)        
  517.         tblLocations_add.Page_Init()
  518.  
  519.         ' Page main processing
  520.         tblLocations_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 tblLocations_add IsNot Nothing Then tblLocations_add.Dispose()
  531.     End Sub
  532. End Class
  533.