
' This file implements the code-behind class for ShowCustomersPage.aspx.
' App_Code\ShowCustomersPage.Controls.vb contains the Table, Row and Record control classes
' for the page.  Best practices calls for overriding methods in the Row or Record control classes.

#Region "Imports statements"

Option Strict On
Imports System
Imports System.Data
Imports System.Collections
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports BaseClasses
Imports BaseClasses.Utils
Imports BaseClasses.Utils.StringUtils
Imports BaseClasses.Data
Imports BaseClasses.Data.SqlProvider
Imports BaseClasses.Data.OrderByItem.OrderDir
Imports BaseClasses.Data.BaseFilter
Imports BaseClasses.Data.BaseFilter.ComparisonOperator
Imports BaseClasses.Web.UI.WebControls
        
Imports Training2.Business
Imports Training2.Data
        

#End Region

  
Namespace Training2.UI
  
Partial Class ShowCustomersPage
        Inherits BaseApplicationPage
' Code-behind class for the ShowCustomersPage page.
' Place your customizations in Section 1. Do not modify Section 2.
        


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

      Public Sub LoadData()
      ' LoadData reads database data and assigns it to UI controls.
      ' Customize by adding code before or after the call to LoadData_Base()
      ' or replace the call to LoadData_Base().
      LoadData_Base()
      End Sub
      


      
#Region "Ajax Functions"

        <System.Web.Services.WebMethod()> _
        Public Shared Function GetRecordFieldValue(ByVal tableName As String, _
                                                  ByVal recordID As String, _
                                                  ByVal columnName As String, _
                                                  ByVal title As String, _
                                                  ByVal persist As Boolean, _
                                                  ByVal popupWindowHeight As Integer, _
                                                  ByVal popupWindowWidth As Integer, _
                                                  ByVal popupWindowScrollBar As Boolean _
                                                  ) As Object()
            ' GetRecordFieldValue gets the pop up window content from the column specified by
            ' columnName in the record specified by the recordID in data base table specified by tableName.
            ' Customize by adding code before or after the call to  GetRecordFieldValue_Base()
            ' or replace the call to  GetRecordFieldValue_Base().
            Return GetRecordFieldValue_Base(tableName, recordID, columnName, title, persist, popupWindowHeight, popupWindowWidth, popupWindowScrollBar)
        End Function

        <System.Web.Services.WebMethod()> _
        Public Shared Function GetImage(ByVal tableName As String, _
                                        ByVal recordID As String, _
                                        ByVal columnName As String, _
                                        ByVal title As String, _
                                        ByVal persist As Boolean, _
                                        ByVal popupWindowHeight As Integer, _
                                        ByVal popupWindowWidth As Integer, _
                                        ByVal popupWindowScrollBar As Boolean _
                                        ) As Object()
            ' GetImage gets the Image url for the image in the column "columnName" and
            ' in the record specified by recordID in data base table specified by tableName.
            ' Customize by adding code before or after the call to  GetImage_Base()
            ' or replace the call to  GetImage_Base().
            Return GetImage_Base(tableName, recordID, columnName, title, persist, popupWindowHeight, popupWindowWidth, popupWindowScrollBar)
        End Function
    
#End Region

    ' Page Event Handlers - buttons, sort, links
    
        Public Sub OKButton_Click(ByVal sender As Object, ByVal args As EventArgs)
            
          ' Click handler for OKButton.
          ' Customize by adding code before the call or replace the call to the Base function with your own code.
          OKButton_Click_Base(sender, args)
          ' NOTE: If the Base function redirects to another page, any code here will not be executed.
        End Sub
        
        Public Sub EditButton_Click(ByVal sender As Object, ByVal args As EventArgs)
            
          ' Click handler for EditButton.
          ' Customize by adding code before the call or replace the call to the Base function with your own code.
          EditButton_Click_Base(sender, args)
          ' NOTE: If the Base function redirects to another page, any code here will not be executed.
        End Sub
        

#End Region

