using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OracleClient;
//using NCBEAI.Adapters.Transport;
using System.Xml;

public partial class Business_AddMerchant : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadClientLevel();
            loadLanguage();
            loadBusinessClass();
            loadCityByRegion();
            loadRegion();
            loadProductType();
            loadpostingMethod();
            loadsettlementMethod();
            loadBusinessUnit();
            loadIncomeRange();
            loadRelationOfficer();
            loadDynamicGroups();
            loadStaticGroups();
            loadBranch(1);
            txtBranch.Text = ddlBranch.SelectedValue;
            loadBUAcc(ddlBusinessUnit.SelectedValue);
            dateRegDate.date = getDayofMonth(DateTime.Now.Day);
            txtRegDate.Text = getDayofMonth(DateTime.Now.Day);
            // rowParent.Visible = false;
            btnSave.Enabled = false;
            lblRetailerID.Visible = false;
            txtParentClientNumber.Visible = false;
            btnParentData.Visible = false;
            ddlCity.Enabled = false;
           // ddlSettlMethod.Enabled = true;
            //ddlSettlMethod.SelectedValue = "001";
            //ddlSettlMethod.Items.Insert(0, "------ Select ------");

        }

    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        //Check proper parent
        if (checkProperParent())
        {
            string error = "", ID = ""; //ID = "35377";
            bool saved = addMerchant(ref ID, ref error);
            if (saved)
            {
                //addAddress(ID);
                lblError.Text = "Merchant saved";
                Response.Redirect("UpdateMerchant.aspx?clID=" + ID);
            }
            else
            {
                if (Helper.OracleError(error))
                {
                    lblError.Text = "Save Failed";
                    ExceptionUtility.LogException(0, "", "", "btnSave_Click", error);
                }
                else
                    lblError.Text = error;
            }
        }
    }

    protected void ddlClientLevel_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlClientLevel.SelectedValue.Equals("001")) //root
        {
            //rowParent.Visible = false;
            lblMerchantName.Text = "Merchant Name (English)";
            lblMerchantNameAr.Text = "Merchant Name (Arabic)";

            ddlRelationshipOfficer.Enabled = true;
            lblRetailerID.Visible = false;
            txtParentClientNumber.Visible = false;
            btnParentData.Visible = false;
            //ddlIncomeRange.Enabled = true;
            // POS Merchant Settlement Method changes 20210729
              ddlSettlMethod.Enabled = false;
        }
        else if (ddlClientLevel.SelectedValue.Equals("002")) //branch
        {
            //rowParent.Visible = true;
            lblMerchantName.Text = "Retailer Name (English)";
            lblMerchantNameAr.Text = "Retailer Name (Arabic)";

            ddlRelationshipOfficer.Enabled = true;
            lblRetailerID.Visible = true;
            txtParentClientNumber.Visible = true;
            btnParentData.Visible = true;
         // POS Merchant Settlement Method changes 20210729
            ddlSettlMethod.Enabled = false;
         // ddlIncomeRange.Enabled = false;
        }
        else
        {
            lblRetailerID.Visible = true;
            txtParentClientNumber.Visible = true;
            btnParentData.Visible = true;
         // POS Merchant Settlement Method changes 20210729
            ddlSettlMethod.Enabled = true;
         // ddlSettlMethod.SelectedValue = "001";
         //   ddlSettlMethod.Items.Insert(0, "------ Select ------");
        }
    }

    private bool addMerchant(ref string ID, ref string error)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "merchant_reg.add_merchant_details";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_merchant_no", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_client_level", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_retailer_name", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_retailer_name_ar", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_registration_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_index", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fdr", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_client_language", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_business_class", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_city_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_street", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_product_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_posting_method", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_posting_method", OracleType.VarChar).Direction = ParameterDirection.Input;
        // POS Merchant Settlement Method changes 20210729
        oracom.Parameters.Add("p_settlement_method", OracleType.VarChar).Direction = ParameterDirection.Input;

        //oracom.Parameters.Add("p_merchant_company", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_relationship_officer", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_parent_retailer_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_manual_application_number", OracleType.Number).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_merchant_contact", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_registration_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_income_range", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_account_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_merchant_acc_no", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rental_percent", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_business_unit", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_DYNAMIC_GROUP_CODE", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_FIXED_GROUP_CODE", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_REGION_CODE", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_parent_client_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_branch_cd", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters.Add("p_client_number", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_merchant_no"].Value = OracleNumber.Null;
        oracom.Parameters["p_client_level"].Value = ddlClientLevel.SelectedValue;
        oracom.Parameters["p_retailer_name"].Value = txtRetailName.Text;
        oracom.Parameters["p_retailer_name_ar"].Value = txtRetailNameAr.Text;
        oracom.Parameters["p_registration_number"].Value = txtRegNo.Text;
        oracom.Parameters["p_index"].Value = txtLegalForm.Text;
        oracom.Parameters["p_fdr"].Value = txtFDR.Text;
        //oracom.Parameters["p_client_language"].Value = ddlLang.SelectedValue;
        oracom.Parameters["p_business_class"].Value = ddlBusinessClass.SelectedValue;
        oracom.Parameters["p_city_code"].Value = ddlCity.SelectedValue;
        //oracom.Parameters["p_street"].Value = txtStreet.Text;
        //oracom.Parameters["p_product_type"].Value = ddlProductType.SelectedValue;

        oracom.Parameters["p_posting_method"].Value = ddlPostingMethod.SelectedValue;
        // POS Merchant Settlement Method changes 20210729
        if (ddlClientLevel.SelectedValue.Equals("003")  )
             oracom.Parameters["p_settlement_method"].Value = ddlSettlMethod.SelectedValue;
        else
            oracom.Parameters["p_settlement_method"].Value = OracleString.Null;

        oracom.Parameters["p_business_unit"].Value = ddlBusinessUnit.SelectedValue;

        oracom.Parameters["p_relationship_officer"].Value = ddlRelationshipOfficer.SelectedValue;
        oracom.Parameters["p_parent_retailer_id"].Value = txtParentClientNumber.Text;
        //if (txtManualAppNo.Text.Length != 0)
        //    oracom.Parameters["p_manual_application_number"].Value = txtManualAppNo.Text;
        //else
        oracom.Parameters["p_manual_application_number"].Value = OracleNumber.Null;
        //oracom.Parameters["p_merchant_contact"].Value = txtMerchantContact.Text;
        oracom.Parameters["p_registration_date"].Value = dateRegDate.date;
        //oracom.Parameters["p_registration_date"].Value = txtRegDate .Text;
        //oracom.Parameters["p_income_range"].Value = ddlIncomeRange.SelectedValue;
        oracom.Parameters["p_account_number"].Value = txtAccNo.Text.Replace(" ", "");
        oracom.Parameters["p_fee_merchant_acc_no"].Value = txtfeemerchantaccno.Text.Replace(" ", "");
        oracom.Parameters["p_rental_percent"].Value = OracleNumber.Null;
        oracom.Parameters["p_region_code"].Value = ddlRegion.SelectedValue;
        if (ddlClientLevel.SelectedValue.Equals("001"))
            oracom.Parameters["p_parent_client_number"].Value = OracleString.Null;
        else
            oracom.Parameters["p_parent_client_number"].Value = txtParentClientNumber.Text;
        oracom.Parameters["p_branch_cd"].Value = ddlBranch.SelectedValue;
        //if (rdDynamic.Checked)
        //{
        //    oracom.Parameters["p_DYNAMIC_GROUP_CODE"].Value = ddlDynamicG.SelectedValue;
        //    oracom.Parameters["p_FIXED_GROUP_CODE"].Value = OracleString.Null;//ddlFixedG.SelectedValue;
        //}
        //else
        //{
        //    oracom.Parameters["p_DYNAMIC_GROUP_CODE"].Value = OracleString.Null;
        //    oracom.Parameters["p_FIXED_GROUP_CODE"].Value = ddlFixedG.SelectedValue;
        //}

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        ID = oracom.Parameters["p_client_number"].Value.ToString();
        error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }

    //loading the lookups lists

    private void loadClientLevel()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_clientlevel";

        oracom.Parameters.Add("p_client_desc", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlClientLevel.DataSource = ds;
        ddlClientLevel.DataBind();

        oracon.Close();
    }
    private void loadBranch(int type)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "bank_lkp_editor.get_branches";

        oracom.Parameters.Add("p_branch_cd", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        if (type == 2)
            oracom.Parameters["p_branch_cd"].Value = ddlBranch.SelectedValue;
        else
            oracom.Parameters["p_branch_cd"].Value = OracleString.Null;

        oracom.Parameters["p_lang"].Value = "EN";

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        if (type == 2)
            txtBranch.Text = ds.Tables[0].Rows[0]["a_nm"].ToString();
        else
        {
            ddlBranch.DataSource = ds;
            ddlBranch.DataBind();
        }
        oracon.Close();
    }
    private void loadLanguage()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_language";

        oracom.Parameters.Add("p_lang", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        //ddlLang.DataSource = ds;
        //ddlLang.DataBind();

        oracon.Close();
    }

    private void loadBusinessClass()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_Businessclass";

        oracom.Parameters.Add("p_Bclass", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlBusinessClass.DataSource = ds;
        ddlBusinessClass.DataBind();

        ddlBusinessClass.Items.Insert(0, "------ Select ------");

        oracon.Close();
    }

    private void loadCityByRegion()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_city_by_region";

        oracom.Parameters.Add("p_region_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_city_names", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_region_code"].Value = ddlRegion.SelectedValue;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlCity.DataSource = ds;
        ddlCity.DataBind();
        ddlCity.SelectedValue = "-1";
        oracon.Close();
    }
    private void loadCity()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_city";

        oracom.Parameters.Add("p_city_names", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlCity.DataSource = ds;
        ddlCity.DataBind();
        ddlCity.SelectedValue = "-1";
        oracon.Close();
    }
    private void loadRegion()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_region";

        oracom.Parameters.Add("p_region_names", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlRegion.DataSource = ds;
        ddlRegion.DataBind();
        ddlRegion.Items.Insert(0, "------ Select ------");
        oracon.Close();
    }

    private void loadProductType()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_Product_type";

        oracom.Parameters.Add("p_ptype", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        //ddlProductType.DataSource = ds;
        //ddlProductType.DataBind();

        oracon.Close();
    }

    private void loadpostingMethod()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_posting_method";

        oracom.Parameters.Add("p_pmethod", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlPostingMethod.DataSource = ds;
        ddlPostingMethod.DataBind();

        oracon.Close();

        ddlPostingMethod.SelectedValue = "001";
        ddlPostingMethod.Enabled = false;
    }

    private void loadsettlementMethod()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_Settl_method";

        oracom.Parameters.Add("p_smethod", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        // POS Merchant Settlement Method changes 20210729
         ddlSettlMethod.DataSource = ds;
         ddlSettlMethod.DataBind();

         //ddlSettlMethod.SelectedValue = "001";
         ddlSettlMethod.Items.Insert(0, "------ Select ------");

        oracon.Close();
    }

    private void loadBusinessUnit()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.Get_Business_Units";

        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlBusinessUnit.DataSource = ds;
        ddlBusinessUnit.DataBind();
        ddlBusinessUnit.SelectedValue = "-1";
        oracon.Close();
    }

    private void loadIncomeRange()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_Income_range";

        oracom.Parameters.Add("c_Income_range", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        //ddlIncomeRange.DataSource = ds;
        //ddlIncomeRange.DataBind();

        oracon.Close();
    }

    private void loadRelationOfficer()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_relationship_officer";

        oracom.Parameters.Add("c_relationship_officer", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlRelationshipOfficer.DataSource = ds;
        ddlRelationshipOfficer.DataBind();

        ddlRelationshipOfficer.Items.Insert(0, "------ Select ------");

        oracon.Close();
    }

    private string getDayofMonth(int pDay)
    {
        string day = "", month = "", year = "";
        if (pDay < 10)
            day = "0" + pDay.ToString();
        else
            day = pDay.ToString();
        if (DateTime.Now.Month < 10)
            month = "0" + DateTime.Now.Month.ToString();
        else
            month = DateTime.Now.Month.ToString();
        year = DateTime.Now.Year.ToString();
        string date = day + "-" + month + "-" + year;
        return date;
    }

    private string loadRegionByCity()
    {
        string regionCode = "";
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_region_by_city";

        oracom.Parameters.Add("p_city_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_city_code"].Value = int.Parse(ddlCity.SelectedValue);

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        regionCode = ds.Tables[0].Rows[0][0].ToString();
        oracon.Close();
        return regionCode;
    }

    private void loadMerchant(string ID)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "merchant_reg.Inherit_Parent_Merchant";

        oracom.Parameters.Add("p_client_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_client_number"].Value = ID;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        oracon.Close();
        if (ds.Tables[0].Rows.Count > 0)
        {

            //set the data in the controls
            txtRetailName.Text = ds.Tables[0].Rows[0]["retailer_name"].ToString();
            txtRetailNameAr.Text = ds.Tables[0].Rows[0]["retailer_name_ar"].ToString();
            txtRegNo.Text = ds.Tables[0].Rows[0]["registration_number"].ToString();
            txtLegalForm.Text = ds.Tables[0].Rows[0]["legal_form"].ToString();
            txtFDR.Text = ds.Tables[0].Rows[0]["fdr_id"].ToString();
            //txtStreet.Text = ds.Tables[0].Rows[0]["street"].ToString();
            //txtManualAppNo.Text = ds.Tables[0].Rows[0]["manual_application_number"].ToString();
            //txtMerchantContact.Text = ds.Tables[0].Rows[0]["merchant_contact"].ToString();
            txtAccNo.Text = ds.Tables[0].Rows[0]["acct_number"].ToString();
            try
            {
                //ddlLang.SelectedValue = ds.Tables[0].Rows[0]["client_language"].ToString();
                ddlBusinessClass.SelectedValue = ds.Tables[0].Rows[0]["business_class"].ToString();
                loadCity();
                ddlCity.Enabled = true;
                ddlCity.SelectedValue = ds.Tables[0].Rows[0]["city_code"].ToString();
                ddlRegion.SelectedValue = loadRegionByCity();
                //ddlPostingMethod.SelectedValue = ds.Tables[0].Rows[0]["posting_method"].ToString();

                // POS Merchant Settlement Method changes 20210729
                if (ddlClientLevel.SelectedValue.Equals("003"))
                {
                    ddlSettlMethod.Enabled = true;
                    ddlSettlMethod.SelectedValue = ds.Tables[0].Rows[0]["settlement_method"].ToString();
                }
                else
                    ddlSettlMethod.Enabled = false;

                //ddlBusinessUnit.SelectedValue = ds.Tables[0].Rows[0]["business_unit"].ToString();
                //loadBUAcc(ddlBusinessUnit.SelectedValue); //mohamed said
                ddlRelationshipOfficer.SelectedValue = ds.Tables[0].Rows[0]["relationship_officer"].ToString();
                ddlBranch.SelectedValue = ds.Tables[0].Rows[0]["branch_no"].ToString();
                txtBranch.Text = ddlBranch.SelectedValue;
                //ddlIncomeRange.SelectedValue = ds.Tables[0].Rows[0]["income_range"].ToString();
                //ddlProductType.SelectedValue = ds.Tables[0].Rows[0]["product_type"].ToString();
            }
            catch (Exception e)
            {
            }
            lblError.Text = "Root name: " + ds.Tables[0].Rows[0]["retailer_name"].ToString();

            if (ds.Tables[0].Rows[0]["dynamic_group_code"].ToString().Length == 0)
            {
                //rdFixed.Checked = true;
                //ddlFixedG.SelectedValue = ds.Tables[0].Rows[0]["fixed_group_code"].ToString();
            }
            else if (ds.Tables[0].Rows[0]["fixed_group_code"].ToString().Length == 0)
            {
                //rdDynamic.Checked = true;
                //ddlDynamicG.SelectedValue = ds.Tables[0].Rows[0]["dynamic_group_code"].ToString();
            }
        }
        else
            lblError.Text = "Parent ID not valid...";
    }

    private void loadBUAcc(string ID)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.Get_Business_Unit_Acct";

        oracom.Parameters.Add("p_bu_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_bu_code"].Value = ID;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        oracon.Close();

        txtBUAcc.Text = ds.Tables[0].Rows[0][0].ToString();

    }

    private void loadDynamicGroups()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.Get_Dyn_Fee_Groups";

        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        //ddlDynamicG.DataSource = ds;
        //ddlDynamicG.DataBind();

        oracon.Close();
    }

    private void loadStaticGroups()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.Get_Fixed_Fee_Groups";

        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        //ddlFixedG.DataSource = ds;
        //ddlFixedG.DataBind();

        oracon.Close();
    }

    protected void btnParentData_Click(object sender, EventArgs e)
    {
        loadMerchant(txtParentClientNumber.Text);
    }

    protected void ddlBusinessUnit_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadBUAcc(ddlBusinessUnit.SelectedValue);
    }

    protected void btnMW_Click(object sender, EventArgs e)
    {
        //checkCCR();
        //if (checkAcc())
        //{
        //    lblError.Text = "Account Verification Done...";
        if (checkCCR())
        {
            lblError.Text = "Account Verification Done...<br>Account Information Acquired...";
            btnSave.Enabled = true;
        }
        else
        {
            btnSave.Enabled = false;
            lblError.Text = ViewState["MESSAGE"].ToString();
        }
        //}
        //else
        //{
        //    lblError.Text = ViewState["MESSAGE"].ToString();
        //}
    }

    private bool checkAcc()
    {
        //string Directory = ConfigurationSettings.AppSettings["MWCertificate"];
        //string XmlMessage = "";
        //string XmlResponse = "";
        //string TransportVia = "I";
        //string TransportMethod = "Synch";
        //string LangItem = "1";

        //NCBEAI.Adapters.Transport.Message Request = new Message(Directory);

        //XmlMessage = "<AccID>"+txtAccNo.Text+"</AccID>";

        //Request.TCod = "AccountDetails";
        //int finalError = Request.PrepareMessage(XmlMessage, LangItem, Directory, TransportVia, TransportMethod, out XmlResponse);

        //if (XmlResponse.Contains("OK"))
        //{
        //    XmlDocument doc = new XmlDocument();
        //    doc.LoadXml(XmlResponse);
        //    XmlNode node = doc.SelectSingleNode("/OK");
        //    return true;
        //}
        //else if (XmlResponse.Contains("ERR"))
        //{
        //    XmlDocument doc = new XmlDocument();
        //    doc.LoadXml(XmlResponse);
        //    XmlNode node = doc.SelectSingleNode("/ERR");
        //    string temp = node.Attributes["Desc"].InnerText;
        //    string temp1 = node.Attributes["NativeErr"].InnerText;
        //    string temp2 = node.Attributes["NativeDesc"].InnerText;

        //    ViewState["MESSAGE"] = temp + " " + temp1 + " " + temp2;
        //    return false;
        //}

        return true;
    }

    private bool checkCCR()
    {
        //string Directory = ConfigurationSettings.AppSettings["MWCertificate"];
        //string XmlMessage = "";
        //string XmlResponse = "";
        //string TransportVia = "I";
        //string TransportMethod = "Synch";
        //string LangItem = "1";

        //NCBEAI.Adapters.Transport.Message Request = new Message(Directory);

        ////XmlMessage = "<AccID>" + txtAccNo.Text + "</AccID>";
        //XmlMessage = "<GetPartyReq tcod=\"GetPartyInformation\"><MSGHDR><MsgDateTime></MsgDateTime><SessionId>1</SessionId><ChannelId>1</ChannelId><FunctionId>0400</FunctionId><UserId>EAIMW</UserId><Lang>AR</Lang><TerminalId>1</TerminalId><Reserved1></Reserved1></MSGHDR><MSGBDY><CTRL><InquiryMode>S</InquiryMode><RMNotes>N</RMNotes><RelationInfo>N</RelationInfo><StatisticalInfo>N</StatisticalInfo><RiskRatingInf>N</RiskRatingInf><LimitsInfo>N</LimitsInfo><SegmentHistoryInfo>N</SegmentHistoryInfo><ProgramDetailsInfo>N</ProgramDetailsInfo><PtyPrdExpInfo>N</PtyPrdExpInfo><PtyInvAsstCurrInfo>N</PtyInvAsstCurrInfo><RelationBasicInfo>Y</RelationBasicInfo><RelationTypes /><PtyNotificationInfo /><PtyInvInfo /><FltrPtyAcctAddr>Y</FltrPtyAcctAddr><FltrPtyCont>Y</FltrPtyCont><FltrPtyIds>Y</FltrPtyIds><ReverseRelationFlg>N</ReverseRelationFlg><FltrNCBCCont>Y</FltrNCBCCont></CTRL><PTY><EcnId></EcnId><PartyId /></PTY><ACCT><AcctNo>" + txtAccNo.Text + "</AcctNo></ACCT><PTYSYSLNK><SysCustUsrNo /></PTYSYSLNK></MSGBDY></GetPartyReq>";
        //Request.TCod = "";
        //int finalError = Request.PrepareMessage(XmlMessage, LangItem, Directory, TransportVia, TransportMethod, out XmlResponse);

        //if (XmlResponse.Contains("OK"))
        //{
        //    XmlDocument doc = new XmlDocument();
        //    doc.LoadXml(XmlResponse);
        //    XmlNode node = doc.SelectSingleNode("/OK/MSGBDY/BASIC/EcnId");
        //    if (node == null)
        //    {
        //        ViewState["MESSAGE"] = "There is no customer with the entered account";
        //        return false;
        //    }
        //    string ECN = node.InnerText;

        //    node = doc.SelectSingleNode("/OK/MSGBDY/BASIC/IdNumber");
        //    string crn = node.InnerText;
        //    txtRegNo.Text = crn;
        //    //call blacklist
        //    if (isBlackList(crn, txtAccNo.Text))
        //    {
        //        ViewState["MESSAGE"] = "This merchant is black listed";
        //        return false;
        //    }
        //    //calling get party with the ECN as filter
        //    string CCRUser = ConfigurationSettings.AppSettings["CCRUser"];
        //    string CCRSession = ConfigurationSettings.AppSettings["CCRSession"];
        //    string CCRChannel = ConfigurationSettings.AppSettings["CCRChannel"];
        //    string CCRTerminal = ConfigurationSettings.AppSettings["CCRTerminal"];

        //    XmlMessage = "<GetPartyReq tcod=\"GetPartyInformation\"><MSGHDR><MsgDateTime>25/12/2013</MsgDateTime><SessionId>" + CCRSession + "</SessionId><ChannelId>" + CCRChannel + "</ChannelId><FunctionId>0400</FunctionId><UserId>" + CCRUser + "</UserId><Lang>AR</Lang><TerminalId>" + CCRTerminal + "</TerminalId><Reserved1>CCR044C</Reserved1></MSGHDR><MSGBDY><CTRL><InquiryMode>P</InquiryMode><RMNotes>N</RMNotes><RelationInfo>N</RelationInfo><StatisticalInfo>N</StatisticalInfo><RiskRatingInf>N</RiskRatingInf><LimitsInfo>N</LimitsInfo><SegmentHistoryInfo>N</SegmentHistoryInfo><ProgramDetailsInfo>N</ProgramDetailsInfo><PtyPrdExpInfo>N</PtyPrdExpInfo><PtyInvAsstCurrInfo>N</PtyInvAsstCurrInfo><RelationBasicInfo>Y</RelationBasicInfo><RelationTypes /><PtyNotificationInfo /><PtyInvInfo /><FltrPtyAcctAddr>Y</FltrPtyAcctAddr><FltrPtyCont>Y</FltrPtyCont><FltrPtyIds>Y</FltrPtyIds><ReverseRelationFlg>N</ReverseRelationFlg><FltrNCBCCont>Y</FltrNCBCCont></CTRL><PTY><EcnId>" + ECN + "</EcnId><PartyId /></PTY><PTYSYSLNK><SysCustUsrNo /></PTYSYSLNK></MSGBDY></GetPartyReq>";
        //    finalError = Request.PrepareMessage(XmlMessage, LangItem, Directory, TransportVia, TransportMethod, out XmlResponse);

        //    if (XmlResponse.Contains("OK"))
        //    {
        //        doc.LoadXml(XmlResponse);
        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTY/FullName");
        //        if (node != null)
        //            txtRetailNameAr.Text = node.InnerText;

        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTYLNG/FullName2");
        //        if (node != null)
        //            txtRetailName.Text = node.InnerText;

        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTYACCTADDR/Address1");
        //        if (node != null)
        //            ViewState["addr1"] = node.InnerText;

        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTYACCTADDR/Address2");
        //        if (node != null)
        //            ViewState["addr2"] = node.InnerText;

        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTYACCTADDR/Address3");
        //        if (node != null)
        //            ViewState["addr3"] = node.InnerText;

        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTYACCTADDR/PoBox");
        //        if (node != null)
        //            ViewState["PoBox"] = node.InnerText;

        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTYACCTADDR/PostalCd");
        //        if (node != null)
        //            ViewState["PostalCd"] = node.InnerText;

        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTYCONT/FaxNo1");
        //        if (node != null)
        //            ViewState["fax"] = node.InnerText;

        //        node = doc.SelectSingleNode("/OK/MSGBDY/DETAILED/PTYCONT/MobileNo1");
        //        if (node != null)
        //            ViewState["mobile"] = node.InnerText;
        //    }
        //    else if (XmlResponse.Contains("ERR"))
        //    {
        //        XmlDocument docErr = new XmlDocument();
        //        docErr.LoadXml(XmlResponse);
        //        XmlNode nodeErr = docErr.SelectSingleNode("/ERR");
        //        string temp = nodeErr.Attributes["Desc"].InnerText;
        //        string temp1 = nodeErr.Attributes["NativeErr"].InnerText;
        //        string temp2 = nodeErr.Attributes["NativeDesc"].InnerText;

        //        ViewState["MESSAGE"] = temp + " " + temp1 + " " + temp2;
        //        return false;
        //    }

        //    return true;
        //}
        //else if (XmlResponse.Contains("ERR"))
        //{
        //    XmlDocument doc = new XmlDocument();
        //    doc.LoadXml(XmlResponse);
        //    XmlNode node = doc.SelectSingleNode("/ERR");
        //    string temp = node.Attributes["Desc"].InnerText;
        //    string temp1 = node.Attributes["NativeErr"].InnerText;
        //    string temp2 = node.Attributes["NativeDesc"].InnerText;

        //    ViewState["MESSAGE"] = temp + " " + temp1 + " " + temp2;
        //    return false;
        //}

        return true;
    }

    protected void txtStreet_TextChanged(object sender, EventArgs e)
    {

    }

    private bool addAddress(string clientNo)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "MER_ADDRESS_EDITOR.Add_Merchant_Address";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_client_no", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_record_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_effective_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_address_category", OracleType.VarChar).Direction = ParameterDirection.Input;
        // POS Merchant Settlement Method changes 20210729
        oracom.Parameters.Add("p_delivery_Method", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_contact_name", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_po_box", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_english_address1", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_english_address2", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_english_address3", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_arabic_address1", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_arabic_address2", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_arabic_address3", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_post_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_city", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_country", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tel_work", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tel_other", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fax", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_mobile", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_mobile_2", OracleType.VarChar).Direction = ParameterDirection.Input;//Amjath 20140824
        oracom.Parameters.Add("p_mobile_3", OracleType.VarChar).Direction = ParameterDirection.Input;//Amjath 20140824
        oracom.Parameters.Add("p_email_address", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_email_2", OracleType.VarChar).Direction = ParameterDirection.Input;//Amjath 20140824
        oracom.Parameters.Add("p_email_3", OracleType.VarChar).Direction = ParameterDirection.Input;//Amjath 20140824
        oracom.Parameters.Add("p_lang", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_type", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_msg", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_client_no"].Value = clientNo;
        oracom.Parameters["p_record_type"].Value = "111";
        oracom.Parameters["p_effective_date"].Value = "090909";
        oracom.Parameters["p_address_category"].Value = "001";// ddlAddressCat.SelectedValue;
        // POS Merchant Settlement Method changes 20210729
        oracom.Parameters["p_delivery_Method"].Value = "001";

        oracom.Parameters["p_contact_name"].Value = txtRetailName.Text;

        if (ViewState["PoBox"] != null)
            oracom.Parameters["p_po_box"].Value = ViewState["PoBox"].ToString();
        else
            oracom.Parameters["p_po_box"].Value = "";

        if (ViewState["addr1"] != null)
            oracom.Parameters["p_arabic_address1"].Value = ViewState["addr1"].ToString();
        else
            oracom.Parameters["p_arabic_address1"].Value = "";

        if (ViewState["addr2"] != null)
            oracom.Parameters["p_arabic_address2"].Value = ViewState["addr2"].ToString();
        else
            oracom.Parameters["p_arabic_address2"].Value = "";

        if (ViewState["addr3"] != null)
            oracom.Parameters["p_arabic_address3"].Value = ViewState["addr3"].ToString();
        else
            oracom.Parameters["p_arabic_address3"].Value = "";

        oracom.Parameters["p_english_address1"].Value = "";//txtEngAdd1.Text;
        oracom.Parameters["p_english_address2"].Value = "";//txtEngAdd2.Text;
        oracom.Parameters["p_english_address3"].Value = "";//txtEngAdd3.Text;

        if (ViewState["PostalCd"] != null)
            oracom.Parameters["p_post_code"].Value = ViewState["PostalCd"].ToString();
        else
            oracom.Parameters["p_post_code"].Value = "";

        oracom.Parameters["p_city"].Value = ddlCity.SelectedValue;
        oracom.Parameters["p_country"].Value = "682";
        oracom.Parameters["p_tel_work"].Value = "";//txtTelWork.Text;
        oracom.Parameters["p_tel_other"].Value = "";//txtTelOther.Text;

        if (ViewState["fax"] != null)
            oracom.Parameters["p_fax"].Value = ViewState["fax"].ToString();
        else
            oracom.Parameters["p_fax"].Value = "";

        if (ViewState["mobile"] != null)
            oracom.Parameters["p_mobile"].Value = ViewState["mobile"].ToString();
        else
            oracom.Parameters["p_mobile"].Value = "";

        oracom.Parameters["p_mobile_2"].Value = "";//txtMobile2.Text;//Amjath 20140824
        oracom.Parameters["p_mobile_3"].Value = "";//txtMobile3.Text;//Amjath 20140824
        oracom.Parameters["p_email_address"].Value = "";//txtEmail.Text;
        oracom.Parameters["p_email_2"].Value = "";//txtEmail2.Text;//Amjath 20140824
        oracom.Parameters["p_email_3"].Value = "";//txtEmail3.Text;//Amjath 20140824
        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        //error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "0")
            return true;
        else
            return false;
    }

    private bool isBlackList(string CRN, string account)
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "MERCHANT_BLACKLIST_EDITOR.Is_BlackListed";

        oracom.Parameters.Add("p_mer_crn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_mer_Acct", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_res", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.Parameters["p_mer_crn"].Value = CRN;
        oracom.Parameters["p_mer_Acct"].Value = account;
        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res"].Value.ToString();
        //error = oracom.Parameters["p_res_msg"].Value.ToString();
        if (a == "Y")
            return true;
        else
            return false;
    }
    protected void ddlRegion_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlCity.Enabled = true;
        if (ddlRegion.SelectedIndex != -1)
            loadCityByRegion();
    }

    private bool checkProperParent()
    {
        // Handle root merchant
        if (ddlClientLevel.SelectedValue == "001")
        {
            return true;
        }

        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "merchant_reg.Inherit_Parent_Merchant";

        oracom.Parameters.Add("p_client_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_output", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_client_number"].Value = txtParentClientNumber.Text;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        oracon.Close();
        if (ds.Tables[0].Rows.Count > 0)
        {

            //set the data in the controls
            string level = ds.Tables[0].Rows[0]["client_level"].ToString();

            if (ddlClientLevel.SelectedValue == "002" && level != "001")
            {
                lblError.Text = "Parent ID must belong to a root merchant...";
                return false;
            }

            if (ddlClientLevel.SelectedValue == "003" && level != "002")
            {
                lblError.Text = "Parent ID must belong to a branch merchant...";
                return false;
            }

            return true;
        }
        else
        {
            lblError.Text = "Parent ID not valid...";
            return false;
        }
    }

    protected void ddlBranch_SelectedIndexChanged1(object sender, EventArgs e)
    {
        loadBranch(2);
    }
}
