Imports CAMS_ADMIN
Imports CAMS_BL
Imports System.Data
Imports System.Text

Public Class frmClients
    Inherits CAMSBasePage

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object
    Protected WithEvents ddlTitle As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlGender As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtSurname As System.Web.UI.WebControls.TextBox
    Protected WithEvents ddlEthnicity As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtName As System.Web.UI.WebControls.TextBox
    Protected WithEvents ddlReligion As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlMaritalStatus As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtAppNINumber As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtAddress As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPostcode As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPartnerNINumber As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtMobile As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtAppEmail As System.Web.UI.WebControls.TextBox
    Protected WithEvents chkPension As System.Web.UI.WebControls.CheckBox
    Protected WithEvents chkPensionCredit As System.Web.UI.WebControls.CheckBox
    Protected WithEvents chkOccupPension As System.Web.UI.WebControls.CheckBox
    Protected WithEvents chkIncomeSupport As System.Web.UI.WebControls.CheckBox
    Protected WithEvents rbMoreThan As System.Web.UI.WebControls.RadioButton
    Protected WithEvents txtMoreLessThan As System.Web.UI.WebControls.TextBox
    Protected WithEvents rbLessThan As System.Web.UI.WebControls.RadioButton
    Protected WithEvents ddlOTName As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtDClientsAddress As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDClientsTelephone As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDClientsPostcode As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtAgeProperty As System.Web.UI.WebControls.TextBox
    Protected WithEvents ddlGenProType As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlTenure As System.Web.UI.WebControls.DropDownList
    Protected WithEvents chkMortgage As System.Web.UI.WebControls.CheckBox
    Protected WithEvents chkLoftInsulation As System.Web.UI.WebControls.CheckBox
    Protected WithEvents txtNameOnDeeds As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtWhereHeld As System.Web.UI.WebControls.TextBox
    Protected WithEvents chkProveTitle As System.Web.UI.WebControls.CheckBox
    Protected WithEvents chkMortgageConsent As System.Web.UI.WebControls.CheckBox
    Protected WithEvents chkLandlordConsent As System.Web.UI.WebControls.CheckBox
    Protected WithEvents chkTenancyAgree As System.Web.UI.WebControls.CheckBox
    Protected WithEvents pnlDeedsClient As System.Web.UI.WebControls.Panel
    Protected WithEvents rbFold As System.Web.UI.WebControls.RadioButton
    Protected WithEvents rbClient As System.Web.UI.WebControls.RadioButton
    Protected WithEvents txtContact1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtContact2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtContact3 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtComments As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtAppBirthDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPartBirthDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents Img1 As System.Web.UI.HtmlControls.HtmlImage
    Protected WithEvents Img2 As System.Web.UI.HtmlControls.HtmlImage
    Protected WithEvents Img3 As System.Web.UI.HtmlControls.HtmlImage
    Protected WithEvents Img4 As System.Web.UI.HtmlControls.HtmlImage
    Protected WithEvents chkClientWithOccup As System.Web.UI.WebControls.CheckBox
    Protected WithEvents txtTelephone As System.Web.UI.WebControls.TextBox
    Protected WithEvents hdEvent As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents hdAction As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents btnDelete As System.Web.UI.HtmlControls.HtmlInputButton
    Protected WithEvents chkOtherIncome As System.Web.UI.WebControls.CheckBox
    Protected WithEvents hdClientId As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents hdSectionId As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents hdTemp As System.Web.UI.HtmlControls.HtmlInputHidden
    Protected WithEvents txtDClientsEmail As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblSymbol As System.Web.UI.WebControls.Label
    Protected WithEvents mnuCams As Menu

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Access Validation to page
        If Not Me.IsPostBack Then
            Dim oEC_User As EC_User = Me.GetUserFromSession

            If Not oEC_User Is Nothing Then
                If Me.HasAccessTo(Me.GetControlID("frmClients.aspx"), oEC_User.AccessGroup) = False Then
                    Me.RedirectToMsgPage(Constants.CONST_ERROR_ACCESSDENIED_TOPAGE)
                End If
            End If

        End If
        'End Access Validation

        'Menu
        mnuCams.CurrentGroup = Constants.MENU_NEW_ID
        mnuCams.CurrentItem = Constants.MENU_NEW_CLIENT_ID
        'End Menu

        'attributes for controls
        txtMoreLessThan.Attributes.Add("onKeyPress", "fnOnlyDigits(event,'decOK')")
        txtAgeProperty.Attributes.Add("onKeyPress", "fnOnlyDigits(event,'decNO')")
        'end attributes

        'Initial values
        If Not Me.IsPostBack Then
            'Define action
            If Not Request.QueryString("action") Is Nothing Then
                hdAction.Value = Request.QueryString("action").Trim.ToUpper  'Update
            Else
                hdAction.Value = "I" 'Insert
            End If
            'end define action

            LoadControls()

        End If
        'End Initial values

        'Postback
        If IsPostBack Then
            If hdEvent.Value = "save" Then
                Save()
            ElseIf hdEvent.Value = "updcontrol" Then
                UpdateddlOTList()
            ElseIf hdEvent.Value = "cancel" Then
                SetCancel()
            ElseIf hdEvent.Value = "close" Then
                DeleteGeneratedClientID()
            End If
        Else
            If hdAction.Value = "U" Then
                LoadClient()
            End If

        End If
        'End postback

        'Added by Raul Callupe
        If Me.IsPostBack = False Then
            Dim stbOutput As New StringBuilder
            stbOutput.Append("<script language='Javascript'>")
            stbOutput.Append("var pag = window.parent.frames(0);")

            If hdAction.Value = "I" Then
                stbOutput.Append("pag.document.all.lblPath.innerHTML='New/Client'")
            Else
                stbOutput.Append("pag.document.all.lblPath.innerHTML='View/Edit Client'")
            End If

            stbOutput.Append("</script>")
            Response.Write(stbOutput.ToString)
        End If
        'End Added

        'Added by Vanessa Ayala
        Me.lblSymbol.Text = ConfigurationSettings.AppSettings("Symbol")
        'End Added
    End Sub