#Region "Section 2: Do not modify this section."


        Protected Overridable Sub Page_InitializeEventHandlers(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
            ' Handles MyBase.Init. Registers event handler for any button, sort or links.
            ' You can add additional Init handlers in Section 1.
        
              AddHandler Me.OKButton.Button.Click, AddressOf OKButton_Click
              AddHandler Me.EditButton.Button.Click, AddressOf EditButton_Click
        End Sub

        ' Handles MyBase.Load.  Read database data and put into the UI controls.
        ' If you need to, you can add additional Load handlers in Section 1.
        Protected Overridable Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
            ' Check if user has access to this page.  Redirects to either sign-in page
            ' or 'no access' page if not. Does not do anything if role-based security
            ' is not turned on, but you can override to add your own security.
            Me.Authorize(Me.GetAuthorizedRoles())
            ' Load data only when displaying the page for the first time
            If (Not Me.IsPostBack) Then
        
                ' Setup the header text for the validation summary control.
                Me.ValidationSummary1.HeaderText = GetResourceValue("ValidationSummaryHeaderText", "Training2")
          

      ' Read the data for all controls on the page.
      ' To change the behavior, override the DataBind method for the individual
      ' record or table UI controls.
      Me.LoadData()
      ElseIf (Me.Request("__EVENTTARGET") = "ChildWindowPostBack") Then

      Try

      ' Must start a transaction before performing database operations
      DbUtils.StartTransaction()

      ' Load data for each record and table UI control.
      ' Ordering is important because child controls get
      ' their parent ids from their parent UI controls.
      
                    Me.CustomersRecordControl.LoadData()
          

      Me.DataBind()

      

      Catch ex As Exception
      'An error has occured so display an error message.
      BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(Me, "Page_Load_Error_Message", ex.Message)
      Finally
      'End database transaction
      DbUtils.EndTransaction()
      End Try

      End If
      End Sub

      Public Shared Function GetRecordFieldValue_Base(ByVal tableName As String, _
      ByVal recordID As String, _
      ByVal columnName As String, _
      ByVal title As String, _
      ByVal persist As Boolean, _
      ByVal popupWindowHeight As Integer, _
      ByVal popupWindowWidth As Integer, _
      ByVal popupWindowScrollBar As Boolean _
      ) As Object()
      Dim content as String = NetUtils.EncodeStringForHtmlDisplay(BaseClasses.Utils.MiscUtils.GetFieldData(tableName, recordID, columnName))
      'content=(formattedValue)
      'returnValue is an array of string values.
      'returnValue(0) represents title of the pop up window
      'returnValue(1) represents content of the pop up window
      ' retrunValue(2) represents whether pop up window should be made persistant
      ' or it should closes as soon as mouse moved out.
      ' returnValue(5) represents whether pop up window should contain scroll bar.
      ' returnValue(3), (4) represents pop up window height and width respectivly
      ' (0),(2),(3),(4) and (5)  is initially set as pass through attribute.
      ' They can be modified by going to Attribute tab of the properties window of the control in aspx page.
      Dim returnValue(6) As Object
      returnValue(0) = title
      returnValue(1) = content
      returnValue(2) = persist
      returnValue(3) = popupWindowWidth
      returnValue(4) = popupWindowHeight
      returnValue(5) = popupWindowScrollBar
      Return returnValue
      End Function

      Public Shared Function GetImage_Base(ByVal tableName As String, _
      ByVal recordID As String, _
      ByVal columnName As String, _
      ByVal title As String, _
      ByVal persist As Boolean, _
      ByVal popupWindowHeight As Integer, _
      ByVal popupWindowWidth As Integer, _
      ByVal popupWindowScrollBar As Boolean _
      ) As Object()
      Dim content As String = "<IMG src =" & """../Shared/ExportFieldValue.aspx?Table=" & tableName & "&Field=" & columnName & "&Record=" & recordID & """/>"
            'returnValue is an array of string values.
            'returnValue(0) represents title of the pop up window.
            'returnValue(1) represents content ie, image url.
            ' retrunValue(2) represents whether pop up window should be made persistant
            ' or it should closes as soon as mouse moved out.
            ' returnValue(3), (4) represents pop up window height and width respectivly
            ' returnValue(5) represents whether pop up window should contain scroll bar.
            ' (0),(2),(3),(4) and (5) is initially set as pass through attribute.
            ' They can be modified by going to Attribute tab of the properties window of the control in aspx page.
            Dim returnValue(6) As Object
            returnValue(0) = title
            returnValue(1) = content
            returnValue(2) = persist
            returnValue(3) = popupWindowWidth
            returnValue(4) = popupWindowHeight
            returnValue(5) = popupWindowScrollBar
            Return returnValue
        End Function
        
    
        ' Load data from database into UI controls.
        ' Modify LoadData in Section 1 above to customize.  Or override DataBind() in
        ' the individual table and record controls to customize.
        Public Sub LoadData_Base()
            Try
              ' Load data only when displaying the page for the first time
              If (Not Me.IsPostBack) Then

                ' Must start a transaction before performing database operations
                DbUtils.StartTransaction()

                ' Load data for each record and table UI control.
                ' Ordering is important because child controls get
                ' their parent ids from their parent UI controls.
        
                    Me.CustomersRecordControl.LoadData()
          
      
                Me.DataBind()
    
        
              End If

            Catch ex As Exception
                ' An error has occured so display an error message.
                Utils.RegisterJScriptAlert(Me, "Page_Load_Error_Message", ex.Message)
            Finally
                If Not Me.IsPostBack Then
                    ' End database transaction
                      DbUtils.EndTransaction()
                End If
            End Try
        End Sub

        ' Write out event methods for the page events
        
        ' event handler for Button with Layout
        Public Sub OKButton_Click_Base(ByVal sender As Object, ByVal args As EventArgs)
              
            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
                

                TargetKey = Me.Page.Request.QueryString.Item("Target")
                If Not TargetKey Is Nothing Then
                   shouldRedirect = False
                End If
      
            Catch ex As Exception
                shouldRedirect = False
                Me.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
    
            End Try
            If shouldRedirect Then
                Me.ShouldSaveControlsToSession = True
                Me.RedirectBack()
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.ShouldSaveControlsToSession = True
            Me.CloseWindow(True)
        
            End If
        End Sub
            
        ' event handler for Button with Layout
        Public Sub EditButton_Click_Base(ByVal sender As Object, ByVal args As EventArgs)
              
            Dim url As String = "../Customers/EditCustomersPage.aspx?Customers={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)
                        Me.CommitTransaction(sender)
          
            Catch ex As Exception
                Me.RollBackTransaction(sender)
                shouldRedirect = False
                Me.ErrorOnPage = True
    
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)
            Finally
                DbUtils.EndTransaction
            End Try
            If shouldRedirect Then
                Me.ShouldSaveControlsToSession = True
                Me.Response.Redirect(url)
            ElseIf Not TargetKey Is Nothing AndAlso _
                        Not shouldRedirect Then
            Me.ShouldSaveControlsToSession = True
            Me.CloseWindow(True)
        
            End If
        End Sub
            
#End Region

  
End Class
  
End Namespace
  