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