#Region "Loading Controls"
    Private Sub UpdateddlOTList()
        Dim oCC_Client As New CC_Client
        Dim dsData As DataSet

        Try
            dsData = oCC_Client.GetDataForControls

            If Not dsData Is Nothing Then
                Util.FillDropDownList(dsData.Tables("OT").DefaultView, ddlOTName, "PROFESSIONALID", "FULLNAME", True, New ListItem("", ""))
                Util.SelectValueFromDropDown(ddlOTName, hdTemp.Value)
                ddlOTName_SelectedIndexChanged(Nothing, Nothing)
            End If
        Catch ex As Exception
        Finally
            hdEvent.Value = String.Empty
            hdTemp.Value = String.Empty
        End Try

    End Sub

    Private Sub LoadControls()
        Dim oCC_Client As New CC_Client
        Dim dsData As DataSet

        If hdAction.Value = "I" Then
            txtAppNINumber.Text = oCC_Client.GetGeneratedClientID
            hdClientId.Value = txtAppNINumber.Text
        End If

        Select Case hdAction.Value
            Case "I"
                btnDelete.Visible = False
            Case "U"
                btnDelete.Visible = True
        End Select

        'Gender
        ddlGender.Items.Clear()
        ddlGender.Items.Add(New ListItem("", ""))
        ddlGender.Items.Add(New ListItem("Male", "M"))
        ddlGender.Items.Add(New ListItem("Female", "F"))
        'End Gender

        Try

            dsData = oCC_Client.GetDataForControls

            If Not dsData Is Nothing Then
                Util.FillDropDownList(dsData.Tables("ETHNICITY").DefaultView, ddlEthnicity, "IDSEQUENCE", "DESCRIPTION", True, New ListItem("", ""))
                Util.FillDropDownList(dsData.Tables("RELIGION").DefaultView, ddlReligion, "IDSEQUENCE", "DESCRIPTION", True, New ListItem("", ""))
                Util.FillDropDownList(dsData.Tables("PROPERTYTYPE").DefaultView, ddlGenProType, "IDSEQUENCE", "DESCRIPTION", True, New ListItem("", ""))
                Util.FillDropDownList(dsData.Tables("TENURE").DefaultView, ddlTenure, "IDSEQUENCE", "DESCRIPTION", True, New ListItem("", ""))
                Util.FillDropDownList(dsData.Tables("TITLE").DefaultView, ddlTitle, "IDSEQUENCE", "DESCRIPTION", True, New ListItem("", ""))
                Util.FillDropDownList(dsData.Tables("MARITALSTATUS").DefaultView, ddlMaritalStatus, "IDSEQUENCE", "DESCRIPTION", True, New ListItem("", ""))
                Util.FillDropDownList(dsData.Tables("OT").DefaultView, ddlOTName, "PROFESSIONALID", "FULLNAME", True, New ListItem("", ""))
            Else
                Throw New Exception("No data")
            End If

        Catch ex As Exception
            ddlEthnicity.Items.Clear() : ddlEthnicity.Items.Add(New ListItem("Empty", ""))
            ddlReligion.Items.Clear() : ddlReligion.Items.Add(New ListItem("Empty", ""))
            ddlGenProType.Items.Clear() : ddlGenProType.Items.Add(New ListItem("Empty", ""))
            ddlTenure.Items.Clear() : ddlEthnicity.Items.Add(New ListItem("Empty", ""))
            ddlTitle.Items.Clear() : ddlEthnicity.Items.Add(New ListItem("Empty", ""))
            ddlMaritalStatus.Items.Clear() : ddlEthnicity.Items.Add(New ListItem("Empty", ""))
            ddlOTName.Items.Clear() : ddlEthnicity.Items.Add(New ListItem("Empty", ""))
        End Try

    End Sub

