
' This file implements the TableControl, TableControlRow, and RecordControl classes for the 
' ShowEmployeesTable2.aspx page.  The Row or RecordControl classes are the 
' ideal place to add code customizations. For example, you can override the LoadData, 
' CreateWhereClause, DataBind, SaveData, GetUIData, and Validate methods.

#Region "Imports statements"

Option Strict On
Imports Microsoft.VisualBasic
Imports BaseClasses.Web.UI.WebControls
Imports System
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports BaseClasses
Imports BaseClasses.Data
Imports BaseClasses.Utils
Imports ReportTools.ReportCreator
Imports ReportTools.Shared

  
        
Imports UseDAL.Business
Imports UseDAL.Data
        

#End Region

  
Namespace UseDAL.UI.Controls.ShowEmployeesTable2

#Region "Section 1: Place your customizations here."

    
Public Class EmployeesTableControlRow
        Inherits BaseEmployeesTableControlRow
        ' The BaseEmployeesTableControlRow implements code for a ROW within the
        ' the EmployeesTableControl table.  The BaseEmployeesTableControlRow implements the DataBind and SaveData methods.
        ' The loading of data is actually performed by the LoadData method in the base class of EmployeesTableControl.

        ' This is the ideal place to add your code customizations. For example, you can override the DataBind, 
        ' SaveData, GetUIData, and Validate methods.
        

End Class

  

Public Class EmployeesTableControl
        Inherits BaseEmployeesTableControl

        ' The BaseEmployeesTableControl class implements the LoadData, DataBind, CreateWhereClause
        ' and other methods to load and display the data in a table control.

        ' This is the ideal place to add your code customizations. You can override the LoadData and CreateWhereClause,
        ' The EmployeesTableControlRow class offers another place where you can customize
        ' the DataBind, GetUIData, SaveData and Validate methods specific to each row displayed on the table.

End Class

  
Public Class OrdersTableControlRow
        Inherits BaseOrdersTableControlRow
        ' The BaseOrdersTableControlRow implements code for a ROW within the
        ' the OrdersTableControl table.  The BaseOrdersTableControlRow implements the DataBind and SaveData methods.
        ' The loading of data is actually performed by the LoadData method in the base class of OrdersTableControl.

        ' This is the ideal place to add your code customizations. For example, you can override the DataBind, 
        ' SaveData, GetUIData, and Validate methods.
        

End Class

  

Public Class OrdersTableControl
        Inherits BaseOrdersTableControl

        ' The BaseOrdersTableControl class implements the LoadData, DataBind, CreateWhereClause
        ' and other methods to load and display the data in a table control.

        ' This is the ideal place to add your code customizations. You can override the LoadData and CreateWhereClause,
        ' The OrdersTableControlRow class offers another place where you can customize
        ' the DataBind, GetUIData, SaveData and Validate methods specific to each row displayed on the table.

End Class

  

#End Region

  

