Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Math
Imports System.IO
Imports System.EnterpriseServices
'Imports System.Drawing
'Imports System.Web.HttpWriter
Imports System.Web.Security
Imports System.Resources.Tools
Imports System.Security.Cryptography
Imports System.Configuration
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.Sql
Imports System.Text
Partial Class Buyer_AccountInfo
    Inherits System.Web.UI.Page
    Dim query As String = ""
    Dim mode As String
    Dim strQry As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try

            Page.LoadControl("~/UserControl/buyeruserinfo.ascx")
            CType(CType(Me.Master.FindControl("Buyeruserinfo1"), UserControl).FindControl("Image7"), Image).Visible = True
            CType(CType(Me.Master.FindControl("Buyeruserinfo1"), UserControl).FindControl("LinkButton5"), LinkButton).Font.Bold = True
            CType(CType(Me.Master.FindControl("Buyeruserinfo1"), UserControl).FindControl("LinkButton5"), LinkButton).Font.Size = 10
            If Session("BuyId") Is Nothing Then
                Response.Redirect("buyer-home.aspx?ses=expire")
                Exit Sub
            End If
            If Page.IsPostBack = False Then
                'lblAccountInfo.Text = getaddress()

                txtFaxNumber.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtFaxCityCode.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtFaxCountryCode.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtPinCode.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtTelCityCode.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtTelCountryCode.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtTelExt.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtTelNumber.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtMobCountryCode.Attributes.Add("onkeypress", "return numbersonly(event)")
                txtMobNumber.Attributes.Add("onkeypress", "return numbersonly(event)")

                getaddress()
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

    Private Function getaddress()
        Dim dr As SqlDataReader
        query = "SELECT dbo.AddressMaster.State_Name, dbo.AddressMaster.Country_Name, dbo.AddressMaster.City_Name, dbo.AddressBook.* " & _
                "FROM dbo.AddressBook INNER JOIN " & _
                      "dbo.AddressMaster ON dbo.AddressBook.AddressBook_CityID = dbo.AddressMaster.City_Kid " & _
                      "where dbo.AddressBook.AddressBook_BuyerID='" & Session("BuyId") & "' and dbo.AddressBook.AddressBook_Kid='1'"
        Dim sqlcon As New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
        sqlcon.Open()
        Dim cmd As New SqlCommand(query, sqlcon)
        dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
        If dr.Read = True Then
            'Dim strAdd As New StringBuilder()
            'strAdd.Append("<b>Name : </b>" & dr.Item("AddressBook_UserName").ToString & "<br>")
            'strAdd.Append("<b>Address : </b>" & dr.Item("AddressBook_Add1").ToString & "<br>")
            'strAdd.Append("<b>Country : </b>" & dr("Country_Name") & "<br>")
            'strAdd.Append("<b>State : </b>" & dr("State_Name") & "<br>")
            'strAdd.Append("<b>City : </b>" & dr("City_Name") & "<br>")
            'strAdd.Append("<b>Pin Code : </b>" & dr.Item("AddressBook_Zipcode") & "<br>")
            'strAdd.Append("<b>TelePhone No. : " & "</b> " & dr.Item("AddressBook_TelNumber") & "<br>")
            'strAdd.Append("<b>Email ID : " & "</b> ")
            'strAdd.Append("<a href=mailto:" & dr.Item("AddressBook_Email") & " > " & dr.Item("AddressBook_Email") & "</a>")
            'strAdd.ToString()

            lblName.Text = dr.Item("AddressBook_UserName").ToString
            lblAddress.Text = dr.Item("AddressBook_Add1").ToString
            lblCountry.Text = dr("Country_Name").ToString
            lblState.Text = dr("State_Name").ToString
            lblCity.Text = dr("City_Name").ToString
            lblPincode.Text = dr.Item("AddressBook_Zipcode").ToString
            lblphone.Text = dr.Item("AddressBook_TelNumber").ToString
            lblEmail.Text = "<a href=mailto:" & dr.Item("AddressBook_Email") & " > " & dr.Item("AddressBook_Email") & "</a>"
            sqlcon.Close()
            'Return strAdd.ToString()
            'strAdd = Nothing
        Else
            sqlcon.Close()
            Return ""
        End If
        sqlcon.Close()
    End Function

    'Protected Sub lnkchangepwd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkchangepwd.Click
    '    'Response.Redirect("ChangePassword.aspx")

    '    Try
    '        divchps.Visible = True
    '        divacinfo.Visible = False
    '        Label1.Text = ReturnValue("select BuyerRegister_EmailId from BuyerRegister where  BuyerRegister_Kid='" & Session("BuyId").ToString().Trim & "'")
    '    Catch ex As Exception
    '        showmessage(ex.Message.ToString, lblerror)
    '    End Try
    'End Sub

    'Protected Sub lnkchangeAcInfo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkchangeAcInfo.Click
    '    'Response.Redirect("EditAccountInfo.aspx")
    '    Try

    '        ddlState.Enabled = False
    '        ddlCity.Enabled = False
    '        divacinfo.Visible = True
    '        divchps.Visible = False
    '        Session("g_User") = "000008I"
    '        Dim dt As New DataTable
    '        Dim parent As String
    '        parent = "Root Category"
    '        Fill_Combo("select Country_Kid,Country_Name from Country_Master where Country_IsDeleted='0' " & _
    '                    " and Country_CompanyId='" & Session("g_Company").ToString & "' order by Country_Name", ddlCountry)
    '        ddlCountry.ClearSelection()
    '        ddlCountry.Items.FindByText("India").Selected = True
    '        ddlCountry_SelectedIndexChanged(sender, e)
    '        dt = ReturnDataTable("Select Distinct Category_Kid, Category_Name from Category_Master where Category_UserId = '" & Session("g_User").ToString & "' and Category_CompanyId = '" & Session("g_Company").ToString & "' and Category_Isdeleted = '0' and Category_ParentId = '" & parent & "'")
    '        chkCategory.DataSource = dt
    '        chkCategory.DataTextField = "Category_Name"
    '        chkCategory.DataValueField = "Category_Kid"
    '        chkCategory.DataBind()
    '        getExistingData()
    '        txtTelCountryCode.MaxLength = 3
    '        txtTelCityCode.MaxLength = 5
    '        txtTelNumber.MaxLength = 8
    '        txtTelExt.MaxLength = 5
    '        txtFaxCityCode.MaxLength = 5
    '        txtFaxCountryCode.MaxLength = 3
    '        txtFaxNumber.MaxLength = 8
    '        txtMobCountryCode.MaxLength = 3
    '        txtMobNumber.MaxLength = 10

    '        'Label14.Visible = False
    '        'txtAddCity.Visible = False
    '        'btnAddCity.Visible = False
    '        'TR2.Visible = False
    '        getMobileCode()

    '    Catch ex As Exception
    '        showmessage(ex.Message.ToString, lblerror)
    '    End Try
    'End Sub
    Private Sub getExistingData()
        Dim dt As DataTable = getTable("Select BuyerRegister_Kid, BuyerRegister_Name, BuyerRegister_EmailId, BuyerRegister_TelephoneNo, BuyerRegister_TelephoneExt,BuyerRegister_MobileNo, BuyerRegister_FaxNo, BuyerRegister_Address, BuyerRegister_PinCode, BuyerRegister_CountryId, BuyerRegister_StateId, BuyerRegister_CityId, BuyerRegister_CompanyName, BuyerRegister_WebSite, BuyerRegister_Category, BuyerRegister_RegDate  from BuyerRegister where BuyerRegister_Kid='" & Session("BuyId") & "' and BuyerRegister_IsDeleted = N'0'", "PR")
        If dt.Rows.Count > 0 Then
            Dim cat(15) As String
            Dim i As Integer
            Dim j As Integer = 0
            FillComboWithOthers("SELECT     State_Kid, State_Name     FROM State_Master WHERE     State_IsDeleted = N'0' AND State_CompanyId = '" & Session("g_Company").ToString & "'", ddlState)
            FillComboWithOthers("SELECT     City_Kid, City_Name     FROM City_Master WHERE     City_IsDeleted = N'0' AND City_CompanyId = '" & Session("g_Company").ToString & "' ", ddlCity)


            txtName.Text = chkDBNull(dt.Rows(0).Item("BuyerRegister_Name")).ToString
            lblUserId.Text = chkDBNull(dt.Rows(0).Item("BuyerRegister_EmailId")).ToString
            Dim pcountry1, pcity1, phoneno1, mcountry1, mobile1, fcountry1, fcity1, faxno1 As String

            If IsDBNull(dt.Rows(0).Item("BuyerRegister_TelephoneNo")) Then
            Else
                phoneno1 = dt.Rows(0).Item("BuyerRegister_TelephoneNo").ToString
                pcountry1 = phoneno1.Substring(0, phoneno1.IndexOf("-"))
                phoneno1 = phoneno1.Substring(phoneno1.IndexOf("-") + 1)
                pcity1 = phoneno1.Substring(0, phoneno1.IndexOf("-"))
                phoneno1 = phoneno1.Substring(phoneno1.IndexOf("-") + 1)
                txtTelCountryCode.Text = pcountry1
                txtTelCityCode.Text = pcity1
                txtTelNumber.Text = phoneno1
            End If

            If IsDBNull(dt.Rows(0).Item("BuyerRegister_MobileNo")) Then
            Else
                mobile1 = dt.Rows(0).Item("BuyerRegister_MobileNo").ToString
                mcountry1 = mobile1.Substring(0, mobile1.IndexOf("-"))
                mobile1 = mobile1.Substring(mobile1.IndexOf("-") + 1)
                txtMobCountryCode.Text = mcountry1
                txtMobNumber.Text = mobile1
            End If



            txtTelExt.Text = chkDBNull(dt.Rows(0).Item("BuyerRegister_TelephoneExt")).ToString

            If IsDBNull(dt.Rows(0).Item("BuyerRegister_FaxNo")) Then
            Else
                faxno1 = dt.Rows(0).Item("BuyerRegister_FaxNo").ToString
                fcountry1 = faxno1.Substring(0, faxno1.IndexOf("-"))
                faxno1 = faxno1.Substring(faxno1.IndexOf("-") + 1)
                fcity1 = faxno1.Substring(0, faxno1.IndexOf("-"))
                faxno1 = faxno1.Substring(faxno1.IndexOf("-") + 1)
                txtFaxCountryCode.Text = fcountry1
                txtFaxCityCode.Text = fcity1
                txtFaxNumber.Text = faxno1
            End If

            txtAddress.Text = chkDBNull(dt.Rows(0).Item("BuyerRegister_Address")).ToString
            txtPinCode.Text = chkDBNull(dt.Rows(0).Item("BuyerRegister_PinCode")).ToString
            txtCompanyName.Text = chkDBNull(dt.Rows(0).Item("BuyerRegister_CompanyName")).ToString
            txtWebSite.Text = chkDBNull(dt.Rows(0).Item("BuyerRegister_WebSite")).ToString

            Dim Category As String = dt.Rows(0).Item("BuyerRegister_Category").ToString
            For i = 0 To 15
                cat(i) = Category.Substring(0, Category.IndexOf("-")).ToString
                Dim s1 As String = cat(i).ToString
                chkCategory.Items.FindByText(s1.Trim).Selected = True
                j = cat(i).ToString.Length + 1
                Category = Category.Remove(0, j)

                If Category = "" Then
                    Exit For
                End If
            Next



            ddlCountry.SelectedIndex = ddlCountry.Items.IndexOf(ddlCountry.Items.FindByValue(dt.Rows(0).Item("BuyerRegister_CountryId").ToString))
            ddlState.SelectedIndex = ddlState.Items.IndexOf(ddlState.Items.FindByValue(dt.Rows(0).Item("BuyerRegister_StateId").ToString))
            ddlCity.SelectedIndex = ddlCity.Items.IndexOf(ddlCity.Items.FindByValue(dt.Rows(0).Item("BuyerRegister_CityId").ToString))
            BtnSaveA.Text = "Update"
            EnableControls(True)

        ElseIf dt.Rows.Count = 0 Then

            BtnSaveA.Text = "Save"
            EnableControls(True)

        End If
        dt = Nothing
    End Sub
    Private Sub EnableControls(ByVal bool As Boolean)

        ' txtAddCity.Enabled = bool
        txtAddress.Enabled = bool
        txtCompanyName.Enabled = bool
        txtFaxCityCode.Enabled = bool
        txtFaxCountryCode.Enabled = bool
        txtFaxNumber.Enabled = bool
        txtMobCountryCode.Enabled = bool
        txtMobNumber.Enabled = bool
        txtName.Enabled = bool
        txtPinCode.Enabled = bool


        txtTelCityCode.Enabled = bool
        txtTelCountryCode.Enabled = bool
        txtTelExt.Enabled = bool
        txtTelNumber.Enabled = bool
        lblUserId.Enabled = bool

        txtWebSite.Enabled = bool
        ddlCity.Enabled = bool
        ddlCountry.Enabled = bool
        ddlState.Enabled = bool

    End Sub

    Protected Sub BtnSaveA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSaveA.Click
        Try

            If BtnSaveA.Text = "Save" Then
                mode = "Insert"

            ElseIf BtnSaveA.Text = "Update" Then
                mode = "Update"
                Try
                    ''Dim EMailid As String
                    ''EMailid = ReturnValue("Select BuyerRegister_EmailId from buyerregister where BuyerRegister_EmailId='" & Trim(lblUserId.Text) & "'")
                    ''If Trim(lblUserId.Text) = EMailid Then
                    ''    'lblUserId.Text = ""
                    ''    lblUserId.Focus()
                    ''    Label17.Visible = True
                    ''    Label17.Text = "This E-Mail Id already registred please choose another E-Mail Id."
                    ''    Exit Sub
                    ''End If
                    Dim val As String
                    val = ""
                    Dim id As String
                    Dim i, j As Integer
                    i = chkCategory.Items.Count
                    For j = 0 To i - 1
                        If chkCategory.Items(j).Selected = True Then
                            val += chkCategory.Items(j).Text & " - "
                            'id = chkCategory.Items(j).Value
                        End If
                    Next

                    Dim telephoneno As String
                    telephoneno = txtTelCountryCode.Text & "-" & txtTelCityCode.Text & "-" & txtTelNumber.Text

                    Dim MobileNo As String
                    MobileNo = txtMobCountryCode.Text & "-" & txtMobNumber.Text

                    Dim FaxNo As String
                    FaxNo = txtFaxCountryCode.Text & "-" & txtFaxCityCode.Text & "-" & txtFaxNumber.Text
                    If val = "" Then
                        lblmsg.Text = "Please Select One Category."
                        'CreateMessageAlert(Me, "Please Select One Category.", "StrKeyVal")
                        Exit Sub
                    End If


                    If ddlCountry.SelectedItem.Text = "Select" Then
                        lblmsg.Text = "Please Select Country."
                        '  CreateMessageAlert(Me, "Please Select Couuntry.", "StrKeyVal")
                        ddlCountry.Focus()
                        Exit Sub
                    End If

                    If ddlState.Items.Count = 0 Then
                        lblmsg.Text = "Please Select State."
                        ' CreateMessageAlert(Me, "Please Select State..!!!", "StrKeyVal")
                        ddlState.Focus()
                        Exit Sub
                    End If
                    If ddlState.SelectedItem.Text = "Select" Then
                        lblmsg.Text = "Please Select State."
                        ' CreateMessageAlert(Me, "Please Select State.", "StrKeyVal")
                        ddlState.Focus()
                        Exit Sub
                    End If

                    If ddlState.SelectedItem.Text = "-Other-" Then
                        lblmsg.Text = "Please Select State."
                        'CreateMessageAlert(Me, "Please Select State.", "StrKeyVal")
                        ddlState.ClearSelection()
                        ddlState.Focus()
                        Exit Sub
                    End If

                    If ddlCity.SelectedItem.Text = "Select" Then
                        lblmsg.Text = "Please Select City."
                        'CreateMessageAlert(Me, "Please Select City.", "StrKeyVal")
                        ddlCity.Focus()
                        Exit Sub
                    End If

                    If ddlCity.SelectedItem.Text = "-Other-" Then
                        lblmsg.Text = "Please Select City."
                        'CreateMessageAlert(Me, "Please Select City.", "StrKeyVal")
                        ddlCity.ClearSelection()
                        ddlCity.Focus()
                        Exit Sub
                    End If

                    Dim country As String
                    country = ddlCountry.SelectedItem.Value

                    Dim State As String
                    State = ddlState.SelectedItem.Value

                    Dim OtherState As String
                    If State = "Select" Then
                        OtherState = ddlState.SelectedItem.Text
                        State = ""
                    Else
                        OtherState = ""
                    End If


                    Dim City As String
                    City = ddlCity.SelectedItem.Value

                    Dim OtherCity As String
                    If City = "Select" Then
                        OtherCity = ddlCity.SelectedItem.Text
                        City = ""
                    Else
                        OtherCity = ""
                    End If

                    Dim con As New SqlConnection                                                    'Define connection variable for connecting to SQL-Server
                    con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")    'Read the ConnectionString from web.config File
                    con.Open()
                    Dim cmd As New SqlCommand                                                       'Define command variable to execute the query
                    cmd.CommandType = CommandType.StoredProcedure                                   'Set the Command Type to Stored procedure
                    cmd.CommandText = "BuyerRegister_Proc"                                        'Assign the Name of Stored Procedure, to Execute
                    cmd.Connection = con                                                            'Assign the connection
                    txtCode.Text = ReturnValue("select BuyerRegister_Code from BuyerRegister where BuyerRegister_Kid='" & Session("BuyId").ToString & "' and BuyerRegister_IsDeleted = N'0' ")
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_Kid", SqlDbType.NVarChar, 10)).Value = Session("BuyId").ToString()      'Add Parameter Banke_Kid and assign the value  to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_Code", SqlDbType.NVarChar, 25)).Value = Trim(txtCode.Text)       'Add Parameter Banke_Code and assign the value of txtBankCode TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_Name", SqlDbType.NVarChar, 100)).Value = Trim(txtName.Text)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_EmailId", SqlDbType.NVarChar, 50)).Value = Trim(lblUserId.Text)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_TelephoneNo", SqlDbType.NVarChar, 50)).Value = telephoneno.ToString       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_TelephoneExt", SqlDbType.NVarChar, 50)).Value = Trim(txtTelExt.Text)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_MobileNo", SqlDbType.NVarChar, 50)).Value = Trim(MobileNo.ToString)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_FaxNo", SqlDbType.NVarChar, 50)).Value = Trim(FaxNo.ToString)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_Address", SqlDbType.NVarChar, 200)).Value = Trim(txtAddress.Text)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_PinCode", SqlDbType.Decimal)).Value = Convert.ToDecimal(Trim(txtPinCode.Text))       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_CountryId", SqlDbType.NVarChar, 10)).Value = Trim(country.ToString)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_StateId", SqlDbType.NVarChar, 10)).Value = Trim(State.ToString)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_OtherState", SqlDbType.NVarChar, 50)).Value = Trim(OtherState.ToString)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_CityId", SqlDbType.NVarChar, 10)).Value = Trim(City.ToString)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_OtherCity", SqlDbType.NVarChar, 50)).Value = Trim(OtherCity)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_CompanyName", SqlDbType.NVarChar, 50)).Value = Trim(txtCompanyName.Text)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_WebSite", SqlDbType.NVarChar, 50)).Value = Trim(txtWebSite.Text)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_Category", SqlDbType.NVarChar, 250)).Value = Trim(val.ToString)       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    'cmd.Parameters.Add(New SqlParameter("@BuyerRegister_RegDate", SqlDbType.DateTime)).Value = Convert.ToDateTime("01-01-1900".ToString).Date
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_FinancialYearId", SqlDbType.NVarChar, 10)).Value = Session("g_FinYear").ToString       'Add Parameter Bank_Name and assign the value of txtBankName TextField to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_CompanyId", SqlDbType.NVarChar, 10)).Value = Session("g_Company").ToString     'Add Parameter Company_Code and assign the value of Session("g_Company") to it
                    cmd.Parameters.Add(New SqlParameter("@BuyerRegister_UserId", SqlDbType.NVarChar, 10)).Value = Session("g_User").ToString            'Add Parameter UserCode and assign the value of Session("g_User").toString to it
                    'Dim passwrd As String = ReturnValue("select BuyerRegister_pwd from BuyerRegister where BuyerRegister_Kid='" & Session("BuyId").ToString & "' and BuyerRegister_IsDeleted = N'0'  ")
                    'cmd.Parameters.Add(New SqlParameter("@BuyerRegister_pwd", SqlDbType.NVarChar, 200)).Value = passwrd.ToString                          'Add Parameter FormName and assign the name of form to it
                    'cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Register"                           'Add Parameter FormName and assign the name of form to it
                    cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.VarChar, 50)).Value = mode.ToString()                                  'Add Parameter Mode and assign the DML Operation to Execute (Insert)
                    cmd.ExecuteNonQuery()
                    con.Close()
                    'CreateMessageAlert(Me, "Successfully Submitted.", "StrKeyVal")
                    getaddress()
                    clearfields()
                    lblAccountInfo.Visible = True
                    lblAccountInfo.Text = "Record Updated Successfully"
                    lblmsg.Text = ""
                    ' Response.Redirect("AccountInfo.aspx")
                    divacinfo.Visible = False
                    '  CreateMessageAlert(Me, "Successfully Submitted.", "StrKeyVal")
                Catch ex As Exception
                    ex.Message.ToString()
                    'CreateMessageAlert(Me, ex.Message, "StrKeyVal")
                End Try
            End If

        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub
    Private Sub getMobileCode()
        txtTelCountryCode.Text = ReturnValue("select Country_ISDCode from country_master where country_kid='" & ddlCountry.SelectedValue.Trim & "'")
        txtMobCountryCode.Text = ReturnValue("select Country_ISDCode from country_master where country_kid='" & ddlCountry.SelectedValue.Trim & "'")
        txtFaxCountryCode.Text = ReturnValue("select Country_ISDCode from country_master where country_kid='" & ddlCountry.SelectedValue.Trim & "'")
    End Sub
    Public Sub clearfields()
        txtAddress.Text = ""
        txtCode.Text = ""
        txtCompanyName.Text = ""
        txtFaxCityCode.Text = ""
        txtFaxCountryCode.Text = ""
        txtFaxNumber.Text = ""
        TxtKid.Text = ""
        txtMobCountryCode.Text = ""
        txtMobNumber.Text = ""
        ' txtOtherCity.Text = ""
        ' txtOtherState.Text = ""
        txtTelCityCode.Text = ""
        txtTelCountryCode.Text = ""
        txtTelExt.Text = ""
        txtTelNumber.Text = ""
        lblUserId.Text = ""
        txtWebSite.Text = ""
        txtPinCode.Text = ""
        ddlCity.ClearSelection()
        ddlState.Items.Clear()
        ddlCountry.Items.Clear()
        ddlState.Enabled = False
        ddlCountry.Enabled = False
    End Sub


    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        If ddlCountry.SelectedIndex > 0 Then
            ddlState.Items.Clear()
            Fill_Combo("Select State_Kid, State_Name from State_Master where State_IsDeleted='0' and State_CountryID='" & ddlCountry.SelectedValue.Trim & "' and State_CompanyId='" & Session("g_Company").ToString & "' order by State_Name", ddlState)
            ddlState.Enabled = True
            ddlCity.Enabled = False
        End If
    End Sub

    Protected Sub ddlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlState.SelectedIndexChanged
        If ddlState.SelectedIndex > 0 Then
            ddlCity.Items.Clear()
            Fill_Combo("Select City_Kid, City_Name from City_Master where City_IsDeleted='0' and City_StateID='" & ddlState.SelectedValue.Trim & "' and City_CompanyId='" & Session("g_Company").ToString & "' order by City_Name", ddlCity)
            ddlCity.Enabled = True
            ddlCity.Visible = True
            'Label9.Visible = True
            TR1.Visible = True
        End If
    End Sub

    Protected Sub ddlCity_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCity.SelectedIndexChanged
        'If ddlCity.SelectedItem.Text.Trim = "Others" Then
        '    btnAddCity.Visible = True
        '    txtAddCity.Visible = True
        '    ddlCity.Visible = False
        '    Label14.Visible = True
        '    Label9.Visible = False
        '    TR1.Visible = False
        '    TR2.Visible = True
        '    Exit Sub
        'End If
    End Sub
    'Protected Sub btnAddCity_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    '    ''Dim cmd As New Data.SqlClient.SqlCommand()
    '    ''Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
    '    ''sqlcoll.Add("@City_Kid", Data.SqlDbType.NVarChar, 50).Value = NewPrimaryKey(Me)
    '    ''sqlcoll.Add("@City_Code", Data.SqlDbType.NVarChar, 50).Value = Generate_Code("select count(*) from City_Master where City_Code='", "CC")
    '    ''sqlcoll.Add("@City_Name", Data.SqlDbType.NVarChar, 50).Value = txtAddCity.Text.Trim
    '    ''sqlcoll.Add("@City_StateID", Data.SqlDbType.NVarChar, 50).Value = ddlState.SelectedValue.Trim
    '    ''sqlcoll.Add("@City_CompanyID", Data.SqlDbType.NVarChar, 50).Value = g_Company
    '    ''sqlcoll.Add("@City_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("City_Master_Proc", sqlcoll)
    '    ''FillComboWithOthers("Select City_Kid, City_Name from City_Master where City_IsDeleted='0' and City_StateID='" & ddlState.SelectedValue.Trim & "' and City_CompanyId='" & g_Company.Trim & "' order by City_Name", ddlCity)
    '    ''ddlCity.ClearSelection()
    '    ''ddlCity.Items.FindByText(txtAddCity.Text.Trim).Selected = True
    '    ''txtAddCity.Text = ""
    '    ''btnAddCity.Visible = False
    '    ''txtAddCity.Visible = False
    '    If txtAddCity.Text <> Nothing Then
    '        Dim cmd As New Data.SqlClient.SqlCommand()
    '        Dim sqlcoll As Data.SqlClient.SqlParameterCollection = cmd.Parameters
    '        sqlcoll.Add("@City_Kid", Data.SqlDbType.NVarChar, 50).Value = NewPrimaryKey(Me)
    '        sqlcoll.Add("@City_Code", Data.SqlDbType.NVarChar, 50).Value = Generate_Code("select count(*) from City_Master where City_Code='", "CC")
    '        sqlcoll.Add("@City_Name", Data.SqlDbType.NVarChar, 50).Value = txtAddCity.Text.Trim
    '        sqlcoll.Add("@City_StateID", Data.SqlDbType.NVarChar, 50).Value = ddlState.SelectedValue.Trim
    '        sqlcoll.Add("@City_CompanyID", Data.SqlDbType.NVarChar, 50).Value = Session("g_Company").ToString
    '        sqlcoll.Add("@City_UserID", Data.SqlDbType.NVarChar, 50).Value = Session("g_User").ToString
    '        sqlcoll.Add("@FormName", Data.SqlDbType.NVarChar, 50).Value = Me.Title.ToString
    '        sqlcoll.Add("@Mode", Data.SqlDbType.Char, 15).Value = "Insert"
    '        ExecQuery("City_Master_Proc", sqlcoll)
    '        FillComboWithOthers("Select City_Kid, City_Name from City_Master where City_IsDeleted='0' and City_StateID='" & ddlState.SelectedValue.Trim & "' and City_CompanyId='" & Session("g_Company").ToString & "' order by City_Name", ddlCity)
    '        ddlCity.ClearSelection()
    '        ddlCity.Items.FindByText(txtAddCity.Text.Trim).Selected = True
    '        txtAddCity.Text = ""
    '        TR1.Visible = True
    '        btnAddCity.Visible = False
    '        txtAddCity.Visible = False
    '        Label14.Visible = False
    '        ddlCity.Visible = True
    '        TR2.Visible = False
    '    Else
    '        TR1.Visible = False
    '        Label13.Visible = True
    '        btnAddCity.Visible = True
    '        txtAddCity.Visible = True
    '        Label14.Visible = True
    '        TR2.Visible = True
    '        Label16.Text = "Please Enter City Name."
    '    End If
    'End Sub
    Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("AccountInfo.aspx")
    End Sub
    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Try
            Dim cipher As String
            cipher = Encrypt(txtOldpassword.Text)
            '   If IsAlreadyPresent("select Count(BuyerRegister_AdminUserId) from BuyerRegister where BuyerRegister_AdminUserId='" & txtOldpassword.Text.Trim & "' and BuyerRegister_Kid='" & Session("BuyId").ToString().Trim & "' and BuyerRegister_IsDeleted='0'") = True Then
            If IsAlreadyPresent("select Count(BuyerRegister_pwd) from BuyerRegister where BuyerRegister_pwd='" & cipher.ToString & "' and BuyerRegister_Kid='" & Session("BuyId").ToString().Trim & "' and BuyerRegister_IsDeleted='0'") = True Then
                If txtnewpassword.Text.Length > 5 Then
                    ' ExecuteQuery("Update BuyerRegister set BuyerRegister_AdminUserId='" & txtnewpassword.Text.Trim & "' where BuyerRegister_AdminUserId='" & txtOldpassword.Text.Trim & "' and BuyerRegister_Kid='" & Session("BuyId").ToString().Trim & "' and BuyerRegister_IsDeleted='0'")
                    ExecuteQuery("Update BuyerRegister set BuyerRegister_pwd='" & Encrypt(txtnewpassword.Text) & "' where BuyerRegister_pwd='" & cipher.ToString & "' and BuyerRegister_Kid='" & Session("BuyId").ToString().Trim & "' and BuyerRegister_IsDeleted='0'")
                    lblMessage.Text = "Password is Successfully Changed !..."
                    txtOldpassword.Text = ""
                Else
                    lblMessage.Text = "New Password Must have 6 Characters !..."
                End If

            Else
                lblMessage.Text = "Old Password is Wrong !..."
            End If
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

    Protected Sub imagecancel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        divchps.Visible = False
    End Sub

    Protected Sub accinfocancel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        divacinfo.Visible = False
    End Sub

    Protected Sub ImageButton2_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Try
            divchps.Visible = True
            divacinfo.Visible = False
            Label1.Text = ReturnValue("select BuyerRegister_EmailId from BuyerRegister where  BuyerRegister_Kid='" & Session("BuyId").ToString().Trim & "'")
            lblAccountInfo.Text = ""
        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
        Try
            lblmsg.Text = ""
            lblAccountInfo.Text = ""
            ddlState.Enabled = False
            ddlCity.Enabled = False
            divacinfo.Visible = True
            divchps.Visible = False
            Session("g_User") = "000008I"
            Dim dt As New DataTable
            Dim parent As String
            parent = "Root Category"
            Fill_Combo("select Country_Kid,Country_Name from Country_Master where Country_IsDeleted='0' " & _
                        " and Country_CompanyId='" & Session("g_Company").ToString & "' order by Country_Name", ddlCountry)
            ddlCountry.ClearSelection()
            ddlCountry.Items.FindByText("India").Selected = True
            ddlCountry_SelectedIndexChanged(sender, e)
            dt = ReturnDataTable("Select Distinct Category_Kid, Category_Name from Category_Master where Category_UserId = '" & Session("g_User").ToString & "' and Category_CompanyId = '" & Session("g_Company").ToString & "' and Category_Isdeleted = '0' and Category_ParentId = '" & parent & "' Order by Category_Name")
            chkCategory.DataSource = dt
            chkCategory.DataTextField = "Category_Name"
            chkCategory.DataValueField = "Category_Kid"
            chkCategory.DataBind()
            getExistingData()
            txtTelCountryCode.MaxLength = 3
            txtTelCityCode.MaxLength = 5
            txtTelNumber.MaxLength = 8
            txtTelExt.MaxLength = 5
            txtFaxCityCode.MaxLength = 5
            txtFaxCountryCode.MaxLength = 3
            txtFaxNumber.MaxLength = 8
            txtMobCountryCode.MaxLength = 3
            txtMobNumber.MaxLength = 10

            'Label14.Visible = False
            'txtAddCity.Visible = False
            'btnAddCity.Visible = False
            'TR2.Visible = False
            getMobileCode()

        Catch ex As Exception
            showmessage(ex.Message.ToString, lblerror)
        End Try
    End Sub

  
    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
End Class