#End Region

#Region "Controls' events"

    Private Sub DeleteGeneratedClientID()
        Dim oCC_Client As New CC_Client

        Try
            oCC_Client.DeleteGeneratedClientID(hdClientId.Value)
        Catch

        End Try
    End Sub

    Private Sub SetCancel()
        DeleteGeneratedClientID()
        Me.RedirectToHome()
    End Sub

    Private Sub ddlOTName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOTName.SelectedIndexChanged
        Dim oCC_Professional As New CC_Professional
        Dim oEC_Professional As EC_Professional

        Try
            If ddlOTName.SelectedValue.Equals(String.Empty) = False Then
                oEC_Professional = oCC_Professional.GetProfessionalByID(Convert.ToInt32(ddlOTName.SelectedValue))

                If Not oEC_Professional Is Nothing Then
                    With oEC_Professional
                        txtDClientsAddress.Text = .Address.Trim
                        txtDClientsTelephone.Text = .Telephone.Trim
                        txtDClientsPostcode.Text = .Postcode.Trim
                        txtDClientsEmail.Text = .Email.Trim
                    End With
                Else
                    Throw New Exception("oEC_Professional is nothing")
                End If
            Else
                Throw New Exception("Dropdownlist value is empty")
            End If
        Catch ex As Exception
            txtDClientsAddress.Text = String.Empty
            txtDClientsTelephone.Text = String.Empty
            txtDClientsPostcode.Text = String.Empty
            txtDClientsEmail.Text = String.Empty
        End Try

    End Sub

#End Region

