home *** CD-ROM | disk | FTP | other *** search
/ 66.142.0.142 / 66.142.0.142.tar / 66.142.0.142 / tblFixtureMasterlist.aspx.vb < prev    next >
Text File  |  2010-08-24  |  32KB  |  1,016 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 tblFixtureMasterlist
  12.     Inherits AspNetMaker7_tfpssnet
  13.  
  14.     ' Page object
  15.     Public tblFixtureMaster_list As ctblFixtureMaster_list
  16.  
  17.     '
  18.     ' Page Class
  19.     '
  20.     Class ctblFixtureMaster_list
  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 = "list"
  85.             m_PageObjName = "tblFixtureMaster_list"
  86.             m_PageObjTypeName = "ctblFixtureMaster_list"
  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.  
  98.             ' Initialize list options
  99.             ListOptions = New cListOptions
  100.         End Sub
  101.  
  102.         '
  103.         '  Subroutine Page_Init
  104.         '  - called before page main
  105.         '  - check Security
  106.         '  - set up response header
  107.         '  - call page load events
  108.         '
  109.         Public Sub Page_Init()
  110.             Security = New cAdvancedSecurity(Me)
  111.             If Not Security.IsLoggedIn() Then Security.AutoLogin()
  112.             If Not Security.IsLoggedIn() Then
  113.                 Security.SaveLastUrl()
  114.                 Page_Terminate("login.aspx")
  115.             End If
  116.  
  117.             ' Table Permission loading event
  118.             Security.TablePermission_Loading()
  119.             Security.LoadCurrentUserLevel(TableName)
  120.  
  121.             ' Table Permission loaded event
  122.             Security.TablePermission_Loaded()
  123.             If Not Security.CanList Then
  124.                 Security.SaveLastUrl()
  125.                 Page_Terminate("login.aspx")
  126.             End If
  127.  
  128.             ' User ID loading event
  129.             Security.UserID_Loading()
  130.             If Security.IsLoggedIn() Then Call Security.LoadUserID()
  131.  
  132.             ' User ID loaded event
  133.             Security.UserID_Loaded()
  134.             tblFixtureMaster.Export = ew_Get("export") ' Get export parameter
  135.             ParentPage.gsExport = tblFixtureMaster.Export ' Get export parameter, used in header
  136.             ParentPage.gsExportFile = tblFixtureMaster.TableVar ' Get export file, used in header
  137.  
  138.             ' Global page loading event (in ewglobal*.vb)
  139.             ParentPage.Page_Loading()
  140.  
  141.             ' Page load event, used in current page
  142.             Page_Load()
  143.         End Sub
  144.  
  145.         '
  146.         '  Class terminate
  147.         '  - clean up page object
  148.         '
  149.         Public Sub Dispose() Implements IDisposable.Dispose
  150.             Page_Terminate("")
  151.         End Sub
  152.  
  153.         '
  154.         '  Sub Page_Terminate
  155.         '  - called when exit page
  156.         '  - clean up connection and objects
  157.         '  - if URL specified, redirect to URL
  158.         '
  159.         Sub Page_Terminate(url As String)
  160.  
  161.             ' Page unload event, used in current page
  162.             Page_Unload()
  163.  
  164.             ' Global page unloaded event (in ewglobal*.vb)
  165.             ParentPage.Page_Unloaded()
  166.  
  167.             ' Close connection
  168.             Conn.Dispose()
  169.             Security = Nothing
  170.             tblFixtureMaster.Dispose()
  171.             tblEmployees.Dispose()
  172.             ListOptions = Nothing
  173.  
  174.             ' Go to URL if specified
  175.             If url <> "" Then
  176.                 HttpContext.Current.Response.Clear()
  177.                 HttpContext.Current.Response.Redirect(url)
  178.             End If
  179.         End Sub
  180.  
  181.     Public lDisplayRecs As Integer ' Number of display records
  182.  
  183.     Public lStartRec As Integer, lStopRec As Integer, lTotalRecs As Integer, lRecRange As Integer
  184.  
  185.     Public sSrchWhere As String
  186.  
  187.     Public lRecCnt As Integer
  188.  
  189.     Public lEditRowCnt As Integer
  190.  
  191.     Public lRowCnt As Integer, lRowIndex As Integer
  192.  
  193.     Public lOptionCnt As Integer
  194.  
  195.     Public lRecPerRow As Integer, lColCnt As Integer
  196.  
  197.     Public sDeleteConfirmMsg As String ' Delete confirm message
  198.  
  199.     Public sDbMasterFilter As String, sDbDetailFilter As String
  200.  
  201.     Public bMasterRecordExists As Boolean
  202.  
  203.     Public ListOptions As Object
  204.  
  205.     Public sMultiSelectKey As String
  206.  
  207.     Public x_ewPriv As Integer
  208.  
  209.     '
  210.     ' Page main processing
  211.     '
  212.     Public Sub Page_Main()
  213.         lDisplayRecs = 20
  214.         lRecRange = EW_PAGER_RANGE
  215.         lRecCnt = 0 ' Record count
  216.  
  217.         ' Search filters        
  218.         Dim sSrchAdvanced As String = "" ' Advanced search filter
  219.         Dim sSrchBasic As String = "" ' Basic search filter
  220.         Dim sFilter As String = ""
  221.         sSrchWhere = "" ' Search WHERE clause        
  222.  
  223.         ' Master/Detail
  224.         sDbMasterFilter = "" ' Master filter
  225.         sDbDetailFilter = "" ' Detail filter
  226.         If IsPageRequest Then ' Validate request
  227.  
  228.             ' Set up records per page dynamically
  229.             SetUpDisplayRecs()
  230.  
  231.             ' Handle reset command
  232.             ResetCmd()
  233.  
  234.             ' Get advanced search criteria
  235.             LoadSearchValues()
  236.             If ValidateSearch() Then
  237.                 sSrchAdvanced = AdvancedSearchWhere()
  238.             Else
  239.                 Message = ParentPage.gsSearchError
  240.             End If
  241.  
  242.             ' Get basic search criteria
  243.             If ParentPage.gsSearchError = "" Then
  244.                 sSrchBasic = BasicSearchWhere()
  245.             End If
  246.  
  247.             ' Set Up Sorting Order
  248.             SetUpSortOrder()
  249.         End If
  250.  
  251.         ' Restore display records
  252.         If (tblFixtureMaster.RecordsPerPage = -1 OrElse tblFixtureMaster.RecordsPerPage > 0) Then
  253.             lDisplayRecs = tblFixtureMaster.RecordsPerPage ' Restore from Session
  254.         Else
  255.             lDisplayRecs = 20 ' Load default
  256.         End If
  257.  
  258.         ' Load Sorting Order
  259.         LoadSortOrder()
  260.  
  261.         ' Build search criteria
  262.         If sSrchAdvanced <> "" Then
  263.             If sSrchWhere <> "" Then
  264.                 sSrchWhere = "(" & sSrchWhere & ") AND (" & sSrchAdvanced & ")"
  265.             Else
  266.                 sSrchWhere = sSrchAdvanced
  267.             End If
  268.         End If
  269.         If sSrchBasic <> "" Then
  270.             If sSrchWhere <> "" Then
  271.                 sSrchWhere = "(" & sSrchWhere & ") AND (" & sSrchBasic & ")"
  272.             Else
  273.                 sSrchWhere = sSrchBasic
  274.             End If
  275.         End If
  276.  
  277.         ' Recordset Searching event
  278.         tblFixtureMaster.Recordset_Searching(sSrchWhere)
  279.  
  280.         ' Save search criteria
  281.         If sSrchWhere <> "" Then
  282.             If sSrchBasic = "" Then ResetBasicSearchParms()
  283.             If sSrchAdvanced = "" Then ResetAdvancedSearchParms()
  284.             tblFixtureMaster.SearchWhere = sSrchWhere ' Save to Session
  285.             lStartRec = 1 ' Reset start record counter
  286.             tblFixtureMaster.StartRecordNumber = lStartRec
  287.         Else
  288.             RestoreSearchParms()
  289.         End If
  290.  
  291.         ' Build filter
  292.         sFilter = ""
  293.         If Not Security.CanList Then
  294.             sFilter = "(0=1)" ' Filter all records
  295.         End If
  296.         If sDbDetailFilter <> "" Then
  297.             If sFilter <> "" Then
  298.                 sFilter = "(" & sFilter & ") AND (" & sDbDetailFilter & ")"
  299.             Else
  300.                 sFilter = sDbDetailFilter
  301.             End If
  302.         End If
  303.         If sSrchWhere <> "" Then
  304.             If sFilter <> "" Then
  305.                 sFilter = "(" & sFilter & ") AND (" & sSrchWhere & ")"
  306.             Else
  307.                 sFilter = sSrchWhere
  308.             End If
  309.         End If
  310.  
  311.         ' Set up filter in Session
  312.         tblFixtureMaster.SessionWhere = sFilter
  313.         tblFixtureMaster.CurrentFilter = ""
  314.     End Sub
  315.  
  316.     '
  317.     ' Set up number of records displayed per page
  318.     '
  319.     Sub SetUpDisplayRecs()
  320.         Dim sWrk As String
  321.         sWrk = ew_Get(EW_TABLE_REC_PER_PAGE)
  322.         If sWrk <> "" Then
  323.             If IsNumeric(sWrk) Then
  324.                 lDisplayRecs = ew_ConvertToInt(sWrk)
  325.             Else
  326.                 If ew_SameText(sWrk, "all") Then ' Display all records
  327.                     lDisplayRecs = -1
  328.                 Else
  329.                     lDisplayRecs = 20 ' Non-numeric, load default
  330.                 End If
  331.             End If
  332.             tblFixtureMaster.RecordsPerPage = lDisplayRecs ' Save to Session
  333.  
  334.             ' Reset start position
  335.             lStartRec = 1
  336.             tblFixtureMaster.StartRecordNumber = lStartRec
  337.         End If
  338.     End Sub
  339.  
  340.     '
  341.     ' Return Advanced Search WHERE based on QueryString parameters
  342.     '
  343.     Function AdvancedSearchWhere() As String        
  344.         If Not Security.CanSearch Then Return ""
  345.         Dim sWhere As String = ""
  346.         BuildSearchSql(sWhere, tblFixtureMaster.lfxMFG, False) ' lfxMFG
  347.         BuildSearchSql(sWhere, tblFixtureMaster.lfxModelType, False) ' lfxModelType
  348.         BuildSearchSql(sWhere, tblFixtureMaster.lfxSerialNumber, False) ' lfxSerialNumber
  349.         BuildSearchSql(sWhere, tblFixtureMaster.lfxLamp, False) ' lfxLamp
  350.         BuildSearchSql(sWhere, tblFixtureMaster.lfxLocationID, False) ' lfxLocationID
  351.         BuildSearchSql(sWhere, tblFixtureMaster.lfxHangPos, False) ' lfxHangPos
  352.         BuildSearchSql(sWhere, tblFixtureMaster.lfxChannel, False) ' lfxChannel
  353.         BuildSearchSql(sWhere, tblFixtureMaster.lfxNotes, False) ' lfxNotes
  354.  
  355.         ' Set up search parm
  356.         If sWhere <> "" Then
  357.             SetSearchParm(tblFixtureMaster.lfxMFG) ' lfxMFG
  358.             SetSearchParm(tblFixtureMaster.lfxModelType) ' lfxModelType
  359.             SetSearchParm(tblFixtureMaster.lfxSerialNumber) ' lfxSerialNumber
  360.             SetSearchParm(tblFixtureMaster.lfxLamp) ' lfxLamp
  361.             SetSearchParm(tblFixtureMaster.lfxLocationID) ' lfxLocationID
  362.             SetSearchParm(tblFixtureMaster.lfxHangPos) ' lfxHangPos
  363.             SetSearchParm(tblFixtureMaster.lfxChannel) ' lfxChannel
  364.             SetSearchParm(tblFixtureMaster.lfxNotes) ' lfxNotes
  365.         End If
  366.         Return sWhere
  367.     End Function
  368.  
  369.     '
  370.     ' Build search SQL
  371.     '
  372.     Sub BuildSearchSql(ByRef Where As String, ByRef Fld As Object, MultiValue As Boolean)
  373.         Dim FldParm As String = Fld.FldVar.Substring(2)
  374.         Dim FldVal As String = Fld.AdvancedSearch.SearchValue
  375.         Dim FldOpr As String = Fld.AdvancedSearch.SearchOperator
  376.         Dim FldCond As String = Fld.AdvancedSearch.SearchCondition
  377.         Dim FldVal2 As String = Fld.AdvancedSearch.SearchValue2
  378.         Dim FldOpr2 As String = Fld.AdvancedSearch.SearchOperator2
  379.         Dim sWrk As String = ""
  380.         FldOpr = FldOpr.Trim().ToUpper()
  381.         If (FldOpr = "") Then FldOpr = "="
  382.         FldOpr2 = FldOpr2.Trim().ToUpper()
  383.         If FldOpr2 = "" Then FldOpr2 = "="
  384.         If EW_SEARCH_MULTI_VALUE_OPTION = 1 Then MultiValue = False
  385.         If FldOpr <> "LIKE" Then MultiValue = False
  386.         If FldOpr2 <> "LIKE" AndAlso FldVal2 <> "" Then MultiValue = False
  387.         If MultiValue Then
  388.             Dim sWrk1 As String, sWrk2 As String
  389.  
  390.             ' Field value 1
  391.             If FldVal <> "" Then
  392.                 sWrk1 = ew_GetMultiSearchSql(Fld, FldVal)
  393.             Else
  394.                 sWrk1 = ""
  395.             End If
  396.  
  397.             ' Field value 2
  398.             If FldVal2 <> "" AndAlso FldCond <> "" Then
  399.                 sWrk2 = ew_GetMultiSearchSql(Fld, FldVal2)
  400.             Else
  401.                 sWrk2 = ""
  402.             End If
  403.  
  404.             ' Build final SQL
  405.             sWrk = sWrk1
  406.             If sWrk2 <> "" Then
  407.                 If sWrk <> "" Then
  408.                     sWrk = "(" & sWrk & ") " & FldCond & " (" & sWrk2 & ")"
  409.                 Else
  410.                     sWrk = sWrk2
  411.                 End If
  412.             End If
  413.         Else
  414.             FldVal = ConvertSearchValue(Fld, FldVal)
  415.             FldVal2 = ConvertSearchValue(Fld, FldVal2)
  416.             sWrk = ew_GetSearchSql(Fld, FldVal, FldOpr, FldCond, FldVal2, FldOpr2)
  417.         End If
  418.         If sWrk <> "" Then
  419.             If Where <> "" Then Where = Where & " AND "
  420.             Where = Where & "(" & sWrk & ")"
  421.         End If
  422.     End Sub
  423.  
  424.     '
  425.     ' Set search parm
  426.     '
  427.     Sub SetSearchParm(ByRef Fld As Object)
  428.         Dim FldParm As String = Fld.FldVar.Substring(2)
  429.         tblFixtureMaster.SetAdvancedSearch("x_" & FldParm, Fld.AdvancedSearch.SearchValue)
  430.         tblFixtureMaster.SetAdvancedSearch("z_" & FldParm, Fld.AdvancedSearch.SearchOperator)
  431.         tblFixtureMaster.SetAdvancedSearch("v_" & FldParm, Fld.AdvancedSearch.SearchCondition)
  432.         tblFixtureMaster.SetAdvancedSearch("y_" & FldParm, Fld.AdvancedSearch.SearchValue2)
  433.         tblFixtureMaster.SetAdvancedSearch("w_" & FldParm, Fld.AdvancedSearch.SearchOperator2)
  434.     End Sub
  435.  
  436.     '
  437.     ' Convert search value
  438.     '
  439.     Function ConvertSearchValue(ByRef Fld As cField, FldVal As Object) As Object
  440.         If Fld.FldDataType = EW_DATATYPE_BOOLEAN Then
  441.             If ew_NotEmpty(FldVal) Then Return IIf(FldVal="1", "True", "False")
  442.         ElseIf Fld.FldDataType = EW_DATATYPE_DATE Then
  443.             If ew_NotEmpty(FldVal) Then Return ew_UnFormatDateTime(FldVal, Fld.FldDateTimeFormat)
  444.         End If
  445.         Return FldVal
  446.     End Function
  447.  
  448.     '
  449.     ' Return Basic Search SQL
  450.     '
  451.     Function BasicSearchSQL(Keyword As String) As String
  452.         Dim sKeyword As String, sSql As String = ""
  453.         sKeyword = ew_AdjustSql(Keyword)        
  454.         sSql = sSql & "[lfxMFG] LIKE '%" & sKeyword & "%' OR "
  455.         sSql = sSql & "[lfxModelType] LIKE '%" & sKeyword & "%' OR "
  456.         sSql = sSql & "[lfxSerialNumber] LIKE '%" & sKeyword & "%' OR "
  457.         sSql = sSql & "[lfxLamp] LIKE '%" & sKeyword & "%' OR "
  458.         sSql = sSql & "[lfxHangPos] LIKE '%" & sKeyword & "%' OR "
  459.         sSql = sSql & "[lfxNotes] LIKE '%" & sKeyword & "%' OR "
  460.         If sSql.EndsWith(" OR ") Then sSql = sSql.SubString(0, sSql.Length-4)
  461.         Return sSql
  462.     End Function
  463.  
  464.     '
  465.     ' Return Basic Search WHERE based on search keyword and type
  466.     '
  467.     Function BasicSearchWhere() As String
  468.         Dim sSearchStr As String = "", sSearchKeyword As String, sSearchType As String
  469.         Dim sSearch As String, arKeyword() As String, sKeyword As String
  470.         If Not Security.CanSearch Then Return ""
  471.         sSearchKeyword = ew_Get(EW_TABLE_BASIC_SEARCH)
  472.         sSearchType = ew_Get(EW_TABLE_BASIC_SEARCH_TYPE)
  473.         If sSearchKeyword <> "" Then
  474.             sSearch = sSearchKeyword.Trim()
  475.             If sSearchType <> "" Then
  476.                 While InStr(sSearch, "  ") > 0
  477.                     sSearch = sSearch.Replace("  ", " ")
  478.                 End While
  479.                 arKeyword = sSearch.Trim().Split(New Char() {" "c})
  480.                 For Each sKeyword In arKeyword
  481.                     If sSearchStr <> "" Then sSearchStr = sSearchStr & " " & sSearchType & " "
  482.                     sSearchStr = sSearchStr & "(" & BasicSearchSQL(sKeyword) & ")"
  483.                 Next
  484.             Else
  485.                 sSearchStr = BasicSearchSQL(sSearch)
  486.             End If
  487.         End If
  488.         If sSearchKeyword <> "" then
  489.             tblFixtureMaster.BasicSearchKeyword = sSearchKeyword
  490.             tblFixtureMaster.BasicSearchType = sSearchType
  491.         End If
  492.         Return sSearchStr
  493.     End Function
  494.  
  495.     '
  496.     ' Clear all search parameters
  497.     '
  498.     Sub ResetSearchParms()
  499.  
  500.         ' Clear search where
  501.         sSrchWhere = ""
  502.         tblFixtureMaster.SearchWhere = sSrchWhere
  503.  
  504.         ' Clear basic search parameters
  505.         ResetBasicSearchParms()
  506.  
  507.         ' Clear advanced search parameters
  508.         ResetAdvancedSearchParms()
  509.     End Sub
  510.  
  511.     '
  512.     ' Clear all basic search parameters
  513.     '
  514.     Sub ResetBasicSearchParms()
  515.  
  516.         ' Clear basic search parameters
  517.         tblFixtureMaster.BasicSearchKeyword = ""
  518.         tblFixtureMaster.BasicSearchType = ""
  519.     End Sub
  520.  
  521.     '
  522.     ' Clear all advanced search parameters
  523.     '
  524.     Sub ResetAdvancedSearchParms()
  525.         tblFixtureMaster.SetAdvancedSearch("x_lfxMFG", "")
  526.         tblFixtureMaster.SetAdvancedSearch("x_lfxModelType", "")
  527.         tblFixtureMaster.SetAdvancedSearch("x_lfxSerialNumber", "")
  528.         tblFixtureMaster.SetAdvancedSearch("x_lfxLamp", "")
  529.         tblFixtureMaster.SetAdvancedSearch("x_lfxLocationID", "")
  530.         tblFixtureMaster.SetAdvancedSearch("x_lfxHangPos", "")
  531.         tblFixtureMaster.SetAdvancedSearch("x_lfxChannel", "")
  532.         tblFixtureMaster.SetAdvancedSearch("x_lfxNotes", "")
  533.     End Sub
  534.  
  535.     '
  536.     ' Restore all search parameters
  537.     '
  538.     Sub RestoreSearchParms()
  539.         sSrchWhere = tblFixtureMaster.SearchWhere
  540.  
  541.         ' Restore advanced search settings
  542.         If ParentPage.gsSearchError = "" Then
  543.             RestoreAdvancedSearchParms()
  544.         End If
  545.     End Sub
  546.  
  547.     '
  548.     ' Restore all advanced search parameters
  549.     '
  550.     Sub RestoreAdvancedSearchParms()
  551.         tblFixtureMaster.lfxMFG.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxMFG")
  552.         tblFixtureMaster.lfxModelType.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxModelType")
  553.         tblFixtureMaster.lfxSerialNumber.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxSerialNumber")
  554.         tblFixtureMaster.lfxLamp.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxLamp")
  555.         tblFixtureMaster.lfxLocationID.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxLocationID")
  556.         tblFixtureMaster.lfxHangPos.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxHangPos")
  557.         tblFixtureMaster.lfxChannel.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxChannel")
  558.         tblFixtureMaster.lfxNotes.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxNotes")
  559.     End Sub
  560.  
  561.     '
  562.     ' Set up Sort parameters based on Sort Links clicked
  563.     '
  564.     Sub SetUpSortOrder()
  565.         Dim sOrderBy As String
  566.         Dim sSortField As String, sLastSort As String, sThisSort As String
  567.         Dim bCtrl As Boolean
  568.  
  569.         ' Check for Ctrl pressed
  570.         bCtrl = (ew_Get("ctrl") <> "")
  571.  
  572.         ' Check for an Order parameter
  573.         If ew_Get("order") <> "" Then
  574.             tblFixtureMaster.CurrentOrder = ew_Get("order")
  575.             tblFixtureMaster.CurrentOrderType = ew_Get("ordertype")
  576.             tblFixtureMaster.UpdateSort(tblFixtureMaster.lfxMFG, bCtrl) ' lfxMFG
  577.             tblFixtureMaster.UpdateSort(tblFixtureMaster.lfxModelType, bCtrl) ' lfxModelType
  578.             tblFixtureMaster.UpdateSort(tblFixtureMaster.lfxSerialNumber, bCtrl) ' lfxSerialNumber
  579.             tblFixtureMaster.UpdateSort(tblFixtureMaster.lfxLamp, bCtrl) ' lfxLamp
  580.             tblFixtureMaster.UpdateSort(tblFixtureMaster.lfxLocationID, bCtrl) ' lfxLocationID
  581.             tblFixtureMaster.UpdateSort(tblFixtureMaster.lfxHangPos, bCtrl) ' lfxHangPos
  582.             tblFixtureMaster.UpdateSort(tblFixtureMaster.lfxChannel, bCtrl) ' lfxChannel
  583.             tblFixtureMaster.StartRecordNumber = 1 ' Reset start position
  584.         End If
  585.     End Sub
  586.  
  587.     '
  588.     ' Load Sort Order parameters
  589.     '
  590.     Sub LoadSortOrder()
  591.         Dim sOrderBy As String
  592.         sOrderBy = tblFixtureMaster.SessionOrderBy ' Get order by from Session
  593.         If sOrderBy = "" Then
  594.             If tblFixtureMaster.SqlOrderBy <> "" Then
  595.                 sOrderBy = tblFixtureMaster.SqlOrderBy
  596.                 tblFixtureMaster.SessionOrderBy = sOrderBy
  597.             End If
  598.         End If
  599.     End Sub
  600.  
  601.     '
  602.     ' Reset command based on querystring parameter "cmd"
  603.     ' - reset: reset search parameters
  604.     ' - resetall: reset search and master/detail parameters
  605.     ' - resetsort: reset sort parameters
  606.     '
  607.     Sub ResetCmd()
  608.         Dim sCmd As String
  609.  
  610.         ' Get reset cmd
  611.         If ew_Get("cmd") <> "" Then
  612.             sCmd = ew_Get("cmd")
  613.  
  614.             ' Reset search criteria
  615.             If ew_SameText(sCmd, "reset") OrElse ew_SameText(sCmd, "resetall") Then
  616.                 ResetSearchParms()
  617.             End If
  618.  
  619.             ' Reset sort criteria
  620.             If ew_SameText(sCmd, "resetsort") Then
  621.                 Dim sOrderBy As String = ""
  622.                 tblFixtureMaster.SessionOrderBy = sOrderBy
  623.                 tblFixtureMaster.lfxMFG.Sort = ""
  624.                 tblFixtureMaster.lfxModelType.Sort = ""
  625.                 tblFixtureMaster.lfxSerialNumber.Sort = ""
  626.                 tblFixtureMaster.lfxLamp.Sort = ""
  627.                 tblFixtureMaster.lfxLocationID.Sort = ""
  628.                 tblFixtureMaster.lfxHangPos.Sort = ""
  629.                 tblFixtureMaster.lfxChannel.Sort = ""
  630.             End If
  631.  
  632.             ' Reset start position
  633.             lStartRec = 1
  634.             tblFixtureMaster.StartRecordNumber = lStartRec
  635.         End If
  636.     End Sub
  637.  
  638.     Public Pager As Object
  639.  
  640.     '
  641.     ' Set up Starting Record parameters
  642.     '
  643.     Sub SetUpStartRec()
  644.         Dim nPageNo As Integer
  645.  
  646.         ' Exit if lDisplayRecs = 0
  647.         If lDisplayRecs = 0 Then Exit Sub
  648.         If IsPageRequest Then ' Validate request
  649.  
  650.             ' Check for a "start" parameter
  651.             If ew_Get(EW_TABLE_START_REC) <> "" AndAlso IsNumeric(ew_Get(EW_TABLE_START_REC)) Then
  652.                 lStartRec = ew_ConvertToInt(ew_Get(EW_TABLE_START_REC))
  653.                 tblFixtureMaster.StartRecordNumber = lStartRec
  654.             ElseIf ew_Get(EW_TABLE_PAGE_NO) <> "" AndAlso IsNumeric(ew_Get(EW_TABLE_PAGE_NO)) Then
  655.                 nPageNo = ew_ConvertToInt(ew_Get(EW_TABLE_PAGE_NO))
  656.                 lStartRec = (nPageNo-1)*lDisplayRecs+1
  657.                 If lStartRec <= 0 Then
  658.                     lStartRec = 1
  659.                 ElseIf lStartRec >= ((lTotalRecs-1)\lDisplayRecs)*lDisplayRecs+1 Then
  660.                     lStartRec = ((lTotalRecs-1)\lDisplayRecs)*lDisplayRecs+1
  661.                 End If
  662.                 tblFixtureMaster.StartRecordNumber = lStartRec
  663.             End If
  664.         End If
  665.         lStartRec = tblFixtureMaster.StartRecordNumber
  666.  
  667.         ' Check if correct start record counter
  668.         If lStartRec <= 0 Then ' Avoid invalid start record counter
  669.             lStartRec = 1 ' Reset start record counter
  670.             tblFixtureMaster.StartRecordNumber = lStartRec
  671.         ElseIf lStartRec > lTotalRecs Then ' Avoid starting record > total records
  672.             lStartRec = ((lTotalRecs-1)\lDisplayRecs)*lDisplayRecs+1 ' Point to last page first record
  673.             tblFixtureMaster.StartRecordNumber = lStartRec
  674.         ElseIf (lStartRec-1) Mod lDisplayRecs <> 0 Then
  675.             lStartRec = ((lStartRec-1)\lDisplayRecs)*lDisplayRecs+1 ' Point to page boundary
  676.             tblFixtureMaster.StartRecordNumber = lStartRec
  677.         End If
  678.     End Sub
  679.  
  680.     '
  681.     ' Load default values
  682.     '
  683.     Sub LoadDefaultValues()
  684.     End Sub
  685.  
  686.     '
  687.     '  Load search values for validation
  688.     '
  689.     Sub LoadSearchValues()
  690.         tblFixtureMaster.lfxMFG.AdvancedSearch.SearchValue = ew_Get("x_lfxMFG")
  691.         tblFixtureMaster.lfxMFG.AdvancedSearch.SearchOperator = ew_Get("z_lfxMFG")
  692.         tblFixtureMaster.lfxModelType.AdvancedSearch.SearchValue = ew_Get("x_lfxModelType")
  693.         tblFixtureMaster.lfxModelType.AdvancedSearch.SearchOperator = ew_Get("z_lfxModelType")
  694.         tblFixtureMaster.lfxSerialNumber.AdvancedSearch.SearchValue = ew_Get("x_lfxSerialNumber")
  695.         tblFixtureMaster.lfxSerialNumber.AdvancedSearch.SearchOperator = ew_Get("z_lfxSerialNumber")
  696.         tblFixtureMaster.lfxLamp.AdvancedSearch.SearchValue = ew_Get("x_lfxLamp")
  697.         tblFixtureMaster.lfxLamp.AdvancedSearch.SearchOperator = ew_Get("z_lfxLamp")
  698.         tblFixtureMaster.lfxLocationID.AdvancedSearch.SearchValue = ew_Get("x_lfxLocationID")
  699.         tblFixtureMaster.lfxLocationID.AdvancedSearch.SearchOperator = ew_Get("z_lfxLocationID")
  700.         tblFixtureMaster.lfxHangPos.AdvancedSearch.SearchValue = ew_Get("x_lfxHangPos")
  701.         tblFixtureMaster.lfxHangPos.AdvancedSearch.SearchOperator = ew_Get("z_lfxHangPos")
  702.         tblFixtureMaster.lfxChannel.AdvancedSearch.SearchValue = ew_Get("x_lfxChannel")
  703.         tblFixtureMaster.lfxChannel.AdvancedSearch.SearchOperator = ew_Get("z_lfxChannel")
  704.         tblFixtureMaster.lfxNotes.AdvancedSearch.SearchValue = ew_Get("x_lfxNotes")
  705.         tblFixtureMaster.lfxNotes.AdvancedSearch.SearchOperator = ew_Get("z_lfxNotes")
  706.     End Sub
  707.  
  708.     '
  709.     ' Load recordset
  710.     '
  711.     Function LoadRecordset() As OleDbDataReader
  712.  
  713.         ' Recordset Selecting event
  714.         tblFixtureMaster.Recordset_Selecting(tblFixtureMaster.CurrentFilter)
  715.  
  716.         ' Load list page SQL
  717.         Dim sSql As String = tblFixtureMaster.ListSQL
  718.  
  719.         ' Write SQL for debug
  720.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  721.  
  722.         ' Count
  723.         lTotalRecs = -1        
  724.         Try            
  725.             If sSql.StartsWith("SELECT * FROM ", StringComparison.InvariantCultureIgnoreCase) AndAlso _                
  726.                 ew_Empty(tblFixtureMaster.SqlGroupBy) AndAlso _
  727.                 ew_Empty(tblFixtureMaster.SqlHaving) Then
  728.                 Dim sCntSql As String = tblFixtureMaster.SelectCountSQL
  729.  
  730.                 ' Write SQL for debug
  731.                 If EW_DEBUG_ENABLED Then ew_Write("<br>" & sCntSql)
  732.                 lTotalRecs = Conn.ExecuteScalar(sCntSql)
  733.             End If            
  734.         Catch
  735.         End Try
  736.  
  737.         ' Load recordset
  738.         Dim Rs As OleDbDataReader = Conn.GetDataReader(sSql)
  739.         If lTotalRecs < 0 AndAlso Rs.HasRows Then
  740.             lTotalRecs = 0
  741.             While Rs.Read()
  742.                 lTotalRecs = lTotalRecs + 1
  743.             End While
  744.             Rs.Close()        
  745.             Rs = Conn.GetDataReader(sSql)
  746.         End If
  747.  
  748.         ' Recordset Selected event
  749.         tblFixtureMaster.Recordset_Selected(Rs)
  750.         Return Rs
  751.     End Function
  752.  
  753.     '
  754.     ' Load row based on key values
  755.     '
  756.     Function LoadRow() As Boolean
  757.         Dim RsRow As OleDbDataReader
  758.         Dim sFilter As String = tblFixtureMaster.KeyFilter
  759.  
  760.         ' Row Selecting event
  761.         tblFixtureMaster.Row_Selecting(sFilter)
  762.  
  763.         ' Load SQL based on filter
  764.         tblFixtureMaster.CurrentFilter = sFilter
  765.         Dim sSql As String = tblFixtureMaster.SQL
  766.  
  767.         ' Write SQL for debug
  768.         If EW_DEBUG_ENABLED Then ew_Write(sSql)
  769.         Try
  770.             RsRow = Conn.GetTempDataReader(sSql)    
  771.             If Not RsRow.Read() Then
  772.                 Return False
  773.             Else                
  774.                 LoadRowValues(RsRow) ' Load row values
  775.  
  776.                 ' Row Selected event
  777.                 tblFixtureMaster.Row_Selected(RsRow)
  778.                 Return True    
  779.             End If
  780.         Catch
  781.             If EW_DEBUG_ENABLED Then Throw
  782.             Return False
  783.         Finally
  784.             Conn.CloseTempDataReader()
  785.         End Try
  786.     End Function
  787.  
  788.     '
  789.     ' Load row values from recordset
  790.     '
  791.     Sub LoadRowValues(ByRef RsRow As OleDbDataReader)
  792.         tblFixtureMaster.lfxID.DbValue = RsRow("lfxID")
  793.         tblFixtureMaster.lfxMFG.DbValue = RsRow("lfxMFG")
  794.         tblFixtureMaster.lfxModelType.DbValue = RsRow("lfxModelType")
  795.         tblFixtureMaster.lfxSerialNumber.DbValue = RsRow("lfxSerialNumber")
  796.         tblFixtureMaster.lfxLamp.DbValue = RsRow("lfxLamp")
  797.         tblFixtureMaster.lfxLocationID.DbValue = RsRow("lfxLocationID")
  798.         tblFixtureMaster.lfxHangPos.DbValue = RsRow("lfxHangPos")
  799.         tblFixtureMaster.lfxChannel.DbValue = RsRow("lfxChannel")
  800.         tblFixtureMaster.lfxNotes.DbValue = RsRow("lfxNotes")
  801.     End Sub
  802.  
  803.     '
  804.     ' Render row values based on field settings
  805.     '
  806.     Sub RenderRow()
  807.  
  808.         ' Row Rendering event
  809.         tblFixtureMaster.Row_Rendering()
  810.  
  811.         '
  812.         '  Common render codes for all row types
  813.         '
  814.         ' lfxMFG
  815.  
  816.         tblFixtureMaster.lfxMFG.CellCssStyle = ""
  817.         tblFixtureMaster.lfxMFG.CellCssClass = ""
  818.  
  819.         ' lfxModelType
  820.         tblFixtureMaster.lfxModelType.CellCssStyle = ""
  821.         tblFixtureMaster.lfxModelType.CellCssClass = ""
  822.  
  823.         ' lfxSerialNumber
  824.         tblFixtureMaster.lfxSerialNumber.CellCssStyle = ""
  825.         tblFixtureMaster.lfxSerialNumber.CellCssClass = ""
  826.  
  827.         ' lfxLamp
  828.         tblFixtureMaster.lfxLamp.CellCssStyle = ""
  829.         tblFixtureMaster.lfxLamp.CellCssClass = ""
  830.  
  831.         ' lfxLocationID
  832.         tblFixtureMaster.lfxLocationID.CellCssStyle = ""
  833.         tblFixtureMaster.lfxLocationID.CellCssClass = ""
  834.  
  835.         ' lfxHangPos
  836.         tblFixtureMaster.lfxHangPos.CellCssStyle = ""
  837.         tblFixtureMaster.lfxHangPos.CellCssClass = ""
  838.  
  839.         ' lfxChannel
  840.         tblFixtureMaster.lfxChannel.CellCssStyle = ""
  841.         tblFixtureMaster.lfxChannel.CellCssClass = ""
  842.  
  843.         '
  844.         '  View  Row
  845.         '
  846.  
  847.         If tblFixtureMaster.RowType = EW_ROWTYPE_VIEW Then ' View row
  848.  
  849.             ' lfxMFG
  850.             tblFixtureMaster.lfxMFG.ViewValue = tblFixtureMaster.lfxMFG.CurrentValue
  851.             tblFixtureMaster.lfxMFG.CssStyle = ""
  852.             tblFixtureMaster.lfxMFG.CssClass = ""
  853.             tblFixtureMaster.lfxMFG.ViewCustomAttributes = ""
  854.  
  855.             ' lfxModelType
  856.             tblFixtureMaster.lfxModelType.ViewValue = tblFixtureMaster.lfxModelType.CurrentValue
  857.             tblFixtureMaster.lfxModelType.CssStyle = ""
  858.             tblFixtureMaster.lfxModelType.CssClass = ""
  859.             tblFixtureMaster.lfxModelType.ViewCustomAttributes = ""
  860.  
  861.             ' lfxSerialNumber
  862.             tblFixtureMaster.lfxSerialNumber.ViewValue = tblFixtureMaster.lfxSerialNumber.CurrentValue
  863.             tblFixtureMaster.lfxSerialNumber.CssStyle = ""
  864.             tblFixtureMaster.lfxSerialNumber.CssClass = ""
  865.             tblFixtureMaster.lfxSerialNumber.ViewCustomAttributes = ""
  866.  
  867.             ' lfxLamp
  868.             tblFixtureMaster.lfxLamp.ViewValue = tblFixtureMaster.lfxLamp.CurrentValue
  869.             tblFixtureMaster.lfxLamp.CssStyle = ""
  870.             tblFixtureMaster.lfxLamp.CssClass = ""
  871.             tblFixtureMaster.lfxLamp.ViewCustomAttributes = ""
  872.  
  873.             ' lfxLocationID
  874.             If ew_NotEmpty(tblFixtureMaster.lfxLocationID.CurrentValue) Then
  875.                 sSqlWrk = "SELECT [locDescription] FROM [tblLocations] WHERE [locID] = " & ew_AdjustSql(tblFixtureMaster.lfxLocationID.CurrentValue) & ""
  876.                 sSqlWrk = sSqlWrk & " AND (" & "[locLighting]=True" & ")"
  877.                 sSqlWrk = sSqlWrk & " ORDER BY [locDescription] "
  878.                 RsWrk = Conn.GetTempDataReader(sSqlWrk)
  879.                 If RsWrk.Read() Then
  880.                     tblFixtureMaster.lfxLocationID.ViewValue = RsWrk("locDescription")
  881.                 Else
  882.                     tblFixtureMaster.lfxLocationID.ViewValue = tblFixtureMaster.lfxLocationID.CurrentValue
  883.                 End If
  884.                 Conn.CloseTempDataReader()
  885.             Else
  886.                 tblFixtureMaster.lfxLocationID.ViewValue = System.DBNull.Value
  887.             End If
  888.             tblFixtureMaster.lfxLocationID.CssStyle = ""
  889.             tblFixtureMaster.lfxLocationID.CssClass = ""
  890.             tblFixtureMaster.lfxLocationID.ViewCustomAttributes = ""
  891.  
  892.             ' lfxHangPos
  893.             tblFixtureMaster.lfxHangPos.ViewValue = tblFixtureMaster.lfxHangPos.CurrentValue
  894.             tblFixtureMaster.lfxHangPos.CssStyle = ""
  895.             tblFixtureMaster.lfxHangPos.CssClass = ""
  896.             tblFixtureMaster.lfxHangPos.ViewCustomAttributes = ""
  897.  
  898.             ' lfxChannel
  899.             tblFixtureMaster.lfxChannel.ViewValue = tblFixtureMaster.lfxChannel.CurrentValue
  900.             tblFixtureMaster.lfxChannel.CssStyle = ""
  901.             tblFixtureMaster.lfxChannel.CssClass = ""
  902.             tblFixtureMaster.lfxChannel.ViewCustomAttributes = ""
  903.  
  904.             ' View refer script
  905.             ' lfxMFG
  906.  
  907.             tblFixtureMaster.lfxMFG.HrefValue = ""
  908.  
  909.             ' lfxModelType
  910.             tblFixtureMaster.lfxModelType.HrefValue = ""
  911.  
  912.             ' lfxSerialNumber
  913.             tblFixtureMaster.lfxSerialNumber.HrefValue = ""
  914.  
  915.             ' lfxLamp
  916.             tblFixtureMaster.lfxLamp.HrefValue = ""
  917.  
  918.             ' lfxLocationID
  919.             tblFixtureMaster.lfxLocationID.HrefValue = ""
  920.  
  921.             ' lfxHangPos
  922.             tblFixtureMaster.lfxHangPos.HrefValue = ""
  923.  
  924.             ' lfxChannel
  925.             tblFixtureMaster.lfxChannel.HrefValue = ""
  926.         End If
  927.  
  928.         ' Row Rendered event
  929.         tblFixtureMaster.Row_Rendered()
  930.     End Sub
  931.  
  932.     '
  933.     ' Validate search
  934.     '
  935.     Function ValidateSearch() As Boolean
  936.  
  937.         ' Initialize
  938.         ParentPage.gsSearchError = ""
  939.  
  940.         ' Check if validation required
  941.         If Not EW_SERVER_VALIDATE Then Return True ' Skip
  942.  
  943.         ' Return validate result    
  944.         Dim Valid As Boolean = (ParentPage.gsSearchError = "")
  945.  
  946.         ' Form_CustomValidate event
  947.         Dim sFormCustomError As String = ""
  948.         Valid = Valid And Form_CustomValidate(sFormCustomError)
  949.         If sFormCustomError <> "" Then
  950.             If ParentPage.gsSearchError <> "" Then ParentPage.gsSearchError = ParentPage.gsSearchError & "<br />"
  951.             ParentPage.gsSearchError = ParentPage.gsSearchError & sFormCustomError
  952.         End If
  953.         Return Valid
  954.     End Function
  955.  
  956.     '
  957.     ' Load advanced search
  958.     '
  959.     Sub LoadAdvancedSearch()
  960.         tblFixtureMaster.lfxMFG.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxMFG")
  961.         tblFixtureMaster.lfxModelType.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxModelType")
  962.         tblFixtureMaster.lfxSerialNumber.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxSerialNumber")
  963.         tblFixtureMaster.lfxLamp.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxLamp")
  964.         tblFixtureMaster.lfxLocationID.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxLocationID")
  965.         tblFixtureMaster.lfxHangPos.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxHangPos")
  966.         tblFixtureMaster.lfxChannel.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxChannel")
  967.         tblFixtureMaster.lfxNotes.AdvancedSearch.SearchValue = tblFixtureMaster.GetAdvancedSearch("x_lfxNotes")
  968.     End Sub
  969.  
  970.         ' Page Load event
  971.         Public Sub Page_Load()
  972.  
  973.             'HttpContext.Current.Response.Write("Page Load")
  974.         End Sub
  975.  
  976.         ' Page Unload event
  977.         Public Sub Page_Unload()
  978.  
  979.             'HttpContext.Current.Response.Write("Page Unload")
  980.         End Sub
  981.  
  982.     ' Form Custom Validate event
  983.     Public Function Form_CustomValidate(ByRef CustomError As String) As Boolean
  984.  
  985.         'Return error message in CustomError
  986.         Return True
  987.     End Function
  988.     End Class
  989.  
  990.     '
  991.     ' ASP.NET Page_Load event
  992.     '
  993.  
  994.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  995.         Response.Buffer = EW_RESPONSE_BUFFER
  996.         Response.Cache.SetCacheability(HttpCacheability.NoCache)
  997.  
  998.         ' Page init
  999.         tblFixtureMaster_list = New ctblFixtureMaster_list(Me)        
  1000.         tblFixtureMaster_list.Page_Init()
  1001.  
  1002.         ' Page main processing
  1003.         tblFixtureMaster_list.Page_Main()
  1004.     End Sub
  1005.  
  1006.     '
  1007.     ' ASP.NET Page_Unload event
  1008.     '
  1009.  
  1010.     Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
  1011.  
  1012.         ' Dispose page object
  1013.         If tblFixtureMaster_list IsNot Nothing Then tblFixtureMaster_list.Dispose()
  1014.     End Sub
  1015. End Class
  1016.