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