#Region "Save"

    Private Sub Save()
        If hdAction.Value.Equals("I") Then
            Insert()
        ElseIf hdAction.Value.Equals("U") Then
            Update()
        ElseIf hdAction.Value.Equals("D") Then
            Delete()
        End If

    End Sub

    Private Sub Insert()
        Dim oEC_Client As EC_Client = SetProperties()
        Dim oCC_Client As New CC_Client
        Dim strMsg As String

        If Not oEC_Client Is Nothing Then
            If oCC_Client.SaveClient(oEC_Client, strMsg) Then
                Me.RedirectToMsgPage(Constants.CONST_MSG_INSERT_SUCCES, "&action=u&clientid=" & oEC_Client.ApplIDN)
            Else
                If strMsg.Equals("INFO_EXISTS") Then
                    Me.RedirectToMsgPage(Constants.CONST_MSG_INSERT_CLIENT_INFOEXISTS)
                ElseIf strMsg.Equals("ID_EXISTS") Then
                    Me.RedirectToMsgPage(Constants.CONST_MSG_INSERT_CLIENT_IDEXISTS)
                Else
                    Me.RedirectToMsgPage(Constants.CONST_ERROR_UNEXPECTED)
                End If
            End If

            oCC_Client.DeleteGeneratedClientID(hdClientId.Value)

        End If

    End Sub

    Private Sub Update()
        Dim oEC_Client As EC_Client = SetProperties()
        Dim oCC_Client As New CC_Client
        Dim strMsg As String

        If Not oEC_Client Is Nothing Then
            If oCC_Client.UpdateClient(hdClientId.Value, oEC_Client, strMsg) Then
                Me.RedirectToMsgPage(Constants.CONST_MSG_UPDATE_SUCCES, "&action=u&clientid=" & oEC_Client.ApplIDN)
            Else
                If strMsg.Equals("OLDID_NOEXISTS") Then
                    Me.RedirectToMsgPage(Constants.CONST_MSG_UPDATE_OLDNOEXISTS)
                ElseIf strMsg.Equals("NEWID_EXISTS") Then
                    Me.RedirectToMsgPage(Constants.CONST_MSG_UPDATE_NEWEXISTS)
                Else
                    Me.RedirectToMsgPage(Constants.CONST_ERROR_UNEXPECTED)
                End If
            End If

        End If
    End Sub

    Private Sub Delete()
        Dim oEC_Client As EC_Client = SetProperties()
        Dim oCC_Client As New CC_Client
        Dim strMsg As String

        If Not oEC_Client Is Nothing Then
            If oCC_Client.DeleteClient(oEC_Client, strMsg) Then
                Me.RedirectToMsgPage(Constants.CONST_MSG_DELETE_SUCCES)
            Else
                If strMsg.Equals("NOEXISTS") Then
                    Me.RedirectToMsgPage(Constants.CONST_MSG_DELETE_NOEXISTS)
                Else
                    Me.RedirectToMsgPage(Constants.CONST_ERROR_UNEXPECTED)
                End If
            End If

        End If
    End Sub

    Private Function SetProperties() As EC_Client
        Dim oEC_Client As New EC_Client
        Dim oEC_User As EC_User = Me.GetUserFromSession

        With oEC_Client
            .Address = txtAddress.Text.Trim
            .AgeProperty = txtAgeProperty.Text.Trim
            .ApplDOB = txtAppBirthDate.Text
            .ApplIDN = txtAppNINumber.Text.Trim.ToUpper
            .Comments = txtComments.Text.Trim
            .ContactName1 = txtContact1.Text.Trim.ToUpper
            .ContactName2 = txtContact2.Text.Trim.ToUpper
            .ContactName3 = txtContact3.Text.Trim.ToUpper

            If rbFold.Checked Then
                .DeedOrganized = "F"
            ElseIf rbClient.Checked Then
                .DeedOrganized = "C"
            Else
                .DeedOrganized = String.Empty
            End If

            .Email = txtAppEmail.Text.Trim
            .Ethnicity = ddlEthnicity.SelectedValue
            .Gender = ddlGender.SelectedValue

            If chkIncomeSupport.Checked Then
                .IncomeSupport = "Y"
            Else
                .IncomeSupport = "N"
            End If

            If chkLandlordConsent.Checked Then
                .LandConsent = "Y"
            Else
                .LandConsent = "N"
            End If

            If chkLoftInsulation.Checked Then
                .LoftInsulation = "Y"
            Else
                .LoftInsulation = "N"
            End If

            .MaritalStatus = ddlMaritalStatus.SelectedValue
            .Mobile = txtMobile.Text.Trim

            If chkMortgageConsent.Checked Then
                .MortConsent = "Y"
            Else
                .MortConsent = "N"
            End If

            If chkMortgage.Checked Then
                .Mortgage = "Y"
            Else
                .Mortgage = "N"
            End If

            .Name = txtName.Text.Trim.ToUpper
            .NameDeed = txtNameOnDeeds.Text.Trim

            If chkOccupPension.Checked Then
                .OccupPension = "Y"
            Else
                .OccupPension = "N"
            End If

            If chkOtherIncome.Checked Then
                .OtherIncome = "Y"
            Else
                .OtherIncome = "N"
            End If

            If chkClientWithOccup.Checked Then
                .OtherOccupants = "Y"
            Else
                .OtherOccupants = "N"
            End If

            .PartDOB = txtPartBirthDate.Text.Trim
            .PartIDN = txtPartnerNINumber.Text.Trim

            If chkPension.Checked Then
                .Pension = "Y"
            Else
                .Pension = "N"
            End If

            If chkPensionCredit.Checked Then
                .PensionCredit = "Y"
            Else
                .PensionCredit = "N"
            End If

            .Postcode = txtPostcode.Text.Trim.ToUpper
            .ProfessionalID = ddlOTName.SelectedValue
            .PropertyType = ddlGenProType.SelectedValue

            If chkProveTitle.Checked Then
                .ProveTitle = "Y"
            Else
                .ProveTitle = "N"
            End If

            .Religion = ddlReligion.SelectedValue
            .SavingAmount = txtMoreLessThan.Text

            If rbMoreThan.Checked Then
                .Savings = "M"
            ElseIf rbLessThan.Checked Then
                .Savings = "L"
            Else
                .Savings = String.Empty
            End If

            .Surname = txtSurname.Text.Trim.ToUpper
            .Telephone = txtTelephone.Text.Trim

            If chkTenancyAgree.Checked Then
                .TenancyAgree = "Y"
            Else
                .TenancyAgree = "N"
            End If

            .Tenure = ddlTenure.SelectedValue
            .Title = ddlTitle.SelectedValue
            .WhereHeld = txtWhereHeld.Text.Trim

            If Not oEC_User Is Nothing Then
                .AddedBy = oEC_User.Login
                .ChangedBy = oEC_User.Login
            End If

        End With

        Return oEC_Client

    End Function

