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