home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblFixtureMasteradd.aspx.vb < prev    next >
Text File  |  2010-08-24  |  22KB  |  696 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 tblFixtureMasteradd
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblFixtureMaster_add As ctblFixtureMaster_add
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblFixtureMaster_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 tblFixtureMaster.UseTokenInUrl Then Url = Url & "t=" & tblFixtureMaster.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 tblFixtureMaster.UseTokenInUrl Then
  44.                 Result = False
  45.                 If ObjForm IsNot Nothing Then
  46.                     Result = (tblFixtureMaster.TableVar = ObjForm.GetValue("t"))
  47.                 End If
  48.                 If ew_Get("t") <> "" Then
  49.                     Result = (tblFixtureMaster.TableVar = ew_Get("t"))
  50.                 End If
  51.                 Return Result
  52.             End If
  53.             Return True            
  54.         End Function    
  55.  
  56.         ' tblFixtureMaster
  57.         Public Property tblFixtureMaster() As ctblFixtureMaster
  58.             Get                
  59.                 Return ParentPage.tblFixtureMaster
  60.             End Get
  61.             Set(ByVal v As ctblFixtureMaster)
  62.                 ParentPage.tblFixtureMaster = v    
  63.             End Set    
  64.         End Property
  65.  
  66.         ' tblFixtureMaster
  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 = "tblFixtureMaster_add"
  86.             m_PageObjTypeName = "ctblFixtureMaster_add"
  87.  
  88.             ' Table Name
  89.             m_TableName = "tblFixtureMaster"
  90.  
  91.             ' Initialize table object
  92.             tblFixtureMaster = New ctblFixtureMaster(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("tblFixtureMasterlist.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.             tblFixtureMaster.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("lfxID") <> "" Then
  184.             tblFixtureMaster.lfxID.QueryStringValue = ew_Get("lfxID")
  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.             tblFixtureMaster.CurrentAction = ObjForm.GetValue("a_add") ' Get form action
  195.             LoadFormValues() ' Load form values
  196.  
  197.             ' Validate Form
  198.             If Not ValidateForm() Then
  199.                 tblFixtureMaster.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.                 tblFixtureMaster.CurrentAction = "C" ' Copy Record
  207.             Else
  208.                 tblFixtureMaster.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 tblFixtureMaster.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("tblFixtureMasterlist.aspx") ' No matching record, return to list
  220.                 End If
  221.             Case "A" ' Add new record
  222.                 tblFixtureMaster.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 = tblFixtureMaster.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.         tblFixtureMaster.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.         tblFixtureMaster.lfxMFG.FormValue = ObjForm.GetValue("x_lfxMFG")
  258.         tblFixtureMaster.lfxMFG.OldValue = ObjForm.GetValue("o_lfxMFG")
  259.         tblFixtureMaster.lfxModelType.FormValue = ObjForm.GetValue("x_lfxModelType")
  260.         tblFixtureMaster.lfxModelType.OldValue = ObjForm.GetValue("o_lfxModelType")
  261.         tblFixtureMaster.lfxSerialNumber.FormValue = ObjForm.GetValue("x_lfxSerialNumber")
  262.         tblFixtureMaster.lfxSerialNumber.OldValue = ObjForm.GetValue("o_lfxSerialNumber")
  263.         tblFixtureMaster.lfxLamp.FormValue = ObjForm.GetValue("x_lfxLamp")
  264.         tblFixtureMaster.lfxLamp.OldValue = ObjForm.GetValue("o_lfxLamp")
  265.         tblFixtureMaster.lfxLocationID.FormValue = ObjForm.GetValue("x_lfxLocationID")
  266.         tblFixtureMaster.lfxLocationID.OldValue = ObjForm.GetValue("o_lfxLocationID")
  267.         tblFixtureMaster.lfxHangPos.FormValue = ObjForm.GetValue("x_lfxHangPos")
  268.         tblFixtureMaster.lfxHangPos.OldValue = ObjForm.GetValue("o_lfxHangPos")
  269.         tblFixtureMaster.lfxChannel.FormValue = ObjForm.GetValue("x_lfxChannel")
  270.         tblFixtureMaster.lfxChannel.OldValue = ObjForm.GetValue("o_lfxChannel")
  271.         tblFixtureMaster.lfxNotes.FormValue = ObjForm.GetValue("x_lfxNotes")
  272.         tblFixtureMaster.lfxNotes.OldValue = ObjForm.GetValue("o_lfxNotes")
  273.         tblFixtureMaster.lfxID.FormValue = ObjForm.GetValue("x_lfxID")
  274.     End Sub
  275.  
  276.     '
  277.     ' Restore form values
  278.     '
  279.     Sub RestoreFormValues()
  280.         tblFixtureMaster.lfxMFG.CurrentValue = tblFixtureMaster.lfxMFG.FormValue
  281.         tblFixtureMaster.lfxModelType.CurrentValue = tblFixtureMaster.lfxModelType.FormValue
  282.         tblFixtureMaster.lfxSerialNumber.CurrentValue = tblFixtureMaster.lfxSerialNumber.FormValue
  283.         tblFixtureMaster.lfxLamp.CurrentValue = tblFixtureMaster.lfxLamp.FormValue
  284.         tblFixtureMaster.lfxLocationID.CurrentValue = tblFixtureMaster.lfxLocationID.FormValue
  285.         tblFixtureMaster.lfxHangPos.CurrentValue = tblFixtureMaster.lfxHangPos.FormValue
  286.         tblFixtureMaster.lfxChannel.CurrentValue = tblFixtureMaster.lfxChannel.FormValue
  287.         tblFixtureMaster.lfxNotes.CurrentValue = tblFixtureMaster.lfxNotes.FormValue
  288.         tblFixtureMaster.lfxID.CurrentValue = tblFixtureMaster.lfxID.FormValue
  289.     End Sub
  290.  
  291.     '
  292.     ' Load row based on key values
  293.     '
  294.     Function LoadRow() As Boolean
  295.         Dim RsRow As OleDbDataReader
  296.         Dim sFilter As String = tblFixtureMaster.KeyFilter
  297.  
  298.         ' Row Selecting event
  299.         tblFixtureMaster.Row_Selecting(sFilter)
  300.  
  301.         ' Load SQL based on filter
  302.         tblFixtureMaster.CurrentFilter = sFilter
  303.         Dim sSql As String = tblFixtureMaster.SQL
  304.  
  305.         ' Write SQL for debug
  306.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  307.         Try
  308.             RsRow = Conn.GetTempDataReader(sSql)    
  309.             If Not RsRow.Read() Then
  310.                 Return False
  311.             Else                
  312.                 LoadRowValues(RsRow) ' Load row values
  313.  
  314.                 ' Row Selected event
  315.                 tblFixtureMaster.Row_Selected(RsRow)
  316.                 Return True    
  317.             End If
  318.         Catch
  319.             If EW_DEBUG_ENABLED Then Throw
  320.             Return False
  321.         Finally
  322.             Conn.CloseTempDataReader()
  323.         End Try
  324.     End Function
  325.  
  326.     '
  327.     ' Load row values from recordset
  328.     '
  329.     Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
  330.         tblFixtureMaster.lfxID.DbValue = RsRow("lfxID")
  331.         tblFixtureMaster.lfxMFG.DbValue = RsRow("lfxMFG")
  332.         tblFixtureMaster.lfxModelType.DbValue = RsRow("lfxModelType")
  333.         tblFixtureMaster.lfxSerialNumber.DbValue = RsRow("lfxSerialNumber")
  334.         tblFixtureMaster.lfxLamp.DbValue = RsRow("lfxLamp")
  335.         tblFixtureMaster.lfxLocationID.DbValue = RsRow("lfxLocationID")
  336.         tblFixtureMaster.lfxHangPos.DbValue = RsRow("lfxHangPos")
  337.         tblFixtureMaster.lfxChannel.DbValue = RsRow("lfxChannel")
  338.         tblFixtureMaster.lfxNotes.DbValue = RsRow("lfxNotes")
  339.     End Sub
  340.  
  341.     '
  342.     ' Render row values based on field settings
  343.     '
  344.     Sub RenderRow()
  345.  
  346.         ' Row Rendering event
  347.         tblFixtureMaster.Row_Rendering()
  348.  
  349.         '
  350.         '  Common render codes for all row types
  351.         '
  352.         ' lfxMFG
  353.  
  354.         tblFixtureMaster.lfxMFG.CellCssStyle = ""
  355.         tblFixtureMaster.lfxMFG.CellCssClass = ""
  356.  
  357.         ' lfxModelType
  358.         tblFixtureMaster.lfxModelType.CellCssStyle = ""
  359.         tblFixtureMaster.lfxModelType.CellCssClass = ""
  360.  
  361.         ' lfxSerialNumber
  362.         tblFixtureMaster.lfxSerialNumber.CellCssStyle = ""
  363.         tblFixtureMaster.lfxSerialNumber.CellCssClass = ""
  364.  
  365.         ' lfxLamp
  366.         tblFixtureMaster.lfxLamp.CellCssStyle = ""
  367.         tblFixtureMaster.lfxLamp.CellCssClass = ""
  368.  
  369.         ' lfxLocationID
  370.         tblFixtureMaster.lfxLocationID.CellCssStyle = ""
  371.         tblFixtureMaster.lfxLocationID.CellCssClass = ""
  372.  
  373.         ' lfxHangPos
  374.         tblFixtureMaster.lfxHangPos.CellCssStyle = ""
  375.         tblFixtureMaster.lfxHangPos.CellCssClass = ""
  376.  
  377.         ' lfxChannel
  378.         tblFixtureMaster.lfxChannel.CellCssStyle = ""
  379.         tblFixtureMaster.lfxChannel.CellCssClass = ""
  380.  
  381.         ' lfxNotes
  382.         tblFixtureMaster.lfxNotes.CellCssStyle = ""
  383.         tblFixtureMaster.lfxNotes.CellCssClass = ""
  384.  
  385.         '
  386.         '  View  Row
  387.         '
  388.  
  389.         If tblFixtureMaster.RowType = EW_ROWTYPE_VIEW Then ' View row
  390.  
  391.             ' lfxMFG
  392.             tblFixtureMaster.lfxMFG.ViewValue = tblFixtureMaster.lfxMFG.CurrentValue
  393.             tblFixtureMaster.lfxMFG.CssStyle = ""
  394.             tblFixtureMaster.lfxMFG.CssClass = ""
  395.             tblFixtureMaster.lfxMFG.ViewCustomAttributes = ""
  396.  
  397.             ' lfxModelType
  398.             tblFixtureMaster.lfxModelType.ViewValue = tblFixtureMaster.lfxModelType.CurrentValue
  399.             tblFixtureMaster.lfxModelType.CssStyle = ""
  400.             tblFixtureMaster.lfxModelType.CssClass = ""
  401.             tblFixtureMaster.lfxModelType.ViewCustomAttributes = ""
  402.  
  403.             ' lfxSerialNumber
  404.             tblFixtureMaster.lfxSerialNumber.ViewValue = tblFixtureMaster.lfxSerialNumber.CurrentValue
  405.             tblFixtureMaster.lfxSerialNumber.CssStyle = ""
  406.             tblFixtureMaster.lfxSerialNumber.CssClass = ""
  407.             tblFixtureMaster.lfxSerialNumber.ViewCustomAttributes = ""
  408.  
  409.             ' lfxLamp
  410.             tblFixtureMaster.lfxLamp.ViewValue = tblFixtureMaster.lfxLamp.CurrentValue
  411.             tblFixtureMaster.lfxLamp.CssStyle = ""
  412.             tblFixtureMaster.lfxLamp.CssClass = ""
  413.             tblFixtureMaster.lfxLamp.ViewCustomAttributes = ""
  414.  
  415.             ' lfxLocationID
  416.             If ew_NotEmpty(tblFixtureMaster.lfxLocationID.CurrentValue) Then
  417.                 sSqlWrk = "SELECT [locDescription] FROM [tblLocations] WHERE [locID] = " & ew_AdjustSql(tblFixtureMaster.lfxLocationID.CurrentValue) & ""
  418.                 sSqlWrk = sSqlWrk & " AND (" & "[locLighting]=True" & ")"
  419.                 sSqlWrk = sSqlWrk & " ORDER BY [locDescription] "
  420.                 RsWrk = Conn.GetTempDataReader(sSqlWrk)
  421.                 If RsWrk.Read() Then
  422.                     tblFixtureMaster.lfxLocationID.ViewValue = RsWrk("locDescription")
  423.                 Else
  424.                     tblFixtureMaster.lfxLocationID.ViewValue = tblFixtureMaster.lfxLocationID.CurrentValue
  425.                 End If
  426.                 Conn.CloseTempDataReader()
  427.             Else
  428.                 tblFixtureMaster.lfxLocationID.ViewValue = System.DBNull.Value
  429.             End If
  430.             tblFixtureMaster.lfxLocationID.CssStyle = ""
  431.             tblFixtureMaster.lfxLocationID.CssClass = ""
  432.             tblFixtureMaster.lfxLocationID.ViewCustomAttributes = ""
  433.  
  434.             ' lfxHangPos
  435.             tblFixtureMaster.lfxHangPos.ViewValue = tblFixtureMaster.lfxHangPos.CurrentValue
  436.             tblFixtureMaster.lfxHangPos.CssStyle = ""
  437.             tblFixtureMaster.lfxHangPos.CssClass = ""
  438.             tblFixtureMaster.lfxHangPos.ViewCustomAttributes = ""
  439.  
  440.             ' lfxChannel
  441.             tblFixtureMaster.lfxChannel.ViewValue = tblFixtureMaster.lfxChannel.CurrentValue
  442.             tblFixtureMaster.lfxChannel.CssStyle = ""
  443.             tblFixtureMaster.lfxChannel.CssClass = ""
  444.             tblFixtureMaster.lfxChannel.ViewCustomAttributes = ""
  445.  
  446.             ' lfxNotes
  447.             tblFixtureMaster.lfxNotes.ViewValue = tblFixtureMaster.lfxNotes.CurrentValue
  448.             tblFixtureMaster.lfxNotes.CssStyle = ""
  449.             tblFixtureMaster.lfxNotes.CssClass = ""
  450.             tblFixtureMaster.lfxNotes.ViewCustomAttributes = ""
  451.  
  452.             ' View refer script
  453.             ' lfxMFG
  454.  
  455.             tblFixtureMaster.lfxMFG.HrefValue = ""
  456.  
  457.             ' lfxModelType
  458.             tblFixtureMaster.lfxModelType.HrefValue = ""
  459.  
  460.             ' lfxSerialNumber
  461.             tblFixtureMaster.lfxSerialNumber.HrefValue = ""
  462.  
  463.             ' lfxLamp
  464.             tblFixtureMaster.lfxLamp.HrefValue = ""
  465.  
  466.             ' lfxLocationID
  467.             tblFixtureMaster.lfxLocationID.HrefValue = ""
  468.  
  469.             ' lfxHangPos
  470.             tblFixtureMaster.lfxHangPos.HrefValue = ""
  471.  
  472.             ' lfxChannel
  473.             tblFixtureMaster.lfxChannel.HrefValue = ""
  474.  
  475.             ' lfxNotes
  476.             tblFixtureMaster.lfxNotes.HrefValue = ""
  477.  
  478.         '
  479.         '  Add Row
  480.         '
  481.  
  482.         ElseIf tblFixtureMaster.RowType = EW_ROWTYPE_ADD Then ' Add row
  483.  
  484.             ' lfxMFG
  485.             tblFixtureMaster.lfxMFG.EditCustomAttributes = ""
  486.             tblFixtureMaster.lfxMFG.EditValue = ew_HtmlEncode(tblFixtureMaster.lfxMFG.CurrentValue)
  487.  
  488.             ' lfxModelType
  489.             tblFixtureMaster.lfxModelType.EditCustomAttributes = ""
  490.             tblFixtureMaster.lfxModelType.EditValue = ew_HtmlEncode(tblFixtureMaster.lfxModelType.CurrentValue)
  491.  
  492.             ' lfxSerialNumber
  493.             tblFixtureMaster.lfxSerialNumber.EditCustomAttributes = ""
  494.             tblFixtureMaster.lfxSerialNumber.EditValue = ew_HtmlEncode(tblFixtureMaster.lfxSerialNumber.CurrentValue)
  495.  
  496.             ' lfxLamp
  497.             tblFixtureMaster.lfxLamp.EditCustomAttributes = ""
  498.             tblFixtureMaster.lfxLamp.EditValue = ew_HtmlEncode(tblFixtureMaster.lfxLamp.CurrentValue)
  499.  
  500.             ' lfxLocationID
  501.             tblFixtureMaster.lfxLocationID.EditCustomAttributes = ""
  502.             sSqlWrk = "SELECT [locID], [locDescription], '' AS Disp2Fld, '' AS SelectFilterFld FROM [tblLocations]"
  503.             sWhereWrk = ""
  504.             If sWhereWrk <> "" Then sWhereWrk = "(" & sWhereWrk & ") AND "
  505.             sWhereWrk = sWhereWrk & "(" & "[locLighting]=True" & ")"
  506.             If sWhereWrk <> "" Then sSqlWrk = sSqlWrk & " WHERE " & sWhereWrk
  507.             sSqlWrk = sSqlWrk & " ORDER BY [locDescription] "
  508.             arwrk = Conn.GetRows(sSqlWrk)
  509.             arwrk.Insert(0, New Object(){"", "Please Select"}) 
  510.             tblFixtureMaster.lfxLocationID.EditValue = arwrk
  511.  
  512.             ' lfxHangPos
  513.             tblFixtureMaster.lfxHangPos.EditCustomAttributes = ""
  514.             tblFixtureMaster.lfxHangPos.EditValue = ew_HtmlEncode(tblFixtureMaster.lfxHangPos.CurrentValue)
  515.  
  516.             ' lfxChannel
  517.             tblFixtureMaster.lfxChannel.EditCustomAttributes = ""
  518.             tblFixtureMaster.lfxChannel.EditValue = ew_HtmlEncode(tblFixtureMaster.lfxChannel.CurrentValue)
  519.  
  520.             ' lfxNotes
  521.             tblFixtureMaster.lfxNotes.EditCustomAttributes = ""
  522.             tblFixtureMaster.lfxNotes.EditValue = ew_HtmlEncode(tblFixtureMaster.lfxNotes.CurrentValue)
  523.         End If
  524.  
  525.         ' Row Rendered event
  526.         tblFixtureMaster.Row_Rendered()
  527.     End Sub
  528.  
  529.     '
  530.     ' Validate form
  531.     '
  532.     Function ValidateForm() As Boolean
  533.  
  534.         ' Initialize
  535.         ParentPage.gsFormError = ""
  536.  
  537.         ' Check if validation required
  538.         If Not EW_SERVER_VALIDATE Then Return (ParentPage.gsFormError = "")
  539.         If ew_Empty(tblFixtureMaster.lfxMFG.FormValue) Then
  540.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  541.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Manufacturer"
  542.         End If
  543.         If ew_Empty(tblFixtureMaster.lfxModelType.FormValue) Then
  544.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  545.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Model / Type"
  546.         End If
  547.         If ew_Empty(tblFixtureMaster.lfxLocationID.FormValue) Then
  548.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  549.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Location"
  550.         End If
  551.         If ew_Empty(tblFixtureMaster.lfxHangPos.FormValue) Then
  552.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  553.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Hang Pos"
  554.         End If
  555.         If ew_Empty(tblFixtureMaster.lfxChannel.FormValue) Then
  556.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  557.             ParentPage.gsFormError = ParentPage.gsFormError & "Please enter required field - Channel"
  558.         End If
  559.         If Not ew_CheckInteger(tblFixtureMaster.lfxChannel.FormValue) Then
  560.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  561.             ParentPage.gsFormError = ParentPage.gsFormError & "Incorrect integer - Channel"
  562.         End If
  563.  
  564.         ' Return validate result
  565.         Dim Valid As Boolean = (ParentPage.gsFormError = "")
  566.  
  567.         ' Form_CustomValidate event
  568.         Dim sFormCustomError As String = ""
  569.         Valid = Valid And Form_CustomValidate(sFormCustomError)
  570.         If sFormCustomError <> "" Then
  571.             If ParentPage.gsFormError <> "" Then ParentPage.gsFormError = ParentPage.gsFormError & "<br />"
  572.             ParentPage.gsFormError = ParentPage.gsFormError & sFormCustomError
  573.         End If
  574.         Return Valid
  575.     End Function
  576.  
  577.     '
  578.     ' Add record
  579.     '
  580.     Function AddRow() As Boolean
  581.         Dim Rs As New OrderedDictionary
  582.         Dim sSql As String, sFilter As String
  583.         Dim bInsertRow As Boolean
  584.         Dim RsChk As OleDbDataReader
  585.         Dim sIdxErrMsg As String
  586.         Dim LastInsertId As Object
  587.  
  588.         ' lfxMFG
  589.         tblFixtureMaster.lfxMFG.SetDbValue(tblFixtureMaster.lfxMFG.CurrentValue, System.DBNull.Value)
  590.         Rs("lfxMFG") = tblFixtureMaster.lfxMFG.DbValue
  591.  
  592.         ' lfxModelType
  593.         tblFixtureMaster.lfxModelType.SetDbValue(tblFixtureMaster.lfxModelType.CurrentValue, System.DBNull.Value)
  594.         Rs("lfxModelType") = tblFixtureMaster.lfxModelType.DbValue
  595.  
  596.         ' lfxSerialNumber
  597.         tblFixtureMaster.lfxSerialNumber.SetDbValue(tblFixtureMaster.lfxSerialNumber.CurrentValue, System.DBNull.Value)
  598.         Rs("lfxSerialNumber") = tblFixtureMaster.lfxSerialNumber.DbValue
  599.  
  600.         ' lfxLamp
  601.         tblFixtureMaster.lfxLamp.SetDbValue(tblFixtureMaster.lfxLamp.CurrentValue, System.DBNull.Value)
  602.         Rs("lfxLamp") = tblFixtureMaster.lfxLamp.DbValue
  603.  
  604.         ' lfxLocationID
  605.         tblFixtureMaster.lfxLocationID.SetDbValue(tblFixtureMaster.lfxLocationID.CurrentValue, System.DBNull.Value)
  606.         Rs("lfxLocationID") = tblFixtureMaster.lfxLocationID.DbValue
  607.  
  608.         ' lfxHangPos
  609.         tblFixtureMaster.lfxHangPos.SetDbValue(tblFixtureMaster.lfxHangPos.CurrentValue, System.DBNull.Value)
  610.         Rs("lfxHangPos") = tblFixtureMaster.lfxHangPos.DbValue
  611.  
  612.         ' lfxChannel
  613.         tblFixtureMaster.lfxChannel.SetDbValue(tblFixtureMaster.lfxChannel.CurrentValue, System.DBNull.Value)
  614.         Rs("lfxChannel") = tblFixtureMaster.lfxChannel.DbValue
  615.  
  616.         ' lfxNotes
  617.         tblFixtureMaster.lfxNotes.SetDbValue(tblFixtureMaster.lfxNotes.CurrentValue, System.DBNull.Value)
  618.         Rs("lfxNotes") = tblFixtureMaster.lfxNotes.DbValue
  619.  
  620.         ' Row Inserting event
  621.         bInsertRow = tblFixtureMaster.Row_Inserting(Rs)
  622.         If bInsertRow Then
  623.             Try    
  624.                 tblFixtureMaster.Insert(Rs)
  625.                 AddRow = True
  626.             Catch e As Exception
  627.                 If EW_DEBUG_ENABLED Then Throw
  628.                 Message = e.Message                
  629.                 AddRow = False
  630.             End Try
  631.         Else
  632.             If tblFixtureMaster.CancelMessage <> "" Then
  633.                 Message = tblFixtureMaster.CancelMessage
  634.                 tblFixtureMaster.CancelMessage = ""
  635.             Else
  636.                 Message = "Insert cancelled"
  637.             End If
  638.             AddRow = False
  639.         End If
  640.         If AddRow Then
  641.             LastInsertId = Conn.GetLastInsertId()
  642.             tblFixtureMaster.lfxID.DbValue = LastInsertId
  643.             Rs("lfxID") = tblFixtureMaster.lfxID.DbValue        
  644.  
  645.             ' Row Inserted event
  646.             tblFixtureMaster.Row_Inserted(Rs)
  647.         End If
  648.     End Function
  649.  
  650.         ' Page Load event
  651.         Public Sub Page_Load()
  652.  
  653.             'HttpContext.Current.Response.Write("Page Load")
  654.         End Sub
  655.  
  656.         ' Page Unload event
  657.         Public Sub Page_Unload()
  658.  
  659.             'HttpContext.Current.Response.Write("Page Unload")
  660.         End Sub
  661.  
  662.     ' Form Custom Validate event
  663.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  664.  
  665.         'Return error message in CustomError
  666.         Return True
  667.     End Function
  668.     End Class
  669.  
  670.     '
  671.     ' ASP.NET Page_Load event
  672.     '
  673.  
  674.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  675.         Response.Buffer = EW_RESPONSE_BUFFER
  676.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  677.  
  678.         ' Page init
  679.         tblFixtureMaster_add = New ctblFixtureMaster_add(Me)        
  680.         tblFixtureMaster_add.Page_Init()
  681.  
  682.         ' Page main processing
  683.         tblFixtureMaster_add.Page_Main()
  684.     End Sub
  685.  
  686.     '
  687.     ' ASP.NET Page_Unload event
  688.     '
  689.  
  690.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  691.  
  692.         ' Dispose page object
  693.         If tblFixtureMaster_add IsNot Nothing Then tblFixtureMaster_add.Dispose()
  694.     End Sub
  695. End Class
  696.