#End Region

#Region "Client's properties"

    Private Sub LoadClient()
        If Not Request.QueryString("action") Is Nothing AndAlso Not Request.QueryString("clientid") Is Nothing Then
            Dim oCC_Client As New CC_Client
            Dim strClientID As String
            Dim oEC_Client As EC_Client

            Try
                strClientID = Request.QueryString("clientid")
                oEC_Client = oCC_Client.GetClientByID(strClientID)

                If Not oEC_Client Is Nothing Then

                    With oEC_Client
                        hdClientId.Value = strClientID 'original client id 
                        txtAddress.Text = .Address.Trim
                        txtAgeProperty.Text = .AgeProperty.Trim
                        txtAppBirthDate.Text = .ApplDOB.Trim
                        txtAppNINumber.Text = .ApplIDN.Trim
                        txtComments.Text = .Comments.Trim
                        txtContact1.Text = .ContactName1.Trim
                        txtContact2.Text = .ContactName2.Trim
                        txtContact3.Text = .ContactName3.Trim

                        If .DeedOrganized.Trim = "F" Then
                            rbFold.Checked = True
                        ElseIf .DeedOrganized = "C" Then
                            rbClient.Checked = True
                        Else
                            rbClient.Checked = False
                            rbFold.Checked = False
                        End If

                        txtAppEmail.Text = .Email.Trim
                        Util.SelectValueFromDropDown(ddlEthnicity, .Ethnicity.Trim)
                        Util.SelectValueFromDropDown(ddlGender, .Gender.Trim)

                        If .IncomeSupport.Trim = "Y" Then
                            chkIncomeSupport.Checked = True
                        Else
                            chkIncomeSupport.Checked = False
                        End If

                        If .LandConsent.Trim = "Y" Then
                            chkLandlordConsent.Checked = True
                        Else
                            chkLandlordConsent.Checked = False
                        End If

                        If .LoftInsulation.Trim = "Y" Then
                            chkLoftInsulation.Checked = True
                        Else
                            chkLoftInsulation.Checked = False
                        End If

                        Util.SelectValueFromDropDown(ddlMaritalStatus, .MaritalStatus.Trim)
                        txtMobile.Text = .Mobile.Trim

                        If .MortConsent.Trim = "Y" Then
                            chkMortgageConsent.Checked = True
                        Else
                            chkMortgageConsent.Checked = False
                        End If

                        If .Mortgage.Trim = "Y" Then
                            chkMortgage.Checked = True
                        Else
                            chkMortgage.Checked = False
                        End If

                        txtName.Text = .Name.Trim
                        txtNameOnDeeds.Text = .NameDeed.Trim

                        If .OccupPension.Trim = "Y" Then
                            chkOccupPension.Checked = True
                        Else
                            chkOccupPension.Checked = False
                        End If

                        If .OtherIncome.Trim = "Y" Then
                            chkOtherIncome.Checked = True
                        Else
                            chkOtherIncome.Checked = False
                        End If

                        If .OtherOccupants.Trim = "Y" Then
                            chkClientWithOccup.Checked = True
                        Else
                            chkClientWithOccup.Checked = False
                        End If

                        txtPartBirthDate.Text = .PartDOB.Trim
                        txtPartnerNINumber.Text = .PartIDN.Trim

                        If .Pension.Trim = "Y" Then
                            chkPension.Checked = True
                        Else
                            chkPension.Checked = False
                        End If

                        If .PensionCredit.Trim = "Y" Then
                            chkPensionCredit.Checked = True
                        Else
                            chkPensionCredit.Checked = False
                        End If

                        txtPostcode.Text = .Postcode.Trim

                        Util.SelectValueFromDropDown(ddlOTName, .ProfessionalID.Trim)
                        ddlOTName_SelectedIndexChanged(Nothing, Nothing)

                        Util.SelectValueFromDropDown(ddlGenProType, .PropertyType.Trim)

                        If .ProveTitle.Trim = "Y" Then
                            chkProveTitle.Checked = True
                        Else
                            chkProveTitle.Checked = False
                        End If

                        Util.SelectValueFromDropDown(ddlReligion, .Religion.Trim)
                        txtMoreLessThan.Text = .SavingAmount.Trim

                        If .Savings.Trim = "M" Then
                            rbMoreThan.Checked = True
                        ElseIf .Savings.Trim = "L" Then
                            rbLessThan.Checked = True
                        Else
                            rbMoreThan.Checked = False
                            rbLessThan.Checked = False
                        End If

                        txtSurname.Text = .Surname.Trim
                        txtTelephone.Text = .Telephone.Trim

                        If .TenancyAgree.Trim = "Y" Then
                            chkTenancyAgree.Checked = True
                        Else
                            chkTenancyAgree.Checked = False
                        End If

                        Util.SelectValueFromDropDown(ddlTenure, .Tenure.Trim)
                        Util.SelectValueFromDropDown(ddlTitle, .Title.Trim)
                        txtWhereHeld.Text = .WhereHeld.Trim

                    End With

                End If

            Catch ex As Exception

            End Try

        End If
    End Sub
#End Region

End Class
