home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblMessageedit.aspx.vb < prev    next >
Text File  |  2010-08-24  |  15KB  |  556 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 tblMessageedit
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblMessage_edit As ctblMessage_edit
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblMessage_edit
  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 = "edit"
  85.             m_PageObjName = "tblMessage_edit"
  86.             m_PageObjTypeName = "ctblMessage_edit"
  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.CanEdit 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.     '
  175.     ' Page main processing
  176.     '
  177.     Sub Page_Main()
  178.  
  179.         ' Load key from QueryString
  180.         If ew_Get("msgID") <> "" Then
  181.             tblMessage.msgID.QueryStringValue = ew_Get("msgID")
  182.         End If
  183.  
  184.         ' Create form object
  185.         ObjForm = New cFormObj
  186.         If ObjForm.GetValue("a_edit") <> "" Then
  187.             tblMessage.CurrentAction = ObjForm.GetValue("a_edit") ' Get action code
  188.             LoadFormValues() ' Get form values
  189.  
  190.             ' Validate Form
  191.             If Not ValidateForm() Then
  192.                 tblMessage.CurrentAction = "" ' Form error, reset action
  193.                 Message = ParentPage.gsFormError
  194.                 LoadRow() ' Restore row
  195.                 RestoreFormValues() ' Restore form values if validate failed
  196.             End If
  197.         Else
  198.             tblMessage.CurrentAction = "I" ' Default action is display
  199.         End If
  200.  
  201.         ' Check if valid key
  202.         If ew_Empty(tblMessage.msgID.CurrentValue) Then Page_Terminate("tblMessagelist.aspx") ' Invalid key, return to list
  203.         Select Case tblMessage.CurrentAction
  204.             Case "I" ' Get a record to display
  205.                 If Not LoadRow() Then ' Load Record based on key
  206.                     Message = "No records found" ' No record found
  207.                     Page_Terminate("tblMessagelist.aspx") ' No matching record, return to list
  208.                 End If
  209.             Case "U" ' Update
  210.                 tblMessage.SendEmail = True ' Send email on update success
  211.                 If EditRow() Then ' Update Record based on key
  212.                     Message = "Update succeeded" ' Update success
  213.                     Dim sReturnUrl As String = tblMessage.ReturnUrl
  214.                     Page_Terminate(sReturnUrl) ' Return to caller
  215.                 Else
  216.                     LoadRow() ' Restore row
  217.                     RestoreFormValues() ' Restore form values if update failed
  218.                 End If
  219.         End Select
  220.  
  221.         ' Render the record
  222.         tblMessage.RowType = EW_ROWTYPE_EDIT ' Render as edit
  223.  
  224.         ' Render row
  225.         RenderRow()
  226.     End Sub
  227.  
  228.     '
  229.     ' Get upload file
  230.     '
  231.     Sub GetUploadFiles()
  232.  
  233.         ' Get upload data
  234.     End Sub
  235.  
  236.     '
  237.     ' Load default values
  238.     '
  239.     Sub LoadDefaultValues()
  240.     End Sub
  241.  
  242.     '
  243.     ' Load form values
  244.     '
  245.     Sub LoadFormValues()
  246.         tblMessage.msgText.FormValue = ObjForm.GetValue("x_msgText")
  247.         tblMessage.msgText.OldValue = ObjForm.GetValue("o_msgText")
  248.         tblMessage.msgStartDate.FormValue = ObjForm.GetValue("x_msgStartDate")
  249.         tblMessage.msgStartDate.CurrentValue = ew_UnFormatDateTime(tblMessage.msgStartDate.CurrentValue, 6)
  250.         tblMessage.msgStartDate.OldValue = ObjForm.GetValue("o_msgStartDate")
  251.         tblMessage.msgEndDate.FormValue = ObjForm.GetValue("x_msgEndDate")
  252.         tblMessage.msgEndDate.CurrentValue = ew_UnFormatDateTime(tblMessage.msgEndDate.CurrentValue, 6)
  253.         tblMessage.msgEndDate.OldValue = ObjForm.GetValue("o_msgEndDate")
  254.         tblMessage.msgID.FormValue = ObjForm.GetValue("x_msgID")
  255.     End Sub
  256.  
  257.     '
  258.     ' Restore form values
  259.     '
  260.     Sub RestoreFormValues()
  261.         tblMessage.msgText.CurrentValue = tblMessage.msgText.FormValue
  262.         tblMessage.msgStartDate.CurrentValue = tblMessage.msgStartDate.FormValue
  263.         tblMessage.msgStartDate.CurrentValue = ew_UnFormatDateTime(tblMessage.msgStartDate.CurrentValue, 6)
  264.         tblMessage.msgEndDate.CurrentValue = tblMessage.msgEndDate.FormValue
  265.         tblMessage.msgEndDate.CurrentValue = ew_UnFormatDateTime(tblMessage.msgEndDate.CurrentValue, 6)
  266.         tblMessage.msgID.CurrentValue = tblMessage.msgID.FormValue
  267.     End Sub
  268.  
  269.     '
  270.     ' Load row based on key values
  271.     '
  272.     Function LoadRow() As Boolean
  273.         Dim RsRow As OleDbDataReader
  274.         Dim sFilter As String = tblMessage.KeyFilter
  275.  
  276.         ' Row Selecting event
  277.         tblMessage.Row_Selecting(sFilter)
  278.  
  279.         ' Load SQL based on filter
  280.         tblMessage.CurrentFilter = sFilter
  281.         Dim sSql As String = tblMessage.SQL
  282.  
  283.         ' Write SQL for debug
  284.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  285.         Try
  286.             RsRow = Conn.GetTempDataReader(sSql)    
  287.             If Not RsRow.Read() Then
  288.                 Return False
  289.             Else                
  290.                 LoadRowValues(RsRow) ' Load row values
  291.  
  292.                 ' Row Selected event
  293.                 tblMessage.Row_Selected(RsRow)
  294.                 Return True    
  295.             End If
  296.         Catch
  297.             If EW_DEBUG_ENABLED Then Throw
  298.             Return False
  299.         Finally
  300.             Conn.CloseTempDataReader()
  301.         End Try
  302.     End Function
  303.  
  304.     '
  305.     ' Load row values from recordset
  306.     '
  307.     Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
  308.         tblMessage.msgID.DbValue = RsRow("msgID")
  309.         tblMessage.msgText.DbValue = RsRow("msgText")
  310.         tblMessage.msgStartDate.DbValue = RsRow("msgStartDate")
  311.         tblMessage.msgEndDate.DbValue = RsRow("msgEndDate")
  312.     End Sub
  313.  
  314.     '
  315.     ' Render row values based on field settings
  316.     '
  317.     Sub RenderRow()
  318.  
  319.         ' Row Rendering event
  320.         tblMessage.Row_Rendering()
  321.  
  322.         '
  323.         '  Common render codes for all row types
  324.         '
  325.         ' msgText
  326.  
  327.         tblMessage.msgText.CellCssStyle = ""
  328.         tblMessage.msgText.CellCssClass = ""
  329.  
  330.         ' msgStartDate
  331.         tblMessage.msgStartDate.CellCssStyle = ""
  332.         tblMessage.msgStartDate.CellCssClass = ""
  333.  
  334.         ' msgEndDate
  335.         tblMessage.msgEndDate.CellCssStyle = ""
  336.         tblMessage.msgEndDate.CellCssClass = ""
  337.  
  338.         '
  339.         '  View  Row
  340.         '
  341.  
  342.         If tblMessage.RowType = EW_ROWTYPE_VIEW Then ' View row
  343.  
  344.             ' msgText
  345.             tblMessage.msgText.ViewValue = tblMessage.msgText.CurrentValue
  346.             tblMessage.msgText.CssStyle = ""
  347.             tblMessage.msgText.CssClass = ""
  348.             tblMessage.msgText.ViewCustomAttributes = ""
  349.  
  350.             ' msgStartDate
  351.             tblMessage.msgStartDate.ViewValue = tblMessage.msgStartDate.CurrentValue
  352.             tblMessage.msgStartDate.ViewValue = ew_FormatDateTime(tblMessage.msgStartDate.ViewValue, 6)
  353.             tblMessage.msgStartDate.CssStyle = ""
  354.             tblMessage.msgStartDate.CssClass = ""
  355.             tblMessage.msgStartDate.ViewCustomAttributes = ""
  356.  
  357.             ' msgEndDate
  358.             tblMessage.msgEndDate.ViewValue = tblMessage.msgEndDate.CurrentValue
  359.             tblMessage.msgEndDate.ViewValue = ew_FormatDateTime(tblMessage.msgEndDate.ViewValue, 6)
  360.             tblMessage.msgEndDate.CssStyle = ""
  361.             tblMessage.msgEndDate.CssClass = ""
  362.             tblMessage.msgEndDate.ViewCustomAttributes = ""
  363.  
  364.             ' View refer script
  365.             ' msgText
  366.  
  367.             tblMessage.msgText.HrefValue = ""
  368.  
  369.             ' msgStartDate
  370.             tblMessage.msgStartDate.HrefValue = ""
  371.  
  372.             ' msgEndDate
  373.             tblMessage.msgEndDate.HrefValue = ""
  374.  
  375.         '
  376.         '  Edit Row
  377.         '
  378.  
  379.         ElseIf tblMessage.RowType = EW_ROWTYPE_EDIT Then ' Edit row
  380.  
  381.             ' msgText
  382.             tblMessage.msgText.EditCustomAttributes = ""
  383.             tblMessage.msgText.EditValue = ew_HtmlEncode(tblMessage.msgText.CurrentValue)
  384.  
  385.             ' msgStartDate
  386.             tblMessage.msgStartDate.EditCustomAttributes = ""
  387.             tblMessage.msgStartDate.EditValue = ew_FormatDateTime(tblMessage.msgStartDate.CurrentValue, 6)
  388.  
  389.             ' msgEndDate
  390.             tblMessage.msgEndDate.EditCustomAttributes = ""
  391.             tblMessage.msgEndDate.EditValue = ew_FormatDateTime(tblMessage.msgEndDate.CurrentValue, 6)
  392.  
  393.             ' Edit refer script
  394.             ' msgText
  395.  
  396.             tblMessage.msgText.HrefValue = ""
  397.  
  398.             ' msgStartDate
  399.             tblMessage.msgStartDate.HrefValue = ""
  400.  
  401.             ' msgEndDate
  402.             tblMessage.msgEndDate.HrefValue = ""
  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.     ' Update record based on key values
  443.     '
  444.     Function EditRow() As Boolean
  445.         Dim RsEdit As OleDbDataReader, RsChk As OleDbDataReader
  446.         Dim sSql As String, sFilter As String
  447.         Dim sSqlChk As String, sFilterChk As String
  448.         Dim bUpdateRow As Boolean
  449.         Dim RsOld As OrderedDictionary
  450.         Dim sIdxErrMsg As String
  451.         Dim Rs As New OrderedDictionary
  452.         sFilter = tblMessage.KeyFilter
  453.         tblMessage.CurrentFilter  = sFilter
  454.         sSql = tblMessage.SQL
  455.         Try
  456.             RsEdit = Conn.GetDataReader(sSql) 
  457.         Catch e As Exception
  458.             If EW_DEBUG_ENABLED Then Throw
  459.             Message = e.Message
  460.             RsEdit.Close()
  461.             EditRow = False
  462.         End Try
  463.         If Not RsEdit.Read() Then
  464.             RsEdit.Close()
  465.             EditRow = False ' Update Failed
  466.         Else
  467.             RsOld = Conn.GetRow(RsEdit)
  468.             RsEdit.Close()
  469.  
  470.             ' msgText
  471.             tblMessage.msgText.SetDbValue(tblMessage.msgText.CurrentValue, System.DBNull.Value)
  472.             Rs("msgText") = tblMessage.msgText.DbValue
  473.  
  474.             ' msgStartDate
  475.             tblMessage.msgStartDate.SetDbValue(ew_UnFormatDateTime(tblMessage.msgStartDate.CurrentValue, 6), System.DBNull.Value)
  476.             Rs("msgStartDate") = tblMessage.msgStartDate.DbValue
  477.  
  478.             ' msgEndDate
  479.             tblMessage.msgEndDate.SetDbValue(ew_UnFormatDateTime(tblMessage.msgEndDate.CurrentValue, 6), System.DBNull.Value)
  480.             Rs("msgEndDate") = tblMessage.msgEndDate.DbValue
  481.  
  482.             ' Row Updating event
  483.             bUpdateRow = tblMessage.Row_Updating(RsOld, Rs)
  484.             If bUpdateRow Then
  485.                 Try
  486.                     tblMessage.Update(Rs)
  487.                     EditRow = True
  488.                 Catch e As Exception
  489.                     If EW_DEBUG_ENABLED Then Throw
  490.                     Message = e.Message
  491.                     EditRow = False
  492.                 End Try
  493.             Else
  494.                 If tblMessage.CancelMessage <> "" Then
  495.                     Message = tblMessage.CancelMessage
  496.                     tblMessage.CancelMessage = ""
  497.                 Else
  498.                     Message = "Update cancelled"
  499.                 End If
  500.                 EditRow = False
  501.             End If
  502.         End If
  503.  
  504.         ' Row Updated event
  505.         If EditRow Then
  506.             tblMessage.Row_Updated(RsOld, Rs)
  507.         End If
  508.     End Function
  509.  
  510.         ' Page Load event
  511.         Public Sub Page_Load()
  512.  
  513.             'HttpContext.Current.Response.Write("Page Load")
  514.         End Sub
  515.  
  516.         ' Page Unload event
  517.         Public Sub Page_Unload()
  518.  
  519.             'HttpContext.Current.Response.Write("Page Unload")
  520.         End Sub
  521.  
  522.     ' Form Custom Validate event
  523.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  524.  
  525.         'Return error message in CustomError
  526.         Return True
  527.     End Function
  528.     End Class
  529.  
  530.     '
  531.     ' ASP.NET Page_Load event
  532.     '
  533.  
  534.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  535.         Response.Buffer = EW_RESPONSE_BUFFER
  536.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  537.  
  538.         ' Page init
  539.         tblMessage_edit = New ctblMessage_edit(Me)        
  540.         tblMessage_edit.Page_Init()
  541.  
  542.         ' Page main processing
  543.         tblMessage_edit.Page_Main()
  544.     End Sub
  545.  
  546.     '
  547.     ' ASP.NET Page_Unload event
  548.     '
  549.  
  550.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  551.  
  552.         ' Dispose page object
  553.         If tblMessage_edit IsNot Nothing Then tblMessage_edit.Dispose()
  554.     End Sub
  555. End Class
  556.