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