//protected void dllState_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (TriggerStateSelectedIndexChangedEvent == false)
    //    {
    //        return;
    //    }
    //    ListControl ddl = ((ListControl)sender);

    //    if (Utils.IsNumeric(ddl.SelectedValue) && Convert.ToInt32(ddl.SelectedValue) > 0)
    //    {
    //        DataTable dt = null;
    //        dt = OrganizationInfo.GetCountryByStateID(Convert.ToInt32(ddl.SelectedValue));

    //        if (dt.Rows.Count > 0)
    //        {
    //            if (sender.Equals(ddlMailingState))
    //            {
    //                txtMailingCity.Text = "";
    //                txtMailingZipCode.Text = "";
    //                if (ddlMailingCountry.Items.FindByValue(Convert.ToString(dt.Rows[0]["CountryId"])) != null)
    //                    ddlMailingCountry.SelectedValue = Convert.ToString(dt.Rows[0]["CountryId"]);
    //            }

    //            if (sender.Equals(ddlBusinessProvince))
    //            {
    //                txtBuinessCity.Text = "";
    //                txtBusinessZipCode.Text = "";
    //                if (ddlBusinessCountry.Items.FindByValue(Convert.ToString(dt.Rows[0]["CountryId"])) != null)
    //                    ddlBusinessCountry.SelectedValue = Convert.ToString(dt.Rows[0]["CountryId"]);
    //            }

    //            if (sender.Equals(ddlSuppliersProvince))
    //            {
    //                txtSupplierCity.Text = "";
    //                txtSupplierZipCode.Text = "";
    //                if (ddlSuppliersCountry.Items.FindByValue(Convert.ToString(dt.Rows[0]["CountryId"])) != null)
    //                    ddlSuppliersCountry.SelectedValue = Convert.ToString(dt.Rows[0]["CountryId"]);
    //            }

    //            if (sender.Equals(ddlclientsProvince))
    //            {
    //                txtClientCity.Text = "";
    //                txtClientZipCode.Text = "";
    //                if (ddlclientsCountry.Items.FindByValue(Convert.ToString(dt.Rows[0]["CountryId"])) != null)
    //                    ddlclientsCountry.SelectedValue = Convert.ToString(dt.Rows[0]["CountryId"]);
    //            }

    //            if (sender.Equals(ddlLocationState))
    //            {
    //                txtLocationCity.Text = "";
    //                txtLocationZipCode.Text = "";
    //                if (ddlLocationCountry.Items.FindByValue(Convert.ToString(dt.Rows[0]["CountryId"])) != null)
    //                    ddlLocationCountry.SelectedValue = Convert.ToString(dt.Rows[0]["CountryId"]);
    //            }
    //        }
    //    }
    //}

    //protected void dllCountry_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (TriggerCountrySelectedIndexChangedEvent == false)
    //    {
    //        return;
    //    }
    //    ListControl ddl = ((ListControl)sender);

    //    if (Utils.IsNumeric(ddl.SelectedValue) && Convert.ToInt32(ddl.SelectedValue) > 0)
    //    {
    //        System.Data.SqlClient.SqlParameter[] prm;

    //        prm = new System.Data.SqlClient.SqlParameter[1];
    //        prm[0] = new System.Data.SqlClient.SqlParameter("@CountryId", Convert.ToInt32(ddl.SelectedValue));

    //        if (sender.Equals(ddlMailingCountry))
    //        {
    //            txtMailingCity.Text = "";
    //            txtMailingZipCode.Text = "";
    //            Utils.GetLookUpData<DropDownList>(ref ddlMailingState, LookUps.State, prm);
    //        }

    //        if (sender.Equals(ddlBusinessCountry))
    //        {
    //            txtBuinessCity.Text = "";
    //            txtBusinessZipCode.Text = "";
    //            Utils.GetLookUpData<DropDownList>(ref ddlBusinessProvince, LookUps.State, prm);
    //        }

    //        if (sender.Equals(ddlSuppliersCountry))
    //        {
    //            txtSupplierCity.Text = "";
    //            txtSupplierZipCode.Text = "";
    //            Utils.GetLookUpData<DropDownList>(ref ddlSuppliersProvince, LookUps.State, prm);
    //        }

    //        if (sender.Equals(ddlclientsCountry))
    //        {
    //            txtClientCity.Text = "";
    //            txtClientZipCode.Text = "";
    //            Utils.GetLookUpData<DropDownList>(ref ddlclientsProvince, LookUps.State, prm);
    //        }

    //        if (sender.Equals(ddlLocationCountry))
    //        {
    //            txtLocationCity.Text = "";
    //            txtLocationZipCode.Text = "";
    //            Utils.GetLookUpData<DropDownList>(ref ddlLocationState, LookUps.State, prm);
    //        }

    //        prm = null;
    //    }
    //}

    protected void gvSupplier_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditSupplier")
        {
            hdnSupplierId.Value = (e.CommandArgument).ToString();
            OrganizationInfo.Supplier ObjOrgSupplier = new OrganizationInfo.Supplier(Conversion.ParseInt(hdnSupplierId.Value));

            hdnSupplierId.Value = ObjOrgSupplier.SupplierID.ToString();
            txtSupplierCompanyName.Text = ObjOrgSupplier.CompanyName;
            ddlSuppliersCountry.SelectedValue = ObjOrgSupplier.CountryID.ToString();
            (ddlSuppliersProvince.SelectedValue) = ObjOrgSupplier.StateId.ToString();
            txtSupplierCity.Text = ObjOrgSupplier.City;
            txtSupplierZipCode.Text = ObjOrgSupplier.Zipcode;
            //   
            DataTable dt;
            dt = OrganizationInfo.GetCityStateAndCountryByZipCode(ObjOrgSupplier.Zipcode);

            if (dt.Rows.Count > 0)
            {
                //  hdnZipCode.Value = Convert.ToString(dt.Rows[0]["ZipcodeID"]);
                txtSupplierCity.Text = Convert.ToString(dt.Rows[0]["CityName"]);
                if (ddlSuppliersCountry.Items.FindByValue(Convert.ToString(dt.Rows[0]["CountryId"])) != null)
                    ddlSuppliersCountry.SelectedValue = Convert.ToString(dt.Rows[0]["CountryId"]);
                System.Data.SqlClient.SqlParameter[] prm;
                prm = new System.Data.SqlClient.SqlParameter[1];
                prm[0] = new System.Data.SqlClient.SqlParameter("@CountryId", ddlSuppliersCountry.SelectedValue);
                Utils.GetLookUpData<DropDownList>(ref ddlSuppliersProvince, LookUps.State, prm);
                prm = null;
                if (ddlSuppliersProvince.Items.FindByValue(Convert.ToString(dt.Rows[0]["StateId"])) != null)
                    ddlSuppliersProvince.SelectedValue = Convert.ToString(dt.Rows[0]["StateId"]);
            }
            hdnSupplierZipCode.Value = ObjOrgSupplier.ZipCodeId.ToString();
            string[] contactnamearray = ObjOrgSupplier.ContactName.Split(' ');
            txtSupplierscontactFirstName.Text = contactnamearray[0]; txtSupplierscontactLastName.Text = contactnamearray[1];
            txtSupplierBusinessPhone1.Text = ObjOrgSupplier.BussinessPhone.Substring(0, 3);
            txtSupplierBusinessPhone2.Text = ObjOrgSupplier.BussinessPhone.Substring(3, 3);
            txtSupplierBusinessPhone3.Text = ObjOrgSupplier.BussinessPhone.Substring(6, 4);
            txtSuppliersownerEmail.Text = ObjOrgSupplier.Email;
            txtSupplierBusinessPhoneExt.Text = ObjOrgSupplier.BusinessPhoneExtention;
            txtSupplierContactCellPhone1.Text = ObjOrgSupplier.CellPhone.Substring(0, 3);
            txtSupplierContactCellPhone2.Text = ObjOrgSupplier.CellPhone.Substring(3, 3);
            txtSupplierContactCellPhone3.Text = ObjOrgSupplier.CellPhone.Substring(6, 4);
            txtSuppliersownerEmail.Text = ObjOrgSupplier.OwnerManagerEmail;
        }
        else
            if (e.CommandName == "DeleteSupplier")
            {
                OrganizationInfo.DeleteSupplierBySupplierId(Convert.ToInt32(e.CommandArgument));
                lblSupplierStatus.Visible = true;
                lblSupplierStatus.Text = "Successfully deleted";
            }
            else
                lblSupplierStatus.Visible = false;

        gvSupplier.DataSource = OrganizationInfo.GetSupplierByOrganizationId(Convert.ToInt32(hdnOrganizationID.Value));
        gvSupplier.DataBind();
        LoadHeaderTextForSupplier();

        hdnSupplierCount.Value = Convert.ToString(gvSupplier.Rows.Count);

        ToolkitScriptManager.RegisterStartupScript(this, this.GetType(), "SetHiddenFieldValue", String.Format("SetHiddenFieldValue('{0}','{1}');", hdnSupplierCount.Value, gvSupplier.Rows.Count), true);
    }
    protected void lnkAddSupplier_Click(object sender, EventArgs e)
    {
        if (Utils.IsNumeric(hdnOrganizationID.Value) == false)
            return;

        OrganizationInfo.Supplier ObjOrgSupplier = new OrganizationInfo.Supplier();

        ObjOrgSupplier.SupplierID = Conversion.ParseInt(hdnSupplierId.Value);

        ObjOrgSupplier.CompanyName = txtSupplierCompanyName.Text;
        ObjOrgSupplier.CountryID = int.Parse(ddlSuppliersCountry.SelectedValue);
        ObjOrgSupplier.StateId = Convert.ToInt32(ddlSuppliersProvince.SelectedValue);
        ObjOrgSupplier.City = txtSupplierCity.Text;
        ObjOrgSupplier.ZipCodeId = Convert.ToInt32(hdnSupplierZipCode.Value);
        ObjOrgSupplier.ContactName = (txtSupplierscontactFirstName.Text.Trim() + " " + txtSupplierscontactLastName.Text.Trim()).Trim();
        ObjOrgSupplier.BussinessPhone = txtSupplierBusinessPhone1.Text.Trim() + txtSupplierBusinessPhone2.Text.Trim() + txtSupplierBusinessPhone3.Text.Trim();
        ObjOrgSupplier.Email = txtSuppliersownerEmail.Text;
        ObjOrgSupplier.IsActive = true;
        ObjOrgSupplier.BusinessPhoneExtention = txtSupplierBusinessPhoneExt.Text;
        ObjOrgSupplier.CellPhone = txtSupplierContactCellPhone1.Text.Trim() + txtSupplierContactCellPhone2.Text.Trim() + txtClientCellPhone3.Text.Trim();
        ObjOrgSupplier.OwnerManagerEmail = txtSuppliersownerEmail.Text;
        ObjOrgSupplier.LanguageID = LanguageId;
        ObjOrgSupplier.DateCreated = DateTime.Now;
        ObjOrgSupplier.CreatedBy = currentUserInfo.UserId;
        ObjOrgSupplier.Count = 0;


        if (OrganizationInfo.SaveSupplierByOrganizationId(Convert.ToInt32(hdnOrganizationID.Value), ObjOrgSupplier) == 0)
        {
            dvsuppliererrormsg.Visible = true;
        }
        else
        {
            dvsuppliererrormsg.Visible = false;
        }
        hdnSupplierId.Value = "0";
        gvSupplier.DataSource = OrganizationInfo.GetSupplierByOrganizationId(Convert.ToInt32(hdnOrganizationID.Value));
        gvSupplier.DataBind();
        LoadHeaderTextForSupplier();

        hdnSupplierCount.Value = Convert.ToString(gvSupplier.Rows.Count);

        if (gvSupplier.Rows.Count < 3)
        {
            //ClearSuppliersFields();
        }

        //ToolkitScriptManager.RegisterStartupScript(this, this.GetType(), "ClearSupplierFields", String.Format("ClearSupplierFields();SetHiddenFieldValue('{0}','{1}');", hdnSupplierCount.ClientID, gvSupplier.Rows.Count), true);

        //txtSupplierZipCode.Text = "";

    }