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