Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class supplier_keycontacts
    Inherits System.Web.UI.Page
    Shared Category(10) As String
    Shared i As Integer
    Shared catid As String
    Shared KeyKid As String
    'Shared SalesKid As String
    'Shared PurchaseKid As String
    'Shared TechnicalKid As String
    'Shared LogisticsKid As String
    'Shared GoodsReturnKid As String
    'Shared AccountsKid As String
    'Shared CustomerCareKid As String
    Shared Mode As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("SupplierID") Is Nothing Then
            Response.Redirect("listproduct.aspx?sess=expire")
            Exit Sub
        End If
        If Request.QueryString("Product") <> Nothing Then
            Session("ProductID") = RemoveLiterals(Request.QueryString("Product").ToString)
        End If
        If Page.IsPostBack = False Then
            If Session.Item("ProductID") Is Nothing Then
                Response.Redirect("List_Product.aspx")
                Exit Sub
            End If

            'txtCountryCode1.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCode1.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCode1.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtPhoneNo1.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtSalesExtn.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodee1.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtMobileNo1.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodeF1.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCodeF1.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtFaxNo1.Attributes.Add("onkeypress", "return numbersonly(event)")


            txtCountryCode2.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCode2.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtPhoneNo2.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtPOExtn.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodee2.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtMobileNo2.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodeF2.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCodeF2.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtFaxNo2.Attributes.Add("onkeypress", "return numbersonly(event)")

            txtCountryCode3.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCode3.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtPhoneNo3.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtTSExtn.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodee3.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtMobileNo3.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodeF3.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCodeF3.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtFaxNo3.Attributes.Add("onkeypress", "return numbersonly(event)")

            txtCountryCode4.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCode4.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtPhoneNo4.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtLCExtn.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodee4.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtMobileNo4.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodeF4.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCodeF4.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtFaxNo4.Attributes.Add("onkeypress", "return numbersonly(event)")

            txtCountryCode5.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCode5.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtPhoneNo5.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtGRSCExtn.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodee5.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtMobileNo5.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodeF5.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCodeF5.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtFaxNo5.Attributes.Add("onkeypress", "return numbersonly(event)")

            txtCountryCode6.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCode6.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtPhoneNo6.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtACExtn.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodee6.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtMobileNo6.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodeF6.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCodeF6.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtFaxNo6.Attributes.Add("onkeypress", "return numbersonly(event)")

            txtCountryCode7.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCode7.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtPhoneNo7.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCCCExtn.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodee7.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtMobileNo7.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCountryCodeF7.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtCityCodeF7.Attributes.Add("onkeypress", "return numbersonly(event)")
            txtFaxNo7.Attributes.Add("onkeypress", "return numbersonly(event)")
            g_Company = Session("g_Company").ToString
            g_User = Session("g_User").ToString
            g_FinYear = Session("g_FinYear").ToString
            catid = ReturnValue("Select Product_CategoryID from Product_Master where Product_Kid= '" & Session("ProductID").ToString() & "'and Product_IsDeleted='0' and Product_CompanyId ='" & g_Company & "' ")
            i = 0
            FillCategoryName(catid, lblSalesCat)
            getsalesexisting()
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                If ddl_SalesOtherProduct.Visible = True Then
                    btnSalesSave.Visible = True
                    btnSalesUpdate.Visible = False
                    unLockControlSalesContact(False)
                Else
                    unLockControlSalesContact(True)
                End If
            End If
            Menu1.Items(0).Selected = True

        End If


    End Sub

    
    ' -----------------------------------------> Menu Event <------------------------------------------
    Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick

        Select Case Menu1.SelectedItem.Value
            Case "0"
                MultiView1.ActiveViewIndex = 0
                salescontacts()
                If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                    If ddl_SalesOtherProduct.Visible = True Then
                        btnSalesSave.Visible = True
                        btnSalesUpdate.Visible = False
                        unLockControlSalesContact(False)
                    Else
                        unLockControlSalesContact(True)
                    End If
                End If
            Case "1"
                MultiView1.ActiveViewIndex = 1
                Purchasecontacts()
                If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                    If ddl_POOtherProduct.Visible = True Then
                        btnPurchaseSave.Visible = True
                        btnPurchaseUpdate.Visible = False
                        unLockControlPOContact(False)
                    Else
                        unLockControlPOContact(True)
                    End If
                End If

            Case "2"
                MultiView1.ActiveViewIndex = 2
                Technicalcontacts()
                If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                    If ddl_TSOtherProducts.Visible = True Then
                        btnTechnicalSave.Visible = True
                        btnTechnicalUpdate.Visible = False
                        unLockControlTSContact(False)
                    Else
                        unLockControlTSContact(True)
                    End If
                End If

            Case "3"
                MultiView1.ActiveViewIndex = 3
                Logisticscontacts()
                If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                    If ddl_LogOtherProducts.Visible = True Then
                        btnLogisticSave.Visible = True
                        btnLogisticUpdate.Visible = False
                        unLockControlLogContact(False)
                    Else
                        unLockControlLogContact(True)
                    End If
                End If

            Case "4"
                MultiView1.ActiveViewIndex = 4
                GoodsReturncontacts()
                If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                    If ddl_GRSOtherProducts.Visible = True Then
                        btnGoodsSave.Visible = True
                        btnGoodsUpdate.Visible = False
                        unLockControlGRSContact(False)
                    Else
                        unLockControlGRSContact(True)
                    End If
                End If

            Case "5"
                MultiView1.ActiveViewIndex = 5
                Accountscontacts()
                If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                    If ddl_ACSOtherProducts.Visible = True Then
                        btnAccountsSave.Visible = True
                        btnAccountsUpdate.Visible = False
                        unLockControlAccountsContact(False)
                    Else
                        unLockControlAccountsContact(True)
                    End If
                End If

            Case "6"
                MultiView1.ActiveViewIndex = 6
                CustomerCarecontacts()
                If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                    If ddl_CCSOtherProducts.Visible = True Then
                        btnCustomerSave.Visible = True
                        btnCustomerUpdate.Visible = False
                        unLockControlCustomerCareContact(False)
                    Else
                        unLockControlCustomerCareContact(True)
                    End If
                End If

            Case "7"
                'Response.Redirect("List_Product.aspx")
        End Select
    End Sub


    ' -----------------------------------------> Sales Contact  <------------------------------------------


    Public Sub salescontacts()
        i = 0
        FillCategoryName(catid, lblSalesCat)
        getsalesexisting()
    End Sub
    Public Sub getsalesexisting()
        Dim dt As Data.DataTable
        dt = getTable("select * from SalesContact where SalesContact_ProductID='" & Session.Item("ProductID").Trim & "' and SalesContact_IsDeleted='0' and SalesContact_CompanyID='" & g_Company.Trim & "'", "SC")
        If dt.Rows.Count > 0 Then
            Mode = "Update"
            KeyKid = dt.Rows(0).Item("SalesContact_Kid").ToString
            txtSalesCode.Text = dt.Rows(0).Item("SalesContact_Code").ToString
            txtSalesCP.Text = dt.Rows(0).Item("SalesContact_ContactPerson").ToString
            txtSalesDesg.Text = dt.Rows(0).Item("SalesContact_Designation").ToString
            txtSalesExtn.Text = dt.Rows(0).Item("SalesContact_PhoneExtn").ToString

            Dim pcountry1, pcity1, phoneno1, mcountry1, mobile1, fcountry1, fcity1, faxno1 As String

            Try
                phoneno1 = dt.Rows(0).Item("SalesContact_PhoneNo").ToString
                If phoneno1.Contains("-") Then
                    pcountry1 = phoneno1.Substring(0, phoneno1.IndexOf("-"))
                    phoneno1 = phoneno1.Substring(phoneno1.IndexOf("-") + 1)
                    If phoneno1.Contains("-") Then
                        pcity1 = phoneno1.Substring(0, phoneno1.IndexOf("-"))
                        phoneno1 = phoneno1.Substring(phoneno1.IndexOf("-") + 1)
                        txtCountryCode1.Text = pcountry1
                        txtCityCode1.Text = pcity1
                        txtPhoneNo1.Text = phoneno1
                    Else
                        txtCityCode1.Text = pcountry1
                        txtPhoneNo1.Text = phoneno1
                    End If
                    
                Else
                    txtPhoneNo1.Text = phoneno1
                End If
                
            Catch ex As Exception
                txtCountryCode1.Text = ""
                txtCityCode1.Text = ""
                txtPhoneNo1.Text = ""
            End Try

            Try
                mobile1 = dt.Rows(0).Item("SalesContact_MobileNo").ToString
                If mobile1.Contains("-") Then
                    mcountry1 = mobile1.Substring(0, mobile1.IndexOf("-"))
                    mobile1 = mobile1.Substring(mobile1.IndexOf("-") + 1)
                    txtCountryCodee1.Text = mcountry1
                    txtMobileNo1.Text = mobile1
                Else
                    txtMobileNo1.Text = mobile1
                End If
                
            Catch ex As Exception
                txtCountryCodee1.Text = ""
                txtMobileNo1.Text = ""
            End Try


            Try
                If IsDBNull(dt.Rows(0).Item("SalesContact_FaxNo")) Then
                Else
                    faxno1 = dt.Rows(0).Item("SalesContact_FaxNo").ToString
                    If faxno1.Contains("-") Then
                        fcountry1 = faxno1.Substring(0, faxno1.IndexOf("-"))
                        faxno1 = faxno1.Substring(faxno1.IndexOf("-") + 1)
                        If faxno1.Contains("-") Then
                            fcity1 = faxno1.Substring(0, faxno1.IndexOf("-"))
                            faxno1 = faxno1.Substring(faxno1.IndexOf("-") + 1)
                            txtCountryCodeF1.Text = fcountry1
                            txtCityCodeF1.Text = fcity1
                            txtFaxNo1.Text = faxno1
                        Else
                            txtCityCodeF1.Text = fcountry1
                            txtFaxNo1.Text = faxno1
                        End If
                        
                    Else
                        txtFaxNo1.Text = faxno1
                    End If
                    
                End If
            Catch ex As Exception
                txtCountryCodeF1.Text = ""
                txtCityCodeF1.Text = ""
                txtFaxNo1.Text = ""
            End Try
            
            txtEmailID.Text = dt.Rows(0).Item("SalesContact_EmailId").ToString
            unLockControlSalesContact(False)
            btnSalesSave.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                btnSalesUpdate.Visible = True
                unLockControlSalesContact(True)
            Else
                btnSalesUpdate.Visible = False
            End If
            'bool_flag = True
            ddl_SalesOtherProduct.Visible = False
            lblSalesExisting.Visible = False
        Else
            ClearFieldsSalesContact()
            Mode = "Insert"
            btnSalesUpdate.Visible = False
            ddl_SalesOtherProduct.Visible = True
            lblSalesExisting.Visible = True
            unLockControlSalesContact(FillExistingDropDown("SELECT SalesContact_ProductId FROM SalesContact WHERE SalesContact_UserId = '" & Session.Item("g_User").ToString.Trim & "' AND SalesContact_CompanyId = '" & g_Company & "' AND SalesContact_IsDeleted = N'0'", ddl_SalesOtherProduct, lblSalesExisting))
            'bool_flag = False
            KeyKid = NewPrimaryKey(Me)
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                unLockControlSalesContact(True)
            End If
            txtSalesCode.Text = Generate_Code("select count(*) from SalesContact where SalesContact_Code='", "SC")
            'ViewState.Add("SExit", False)
        End If
        dt.Clear()
    End Sub
    Protected Sub btnSalesSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSalesSave.Click

        If Page.IsValid = False Then
            CreateMessageAlert(Me, "Please fill Required Information.!", "strkeyval")
            Exit Sub
        Else
            Dim cmd As New Data.SqlClient.SqlCommand()
            Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
            sqlcoll.Clear()

            sqlcoll.Add("@SalesContact_Kid", Data.SqlDbType.NVarChar, 10).Value = RemoveLiterals(KeyKid.ToString.Trim)
            sqlcoll.Add("@SalesContact_Code", Data.SqlDbType.NVarChar, 25).Value = txtSalesCode.Text.Trim
            sqlcoll.Add("@SalesContact_ContactPerson", Data.SqlDbType.NVarChar, 100).Value = txtSalesCP.Text.Trim
            sqlcoll.Add("@SalesContact_Designation", Data.SqlDbType.NVarChar, 50).Value = txtSalesDesg.Text.Trim
            sqlcoll.Add("@SalesContact_PhoneNo", Data.SqlDbType.NVarChar, 15).Value = txtCountryCode1.Text.Trim & "-" & txtCityCode1.Text.Trim & "-" & txtPhoneNo1.Text.Trim
            sqlcoll.Add("@SalesContact_PhoneExtn", Data.SqlDbType.NVarChar, 15).Value = txtSalesExtn.Text.Trim
            sqlcoll.Add("@SalesContact_MobileNo", Data.SqlDbType.NVarChar, 15).Value = txtCountryCodee1.Text & "-" & txtMobileNo1.Text.Trim
            If txtCountryCodeF1.Text = "" And txtCityCodeF1.Text = "" And txtFaxNo1.Text = "" Then

            Else
                sqlcoll.Add("@SalesContact_FaxNo", Data.SqlDbType.NVarChar, 15).Value = txtCountryCodeF1.Text & "-" & txtCityCodeF1.Text & "-" & txtFaxNo1.Text.Trim
            End If
            sqlcoll.Add("@SalesContact_EmailId", Data.SqlDbType.NVarChar, 50).Value = txtEmailID.Text.Trim
            sqlcoll.Add("@SalesContact_ProductId", Data.SqlDbType.NVarChar, 10).Value = Session("ProductID")
            sqlcoll.Add("@SalesContact_FinancialYearId", Data.SqlDbType.NVarChar, 10).Value = g_FinYear
            sqlcoll.Add("@SalesContact_CompanyID", Data.SqlDbType.NVarChar, 10).Value = g_Company
            sqlcoll.Add("@SalesContact_UserID", Data.SqlDbType.NVarChar, 10).Value = g_User
            sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
            sqlcoll.Add("@Mode", Data.SqlDbType.NVarChar, 10).Value = Mode
            ExecQuery("SalesContact_Proc", sqlcoll)
            sqlcoll.Clear()
            CreateMessageAlert(Me, "Sales Contact Saved Successfully.", "StrKeyVal")
            Purchasecontacts()
            MultiView1.ActiveViewIndex = 1

            Menu1.Items(1).Selected = True
            Menu1.StaticSelectedStyle.ForeColor = Drawing.Color.LightGreen
        End If



    End Sub
    Protected Sub ddl_SalesOtherProduct_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_SalesOtherProduct.SelectedIndexChanged
        If ddl_SalesOtherProduct.SelectedIndex > 0 Then
            If ddl_SalesOtherProduct.SelectedItem.Text = "Add New" Then
                unLockControlSalesContact(True)
                ClearFieldsSalesContact()
            Else
                Dim Kid As String = ddl_SalesOtherProduct.SelectedItem.Value

                Dim dt As DataTable = getTable("SELECT     SalesContact.*    FROM SalesContact WHERE     SalesContact_productid = '" & Kid.ToString.Trim & "' AND SalesContact_companyid = '" & g_Company & "' AND SalesContact_IsDeleted = N'0'", "PR")
                If dt.Rows.Count > 0 Then
                    'txtSalesCode.Text = dt.Rows(0).Item("SalesContact_Code").ToString
                    txtSalesCP.Text = dt.Rows(0).Item("SalesContact_ContactPerson").ToString
                    txtSalesDesg.Text = dt.Rows(0).Item("SalesContact_Designation").ToString
                    txtSalesExtn.Text = dt.Rows(0).Item("SalesContact_PhoneExtn").ToString

                    Dim pcountry1, pcity1, phoneno1, mcountry1, mobile1, fcountry1, fcity1, faxno1 As String

                    Try
                        phoneno1 = dt.Rows(0).Item("SalesContact_PhoneNo").ToString
                        If phoneno1.Contains("-") Then
                            pcountry1 = phoneno1.Substring(0, phoneno1.IndexOf("-"))
                            phoneno1 = phoneno1.Substring(phoneno1.IndexOf("-") + 1)
                            If phoneno1.Contains("-") Then
                                pcity1 = phoneno1.Substring(0, phoneno1.IndexOf("-"))
                                phoneno1 = phoneno1.Substring(phoneno1.IndexOf("-") + 1)
                                txtCountryCode1.Text = pcountry1
                                txtCityCode1.Text = pcity1
                                txtPhoneNo1.Text = phoneno1
                            Else
                                txtCityCode1.Text = pcountry1
                                txtPhoneNo1.Text = phoneno1
                            End If

                        Else
                            txtPhoneNo1.Text = phoneno1
                        End If

                    Catch ex As Exception
                        txtCountryCode1.Text = ""
                        txtCityCode1.Text = ""
                        txtPhoneNo1.Text = ""
                    End Try

                    Try
                        mobile1 = dt.Rows(0).Item("SalesContact_MobileNo").ToString
                        If mobile1.Contains("-") Then
                            mcountry1 = mobile1.Substring(0, mobile1.IndexOf("-"))
                            mobile1 = mobile1.Substring(mobile1.IndexOf("-") + 1)
                            txtCountryCodee1.Text = mcountry1
                            txtMobileNo1.Text = mobile1
                        Else
                            txtMobileNo1.Text = mobile1
                        End If

                    Catch ex As Exception
                        txtCountryCodee1.Text = ""
                        txtMobileNo1.Text = ""
                    End Try


                    Try
                        If IsDBNull(dt.Rows(0).Item("SalesContact_FaxNo")) Then
                        Else
                            faxno1 = dt.Rows(0).Item("SalesContact_FaxNo").ToString
                            If faxno1.Contains("-") Then
                                fcountry1 = faxno1.Substring(0, faxno1.IndexOf("-"))
                                faxno1 = faxno1.Substring(faxno1.IndexOf("-") + 1)
                                If faxno1.Contains("-") Then
                                    fcity1 = faxno1.Substring(0, faxno1.IndexOf("-"))
                                    faxno1 = faxno1.Substring(faxno1.IndexOf("-") + 1)
                                    txtCountryCodeF1.Text = fcountry1
                                    txtCityCodeF1.Text = fcity1
                                    txtFaxNo1.Text = faxno1
                                Else
                                    txtCityCodeF1.Text = fcountry1
                                    txtFaxNo1.Text = faxno1
                                End If

                            Else
                                txtFaxNo1.Text = faxno1
                            End If

                        End If
                    Catch ex As Exception
                        txtCountryCodeF1.Text = ""
                        txtCityCodeF1.Text = ""
                        txtFaxNo1.Text = ""
                    End Try
                    txtEmailID.Text = dt.Rows(0).Item("SalesContact_EmailId").ToString
                    unLockControlSalesContact(True)

                    'ddl_ClientOtherProduct.Visible = False
                End If
                dt.Clear()
            End If
        Else
            unLockControlSalesContact(False)
            ClearFieldsSalesContact()
        End If
    End Sub
    Protected Sub btnSalesUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSalesUpdate.Click
        btnSalesSave_Click(sender, e)
    End Sub
    Public Sub unLockControlSalesContact(ByVal Action As Boolean)
        txtCountryCode1.Enabled = Action
        txtCountryCodee1.Enabled = Action
        txtCityCode1.Enabled = Action
        txtCountryCodee1.Enabled = Action
        txtCountryCodeF1.Enabled = Action
        txtSalesCode.Enabled = Action
        txtSalesCP.Enabled = Action
        txtSalesDesg.Enabled = Action
        txtCityCodeF1.Enabled = Action
        txtPhoneNo1.Enabled = Action
        txtSalesExtn.Enabled = Action
        txtMobileNo1.Enabled = Action
        txtFaxNo1.Enabled = Action
        txtEmailID.Enabled = Action
    End Sub
    Public Sub ClearFieldsSalesContact()
        txtCountryCode1.Text = ""
        txtCountryCodee1.Text = ""
        txtCityCode1.Text = ""
        txtCountryCodee1.Text = ""
        txtCountryCodeF1.Text = ""
        '   txtSalesCode.Text = ""
        txtSalesCP.Text = ""
        txtSalesDesg.Text = ""
        txtCityCodeF1.Text = ""
        txtPhoneNo1.Text = ""
        txtSalesExtn.Text = ""
        txtMobileNo1.Text = ""
        txtFaxNo1.Text = ""
        txtEmailID.Text = ""
    End Sub


    ' -----------------------------------------> Purchase Contact  <--------------------------------------

    Public Sub Purchasecontacts()
        i = 0
        FillCategoryName(catid, lblPurchaseCat)
        getPurchaseexisting()
    End Sub
    Public Sub getPurchaseexisting()
        Dim dt As DataTable
        dt = getTable("select * from PurchaseOrderContact where POContact_ProductId='" & Session.Item("ProductID").Trim & "' and POContact_IsDeleted='0' and POContact_CompanyID='" & g_Company.Trim & "' and POContact_UserID='" & g_User.Trim & "'", "PO")
        If dt.Rows.Count > 0 Then
            Mode = "Update"
            KeyKid = dt.Rows(0).Item("POContact_Kid").ToString
            txtPOCode.Text = dt.Rows(0).Item("POContact_Code").ToString
            txtPOCP.Text = dt.Rows(0).Item("POContact_ContactPerson").ToString
            txtPODesg.Text = dt.Rows(0).Item("POContact_Designation").ToString
            txtPOExtn.Text = dt.Rows(0).Item("POContact_PhoneExtn").ToString
            Dim pcountry2, pcity2, phoneno2, mcountry2, mobile2, fcountry2, fcity2, faxno2 As String
            Try
                phoneno2 = dt.Rows(0).Item("POContact_PhoneNo").ToString
                If phoneno2.Contains("-") Then
                    pcountry2 = phoneno2.Substring(0, phoneno2.IndexOf("-"))
                    phoneno2 = phoneno2.Substring(phoneno2.IndexOf("-") + 1)
                    If phoneno2.Contains("-") Then
                        pcity2 = phoneno2.Substring(0, phoneno2.IndexOf("-"))
                        phoneno2 = phoneno2.Substring(phoneno2.IndexOf("-") + 1)
                        txtCountryCode2.Text = pcountry2
                        txtCityCode2.Text = pcity2
                        txtPhoneNo2.Text = phoneno2
                    Else
                        txtCityCode2.Text = pcountry2
                        txtPhoneNo2.Text = phoneno2
                    End If
                    
                Else
                    txtPhoneNo2.Text = phoneno2
                End If
            Catch ex As Exception
                txtCountryCode2.Text = ""
                txtCityCode2.Text = ""
                txtPhoneNo2.Text = ""
            End Try

            Try
                mobile2 = dt.Rows(0).Item("POContact_MobileNo").ToString
                If mobile2.Contains("-") Then
                    mcountry2 = mobile2.Substring(0, mobile2.IndexOf("-"))
                    mobile2 = mobile2.Substring(mobile2.IndexOf("-") + 1)
                    txtCountryCodee2.Text = mcountry2
                    txtMobileNo2.Text = mobile2
                Else
                    txtMobileNo2.Text = mobile2
                End If
                
            Catch ex As Exception
                txtCountryCodee2.Text = ""
                txtMobileNo2.Text = ""

            End Try

            Try
                If IsDBNull(dt.Rows(0).Item("POContact_FaxNo")) Then
                Else
                    faxno2 = dt.Rows(0).Item("POContact_FaxNo").ToString
                    If faxno2.Contains("-") Then
                        fcountry2 = faxno2.Substring(0, faxno2.IndexOf("-"))
                        faxno2 = faxno2.Substring(faxno2.IndexOf("-") + 1)
                        If faxno2.Contains("-") Then
                            fcity2 = faxno2.Substring(0, faxno2.IndexOf("-"))
                            faxno2 = faxno2.Substring(faxno2.IndexOf("-") + 1)
                            txtCountryCodeF2.Text = fcountry2
                            txtCityCodeF2.Text = fcity2
                            txtFaxNo2.Text = faxno2
                        Else
                            txtCityCodeF2.Text = fcountry2
                            txtFaxNo2.Text = faxno2
                        End If
                        
                    Else
                        txtFaxNo2.Text = faxno2
                    End If
                    
                End If
            Catch ex As Exception
                txtCountryCodeF2.Text = ""
                txtCityCodeF2.Text = ""
                txtFaxNo2.Text = ""
            End Try
            
            
            txtPOEmailID.Text = dt.Rows(0).Item("POContact_EmailId").ToString
            unLockControlPOContact(False)
            ddl_POOtherProduct.Visible = False
            lblPerExisting.Visible = False
            btnPurchaseSave.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                btnPurchaseUpdate.Visible = True
                unLockControlPOContact(True)
            Else
                btnPurchaseUpdate.Visible = False
            End If
        Else
            ClearFieldsPOContact()
            Mode = "Insert"
            KeyKid = NewPrimaryKey(Me)
            btnPurchaseUpdate.Visible = False
            unLockControlPOContact(FillExistingDropDown("SELECT POContact_ProductId FROM PurchaseOrderContact WHERE POContact_UserId = '" & Session.Item("g_User").ToString.Trim & "' AND POContact_CompanyId = '" & g_Company & "' AND POContact_IsDeleted = N'0'", ddl_POOtherProduct, lblPerExisting))
            'ddl_POOtherProduct.Visible = True
            'lblPerExisting.Visible = True
            txtPOCode.Text = Generate_Code("select count(*) from PurchaseOrderContact where POContact_Code='", "PO")
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                unLockControlPOContact(True)
            End If
        End If
        dt.Clear()
    End Sub
    Protected Sub btnPurchaseSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPurchaseSave.Click

        Dim cmd As New Data.SqlClient.SqlCommand()
        Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
        sqlcoll.Clear()
        sqlcoll.Add("@POContact_Kid", Data.SqlDbType.NVarChar, 50).Value = RemoveLiterals(KeyKid.ToString.Trim)
        sqlcoll.Add("@POContact_Code", Data.SqlDbType.NVarChar, 50).Value = txtPOCode.Text.Trim
        sqlcoll.Add("@POContact_ContactPerson", Data.SqlDbType.NVarChar, 50).Value = txtPOCP.Text.Trim
        sqlcoll.Add("@POContact_Designation", Data.SqlDbType.NVarChar, 50).Value = txtPODesg.Text.Trim
        sqlcoll.Add("@POContact_PhoneNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCode2.Text & "-" & txtCityCode2.Text & "-" & txtPhoneNo2.Text.Trim
        sqlcoll.Add("@POContact_PhoneExtn", Data.SqlDbType.NVarChar, 50).Value = txtPOExtn.Text.Trim
        sqlcoll.Add("@POContact_MobileNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodee2.Text & "-" & txtMobileNo2.Text.Trim
        If txtCountryCodeF2.Text = "" And txtCityCodeF2.Text = "" And txtFaxNo2.Text = "" Then
        Else
            sqlcoll.Add("@POContact_FaxNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodeF2.Text & "-" & txtCityCodeF2.Text & "-" & txtFaxNo2.Text.Trim
        End If
        sqlcoll.Add("@POContact_EmailId", Data.SqlDbType.NVarChar, 50).Value = txtPOEmailID.Text.Trim
        sqlcoll.Add("@POContact_ProductId", Data.SqlDbType.NVarChar, 50).Value = Session("ProductID")
        sqlcoll.Add("@POContact_FinancialYearId", Data.SqlDbType.NVarChar, 50).Value = g_FinYear
        sqlcoll.Add("@POContact_CompanyID", Data.SqlDbType.NVarChar, 50).Value = g_Company
        sqlcoll.Add("@POContact_UserID", Data.SqlDbType.NVarChar, 50).Value = g_User
        sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
        sqlcoll.Add("@Mode", Data.SqlDbType.Char, 15).Value = "Insert"
        ExecQuery("PurchaseOrderContact_Proc", sqlcoll)
        sqlcoll.Clear()
        CreateMessageAlert(Me, "Purchase Order Contact Saved Successfully.", "StrKeyVal")
        Technicalcontacts()
        MultiView1.ActiveViewIndex = 2
        Menu1.Items(2).Selected = True
        Menu1.StaticSelectedStyle.ForeColor = Drawing.Color.LightGreen

    End Sub
    Protected Sub ddl_POOtherProduct_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_POOtherProduct.SelectedIndexChanged
        If ddl_POOtherProduct.SelectedIndex > 0 Then
            If ddl_POOtherProduct.SelectedItem.Text = "Add New" Then
                unLockControlPOContact(True)
                ClearFieldsPOContact()

            Else
                Dim Kid As String = ddl_POOtherProduct.SelectedItem.Value
                Dim dt As DataTable = getTable("SELECT     PurchaseOrderContact.*    FROM PurchaseOrderContact WHERE     POContact_productid = '" & Kid.ToString.Trim & "' AND POContact_companyid = '" & g_Company & "' AND POContact_IsDeleted = N'0'", "PR")
                If dt.Rows.Count > 0 Then

                    'txtPOCode.Text = dt.Rows(0).Item("POContact_Code").ToString
                    txtPOCP.Text = dt.Rows(0).Item("POContact_ContactPerson").ToString
                    txtPODesg.Text = dt.Rows(0).Item("POContact_Designation").ToString
                    txtPOExtn.Text = dt.Rows(0).Item("POContact_PhoneExtn").ToString
                    Dim pcountry2, pcity2, phoneno2, mcountry2, mobile2, fcountry2, fcity2, faxno2 As String
                    Try
                        phoneno2 = dt.Rows(0).Item("POContact_PhoneNo").ToString
                        If phoneno2.Contains("-") Then
                            pcountry2 = phoneno2.Substring(0, phoneno2.IndexOf("-"))
                            phoneno2 = phoneno2.Substring(phoneno2.IndexOf("-") + 1)
                            If phoneno2.Contains("-") Then
                                pcity2 = phoneno2.Substring(0, phoneno2.IndexOf("-"))
                                phoneno2 = phoneno2.Substring(phoneno2.IndexOf("-") + 1)
                                txtCountryCode2.Text = pcountry2
                                txtCityCode2.Text = pcity2
                                txtPhoneNo2.Text = phoneno2
                            Else
                                txtCityCode2.Text = pcountry2
                                txtPhoneNo2.Text = phoneno2
                            End If

                        Else
                            txtPhoneNo2.Text = phoneno2
                        End If
                    Catch ex As Exception
                        txtCountryCode2.Text = ""
                        txtCityCode2.Text = ""
                        txtPhoneNo2.Text = ""
                    End Try

                    Try
                        mobile2 = dt.Rows(0).Item("POContact_MobileNo").ToString
                        If mobile2.Contains("-") Then
                            mcountry2 = mobile2.Substring(0, mobile2.IndexOf("-"))
                            mobile2 = mobile2.Substring(mobile2.IndexOf("-") + 1)
                            txtCountryCodee2.Text = mcountry2
                            txtMobileNo2.Text = mobile2
                        Else
                            txtMobileNo2.Text = mobile2
                        End If

                    Catch ex As Exception
                        txtCountryCodee2.Text = ""
                        txtMobileNo2.Text = ""

                    End Try

                    Try
                        If IsDBNull(dt.Rows(0).Item("POContact_FaxNo")) Then
                        Else
                            faxno2 = dt.Rows(0).Item("POContact_FaxNo").ToString
                            If faxno2.Contains("-") Then
                                fcountry2 = faxno2.Substring(0, faxno2.IndexOf("-"))
                                faxno2 = faxno2.Substring(faxno2.IndexOf("-") + 1)
                                If faxno2.Contains("-") Then
                                    fcity2 = faxno2.Substring(0, faxno2.IndexOf("-"))
                                    faxno2 = faxno2.Substring(faxno2.IndexOf("-") + 1)
                                    txtCountryCodeF2.Text = fcountry2
                                    txtCityCodeF2.Text = fcity2
                                    txtFaxNo2.Text = faxno2
                                Else
                                    txtCityCodeF2.Text = fcountry2
                                    txtFaxNo2.Text = faxno2
                                End If

                            Else
                                txtFaxNo2.Text = faxno2
                            End If

                        End If
                    Catch ex As Exception
                        txtCountryCodeF2.Text = ""
                        txtCityCodeF2.Text = ""
                        txtFaxNo2.Text = ""
                    End Try
                    txtPOEmailID.Text = dt.Rows(0).Item("POContact_EmailId").ToString

                    unLockControlPOContact(True)

                End If
                dt.Clear()
            End If
        Else
            unLockControlPOContact(False)
            ClearFieldsPOContact()
        End If
    End Sub
    Protected Sub btnPurchaseUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPurchaseUpdate.Click
        btnPurchaseSave_Click(sender, e)
    End Sub
    Public Sub unLockControlPOContact(ByVal Action As Boolean)
        txtPOCode.Enabled = Action
        txtPOCP.Enabled = Action
        txtCountryCode2.Enabled = Action
        txtCountryCodee2.Enabled = Action
        txtCountryCodeF2.Enabled = Action
        txtCityCode2.Enabled = Action
        txtCityCodeF2.Enabled = Action
        txtPODesg.Enabled = Action
        txtPhoneNo2.Enabled = Action
        txtPOExtn.Enabled = Action
        txtMobileNo2.Enabled = Action
        txtFaxNo2.Enabled = Action
        txtPOEmailID.Enabled = Action
    End Sub
    Public Sub ClearFieldsPOContact()
        ' txtPOCode.Text = ""
        txtPOCP.Text = ""
        txtCountryCode2.Text = ""
        txtCountryCodee2.Text = ""
        txtCountryCodeF2.Text = ""
        txtCityCode2.Text = ""
        txtCityCodeF2.Text = ""
        txtPODesg.Text = ""
        txtPhoneNo2.Text = ""
        txtPOExtn.Text = ""
        txtMobileNo2.Text = ""
        txtFaxNo2.Text = ""
        txtPOEmailID.Text = ""
    End Sub



    ' -----------------------------------------> Technical Contact  <-----------------------------------


    Public Sub Technicalcontacts()
        i = 0
        FillCategoryName(catid, LblTechnicalCat)
        gettechnicalexisting()
    End Sub
    Public Sub gettechnicalexisting()
        Dim dt As DataTable
        dt = getTable("select * from TechServicesContact where TechServicesContact_ProductID='" & Session.Item("ProductID").Trim & "' and TechServicesContact_IsDeleted='0' and TechServicesContact_CompanyID='" & g_Company.Trim & "'", "TS")
        If dt.Rows.Count > 0 Then
            Mode = "Update"
            KeyKid = dt.Rows(0).Item("TechServicesContact_Kid").ToString
            txtTSCode.Text = dt.Rows(0).Item("TechServicesContact_Code").ToString
            txtTSCP.Text = dt.Rows(0).Item("TechServicesContact_ContactPerson").ToString
            txtTSDesg.Text = dt.Rows(0).Item("TechServicesContact_Designation").ToString
            txtTSExtn.Text = dt.Rows(0).Item("TechServicesContact_PhoneExtn").ToString

            Dim pcountry3, pcity3, phoneno3, mcountry3, mobile3, fcountry3, fcity3, faxno3 As String

            Try
                phoneno3 = dt.Rows(0).Item("TechServicesContact_PhoneNo").ToString
                If phoneno3.Contains("-") Then
                    pcountry3 = phoneno3.Substring(0, phoneno3.IndexOf("-"))
                    phoneno3 = phoneno3.Substring(phoneno3.IndexOf("-") + 1)
                    If phoneno3.Contains("-") Then
                        pcity3 = phoneno3.Substring(0, phoneno3.IndexOf("-"))
                        phoneno3 = phoneno3.Substring(phoneno3.IndexOf("-") + 1)
                        txtCountryCode3.Text = pcountry3
                        txtCityCode3.Text = pcity3
                        txtPhoneNo3.Text = phoneno3
                    Else
                        txtCityCode3.Text = pcountry3
                        txtPhoneNo3.Text = phoneno3
                    End If
                    
                Else
                    txtPhoneNo3.Text = phoneno3
                End If
                
            Catch ex As Exception
                txtCountryCode3.Text = ""
                txtCityCode3.Text = ""
                txtPhoneNo3.Text = ""
            End Try

            Try
                mobile3 = dt.Rows(0).Item("TechServicesContact_MobileNo").ToString
                If mobile3.Contains("-") Then
                    mcountry3 = mobile3.Substring(0, mobile3.IndexOf("-"))
                    mobile3 = mobile3.Substring(mobile3.IndexOf("-") + 1)
                    txtCountryCodee3.Text = mcountry3
                    txtMobileNo3.Text = mobile3
                Else
                    txtMobileNo3.Text = mobile3
                End If
                
            Catch ex As Exception
                txtCountryCodee3.Text = ""
                txtMobileNo3.Text = ""
            End Try

            Try
                If IsDBNull(dt.Rows(0).Item("TechServicesContact_FaxNo")) Then
                Else
                    faxno3 = dt.Rows(0).Item("TechServicesContact_FaxNo").ToString
                    If faxno3.Contains("-") Then
                        fcountry3 = faxno3.Substring(0, faxno3.IndexOf("-"))
                        faxno3 = faxno3.Substring(faxno3.IndexOf("-") + 1)
                        If faxno3.Contains("-") Then
                            fcity3 = faxno3.Substring(0, faxno3.IndexOf("-"))
                            faxno3 = faxno3.Substring(faxno3.IndexOf("-") + 1)
                            txtCountryCodeF3.Text = fcountry3
                            txtCityCodeF3.Text = fcity3
                            txtFaxNo3.Text = faxno3
                        Else
                            txtCityCodeF3.Text = fcountry3
                            txtFaxNo3.Text = faxno3
                        End If
                        
                    Else
                        txtFaxNo3.Text = faxno3
                    End If
                    
                End If
            Catch ex As Exception
                txtCountryCodeF3.Text = ""
                txtCityCodeF3.Text = ""
                txtFaxNo3.Text = ""

            End Try
            
            
            txtTSEmailID.Text = dt.Rows(0).Item("TechServicesContact_EmailId").ToString
            unLockControlTSContact(False)
            ddl_TSOtherProducts.Visible = False
            lblTechExisting.Visible = False

            btnTechnicalSave.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                btnTechnicalUpdate.Visible = True
                unLockControlTSContact(True)
            Else
                btnTechnicalUpdate.Visible = False
            End If

        Else
            ClearFieldsTSContact()
            Mode = "Insert"
            unLockControlTSContact(FillExistingDropDown("SELECT TechServicesContact_ProductId FROM TechServicesContact WHERE TechServicesContact_UserId = '" & Session.Item("g_User").ToString.Trim & "' AND TechServicesContact_CompanyId = '" & g_Company & "' AND TechServicesContact_IsDeleted = N'0'", ddl_TSOtherProducts, lblTechExisting))
            btnTechnicalUpdate.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                unLockControlTSContact(True)
            End If
            KeyKid = NewPrimaryKey(Me)
            'ddl_TSOtherProducts.Visible = True
            'lblTechExisting.Visible = True
            txtTSCode.Text = Generate_Code("select count(*) from TechServicesContact where TechServicesContact_Code='", "TS")
            ViewState.Add("TExit", False)
        End If
        dt.Clear()
    End Sub
    Protected Sub btnTechnicalSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTechnicalSave.Click

        Dim cmd As New Data.SqlClient.SqlCommand()
        Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
        sqlcoll.Clear()
        sqlcoll.Add("@TechServicesContact_Kid", Data.SqlDbType.NVarChar, 50).Value = RemoveLiterals(KeyKid.ToString.Trim)
        sqlcoll.Add("@TechServicesContact_Code", Data.SqlDbType.NVarChar, 50).Value = txtTSCode.Text.Trim
        sqlcoll.Add("@TechServicesContact_ContactPerson", Data.SqlDbType.NVarChar, 50).Value = txtTSCP.Text.Trim
        sqlcoll.Add("@TechServicesContact_Designation", Data.SqlDbType.NVarChar, 50).Value = txtTSDesg.Text.Trim
        sqlcoll.Add("@TechServicesContact_PhoneNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCode3.Text & "-" & txtCityCode3.Text & "-" & txtPhoneNo3.Text.Trim
        sqlcoll.Add("@TechServicesContact_PhoneExtn", Data.SqlDbType.NVarChar, 50).Value = txtTSExtn.Text.Trim
        sqlcoll.Add("@TechServicesContact_MobileNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodee3.Text & "-" & txtMobileNo3.Text
        If txtCountryCodeF3.Text = "" And txtCityCodeF3.Text = "" And txtFaxNo3.Text = "" Then
        Else
            sqlcoll.Add("@TechServicesContact_FaxNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodeF3.Text & "-" & txtCityCodeF3.Text & "-" & txtFaxNo3.Text.Trim
        End If
        sqlcoll.Add("@TechServicesContact_EmailId", Data.SqlDbType.NVarChar, 50).Value = txtTSEmailID.Text.Trim
        sqlcoll.Add("@TechServicesContact_ProductId", Data.SqlDbType.NVarChar, 50).Value = Session("ProductID")
        sqlcoll.Add("@TechServicesContact_FinancialYearId", Data.SqlDbType.NVarChar, 50).Value = g_FinYear
        sqlcoll.Add("@TechServicesContact_CompanyID", Data.SqlDbType.NVarChar, 50).Value = g_Company
        sqlcoll.Add("@TechServicesContact_UserID", Data.SqlDbType.NVarChar, 50).Value = g_User
        sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
        sqlcoll.Add("@Mode", Data.SqlDbType.Char, 15).Value = Mode
        ExecQuery("TechServicesContact_Proc", sqlcoll)
        sqlcoll.Clear()
        CreateMessageAlert(Me, "Technical Services Contact Saved Successfully.", "StrKeyVal")
        Logisticscontacts()
        MultiView1.ActiveViewIndex = 3
        Menu1.Items(3).Selected = True
        Menu1.StaticSelectedStyle.ForeColor = Drawing.Color.LightGreen
    End Sub
    Protected Sub ddl_TSOtherProducts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_TSOtherProducts.SelectedIndexChanged
        If ddl_TSOtherProducts.SelectedIndex > 0 Then
            If ddl_TSOtherProducts.SelectedItem.Text = "Add New" Then
                unLockControlTSContact(True)
                ClearFieldsTSContact()

            Else
                Dim Kid As String = ddl_TSOtherProducts.SelectedItem.Value

                Dim dt As DataTable = getTable("SELECT     TechServicesContact.*    FROM TechServicesContact WHERE     TechServicesContact_productid = '" & Kid.ToString.Trim & "' AND TechServicesContact_companyid = '" & g_Company & "' AND TechServicesContact_IsDeleted = N'0'", "PR")
                If dt.Rows.Count > 0 Then

                    'txtTSCode.Text = dt.Rows(0).Item("TechServicesContact_Code").ToString
                    txtTSCP.Text = dt.Rows(0).Item("TechServicesContact_ContactPerson").ToString
                    txtTSDesg.Text = dt.Rows(0).Item("TechServicesContact_Designation").ToString
                    txtTSExtn.Text = dt.Rows(0).Item("TechServicesContact_PhoneExtn").ToString

                    Dim pcountry3, pcity3, phoneno3, mcountry3, mobile3, fcountry3, fcity3, faxno3 As String

                    Try
                        phoneno3 = dt.Rows(0).Item("TechServicesContact_PhoneNo").ToString
                        If phoneno3.Contains("-") Then
                            pcountry3 = phoneno3.Substring(0, phoneno3.IndexOf("-"))
                            phoneno3 = phoneno3.Substring(phoneno3.IndexOf("-") + 1)
                            If phoneno3.Contains("-") Then
                                pcity3 = phoneno3.Substring(0, phoneno3.IndexOf("-"))
                                phoneno3 = phoneno3.Substring(phoneno3.IndexOf("-") + 1)
                                txtCountryCode3.Text = pcountry3
                                txtCityCode3.Text = pcity3
                                txtPhoneNo3.Text = phoneno3
                            Else
                                txtCityCode3.Text = pcountry3
                                txtPhoneNo3.Text = phoneno3
                            End If

                        Else
                            txtPhoneNo3.Text = phoneno3
                        End If

                    Catch ex As Exception
                        txtCountryCode3.Text = ""
                        txtCityCode3.Text = ""
                        txtPhoneNo3.Text = ""
                    End Try

                    Try
                        mobile3 = dt.Rows(0).Item("TechServicesContact_MobileNo").ToString
                        If mobile3.Contains("-") Then
                            mcountry3 = mobile3.Substring(0, mobile3.IndexOf("-"))
                            mobile3 = mobile3.Substring(mobile3.IndexOf("-") + 1)
                            txtCountryCodee3.Text = mcountry3
                            txtMobileNo3.Text = mobile3
                        Else
                            txtMobileNo3.Text = mobile3
                        End If

                    Catch ex As Exception
                        txtCountryCodee3.Text = ""
                        txtMobileNo3.Text = ""
                    End Try

                    Try
                        If IsDBNull(dt.Rows(0).Item("TechServicesContact_FaxNo")) Then
                        Else
                            faxno3 = dt.Rows(0).Item("TechServicesContact_FaxNo").ToString
                            If faxno3.Contains("-") Then
                                fcountry3 = faxno3.Substring(0, faxno3.IndexOf("-"))
                                faxno3 = faxno3.Substring(faxno3.IndexOf("-") + 1)
                                If faxno3.Contains("-") Then
                                    fcity3 = faxno3.Substring(0, faxno3.IndexOf("-"))
                                    faxno3 = faxno3.Substring(faxno3.IndexOf("-") + 1)
                                    txtCountryCodeF3.Text = fcountry3
                                    txtCityCodeF3.Text = fcity3
                                    txtFaxNo3.Text = faxno3
                                Else
                                    txtCityCodeF3.Text = fcountry3
                                    txtFaxNo3.Text = faxno3
                                End If

                            Else
                                txtFaxNo3.Text = faxno3
                            End If

                        End If
                    Catch ex As Exception
                        txtCountryCodeF3.Text = ""
                        txtCityCodeF3.Text = ""
                        txtFaxNo3.Text = ""

                    End Try
                    txtTSEmailID.Text = dt.Rows(0).Item("TechServicesContact_EmailId").ToString

                    unLockControlTSContact(True)

                End If
                dt.Clear()
            End If
        Else
            unLockControlTSContact(False)
            ClearFieldsTSContact()
        End If
    End Sub
    Protected Sub btnTechnicalUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTechnicalUpdate.Click
        btnTechnicalSave_Click(sender, e)
    End Sub
    Public Sub unLockControlTSContact(ByVal Action As Boolean)
        txtTSCode.Enabled = Action
        txtTSCP.Enabled = Action
        txtTSDesg.Enabled = Action
        txtCountryCode3.Enabled = Action
        txtCountryCodee3.Enabled = Action
        txtCountryCodeF3.Enabled = Action
        txtCityCode3.Enabled = Action
        txtCityCodeF3.Enabled = Action
        txtPhoneNo3.Enabled = Action
        txtTSExtn.Enabled = Action
        txtMobileNo3.Enabled = Action
        txtFaxNo3.Enabled = Action
        txtTSEmailID.Enabled = Action
    End Sub
    Public Sub ClearFieldsTSContact()
        '  txtTSCode.Text = ""
        txtTSCP.Text = ""
        txtTSDesg.Text = ""
        txtCountryCode3.Text = ""
        txtCountryCodee3.Text = ""
        txtCountryCodeF3.Text = ""
        txtCityCode3.Text = ""
        txtCityCodeF3.Text = ""
        txtPhoneNo3.Text = ""
        txtTSExtn.Text = ""
        txtMobileNo3.Text = ""
        txtFaxNo3.Text = ""
        txtTSEmailID.Text = ""
    End Sub



    ' -----------------------------------------> Logistics Contact  <---------------------------------------


    Public Sub Logisticscontacts()
        i = 0
        FillCategoryName(catid, lblLogisticsCat)
        getlogisticsexisting()

    End Sub
    Public Sub getlogisticsexisting()
        Dim dt As DataTable
        dt = getTable("select * from LogisticsContact where LogisticsContact_ProductID='" & Session.Item("ProductID").Trim & "' and LogisticsContact_IsDeleted='0' and LogisticsContact_CompanyID='" & g_Company.Trim & "'", "LC")
        If dt.Rows.Count > 0 Then
            Mode = "Update"
            KeyKid = dt.Rows(0).Item("LogisticsContact_Kid").ToString
            txtLCCode.Text = dt.Rows(0).Item("LogisticsContact_Code").ToString
            txtLCCP.Text = dt.Rows(0).Item("LogisticsContact_ContactPerson").ToString
            txtLCDesg.Text = dt.Rows(0).Item("LogisticsContact_Designation").ToString
            txtLCExtn.Text = dt.Rows(0).Item("LogisticsContact_PhoneExtn").ToString

            Dim pcountry4, pcity4, phoneno4, mcountry4, mobile4, fcountry4, fcity4, faxno4 As String

            Try
                phoneno4 = dt.Rows(0).Item("LogisticsContact_PhoneNo").ToString
                If phoneno4.Contains("-") Then
                    pcountry4 = phoneno4.Substring(0, phoneno4.IndexOf("-"))
                    phoneno4 = phoneno4.Substring(phoneno4.IndexOf("-") + 1)
                    If phoneno4.Contains("-") Then
                        pcity4 = phoneno4.Substring(0, phoneno4.IndexOf("-"))
                        phoneno4 = phoneno4.Substring(phoneno4.IndexOf("-") + 1)
                        txtCountryCode4.Text = pcountry4
                        txtCityCode4.Text = pcity4
                        txtPhoneNo4.Text = phoneno4
                    Else
                        txtCityCode4.Text = pcountry4
                        txtPhoneNo4.Text = phoneno4
                    End If
                    
                Else
                    txtPhoneNo4.Text = phoneno4
                End If
                
            Catch ex As Exception
                txtCountryCode4.Text = ""
                txtCityCode4.Text = ""
                txtPhoneNo4.Text = ""
            End Try

            Try
                mobile4 = dt.Rows(0).Item("LogisticsContact_MobileNo").ToString
                If mobile4.Contains("-") Then
                    mcountry4 = mobile4.Substring(0, mobile4.IndexOf("-"))
                    mobile4 = mobile4.Substring(mobile4.IndexOf("-") + 1)
                    txtCountryCodee4.Text = mcountry4
                    txtMobileNo4.Text = mobile4
                Else
                    txtMobileNo4.Text = mobile4
                End If
                
            Catch ex As Exception
                txtCountryCodee4.Text = ""
                txtMobileNo4.Text = ""
            End Try

            Try
                If IsDBNull(dt.Rows(0).Item("LogisticsContact_FaxNo")) Then
                Else
                    faxno4 = dt.Rows(0).Item("LogisticsContact_FaxNo").ToString
                    If faxno4.Contains("-") Then
                        fcountry4 = faxno4.Substring(0, faxno4.IndexOf("-"))
                        faxno4 = faxno4.Substring(faxno4.IndexOf("-") + 1)
                        If faxno4.Contains("-") Then
                            fcity4 = faxno4.Substring(0, faxno4.IndexOf("-"))
                            faxno4 = faxno4.Substring(faxno4.IndexOf("-") + 1)
                            txtCountryCodeF4.Text = fcountry4
                            txtCityCodeF4.Text = fcity4
                            txtFaxNo4.Text = faxno4
                        Else
                            txtCityCodeF4.Text = fcountry4
                            txtFaxNo4.Text = faxno4
                        End If
                        
                    Else
                        txtFaxNo4.Text = faxno4
                    End If
                    
                End If
            Catch ex As Exception
                txtCountryCodeF4.Text = ""
                txtCityCodeF4.Text = ""
                txtFaxNo4.Text = ""
            End Try
            
            txtLCEmailID.Text = dt.Rows(0).Item("LogisticsContact_EmailId").ToString
            unLockControlLogContact(False)
            ddl_LogOtherProducts.Visible = False
            lblLogisticsExisting.Visible = False

            btnLogisticSave.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                btnLogisticUpdate.Visible = True
                unLockControlLogContact(True)
            Else
                btnLogisticUpdate.Visible = False
            End If

        Else
            ClearFieldsLogContact()
            Mode = "Insert"
            KeyKid = NewPrimaryKey(Me)
            unLockControlLogContact(FillExistingDropDown("SELECT LogisticsContact_ProductId FROM LogisticsContact WHERE LogisticsContact_UserId = '" & Session.Item("g_User").ToString.Trim & "' AND LogisticsContact_CompanyId = '" & g_Company & "' AND LogisticsContact_IsDeleted = N'0'", ddl_LogOtherProducts, lblLogisticsExisting))
            btnLogisticUpdate.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                unLockControlLogContact(True)
            End If
            'ddl_LogOtherProducts.Visible = True
            'lblLogisticsExisting.Visible = True
            txtLCCode.Text = Generate_Code("select count(*) from LogisticsContact where LogisticsContact_Code='", "LC")
        End If
        dt.Clear()
    End Sub
    Protected Sub btnLogisticSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogisticSave.Click
        Dim cmd As New Data.SqlClient.SqlCommand()
        Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
        sqlcoll.Clear()
        sqlcoll.Add("@LogisticsContact_Kid", Data.SqlDbType.NVarChar, 50).Value = RemoveLiterals(KeyKid.ToString.Trim)
        sqlcoll.Add("@LogisticsContact_Code", Data.SqlDbType.NVarChar, 50).Value = txtLCCode.Text.Trim
        sqlcoll.Add("@LogisticsContact_ContactPerson", Data.SqlDbType.NVarChar, 50).Value = txtLCCP.Text.Trim
        sqlcoll.Add("@LogisticsContact_Designation", Data.SqlDbType.NVarChar, 50).Value = txtLCDesg.Text.Trim
        sqlcoll.Add("@LogisticsContact_PhoneNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCode4.Text & "-" & txtCityCode4.Text & "-" & txtPhoneNo4.Text.Trim
        sqlcoll.Add("@LogisticsContact_PhoneExtn", Data.SqlDbType.NVarChar, 50).Value = txtLCExtn.Text.Trim
        sqlcoll.Add("@LogisticsContact_MobileNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodee4.Text & "-" & txtMobileNo4.Text.Trim
        If txtCountryCodeF4.Text = "" And txtCityCodeF4.Text = "" And txtFaxNo4.Text = "" Then
        Else
            sqlcoll.Add("@LogisticsContact_FaxNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodeF4.Text & "-" & txtCityCodeF4.Text & "-" & txtFaxNo4.Text.Trim
        End If
        sqlcoll.Add("@LogisticsContact_EmailId", Data.SqlDbType.NVarChar, 50).Value = txtLCEmailID.Text.Trim
        sqlcoll.Add("@LogisticsContact_ProductId", Data.SqlDbType.NVarChar, 50).Value = Session("ProductID")
        sqlcoll.Add("@LogisticsContact_FinancialYearId", Data.SqlDbType.NVarChar, 50).Value = g_FinYear
        sqlcoll.Add("@LogisticsContact_CompanyID", Data.SqlDbType.NVarChar, 50).Value = g_Company
        sqlcoll.Add("@LogisticsContact_UserID", Data.SqlDbType.NVarChar, 50).Value = g_User
        sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
        sqlcoll.Add("@Mode", Data.SqlDbType.Char, 15).Value = Mode
        ExecQuery("LogisticsContact_Proc", sqlcoll)
        sqlcoll.Clear()
        CreateMessageAlert(Me, "Logistic Contact Saved Successfully.", "StrKeyVal")
        GoodsReturncontacts()
        MultiView1.ActiveViewIndex = 4
        Menu1.Items(4).Selected = True
        Menu1.StaticSelectedStyle.ForeColor = Drawing.Color.LightGreen
    End Sub
    Protected Sub ddl_LogOtherProducts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_LogOtherProducts.SelectedIndexChanged
        If ddl_LogOtherProducts.SelectedIndex > 0 Then
            If ddl_LogOtherProducts.SelectedItem.Text = "Add New" Then
                unLockControlLogContact(True)
                ClearFieldsLogContact()
            Else
                unLockControlLogContact(True)
                Dim Kid As String = ddl_LogOtherProducts.SelectedItem.Value

                Dim dt As DataTable = getTable("SELECT     LogisticsContact.*    FROM LogisticsContact WHERE     LogisticsContact_productid = '" & Kid.ToString.Trim & "' AND LogisticsContact_companyid = '" & g_Company & "' AND LogisticsContact_IsDeleted = N'0'", "PR")
                If dt.Rows.Count > 0 Then
                    'txtLCCode.Text = dt.Rows(0).Item("LogisticsContact_Code").ToString
                    txtLCCP.Text = dt.Rows(0).Item("LogisticsContact_ContactPerson").ToString
                    txtLCDesg.Text = dt.Rows(0).Item("LogisticsContact_Designation").ToString
                    txtLCExtn.Text = dt.Rows(0).Item("LogisticsContact_PhoneExtn").ToString
                    Dim pcountry4, pcity4, phoneno4, mcountry4, mobile4, fcountry4, fcity4, faxno4 As String

                    Try
                        phoneno4 = dt.Rows(0).Item("LogisticsContact_PhoneNo").ToString
                        If phoneno4.Contains("-") Then
                            pcountry4 = phoneno4.Substring(0, phoneno4.IndexOf("-"))
                            phoneno4 = phoneno4.Substring(phoneno4.IndexOf("-") + 1)
                            If phoneno4.Contains("-") Then
                                pcity4 = phoneno4.Substring(0, phoneno4.IndexOf("-"))
                                phoneno4 = phoneno4.Substring(phoneno4.IndexOf("-") + 1)
                                txtCountryCode4.Text = pcountry4
                                txtCityCode4.Text = pcity4
                                txtPhoneNo4.Text = phoneno4
                            Else
                                txtCityCode4.Text = pcountry4
                                txtPhoneNo4.Text = phoneno4
                            End If

                        Else
                            txtPhoneNo4.Text = phoneno4
                        End If

                    Catch ex As Exception
                        txtCountryCode4.Text = ""
                        txtCityCode4.Text = ""
                        txtPhoneNo4.Text = ""
                    End Try

                    Try
                        mobile4 = dt.Rows(0).Item("LogisticsContact_MobileNo").ToString
                        If mobile4.Contains("-") Then
                            mcountry4 = mobile4.Substring(0, mobile4.IndexOf("-"))
                            mobile4 = mobile4.Substring(mobile4.IndexOf("-") + 1)
                            txtCountryCodee4.Text = mcountry4
                            txtMobileNo4.Text = mobile4
                        Else
                            txtMobileNo4.Text = mobile4
                        End If

                    Catch ex As Exception
                        txtCountryCodee4.Text = ""
                        txtMobileNo4.Text = ""
                    End Try

                    Try
                        If IsDBNull(dt.Rows(0).Item("LogisticsContact_FaxNo")) Then
                        Else
                            faxno4 = dt.Rows(0).Item("LogisticsContact_FaxNo").ToString
                            If faxno4.Contains("-") Then
                                fcountry4 = faxno4.Substring(0, faxno4.IndexOf("-"))
                                faxno4 = faxno4.Substring(faxno4.IndexOf("-") + 1)
                                If faxno4.Contains("-") Then
                                    fcity4 = faxno4.Substring(0, faxno4.IndexOf("-"))
                                    faxno4 = faxno4.Substring(faxno4.IndexOf("-") + 1)
                                    txtCountryCodeF4.Text = fcountry4
                                    txtCityCodeF4.Text = fcity4
                                    txtFaxNo4.Text = faxno4
                                Else
                                    txtCityCodeF4.Text = fcountry4
                                    txtFaxNo4.Text = faxno4
                                End If

                            Else
                                txtFaxNo4.Text = faxno4
                            End If

                        End If
                    Catch ex As Exception
                        txtCountryCodeF4.Text = ""
                        txtCityCodeF4.Text = ""
                        txtFaxNo4.Text = ""
                    End Try
                    txtLCEmailID.Text = dt.Rows(0).Item("LogisticsContact_EmailId").ToString
                    unLockControlTSContact(True)

                End If
                dt.Clear()
            End If
        Else
            unLockControlLogContact(False)
            ClearFieldsLogContact()
        End If
    End Sub
    Protected Sub btnLogisticUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogisticUpdate.Click
        btnLogisticSave_Click(sender, e)
    End Sub
    Public Sub unLockControlLogContact(ByVal Action As Boolean)
        txtLCCode.Enabled = Action
        txtLCCP.Enabled = Action
        txtLCDesg.Enabled = Action
        txtCountryCode4.Enabled = Action
        txtCountryCodee4.Enabled = Action
        txtCountryCodeF4.Enabled = Action
        txtCityCode4.Enabled = Action
        txtCityCodeF4.Enabled = Action
        txtPhoneNo4.Enabled = Action
        txtLCExtn.Enabled = Action
        txtMobileNo4.Enabled = Action
        txtFaxNo4.Enabled = Action
        txtLCEmailID.Enabled = Action
    End Sub
    Public Sub ClearFieldsLogContact()
        '     txtLCCode.Text = ""
        txtLCCP.Text = ""
        txtLCDesg.Text = ""
        txtCountryCode4.Text = ""
        txtCountryCodee4.Text = ""
        txtCountryCodeF4.Text = ""
        txtCityCode4.Text = ""
        txtCityCodeF4.Text = ""
        txtPhoneNo4.Text = ""
        txtLCExtn.Text = ""
        txtMobileNo4.Text = ""
        txtFaxNo4.Text = ""
        txtLCEmailID.Text = ""
    End Sub


    ' -----------------------------------------> Goods Return Contact  <---------------------------------------


    Public Sub GoodsReturncontacts()
        i = 0
        FillCategoryName(catid, lblGoodsReturnCat)
        getgoodsreturnexisting()
    End Sub
    Public Sub getgoodsreturnexisting()
        Dim dt As DataTable
        dt = getTable("select * from GoodsReturnServicesContact where GRSC_ProductID='" & Session.Item("ProductID").Trim & "' and GRSC_IsDeleted='0' and GRSC_CompanyID='" & g_Company.Trim & "'", "GRSC")
        If dt.Rows.Count > 0 Then
            Mode = "Update"
            KeyKid = dt.Rows(0).Item("GRSC_Kid").ToString
            txtGRSCCode.Text = dt.Rows(0).Item("GRSC_Code").ToString
            txtGRSCCP.Text = dt.Rows(0).Item("GRSC_ContactPerson").ToString
            txtGRSCDesg.Text = dt.Rows(0).Item("GRSC_Designation").ToString
            txtGRSCExtn.Text = dt.Rows(0).Item("GRSC_PhoneExtn").ToString

            Dim pcountry5, pcity5, phoneno5, mcountry5, mobile5, fcountry5, fcity5, faxno5 As String
            Try
                phoneno5 = dt.Rows(0).Item("GRSC_PhoneNo").ToString
                If phoneno5.Contains("-") Then
                    pcountry5 = phoneno5.Substring(0, phoneno5.IndexOf("-"))
                    phoneno5 = phoneno5.Substring(phoneno5.IndexOf("-") + 1)
                    If phoneno5.Contains("-") Then
                        pcity5 = phoneno5.Substring(0, phoneno5.IndexOf("-"))
                        phoneno5 = phoneno5.Substring(phoneno5.IndexOf("-") + 1)
                        txtCountryCode5.Text = pcountry5
                        txtCityCode5.Text = pcity5
                        txtPhoneNo5.Text = phoneno5
                    Else
                        txtCityCode5.Text = pcountry5
                        txtPhoneNo5.Text = phoneno5
                    End If
                    
                Else
                    txtPhoneNo5.Text = phoneno5
                End If
                
            Catch ex As Exception
                txtCountryCode5.Text = ""
                txtCityCode5.Text = ""
                txtPhoneNo5.Text = ""
            End Try

            Try
                mobile5 = dt.Rows(0).Item("GRSC_MobileNo").ToString
                If mobile5.Contains("-") Then
                    mcountry5 = mobile5.Substring(0, mobile5.IndexOf("-"))
                    mobile5 = mobile5.Substring(mobile5.IndexOf("-") + 1)
                    txtCountryCodee5.Text = mcountry5
                    txtMobileNo5.Text = mobile5
                Else
                    txtMobileNo5.Text = mobile5
                End If
                
            Catch ex As Exception
                txtCountryCodee5.Text = ""
                txtMobileNo5.Text = ""
            End Try

            Try
                If IsDBNull(dt.Rows(0).Item("GRSC_FaxNo")) Then
                Else
                    faxno5 = dt.Rows(0).Item("GRSC_FaxNo").ToString
                    If faxno5.Contains("-") Then
                        fcountry5 = faxno5.Substring(0, faxno5.IndexOf("-"))
                        faxno5 = faxno5.Substring(faxno5.IndexOf("-") + 1)
                        If faxno5.Contains("-") Then
                            fcity5 = faxno5.Substring(0, faxno5.IndexOf("-"))
                            faxno5 = faxno5.Substring(faxno5.IndexOf("-") + 1)
                            txtCountryCodeF5.Text = fcountry5
                            txtCityCodeF5.Text = fcity5
                            txtFaxNo5.Text = faxno5
                        Else
                            txtCityCodeF5.Text = fcountry5
                            txtFaxNo5.Text = faxno5
                        End If
                        
                    Else
                        txtFaxNo5.Text = faxno5
                    End If
                    
                End If
            Catch ex As Exception
                txtCountryCodeF5.Text = ""
                txtCityCodeF5.Text = ""
                txtFaxNo5.Text = ""

            End Try
            
            txtGRSCEmailID.Text = dt.Rows(0).Item("GRSC_EmailId").ToString

            unLockControlGRSContact(False)
            ddl_GRSOtherProducts.Visible = False
            lblGoodsReturnExisting.Visible = False

            btnGoodsSave.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                unLockControlGRSContact(True)
                btnGoodsUpdate.Visible = True
            Else
                btnGoodsUpdate.Visible = False
            End If

        Else
            ClearFieldsGRSContact()
            Mode = "Insert"
            KeyKid = NewPrimaryKey(Me)
            unLockControlGRSContact(FillExistingDropDown("SELECT GRSC_ProductId FROM GoodsReturnServicesContact WHERE GRSC_UserId = '" & Session.Item("g_User").ToString.Trim & "' AND GRSC_CompanyId = '" & g_Company & "' AND GRSC_IsDeleted = N'0'", ddl_GRSOtherProducts, lblGoodsReturnExisting))
            btnGoodsUpdate.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                unLockControlGRSContact(True)
            End If
            'ddl_GRSOtherProducts.Visible = True
            'lblGoodsReturnExisting.Visible = True
            txtGRSCCode.Text = Generate_Code("select count(*) from GoodsReturnServicesContact where GRSC_Code='", "GRSC")
        End If
        dt.Clear()
    End Sub
    Protected Sub btnGoodsSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGoodsSave.Click
        Dim cmd As New Data.SqlClient.SqlCommand()
        Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
        sqlcoll.Clear()
        sqlcoll.Add("@GRSC_Kid", Data.SqlDbType.NVarChar, 50).Value = RemoveLiterals(KeyKid.ToString.Trim)
        sqlcoll.Add("@GRSC_Code", Data.SqlDbType.NVarChar, 50).Value = txtGRSCCode.Text.Trim
        sqlcoll.Add("@GRSC_ContactPerson", Data.SqlDbType.NVarChar, 50).Value = txtGRSCCP.Text.Trim
        sqlcoll.Add("@GRSC_Designation", Data.SqlDbType.NVarChar, 50).Value = txtGRSCDesg.Text.Trim
        sqlcoll.Add("@GRSC_PhoneNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCode5.Text & "-" & txtCityCode5.Text & "-" & txtPhoneNo5.Text.Trim
        sqlcoll.Add("@GRSC_PhoneExtn", Data.SqlDbType.NVarChar, 50).Value = txtGRSCExtn.Text.Trim
        sqlcoll.Add("@GRSC_MobileNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodee5.Text & "-" & txtMobileNo5.Text.Trim
        If txtCountryCodeF5.Text = "" And txtCityCodeF5.Text = "" And txtFaxNo5.Text = "" Then
        Else
            sqlcoll.Add("@GRSC_FaxNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodeF5.Text & "-" & txtCityCodeF5.Text & "-" & txtFaxNo5.Text.Trim
        End If
        sqlcoll.Add("@GRSC_EmailId", Data.SqlDbType.NVarChar, 50).Value = txtGRSCEmailID.Text.Trim
        sqlcoll.Add("@GRSC_ProductId", Data.SqlDbType.NVarChar, 50).Value = Session("ProductID")
        sqlcoll.Add("@GRSC_FinancialYearId", Data.SqlDbType.NVarChar, 50).Value = g_FinYear
        sqlcoll.Add("@GRSC_CompanyID", Data.SqlDbType.NVarChar, 50).Value = g_Company
        sqlcoll.Add("@GRSC_UserID", Data.SqlDbType.NVarChar, 50).Value = g_User
        sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
        sqlcoll.Add("@Mode", Data.SqlDbType.Char, 15).Value = Mode
        ExecQuery("GoodsReturnServicesContact_Proc", sqlcoll)
        sqlcoll.Clear()
        CreateMessageAlert(Me, "Goods Return Services Contact Saved Successfully.", "StrKeyVal")
        Accountscontacts()
        MultiView1.ActiveViewIndex = 5
        Menu1.Items(5).Selected = True
        Menu1.StaticSelectedStyle.ForeColor = Drawing.Color.LightGreen
    End Sub
    Protected Sub ddl_GRSOtherProducts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_GRSOtherProducts.SelectedIndexChanged
        If ddl_GRSOtherProducts.SelectedIndex > 0 Then
            If ddl_GRSOtherProducts.SelectedItem.Text = "Add New" Then
                unLockControlGRSContact(True)
                ClearFieldsGRSContact()

            Else
                Dim Kid As String = ddl_GRSOtherProducts.SelectedItem.Value

                Dim dt As DataTable = getTable("SELECT     GoodsReturnServicesContact.*    FROM GoodsReturnServicesContact WHERE    GRSC_productid = '" & Kid.ToString.Trim & "' AND GRSC_companyid = '" & g_Company & "' AND GRSC_IsDeleted = N'0'", "PR")
                If dt.Rows.Count > 0 Then

                    'txtGRSCCode.Text = dt.Rows(0).Item("GRSC_Code").ToString
                    txtGRSCCP.Text = dt.Rows(0).Item("GRSC_ContactPerson").ToString
                    txtGRSCDesg.Text = dt.Rows(0).Item("GRSC_Designation").ToString
                    txtGRSCExtn.Text = dt.Rows(0).Item("GRSC_PhoneExtn").ToString

                    Dim pcountry5, pcity5, phoneno5, mcountry5, mobile5, fcountry5, fcity5, faxno5 As String
                    Try
                        phoneno5 = dt.Rows(0).Item("GRSC_PhoneNo").ToString
                        If phoneno5.Contains("-") Then
                            pcountry5 = phoneno5.Substring(0, phoneno5.IndexOf("-"))
                            phoneno5 = phoneno5.Substring(phoneno5.IndexOf("-") + 1)
                            If phoneno5.Contains("-") Then
                                pcity5 = phoneno5.Substring(0, phoneno5.IndexOf("-"))
                                phoneno5 = phoneno5.Substring(phoneno5.IndexOf("-") + 1)
                                txtCountryCode5.Text = pcountry5
                                txtCityCode5.Text = pcity5
                                txtPhoneNo5.Text = phoneno5
                            Else
                                txtCityCode5.Text = pcountry5
                                txtPhoneNo5.Text = phoneno5
                            End If

                        Else
                            txtPhoneNo5.Text = phoneno5
                        End If

                    Catch ex As Exception
                        txtCountryCode5.Text = ""
                        txtCityCode5.Text = ""
                        txtPhoneNo5.Text = ""
                    End Try

                    Try
                        mobile5 = dt.Rows(0).Item("GRSC_MobileNo").ToString
                        If mobile5.Contains("-") Then
                            mcountry5 = mobile5.Substring(0, mobile5.IndexOf("-"))
                            mobile5 = mobile5.Substring(mobile5.IndexOf("-") + 1)
                            txtCountryCodee5.Text = mcountry5
                            txtMobileNo5.Text = mobile5
                        Else
                            txtMobileNo5.Text = mobile5
                        End If

                    Catch ex As Exception
                        txtCountryCodee5.Text = ""
                        txtMobileNo5.Text = ""
                    End Try

                    Try
                        If IsDBNull(dt.Rows(0).Item("GRSC_FaxNo")) Then
                        Else
                            faxno5 = dt.Rows(0).Item("GRSC_FaxNo").ToString
                            If faxno5.Contains("-") Then
                                fcountry5 = faxno5.Substring(0, faxno5.IndexOf("-"))
                                faxno5 = faxno5.Substring(faxno5.IndexOf("-") + 1)
                                If faxno5.Contains("-") Then
                                    fcity5 = faxno5.Substring(0, faxno5.IndexOf("-"))
                                    faxno5 = faxno5.Substring(faxno5.IndexOf("-") + 1)
                                    txtCountryCodeF5.Text = fcountry5
                                    txtCityCodeF5.Text = fcity5
                                    txtFaxNo5.Text = faxno5
                                Else
                                    txtCityCodeF5.Text = fcountry5
                                    txtFaxNo5.Text = faxno5
                                End If

                            Else
                                txtFaxNo5.Text = faxno5
                            End If

                        End If
                    Catch ex As Exception
                        txtCountryCodeF5.Text = ""
                        txtCityCodeF5.Text = ""
                        txtFaxNo5.Text = ""

                    End Try

                    txtGRSCEmailID.Text = dt.Rows(0).Item("GRSC_EmailId").ToString


                    unLockControlGRSContact(True)

                End If
                dt.Clear()
            End If
        Else
            unLockControlGRSContact(False)
            ClearFieldsGRSContact()
        End If

    End Sub
    Protected Sub btnGoodsUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGoodsUpdate.Click
        btnGoodsSave_Click(sender, e)
    End Sub
    Public Sub unLockControlGRSContact(ByVal Action As Boolean)
        txtGRSCCode.Enabled = Action
        txtGRSCCP.Enabled = Action
        txtGRSCDesg.Enabled = Action

        txtCountryCode5.Enabled = Action
        txtCountryCodee5.Enabled = Action
        txtCountryCodeF5.Enabled = Action
        txtCityCode5.Enabled = Action
        txtCityCodeF5.Enabled = Action


        txtPhoneNo5.Enabled = Action
        txtGRSCExtn.Enabled = Action
        txtMobileNo5.Enabled = Action
        txtFaxNo5.Enabled = Action
        txtGRSCEmailID.Enabled = Action
    End Sub
    Public Sub ClearFieldsGRSContact()
        '    txtGRSCCode.Text = ""
        txtGRSCCP.Text = ""
        txtGRSCDesg.Text = ""

        txtCountryCode5.Text = ""
        txtCountryCodee5.Text = ""
        txtCountryCodeF5.Text = ""
        txtCityCode5.Text = ""
        txtCityCodeF5.Text = ""


        txtPhoneNo5.Text = ""
        txtGRSCExtn.Text = ""
        txtMobileNo5.Text = ""
        txtFaxNo5.Text = ""
        txtGRSCEmailID.Text = ""
    End Sub


    ' -----------------------------------------> Accounts Contact  <---------------------------------------

    Public Sub Accountscontacts()
        i = 0
        FillCategoryName(catid, lblAccountsCat)
        getaccountsexisting()
    End Sub
    Public Sub getaccountsexisting()
        Dim dt As DataTable
        dt = getTable("select * from AccountsContact where AccountsContact_SupplierID='" & Session.Item("SupplierID").Trim & "' and AccountsContact_IsDeleted='0' and AccountsContact_CompanyID='" & g_Company.Trim & "'", "AC")
        If dt.Rows.Count > 0 Then
            Mode = "Update"
            KeyKid = dt.Rows(0).Item("AccountsContact_Kid").ToString
            txtACCode.Text = dt.Rows(0).Item("AccountsContact_Code").ToString
            txtACCP.Text = dt.Rows(0).Item("AccountsContact_ContactPerson").ToString
            txtACDesg.Text = dt.Rows(0).Item("AccountsContact_Designation").ToString
            txtACExtn.Text = dt.Rows(0).Item("AccountsContact_PhoneExtn").ToString


            Dim pcountry6, pcity6, phoneno6, mcountry6, mobile6, fcountry6, fcity6, faxno6 As String
            Try
                phoneno6 = dt.Rows(0).Item("AccountsContact_PhoneNo").ToString
                If phoneno6.Contains("-") Then
                    pcountry6 = phoneno6.Substring(0, phoneno6.IndexOf("-"))
                    phoneno6 = phoneno6.Substring(phoneno6.IndexOf("-") + 1)
                    If phoneno6.Contains("-") Then
                        pcity6 = phoneno6.Substring(0, phoneno6.IndexOf("-"))
                        phoneno6 = phoneno6.Substring(phoneno6.IndexOf("-") + 1)
                        txtCountryCode6.Text = pcountry6
                        txtCityCode6.Text = pcity6
                        txtPhoneNo6.Text = phoneno6
                    Else
                        txtCityCode6.Text = pcountry6
                        txtPhoneNo6.Text = phoneno6
                    End If
                    
                Else
                    txtPhoneNo6.Text = phoneno6
                End If
                
            Catch ex As Exception
                txtCountryCode6.Text = ""
                txtCityCode6.Text = ""
                txtPhoneNo6.Text = ""
            End Try


            Try
                mobile6 = dt.Rows(0).Item("AccountsContact_MobileNo").ToString
                If mobile6.Contains("-") Then
                    mcountry6 = mobile6.Substring(0, mobile6.IndexOf("-"))
                    mobile6 = mobile6.Substring(mobile6.IndexOf("-") + 1)
                    txtCountryCodee6.Text = mcountry6
                    txtMobileNo6.Text = mobile6
                Else
                    txtMobileNo6.Text = mobile6
                End If
                
            Catch ex As Exception
                txtCountryCodee6.Text = ""
                txtMobileNo6.Text = ""
            End Try

            Try
                If IsDBNull(dt.Rows(0).Item("AccountsContact_FaxNo")) Then
                Else
                    faxno6 = dt.Rows(0).Item("AccountsContact_FaxNo").ToString
                    If faxno6.Contains("-") Then
                        fcountry6 = faxno6.Substring(0, faxno6.IndexOf("-"))
                        faxno6 = faxno6.Substring(faxno6.IndexOf("-") + 1)
                        If faxno6.Contains("-") Then
                            fcity6 = faxno6.Substring(0, faxno6.IndexOf("-"))
                            faxno6 = faxno6.Substring(faxno6.IndexOf("-") + 1)
                            txtCountryCodeF6.Text = fcountry6
                            txtCityCodeF6.Text = fcity6
                            txtFaxNo6.Text = faxno6
                        Else
                            txtCityCodeF6.Text = fcountry6
                            txtFaxNo6.Text = faxno6
                        End If
                        
                    Else
                        txtFaxNo6.Text = faxno6
                    End If
                    
                End If
            Catch ex As Exception
                txtCountryCodeF6.Text = ""
                txtCityCodeF6.Text = ""
                txtFaxNo6.Text = ""
            End Try

            txtACEmailID.Text = dt.Rows(0).Item("AccountsContact_EmailId").ToString
            unLockControlAccountsContact(False)
            lblAccountsExisting.Visible = False
            ddl_ACSOtherProducts.Visible = False
            btnAccountsSave.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                unLockControlAccountsContact(True)
                btnAccountsUpdate.Visible = True
            Else
                btnAccountsUpdate.Visible = False
            End If
        Else
            ClearFieldsAccountsContact()
            Mode = "Insert"
            KeyKid = NewPrimaryKey(Me)
            'lblAccountsExisting.Visible = False
            'ddl_ACSOtherProducts.Visible = False
            'unLockControlAccountsContact(False)
            'FillExistingDropDown("SELECT SalesContact_ProductId FROM SalesContact WHERE SalesContact_UserId = '" & Session.Item("g_User").ToString.Trim & "' AND SalesContact_CompanyId = '" & g_Company & "' AND SalesContact_IsDeleted = N'0'", ddl_ACSOtherProducts, lblAccountsExisting)
            unLockControlAccountsContact(True)
            btnAccountsUpdate.Visible = False
            txtACCode.Text = Generate_Code("select count(*) from AccountsContact where AccountsContact_Code='", "AC")

        End If
        dt.Clear()
    End Sub
    Protected Sub btnAccountsSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAccountsSave.Click
        Dim cmd As New Data.SqlClient.SqlCommand()
        Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
        sqlcoll.Clear()
        sqlcoll.Add("@AccountsContact_Kid", Data.SqlDbType.NVarChar, 50).Value = RemoveLiterals(KeyKid.ToString.Trim)
        sqlcoll.Add("@AccountsContact_Code", Data.SqlDbType.NVarChar, 50).Value = txtACCode.Text.Trim
        sqlcoll.Add("@AccountsContact_ContactPerson", Data.SqlDbType.NVarChar, 50).Value = txtACCP.Text.Trim
        sqlcoll.Add("@AccountsContact_Designation", Data.SqlDbType.NVarChar, 50).Value = txtACDesg.Text.Trim
        sqlcoll.Add("@AccountsContact_PhoneNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCode6.Text & "-" & txtCityCode6.Text & "-" & txtPhoneNo6.Text.Trim
        sqlcoll.Add("@AccountsContact_PhoneExtn", Data.SqlDbType.NVarChar, 50).Value = txtACExtn.Text.Trim
        sqlcoll.Add("@AccountsContact_MobileNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodee6.Text & "-" & txtMobileNo6.Text.Trim
        If txtCountryCodeF6.Text = "" And txtCityCodeF6.Text = "" And txtFaxNo6.Text = "" Then
        Else
            sqlcoll.Add("@AccountsContact_FaxNo", Data.SqlDbType.NVarChar, 50).Value = txtCountryCodeF6.Text & "-" & txtCityCodeF6.Text & "-" & txtFaxNo6.Text.Trim
        End If
        sqlcoll.Add("@AccountsContact_EmailId", Data.SqlDbType.NVarChar, 50).Value = txtACEmailID.Text.Trim
        sqlcoll.Add("@AccountsContact_SupplierId", Data.SqlDbType.NVarChar, 50).Value = Session("SupplierID")
        sqlcoll.Add("@AccountsContact_FinancialYearId", Data.SqlDbType.NVarChar, 50).Value = g_FinYear
        sqlcoll.Add("@AccountsContact_CompanyId", Data.SqlDbType.NVarChar, 50).Value = g_Company
        sqlcoll.Add("@AccountsContact_UserID", Data.SqlDbType.NVarChar, 50).Value = g_User
        sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
        sqlcoll.Add("@Mode", Data.SqlDbType.Char, 15).Value = Mode
        ExecQuery("AccountsContact_Proc", sqlcoll)
        sqlcoll.Clear()
        CreateMessageAlert(Me, "Account Services Contact Saved Successfully.", "StrKeyVal")
        CustomerCarecontacts()
        MultiView1.ActiveViewIndex = 6
        Menu1.Items(6).Selected = True
        Menu1.StaticSelectedStyle.ForeColor = Drawing.Color.LightGreen
    End Sub
    Protected Sub ddl_ACSOtherProducts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_ACSOtherProducts.SelectedIndexChanged

    End Sub
    Protected Sub btnAccountsUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAccountsUpdate.Click
        btnAccountsSave_Click(sender, e)
    End Sub
    Public Sub unLockControlAccountsContact(ByVal Action As Boolean)
        txtACCode.Enabled = Action
        txtACCP.Enabled = Action
        txtACDesg.Enabled = Action
        txtCountryCode6.Enabled = Action
        txtCountryCodee6.Enabled = Action
        txtCountryCodeF6.Enabled = Action
        txtCityCode6.Enabled = Action
        txtCityCodeF6.Enabled = Action
        txtPhoneNo6.Enabled = Action
        txtACExtn.Enabled = Action
        txtMobileNo6.Enabled = Action
        txtFaxNo6.Enabled = Action
        txtACEmailID.Enabled = Action
    End Sub
    Public Sub ClearFieldsAccountsContact()
        txtACCode.Text = ""
        txtACCP.Text = ""
        txtACDesg.Text = ""
        txtCountryCode6.Text = ""
        txtCountryCodee6.Text = ""
        txtCountryCodeF6.Text = ""
        txtCityCode6.Text = ""
        txtCityCodeF6.Text = ""
        txtPhoneNo6.Text = ""
        txtACExtn.Text = ""
        txtMobileNo6.Text = ""
        txtFaxNo6.Text = ""
        txtACEmailID.Text = ""
    End Sub



    ' -----------------------------------------> Customer Care Contact  <---------------------------------------

    Public Sub CustomerCarecontacts()
        i = 0
        FillCategoryName(catid, lblCustomerCareCat)
        getcustomercareexisting()
    End Sub
    Public Sub getcustomercareexisting()
        Dim dt As DataTable
        dt = getTable("select * from CustomerCareContact where CustomerCareCont_SupplierID='" & Session.Item("SupplierID").Trim & "' and CustomerCareCont_IsDeleted='0' and CustomerCareCont_CompanyID='" & g_Company.Trim & "'", "CCC")
        If dt.Rows.Count > 0 Then
            Mode = "Update"
            KeyKid = dt.Rows(0).Item("CustomerCareCont_Kid").ToString
            txtCCCCode.Text = dt.Rows(0).Item("CustomerCareCont_Code").ToString
            txtCCCCP.Text = dt.Rows(0).Item("CustomerCareCont_ContactPerson").ToString
            txtCCCDesg.Text = dt.Rows(0).Item("CustomerCareCont_Designation").ToString
            txtCCCExtn.Text = dt.Rows(0).Item("CustomerCareCont_PhoneExtn").ToString

            Dim pcountry7, pcity7, phoneno7, mcountry7, mobile7, fcountry7, fcity7, faxno7 As String
            Try
                phoneno7 = dt.Rows(0).Item("CustomerCareCont_PhoneNo").ToString
                If phoneno7.Contains("-") Then
                    pcountry7 = phoneno7.Substring(0, phoneno7.IndexOf("-"))
                    phoneno7 = phoneno7.Substring(phoneno7.IndexOf("-") + 1)
                    If phoneno7.Contains("-") Then
                        pcity7 = phoneno7.Substring(0, phoneno7.IndexOf("-"))
                        phoneno7 = phoneno7.Substring(phoneno7.IndexOf("-") + 1)
                        txtCountryCode7.Text = pcountry7
                        txtCityCode7.Text = pcity7
                        txtPhoneNo7.Text = phoneno7
                    Else
                        txtCityCode7.Text = pcountry7
                        txtPhoneNo7.Text = phoneno7
                    End If
                    
                Else
                    txtPhoneNo7.Text = phoneno7
                End If
                
            Catch ex As Exception
                txtCountryCode7.Text = ""
                txtCityCode7.Text = ""
                txtPhoneNo7.Text = ""
            End Try

            Try
                mobile7 = dt.Rows(0).Item("CustomerCareCont_MobileNo").ToString
                If mobile7.Contains("-") Then
                    mcountry7 = mobile7.Substring(0, mobile7.IndexOf("-"))
                    mobile7 = mobile7.Substring(mobile7.IndexOf("-") + 1)
                    txtCountryCodee7.Text = mcountry7
                    txtMobileNo7.Text = mobile7
                Else
                    txtMobileNo7.Text = mobile7
                End If
                
            Catch ex As Exception
                txtCountryCodee7.Text = ""
                txtMobileNo7.Text = ""
            End Try

            Try
                If IsDBNull(dt.Rows(0).Item("CustomerCareCont_FaxNo")) Then
                Else
                    faxno7 = dt.Rows(0).Item("CustomerCareCont_FaxNo").ToString
                    If faxno7.Contains("-") Then
                        fcountry7 = faxno7.Substring(0, faxno7.IndexOf("-"))
                        faxno7 = faxno7.Substring(faxno7.IndexOf("-") + 1)
                        If faxno7.Contains("-") Then
                            fcity7 = faxno7.Substring(0, faxno7.IndexOf("-"))
                            faxno7 = faxno7.Substring(faxno7.IndexOf("-") + 1)
                            txtCountryCodeF7.Text = fcountry7
                            txtCityCodeF7.Text = fcity7
                            txtFaxNo7.Text = faxno7
                        Else
                            txtCityCodeF7.Text = fcountry7
                            txtFaxNo7.Text = faxno7
                        End If
                        
                    Else
                        txtFaxNo7.Text = faxno7
                    End If
                    
                End If
            Catch ex As Exception
                txtCountryCodeF7.Text = ""
                txtCityCodeF7.Text = ""
                txtFaxNo7.Text = ""
            End Try
            

            txtCCCEmailID.Text = dt.Rows(0).Item("CustomerCareCont_EmailId").ToString
            unLockControlCustomerCareContact(False)
            lblCustomerCareExisting.Visible = False
            ddl_CCSOtherProducts.Visible = False
            btnCustomerSave.Visible = False
            If Session("AdminID") <> Nothing Or Session("AdminID") = Nothing Then
                unLockControlCustomerCareContact(True)
                btnCustomerUpdate.Visible = True
            Else
                btnCustomerUpdate.Visible = False
            End If
        Else
            ClearFieldsCustomerCareContact()
            Mode = "Insert"
            KeyKid = NewPrimaryKey(Me)
            'lblCustomerCareExisting.Visible = False
            'ddl_CCSOtherProducts.Visible = False
            'unLockControlCustomerCareContact(False)
            'FillExistingDropDown("SELECT CustomerCareCont_ProductId FROM SalesContact WHERE SalesContact_UserId = '" & Session.Item("g_User").ToString.Trim & "' AND SalesContact_CompanyId = '" & g_Company & "' AND SalesContact_IsDeleted = N'0'", ddl_CCSOtherProducts, lblCustomerCareExisting)
            unLockControlCustomerCareContact(True)
            btnCustomerUpdate.Visible = False
            txtCCCCode.Text = Generate_Code("select count(*) from CustomerCareContact where CustomerCareCont_Code='", "CC")
        End If
        dt.Clear()
    End Sub
    Protected Sub btnCustomerSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCustomerSave.Click
        Dim cmd As New Data.SqlClient.SqlCommand()
        Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
        sqlcoll.Clear()
        sqlcoll.Add("@CustomerCareCont_Kid", Data.SqlDbType.NVarChar, 10).Value = RemoveLiterals(KeyKid.ToString.Trim)
        sqlcoll.Add("@CustomerCareCont_Code", Data.SqlDbType.NVarChar, 25).Value = txtCCCCode.Text.Trim
        sqlcoll.Add("@CustomerCareCont_ContactPerson", Data.SqlDbType.NVarChar, 100).Value = txtCCCCP.Text.Trim
        sqlcoll.Add("@CustomerCareCont_Designation", Data.SqlDbType.NVarChar, 50).Value = txtCCCDesg.Text.Trim
        sqlcoll.Add("@CustomerCareCont_PhoneNo", Data.SqlDbType.NVarChar, 15).Value = txtCountryCode7.Text & "-" & txtCityCode7.Text & "-" & txtPhoneNo7.Text.Trim
        sqlcoll.Add("@CustomerCareCont_PhoneExtn", Data.SqlDbType.NVarChar, 15).Value = txtCCCExtn.Text.Trim
        sqlcoll.Add("@CustomerCareCont_MobileNo", Data.SqlDbType.NVarChar, 15).Value = txtCountryCodee7.Text & "-" & txtMobileNo7.Text.Trim
        If txtCountryCodeF7.Text = "" And txtCityCodeF7.Text = "" And txtFaxNo7.Text = "" Then

        Else
            sqlcoll.Add("@CustomerCareCont_FaxNo", Data.SqlDbType.NVarChar, 15).Value = txtCountryCodeF7.Text & "-" & txtCityCodeF7.Text & "-" & txtFaxNo7.Text.Trim
        End If
        sqlcoll.Add("@CustomerCareCont_EmailId", Data.SqlDbType.NVarChar, 50).Value = txtCCCEmailID.Text.Trim
        sqlcoll.Add("@CustomerCareCont_SupplierId", Data.SqlDbType.NVarChar, 50).Value = Session("SupplierID")
        sqlcoll.Add("@CustomerCareCont_FinancialYearId", Data.SqlDbType.NVarChar, 10).Value = g_FinYear
        sqlcoll.Add("@CustomerCareCont_CompanyId", Data.SqlDbType.NVarChar, 10).Value = g_Company
        sqlcoll.Add("@CustomerCareCont_UserID", Data.SqlDbType.NVarChar, 10).Value = g_User
        sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
        sqlcoll.Add("@Mode", Data.SqlDbType.Char, 10).Value = Mode
        ExecQuery("CustomerCareContact_Proc", sqlcoll)
        sqlcoll.Clear()
        CreateMessageAlert(Me, "Customer Care Services Contact Saved Successfully.", "StrKeyVal")
        Response.Redirect("WoodData.aspx")
    End Sub
    Protected Sub ddl_CCSOtherProducts_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_CCSOtherProducts.SelectedIndexChanged

    End Sub
    Protected Sub btnCustomerUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCustomerUpdate.Click
        btnCustomerSave_Click(sender, e)
    End Sub
    Public Sub unLockControlCustomerCareContact(ByVal Action As Boolean)
        txtCCCCode.Enabled = Action
        txtCCCCP.Enabled = Action
        txtCCCDesg.Enabled = Action
        txtCountryCode7.Enabled = Action
        txtCountryCodee7.Enabled = Action
        txtCountryCodeF7.Enabled = Action
        txtCityCode7.Enabled = Action
        txtCityCodeF7.Enabled = Action
        txtPhoneNo7.Enabled = Action
        txtCCCExtn.Enabled = Action
        txtMobileNo7.Enabled = Action
        txtFaxNo7.Enabled = Action
        txtCCCEmailID.Enabled = Action
    End Sub
    Public Sub ClearFieldsCustomerCareContact()
        txtCCCCode.Text = ""
        txtCCCCP.Text = ""
        txtCCCDesg.Text = ""
        txtCountryCode7.Text = ""
        txtCountryCodee7.Text = ""
        txtCountryCodeF7.Text = ""
        txtCityCode7.Text = ""
        txtCityCodeF7.Text = ""
        txtPhoneNo7.Text = ""
        txtCCCExtn.Text = ""
        txtMobileNo7.Text = ""
        txtFaxNo7.Text = ""
        txtCCCEmailID.Text = ""
    End Sub

    ' -----------------------------------------> Functions  <---------------------------------------

    Public Function FillExistingDropDown(ByVal strQuery As String, ByVal ddl As DropDownList, ByVal lbl As Label) As Boolean
        Dim dt1 As DataTable = getTable(strQuery, "PR")
        Dim i As Integer
        Dim Kid As String
        Dim KidBool As Boolean = True

        For i = 0 To dt1.Rows.Count - 1
            If KidBool = True Then
                Kid = "'" & dt1.Rows(i).Item(0).ToString & "'"
                KidBool = False
            Else
                Kid &= ","
                Kid &= "'" & dt1.Rows(i).Item(0).ToString & "'"

            End If

        Next

        Fill_Combo("Select Product_Kid,Product_Name from Product_Master where Product_SupplierID='" & Session.Item("SupplierID").ToString.Trim & "'and Product_Kid In ( " & Kid & ")", ddl)

        If ddl.Items.Count > 1 Then
            ddl.Items.Insert(ddl.Items.Count, "Add New")
            lbl.Visible = True
            Return False
            'unLockControlSalesContact(False)
        Else
            lbl.Visible = False
            ddl.Visible = False
            Return True
            'unLockControlSalesContact(True)
        End If

    End Function
    Public Sub FillCategoryName(ByVal Catid As String, ByVal lbl As Label)
        lbl.Text = ""
        Dim dt As DataTable
        dt = ReturnDataTable("Select * From Category_Master Where Category_Kid ='" & Catid & "' and Category_Isdeleted = '0' ")
        Dim ParentId As String
        ParentId = dt.Rows(0).Item(3).ToString()
        If ParentId = "Root Category" Then
            'Label1.Text += dt.Rows(0).Item(2).ToString()
            'Dim CategoryName(10) As String
            Dim j As Integer
            Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
            'Array.Reverse(Category)
            For j = 0 To i
                lbl.Text += Category(i)
                i = i - 1
            Next
            Exit Sub
        Else
            Category(i) = dt.Rows(0).Item(2).ToString() & "  >  "
            i = i + 1
            'Label1.Text += dt.Rows(0).Item(2).ToString() & "  >>  "
            FillCategoryName(dt.Rows(0).Item(3).ToString(), lbl)
        End If
        dt.Clear()
        'GridView1.DataSource = dt
        'GridView1.DataBind()
    End Sub
    Protected Sub lnkprodaddi_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkprodaddi.Click
        Response.Redirect("product-price.aspx")
    End Sub

    Protected Sub lnkkeycontact_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkkeycontact.Click
        Response.Redirect("supplier-keycontacts.aspx")
    End Sub

   
End Class
