home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblEventsaddopt.aspx.vb < prev    next >
Text File  |  2010-08-24  |  12KB  |  471 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 tblEventsaddopt
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblEvents_addopt As ctblEvents_addopt
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblEvents_addopt
  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 tblEvents.UseTokenInUrl Then Url = Url & "t=" & tblEvents.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 tblEvents.UseTokenInUrl Then
  44.                 Result = False
  45.                 If ObjForm IsNot Nothing Then
  46.                     Result = (tblEvents.TableVar = ObjForm.GetValue("t"))
  47.                 End If
  48.                 If ew_Get("t") <> "" Then
  49.                     Result = (tblEvents.TableVar = ew_Get("t"))
  50.                 End If
  51.                 Return Result
  52.             End If
  53.             Return True            
  54.         End Function    
  55.  
  56.         ' tblEvents
  57.         Public Property tblEvents() As ctblEvents
  58.             Get                
  59.                 Return ParentPage.tblEvents
  60.             End Get
  61.             Set(ByVal v As ctblEvents)
  62.                 ParentPage.tblEvents = v    
  63.             End Set    
  64.         End Property
  65.  
  66.         ' tblEvents
  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 = "addopt"
  85.             m_PageObjName = "tblEvents_addopt"
  86.             m_PageObjTypeName = "ctblEvents_addopt"
  87.  
  88.             ' Table Name
  89.             m_TableName = "tblEvents"
  90.  
  91.             ' Initialize table object
  92.             tblEvents = New ctblEvents(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("tblEventslist.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.             tblEvents.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.         ' Create form object
  180.         ObjForm = New cFormObj
  181.  
  182.         ' Process form if post back
  183.         If ObjForm.GetValue("a_addopt") <> "" Then
  184.             tblEvents.CurrentAction = ObjForm.GetValue("a_addopt") ' Get form action
  185.             LoadFormValues() ' Load form values
  186.  
  187.             ' Validate Form
  188.             If Not ValidateForm() Then
  189.                 tblEvents.CurrentAction = "I" ' Form error, reset action
  190.                 Message = ParentPage.gsFormError
  191.             End If
  192.  
  193.         ' Not post back
  194.         Else
  195.             tblEvents.CurrentAction = "I" ' Display Blank Record
  196.             LoadDefaultValues() ' Load default values
  197.         End If
  198.  
  199.         ' Perform action based on action code
  200.         Select Case tblEvents.CurrentAction
  201.             Case "I" ' Blank record, no action required
  202.             Case "A" ' Add new record
  203.                 tblEvents.SendEmail = True ' Send email on add success
  204.                 If AddRow() Then ' Add successful
  205.                     Dim XMLDoc As Object, XMLRoot As Object, Element As Object
  206.                     XMLDoc = New XmlDocument()
  207.                     XMLRoot = XMLDoc.CreateElement("result")
  208.                     XMLDoc.AppendChild(XMLRoot)
  209.                     Element = XMLDoc.CreateElement("x_evtID")
  210.                     XMLRoot.AppendChild(Element)
  211.                     Element.AppendChild(XMLDoc.CreateTextNode(Convert.ToString(tblEvents.evtID.DbValue)))
  212.                     Element = XMLDoc.CreateElement("x_evtDescription")
  213.                     XMLRoot.AppendChild(Element)
  214.                     Element.AppendChild(XMLDoc.CreateTextNode(Convert.ToString(tblEvents.evtDescription.FormValue)))
  215.                     HttpContext.Current.Response.Clear()
  216.                     HttpContext.Current.Response.ContentType = "text/xml"
  217.                     ew_Write("<?xml version=""1.0"" encoding=""utf-8"" ?>")
  218.                     ew_Write(XMLDoc.OuterXml)
  219.                     Page_Terminate("")
  220.                     ew_End()
  221.                 Else
  222.                     RestoreFormValues() ' Add failed, restore form values
  223.                 End If
  224.         End Select
  225.  
  226.         ' Render row
  227.         tblEvents.RowType = EW_ROWTYPE_ADD ' Render add type
  228.         RenderRow()
  229.     End Sub
  230.  
  231.     '
  232.     ' Get upload file
  233.     '
  234.     Sub GetUploadFiles()
  235.  
  236.         ' Get upload data
  237.     End Sub
  238.  
  239.     '
  240.     ' Load default values
  241.     '
  242.     Sub LoadDefaultValues()
  243.     End Sub
  244.  
  245.     '
  246.     ' Load form values
  247.     '
  248.     Sub LoadFormValues()
  249.         tblEvents.evtDescription.FormValue = ObjForm.GetValue("x_evtDescription")
  250.         tblEvents.evtDescription.OldValue = ObjForm.GetValue("o_evtDescription")
  251.         tblEvents.evtID.FormValue = ObjForm.GetValue("x_evtID")
  252.     End Sub
  253.  
  254.     '
  255.     ' Restore form values
  256.     '
  257.     Sub RestoreFormValues()
  258.         tblEvents.evtDescription.CurrentValue = tblEvents.evtDescription.FormValue
  259.         tblEvents.evtID.CurrentValue = tblEvents.evtID.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 = tblEvents.KeyFilter
  268.  
  269.         ' Row Selecting event
  270.         tblEvents.Row_Selecting(sFilter)
  271.  
  272.         ' Load SQL based on filter
  273.         tblEvents.CurrentFilter = sFilter
  274.         Dim sSql As String = tblEvents.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.                 tblEvents.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.         tblEvents.evtID.DbValue = RsRow("evtID")
  302.         tblEvents.evtDescription.DbValue = RsRow("evtDescription")
  303.     End Sub
  304.  
  305.     '
  306.     ' Render row values based on field settings
  307.     '
  308.     Sub RenderRow()
  309.  
  310.         ' Row Rendering event
  311.         tblEvents.Row_Rendering()
  312.  
  313.         '
  314.         '  Common render codes for all row types
  315.         '
  316.         ' evtDescription
  317.  
  318.         tblEvents.evtDescription.CellCssStyle = ""
  319.         tblEvents.evtDescription.CellCssClass = ""
  320.  
  321.         '
  322.         '  View  Row
  323.         '
  324.  
  325.         If tblEvents.RowType = EW_ROWTYPE_VIEW Then ' View row
  326.  
  327.             ' evtID
  328.             tblEvents.evtID.ViewValue = tblEvents.evtID.CurrentValue
  329.             tblEvents.evtID.CssStyle = ""
  330.             tblEvents.evtID.CssClass = ""
  331.             tblEvents.evtID.ViewCustomAttributes = ""
  332.  
  333.             ' evtDescription
  334.             tblEvents.evtDescription.ViewValue = tblEvents.evtDescription.CurrentValue
  335.             tblEvents.evtDescription.CssStyle = ""
  336.             tblEvents.evtDescription.CssClass = ""
  337.             tblEvents.evtDescription.ViewCustomAttributes = ""
  338.  
  339.             ' View refer script
  340.             ' evtDescription
  341.  
  342.             tblEvents.evtDescription.HrefValue = ""
  343.  
  344.         '
  345.         '  Add Row
  346.         '
  347.  
  348.         ElseIf tblEvents.RowType = EW_ROWTYPE_ADD Then ' Add row
  349.  
  350.             ' evtDescription
  351.             tblEvents.evtDescription.EditCustomAttributes = ""
  352.             tblEvents.evtDescription.EditValue = ew_HtmlEncode(tblEvents.evtDescription.CurrentValue)
  353.         End If
  354.  
  355.         ' Row Rendered event
  356.         tblEvents.Row_Rendered()
  357.     End Sub
  358.  
  359.     '
  360.     ' Validate form
  361.     '
  362.     Function ValidateForm() As Boolean
  363.  
  364.         ' Initialize
  365.         ParentPage.gsFormError = ""
  366.  
  367.         ' Return validate result
  368.         Dim Valid As Boolean = (ParentPage.gsFormError = "")
  369.  
  370.         ' Form_CustomValidate event
  371.         Dim sFormCustomError As String = ""
  372.         Valid = Valid And Form_CustomValidate(sFormCustomError)
  373.         If sFormCustomError <> "" Then
  374.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  375.             ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  376.         End If
  377.         Return Valid
  378.     End Function
  379.  
  380.     '
  381.     ' Add record
  382.     '
  383.     Function AddRow() As Boolean
  384.         Dim Rs As New OrderedDictionary
  385.         Dim sSql As String, sFilter As String
  386.         Dim bInsertRow As Boolean
  387.         Dim RsChk As OleDbDataReader
  388.         Dim sIdxErrMsg As String
  389.         Dim LastInsertId As Object
  390.  
  391.         ' evtDescription
  392.         tblEvents.evtDescription.SetDbValue(tblEvents.evtDescription.CurrentValue, System.DBNull.Value)
  393.         Rs("evtDescription") = tblEvents.evtDescription.DbValue
  394.  
  395.         ' Row Inserting event
  396.         bInsertRow = tblEvents.Row_Inserting(Rs)
  397.         If bInsertRow Then
  398.             Try    
  399.                 tblEvents.Insert(Rs)
  400.                 AddRow = True
  401.             Catch e As Exception
  402.                 If EW_DEBUG_ENABLED Then Throw
  403.                 Message = e.Message                
  404.                 AddRow = False
  405.             End Try
  406.         Else
  407.             If tblEvents.CancelMessage <> "" Then
  408.                 Message = tblEvents.CancelMessage
  409.                 tblEvents.CancelMessage = ""
  410.             Else
  411.                 Message = "Insert cancelled"
  412.             End If
  413.             AddRow = False
  414.         End If
  415.         If AddRow Then
  416.             LastInsertId = Conn.GetLastInsertId()
  417.             tblEvents.evtID.DbValue = LastInsertId
  418.             Rs("evtID") = tblEvents.evtID.DbValue        
  419.  
  420.             ' Row Inserted event
  421.             tblEvents.Row_Inserted(Rs)
  422.         End If
  423.     End Function
  424.  
  425.         ' Page Load event
  426.         Public Sub Page_Load()
  427.  
  428.             'HttpContext.Current.Response.Write("Page Load")
  429.         End Sub
  430.  
  431.         ' Page Unload event
  432.         Public Sub Page_Unload()
  433.  
  434.             'HttpContext.Current.Response.Write("Page Unload")
  435.         End Sub
  436.  
  437.     ' Form Custom Validate event
  438.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  439.  
  440.         'Return error message in CustomError
  441.         Return True
  442.     End Function
  443.     End Class
  444.  
  445.     '
  446.     ' ASP.NET Page_Load event
  447.     '
  448.  
  449.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  450.         Response.Buffer = EW_RESPONSE_BUFFER
  451.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  452.  
  453.         ' Page init
  454.         tblEvents_addopt = New ctblEvents_addopt(Me)        
  455.         tblEvents_addopt.Page_Init()
  456.  
  457.         ' Page main processing
  458.         tblEvents_addopt.Page_Main()
  459.     End Sub
  460.  
  461.     '
  462.     ' ASP.NET Page_Unload event
  463.     '
  464.  
  465.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  466.  
  467.         ' Dispose page object
  468.         If tblEvents_addopt IsNot Nothing Then tblEvents_addopt.Dispose()
  469.     End Sub
  470. End Class
  471.