home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / ltgFixtureTypeedit.aspx.vb < prev    next >
Text File  |  2014-01-25  |  14KB  |  523 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 ltgFixtureTypeedit
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public ltgFixtureType_edit As cltgFixtureType_edit
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class cltgFixtureType_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 ltgFixtureType.UseTokenInUrl Then Url = Url & "t=" & ltgFixtureType.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 ltgFixtureType.UseTokenInUrl Then
  44.                 Result = False
  45.                 If ObjForm IsNot Nothing Then
  46.                     Result = (ltgFixtureType.TableVar = ObjForm.GetValue("t"))
  47.                 End If
  48.                 If ew_Get("t") <> "" Then
  49.                     Result = (ltgFixtureType.TableVar = ew_Get("t"))
  50.                 End If
  51.                 Return Result
  52.             End If
  53.             Return True            
  54.         End Function    
  55.  
  56.         ' ltgFixtureType
  57.         Public Property ltgFixtureType() As cltgFixtureType
  58.             Get                
  59.                 Return ParentPage.ltgFixtureType
  60.             End Get
  61.             Set(ByVal v As cltgFixtureType)
  62.                 ParentPage.ltgFixtureType = v    
  63.             End Set    
  64.         End Property
  65.  
  66.         ' ltgFixtureType
  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 = "ltgFixtureType_edit"
  86.             m_PageObjTypeName = "cltgFixtureType_edit"
  87.  
  88.             ' Table Name
  89.             m_TableName = "ltgFixtureType"
  90.  
  91.             ' Initialize table object
  92.             ltgFixtureType = New cltgFixtureType(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("ltgFixtureTypelist.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.             ltgFixtureType.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("ftyID") <> "" Then
  181.             ltgFixtureType.ftyID.QueryStringValue = ew_Get("ftyID")
  182.         End If
  183.  
  184.         ' Create form object
  185.         ObjForm = New cFormObj
  186.         If ObjForm.GetValue("a_edit") <> "" Then
  187.             ltgFixtureType.CurrentAction = ObjForm.GetValue("a_edit") ' Get action code
  188.             LoadFormValues() ' Get form values
  189.  
  190.             ' Validate Form
  191.             If Not ValidateForm() Then
  192.                 ltgFixtureType.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.             ltgFixtureType.CurrentAction = "I" ' Default action is display
  199.         End If
  200.  
  201.         ' Check if valid key
  202.         If ew_Empty(ltgFixtureType.ftyID.CurrentValue) Then Page_Terminate("ltgFixtureTypelist.aspx") ' Invalid key, return to list
  203.         Select Case ltgFixtureType.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("ltgFixtureTypelist.aspx") ' No matching record, return to list
  208.                 End If
  209.             Case "U" ' Update
  210.                 ltgFixtureType.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 = ltgFixtureType.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.         ltgFixtureType.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.         ltgFixtureType.ftyDescription.FormValue = ObjForm.GetValue("x_ftyDescription")
  247.         ltgFixtureType.ftyDescription.OldValue = ObjForm.GetValue("o_ftyDescription")
  248.         ltgFixtureType.ftyIsActive.FormValue = ObjForm.GetValue("x_ftyIsActive")
  249.         ltgFixtureType.ftyIsActive.OldValue = ObjForm.GetValue("o_ftyIsActive")
  250.         ltgFixtureType.ftyID.FormValue = ObjForm.GetValue("x_ftyID")
  251.     End Sub
  252.  
  253.     '
  254.     ' Restore form values
  255.     '
  256.     Sub RestoreFormValues()
  257.         ltgFixtureType.ftyDescription.CurrentValue = ltgFixtureType.ftyDescription.FormValue
  258.         ltgFixtureType.ftyIsActive.CurrentValue = ltgFixtureType.ftyIsActive.FormValue
  259.         ltgFixtureType.ftyID.CurrentValue = ltgFixtureType.ftyID.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 = ltgFixtureType.KeyFilter
  268.  
  269.         ' Row Selecting event
  270.         ltgFixtureType.Row_Selecting(sFilter)
  271.  
  272.         ' Load SQL based on filter
  273.         ltgFixtureType.CurrentFilter = sFilter
  274.         Dim sSql As String = ltgFixtureType.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.                 ltgFixtureType.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.         ltgFixtureType.ftyID.DbValue = RsRow("ftyID")
  302.         ltgFixtureType.ftyDescription.DbValue = RsRow("ftyDescription")
  303.         ltgFixtureType.ftyIsActive.DbValue = IIf(ew_ConvertToBool(RsRow("ftyIsActive")), "1", "0")
  304.     End Sub
  305.  
  306.     '
  307.     ' Render row values based on field settings
  308.     '
  309.     Sub RenderRow()
  310.  
  311.         ' Row Rendering event
  312.         ltgFixtureType.Row_Rendering()
  313.  
  314.         '
  315.         '  Common render codes for all row types
  316.         '
  317.         ' ftyDescription
  318.  
  319.         ltgFixtureType.ftyDescription.CellCssStyle = ""
  320.         ltgFixtureType.ftyDescription.CellCssClass = ""
  321.  
  322.         ' ftyIsActive
  323.         ltgFixtureType.ftyIsActive.CellCssStyle = ""
  324.         ltgFixtureType.ftyIsActive.CellCssClass = ""
  325.  
  326.         '
  327.         '  View  Row
  328.         '
  329.  
  330.         If ltgFixtureType.RowType = EW_ROWTYPE_VIEW Then ' View row
  331.  
  332.             ' ftyID
  333.             ltgFixtureType.ftyID.ViewValue = ltgFixtureType.ftyID.CurrentValue
  334.             ltgFixtureType.ftyID.CssStyle = ""
  335.             ltgFixtureType.ftyID.CssClass = ""
  336.             ltgFixtureType.ftyID.ViewCustomAttributes = ""
  337.  
  338.             ' ftyDescription
  339.             ltgFixtureType.ftyDescription.ViewValue = ltgFixtureType.ftyDescription.CurrentValue
  340.             ltgFixtureType.ftyDescription.CssStyle = ""
  341.             ltgFixtureType.ftyDescription.CssClass = ""
  342.             ltgFixtureType.ftyDescription.ViewCustomAttributes = ""
  343.  
  344.             ' ftyIsActive
  345.             If Convert.ToString(ltgFixtureType.ftyIsActive.CurrentValue) = "1" Then
  346.                 ltgFixtureType.ftyIsActive.ViewValue = "Yes"
  347.             Else
  348.                 ltgFixtureType.ftyIsActive.ViewValue = "No"
  349.             End If
  350.             ltgFixtureType.ftyIsActive.CssStyle = ""
  351.             ltgFixtureType.ftyIsActive.CssClass = ""
  352.             ltgFixtureType.ftyIsActive.ViewCustomAttributes = ""
  353.  
  354.             ' View refer script
  355.             ' ftyDescription
  356.  
  357.             ltgFixtureType.ftyDescription.HrefValue = ""
  358.  
  359.             ' ftyIsActive
  360.             ltgFixtureType.ftyIsActive.HrefValue = ""
  361.  
  362.         '
  363.         '  Edit Row
  364.         '
  365.  
  366.         ElseIf ltgFixtureType.RowType = EW_ROWTYPE_EDIT Then ' Edit row
  367.  
  368.             ' ftyDescription
  369.             ltgFixtureType.ftyDescription.EditCustomAttributes = ""
  370.             ltgFixtureType.ftyDescription.EditValue = ew_HtmlEncode(ltgFixtureType.ftyDescription.CurrentValue)
  371.  
  372.             ' ftyIsActive
  373.             ltgFixtureType.ftyIsActive.EditCustomAttributes = ""
  374.  
  375.             ' Edit refer script
  376.             ' ftyDescription
  377.  
  378.             ltgFixtureType.ftyDescription.HrefValue = ""
  379.  
  380.             ' ftyIsActive
  381.             ltgFixtureType.ftyIsActive.HrefValue = ""
  382.         End If
  383.  
  384.         ' Row Rendered event
  385.         ltgFixtureType.Row_Rendered()
  386.     End Sub
  387.  
  388.     '
  389.     ' Validate form
  390.     '
  391.     Function ValidateForm() As Boolean
  392.  
  393.         ' Initialize
  394.         ParentPage.gsFormError = ""
  395.  
  396.         ' Check if validation required
  397.         If Not EW_SERVER_VALIDATE Then Return (ParentPage.gsFormError = "")
  398.  
  399.         ' Return validate result
  400.         Dim Valid As Boolean = (ParentPage.gsFormError = "")
  401.  
  402.         ' Form_CustomValidate event
  403.         Dim sFormCustomError As String = ""
  404.         Valid = Valid And Form_CustomValidate(sFormCustomError)
  405.         If sFormCustomError <> "" Then
  406.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  407.             ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  408.         End If
  409.         Return Valid
  410.     End Function
  411.  
  412.     '
  413.     ' Update record based on key values
  414.     '
  415.     Function EditRow() As Boolean
  416.         Dim RsEdit As OleDbDataReader, RsChk As OleDbDataReader
  417.         Dim sSql As String, sFilter As String
  418.         Dim sSqlChk As String, sFilterChk As String
  419.         Dim bUpdateRow As Boolean
  420.         Dim RsOld As OrderedDictionary
  421.         Dim sIdxErrMsg As String
  422.         Dim Rs As New OrderedDictionary
  423.         sFilter = ltgFixtureType.KeyFilter
  424.         ltgFixtureType.CurrentFilter  = sFilter
  425.         sSql = ltgFixtureType.SQL
  426.         Try
  427.             RsEdit = Conn.GetDataReader(sSql) 
  428.         Catch e As Exception
  429.             If EW_DEBUG_ENABLED Then Throw
  430.             Message = e.Message
  431.             RsEdit.Close()
  432.             EditRow = False
  433.         End Try
  434.         If Not RsEdit.Read() Then
  435.             RsEdit.Close()
  436.             EditRow = False ' Update Failed
  437.         Else
  438.             RsOld = Conn.GetRow(RsEdit)
  439.             RsEdit.Close()
  440.  
  441.             ' ftyDescription
  442.             ltgFixtureType.ftyDescription.SetDbValue(ltgFixtureType.ftyDescription.CurrentValue, System.DBNull.Value)
  443.             Rs("ftyDescription") = ltgFixtureType.ftyDescription.DbValue
  444.  
  445.             ' ftyIsActive
  446.             ltgFixtureType.ftyIsActive.SetDbValue((ltgFixtureType.ftyIsActive.CurrentValue <> "" And Not IsDBNull(ltgFixtureType.ftyIsActive.CurrentValue)), System.DBNull.Value)
  447.             Rs("ftyIsActive") = ltgFixtureType.ftyIsActive.DbValue
  448.  
  449.             ' Row Updating event
  450.             bUpdateRow = ltgFixtureType.Row_Updating(RsOld, Rs)
  451.             If bUpdateRow Then
  452.                 Try
  453.                     ltgFixtureType.Update(Rs)
  454.                     EditRow = True
  455.                 Catch e As Exception
  456.                     If EW_DEBUG_ENABLED Then Throw
  457.                     Message = e.Message
  458.                     EditRow = False
  459.                 End Try
  460.             Else
  461.                 If ltgFixtureType.CancelMessage <> "" Then
  462.                     Message = ltgFixtureType.CancelMessage
  463.                     ltgFixtureType.CancelMessage = ""
  464.                 Else
  465.                     Message = "Update cancelled"
  466.                 End If
  467.                 EditRow = False
  468.             End If
  469.         End If
  470.  
  471.         ' Row Updated event
  472.         If EditRow Then
  473.             ltgFixtureType.Row_Updated(RsOld, Rs)
  474.         End If
  475.     End Function
  476.  
  477.         ' Page Load event
  478.         Public Sub Page_Load()
  479.  
  480.             'HttpContext.Current.Response.Write("Page Load")
  481.         End Sub
  482.  
  483.         ' Page Unload event
  484.         Public Sub Page_Unload()
  485.  
  486.             'HttpContext.Current.Response.Write("Page Unload")
  487.         End Sub
  488.  
  489.     ' Form Custom Validate event
  490.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  491.  
  492.         'Return error message in CustomError
  493.         Return True
  494.     End Function
  495.     End Class
  496.  
  497.     '
  498.     ' ASP.NET Page_Load event
  499.     '
  500.  
  501.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  502.         Response.Buffer = EW_RESPONSE_BUFFER
  503.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  504.  
  505.         ' Page init
  506.         ltgFixtureType_edit = New cltgFixtureType_edit(Me)        
  507.         ltgFixtureType_edit.Page_Init()
  508.  
  509.         ' Page main processing
  510.         ltgFixtureType_edit.Page_Main()
  511.     End Sub
  512.  
  513.     '
  514.     ' ASP.NET Page_Unload event
  515.     '
  516.  
  517.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  518.  
  519.         ' Dispose page object
  520.         If ltgFixtureType_edit IsNot Nothing Then ltgFixtureType_edit.Dispose()
  521.     End Sub
  522. End Class
  523.