#Region "Section 2: Do not modify this section."
    
    
' Base class for the EmployeesTableControlRow control on the ShowEmployeesTable2 page.
' Do not modify this class. Instead override any method in EmployeesTableControlRow.
Public Class BaseEmployeesTableControlRow
        Inherits UseDAL.UI.BaseApplicationRecordControl

        '  To customize, override this method in EmployeesTableControlRow.
      Protected Overridable Sub Control_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init

      
      
            ' Register the event handlers.
        
              AddHandler Me.EmployeesRowCopyButton.Click, AddressOf EmployeesRowCopyButton_Click
              
              AddHandler Me.EmployeesRowDeleteButton.Click, AddressOf EmployeesRowDeleteButton_Click
              
              AddHandler Me.EmployeesRowEditButton.Click, AddressOf EmployeesRowEditButton_Click
              
              AddHandler Me.EmployeesRowViewButton.Click, AddressOf EmployeesRowViewButton_Click
              
        End Sub

        '  To customize, override this method in EmployeesTableControlRow.
        Protected Overridable Sub Control_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
                ' Show confirmation message on Click
                Me.EmployeesRowDeleteButton.Attributes.Add("onClick", "return (confirm('" & (CType(Me.Page,BaseApplicationPage)).GetResourceValue("DeleteRecordConfirm", "UseDAL") & "'));")
    
    End Sub

        ' Read data from database.  To customize, override this method in EmployeesTableControlRow.
        Public Overridable Sub LoadData()        
        
        Dim ordersTableControlObj As OrdersTableControl= DirectCast(MiscUtils.FindControlRecursively(Me, "OrdersTableControl"), OrdersTableControl)
        ordersTableControlObj.DataChanged = True
      
            If Not Me.RecordUniqueId Is Nothing AndAlso Me.RecordUniqueId.Trim <> "" Then
                Me.DataSource = EmployeesTable.GetRecord(Me.RecordUniqueId, True)
                Return
            End If
        
            ' Since this is a row in the table, the data for this row is loaded by the 
            ' LoadData method of the BaseEmployeesTableControl when the data for the entire
            ' table is loaded.
            Me.DataSource = New EmployeesRecord()
          
        End Sub

        ' Populate the UI controls using the DataSource.  To customize, override this method in EmployeesTableControlRow.
        Public Overrides Sub DataBind()

            MyBase.DataBind()

            ' Make sure that the DataSource is initialized.
            If Me.DataSource Is Nothing Then
                Return
            End If
        
      
            ' For each field, check to see if a value is specified.  If a value is specified,
            ' then format the value for display.  If no value is specified, use the default value (formatted).

        
            If Me.DataSource.AddressSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.Address)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.Address.Text = formattedValue
              
            Else      
                Me.Address.Text = EmployeesTable.Address.Format(EmployeesTable.Address.DefaultValue)
              
            End If
                    
            If Me.Address.Text Is Nothing _
                OrElse Me.Address.Text.Trim() = "" Then
                Me.Address.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.BirthDateSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.BirthDate)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.BirthDate.Text = formattedValue
              
            Else      
                Me.BirthDate.Text = EmployeesTable.BirthDate.Format(EmployeesTable.BirthDate.DefaultValue)
              
            End If
                    
            If Me.BirthDate.Text Is Nothing _
                OrElse Me.BirthDate.Text.Trim() = "" Then
                Me.BirthDate.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.CitySpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.City)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.City.Text = formattedValue
              
            Else      
                Me.City.Text = EmployeesTable.City.Format(EmployeesTable.City.DefaultValue)
              
            End If
                    
            If Me.City.Text Is Nothing _
                OrElse Me.City.Text.Trim() = "" Then
                Me.City.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.CountrySpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.Country)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.Country.Text = formattedValue
              
            Else      
                Me.Country.Text = EmployeesTable.Country.Format(EmployeesTable.Country.DefaultValue)
              
            End If
                    
            If Me.Country.Text Is Nothing _
                OrElse Me.Country.Text.Trim() = "" Then
                Me.Country.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.CreatedBySpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.CreatedBy)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                    Dim popupThreshold as Integer = CType(100, Integer)
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If
                                
                    If Len(formattedValue) >= popupThreshold Then 
                        formattedValue= "<a onclick = 'gPersist=true;' onmouseout='detailRolloverPopupClose();' " _
                            & "onmouseover='SaveMousePosition(event); delayRolloverPopup(""PageMethods.GetRecordFieldValue(\""UseDAL.Business.EmployeesTable, App_Code\"",\""" _
                            & (HttpUtility.UrlEncode(Me.DataSource.GetID.ToString())).Replace("\","\\\\") & "\"", \""CreatedBy\"", \""Created By\"", false, 200," _
                            & " 300, true, PopupDisplayWindowCallBackWith20);"", 500);'>" &  NetUtils.EncodeStringForHtmlDisplay(formattedValue.Substring(0, maxLength))
                        If (maxLength = CType(100, Integer)) Then
                            formattedValue = formattedValue & "..." & "</a>"
                        Else
                            formattedValue = formattedValue & "</a>"
                            
                        End If
                    Else
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    End If
                End If  
                
                Me.CreatedBy.Text = formattedValue
              
            Else      
                Me.CreatedBy.Text = EmployeesTable.CreatedBy.Format(EmployeesTable.CreatedBy.DefaultValue)
              
            End If
                    
            If Me.CreatedBy.Text Is Nothing _
                OrElse Me.CreatedBy.Text.Trim() = "" Then
                Me.CreatedBy.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.CreatedOnSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.CreatedOn)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.CreatedOn.Text = formattedValue
              
            Else      
                Me.CreatedOn.Text = EmployeesTable.CreatedOn.Format(EmployeesTable.CreatedOn.DefaultValue)
              
            End If
                    
            If Me.CreatedOn.Text Is Nothing _
                OrElse Me.CreatedOn.Text.Trim() = "" Then
                Me.CreatedOn.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ExtensionSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.Extension)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.Extension.Text = formattedValue
              
            Else      
                Me.Extension.Text = EmployeesTable.Extension.Format(EmployeesTable.Extension.DefaultValue)
              
            End If
                    
            If Me.Extension.Text Is Nothing _
                OrElse Me.Extension.Text.Trim() = "" Then
                Me.Extension.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.FirstNameSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.FirstName)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.FirstName.Text = formattedValue
              
            Else      
                Me.FirstName.Text = EmployeesTable.FirstName.Format(EmployeesTable.FirstName.DefaultValue)
              
            End If
                    
            If Me.FirstName.Text Is Nothing _
                OrElse Me.FirstName.Text.Trim() = "" Then
                Me.FirstName.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.HireDateSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.HireDate)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.HireDate.Text = formattedValue
              
            Else      
                Me.HireDate.Text = EmployeesTable.HireDate.Format(EmployeesTable.HireDate.DefaultValue)
              
            End If
                    
            If Me.HireDate.Text Is Nothing _
                OrElse Me.HireDate.Text.Trim() = "" Then
                Me.HireDate.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.HomePhoneSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.HomePhone)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.HomePhone.Text = formattedValue
              
            Else      
                Me.HomePhone.Text = EmployeesTable.HomePhone.Format(EmployeesTable.HomePhone.DefaultValue)
              
            End If
                    
            If Me.HomePhone.Text Is Nothing _
                OrElse Me.HomePhone.Text.Trim() = "" Then
                Me.HomePhone.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.LastNameSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.LastName)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.LastName.Text = formattedValue
              
            Else      
                Me.LastName.Text = EmployeesTable.LastName.Format(EmployeesTable.LastName.DefaultValue)
              
            End If
                    
            If Me.LastName.Text Is Nothing _
                OrElse Me.LastName.Text.Trim() = "" Then
                Me.LastName.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.LastUpdatedBySpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.LastUpdatedBy)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                    Dim popupThreshold as Integer = CType(100, Integer)
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If
                                
                    If Len(formattedValue) >= popupThreshold Then 
                        formattedValue= "<a onclick = 'gPersist=true;' onmouseout='detailRolloverPopupClose();' " _
                            & "onmouseover='SaveMousePosition(event); delayRolloverPopup(""PageMethods.GetRecordFieldValue(\""UseDAL.Business.EmployeesTable, App_Code\"",\""" _
                            & (HttpUtility.UrlEncode(Me.DataSource.GetID.ToString())).Replace("\","\\\\") & "\"", \""LastUpdatedBy\"", \""Last Updated By\"", false, 200," _
                            & " 300, true, PopupDisplayWindowCallBackWith20);"", 500);'>" &  NetUtils.EncodeStringForHtmlDisplay(formattedValue.Substring(0, maxLength))
                        If (maxLength = CType(100, Integer)) Then
                            formattedValue = formattedValue & "..." & "</a>"
                        Else
                            formattedValue = formattedValue & "</a>"
                            
                        End If
                    Else
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    End If
                End If  
                
                Me.LastUpdatedBy.Text = formattedValue
              
            Else      
                Me.LastUpdatedBy.Text = EmployeesTable.LastUpdatedBy.Format(EmployeesTable.LastUpdatedBy.DefaultValue)
              
            End If
                    
            If Me.LastUpdatedBy.Text Is Nothing _
                OrElse Me.LastUpdatedBy.Text.Trim() = "" Then
                Me.LastUpdatedBy.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.LastUpdatedOnSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.LastUpdatedOn)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.LastUpdatedOn.Text = formattedValue
              
            Else      
                Me.LastUpdatedOn.Text = EmployeesTable.LastUpdatedOn.Format(EmployeesTable.LastUpdatedOn.DefaultValue)
              
            End If
                    
            If Me.LastUpdatedOn.Text Is Nothing _
                OrElse Me.LastUpdatedOn.Text.Trim() = "" Then
                Me.LastUpdatedOn.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.NotesSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.Notes)
                If Not formattedValue is Nothing Then
                    Dim popupThreshold as Integer = CType(100, Integer)
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                         
                        formattedValue = HttpUtility.HtmlEncode(formattedValue) 
                    End If
                                
                    If Len(formattedValue) >= popupThreshold Then 
                        formattedValue= "<a onclick = 'gPersist=true;' onmouseout='detailRolloverPopupClose();' " _
                            & "onmouseover='SaveMousePosition(event); delayRolloverPopup(""PageMethods.GetRecordFieldValue(\""UseDAL.Business.EmployeesTable, App_Code\"",\""" _
                            & (HttpUtility.UrlEncode(Me.DataSource.GetID.ToString())).Replace("\","\\\\") & "\"", \""Notes\"", \""Notes\"", false, 200," _
                            & " 300, true, PopupDisplayWindowCallBackWith20);"", 500);'>" &  NetUtils.EncodeStringForHtmlDisplay(formattedValue.Substring(0, maxLength))
                        If (maxLength = CType(100, Integer)) Then
                            formattedValue = formattedValue & "..." & "</a>"
                        Else
                            formattedValue = formattedValue & "</a>"
                            
                            formattedValue = "<table border=""0"" cellpadding=""0"" cellspacing=""0""><tr><td>" & formattedValue & "</td></tr></table>"
                        End If
                    Else
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        Else
                            formattedValue = "<table border=""0"" cellpadding=""0"" cellspacing=""0""><tr><td>" & formattedValue & "</td></tr></table>"
                        End If
                    End If
                End If  
                
                Me.Notes.Text = formattedValue
              
            Else      
                Me.Notes.Text = EmployeesTable.Notes.Format(EmployeesTable.Notes.DefaultValue)
              
            End If
                    
            If Me.Notes.Text Is Nothing _
                OrElse Me.Notes.Text.Trim() = "" Then
                Me.Notes.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.PhotoSpecified Then
                  
                Me.Photo.Attributes.Add("onclick", "gPersist=true;")
                Me.Photo.Attributes.Add("onmouseout","detailRolloverPopupClose();")
                Me.Photo.Attributes.Add("onmouseover","SaveMousePosition(event);delayRolloverPopup(""PageMethods.GetImage(\""" & Me.Page.Encrypt("Employees") _
                    & "\"", \""" & Me.Page.Encrypt(HttpUtility.UrlEncode(Me.DataSource.GetID().ToString())) _
                    & "\"", \""" & Me.Page.Encrypt("Photo") & "\"", \""" & "Photo" & "\"", false, 200," _
                    & " 300, true, PopupDisplayWindowCallBackWith20);"",500);")
                                    
                Me.Photo.ImageUrl = Me.DataSource.FormatImageUrl(EmployeesTable.Photo, Me.Page.Encrypt("Employees"), Me.Page.Encrypt("Photo"), Me.Page.Encrypt(Me.DataSource.GetID().ToXmlString()), 20)
                            
                Me.Photo.Visible = True
            Else
                Me.Photo.Visible = False
            End If
                
            If Me.DataSource.PostalCodeSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.PostalCode)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.PostalCode.Text = formattedValue
              
            Else      
                Me.PostalCode.Text = EmployeesTable.PostalCode.Format(EmployeesTable.PostalCode.DefaultValue)
              
            End If
                    
            If Me.PostalCode.Text Is Nothing _
                OrElse Me.PostalCode.Text.Trim() = "" Then
                Me.PostalCode.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.RegionSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.Region)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.Region.Text = formattedValue
              
            Else      
                Me.Region.Text = EmployeesTable.Region.Format(EmployeesTable.Region.DefaultValue)
              
            End If
                    
            If Me.Region.Text Is Nothing _
                OrElse Me.Region.Text.Trim() = "" Then
                Me.Region.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ReportsToSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.ReportsTo)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ReportsTo.Text = formattedValue
              
            Else      
                Me.ReportsTo.Text = EmployeesTable.ReportsTo.Format(EmployeesTable.ReportsTo.DefaultValue)
              
            End If
                    
            If Me.ReportsTo.Text Is Nothing _
                OrElse Me.ReportsTo.Text.Trim() = "" Then
                Me.ReportsTo.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.TitleSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.Title)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.Title.Text = formattedValue
              
            Else      
                Me.Title.Text = EmployeesTable.Title.Format(EmployeesTable.Title.DefaultValue)
              
            End If
                    
            If Me.Title.Text Is Nothing _
                OrElse Me.Title.Text.Trim() = "" Then
                Me.Title.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.TitleOfCourtesySpecified Then
                Dim formattedValue As String = Me.DataSource.Format(EmployeesTable.TitleOfCourtesy)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.TitleOfCourtesy.Text = formattedValue
              
            Else      
                Me.TitleOfCourtesy.Text = EmployeesTable.TitleOfCourtesy.Format(EmployeesTable.TitleOfCourtesy.DefaultValue)
              
            End If
                    
            If Me.TitleOfCourtesy.Text Is Nothing _
                OrElse Me.TitleOfCourtesy.Text.Trim() = "" Then
                Me.TitleOfCourtesy.Text = "&nbsp;"
            End If
                  
            Me.IsNewRecord = True
            If Me.DataSource.IsCreated Then
                Me.IsNewRecord = False
        
                Me.RecordUniqueId = Me.DataSource.GetID.ToXmlString()
            End If

            

            ' Load data for each record and table UI control.
            ' Ordering is important because child controls get 
            ' their parent ids from their parent UI controls.
            Dim shouldResetControl as Boolean = False
            
        Dim recOrdersTableControl as OrdersTableControl = DirectCast(MiscUtils.FindControlRecursively(Me, "OrdersTableControl"), OrdersTableControl)
        recOrdersTableControl.LoadData()
        recOrdersTableControl.DataBind()
        
      End Sub

        
        
        ' To customize, override this method in EmployeesTableControlRow.
        Public Overridable Sub SaveData()

            ' 1. Load the existing record from the database. Since we save the entire record, this ensures 
            ' that fields that are not displayed also properly initialized.
            Me.LoadData()
        
              
            ' 2. Validate the data.  Override in EmployeesTableControlRow to add custom validation.
            Me.Validate()

            ' 3. Set the values in the record with data from UI controls.  Override in EmployeesTableControlRow to set additional fields.
            Me.GetUIData()

            ' 4. Save in the database.
            ' We should not save the record if the data did not change. This
            ' will save a database hit and avoid triggering any database triggers.
            If Me.DataSource.IsAnyValueChanged Then
                ' Save record to database but do not commit.
                ' Auto generated ids are available after saving for use by child (dependent) records.
                Me.DataSource.Save()
              
                DirectCast(GetParentControlObject(Me, "EmployeesTableControl"), EmployeesTableControl).DataChanged = True
                DirectCast(GetParentControlObject(Me, "EmployeesTableControl"), EmployeesTableControl).ResetData = True
            End If
            Me.DataChanged = True
            Me.ResetData = True
            ' Reseting of Me.IsNewRecord is moved to Save button's click even handler.
            ' Me.IsNewRecord() = False
            
        Dim recOrdersTableControl as OrdersTableControl = DirectCast(MiscUtils.FindControlRecursively(Me, "OrdersTableControl"), OrdersTableControl)
        recOrdersTableControl.SaveData()
        
        End Sub

        ' To customize, override this method in EmployeesTableControlRow.
        Public Overridable Sub GetUIData()
            
        End Sub

        
      
        ' To customize, override this method in EmployeesTableControlRow.
        Public Overridable Function CreateWhereClause() As WhereClause
        
            Return Nothing
          
        End Function
        

        ' To customize, override this method in EmployeesTableControlRow.
        Public Overridable Sub Validate() 
            ' Initially empty.  Override to add custom validation.
        End Sub

        Public Overridable Sub Delete()
        
            If Me.IsNewRecord() Then
                Return
            End If

            Dim pk As KeyValue = KeyValue.XmlToKey(Me.RecordUniqueId)
            EmployeesTable.DeleteRecord(pk)

          
            DirectCast(GetParentControlObject(Me, "EmployeesTableControl"), EmployeesTableControl).DataChanged = True
            DirectCast(GetParentControlObject(Me, "EmployeesTableControl"), EmployeesTableControl).ResetData = True
        End Sub

        Protected Overridable Sub Control_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
            Try
                DbUtils.StartTransaction()

                If Not Me.Page.ErrorOnPage AndAlso (Me.Page.IsPageRefresh OrElse Me.DataChanged OrElse Me.ResetData) Then
                    Me.LoadData()
                    Me.DataBind()
                End If

            Catch ex As Exception
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction()
            End Try
        End Sub
        
        

        Protected Overrides Sub LoadViewState(ByVal savedState As Object)
            MyBase.LoadViewState(savedState)
            Dim isNewRecord As String = CType(ViewState("IsNewRecord"), String)
            If Not isNewRecord Is Nothing AndAlso isNewRecord.Trim <> "" Then
                Me.IsNewRecord = Boolean.Parse(isNewRecord)
            End If
            
            Dim myCheckSum As String = CType(ViewState("CheckSum"), String)
            If Not myCheckSum Is Nothing AndAlso myCheckSum.Trim <> "" Then
                Me.CheckSum = myCheckSum
            End If
            
        End Sub

        Protected Overrides Function SaveViewState() As Object
            ViewState("IsNewRecord") = Me.IsNewRecord.ToString()
            ViewState("CheckSum") = Me.CheckSum
            
            Return MyBase.SaveViewState()
        End Function
        
        
        ' event handler for ImageButton
        Public Overridable Sub EmployeesRowCopyButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Dim url As String = "../Employees/AddEmployees.aspx?Employees={PK}"
            Dim shouldRedirect As Boolean = True
            Dim TargetKey As String = Nothing
            Dim DFKA As String = Nothing
            Dim id As String = Nothing
            Dim value As String = Nothing
            Try
                DbUtils.StartTransaction
                
            url = Me.ModifyRedirectUrl(url, "",False)
            url = Me.Page.ModifyRedirectUrl(url, "",False)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                shouldRedirect = False
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
            If shouldRedirect Then
                Me.Page.ShouldSaveControlsToSession = True
                Me.Page.Response.Redirect(url)
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.Page.ShouldSaveControlsToSession = True
            Me.Page.CloseWindow(True)
        
            End If              
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesRowDeleteButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                DbUtils.StartTransaction
                
            If(Not Me.Page.IsPageRefresh) Then
        
                  Me.Delete()
              
            End If
      Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesRowEditButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Dim url As String = "../Employees/EditEmployees.aspx?Employees={PK}"
            Dim shouldRedirect As Boolean = True
            Dim TargetKey As String = Nothing
            Dim DFKA As String = Nothing
            Dim id As String = Nothing
            Dim value As String = Nothing
            Try
                DbUtils.StartTransaction
                
            url = Me.ModifyRedirectUrl(url, "",False)
            url = Me.Page.ModifyRedirectUrl(url, "",False)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                shouldRedirect = False
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
            If shouldRedirect Then
                Me.Page.ShouldSaveControlsToSession = True
                Me.Page.Response.Redirect(url)
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.Page.ShouldSaveControlsToSession = True
            Me.Page.CloseWindow(True)
        
            End If              
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesRowViewButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Dim url As String = "../Employees/ShowEmployees.aspx?Employees={PK}"
            Dim shouldRedirect As Boolean = True
            Dim TargetKey As String = Nothing
            Dim DFKA As String = Nothing
            Dim id As String = Nothing
            Dim value As String = Nothing
            Try
                DbUtils.StartTransaction
                
            url = Me.ModifyRedirectUrl(url, "",False)
            url = Me.Page.ModifyRedirectUrl(url, "",False)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                shouldRedirect = False
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
            If shouldRedirect Then
                Me.Page.ShouldSaveControlsToSession = True
                Me.Page.Response.Redirect(url)
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.Page.ShouldSaveControlsToSession = True
            Me.Page.CloseWindow(True)
        
            End If              
        End Sub
            
   
        Private _IsNewRecord As Boolean = True
        Public Overridable Property IsNewRecord() As Boolean
            Get
                Return Me._IsNewRecord
            End Get
            Set(ByVal value As Boolean)
                Me._IsNewRecord = value
            End Set
        End Property

        Private _DataChanged As Boolean = False
        Public Overridable Property DataChanged() As Boolean
            Get
                Return Me._DataChanged
            End Get
            Set(ByVal Value As Boolean)
                Me._DataChanged = Value
            End Set
        End Property

        Private _ResetData As Boolean = False
        Public Overridable Property ResetData() As Boolean
            Get
                Return Me._ResetData
            End Get
            Set(ByVal Value As Boolean)
                Me._ResetData = Value
            End Set
        End Property
        
        Public Property RecordUniqueId() As String
            Get
                Return CType(Me.ViewState("BaseEmployeesTableControlRow_Rec"), String)
            End Get
            Set(ByVal value As String)
                Me.ViewState("BaseEmployeesTableControlRow_Rec") = value
            End Set
        End Property
        
        Private _DataSource As EmployeesRecord
        Public Property DataSource() As EmployeesRecord
            Get
                Return Me._DataSource
            End Get
            Set(ByVal value As EmployeesRecord)
                Me._DataSource = value
            End Set
        End Property

        Private _checkSum As String
        Public Overridable Property CheckSum() As String
            Get
                Return Me._checkSum
            End Get
            Set(ByVal value As String)
                Me._checkSum = value
            End Set
        End Property
        
        Private _TotalPages As Integer
        Public Property TotalPages() As Integer
            Get
                Return Me._TotalPages
            End Get
            Set(ByVal value As Integer)
                Me._TotalPages = value
            End Set
        End Property
        
        Private _PageIndex As Integer
        Public Property PageIndex() As Integer
            Get
                ' Return the PageIndex
                Return Me._PageIndex
            End Get
            Set(ByVal value As Integer)
                Me._PageIndex = value
            End Set
        End Property
    
        Private _DisplayLastPage As Boolean
        Public Property DisplayLastPage() As Boolean
            Get
                Return Me._DisplayLastPage
            End Get
            Set(ByVal value As Boolean)
                Me._DisplayLastPage = value
            End Set
        End Property
        
        

#Region "Helper Properties"
        
        Public ReadOnly Property Address() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Address"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property BirthDate() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "BirthDate"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property City() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "City"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property Country() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Country"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property CreatedBy() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "CreatedBy"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property CreatedOn() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "CreatedOn"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property EmployeesRecordRowSelection() As System.Web.UI.WebControls.CheckBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesRecordRowSelection"), System.Web.UI.WebControls.CheckBox)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesRowCopyButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesRowCopyButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesRowDeleteButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesRowDeleteButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesRowEditButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesRowEditButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesRowViewButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesRowViewButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property Extension() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Extension"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property FirstName() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "FirstName"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property HireDate() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "HireDate"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property HomePhone() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "HomePhone"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property LastName() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "LastName"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property LastUpdatedBy() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "LastUpdatedBy"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property LastUpdatedOn() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "LastUpdatedOn"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property Notes() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Notes"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property OrdersTableControl() As OrdersTableControl
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "OrdersTableControl"), OrdersTableControl)
            End Get
        End Property
        
        Public ReadOnly Property Photo() As System.Web.UI.WebControls.Image
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Photo"), System.Web.UI.WebControls.Image)
            End Get
        End Property
            
        Public ReadOnly Property PostalCode() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "PostalCode"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property Region() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Region"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ReportsTo() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ReportsTo"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property Title() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Title"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property TitleOfCourtesy() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "TitleOfCourtesy"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
    #End Region

    #Region "Helper Functions"

    Public Overrides Overloads Function ModifyRedirectUrl(ByVal url As String, ByVal arg As String, ByVal bEncrypt As Boolean) As String
        Return Me.Page.EvaluateExpressions(url, arg, bEncrypt, Me)
    End Function

    Public Overrides Overloads Function EvaluateExpressions(ByVal url As String, ByVal arg As String, ByVal bEncrypt As Boolean) As String
    Dim rec As EmployeesRecord = Nothing
            
            Try
                rec = Me.GetRecord()
            Catch ex As Exception
                ' Do nothing
            End Try

            If rec Is Nothing AndAlso url.IndexOf("{") >= 0 Then
                ' Localization.
                
            Throw New Exception(Page.GetResourceValue("Err:RecDataSrcNotInitialized", "UseDAL"))
                    
            End If
            Return EvaluateExpressions(url, arg, rec, bEncrypt)
        End Function

        Public Overridable Function GetRecord() As EmployeesRecord
            If Not Me.DataSource Is Nothing Then
                Return Me.DataSource
            End If
            
            If Not Me.RecordUniqueId Is Nothing Then
                Return EmployeesTable.GetRecord(Me.RecordUniqueId, True)
            End If
            
            ' Localization.
            
            Throw New Exception(Page.GetResourceValue("Err:RetrieveRec", "UseDAL"))
                
        End Function

        Public Shadows ReadOnly Property Page() As BaseApplicationPage
            Get
                Return DirectCast(MyBase.Page, BaseApplicationPage)
            End Get
        End Property

#End Region

End Class

  

' Base class for the EmployeesTableControl control on the ShowEmployeesTable2 page.
' Do not modify this class. Instead override any method in EmployeesTableControl.
Public Class BaseEmployeesTableControl
        Inherits UseDAL.UI.BaseApplicationTableControl

        Protected Overridable Sub Control_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init

            ' Setup the pagination events.
        
              AddHandler Me.EmployeesPagination.FirstPage.Click, AddressOf EmployeesPagination_FirstPage_Click
              
              AddHandler Me.EmployeesPagination.LastPage.Click, AddressOf EmployeesPagination_LastPage_Click
              
              AddHandler Me.EmployeesPagination.NextPage.Click, AddressOf EmployeesPagination_NextPage_Click
              
              AddHandler Me.EmployeesPagination.PageSizeButton.Click, AddressOf EmployeesPagination_PageSizeButton_Click
            
              AddHandler Me.EmployeesPagination.PreviousPage.Click, AddressOf EmployeesPagination_PreviousPage_Click
              

            ' Setup the sorting events.
        
              AddHandler Me.AddressLabel.Click, AddressOf AddressLabel_Click
            
              AddHandler Me.BirthDateLabel.Click, AddressOf BirthDateLabel_Click
            
              AddHandler Me.CityLabel.Click, AddressOf CityLabel_Click
            
              AddHandler Me.CountryLabel.Click, AddressOf CountryLabel_Click
            
              AddHandler Me.CreatedByLabel.Click, AddressOf CreatedByLabel_Click
            
              AddHandler Me.CreatedOnLabel.Click, AddressOf CreatedOnLabel_Click
            
              AddHandler Me.ExtensionLabel.Click, AddressOf ExtensionLabel_Click
            
              AddHandler Me.FirstNameLabel.Click, AddressOf FirstNameLabel_Click
            
              AddHandler Me.HireDateLabel.Click, AddressOf HireDateLabel_Click
            
              AddHandler Me.HomePhoneLabel.Click, AddressOf HomePhoneLabel_Click
            
              AddHandler Me.LastNameLabel1.Click, AddressOf LastNameLabel1_Click
            
              AddHandler Me.LastUpdatedByLabel.Click, AddressOf LastUpdatedByLabel_Click
            
              AddHandler Me.LastUpdatedOnLabel.Click, AddressOf LastUpdatedOnLabel_Click
            
              AddHandler Me.PostalCodeLabel1.Click, AddressOf PostalCodeLabel1_Click
            
              AddHandler Me.RegionLabel.Click, AddressOf RegionLabel_Click
            
              AddHandler Me.ReportsToLabel.Click, AddressOf ReportsToLabel_Click
            
              AddHandler Me.TitleLabel.Click, AddressOf TitleLabel_Click
            
              AddHandler Me.TitleOfCourtesyLabel.Click, AddressOf TitleOfCourtesyLabel_Click
            

            ' Setup the button events.
        
              AddHandler Me.EmployeesCopyButton.Click, AddressOf EmployeesCopyButton_Click
              
              AddHandler Me.EmployeesDeleteButton.Click, AddressOf EmployeesDeleteButton_Click
              
              AddHandler Me.EmployeesEditButton.Click, AddressOf EmployeesEditButton_Click
              
              AddHandler Me.EmployeesExportButton.Click, AddressOf EmployeesExportButton_Click
              
              Me.Page.RegisterPostBackTrigger(MiscUtils.FindControlRecursively(Me,"EmployeesExportButton"), MiscUtils.FindControlRecursively(Me.Page,"UpdatePanel1"))
                        
              AddHandler Me.EmployeesExportExcelButton.Click, AddressOf EmployeesExportExcelButton_Click
              
              Me.Page.RegisterPostBackTrigger(MiscUtils.FindControlRecursively(Me,"EmployeesExportExcelButton"), MiscUtils.FindControlRecursively(Me.Page,"UpdatePanel1"))
                        
              AddHandler Me.EmployeesImportButton.Click, AddressOf EmployeesImportButton_Click
              
              AddHandler Me.EmployeesNewButton.Click, AddressOf EmployeesNewButton_Click
              
              AddHandler Me.EmployeesPDFButton.Click, AddressOf EmployeesPDFButton_Click
              
              Me.Page.RegisterPostBackTrigger(MiscUtils.FindControlRecursively(Me,"EmployeesPDFButton"), MiscUtils.FindControlRecursively(Me.Page,"UpdatePanel1"))
                        
              AddHandler Me.EmployeesRefreshButton.Click, AddressOf EmployeesRefreshButton_Click
              
              AddHandler Me.EmployeesResetButton.Click, AddressOf EmployeesResetButton_Click
              
              AddHandler Me.EmployeesWordButton.Click, AddressOf EmployeesWordButton_Click
              
              Me.Page.RegisterPostBackTrigger(MiscUtils.FindControlRecursively(Me,"EmployeesWordButton"), MiscUtils.FindControlRecursively(Me.Page,"UpdatePanel1"))
                        
              AddHandler Me.EmployeesSearchButton.Button.Click, AddressOf EmployeesSearchButton_Click
              

            ' Setup the filter and search events.
        
            AddHandler Me.LastNameFilter.SelectedIndexChanged, AddressOf LastNameFilter_SelectedIndexChanged
            AddHandler Me.PostalCodeFilter.SelectedIndexChanged, AddressOf PostalCodeFilter_SelectedIndexChanged
            If Not Me.Page.IsPostBack AndAlso Me.InSession(Me.EmployeesSearchArea) Then
                
                Me.EmployeesSearchArea.Text = Me.GetFromSession(Me.EmployeesSearchArea)
            End If
            If Not Me.Page.IsPostBack AndAlso Me.InSession(Me.LastNameFilter) Then
                Me.LastNameFilter.Items.Add(New ListItem(Me.GetFromSession(Me.LastNameFilter), Me.GetFromSession(Me.LastNameFilter)))
                Me.LastNameFilter.SelectedValue = Me.GetFromSession(Me.LastNameFilter)
            End If
            If Not Me.Page.IsPostBack AndAlso Me.InSession(Me.PostalCodeFilter) Then
                Me.PostalCodeFilter.Items.Add(New ListItem(Me.GetFromSession(Me.PostalCodeFilter), Me.GetFromSession(Me.PostalCodeFilter)))
                Me.PostalCodeFilter.SelectedValue = Me.GetFromSession(Me.PostalCodeFilter)
            End If

            ' Control Initializations.
            ' Initialize the table's current sort order.
            If Me.InSession(Me, "Order_By") Then
                Me.CurrentSortOrder = OrderBy.FromXmlString(Me.GetFromSession(Me, "Order_By", Nothing))
            Else
                Me.CurrentSortOrder = New OrderBy(True, True)
        
            End If

            ' Setup default pagination settings.
        
            Me.PageSize = CInt(Me.GetFromSession(Me, "Page_Size", "10"))
            Me.PageIndex = CInt(Me.GetFromSession(Me, "Page_Index", "0"))
            Me.ClearControlsFromSession()
        End Sub

        Protected Overridable Sub Control_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
            SaveControlsToSession_Ajax()
        
                ' Show confirmation message on Click
                Me.EmployeesDeleteButton.Attributes.Add("onClick", "return (confirm('" & (CType(Me.Page,BaseApplicationPage)).GetResourceValue("DeleteConfirm", "UseDAL") & "'));")
        End Sub

        ' Read data from database. Returns an array of records that can be assigned
        ' to the DataSource table control property.
        Public Overridable Sub LoadData()
            Try
            
                ' The WHERE clause will be empty when displaying all records in table.
                Dim wc As WhereClause = CreateWhereClause()
                If Not wc Is Nothing AndAlso Not wc.RunQuery Then
                    ' Initialize an empty array of records
                    Dim alist As New ArrayList(0)
                    Me.DataSource = DirectCast(alist.ToArray(GetType(EmployeesRecord)), EmployeesRecord())
                    ' Add records to the list if needed.
                    Me.AddNewRecords()
                    Return
                End If

                Dim orderBy As OrderBy = CreateOrderBy()

                ' Get the pagesize from the pagesize control.
                Me.GetPageSize()

                ' Get the total number of records to be displayed.
                Me.TotalRecords = EmployeesTable.GetRecordCount(wc)

                ' Go to the last page.
                If Me.TotalPages <= 0 OrElse Me.PageIndex < 0 Then
                    Me.PageIndex = 0
                ElseIf Me.DisplayLastPage OrElse Me.PageIndex >= Me.TotalPages Then
                    Me.PageIndex = Me.TotalPages - 1
                End If

                ' Retrieve the records and set the table DataSource.
                ' Only PageSize records are fetched starting at PageIndex (zero based).
                If Me.TotalRecords <= 0 Then
                    ' Initialize an empty array of records
                    Dim alist As New ArrayList(0)
                    Me.DataSource = DirectCast(alist.ToArray(GetType(EmployeesRecord)), EmployeesRecord())
                ElseIf Me.AddNewRecord > 0 Then
                    ' Get the records from the posted data
                    Dim postdata As New ArrayList
                    For Each rc As EmployeesTableControlRow In Me.GetRecordControls()
                        If Not rc.IsNewRecord Then
                            rc.DataSource = rc.GetRecord()
                            rc.GetUIData()
                            postdata.Add(rc.DataSource)
                        End If
                    Next
                    Me.DataSource = DirectCast(postdata.ToArray(GetType(EmployeesRecord)), EmployeesRecord())
                Else
                    ' Get the records from the database
                    Me.DataSource = EmployeesTable.GetRecords(wc, orderBy, Me.PageIndex, Me.PageSize)
                End If
                ' Add records to the list.
                Me.AddNewRecords()
            
                ' Turn off the ToggleAll checkbox
                Me.EmployeesToggleAll.Checked = False
            

                ' Initialize the page and grand totals. now
            
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        ' Populate the UI controls.
        Public Overrides Sub DataBind()

            MyBase.DataBind()

            ' Make sure that the DataSource is initialized.
            If Me.DataSource Is Nothing Then
                Return
            End If

        

            ' Setup the pagination controls.
            BindPaginationControls()

            ' Populate all filters data.
        
            Me.PopulateLastNameFilter(GetSelectedValue(Me.LastNameFilter, Me.GetFromSession(Me.LastNameFilter)), 500)
                    
            Me.PopulatePostalCodeFilter(GetSelectedValue(Me.PostalCodeFilter, Me.GetFromSession(Me.PostalCodeFilter)), 500)
                    

            ' Bind the repeater with the list of records to expand the UI.
            Dim rep As System.Web.UI.WebControls.Repeater = CType(Me.FindControl("EmployeesTableControlRepeater"), System.Web.UI.WebControls.Repeater)
      If rep is Nothing Then Return
            rep.DataSource = DataSource()
            rep.DataBind()

            Dim index as Integer = 0
            For Each repItem as System.Web.UI.WebControls.RepeaterItem in rep.Items
                ' Loop through all rows in the table, set its DataSource and call DataBind().
                Dim recControl as EmployeesTableControlRow = DirectCast(repItem.FindControl("EmployeesTableControlRow"),EmployeesTableControlRow) 
                recControl.DataSource = Me.DataSource(index)
                recControl.DataBind()
                recControl.Visible = Not Me.InDeletedRecordIds(recControl)
                index += 1
            Next

        
      ' setting the state of expand or collapse alternative rows
      
      End Sub

        Public Overridable Sub ResetControl()
        
            
              Me.LastNameFilter.ClearSelection()
            
              Me.PostalCodeFilter.ClearSelection()
            
              Me.EmployeesSearchArea.Text = ""
            
              Me.CurrentSortOrder.Reset()
              If (Me.InSession(Me, "Order_By")) Then
              Me.CurrentSortOrder = OrderBy.FromXmlString(Me.GetFromSession(Me, "Order_By", Nothing))
              Else
              Me.CurrentSortOrder = New OrderBy(true, true)
            
            End If
                
            Me.PageIndex = 0
    End Sub


     

        Protected Overridable Sub BindPaginationControls()

            ' Setup the pagination controls.

            ' Bind the buttons for EmployeesTableControl pagination.
        
            Me.EmployeesPagination.FirstPage.Enabled = Not (Me.PageIndex = 0)
            Me.EmployeesPagination.LastPage.Enabled = Not (Me.PageIndex = Me.TotalPages - 1)
            If Me.TotalPages = 0 Then
                Me.EmployeesPagination.LastPage.Enabled = False
            End If
          
            Me.EmployeesPagination.NextPage.Enabled = Not (Me.PageIndex = Me.TotalPages - 1)
            If Me.TotalPages = 0 Then
                Me.EmployeesPagination.NextPage.Enabled = False
            End If
          
            Me.EmployeesPagination.PreviousPage.Enabled = Not (Me.PageIndex = 0)

            ' Bind the pagination labels.
        
            If Me.TotalPages > 0 Then
                Me.EmployeesPagination.CurrentPage.Text = (Me.PageIndex + 1).ToString()
            Else
                Me.EmployeesPagination.CurrentPage.Text = "0"
            End If
            Me.EmployeesPagination.PageSize.Text = Me.PageSize.ToString()
            Me.EmployeesPagination.TotalItems.Text = Me.TotalRecords.ToString()
            Me.EmployeesPagination.TotalPages.Text = Me.TotalPages.ToString()
        End Sub

        Public Overridable Sub SaveData()
            Dim recCtl As EmployeesTableControlRow
            For Each recCtl In Me.GetRecordControls()
        
                If Me.InDeletedRecordIds(recCtl) Then
                    recCtl.Delete()
                Else
                    If recCtl.Visible Then
                        recCtl.SaveData()
                    End If
                End If
          
            Next
            
            Me.DataChanged = True
            Me.ResetData = True
            
            
          
          ' When one tries to add two duplicate records, an exception is thrown.Before throwing an exception, the first record's IsNewRecord property is set to false. 
          ' Now when one tries to delete these two records simultaneously, since the first record's IsNewRecord property is false, the server tries to delete it from the database, which result in an error.
          ' To avoid this problem every record's IsNewRecord property is set to false only after all the records are saved in the database. 
          For Each recCtl in Me.GetRecordControls()
              recCtl.IsNewRecord = False
          Next
    
      
                ' Whenever an existing record is deleted and saved and then tried to add the same record, it does not display the newly added record after saving, because, while displaying each records DeletedRecordIds is checked to see if it is waiting to be deleted.
          ' Since DeletedRecordIds is not reset after each record deletion, when one tries to add the same record it sees record id in DeleteReordIds and does not display it. 
          ' To overcome this problem, DeletedRecordIds is reset.
           Me.DeletedRecordIds = Nothing
      
            
            
        End Sub

        Public Overridable Function CreateOrderBy() As OrderBy
            Return Me.CurrentSortOrder
        End Function
        
        'This CreateWhereClause is used for loading the data.
        Public Overridable Function CreateWhereClause() As WhereClause
            EmployeesTable.Instance.InnerFilter = Nothing
            Dim wc As WhereClause = New WhereClause()
            ' Compose the WHERE clause consiting of:
            ' 1. Static clause defined at design time.
            ' 2. User selected filter criteria.
            ' 3. User selected search criteria.

              
            If IsValueSelected(Me.EmployeesSearchArea) Then
                ' Strip "..." from begin and ending of the search text, otherwise the search will return 0 values as in database "..." is not stored.
                If Me.EmployeesSearchArea.Text.StartsWith("...") then
                    Me.EmployeesSearchArea.Text = Me.EmployeesSearchArea.Text.SubString(3,Me.EmployeesSearchArea.Text.Length-3)
                End If
                If Me.EmployeesSearchArea.Text.EndsWith("...") then
                    Me.EmployeesSearchArea.Text = Me.EmployeesSearchArea.Text.SubString(0,Me.EmployeesSearchArea.Text.Length-3)
                End If
                ' After stripping "..." see if the search text is null or empty.
                If IsValueSelected(Me.EmployeesSearchArea) Then
                      
                    ' These clauses are added depending on operator and fields selected in Control's property page, bindings tab.
                    Dim search As WhereClause = New WhereClause()
                    
                    search.iOR(EmployeesTable.LastName, BaseFilter.ComparisonOperator.Contains, MiscUtils.GetSelectedValue(Me.EmployeesSearchArea, Me.GetFromSession(Me.EmployeesSearchArea)), True, False)
        
                    search.iOR(EmployeesTable.PostalCode, BaseFilter.ComparisonOperator.Contains, MiscUtils.GetSelectedValue(Me.EmployeesSearchArea, Me.GetFromSession(Me.EmployeesSearchArea)), True, False)
        
                    wc.iAND(search)
                End If
            End If
                  
            If IsValueSelected(Me.LastNameFilter) Then
                
                wc.iAND(EmployeesTable.LastName, BaseFilter.ComparisonOperator.EqualsTo, MiscUtils.GetSelectedValue(Me.LastNameFilter, Me.GetFromSession(Me.LastNameFilter)), False, False)
                    
                
            End If
                       
            If IsValueSelected(Me.PostalCodeFilter) Then
                
                wc.iAND(EmployeesTable.PostalCode, BaseFilter.ComparisonOperator.EqualsTo, MiscUtils.GetSelectedValue(Me.PostalCodeFilter, Me.GetFromSession(Me.PostalCodeFilter)), False, False)
                    
                
            End If
                       
            Return wc
        End Function
        
        
        ' This CreateWhereClause is used for loading list of suggestions for Auto Type-Ahead feature.
        Public Overridable Function CreateWhereClause(ByVal searchText as String, ByVal fromSearchControl as String, ByVal AutoTypeAheadSearch as String, ByVal AutoTypeAheadWordSeparators as String) As WhereClause
            EmployeesTable.Instance.InnerFilter = Nothing
            Dim wc As WhereClause = New WhereClause()
            ' Compose the WHERE clause consiting of:
            ' 1. Static clause defined at design time.
            ' 2. User selected filter criteria.
            ' 3. User selected search criteria.
            Dim appRelativeVirtualPath As String = CType(HttpContext.Current.Session("AppRelativeVirtualPath"), String)
            
            ' Adds clauses if values are selected in Filter controls which are configured in the page.
          
            If IsValueSelected(searchText) and fromSearchControl = "EmployeesSearchArea" Then
                Dim formatedSearchText as String = searchText
                ' strip "..." from begin and ending of the search text, otherwise the search will return 0 values as in database "..." is not stored.
                If searchText.StartsWith("...") then
                    formatedSearchText = searchText.SubString(3,searchText.Length-3)
                End If
                If searchText.EndsWith("...") then
                    formatedSearchText = searchText.SubString(0,searchText.Length-3)
                End If
                'After stripping "...", trim any leading and trailing whitespaces 
                formatedSearchText = formatedSearchText.Trim()
                ' After stripping "..." see if the search text is null or empty.
                If IsValueSelected(formatedSearchText) Then
                      
                    ' These clauses are added depending on operator and fields selected in Control's property page, bindings tab.
                    Dim search As WhereClause = New WhereClause()
                    
                    If InvariantLCase(AutoTypeAheadSearch).equals("wordsstartingwithsearchstring") Then
                
                        search.iOR(EmployeesTable.LastName, BaseFilter.ComparisonOperator.Starts_With, formatedSearchText, True, False)
                        search.iOR(EmployeesTable.LastName, BaseFilter.ComparisonOperator.Contains, AutoTypeAheadWordSeparators & formatedSearchText, True, False)
                
                        search.iOR(EmployeesTable.PostalCode, BaseFilter.ComparisonOperator.Starts_With, formatedSearchText, True, False)
                        search.iOR(EmployeesTable.PostalCode, BaseFilter.ComparisonOperator.Contains, AutoTypeAheadWordSeparators & formatedSearchText, True, False)
                
                    Else
                        
                        search.iOR(EmployeesTable.LastName, BaseFilter.ComparisonOperator.Contains, formatedSearchText, True, False)
                        search.iOR(EmployeesTable.PostalCode, BaseFilter.ComparisonOperator.Contains, formatedSearchText, True, False)
                    End If
                    wc.iAND(search)
                End If
            End If
                  
            Dim LastNameFilterSelectedValue As String = CType(HttpContext.Current.Session()(HttpContext.Current.Session.SessionID & appRelativeVirtualPath & "LastNameFilter_Ajax"), String)
            If IsValueSelected(LastNameFilterSelectedValue) Then
              
                wc.iAND(EmployeesTable.LastName, BaseFilter.ComparisonOperator.EqualsTo, LastNameFilterSelectedValue, false, False)
                      
            End If
                      
            Dim PostalCodeFilterSelectedValue As String = CType(HttpContext.Current.Session()(HttpContext.Current.Session.SessionID & appRelativeVirtualPath & "PostalCodeFilter_Ajax"), String)
            If IsValueSelected(PostalCodeFilterSelectedValue) Then
              
                wc.iAND(EmployeesTable.PostalCode, BaseFilter.ComparisonOperator.EqualsTo, PostalCodeFilterSelectedValue, false, False)
                      
            End If
                      
            Return wc
        End Function
          
        Public Overridable Function GetAutoCompletionList_EmployeesSearchArea(ByVal prefixText As String, ByVal count As Integer) As String()
            Dim resultList As ArrayList = New ArrayList
            Dim wordList As ArrayList = New ArrayList
            Dim iteration As Integer = 0
            
            Dim wc As WhereClause = CreateWhereClause(prefixText,"EmployeesSearchArea", "WordsStartingWithSearchString", "[!a-zA-Z0-9]")
            While (resultList.Count < count AndAlso iteration < 5)
                ' Fetch 100 records in each iteration
                Dim records() As UseDAL.Business.EmployeesRecord = EmployeesTable.GetRecords(wc, Nothing, iteration, 100)
                Dim rec As EmployeesRecord = Nothing
                Dim resultItem As String = ""
                For Each rec In records
                    ' Exit the loop if recordList count has reached AutoTypeAheadListSize.
                    If resultList.Count >= count then
                        Exit For
                    End If
                    ' If the field is configured to Display as Foreign key, Format() method returns the 
                    ' Display as Forien Key value instead of original field value.
                    ' Since search had to be done in multiple fields (selected in Control's page property, binding tab) in a record,
                    ' We need to find relevent field to display which matches the prefixText and is not already present in the result list.
                
                    resultItem = rec.Format(EmployeesTable.LastName)
                    If resultItem IsNot Nothing AndAlso resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).Contains(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture))  Then
                        Dim isAdded as Boolean = FormatSuggestions(prefixText, resultItem, 50, "AtBeginningOfMatchedString", "WordsStartingWithSearchString", "[^a-zA-Z0-9]", resultList)
                        If isAdded Then
                            Continue For
                        End If
                    End If
      
                    resultItem = rec.Format(EmployeesTable.PostalCode)
                    If resultItem IsNot Nothing AndAlso resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).Contains(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture))  Then
                        Dim isAdded as Boolean = FormatSuggestions(prefixText, resultItem, 50, "AtBeginningOfMatchedString", "WordsStartingWithSearchString", "[^a-zA-Z0-9]", resultList)
                        If isAdded Then
                            Continue For
                        End If
                    End If
      
                Next
                ' Exit the loop if number of records found is less as further iteration will not return any more records
                If records.Length < 100 Then
                    Exit While
                End If
                iteration += 1
            End While
            resultList.Sort()
            Dim result() As String = New String(resultList.Count - 1) {}
            Array.Copy(resultList.ToArray, result, resultList.Count)
            Return result
        End Function
          
          
        'Formats the resultItem and adds it to the list of suggestions.
        Public Overridable Function FormatSuggestions(ByVal prefixText As String, ByVal resultItem as String, _
                                                 ByVal columnLength As Integer, ByVal AutoTypeAheadDisplayFoundText as String, _
                                                 ByVal autoTypeAheadSearch as String, ByVal AutoTypeAheadWordSeparators as String, _
                                                 ByVal resultList as ArrayList) as Boolean
            Dim index As Integer = resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).IndexOf(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture))
            Dim itemToAdd As String = ""
            Dim isFound as Boolean = False
            Dim isAdded as Boolean = False
            ' Get the index where prfixt is at the beginning of resultItem. If not found then, index of word which begins with prefixText.
            If InvariantLCase(autoTypeAheadSearch).equals("wordsstartingwithsearchstring") and not index = 0 Then
                ' Expression to find word which contains AutoTypeAheadWordSeparators followed by prefixText
                Dim regex1 As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex( AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                If regex1.IsMatch(resultItem) Then
                    index = regex1.Match(resultItem).Index
                    isFound = True
                End If
                ' If the prefixText is found immediatly after white space then starting of the word is found so don not search any further
                If not resultItem(index).ToString() = " " Then
                    ' Expression to find beginning of the word which contains AutoTypeAheadWordSeparators followed by prefixText
                    Dim regex As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\\S*" + AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    If regex.IsMatch(resultItem) Then
                        index = regex.Match(resultItem).Index
                        isFound = True
                    End If
                 End If
            End If
            ' If autoTypeAheadSearch value is wordsstartingwithsearchstring then, extract the substring only if the prefixText is found at the 
            ' beginning of the resultItem (index = 0) or a word in resultItem is found starts with prefixText. 
            If index = 0 Or isFound Or InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring") then
                If InvariantLCase(AutoTypeAheadDisplayFoundText).equals("atbeginningofmatchedstring") Then
                    ' Expression to find beginning of the word which contains prefixText
                    Dim regex1 As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\\S*" + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    '  Find the beginning of the word which contains prefexText
                    If (StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring") AndAlso regex1.IsMatch(resultItem)) Then
                        index = regex1.Match(resultItem).Index
                        isFound = True
                    End If
                    ' Display string from the index till end of the string if sub string from index till end is less than columnLength value.
                    If Len(resultItem) - index <= columnLength Then
                        If index = 0 Then 
                            itemToAdd = resultItem 
                        Else
                            itemToAdd = "..." & resultItem.Substring(index, Len(resultItem) - index) 
                        End If
                    Else
                        If index = 0 Then
                            itemToAdd = resultItem.Substring(index, (columnLength - 3)) & "..."
                        Else
                            'Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                            itemToAdd = "..." & resultItem.Substring(index , columnLength - 6) & "..." 
                        End If
                    End If
                ElseIf InvariantLCase(AutoTypeAheadDisplayFoundText).equals("inmiddleofmatchedstring") Then
                    Dim subStringBeginIndex as Integer = CType(columnLength/2, Integer)
                    If Len(resultItem) <= columnLength Then
                        itemToAdd = resultItem
                    Else
                        ' Sanity check at end of the string
                        If index + Len(prefixText) = columnLength Then
                            itemToAdd =  "..." & resultItem.Substring(index-columnLength,index)
                        ElseIf Len(resultITem) - index < subStringBeginIndex Then 
                            ' Display string from the end till columnLength value if, index is closer to the end of the string.
                            itemToAdd =  "..." & resultItem.Substring(Len(resultItem)-columnLength,Len(resultItem))
                        ElseIf index <= subStringBeginIndex Then 
                            ' Sanity chet at beginning of the string
                            itemToAdd =  resultItem.Substring(0, columnLength) & "..."
                        Else
                            ' Display string containing text before the prefixText occures and text after the prefixText
                            itemToAdd =  "..." & resultItem.Substring(index - subStringBeginIndex, columnLength) & "..." 
                        End If
                    End If
                ElseIf InvariantLCase(AutoTypeAheadDisplayFoundText).equals("atendofmatchedstring") Then
                     ' Expression to find ending of the word which contains prefexText
                    Dim regex1 as System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\s", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    ' Find the ending of the word which contains prefexText
                    If regex1.IsMatch(resultItem, index + 1) Then
                        index = regex1.Match(resultItem, index + 1).Index
                    Else
                        ' If the word which contains prefexText is the last word in string, regex1.IsMatch returns false.
                        index = resultItem.Length
                    End If
                    If index > Len(resultItem) Then
                        index = Len(resultItem)
                    End If
                    ' If text from beginning of the string till index is less than columnLength value then, display string from the beginning till index.
                    If  index <= columnLength Then
                        if index = Len(resultItem) then   'Make decision to append "..."
                            itemToAdd = resultItem.Substring(0,index)
                        Else
                            itemToAdd = resultItem.Substring(0,index) & "..."
                        End If
                    Else
                        If index = Len(resultItem) Then
                            itemToAdd = "..." & resultItem.Substring(index - (columnLength - 3), (columnLength - 3))
                        Else
                            'Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                            itemToAdd = "..." & resultItem.Substring(index - (columnLength - 6), columnLength - 6) & "..." 
                        End If
                    End If
                End If
                
                ' Remove newline character from itemToAdd
                Dim prefixTextIndex As Integer = itemToAdd.IndexOf(prefixText, StringComparison.CurrentCultureIgnoreCase)
                ' If itemToAdd contains any newline after the search text then show text only till newline
                Dim regex2 As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("(" & vbCrLf & "|" & vbLf & ")", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                Dim newLineIndexAfterPrefix As Integer = -1
                If regex2.IsMatch(itemToAdd, prefixTextIndex) Then
                    newLineIndexAfterPrefix = regex2.Match(itemToAdd, prefixTextIndex).Index
                End If
                If (newLineIndexAfterPrefix > -1) Then
                    If itemToAdd.EndsWith("...") Then
                        itemToAdd = (itemToAdd.Substring(0, newLineIndexAfterPrefix) + "...")
                    Else
                        itemToAdd = itemToAdd.Substring(0, newLineIndexAfterPrefix)
                    End If
                End If
                ' If itemToAdd contains any newline before search text then show text which comes after newline
                Dim regex3 As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("(" & vbCrLf & "|" & vbLf & ")", (System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.RightToLeft))
                Dim newLineIndexBeforePrefix As Integer = -1
                If regex3.IsMatch(itemToAdd, prefixTextIndex) Then
                    newLineIndexBeforePrefix = regex3.Match(itemToAdd, prefixTextIndex).Index
                End If
                If (newLineIndexBeforePrefix > -1) Then
                    If itemToAdd.StartsWith("...") Then
                        itemToAdd = ("..." + itemToAdd.Substring((newLineIndexBeforePrefix + regex3.Match(itemToAdd, prefixTextIndex).Length)))
                    Else
                        itemToAdd = itemToAdd.Substring((newLineIndexBeforePrefix + regex3.Match(itemToAdd, prefixTextIndex).Length))
                    End If
                End If

                If Not itemToAdd is nothing AndAlso Not resultList.Contains(itemToAdd) Then
                    resultList.Add(itemToAdd)
                    isAdded = true
                End If
            End If
            Return isAdded
        End Function
        
    
        Protected Overridable Sub GetPageSize()
        
            If Me.EmployeesPagination.PageSize.Text.Trim <> "" Then
                Try
                    'Me.PageSize = Integer.Parse(Me.EmployeesPagination.PageSize.Text)
                Catch ex As Exception
                End Try
            End If
        End Sub

        Protected Overridable Sub AddNewRecords()
            Dim newRecordList As ArrayList = New ArrayList()

            ' Loop though all the record controls and if the record control
            ' does not have a unique record id set, then create a record
            ' and add to the list.
            If Not Me.ResetData Then
                Dim rep As System.Web.UI.WebControls.Repeater = CType(Me.FindControl("EmployeesTableControlRepeater"), System.Web.UI.WebControls.Repeater)
        If rep is Nothing Then Return

                Dim repItem As System.Web.UI.WebControls.RepeaterItem
                For Each repItem In rep.Items
                    ' Loop through all rows in the table, set its DataSource and call DataBind().
                    Dim recControl As EmployeesTableControlRow = DirectCast(repItem.FindControl("EmployeesTableControlRow"), EmployeesTableControlRow)

                    If recControl.Visible AndAlso recControl.IsNewRecord() Then
                        Dim rec As EmployeesRecord = New EmployeesRecord()
        
                        If recControl.Address.Text <> "" Then
                            rec.Parse(recControl.Address.Text, EmployeesTable.Address)
                        End If
                        If recControl.BirthDate.Text <> "" Then
                            rec.Parse(recControl.BirthDate.Text, EmployeesTable.BirthDate)
                        End If
                        If recControl.City.Text <> "" Then
                            rec.Parse(recControl.City.Text, EmployeesTable.City)
                        End If
                        If recControl.Country.Text <> "" Then
                            rec.Parse(recControl.Country.Text, EmployeesTable.Country)
                        End If
                        If recControl.CreatedBy.Text <> "" Then
                            rec.Parse(recControl.CreatedBy.Text, EmployeesTable.CreatedBy)
                        End If
                        If recControl.CreatedOn.Text <> "" Then
                            rec.Parse(recControl.CreatedOn.Text, EmployeesTable.CreatedOn)
                        End If
                        If recControl.Extension.Text <> "" Then
                            rec.Parse(recControl.Extension.Text, EmployeesTable.Extension)
                        End If
                        If recControl.FirstName.Text <> "" Then
                            rec.Parse(recControl.FirstName.Text, EmployeesTable.FirstName)
                        End If
                        If recControl.HireDate.Text <> "" Then
                            rec.Parse(recControl.HireDate.Text, EmployeesTable.HireDate)
                        End If
                        If recControl.HomePhone.Text <> "" Then
                            rec.Parse(recControl.HomePhone.Text, EmployeesTable.HomePhone)
                        End If
                        If recControl.LastName.Text <> "" Then
                            rec.Parse(recControl.LastName.Text, EmployeesTable.LastName)
                        End If
                        If recControl.LastUpdatedBy.Text <> "" Then
                            rec.Parse(recControl.LastUpdatedBy.Text, EmployeesTable.LastUpdatedBy)
                        End If
                        If recControl.LastUpdatedOn.Text <> "" Then
                            rec.Parse(recControl.LastUpdatedOn.Text, EmployeesTable.LastUpdatedOn)
                        End If
                        If recControl.Notes.Text <> "" Then
                            rec.Parse(recControl.Notes.Text, EmployeesTable.Notes)
                        End If
                        If recControl.PostalCode.Text <> "" Then
                            rec.Parse(recControl.PostalCode.Text, EmployeesTable.PostalCode)
                        End If
                        If recControl.Region.Text <> "" Then
                            rec.Parse(recControl.Region.Text, EmployeesTable.Region)
                        End If
                        If recControl.ReportsTo.Text <> "" Then
                            rec.Parse(recControl.ReportsTo.Text, EmployeesTable.ReportsTo)
                        End If
                        If recControl.Title.Text <> "" Then
                            rec.Parse(recControl.Title.Text, EmployeesTable.Title)
                        End If
                        If recControl.TitleOfCourtesy.Text <> "" Then
                            rec.Parse(recControl.TitleOfCourtesy.Text, EmployeesTable.TitleOfCourtesy)
                        End If
                        newRecordList.Add(rec)
                    End If
                Next
            End If

            ' Add any new record to the list.
            Dim index As Integer = 0
            For index = 1 To Me.AddNewRecord
                newRecordList.Insert(0, New EmployeesRecord())
            Next
            Me.AddNewRecord = 0

            ' Finally, add any new records to the DataSource.
            If newRecordList.Count > 0 Then
                Dim finalList As ArrayList = New ArrayList(Me.DataSource)
                finalList.InsertRange(0, newRecordList)

                Me.DataSource = DirectCast(finalList.ToArray(GetType(EmployeesRecord)), EmployeesRecord())
            End If

        End Sub

        
        Public Sub AddToDeletedRecordIds(ByVal rec As EmployeesTableControlRow)
            If rec.IsNewRecord() Then
                Return
            End If

            If Not Me.DeletedRecordIds Is Nothing AndAlso Me.DeletedRecordIds.Trim <> "" Then
                Me.DeletedRecordIds &= ","
            End If

            Me.DeletedRecordIds &= "[" & rec.RecordUniqueId & "]"
        End Sub

        Protected Overridable Function InDeletedRecordIds(ByVal rec As EmployeesTableControlRow) As Boolean
            If Me.DeletedRecordIds Is Nothing OrElse Me.DeletedRecordIds.Trim = "" Then
                Return False
            End If

            Return Me.DeletedRecordIds.IndexOf("[" & rec.RecordUniqueId & "]") >= 0
        End Function

        Private _DeletedRecordIds As String
        Public Property DeletedRecordIds() As String
            Get
                Return Me._DeletedRecordIds
            End Get

            Set(ByVal value As String)
                Me._DeletedRecordIds = value
            End Set
        End Property
        
        ' Get the filters' data for LastNameFilter
        Protected Overridable Sub PopulateLastNameFilter(ByVal selectedValue As String, ByVal maxItems As Integer)
                    
            ' Setup the WHERE clause, including the base table if needed.
                
            Dim wc As WhereClause = Me.CreateWhereClause_LastNameFilter()
                  
            Dim orderBy As OrderBy = New OrderBy(False, True)
            orderBy.Add(EmployeesTable.LastName, OrderByItem.OrderDir.Asc)

            Dim list() As String = EmployeesTable.GetValues(EmployeesTable.LastName, wc, orderBy, maxItems)
            
            Me.LastNameFilter.Items.Clear()
            Dim itemValue As String
            
             For Each itemValue In list
                ' Create the item and add to the list.
                Dim fvalue As String
                If ( EmployeesTable.LastName.IsColumnValueTypeBoolean()) Then
                    fvalue = itemValue
                Else
                    fvalue = EmployeesTable.LastName.Format(itemValue)
                End If
                Dim item As ListItem = New ListItem(fvalue, itemValue)
                Me.LastNameFilter.Items.Add(item)
            Next
                    
      ' Add the All item.
            Me.LastNameFilter.Items.Insert(0, New ListItem(Page.GetResourceValue("Txt:All", "UseDAL"), "--ANY--"))	
        
            ' Set the selected value.
            SetSelectedValue(Me.LastNameFilter, selectedValue)

                
        End Sub
            
        ' Get the filters' data for PostalCodeFilter
        Protected Overridable Sub PopulatePostalCodeFilter(ByVal selectedValue As String, ByVal maxItems As Integer)
                    
            ' Setup the WHERE clause, including the base table if needed.
                
            Dim wc As WhereClause = Me.CreateWhereClause_PostalCodeFilter()
                  
            Dim orderBy As OrderBy = New OrderBy(False, True)
            orderBy.Add(EmployeesTable.PostalCode, OrderByItem.OrderDir.Asc)

            Dim list() As String = EmployeesTable.GetValues(EmployeesTable.PostalCode, wc, orderBy, maxItems)
            
            Me.PostalCodeFilter.Items.Clear()
            Dim itemValue As String
            
             For Each itemValue In list
                ' Create the item and add to the list.
                Dim fvalue As String
                If ( EmployeesTable.PostalCode.IsColumnValueTypeBoolean()) Then
                    fvalue = itemValue
                Else
                    fvalue = EmployeesTable.PostalCode.Format(itemValue)
                End If
                Dim item As ListItem = New ListItem(fvalue, itemValue)
                Me.PostalCodeFilter.Items.Add(item)
            Next
                    
      ' Add the All item.
            Me.PostalCodeFilter.Items.Insert(0, New ListItem(Page.GetResourceValue("Txt:All", "UseDAL"), "--ANY--"))	
        
            ' Set the selected value.
            SetSelectedValue(Me.PostalCodeFilter, selectedValue)

                
        End Sub
            
    ' Create a where clause for the filter EmployeesSearchArea.
        Public Overridable Function CreateWhereClause_EmployeesSearchArea() As WhereClause
      
      return new WhereClause()
        
        End Function			
            
    ' Create a where clause for the filter LastNameFilter.
        Public Overridable Function CreateWhereClause_LastNameFilter() As WhereClause
      
      return new WhereClause()
        
        End Function			
            
    ' Create a where clause for the filter PostalCodeFilter.
        Public Overridable Function CreateWhereClause_PostalCodeFilter() As WhereClause
      
      return new WhereClause()
        
        End Function			
            
        Protected Overridable Sub Control_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
            Try
                DbUtils.StartTransaction
                
                If Not Me.Page.ErrorOnPage AndAlso (Me.Page.IsPageRefresh OrElse Me.DataChanged OrElse Me.ResetData) Then
                    Me.LoadData()
                    Me.DataBind()
                End If
                
            Catch ex As Exception
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
        End Sub
        
        Protected Overrides Sub SaveControlsToSession()
            MyBase.SaveControlsToSession()

            ' Save filter controls to values to session.
        
            Me.SaveToSession(Me.EmployeesSearchArea, Me.EmployeesSearchArea.Text)
                  
            Me.SaveToSession(Me.LastNameFilter, Me.LastNameFilter.SelectedValue)
                  
            Me.SaveToSession(Me.PostalCodeFilter, Me.PostalCodeFilter.SelectedValue)
                  
            
            ' Save table control properties to the session.
            If Not Me.CurrentSortOrder Is Nothing Then
                Me.SaveToSession(Me, "Order_By", Me.CurrentSortOrder.ToXmlString())
            End If
            Me.SaveToSession(Me, "Page_Index", Me.PageIndex.ToString())
            Me.SaveToSession(Me, "Page_Size", Me.PageSize.ToString())
        
            Me.SaveToSession(Me, "DeletedRecordIds", Me.DeletedRecordIds)  
        
        End Sub
        
        Protected  Sub SaveControlsToSession_Ajax()
            ' Save filter controls to values to session.
          
      Me.SaveToSession("EmployeesSearchArea_Ajax", Me.EmployeesSearchArea.Text)
              
      Me.SaveToSession("LastNameFilter_Ajax", Me.LastNameFilter.SelectedValue)
              
      Me.SaveToSession("PostalCodeFilter_Ajax", Me.PostalCodeFilter.SelectedValue)
              
            HttpContext.Current.Session("AppRelativeVirtualPath") = Me.Page.AppRelativeVirtualPath
         
        End Sub
        
        Protected Overrides Sub ClearControlsFromSession()
            MyBase.ClearControlsFromSession()

            ' Clear filter controls values from the session.
        
            Me.RemoveFromSession(Me.EmployeesSearchArea)
            Me.RemoveFromSession(Me.LastNameFilter)
            Me.RemoveFromSession(Me.PostalCodeFilter)
            
            ' Clear table properties from the session.
            Me.RemoveFromSession(Me, "Order_By")
            Me.RemoveFromSession(Me, "Page_Index")
            Me.RemoveFromSession(Me, "Page_Size")
            
            Me.RemoveFromSession(Me, "DeletedRecordIds")  
            
        End Sub

        Protected Overrides Sub LoadViewState(ByVal savedState As Object)
            MyBase.LoadViewState(savedState)

            Dim orderByStr As String = CType(ViewState("EmployeesTableControl_OrderBy"), String)
            If Not orderByStr Is Nothing AndAlso orderByStr.Trim <> "" Then
                Me.CurrentSortOrder = BaseClasses.Data.OrderBy.FromXmlString(orderByStr)
            Else
                Me.CurrentSortOrder = New OrderBy(True, True)
            End If

            Dim pageIndex As String = CType(ViewState("Page_Index"), String)
            If Not pageIndex Is Nothing Then
                Me.PageIndex = CInt(pageIndex)
            End If

            Dim pageSize As String = CType(ViewState("Page_Size"), String)
            If Not pageSize Is Nothing Then
                Me.PageSize = CInt(pageSize)
            End If
        
            Me.DeletedRecordIds = CType(Me.ViewState("DeletedRecordIds"), String)
        
        End Sub

        Protected Overrides Function SaveViewState() As Object
            
            If Not Me.CurrentSortOrder Is Nothing Then
                Me.ViewState("EmployeesTableControl_OrderBy") = Me.CurrentSortOrder.ToXmlString()
            End If
            
            Me.ViewState("Page_Index") = Me.PageIndex
            Me.ViewState("Page_Size") = Me.PageSize
        
            Me.ViewState("DeletedRecordIds") = Me.DeletedRecordIds
        
            Return MyBase.SaveViewState()

        End Function

        ' Generate the event handling functions for pagination events.
        
        ' event handler for ImageButton
        Public Overridable Sub EmployeesPagination_FirstPage_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                
            Me.PageIndex = 0
            Me.DataChanged = True
      
            Catch ex As Exception
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesPagination_LastPage_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                
            Me.DisplayLastPage = True
            Me.DataChanged = True
      
            Catch ex As Exception
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesPagination_NextPage_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                
            Me.PageIndex += 1
            Me.DataChanged = True
      
            Catch ex As Exception
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
                  
        End Sub
            
        ' event handler for LinkButton
        Public Overridable Sub EmployeesPagination_PageSizeButton_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Try
                
            Me.DataChanged = True
      
            Me.PageSize = Integer.Parse(Me.EmployeesPagination.PageSize.Text)
      
            Me.PageIndex = Integer.Parse(Me.EmployeesPagination.CurrentPage.Text) - 1
          
            Catch ex As Exception
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
    
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesPagination_PreviousPage_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                
            If Me.PageIndex > 0 Then
                Me.PageIndex -= 1
                Me.DataChanged = True
            End If
      
            Catch ex As Exception
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
                  
        End Sub
            

        ' Generate the event handling functions for sorting events.
        
        ' event handler for FieldSort
        Public Overridable Sub AddressLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.Address)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.Address, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub BirthDateLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.BirthDate)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.BirthDate, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub CityLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.City)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.City, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub CountryLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.Country)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.Country, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub CreatedByLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.CreatedBy)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.CreatedBy, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub CreatedOnLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.CreatedOn)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.CreatedOn, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ExtensionLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.Extension)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.Extension, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub FirstNameLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.FirstName)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.FirstName, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub HireDateLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.HireDate)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.HireDate, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub HomePhoneLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.HomePhone)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.HomePhone, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub LastNameLabel1_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.LastName)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.LastName, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub LastUpdatedByLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.LastUpdatedBy)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.LastUpdatedBy, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub LastUpdatedOnLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.LastUpdatedOn)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.LastUpdatedOn, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub PostalCodeLabel1_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.PostalCode)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.PostalCode, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub RegionLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.Region)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.Region, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ReportsToLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.ReportsTo)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.ReportsTo, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub TitleLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.Title)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.Title, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub TitleOfCourtesyLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(EmployeesTable.TitleOfCourtesy)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(EmployeesTable.TitleOfCourtesy, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            

        ' Generate the event handling functions for button events.
        
        ' event handler for ImageButton
        Public Overridable Sub EmployeesCopyButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Dim url As String = "../Employees/AddEmployees.aspx?Employees={PK}"
            Dim shouldRedirect As Boolean = True
            Dim TargetKey As String = Nothing
            Dim DFKA As String = Nothing
            Dim id As String = Nothing
            Dim value As String = Nothing
            Try
                DbUtils.StartTransaction
                
            url = Me.ModifyRedirectUrl(url, "",False)
            url = Me.Page.ModifyRedirectUrl(url, "",False)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                shouldRedirect = False
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
            If shouldRedirect Then
                Me.Page.ShouldSaveControlsToSession = True
                Me.Page.Response.Redirect(url)
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.Page.ShouldSaveControlsToSession = True
            Me.Page.CloseWindow(True)
        
            End If              
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesDeleteButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                DbUtils.StartTransaction
                
            If(Not Me.Page.IsPageRefresh) Then
        
                Me.DeleteSelectedRecords(False)
          
            End If
      Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesEditButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Dim url As String = "../Employees/EditEmployees.aspx?Employees={PK}"
            Dim shouldRedirect As Boolean = True
            Dim TargetKey As String = Nothing
            Dim DFKA As String = Nothing
            Dim id As String = Nothing
            Dim value As String = Nothing
            Try
                DbUtils.StartTransaction
                
            url = Me.ModifyRedirectUrl(url, "",False)
            url = Me.Page.ModifyRedirectUrl(url, "",False)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                shouldRedirect = False
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
            If shouldRedirect Then
                Me.Page.ShouldSaveControlsToSession = True
                Me.Page.Response.Redirect(url)
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.Page.ShouldSaveControlsToSession = True
            Me.Page.CloseWindow(True)
        
            End If              
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesExportButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                DbUtils.StartTransaction
                
          ' Build the where clause based on the current filter and search criteria
          ' Create the Order By clause based on the user's current sorting preference.
          
              Dim wc As WhereClause = CreateWhereClause
              Dim orderBy As OrderBy = Nothing
              
              orderBy = CreateOrderBy
              
          ' Add each of the columns in order of export.
          Dim columns() as BaseColumn = New BaseColumn() { _
                       EmployeesTable.LastName, _ 
             EmployeesTable.FirstName, _ 
             EmployeesTable.Title, _ 
             EmployeesTable.TitleOfCourtesy, _ 
             EmployeesTable.BirthDate, _ 
             EmployeesTable.HireDate, _ 
             EmployeesTable.Address, _ 
             EmployeesTable.City, _ 
             EmployeesTable.Region, _ 
             EmployeesTable.PostalCode, _ 
             EmployeesTable.Country, _ 
             EmployeesTable.HomePhone, _ 
             EmployeesTable.Extension, _ 
             EmployeesTable.Notes, _ 
             EmployeesTable.ReportsTo, _ 
             EmployeesTable.CreatedOn, _ 
             EmployeesTable.CreatedBy, _ 
             EmployeesTable.LastUpdatedOn, _ 
             EmployeesTable.LastUpdatedBy, _ 
             Nothing}
            Dim rep as ExportData = New ExportData(EmployeesTable.Instance, wc, orderBy, columns)
            rep.ExportToCSV(Me.Page.Response)
        Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesExportExcelButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                DbUtils.StartTransaction
                
            ' To customize the columns or the format, override this function in Section 1 of the page 
            ' and modify it to your liking.
            ' Build the where clause based on the current filter and search criteria
            ' Create the Order By clause based on the user's current sorting preference.
          
              Dim wc As WhereClause = CreateWhereClause
              Dim orderBy As OrderBy = Nothing
              
              orderBy = CreateOrderBy
              
            ' Create an instance of the Excel report class with the table class, where clause and order by.
            Dim excelReport as ExportData = New ExportData(EmployeesTable.Instance, wc, orderBy)
            ' Add each of the columns in order of export.
            ' To customize the data type, change the second parameter of the new ExcelColumn to be
            ' a format string from Excel's Format Cell menu. For example "dddd, mmmm dd, yyyy h:mm AM/PM;@", "#,##0.00"
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.LastName, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.FirstName, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.Title, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.TitleOfCourtesy, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.BirthDate, "Short Date"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.HireDate, "Short Date"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.Address, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.City, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.Region, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.PostalCode, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.Country, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.HomePhone, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.Extension, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.Notes, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.ReportsTo, "0"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.CreatedOn, "Short Date"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.CreatedBy, "Default"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.LastUpdatedOn, "Short Date"))
             excelReport.AddColumn(New ExcelColumn(EmployeesTable.LastUpdatedBy, "Default"))

            excelReport.ExportToExcel(Me.Page.Response)
            Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesImportButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Dim url As String = "../Shared/SelectFileToImport.aspx?TableName=Employees"
            Try
                DbUtils.StartTransaction
                
            Dim script As String = "window.open('" &  Me.Page.EncryptUrlParameter(url) &  "','importWindow', 'width=700, height=500,top=' +(screen.availHeight-500)/2 + ',left=' + (screen.availWidth-700)/2+ ', resizable=yes, scrollbars=yes,modal=yes');"
            'If (Not Me.Page.ClientScript.IsStartupScriptRegistered("OpenPopup")) Then
            ScriptManager.RegisterStartupScript(Me.Page, Page.GetType(), "OpenPopup", script, true)
            'End If
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesNewButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Dim url As String = "../Employees/AddEmployees.aspx"
            Dim shouldRedirect As Boolean = True
            Dim TargetKey As String = Nothing
            Dim DFKA As String = Nothing
            Dim id As String = Nothing
            Dim value As String = Nothing
            Try
                DbUtils.StartTransaction
                
            url = Me.ModifyRedirectUrl(url, "",False)
            url = Me.Page.ModifyRedirectUrl(url, "",False)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                shouldRedirect = False
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
            If shouldRedirect Then
                Me.Page.ShouldSaveControlsToSession = True
                Me.Page.Response.Redirect(url)
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.Page.ShouldSaveControlsToSession = True
            Me.Page.CloseWindow(True)
        
            End If              
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesPDFButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                DbUtils.StartTransaction
                
                Dim report As PDFReport = New PDFReport 
                report.SpecificReportFileName = Page.Server.MapPath("ShowEmployeesTable2.EmployeesPDFButton.report")
                ' report.Title replaces the value tag of page header and footer containing ${ReportTitle}
                report.Title = "Employees"
                ' If ShowEmployeesTable2.EmployeesPDFButton.report specifies a valid report template,
                ' AddColumn method will generate a report template.   
                ' Each AddColumn method-call specifies a column
                ' The 1st parameter represents the text of the column header
                ' The 2nd parameter represents the horizontal alignment of the column header
                ' The 3rd parameter represents the text format of the column detail
                ' The 4th parameter represents the horizontal alignment of the column detail
                ' The 5th parameter represents the relative width of the column   			
                 report.AddColumn(EmployeesTable.LastName.Name, ReportEnum.Align.Left, "${EmployeesTable.LastName.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.FirstName.Name, ReportEnum.Align.Left, "${EmployeesTable.FirstName.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.Title.Name, ReportEnum.Align.Left, "${EmployeesTable.Title.Name}", ReportEnum.Align.Left, 24)
                 report.AddColumn(EmployeesTable.TitleOfCourtesy.Name, ReportEnum.Align.Left, "${EmployeesTable.TitleOfCourtesy.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.BirthDate.Name, ReportEnum.Align.Left, "${EmployeesTable.BirthDate.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.HireDate.Name, ReportEnum.Align.Left, "${EmployeesTable.HireDate.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.Address.Name, ReportEnum.Align.Left, "${EmployeesTable.Address.Name}", ReportEnum.Align.Left, 30)
                 report.AddColumn(EmployeesTable.City.Name, ReportEnum.Align.Left, "${EmployeesTable.City.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.Region.Name, ReportEnum.Align.Left, "${EmployeesTable.Region.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.PostalCode.Name, ReportEnum.Align.Left, "${EmployeesTable.PostalCode.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.Country.Name, ReportEnum.Align.Left, "${EmployeesTable.Country.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.HomePhone.Name, ReportEnum.Align.Left, "${EmployeesTable.HomePhone.Name}", ReportEnum.Align.Left, 19)
                 report.AddColumn(EmployeesTable.Extension.Name, ReportEnum.Align.Left, "${EmployeesTable.Extension.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.Notes.Name, ReportEnum.Align.Left, "${EmployeesTable.Notes.Name}", ReportEnum.Align.Left, 30)
                 report.AddColumn(EmployeesTable.ReportsTo.Name, ReportEnum.Align.Right, "${EmployeesTable.ReportsTo.Name}", ReportEnum.Align.Right, 15)
                 report.AddColumn(EmployeesTable.CreatedOn.Name, ReportEnum.Align.Left, "${EmployeesTable.CreatedOn.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.CreatedBy.Name, ReportEnum.Align.Left, "${EmployeesTable.CreatedBy.Name}", ReportEnum.Align.Left, 30)
                 report.AddColumn(EmployeesTable.LastUpdatedOn.Name, ReportEnum.Align.Left, "${EmployeesTable.LastUpdatedOn.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.LastUpdatedBy.Name, ReportEnum.Align.Left, "${EmployeesTable.LastUpdatedBy.Name}", ReportEnum.Align.Left, 30)

              Dim whereClause As WhereClause = CreateWhereClause
              
              Dim orderBy As OrderBy = CreateOrderBy
                
                Dim rowsPerQuery As Integer = 1000 
                Dim pageNum As Integer = 0 
                Dim recordCount As Integer = 0 
                Dim totalRecords As Integer = EmployeesTable.GetRecordCount(whereClause)
                                
                report.Page = Page.GetResourceValue("Txt:Page", "UseDAL")
                report.ApplicationPath = Me.Page.MapPath(Page.Request.ApplicationPath)

                Dim columns As ColumnList = EmployeesTable.GetColumnList()
                Dim records As EmployeesRecord() = Nothing
                Do 
                    records = EmployeesTable.GetRecords(whereClause, orderBy, pageNum, rowsPerQuery)
                    If Not (records Is Nothing) AndAlso records.Length > 0 AndAlso whereClause.RunQuery Then 
                        For Each record As EmployeesRecord In records 
                            ' AddData method takes four parameters   
                            ' The 1st parameters represent the data format
                            ' The 2nd parameters represent the data value
                            ' The 3rd parameters represent the default alignment of column using the data
                            ' The 4th parameters represent the maximum length of the data value being shown
                             report.AddData("${EmployeesTable.LastName.Name}", record.Format(EmployeesTable.LastName), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.FirstName.Name}", record.Format(EmployeesTable.FirstName), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Title.Name}", record.Format(EmployeesTable.Title), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.TitleOfCourtesy.Name}", record.Format(EmployeesTable.TitleOfCourtesy), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.BirthDate.Name}", record.Format(EmployeesTable.BirthDate), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.HireDate.Name}", record.Format(EmployeesTable.HireDate), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Address.Name}", record.Format(EmployeesTable.Address), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.City.Name}", record.Format(EmployeesTable.City), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Region.Name}", record.Format(EmployeesTable.Region), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.PostalCode.Name}", record.Format(EmployeesTable.PostalCode), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Country.Name}", record.Format(EmployeesTable.Country), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.HomePhone.Name}", record.Format(EmployeesTable.HomePhone), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Extension.Name}", record.Format(EmployeesTable.Extension), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Notes.Name}", record.Format(EmployeesTable.Notes), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.ReportsTo.Name}", record.Format(EmployeesTable.ReportsTo), ReportEnum.Align.Right, 100)
                             report.AddData("${EmployeesTable.CreatedOn.Name}", record.Format(EmployeesTable.CreatedOn), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.CreatedBy.Name}", record.Format(EmployeesTable.CreatedBy), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.LastUpdatedOn.Name}", record.Format(EmployeesTable.LastUpdatedOn), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.LastUpdatedBy.Name}", record.Format(EmployeesTable.LastUpdatedBy), ReportEnum.Align.Left, 100)

                            report.WriteRow 
                        Next 
                        pageNum = pageNum + 1
                        recordCount += records.Length 
                    End If 
                Loop While Not (records Is Nothing) AndAlso recordCount < totalRecords  AndAlso whereClause.RunQuery 
                report.Close 
                BaseClasses.Utils.NetUtils.WriteResponseBinaryAttachment(Me.Page.Response, report.Title + ".pdf", report.ReportInByteArray, 0, true)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesRefreshButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                
            DirectCast(Me.Page.FindControlRecursively("EmployeesTableControl"), EmployeesTableControl).ResetData = True
                
            Catch ex As Exception
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesResetButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                
              Me.LastNameFilter.ClearSelection
              Me.PostalCodeFilter.ClearSelection
              Me.EmployeesSearchArea.Text = ""
              Me.CurrentSortOrder.Reset()
              If Me.InSession(Me, "Order_By") Then
                  Me.CurrentSortOrder = OrderBy.FromXmlString(Me.GetFromSession(Me, "Order_By", Nothing))
              Else
                  Me.CurrentSortOrder = New OrderBy(True, True)
          
              End If
              

        Me.DataChanged = True
            
            Catch ex As Exception
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
                  
        End Sub
            
        ' event handler for ImageButton
        Public Overridable Sub EmployeesWordButton_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                DbUtils.StartTransaction
                
                Dim report As WordReport = New WordReport
                report.SpecificReportFileName = Page.Server.MapPath("ShowEmployeesTable2.EmployeesWordButton.word")
                ' report.Title replaces the value tag of page header and footer containing ${ReportTitle}
                report.Title = "Employees"
                ' If ShowEmployeesTable2.EmployeesWordButton.report specifies a valid report template,
                ' AddColumn method will generate a report template.
                ' Each AddColumn method-call specifies a column
                ' The 1st parameter represents the text of the column header
                ' The 2nd parameter represents the horizontal alignment of the column header
                ' The 3rd parameter represents the text format of the column detail
                ' The 4th parameter represents the horizontal alignment of the column detail
                ' The 5th parameter represents the relative width of the column
                 report.AddColumn(EmployeesTable.LastName.Name, ReportEnum.Align.Left, "${EmployeesTable.LastName.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.FirstName.Name, ReportEnum.Align.Left, "${EmployeesTable.FirstName.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.Title.Name, ReportEnum.Align.Left, "${EmployeesTable.Title.Name}", ReportEnum.Align.Left, 24)
                 report.AddColumn(EmployeesTable.TitleOfCourtesy.Name, ReportEnum.Align.Left, "${EmployeesTable.TitleOfCourtesy.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.BirthDate.Name, ReportEnum.Align.Left, "${EmployeesTable.BirthDate.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.HireDate.Name, ReportEnum.Align.Left, "${EmployeesTable.HireDate.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.Address.Name, ReportEnum.Align.Left, "${EmployeesTable.Address.Name}", ReportEnum.Align.Left, 30)
                 report.AddColumn(EmployeesTable.City.Name, ReportEnum.Align.Left, "${EmployeesTable.City.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.Region.Name, ReportEnum.Align.Left, "${EmployeesTable.Region.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.PostalCode.Name, ReportEnum.Align.Left, "${EmployeesTable.PostalCode.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.Country.Name, ReportEnum.Align.Left, "${EmployeesTable.Country.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.HomePhone.Name, ReportEnum.Align.Left, "${EmployeesTable.HomePhone.Name}", ReportEnum.Align.Left, 19)
                 report.AddColumn(EmployeesTable.Extension.Name, ReportEnum.Align.Left, "${EmployeesTable.Extension.Name}", ReportEnum.Align.Left, 15)
                 report.AddColumn(EmployeesTable.Notes.Name, ReportEnum.Align.Left, "${EmployeesTable.Notes.Name}", ReportEnum.Align.Left, 30)
                 report.AddColumn(EmployeesTable.ReportsTo.Name, ReportEnum.Align.Right, "${EmployeesTable.ReportsTo.Name}", ReportEnum.Align.Right, 15)
                 report.AddColumn(EmployeesTable.CreatedOn.Name, ReportEnum.Align.Left, "${EmployeesTable.CreatedOn.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.CreatedBy.Name, ReportEnum.Align.Left, "${EmployeesTable.CreatedBy.Name}", ReportEnum.Align.Left, 30)
                 report.AddColumn(EmployeesTable.LastUpdatedOn.Name, ReportEnum.Align.Left, "${EmployeesTable.LastUpdatedOn.Name}", ReportEnum.Align.Left, 20)
                 report.AddColumn(EmployeesTable.LastUpdatedBy.Name, ReportEnum.Align.Left, "${EmployeesTable.LastUpdatedBy.Name}", ReportEnum.Align.Left, 30)

              Dim whereClause As WhereClause = CreateWhereClause
              
              Dim orderBy As OrderBy = CreateOrderBy
                
                Dim rowsPerQuery As Integer = 1000
                Dim pageNum As Integer = 0
                Dim recordCount As Integer = 0
                Dim totalRecords As Integer = EmployeesTable.GetRecordCount(whereClause)

                report.Page = Page.GetResourceValue("Txt:Page", "UseDAL")
                report.ApplicationPath = Me.Page.MapPath(Page.Request.ApplicationPath)

                Dim columns As ColumnList = EmployeesTable.GetColumnList()
                Dim records As EmployeesRecord() = Nothing
                Do
                    records = EmployeesTable.GetRecords(whereClause, orderBy, pageNum, rowsPerQuery)
                    If Not (records Is Nothing) AndAlso records.Length > 0 AndAlso whereClause.RunQuery Then
                        For Each record As EmployeesRecord In records
                            ' AddData method takes four parameters
                            ' The 1st parameters represent the data format
                            ' The 2nd parameters represent the data value
                            ' The 3rd parameters represent the default alignment of column using the data
                            ' The 4th parameters represent the maximum length of the data value being shown
                             report.AddData("${EmployeesTable.LastName.Name}", record.Format(EmployeesTable.LastName), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.FirstName.Name}", record.Format(EmployeesTable.FirstName), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Title.Name}", record.Format(EmployeesTable.Title), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.TitleOfCourtesy.Name}", record.Format(EmployeesTable.TitleOfCourtesy), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.BirthDate.Name}", record.Format(EmployeesTable.BirthDate), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.HireDate.Name}", record.Format(EmployeesTable.HireDate), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Address.Name}", record.Format(EmployeesTable.Address), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.City.Name}", record.Format(EmployeesTable.City), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Region.Name}", record.Format(EmployeesTable.Region), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.PostalCode.Name}", record.Format(EmployeesTable.PostalCode), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Country.Name}", record.Format(EmployeesTable.Country), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.HomePhone.Name}", record.Format(EmployeesTable.HomePhone), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Extension.Name}", record.Format(EmployeesTable.Extension), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.Notes.Name}", record.Format(EmployeesTable.Notes), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.ReportsTo.Name}", record.Format(EmployeesTable.ReportsTo), ReportEnum.Align.Right, 100)
                             report.AddData("${EmployeesTable.CreatedOn.Name}", record.Format(EmployeesTable.CreatedOn), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.CreatedBy.Name}", record.Format(EmployeesTable.CreatedBy), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.LastUpdatedOn.Name}", record.Format(EmployeesTable.LastUpdatedOn), ReportEnum.Align.Left, 100)
                             report.AddData("${EmployeesTable.LastUpdatedBy.Name}", record.Format(EmployeesTable.LastUpdatedBy), ReportEnum.Align.Left, 100)

                            report.WriteRow
                        Next
                        pageNum = pageNum + 1
                        recordCount += records.Length
                    End If
                Loop While Not (records Is Nothing) AndAlso recordCount < totalRecords AndAlso whereClause.RunQuery 
                report.save
                BaseClasses.Utils.NetUtils.WriteResponseBinaryAttachment(Me.Page.Response, report.Title + ".doc", report.ReportInByteArray, 0, true)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
                  
        End Sub
            
        ' event handler for Button with Layout
        Public Overridable Sub EmployeesSearchButton_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Try
                
          Me.DataChanged = True
      
            Catch ex As Exception
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
    
        End Sub
            
      

        ' Generate the event handling functions for filter and search events.
        
        ' event handler for FieldFilter
        Protected Overridable Sub LastNameFilter_SelectedIndexChanged(ByVal sender As Object, ByVal args As EventArgs)
           Me.DataChanged = True
        End Sub
            
        ' event handler for FieldFilter
        Protected Overridable Sub PostalCodeFilter_SelectedIndexChanged(ByVal sender As Object, ByVal args As EventArgs)
           Me.DataChanged = True
        End Sub
            

        ' pagination properties
        Private _PageSize As Integer
        Public Property PageSize() As Integer
            Get
                Return Me._PageSize
            End Get
            Set(ByVal value As Integer)
                Me._PageSize = value
            End Set
        End Property

        Private _PageIndex As Integer
        Public Property PageIndex() As Integer
            Get
                ' Return the PageIndex
                Return Me._PageIndex
            End Get
            Set(ByVal value As Integer)
                Me._PageIndex = value
            End Set
        End Property

        Private _TotalRecords As Integer
        Public Property TotalRecords() As Integer
            Get
                Return Me._TotalRecords
            End Get
            Set(ByVal value As Integer)
                If Me.PageSize > 0 Then
                    Me.TotalPages = CInt(Math.Ceiling(value / Me.PageSize))
                End If

                Me._TotalRecords = value
            End Set
        End Property

        Private _TotalPages As Integer
        Public Property TotalPages() As Integer
            Get
                Return Me._TotalPages
            End Get
            Set(ByVal value As Integer)
                Me._TotalPages = value
            End Set
        End Property

        Private _DisplayLastPage As Boolean
        Public Property DisplayLastPage() As Boolean
            Get
                Return Me._DisplayLastPage
            End Get
            Set(ByVal value As Boolean)
                Me._DisplayLastPage = value
            End Set
        End Property

        Private _DataChanged As Boolean = False
        Public Property DataChanged() As Boolean
            Get
                Return Me._DataChanged
            End Get
            Set(ByVal value As Boolean)
                Me._DataChanged = value
            End Set
        End Property
        
        Private _ResetData As Boolean = False
        Public Property ResetData() As Boolean
            Get
                Return Me._ResetData
            End Get
            Set(ByVal value As Boolean)
                Me._ResetData = value
            End Set
        End Property

        Private _AddNewRecord As Integer = 0
        Public Property AddNewRecord() As Integer
            Get
                Return Me._AddNewRecord
            End Get
            Set(ByVal value As Integer)
                Me._AddNewRecord = value
            End Set
        End Property

        Private _CurrentSortOrder As OrderBy = Nothing
        Public Property CurrentSortOrder() As OrderBy
            Get
                Return Me._CurrentSortOrder
            End Get
            Set(ByVal value As BaseClasses.Data.OrderBy)
                Me._CurrentSortOrder = value
            End Set
        End Property

        Private _DataSource() As EmployeesRecord = Nothing
        Public Property DataSource() As EmployeesRecord ()
            Get
                Return Me._DataSource
            End Get
            Set(ByVal value() As EmployeesRecord)
                Me._DataSource = value
            End Set
        End Property

#Region "Helper Properties"
        
        Public ReadOnly Property AddressLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "AddressLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property BirthDateLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "BirthDateLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ChildTableLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ChildTableLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property CityLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "CityLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property CountryLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "CountryLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property CreatedByLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "CreatedByLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property CreatedOnLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "CreatedOnLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesCopyButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesCopyButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesDeleteButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesDeleteButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesEditButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesEditButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesExportButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesExportButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesExportExcelButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesExportExcelButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesImportButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesImportButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesNewButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesNewButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesPagination() As UseDAL.UI.IPagination
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesPagination"), UseDAL.UI.IPagination)
          End Get
          End Property
        
        Public ReadOnly Property EmployeesPDFButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesPDFButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesRefreshButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesRefreshButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesResetButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesResetButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesSearchArea() As System.Web.UI.WebControls.TextBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesSearchArea"), System.Web.UI.WebControls.TextBox)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesSearchButton() As UseDAL.UI.IThemeButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesSearchButton"), UseDAL.UI.IThemeButton)
          End Get
          End Property
        
        Public ReadOnly Property EmployeesTitle() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesTitle"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesToggleAll() As System.Web.UI.WebControls.CheckBox
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesToggleAll"), System.Web.UI.WebControls.CheckBox)
            End Get
        End Property
        
        Public ReadOnly Property EmployeesWordButton() As System.Web.UI.WebControls.ImageButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "EmployeesWordButton"), System.Web.UI.WebControls.ImageButton)
            End Get
        End Property
        
        Public ReadOnly Property ExtensionLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ExtensionLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property FirstNameLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "FirstNameLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property HireDateLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "HireDateLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property HomePhoneLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "HomePhoneLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property LastNameFilter() As System.Web.UI.WebControls.DropDownList
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "LastNameFilter"), System.Web.UI.WebControls.DropDownList)
            End Get
        End Property
        
        Public ReadOnly Property LastNameLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "LastNameLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property LastNameLabel1() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "LastNameLabel1"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property LastUpdatedByLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "LastUpdatedByLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property LastUpdatedOnLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "LastUpdatedOnLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property NotesLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "NotesLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property PhotoLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "PhotoLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property PostalCodeFilter() As System.Web.UI.WebControls.DropDownList
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "PostalCodeFilter"), System.Web.UI.WebControls.DropDownList)
            End Get
        End Property
        
        Public ReadOnly Property PostalCodeLabel() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "PostalCodeLabel"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
        
        Public ReadOnly Property PostalCodeLabel1() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "PostalCodeLabel1"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property RegionLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "RegionLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ReportsToLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ReportsToLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property TitleLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "TitleLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property TitleOfCourtesyLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "TitleOfCourtesyLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
#End Region

#Region "Helper Functions"
        
        Public Overrides Overloads Function ModifyRedirectUrl(url As String, arg As String, ByVal bEncrypt As Boolean) As String
            Return Me.Page.EvaluateExpressions(url, arg, bEncrypt, Me)
        End Function
      
           Public Overrides Overloads Function EvaluateExpressions(url As String, arg As String, ByVal bEncrypt As Boolean) As String
            Dim needToProcess As Boolean = AreAnyUrlParametersForMe(url, arg)
            If (needToProcess) Then
                Dim recCtl As EmployeesTableControlRow = Me.GetSelectedRecordControl()
                If recCtl Is Nothing AndAlso url.IndexOf("{") >= 0 Then
                    ' Localization.
                    Throw New Exception(Page.GetResourceValue("Err:NoRecSelected", "UseDAL"))
                End If

                Dim rec As EmployeesRecord = Nothing
                If Not recCtl Is Nothing Then
                    rec = recCtl.GetRecord()
                End If
                Return EvaluateExpressions(url, arg, rec, bEncrypt)
            End If
            Return url
        End Function
          
        Public Overridable Function GetSelectedRecordIndex() As Integer
            Dim counter As Integer = 0
            Dim recControl As EmployeesTableControlRow
            For Each recControl In Me.GetRecordControls()
                If recControl.EmployeesRecordRowSelection.Checked Then
                    Return counter
                End If
                counter += 1
            Next
            Return -1
        End Function
        
        Public Overridable Function GetSelectedRecordControl() As EmployeesTableControlRow
            Dim selectedList() As EmployeesTableControlRow = Me.GetSelectedRecordControls()
            If selectedList.Length = 0 Then
                Return Nothing
            End If
            Return selectedList(0)
          
        End Function

        Public Overridable Function GetSelectedRecordControls() As EmployeesTableControlRow()
        
            Dim selectedList As ArrayList = New ArrayList(25)
            Dim recControl As EmployeesTableControlRow
            For Each recControl In Me.GetRecordControls()
                If recControl.EmployeesRecordRowSelection.Checked Then
                    selectedList.Add(recControl)
                End If
            Next
            Return DirectCast(selectedList.ToArray(GetType(EmployeesTableControlRow)), EmployeesTableControlRow())
          
        End Function

        Public Overridable Sub DeleteSelectedRecords(ByVal deferDeletion As Boolean)
            Dim recList() As EmployeesTableControlRow = Me.GetSelectedRecordControls()
            If recList.Length = 0 Then
                ' Localization.
                Throw New Exception(Page.GetResourceValue("Err:NoRecSelected", "UseDAL"))
            End If
            
            Dim recCtl As EmployeesTableControlRow
            For Each recCtl In recList
                If deferDeletion Then
                    If Not recCtl.IsNewRecord Then
                
                        Me.AddToDeletedRecordIds(recCtl)
                  
                    End If
                    recCtl.Visible = False
                
                    recCtl.EmployeesRecordRowSelection.Checked = False
                
                Else
                
                    recCtl.Delete()
                    Me.DataChanged = True
                    Me.ResetData = True
                  
                End If
            Next
        End Sub

        Public Function GetRecordControls() As EmployeesTableControlRow()
            Dim recList As ArrayList = New ArrayList()
            Dim rep As System.Web.UI.WebControls.Repeater = CType(Me.FindControl("EmployeesTableControlRepeater"), System.Web.UI.WebControls.Repeater)
      If rep is Nothing Then Return Nothing
            Dim repItem As System.Web.UI.WebControls.RepeaterItem

            For Each repItem In rep.Items
                Dim recControl As EmployeesTableControlRow = DirectCast(repItem.FindControl("EmployeesTableControlRow"), EmployeesTableControlRow)
                recList.Add(recControl)
            Next

            Return DirectCast(recList.ToArray(GetType(EmployeesTableControlRow)), EmployeesTableControlRow())
        End Function

        Public Shadows ReadOnly Property Page() As BaseApplicationPage
            Get
                Return DirectCast(MyBase.Page, BaseApplicationPage)
            End Get
        End Property

#End Region

    

End Class

  
' Base class for the OrdersTableControlRow control on the ShowEmployeesTable2 page.
' Do not modify this class. Instead override any method in OrdersTableControlRow.
Public Class BaseOrdersTableControlRow
        Inherits UseDAL.UI.BaseApplicationRecordControl

        '  To customize, override this method in OrdersTableControlRow.
      Protected Overridable Sub Control_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init

      
      
            ' Register the event handlers.
        
              AddHandler Me.CustomerID.Click, AddressOf CustomerID_Click
            
        End Sub

        '  To customize, override this method in OrdersTableControlRow.
        Protected Overridable Sub Control_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
    
    End Sub

        ' Read data from database.  To customize, override this method in OrdersTableControlRow.
        Public Overridable Sub LoadData()        
        
            If Not Me.RecordUniqueId Is Nothing AndAlso Me.RecordUniqueId.Trim <> "" Then
                Me.DataSource = OrdersTable.GetRecord(Me.RecordUniqueId, True)
                Return
            End If
        
            ' Since this is a row in the table, the data for this row is loaded by the 
            ' LoadData method of the BaseOrdersTableControl when the data for the entire
            ' table is loaded.
            Me.DataSource = New OrdersRecord()
          
        End Sub

        ' Populate the UI controls using the DataSource.  To customize, override this method in OrdersTableControlRow.
        Public Overrides Sub DataBind()

            MyBase.DataBind()

            ' Make sure that the DataSource is initialized.
            If Me.DataSource Is Nothing Then
                Return
            End If
        
      
            ' For each field, check to see if a value is specified.  If a value is specified,
            ' then format the value for display.  If no value is specified, use the default value (formatted).

        
            If Me.DataSource.CustomerIDSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.CustomerID)
                Me.CustomerID.Text = formattedValue
              
            Else      
                Me.CustomerID.Text = OrdersTable.CustomerID.Format(OrdersTable.CustomerID.DefaultValue)
              
            End If
                    
            If Me.DataSource.FreightSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.Freight, "$#,##0.00;($#,##0.00)")
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.Freight.Text = formattedValue
              
            Else      
                Me.Freight.Text = OrdersTable.Freight.Format(OrdersTable.Freight.DefaultValue, "$#,##0.00;($#,##0.00)")
              
            End If
                    
            If Me.Freight.Text Is Nothing _
                OrElse Me.Freight.Text.Trim() = "" Then
                Me.Freight.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.OrderDateSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.OrderDate)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.OrderDate.Text = formattedValue
              
            Else      
                Me.OrderDate.Text = OrdersTable.OrderDate.Format(OrdersTable.OrderDate.DefaultValue)
              
            End If
                    
            If Me.OrderDate.Text Is Nothing _
                OrElse Me.OrderDate.Text.Trim() = "" Then
                Me.OrderDate.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.RequiredDateSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.RequiredDate)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.RequiredDate.Text = formattedValue
              
            Else      
                Me.RequiredDate.Text = OrdersTable.RequiredDate.Format(OrdersTable.RequiredDate.DefaultValue)
              
            End If
                    
            If Me.RequiredDate.Text Is Nothing _
                OrElse Me.RequiredDate.Text.Trim() = "" Then
                Me.RequiredDate.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ShipAddressSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.ShipAddress)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ShipAddress.Text = formattedValue
              
            Else      
                Me.ShipAddress.Text = OrdersTable.ShipAddress.Format(OrdersTable.ShipAddress.DefaultValue)
              
            End If
                    
            If Me.ShipAddress.Text Is Nothing _
                OrElse Me.ShipAddress.Text.Trim() = "" Then
                Me.ShipAddress.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ShipCitySpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.ShipCity)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ShipCity.Text = formattedValue
              
            Else      
                Me.ShipCity.Text = OrdersTable.ShipCity.Format(OrdersTable.ShipCity.DefaultValue)
              
            End If
                    
            If Me.ShipCity.Text Is Nothing _
                OrElse Me.ShipCity.Text.Trim() = "" Then
                Me.ShipCity.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ShipCountrySpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.ShipCountry)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ShipCountry.Text = formattedValue
              
            Else      
                Me.ShipCountry.Text = OrdersTable.ShipCountry.Format(OrdersTable.ShipCountry.DefaultValue)
              
            End If
                    
            If Me.ShipCountry.Text Is Nothing _
                OrElse Me.ShipCountry.Text.Trim() = "" Then
                Me.ShipCountry.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ShipNameSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.ShipName)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ShipName.Text = formattedValue
              
            Else      
                Me.ShipName.Text = OrdersTable.ShipName.Format(OrdersTable.ShipName.DefaultValue)
              
            End If
                    
            If Me.ShipName.Text Is Nothing _
                OrElse Me.ShipName.Text.Trim() = "" Then
                Me.ShipName.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ShippedDateSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.ShippedDate)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ShippedDate.Text = formattedValue
              
            Else      
                Me.ShippedDate.Text = OrdersTable.ShippedDate.Format(OrdersTable.ShippedDate.DefaultValue)
              
            End If
                    
            If Me.ShippedDate.Text Is Nothing _
                OrElse Me.ShippedDate.Text.Trim() = "" Then
                Me.ShippedDate.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ShipPostalCodeSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.ShipPostalCode)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ShipPostalCode.Text = formattedValue
              
            Else      
                Me.ShipPostalCode.Text = OrdersTable.ShipPostalCode.Format(OrdersTable.ShipPostalCode.DefaultValue)
              
            End If
                    
            If Me.ShipPostalCode.Text Is Nothing _
                OrElse Me.ShipPostalCode.Text.Trim() = "" Then
                Me.ShipPostalCode.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ShipRegionSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.ShipRegion)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ShipRegion.Text = formattedValue
              
            Else      
                Me.ShipRegion.Text = OrdersTable.ShipRegion.Format(OrdersTable.ShipRegion.DefaultValue)
              
            End If
                    
            If Me.ShipRegion.Text Is Nothing _
                OrElse Me.ShipRegion.Text.Trim() = "" Then
                Me.ShipRegion.Text = "&nbsp;"
            End If
                  
            If Me.DataSource.ShipViaSpecified Then
                Dim formattedValue As String = Me.DataSource.Format(OrdersTable.ShipVia)
                formattedValue = HttpUtility.HtmlEncode(formattedValue)
                If Not formattedValue is Nothing Then
                              
                    Dim maxLength as Integer = Len(formattedValue)
                    If (maxLength > CType(100, Integer)) Then
                        maxLength = CType(100, Integer)
                        
                    End If                    
                        If maxLength = CType(100, Integer) Then
                            formattedValue= NetUtils.EncodeStringForHtmlDisplay(formattedValue.SubString(0,MaxLength))
                            formattedValue = formattedValue & "..."
                            
                        End If
                    
                End If  
                            
                Me.ShipVia.Text = formattedValue
              
            Else      
                Me.ShipVia.Text = OrdersTable.ShipVia.Format(OrdersTable.ShipVia.DefaultValue)
              
            End If
                    
            If Me.ShipVia.Text Is Nothing _
                OrElse Me.ShipVia.Text.Trim() = "" Then
                Me.ShipVia.Text = "&nbsp;"
            End If
                  
            Me.IsNewRecord = True
            If Me.DataSource.IsCreated Then
                Me.IsNewRecord = False
        
                Me.RecordUniqueId = Me.DataSource.GetID.ToXmlString()
            End If

            

            ' Load data for each record and table UI control.
            ' Ordering is important because child controls get 
            ' their parent ids from their parent UI controls.
            Dim shouldResetControl as Boolean = False
            
      End Sub

        
        
        ' To customize, override this method in OrdersTableControlRow.
        Public Overridable Sub SaveData()

            ' 1. Load the existing record from the database. Since we save the entire record, this ensures 
            ' that fields that are not displayed also properly initialized.
            Me.LoadData()
        
        Dim employeesTableControlObj as EmployeesTableControl
        
  
          employeesTableControlObj = DirectCast(Me.Page.FindControlRecursively("EmployeesTableControl"), EmployeesTableControl)
          If (Not IsNothing(employeesTableControlObj) AndAlso IsNothing(employeesTableControlObj.DataSource)) 
                ' Load the record if it is not loaded yet.
                employeesTableControlObj.LoadData()
            End If
            If (IsNothing(employeesTableControlObj) OrElse IsNothing(employeesTableControlObj.DataSource)) 
                ' Get the error message from the application resource file.
                Throw New Exception(Page.GetResourceValue("Err:NoParentRecId", "UseDAL"))
            End If
            
              
            ' 2. Validate the data.  Override in OrdersTableControlRow to add custom validation.
            Me.Validate()

            ' 3. Set the values in the record with data from UI controls.  Override in OrdersTableControlRow to set additional fields.
            Me.GetUIData()

            ' 4. Save in the database.
            ' We should not save the record if the data did not change. This
            ' will save a database hit and avoid triggering any database triggers.
            If Me.DataSource.IsAnyValueChanged Then
                ' Save record to database but do not commit.
                ' Auto generated ids are available after saving for use by child (dependent) records.
                Me.DataSource.Save()
              
                DirectCast(GetParentControlObject(Me, "OrdersTableControl"), OrdersTableControl).DataChanged = True
                DirectCast(GetParentControlObject(Me, "OrdersTableControl"), OrdersTableControl).ResetData = True
            End If
            Me.DataChanged = True
            Me.ResetData = True
            ' Reseting of Me.IsNewRecord is moved to Save button's click even handler.
            ' Me.IsNewRecord() = False
            
        End Sub

        ' To customize, override this method in OrdersTableControlRow.
        Public Overridable Sub GetUIData()
            
        End Sub

        
      
        ' To customize, override this method in OrdersTableControlRow.
        Public Overridable Function CreateWhereClause() As WhereClause
        
            Return Nothing
          
        End Function
        

        ' To customize, override this method in OrdersTableControlRow.
        Public Overridable Sub Validate() 
            ' Initially empty.  Override to add custom validation.
        End Sub

        Public Overridable Sub Delete()
        
            If Me.IsNewRecord() Then
                Return
            End If

            Dim pk As KeyValue = KeyValue.XmlToKey(Me.RecordUniqueId)
            OrdersTable.DeleteRecord(pk)

          
            DirectCast(GetParentControlObject(Me, "OrdersTableControl"), OrdersTableControl).DataChanged = True
            DirectCast(GetParentControlObject(Me, "OrdersTableControl"), OrdersTableControl).ResetData = True
        End Sub

        Protected Overridable Sub Control_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
            Try
                DbUtils.StartTransaction()

                If Not Me.Page.ErrorOnPage AndAlso (Me.Page.IsPageRefresh OrElse Me.DataChanged OrElse Me.ResetData) Then
                    Me.LoadData()
                    Me.DataBind()
                End If

            Catch ex As Exception
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction()
            End Try
        End Sub
        
        

        Protected Overrides Sub LoadViewState(ByVal savedState As Object)
            MyBase.LoadViewState(savedState)
            Dim isNewRecord As String = CType(ViewState("IsNewRecord"), String)
            If Not isNewRecord Is Nothing AndAlso isNewRecord.Trim <> "" Then
                Me.IsNewRecord = Boolean.Parse(isNewRecord)
            End If
            
            Dim myCheckSum As String = CType(ViewState("CheckSum"), String)
            If Not myCheckSum Is Nothing AndAlso myCheckSum.Trim <> "" Then
                Me.CheckSum = myCheckSum
            End If
            
        End Sub

        Protected Overrides Function SaveViewState() As Object
            ViewState("IsNewRecord") = Me.IsNewRecord.ToString()
            ViewState("CheckSum") = Me.CheckSum
            
            Return MyBase.SaveViewState()
        End Function
        
        
        ' event handler for LinkButton
        Public Overridable Sub CustomerID_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim url As String = "../Customers/ShowCustomers.aspx?Customers={OrdersTableControlRow:FK:CustomersOrders}"
            Dim shouldRedirect As Boolean = True
            Dim TargetKey As String = Nothing
            Dim DFKA As String = Nothing
            Dim id As String = Nothing
            Dim value As String = Nothing
            Try
                DbUtils.StartTransaction
                
            url = Me.ModifyRedirectUrl(url, "",False)
            url = Me.Page.ModifyRedirectUrl(url, "",False)
          Me.Page.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.Page.RollBackTransaction(sender)
                shouldRedirect = False
                Me.Page.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
            If shouldRedirect Then
                Me.Page.ShouldSaveControlsToSession = True
                Me.Page.Response.Redirect(url)
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.Page.ShouldSaveControlsToSession = True
            Me.Page.CloseWindow(True)
        
            End If
        End Sub
            
   
        Private _IsNewRecord As Boolean = True
        Public Overridable Property IsNewRecord() As Boolean
            Get
                Return Me._IsNewRecord
            End Get
            Set(ByVal value As Boolean)
                Me._IsNewRecord = value
            End Set
        End Property

        Private _DataChanged As Boolean = False
        Public Overridable Property DataChanged() As Boolean
            Get
                Return Me._DataChanged
            End Get
            Set(ByVal Value As Boolean)
                Me._DataChanged = Value
            End Set
        End Property

        Private _ResetData As Boolean = False
        Public Overridable Property ResetData() As Boolean
            Get
                Return Me._ResetData
            End Get
            Set(ByVal Value As Boolean)
                Me._ResetData = Value
            End Set
        End Property
        
        Public Property RecordUniqueId() As String
            Get
                Return CType(Me.ViewState("BaseOrdersTableControlRow_Rec"), String)
            End Get
            Set(ByVal value As String)
                Me.ViewState("BaseOrdersTableControlRow_Rec") = value
            End Set
        End Property
        
        Private _DataSource As OrdersRecord
        Public Property DataSource() As OrdersRecord
            Get
                Return Me._DataSource
            End Get
            Set(ByVal value As OrdersRecord)
                Me._DataSource = value
            End Set
        End Property

        Private _checkSum As String
        Public Overridable Property CheckSum() As String
            Get
                Return Me._checkSum
            End Get
            Set(ByVal value As String)
                Me._checkSum = value
            End Set
        End Property
        
        Private _TotalPages As Integer
        Public Property TotalPages() As Integer
            Get
                Return Me._TotalPages
            End Get
            Set(ByVal value As Integer)
                Me._TotalPages = value
            End Set
        End Property
        
        Private _PageIndex As Integer
        Public Property PageIndex() As Integer
            Get
                ' Return the PageIndex
                Return Me._PageIndex
            End Get
            Set(ByVal value As Integer)
                Me._PageIndex = value
            End Set
        End Property
    
        Private _DisplayLastPage As Boolean
        Public Property DisplayLastPage() As Boolean
            Get
                Return Me._DisplayLastPage
            End Get
            Set(ByVal value As Boolean)
                Me._DisplayLastPage = value
            End Set
        End Property
        
        

#Region "Helper Properties"
        
        Public ReadOnly Property CustomerID() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "CustomerID"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
            
        Public ReadOnly Property Freight() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "Freight"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property OrderDate() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "OrderDate"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property RequiredDate() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "RequiredDate"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ShipAddress() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipAddress"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ShipCity() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipCity"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ShipCountry() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipCountry"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ShipName() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipName"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ShippedDate() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShippedDate"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ShipPostalCode() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipPostalCode"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ShipRegion() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipRegion"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
        Public ReadOnly Property ShipVia() As System.Web.UI.WebControls.Literal
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipVia"), System.Web.UI.WebControls.Literal)
            End Get
        End Property
            
    #End Region

    #Region "Helper Functions"

    Public Overrides Overloads Function ModifyRedirectUrl(ByVal url As String, ByVal arg As String, ByVal bEncrypt As Boolean) As String
        Return Me.Page.EvaluateExpressions(url, arg, bEncrypt, Me)
    End Function

    Public Overrides Overloads Function EvaluateExpressions(ByVal url As String, ByVal arg As String, ByVal bEncrypt As Boolean) As String
    Dim rec As OrdersRecord = Nothing
            
            Try
                rec = Me.GetRecord()
            Catch ex As Exception
                ' Do nothing
            End Try

            If rec Is Nothing AndAlso url.IndexOf("{") >= 0 Then
                ' Localization.
                
            Throw New Exception(Page.GetResourceValue("Err:RecDataSrcNotInitialized", "UseDAL"))
                    
            End If
            Return EvaluateExpressions(url, arg, rec, bEncrypt)
        End Function

        Public Overridable Function GetRecord() As OrdersRecord
            If Not Me.DataSource Is Nothing Then
                Return Me.DataSource
            End If
            
            If Not Me.RecordUniqueId Is Nothing Then
                Return OrdersTable.GetRecord(Me.RecordUniqueId, True)
            End If
            
            ' Localization.
            
            Return Nothing
                
        End Function

        Public Shadows ReadOnly Property Page() As BaseApplicationPage
            Get
                Return DirectCast(MyBase.Page, BaseApplicationPage)
            End Get
        End Property

#End Region

End Class

  

' Base class for the OrdersTableControl control on the ShowEmployeesTable2 page.
' Do not modify this class. Instead override any method in OrdersTableControl.
Public Class BaseOrdersTableControl
        Inherits UseDAL.UI.BaseApplicationTableControl

        Protected Overridable Sub Control_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init

            ' Setup the pagination events.
        

            ' Setup the sorting events.
        
              AddHandler Me.CustomerIDLabel1.Click, AddressOf CustomerIDLabel1_Click
            
              AddHandler Me.FreightLabel.Click, AddressOf FreightLabel_Click
            
              AddHandler Me.OrderDateLabel.Click, AddressOf OrderDateLabel_Click
            
              AddHandler Me.RequiredDateLabel.Click, AddressOf RequiredDateLabel_Click
            
              AddHandler Me.ShipAddressLabel.Click, AddressOf ShipAddressLabel_Click
            
              AddHandler Me.ShipCityLabel.Click, AddressOf ShipCityLabel_Click
            
              AddHandler Me.ShipCountryLabel.Click, AddressOf ShipCountryLabel_Click
            
              AddHandler Me.ShipNameLabel.Click, AddressOf ShipNameLabel_Click
            
              AddHandler Me.ShippedDateLabel.Click, AddressOf ShippedDateLabel_Click
            
              AddHandler Me.ShipPostalCodeLabel.Click, AddressOf ShipPostalCodeLabel_Click
            
              AddHandler Me.ShipRegionLabel.Click, AddressOf ShipRegionLabel_Click
            
              AddHandler Me.ShipViaLabel1.Click, AddressOf ShipViaLabel1_Click
            

            ' Setup the button events.
        

            ' Setup the filter and search events.
        

            ' Control Initializations.
            ' Initialize the table's current sort order.
            If Me.InSession(Me, "Order_By") Then
                Me.CurrentSortOrder = OrderBy.FromXmlString(Me.GetFromSession(Me, "Order_By", Nothing))
            Else
                Me.CurrentSortOrder = New OrderBy(True, True)
        
            End If

            ' Setup default pagination settings.
        
            Me.PageSize = CInt(Me.GetFromSession(Me, "Page_Size", "10"))
            Me.PageIndex = CInt(Me.GetFromSession(Me, "Page_Index", "0"))
            Me.ClearControlsFromSession()
        End Sub

        Protected Overridable Sub Control_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
            SaveControlsToSession_Ajax()
        
        End Sub

        ' Read data from database. Returns an array of records that can be assigned
        ' to the DataSource table control property.
        Public Overridable Sub LoadData()
            Try
            
                ' The WHERE clause will be empty when displaying all records in table.
                Dim wc As WhereClause = CreateWhereClause()
                If Not wc Is Nothing AndAlso Not wc.RunQuery Then
                    ' Initialize an empty array of records
                    Dim alist As New ArrayList(0)
                    Me.DataSource = DirectCast(alist.ToArray(GetType(OrdersRecord)), OrdersRecord())
                    ' Add records to the list if needed.
                    Me.AddNewRecords()
                    Return
                End If

                Dim orderBy As OrderBy = CreateOrderBy()

                ' Get the pagesize from the pagesize control.
                Me.GetPageSize()

                ' Get the total number of records to be displayed.
                Me.TotalRecords = OrdersTable.GetRecordCount(wc)

                ' Go to the last page.
                If Me.TotalPages <= 0 OrElse Me.PageIndex < 0 Then
                    Me.PageIndex = 0
                ElseIf Me.DisplayLastPage OrElse Me.PageIndex >= Me.TotalPages Then
                    Me.PageIndex = Me.TotalPages - 1
                End If

                ' Retrieve the records and set the table DataSource.
                ' Only PageSize records are fetched starting at PageIndex (zero based).
                If Me.TotalRecords <= 0 Then
                    ' Initialize an empty array of records
                    Dim alist As New ArrayList(0)
                    Me.DataSource = DirectCast(alist.ToArray(GetType(OrdersRecord)), OrdersRecord())
                ElseIf Me.AddNewRecord > 0 Then
                    ' Get the records from the posted data
                    Dim postdata As New ArrayList
                    For Each rc As OrdersTableControlRow In Me.GetRecordControls()
                        If Not rc.IsNewRecord Then
                            rc.DataSource = rc.GetRecord()
                            rc.GetUIData()
                            postdata.Add(rc.DataSource)
                        End If
                    Next
                    Me.DataSource = DirectCast(postdata.ToArray(GetType(OrdersRecord)), OrdersRecord())
                Else
                    ' Get the records from the database
                    Me.DataSource = OrdersTable.GetRecords(wc, orderBy, Me.PageIndex, Me.PageSize)
                End If
                ' Add records to the list.
                Me.AddNewRecords()
            

                ' Initialize the page and grand totals. now
            
            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        ' Populate the UI controls.
        Public Overrides Sub DataBind()

            MyBase.DataBind()

            ' Make sure that the DataSource is initialized.
            If Me.DataSource Is Nothing Then
                Return
            End If

        
          ' Improve performance by prefetching display as records.
          Me.PreFetchForeignKeyValues()
        

            ' Setup the pagination controls.
            BindPaginationControls()

            ' Populate all filters data.
        

            ' Bind the repeater with the list of records to expand the UI.
            Dim rep As System.Web.UI.WebControls.Repeater = CType(Me.FindControl("OrdersTableControlRepeater"), System.Web.UI.WebControls.Repeater)
      If rep is Nothing Then Return
            rep.DataSource = DataSource()
            rep.DataBind()

            Dim index as Integer = 0
            For Each repItem as System.Web.UI.WebControls.RepeaterItem in rep.Items
                ' Loop through all rows in the table, set its DataSource and call DataBind().
                Dim recControl as OrdersTableControlRow = DirectCast(repItem.FindControl("OrdersTableControlRow"),OrdersTableControlRow) 
                recControl.DataSource = Me.DataSource(index)
                recControl.DataBind()
                recControl.Visible = Not Me.InDeletedRecordIds(recControl)
                index += 1
            Next

        
      ' setting the state of expand or collapse alternative rows
      
      End Sub

        Public Overridable Sub ResetControl()
        
            
              Me.CurrentSortOrder.Reset()
              If (Me.InSession(Me, "Order_By")) Then
              Me.CurrentSortOrder = OrderBy.FromXmlString(Me.GetFromSession(Me, "Order_By", Nothing))
              Else
              Me.CurrentSortOrder = New OrderBy(true, true)
            
            End If
                
            Me.PageIndex = 0
    End Sub


    
          Public Sub PreFetchForeignKeyValues()
          If (IsNothing(Me.DataSource))
            Return
          End If
          
            Me.Page.PregetDfkaRecords(OrdersTable.CustomerID, Me.DataSource)
          
            Me.Page.PregetDfkaRecords(OrdersTable.ShipVia, Me.DataSource)
          
          End Sub
         

        Protected Overridable Sub BindPaginationControls()

            ' Setup the pagination controls.

            ' Bind the buttons for OrdersTableControl pagination.
        

            ' Bind the pagination labels.
        
        End Sub

        Public Overridable Sub SaveData()
            Dim recCtl As OrdersTableControlRow
            For Each recCtl In Me.GetRecordControls()
        
                If Me.InDeletedRecordIds(recCtl) Then
                    recCtl.Delete()
                Else
                    If recCtl.Visible Then
                        recCtl.SaveData()
                    End If
                End If
          
            Next
            
            Me.DataChanged = True
            Me.ResetData = True
            
            
          
          ' When one tries to add two duplicate records, an exception is thrown.Before throwing an exception, the first record's IsNewRecord property is set to false. 
          ' Now when one tries to delete these two records simultaneously, since the first record's IsNewRecord property is false, the server tries to delete it from the database, which result in an error.
          ' To avoid this problem every record's IsNewRecord property is set to false only after all the records are saved in the database. 
          For Each recCtl in Me.GetRecordControls()
              recCtl.IsNewRecord = False
          Next
    
      
                ' Whenever an existing record is deleted and saved and then tried to add the same record, it does not display the newly added record after saving, because, while displaying each records DeletedRecordIds is checked to see if it is waiting to be deleted.
          ' Since DeletedRecordIds is not reset after each record deletion, when one tries to add the same record it sees record id in DeleteReordIds and does not display it. 
          ' To overcome this problem, DeletedRecordIds is reset.
           Me.DeletedRecordIds = Nothing
      
            
            
        End Sub

        Public Overridable Function CreateOrderBy() As OrderBy
            Return Me.CurrentSortOrder
        End Function
        
        'This CreateWhereClause is used for loading the data.
        Public Overridable Function CreateWhereClause() As WhereClause
            OrdersTable.Instance.InnerFilter = Nothing
            Dim wc As WhereClause = New WhereClause()
            ' Compose the WHERE clause consiting of:
            ' 1. Static clause defined at design time.
            ' 2. User selected filter criteria.
            ' 3. User selected search criteria.

              
      Dim selectedRecordKeyValue as KeyValue = New KeyValue()
    
              Dim employeesTableControlObjRow As EmployeesTableControlRow = DirectCast(MiscUtils.GetParentControlObject(Me, "EmployeesTableControlRow") ,EmployeesTableControlRow)
            
                If (Not IsNothing(employeesTableControlObjRow) AndAlso Not IsNothing(employeesTableControlObjRow.GetRecord()) AndAlso Not IsNothing(employeesTableControlObjRow.GetRecord().EmployeeID))
                    wc.iAND(OrdersTable.EmployeeID, BaseFilter.ComparisonOperator.EqualsTo, employeesTableControlObjRow.GetRecord().EmployeeID.ToString())
                Else
                    wc.RunQuery = False
                    Return wc                    
                End If
                
              
      HttpContext.Current.Session("OrdersTableControlWhereClause") = selectedRecordKeyValue.ToXmlString()
    
            Return wc
        End Function
        
        
        ' This CreateWhereClause is used for loading list of suggestions for Auto Type-Ahead feature.
        Public Overridable Function CreateWhereClause(ByVal searchText as String, ByVal fromSearchControl as String, ByVal AutoTypeAheadSearch as String, ByVal AutoTypeAheadWordSeparators as String) As WhereClause
            OrdersTable.Instance.InnerFilter = Nothing
            Dim wc As WhereClause = New WhereClause()
            ' Compose the WHERE clause consiting of:
            ' 1. Static clause defined at design time.
            ' 2. User selected filter criteria.
            ' 3. User selected search criteria.
            Dim appRelativeVirtualPath As String = CType(HttpContext.Current.Session("AppRelativeVirtualPath"), String)
            
            Dim selectedRecordInEmployeesTableControl as String = DirectCast(HttpContext.Current.Session("OrdersTableControlWhereClause"), String)
            
            If Not selectedRecordInEmployeesTableControl Is Nothing AndAlso KeyValue.IsXmlKey(selectedRecordInEmployeesTableControl) Then
                Dim selectedRecordKeyValue as KeyValue = KeyValue.XmlToKey(selectedRecordInEmployeesTableControl)
                
       If Not IsNothing(selectedRecordKeyValue) AndAlso selectedRecordKeyValue.ContainsColumn(OrdersTable.EmployeeID) Then
            wc.iAND(OrdersTable.EmployeeID, BaseFilter.ComparisonOperator.EqualsTo, selectedRecordKeyValue.GetColumnValue(OrdersTable.EmployeeID).ToString())
        End If
    
  
            End If
          
            ' Adds clauses if values are selected in Filter controls which are configured in the page.
          
            Return wc
        End Function
          
          
        'Formats the resultItem and adds it to the list of suggestions.
        Public Overridable Function FormatSuggestions(ByVal prefixText As String, ByVal resultItem as String, _
                                                 ByVal columnLength As Integer, ByVal AutoTypeAheadDisplayFoundText as String, _
                                                 ByVal autoTypeAheadSearch as String, ByVal AutoTypeAheadWordSeparators as String, _
                                                 ByVal resultList as ArrayList) as Boolean
            Dim index As Integer = resultItem.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture).IndexOf(prefixText.ToUpper(System.Threading.Thread.CurrentThread.CurrentCulture))
            Dim itemToAdd As String = ""
            Dim isFound as Boolean = False
            Dim isAdded as Boolean = False
            ' Get the index where prfixt is at the beginning of resultItem. If not found then, index of word which begins with prefixText.
            If InvariantLCase(autoTypeAheadSearch).equals("wordsstartingwithsearchstring") and not index = 0 Then
                ' Expression to find word which contains AutoTypeAheadWordSeparators followed by prefixText
                Dim regex1 As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex( AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                If regex1.IsMatch(resultItem) Then
                    index = regex1.Match(resultItem).Index
                    isFound = True
                End If
                ' If the prefixText is found immediatly after white space then starting of the word is found so don not search any further
                If not resultItem(index).ToString() = " " Then
                    ' Expression to find beginning of the word which contains AutoTypeAheadWordSeparators followed by prefixText
                    Dim regex As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\\S*" + AutoTypeAheadWordSeparators + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    If regex.IsMatch(resultItem) Then
                        index = regex.Match(resultItem).Index
                        isFound = True
                    End If
                 End If
            End If
            ' If autoTypeAheadSearch value is wordsstartingwithsearchstring then, extract the substring only if the prefixText is found at the 
            ' beginning of the resultItem (index = 0) or a word in resultItem is found starts with prefixText. 
            If index = 0 Or isFound Or InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring") then
                If InvariantLCase(AutoTypeAheadDisplayFoundText).equals("atbeginningofmatchedstring") Then
                    ' Expression to find beginning of the word which contains prefixText
                    Dim regex1 As System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\\S*" + prefixText, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    '  Find the beginning of the word which contains prefexText
                    If (StringUtils.InvariantLCase(autoTypeAheadSearch).Equals("anywhereinstring") AndAlso regex1.IsMatch(resultItem)) Then
                        index = regex1.Match(resultItem).Index
                        isFound = True
                    End If
                    ' Display string from the index till end of the string if sub string from index till end is less than columnLength value.
                    If Len(resultItem) - index <= columnLength Then
                        If index = 0 Then 
                            itemToAdd = resultItem 
                        Else
                            itemToAdd = "..." & resultItem.Substring(index, Len(resultItem) - index) 
                        End If
                    Else
                        If index = 0 Then
                            itemToAdd = resultItem.Substring(index, (columnLength - 3)) & "..."
                        Else
                            'Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                            itemToAdd = "..." & resultItem.Substring(index , columnLength - 6) & "..." 
                        End If
                    End If
                ElseIf InvariantLCase(AutoTypeAheadDisplayFoundText).equals("inmiddleofmatchedstring") Then
                    Dim subStringBeginIndex as Integer = CType(columnLength/2, Integer)
                    If Len(resultItem) <= columnLength Then
                        itemToAdd = resultItem
                    Else
                        ' Sanity check at end of the string
                        If index + Len(prefixText) = columnLength Then
                            itemToAdd =  "..." & resultItem.Substring(index-columnLength,index)
                        ElseIf Len(resultITem) - index < subStringBeginIndex Then 
                            ' Display string from the end till columnLength value if, index is closer to the end of the string.
                            itemToAdd =  "..." & resultItem.Substring(Len(resultItem)-columnLength,Len(resultItem))
                        ElseIf index <= subStringBeginIndex Then 
                            ' Sanity chet at beginning of the string
                            itemToAdd =  resultItem.Substring(0, columnLength) & "..."
                        Else
                            ' Display string containing text before the prefixText occures and text after the prefixText
                            itemToAdd =  "..." & resultItem.Substring(index - subStringBeginIndex, columnLength) & "..." 
                        End If
                    End If
                ElseIf InvariantLCase(AutoTypeAheadDisplayFoundText).equals("atendofmatchedstring") Then
                     ' Expression to find ending of the word which contains prefexText
                    Dim regex1 as System.Text.RegularExpressions.Regex = new System.Text.RegularExpressions.Regex("\s", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                    ' Find the ending of the word which contains prefexText
                    If regex1.IsMatch(resultItem, index + 1) Then
                        index = regex1.Match(resultItem, index + 1).Index
                    Else
                        ' If the word which contains prefexText is the last word in string, regex1.IsMatch returns false.
                        index = resultItem.Length
                    End If
                    If index > Len(resultItem) Then
                        index = Len(resultItem)
                    End If
                    ' If text from beginning of the string till index is less than columnLength value then, display string from the beginning till index.
                    If  index <= columnLength Then
                        if index = Len(resultItem) then   'Make decision to append "..."
                            itemToAdd = resultItem.Substring(0,index)
                        Else
                            itemToAdd = resultItem.Substring(0,index) & "..."
                        End If
                    Else
                        If index = Len(resultItem) Then
                            itemToAdd = "..." & resultItem.Substring(index - (columnLength - 3), (columnLength - 3))
                        Else
                            'Truncate the string to show only columnLength - 6 characters as begining and trailing "..." has to be appended.
                            itemToAdd = "..." & resultItem.Substring(index - (columnLength - 6), columnLength - 6) & "..." 
                        End If
                    End If
                End If
                
                ' Remove newline character from itemToAdd
                Dim prefixTextIndex As Integer = itemToAdd.IndexOf(prefixText, StringComparison.CurrentCultureIgnoreCase)
                ' If itemToAdd contains any newline after the search text then show text only till newline
                Dim regex2 As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("(" & vbCrLf & "|" & vbLf & ")", System.Text.RegularExpressions.RegexOptions.IgnoreCase)
                Dim newLineIndexAfterPrefix As Integer = -1
                If regex2.IsMatch(itemToAdd, prefixTextIndex) Then
                    newLineIndexAfterPrefix = regex2.Match(itemToAdd, prefixTextIndex).Index
                End If
                If (newLineIndexAfterPrefix > -1) Then
                    If itemToAdd.EndsWith("...") Then
                        itemToAdd = (itemToAdd.Substring(0, newLineIndexAfterPrefix) + "...")
                    Else
                        itemToAdd = itemToAdd.Substring(0, newLineIndexAfterPrefix)
                    End If
                End If
                ' If itemToAdd contains any newline before search text then show text which comes after newline
                Dim regex3 As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("(" & vbCrLf & "|" & vbLf & ")", (System.Text.RegularExpressions.RegexOptions.IgnoreCase Or System.Text.RegularExpressions.RegexOptions.RightToLeft))
                Dim newLineIndexBeforePrefix As Integer = -1
                If regex3.IsMatch(itemToAdd, prefixTextIndex) Then
                    newLineIndexBeforePrefix = regex3.Match(itemToAdd, prefixTextIndex).Index
                End If
                If (newLineIndexBeforePrefix > -1) Then
                    If itemToAdd.StartsWith("...") Then
                        itemToAdd = ("..." + itemToAdd.Substring((newLineIndexBeforePrefix + regex3.Match(itemToAdd, prefixTextIndex).Length)))
                    Else
                        itemToAdd = itemToAdd.Substring((newLineIndexBeforePrefix + regex3.Match(itemToAdd, prefixTextIndex).Length))
                    End If
                End If

                If Not itemToAdd is nothing AndAlso Not resultList.Contains(itemToAdd) Then
                    resultList.Add(itemToAdd)
                    isAdded = true
                End If
            End If
            Return isAdded
        End Function
        
    
        Protected Overridable Sub GetPageSize()
        
        End Sub

        Protected Overridable Sub AddNewRecords()
            Dim newRecordList As ArrayList = New ArrayList()

            ' Loop though all the record controls and if the record control
            ' does not have a unique record id set, then create a record
            ' and add to the list.
            If Not Me.ResetData Then
                Dim rep As System.Web.UI.WebControls.Repeater = CType(Me.FindControl("OrdersTableControlRepeater"), System.Web.UI.WebControls.Repeater)
        If rep is Nothing Then Return

                Dim repItem As System.Web.UI.WebControls.RepeaterItem
                For Each repItem In rep.Items
                    ' Loop through all rows in the table, set its DataSource and call DataBind().
                    Dim recControl As OrdersTableControlRow = DirectCast(repItem.FindControl("OrdersTableControlRow"), OrdersTableControlRow)

                    If recControl.Visible AndAlso recControl.IsNewRecord() Then
                        Dim rec As OrdersRecord = New OrdersRecord()
        
                        If recControl.CustomerID.Text <> "" Then
                            rec.Parse(recControl.CustomerID.Text, OrdersTable.CustomerID)
                        End If
                        If recControl.Freight.Text <> "" Then
                            rec.Parse(recControl.Freight.Text, OrdersTable.Freight)
                        End If
                        If recControl.OrderDate.Text <> "" Then
                            rec.Parse(recControl.OrderDate.Text, OrdersTable.OrderDate)
                        End If
                        If recControl.RequiredDate.Text <> "" Then
                            rec.Parse(recControl.RequiredDate.Text, OrdersTable.RequiredDate)
                        End If
                        If recControl.ShipAddress.Text <> "" Then
                            rec.Parse(recControl.ShipAddress.Text, OrdersTable.ShipAddress)
                        End If
                        If recControl.ShipCity.Text <> "" Then
                            rec.Parse(recControl.ShipCity.Text, OrdersTable.ShipCity)
                        End If
                        If recControl.ShipCountry.Text <> "" Then
                            rec.Parse(recControl.ShipCountry.Text, OrdersTable.ShipCountry)
                        End If
                        If recControl.ShipName.Text <> "" Then
                            rec.Parse(recControl.ShipName.Text, OrdersTable.ShipName)
                        End If
                        If recControl.ShippedDate.Text <> "" Then
                            rec.Parse(recControl.ShippedDate.Text, OrdersTable.ShippedDate)
                        End If
                        If recControl.ShipPostalCode.Text <> "" Then
                            rec.Parse(recControl.ShipPostalCode.Text, OrdersTable.ShipPostalCode)
                        End If
                        If recControl.ShipRegion.Text <> "" Then
                            rec.Parse(recControl.ShipRegion.Text, OrdersTable.ShipRegion)
                        End If
                        If recControl.ShipVia.Text <> "" Then
                            rec.Parse(recControl.ShipVia.Text, OrdersTable.ShipVia)
                        End If
                        newRecordList.Add(rec)
                    End If
                Next
            End If

            ' Add any new record to the list.
            Dim index As Integer = 0
            For index = 1 To Me.AddNewRecord
                newRecordList.Insert(0, New OrdersRecord())
            Next
            Me.AddNewRecord = 0

            ' Finally, add any new records to the DataSource.
            If newRecordList.Count > 0 Then
                Dim finalList As ArrayList = New ArrayList(Me.DataSource)
                finalList.InsertRange(0, newRecordList)

                Me.DataSource = DirectCast(finalList.ToArray(GetType(OrdersRecord)), OrdersRecord())
            End If

        End Sub

        
        Public Sub AddToDeletedRecordIds(ByVal rec As OrdersTableControlRow)
            If rec.IsNewRecord() Then
                Return
            End If

            If Not Me.DeletedRecordIds Is Nothing AndAlso Me.DeletedRecordIds.Trim <> "" Then
                Me.DeletedRecordIds &= ","
            End If

            Me.DeletedRecordIds &= "[" & rec.RecordUniqueId & "]"
        End Sub

        Protected Overridable Function InDeletedRecordIds(ByVal rec As OrdersTableControlRow) As Boolean
            If Me.DeletedRecordIds Is Nothing OrElse Me.DeletedRecordIds.Trim = "" Then
                Return False
            End If

            Return Me.DeletedRecordIds.IndexOf("[" & rec.RecordUniqueId & "]") >= 0
        End Function

        Private _DeletedRecordIds As String
        Public Property DeletedRecordIds() As String
            Get
                Return Me._DeletedRecordIds
            End Get

            Set(ByVal value As String)
                Me._DeletedRecordIds = value
            End Set
        End Property
        
        Protected Overridable Sub Control_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
            Try
                DbUtils.StartTransaction
                
                If Not Me.Page.ErrorOnPage AndAlso (Me.Page.IsPageRefresh OrElse Me.DataChanged OrElse Me.ResetData) Then
                    Me.LoadData()
                    Me.DataBind()
                End If
                
            Catch ex As Exception
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
        End Sub
        
        Protected Overrides Sub SaveControlsToSession()
            MyBase.SaveControlsToSession()

            ' Save filter controls to values to session.
        
            
            ' Save table control properties to the session.
            If Not Me.CurrentSortOrder Is Nothing Then
                Me.SaveToSession(Me, "Order_By", Me.CurrentSortOrder.ToXmlString())
            End If
            Me.SaveToSession(Me, "Page_Index", Me.PageIndex.ToString())
            Me.SaveToSession(Me, "Page_Size", Me.PageSize.ToString())
        
            Me.SaveToSession(Me, "DeletedRecordIds", Me.DeletedRecordIds)  
        
        End Sub
        
        Protected  Sub SaveControlsToSession_Ajax()
            ' Save filter controls to values to session.
          
            HttpContext.Current.Session("AppRelativeVirtualPath") = Me.Page.AppRelativeVirtualPath
         
        End Sub
        
        Protected Overrides Sub ClearControlsFromSession()
            MyBase.ClearControlsFromSession()

            ' Clear filter controls values from the session.
        
            
            ' Clear table properties from the session.
            Me.RemoveFromSession(Me, "Order_By")
            Me.RemoveFromSession(Me, "Page_Index")
            Me.RemoveFromSession(Me, "Page_Size")
            
            Me.RemoveFromSession(Me, "DeletedRecordIds")  
            
        End Sub

        Protected Overrides Sub LoadViewState(ByVal savedState As Object)
            MyBase.LoadViewState(savedState)

            Dim orderByStr As String = CType(ViewState("OrdersTableControl_OrderBy"), String)
            If Not orderByStr Is Nothing AndAlso orderByStr.Trim <> "" Then
                Me.CurrentSortOrder = BaseClasses.Data.OrderBy.FromXmlString(orderByStr)
            Else
                Me.CurrentSortOrder = New OrderBy(True, True)
            End If

            Dim pageIndex As String = CType(ViewState("Page_Index"), String)
            If Not pageIndex Is Nothing Then
                Me.PageIndex = CInt(pageIndex)
            End If

            Dim pageSize As String = CType(ViewState("Page_Size"), String)
            If Not pageSize Is Nothing Then
                Me.PageSize = CInt(pageSize)
            End If
        
            Me.DeletedRecordIds = CType(Me.ViewState("DeletedRecordIds"), String)
        
        End Sub

        Protected Overrides Function SaveViewState() As Object
            
            If Not Me.CurrentSortOrder Is Nothing Then
                Me.ViewState("OrdersTableControl_OrderBy") = Me.CurrentSortOrder.ToXmlString()
            End If
            
            Me.ViewState("Page_Index") = Me.PageIndex
            Me.ViewState("Page_Size") = Me.PageSize
        
            Me.ViewState("DeletedRecordIds") = Me.DeletedRecordIds
        
            Return MyBase.SaveViewState()

        End Function

        ' Generate the event handling functions for pagination events.
        

        ' Generate the event handling functions for sorting events.
        
        ' event handler for FieldSort
        Public Overridable Sub CustomerIDLabel1_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.CustomerID)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.CustomerID, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub FreightLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.Freight)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.Freight, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub OrderDateLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.OrderDate)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.OrderDate, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub RequiredDateLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.RequiredDate)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.RequiredDate, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ShipAddressLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.ShipAddress)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.ShipAddress, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ShipCityLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.ShipCity)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.ShipCity, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ShipCountryLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.ShipCountry)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.ShipCountry, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ShipNameLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.ShipName)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.ShipName, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ShippedDateLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.ShippedDate)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.ShippedDate, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ShipPostalCodeLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.ShipPostalCode)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.ShipPostalCode, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ShipRegionLabel_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.ShipRegion)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.ShipRegion, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            
        ' event handler for FieldSort
        Public Overridable Sub ShipViaLabel1_Click(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim sd As OrderByItem = Me.CurrentSortOrder.Find(OrdersTable.ShipVia)
            If Not sd Is Nothing Then
                sd.Reverse()
            Else
                Me.CurrentSortOrder.Reset()
                Me.CurrentSortOrder.Add(OrdersTable.ShipVia, OrderByItem.OrderDir.Asc)
            End If

            Me.DataChanged = True
              
        End Sub
            

        ' Generate the event handling functions for button events.
        
      

        ' Generate the event handling functions for filter and search events.
        

        ' pagination properties
        Private _PageSize As Integer
        Public Property PageSize() As Integer
            Get
                Return Me._PageSize
            End Get
            Set(ByVal value As Integer)
                Me._PageSize = value
            End Set
        End Property

        Private _PageIndex As Integer
        Public Property PageIndex() As Integer
            Get
                ' Return the PageIndex
                Return Me._PageIndex
            End Get
            Set(ByVal value As Integer)
                Me._PageIndex = value
            End Set
        End Property

        Private _TotalRecords As Integer
        Public Property TotalRecords() As Integer
            Get
                Return Me._TotalRecords
            End Get
            Set(ByVal value As Integer)
                If Me.PageSize > 0 Then
                    Me.TotalPages = CInt(Math.Ceiling(value / Me.PageSize))
                End If

                Me._TotalRecords = value
            End Set
        End Property

        Private _TotalPages As Integer
        Public Property TotalPages() As Integer
            Get
                Return Me._TotalPages
            End Get
            Set(ByVal value As Integer)
                Me._TotalPages = value
            End Set
        End Property

        Private _DisplayLastPage As Boolean
        Public Property DisplayLastPage() As Boolean
            Get
                Return Me._DisplayLastPage
            End Get
            Set(ByVal value As Boolean)
                Me._DisplayLastPage = value
            End Set
        End Property

        Private _DataChanged As Boolean = False
        Public Property DataChanged() As Boolean
            Get
                Return Me._DataChanged
            End Get
            Set(ByVal value As Boolean)
                Me._DataChanged = value
            End Set
        End Property
        
        Private _ResetData As Boolean = False
        Public Property ResetData() As Boolean
            Get
                Return Me._ResetData
            End Get
            Set(ByVal value As Boolean)
                Me._ResetData = value
            End Set
        End Property

        Private _AddNewRecord As Integer = 0
        Public Property AddNewRecord() As Integer
            Get
                Return Me._AddNewRecord
            End Get
            Set(ByVal value As Integer)
                Me._AddNewRecord = value
            End Set
        End Property

        Private _CurrentSortOrder As OrderBy = Nothing
        Public Property CurrentSortOrder() As OrderBy
            Get
                Return Me._CurrentSortOrder
            End Get
            Set(ByVal value As BaseClasses.Data.OrderBy)
                Me._CurrentSortOrder = value
            End Set
        End Property

        Private _DataSource() As OrdersRecord = Nothing
        Public Property DataSource() As OrdersRecord ()
            Get
                Return Me._DataSource
            End Get
            Set(ByVal value() As OrdersRecord)
                Me._DataSource = value
            End Set
        End Property

#Region "Helper Properties"
        
        Public ReadOnly Property CustomerIDLabel1() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "CustomerIDLabel1"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property FreightLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "FreightLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property OrderDateLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "OrderDateLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property RequiredDateLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "RequiredDateLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ShipAddressLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipAddressLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ShipCityLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipCityLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ShipCountryLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipCountryLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ShipNameLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipNameLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ShippedDateLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShippedDateLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ShipPostalCodeLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipPostalCodeLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ShipRegionLabel() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipRegionLabel"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
        Public ReadOnly Property ShipViaLabel1() As System.Web.UI.WebControls.LinkButton
            Get
                Return CType(BaseClasses.Utils.MiscUtils.FindControlRecursively(Me, "ShipViaLabel1"), System.Web.UI.WebControls.LinkButton)
            End Get
        End Property
        
#End Region

#Region "Helper Functions"
        
        Public Overrides Overloads Function ModifyRedirectUrl(url As String, arg As String, ByVal bEncrypt As Boolean) As String
            Return Me.Page.EvaluateExpressions(url, arg, bEncrypt, Me)
        End Function
      
           Public Overrides Overloads Function EvaluateExpressions(url As String, arg As String, ByVal bEncrypt As Boolean) As String
            Dim needToProcess As Boolean = AreAnyUrlParametersForMe(url, arg)
            If (needToProcess) Then
                Dim recCtl As OrdersTableControlRow = Me.GetSelectedRecordControl()
                If recCtl Is Nothing AndAlso url.IndexOf("{") >= 0 Then
                    ' Localization.
                    Throw New Exception(Page.GetResourceValue("Err:NoRecSelected", "UseDAL"))
                End If

                Dim rec As OrdersRecord = Nothing
                If Not recCtl Is Nothing Then
                    rec = recCtl.GetRecord()
                End If
                Return EvaluateExpressions(url, arg, rec, bEncrypt)
            End If
            Return url
        End Function
          
        Public Overridable Function GetSelectedRecordControl() As OrdersTableControlRow
            Return Nothing
          
        End Function

        Public Overridable Function GetSelectedRecordControls() As OrdersTableControlRow()
        
            Return DirectCast((new ArrayList()).ToArray(GetType(OrdersTableControlRow)), OrdersTableControlRow())
          
        End Function

        Public Overridable Sub DeleteSelectedRecords(ByVal deferDeletion As Boolean)
            Dim recList() As OrdersTableControlRow = Me.GetSelectedRecordControls()
            If recList.Length = 0 Then
                ' Localization.
                Throw New Exception(Page.GetResourceValue("Err:NoRecSelected", "UseDAL"))
            End If
            
            Dim recCtl As OrdersTableControlRow
            For Each recCtl In recList
                If deferDeletion Then
                    If Not recCtl.IsNewRecord Then
                
                        Me.AddToDeletedRecordIds(recCtl)
                  
                    End If
                    recCtl.Visible = False
                
                Else
                
                    recCtl.Delete()
                    Me.DataChanged = True
                    Me.ResetData = True
                  
                End If
            Next
        End Sub

        Public Function GetRecordControls() As OrdersTableControlRow()
            Dim recList As ArrayList = New ArrayList()
            Dim rep As System.Web.UI.WebControls.Repeater = CType(Me.FindControl("OrdersTableControlRepeater"), System.Web.UI.WebControls.Repeater)
      If rep is Nothing Then Return Nothing
            Dim repItem As System.Web.UI.WebControls.RepeaterItem

            For Each repItem In rep.Items
                Dim recControl As OrdersTableControlRow = DirectCast(repItem.FindControl("OrdersTableControlRow"), OrdersTableControlRow)
                recList.Add(recControl)
            Next

            Return DirectCast(recList.ToArray(GetType(OrdersTableControlRow)), OrdersTableControlRow())
        End Function

        Public Shadows ReadOnly Property Page() As BaseApplicationPage
            Get
                Return DirectCast(MyBase.Page, BaseApplicationPage)
            End Get
        End Property

#End Region

    

End Class

  

#End Region
    
  
End Namespace

  