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 System.Drawing;

public partial class Business_UpdateMerchant : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadClientLevel();
            loadLanguage();
            loadBusinessClass();
            loadCity();
            loadProductType();
            loadPostingMethod();
            loadsettlementMethod();
            loadBusinessUnit();
            loadServices();
            loadTerminals();
            loadCurrancy();
            loadIncomeRange();
            loadRelationOfficer();
            loadAddressCategory();
            loadTerminalStatus();
            loadChargeReason();
            loadComments();
            loadDynamicGroups();
            loadStaticGroups();

            string clID         = Request.QueryString["clID"];
            lblClientNo.Text    = clID;
            loadMerchant         (clID);
            loadMerchantAddresses(clID, Helper.gridSize(), 1);
            loadMerchantServices (clID, Helper.gridSize(), 1);
            loadMerchantTerminals(clID, Helper.gridSize(), 1);
            loadBUAcc(ddlBusinessUnit.SelectedValue);
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {


        if (txtRetailName.Text.Length == 0 ||  ddlBusinessUnit.SelectedValue == "-1")
            lblError.Text = "Merchant Name and Business Unit cannot be empty";

        else if (true)
        {
            string error = "", ID = Request.QueryString["clID"];
            bool saved = updateMerchant(ref error);
            if (saved)
            {
                lblError.Text = "Merchant saved";
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + ID + "&action=Update Merchant','MerchantComment','status=1,width=700,height=250')", true);
            }
            else
            {
                lblError.Text = error;
            }
        }
        else
        {
            lblError.Text = "please complete all the mandatory fields in the screen.";
        }
    }

    private bool updateMerchant(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.update_merchant_info";

        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_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_legal_form", 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_settlement_method", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_business_unit", OracleType.VarChar).Direction = ParameterDirection.Input;

        oracom.Parameters.Add("p_relationship_officer", 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_rental_percent", OracleType.Number).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_acct_number", 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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_client_no"].Value = Request.QueryString["clID"];
        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_legal_form"].Value = txtLegalForm.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;
        oracom.Parameters["p_settlement_method"].Value = ddlSettlMethod.SelectedValue;
        oracom.Parameters["p_business_unit"].Value = ddlBusinessUnit.SelectedValue;
        
        oracom.Parameters["p_relationship_officer"].Value = ddlRelationshipOfficer.SelectedValue;
        oracom.Parameters["p_manual_application_number"].Value = txtManualAppNo.Text;
        oracom.Parameters["p_merchant_contact"].Value = txtMerchantContact.Text;
        oracom.Parameters["p_registration_date"].Value = dateRegDate.date;
        oracom.Parameters["p_income_range"].Value = ddlIncomeRange.SelectedValue;
        oracom.Parameters["p_rental_percent"].Value = OracleNumber.Null;

        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.Parameters["p_acct_number"].Value = txtAccNoGeneral.Text;

        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 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.get_merchant_by_id";

        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();

        //set the data in the controls
        ddlClientLevel.SelectedValue = ds.Tables[0].Rows[0]["client_level"].ToString();
        ddlClientLevel.Enabled = false;
        if (ddlClientLevel.SelectedValue.Equals("001"))
        {
            lblMerchantName.Text = "Merchant Name";
            lblMerchantNameAr.Text = "Arabic Merchant Name";
        }
        else
        {
            lblMerchantName.Text = "Retailer Name";
            lblMerchantNameAr.Text = "Arabic Retailer Name";
        }

        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();
        ddlLang.SelectedValue = ds.Tables[0].Rows[0]["client_language"].ToString();
        ddlBusinessClass.SelectedValue = ds.Tables[0].Rows[0]["business_class"].ToString();
        ddlCity.SelectedValue = ds.Tables[0].Rows[0]["city_code"].ToString();
        txtStreet.Text = ds.Tables[0].Rows[0]["street"].ToString();
        ddlProductType.SelectedValue = ds.Tables[0].Rows[0]["product_type"].ToString();
        ddlPostingMethod.SelectedValue = ds.Tables[0].Rows[0]["posting_method"].ToString();
        ddlSettlMethod.SelectedValue = ds.Tables[0].Rows[0]["settlement_method"].ToString();
        ddlBusinessUnit.SelectedValue = ds.Tables[0].Rows[0]["business_unit"].ToString();
        ddlRelationshipOfficer.SelectedValue = ds.Tables[0].Rows[0]["relationship_officer"].ToString();
        txtRetailerID.Text = ds.Tables[0].Rows[0]["retailer_id"].ToString();
        txtManualAppNo.Text = ds.Tables[0].Rows[0]["manual_application_number"].ToString();
        txtMerchantContact.Text = ds.Tables[0].Rows[0]["merchant_contact"].ToString();
        dateRegDate.date = ds.Tables[0].Rows[0]["registration_date"].ToString();
        ddlIncomeRange.SelectedValue = ds.Tables[0].Rows[0]["income_range"].ToString();
        txtAccNoGeneral.Text = ds.Tables[0].Rows[0]["acct_number"].ToString();
        
        txtBUAcc.Text = ds.Tables[0].Rows[0]["bu_acct"].ToString();

        string dynamic = ds.Tables[0].Rows[0]["dynamic_group_code"].ToString();
        string fixxed = ds.Tables[0].Rows[0]["fixed_group_code"].ToString();

        if (dynamic.Length > 0)
        {
            ddlDynamicG.SelectedValue = dynamic;
            rdDynamic.Checked = true;
        }
        else if (fixxed.Length > 0)
        {
            ddlFixedG.SelectedValue = fixxed;
            rdFixed.Checked = true;
        }

        ViewState["cat_com"] = ds.Tables[0].Rows[0]["cat_commision"].ToString();

        //**************************************************************************************************************************************************************************//
        //load the old values

        txtAccNoGeneralOld.Text = ds.Tables[0].Rows[0]["acct_number_old"].ToString();
        if (txtAccNoGeneralOld.Text == txtAccNoGeneral.Text)
            txtAccNoGeneralOld.Visible = false;
        else
            txtAccNoGeneralOld.Visible = true;

        txtRetailNameOld.Text = ds.Tables[0].Rows[0]["retailer_name_old"].ToString();
        if (txtRetailNameOld.Text == txtRetailName.Text)
            txtRetailNameOld.Visible = false;
        else
            txtRetailNameOld.Visible = true;

        txtRetailNameArOld.Text = ds.Tables[0].Rows[0]["retailer_name_ar_old"].ToString();
        if (txtRetailNameArOld.Text == txtRetailNameAr.Text)
            txtRetailNameArOld.Visible = false;
        else
            txtRetailNameArOld.Visible = true;

        txtLegalFormOld.Text = ds.Tables[0].Rows[0]["legal_form_old"].ToString();
        if (txtLegalFormOld.Text == txtLegalForm.Text)
            txtLegalFormOld.Visible = false;
        else
            txtLegalFormOld.Visible = true;

        txtLegalFormOld.Text = ds.Tables[0].Rows[0]["legal_form_old"].ToString();
        if (txtLegalFormOld.Text == txtLegalForm.Text)
            txtLegalFormOld.Visible = false;
        else
            txtLegalFormOld.Visible = true;

        ddlLangOld.SelectedValue = ds.Tables[0].Rows[0]["client_language_old"].ToString();
        if (ddlLangOld.SelectedIndex == ddlLang.SelectedIndex)
            ddlLangOld.Visible = false;
        else
            ddlLangOld.Visible = true;

        ddlBusinessClassOld.SelectedValue = ds.Tables[0].Rows[0]["business_class_old"].ToString();
        if (ddlBusinessClassOld.SelectedIndex == ddlBusinessClass.SelectedIndex)
            ddlBusinessClassOld.Visible = false;
        else
            ddlBusinessClassOld.Visible = true;

        ddlCityOld.SelectedValue = ds.Tables[0].Rows[0]["city_code_old"].ToString();
        if (ddlCityOld.SelectedIndex == ddlCity.SelectedIndex)
            ddlCityOld.Visible = false;
        else
            ddlCityOld.Visible = true;

        txtStreetOld.Text = ds.Tables[0].Rows[0]["street_old"].ToString();
        if (txtStreetOld.Text == txtStreet.Text)
            txtStreetOld.Visible = false;
        else
            txtStreetOld.Visible = true;

        ddlProductTypeOld.SelectedValue = ds.Tables[0].Rows[0]["product_type_old"].ToString();
        if (ddlProductTypeOld.SelectedIndex == ddlProductType.SelectedIndex)
            ddlProductTypeOld.Visible = false;
        else
            ddlProductTypeOld.Visible = true;

        ddlDynamicGOld.SelectedValue = ds.Tables[0].Rows[0]["dynamic_group_code_old"].ToString();
        if (ddlDynamicGOld.SelectedIndex == ddlDynamicG.SelectedIndex)
            ddlDynamicGOld.Visible = false;
        else
            ddlDynamicGOld.Visible = true;

        ddlFixedGOld.SelectedValue = ds.Tables[0].Rows[0]["fixed_group_code_old"].ToString();
        if (ddlFixedGOld.SelectedIndex == ddlFixedG.SelectedIndex)
            ddlFixedGOld.Visible = false;
        else
            ddlFixedGOld.Visible = true;

        ddlBusinessUnitOld.SelectedValue = ds.Tables[0].Rows[0]["business_unit_old"].ToString();
        if (ddlBusinessUnitOld.SelectedIndex == ddlBusinessUnit.SelectedIndex)
            ddlBusinessUnitOld.Visible = false;
        else
            ddlBusinessUnitOld.Visible = true;

        ddlIncomeRangeOld.SelectedValue = ds.Tables[0].Rows[0]["income_range_old"].ToString();
        if (ddlIncomeRangeOld.SelectedIndex == ddlIncomeRange.SelectedIndex)
            ddlIncomeRangeOld.Visible = false;
        else
            ddlIncomeRangeOld.Visible = true;

        ddlRelationshipOfficerOld.SelectedValue = ds.Tables[0].Rows[0]["relationship_officer_old"].ToString();
        if (ddlRelationshipOfficerOld.SelectedIndex == ddlRelationshipOfficer.SelectedIndex)
            ddlRelationshipOfficerOld.Visible = false;
        else
            ddlRelationshipOfficerOld.Visible = true;

        txtManualAppNoOld.Text = ds.Tables[0].Rows[0]["manual_application_number_old"].ToString();
        if (txtManualAppNoOld.Text == txtManualAppNo.Text)
            txtManualAppNoOld.Visible = false;
        else
            txtManualAppNoOld.Visible = true;

        txtMerchantContactOld.Text = ds.Tables[0].Rows[0]["merchant_contact_old"].ToString();
        if (txtMerchantContactOld.Text == txtMerchantContact.Text)
            txtMerchantContactOld.Visible = false;
        else
            txtMerchantContactOld.Visible = true;

        dateRegDateOld.Text = ds.Tables[0].Rows[0]["registration_date_old"].ToString();
        if (dateRegDateOld.Text == dateRegDate.FormatedDate)
            dateRegDateOld.Visible = false;
        else
            dateRegDateOld.Visible = true;

        txtRegNoOld.Text = ds.Tables[0].Rows[0]["registration_number_old"].ToString();
        if (txtRegNoOld.Text == txtRegNo.Text)
            txtRegNoOld.Visible = false;
        else
            txtRegNoOld.Visible = true;
    }

    private void loadMerchantAddresses(string MerID, int pageSize, int pageNumber)
    {
        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.Get_Merchant_Addresses";

        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_page_size", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_page_num", OracleType.Number).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_outputaddr", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

        oracom.Parameters["p_client_no"].Value = MerID;

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

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

        int nop = int.Parse(oracom.Parameters["p_total_pages"].Value.ToString());
        oracon.Close();

        gvAddresses.DataSource = ds;
        gvAddresses.DataBind();
    }

    private void loadMerchantServices(string MerID, int pageSize, int pageNumber)
    {
        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_service.get_appl_service";

        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_page_size", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_page_num", OracleType.Number).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_output", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

        oracom.Parameters["p_client_no"].Value = MerID;

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

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

        int nop = int.Parse(oracom.Parameters["p_total_pages"].Value.ToString());
        oracon.Close();

        gvServices.DataSource = ds;
        gvServices.DataBind();
    }

    private void loadMerchantTerminals(string MerID, int pageSize, int pageNumber)
    {
        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_DEVICE_LINK_EDITOR.Get_Client_Device_Links";

        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_page_size", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_page_num", OracleType.Number).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_outputdevicelink", OracleType.Cursor).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_total_pages", OracleType.Number).Direction = ParameterDirection.Output;

        oracom.Parameters["p_client_no"].Value = MerID;

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

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

        int nop = int.Parse(oracom.Parameters["p_total_pages"].Value.ToString());
        oracon.Close();

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

        if (pageNumber == 1)
        {
            ddlPages.Items.Clear();
            for (int i = 1; i <= nop; i++)
            {
                ddlPages.Items.Add(i.ToString());
            }
        }
    }

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

    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();

    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        
          loadMerchantTerminals(Request.QueryString["clID"], Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
    }


    //********************************   loading the lookups lists   ********************************\\

    private void loadComments()
    {
        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_NOTE_EDITOR.Display_Reg_Notes";

        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_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_output", OracleType.Cursor).Direction = ParameterDirection.Output;

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



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

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

        oracon.Close();
    }

    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();
        ddlDynamicGOld.DataSource = ds;
        ddlDynamicGOld.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();
        ddlFixedGOld.DataSource = ds;
        ddlFixedGOld.DataBind();

        oracon.Close();
    }
    
    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 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();

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

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

        DropDownList1Old.DataSource = ds;
        DropDownList1Old.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();

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

        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();

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

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

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

        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();
        ddlProductTypeOld.DataSource = ds;
        ddlProductTypeOld.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.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);

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

        oracon.Close();

        ddlSettlMethod.Enabled = false;
    }

    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();
        ddlBusinessUnitOld.DataSource = ds;
        ddlBusinessUnitOld.DataBind();

        oracon.Close();
    }

    private void loadServices()
    {
        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_MerServices";

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

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

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

        oracon.Close();
    }

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "DEVICE_REPOSITORY_EDITOR.Get_Available_Device_List";

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

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

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

        oracon.Close();
    }

    private void loadCurrancy()
    {
        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_Merch_Currency";

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

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

        ddlCurrancy.DataSource = ds;
        ddlCurrancy.DataBind();
        ddlCurrancyOld.DataSource = ds;
        ddlCurrancyOld.DataBind();

        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();
        ddlIncomeRangeOld.DataSource = ds;
        ddlIncomeRangeOld.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();
        ddlRelationshipOfficerOld.DataSource = ds;
        ddlRelationshipOfficerOld.DataBind();

        oracon.Close();
    }

    private void loadAddressCategory()
    {
        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_address_category";

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

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

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

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

        oracon.Close();
    }

    private void loadTerminalStatus()
    {
        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_terminal_status";

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

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

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

        oracon.Close();
    }

    private void loadChargeReason()
    {
        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_Charge_Reasons";

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

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

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

        oracon.Close();
    }

    //****************************************    Addresses   ****************************************\\

    protected void btnAddAddress_Click(object sender, EventArgs e)
    {
        pnlAddress.Visible = true;
        ViewState["mode"] = "a";

            txtContactnameOld.Visible = false;
            txtPOBoxOld.Visible = false;
            txtEngAdd1Old.Visible = false;
            txtEngAdd2Old.Visible = false;
            txtEngAdd3Old.Visible = false;
            txtArabAdd1Old.Visible = false;
            txtArabAdd2Old.Visible = false;
            txtArabAdd3Old.Visible = false;
            txtPostCodeOld.Visible = false;
            txtTelWorkOld.Visible = false;
            txtTelOtherOld.Visible = false;
            txtFaxOld.Visible = false;
            txtMobileOld.Visible = false;
            txtEmailOld.Visible = false;
            ddlAddressCityOld.Visible = false;
            ddlAddressCatOld.Visible = false;
    }

    protected void btnCancelAddress_Click(object sender, EventArgs e)
    {
        pnlAddress.Visible = false;
        ViewState["mode"] = null;
    }

    protected void btnSaveAddress_Click(object sender, EventArgs e)
    {
        try
        {
            string mode = ViewState["mode"].ToString();
            string error = "";
            if (mode.Equals("a"))
            {
                string clID = Request.QueryString["clID"];
                bool saved = addAddress(clID, ref error);
                if (saved)
                {
                    lblError.Text = "Address data Saved";
                    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + clID + "&action=Add Address','MerchantComment','status=1,width=700,height=250')", true);
                }
                else
                {
                    lblError.Text = error;
                }
            }
            else if (mode.Equals("u"))
            {
                string clID = Request.QueryString["clID"];
                string Uid = ViewState["rowid"].ToString();
                bool saved = updateAddress(Uid, ref error);
                if (saved)
                {
                    lblError.Text = "Address data Saved";
                    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + clID + "&action=Update Address','MerchantComment','status=1,width=700,height=250')", true);
                }
                else
                {
                    lblError.Text = error;
                }
            }
            loadMerchantAddresses(Request.QueryString["clID"], Helper.gridSize(), 1);
            ViewState["mode"] = null;
            ViewState["rowid"] = null;
            pnlAddress.Visible = false;
        }
        catch (Exception ex)
        {
        }
    }

    private bool addAddress(string clientNo, 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 = "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;
        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_email_address", 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["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 = ddlAddressCat.SelectedValue;

        oracom.Parameters["p_contact_name"].Value = txtContactname.Text;
        oracom.Parameters["p_po_box"].Value = txtPOBox.Text;
        oracom.Parameters["p_english_address1"].Value = txtEngAdd1.Text;
        oracom.Parameters["p_english_address2"].Value = txtEngAdd2.Text;
        oracom.Parameters["p_english_address3"].Value = txtEngAdd3.Text;
        oracom.Parameters["p_arabic_address1"].Value = txtArabAdd1.Text;
        oracom.Parameters["p_arabic_address2"].Value = txtArabAdd2.Text;
        oracom.Parameters["p_arabic_address3"].Value = txtArabAdd3.Text;
        oracom.Parameters["p_post_code"].Value = txtPostCode.Text;
        oracom.Parameters["p_city"].Value = ddlAddressCity.SelectedValue;
        oracom.Parameters["p_country"].Value = "682";
        oracom.Parameters["p_tel_work"].Value = txtTelWork.Text;
        oracom.Parameters["p_tel_other"].Value = txtTelOther.Text;
        oracom.Parameters["p_fax"].Value = txtFax.Text;
        oracom.Parameters["p_mobile"].Value = txtMobile.Text;
        oracom.Parameters["p_email_address"].Value = txtEmail.Text;

        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 updateAddress(string clientNo, 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 = "MER_ADDRESS_EDITOR.Update_Merchant_Address";

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

        oracom.Parameters.Add("p_ma_code", 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;
        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_email_address", 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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_ma_code"].Value = clientNo;
        oracom.Parameters["p_record_type"].Value = "111";
        oracom.Parameters["p_effective_date"].Value = "090909";
        oracom.Parameters["p_address_category"].Value = ddlAddressCat.SelectedValue;

        oracom.Parameters["p_contact_name"].Value = txtContactname.Text;
        oracom.Parameters["p_po_box"].Value = txtPOBox.Text;
        oracom.Parameters["p_english_address1"].Value = txtEngAdd1.Text;
        oracom.Parameters["p_english_address2"].Value = txtEngAdd2.Text;
        oracom.Parameters["p_english_address3"].Value = txtEngAdd3.Text;
        oracom.Parameters["p_arabic_address1"].Value = txtArabAdd1.Text;
        oracom.Parameters["p_arabic_address2"].Value = txtArabAdd2.Text;
        oracom.Parameters["p_arabic_address3"].Value = txtArabAdd3.Text;
        oracom.Parameters["p_post_code"].Value = txtPostCode.Text;
        oracom.Parameters["p_city"].Value = ddlAddressCity.SelectedValue;
        oracom.Parameters["p_country"].Value = "682";
        oracom.Parameters["p_tel_work"].Value = txtTelWork.Text;
        oracom.Parameters["p_tel_other"].Value = txtTelOther.Text;
        oracom.Parameters["p_fax"].Value = txtFax.Text;
        oracom.Parameters["p_mobile"].Value = txtMobile.Text;
        oracom.Parameters["p_email_address"].Value = txtEmail.Text;

        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 void loadAddressByID(string addressID)
    {
        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.Get_Merchant_Address_by_id";

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

        oracom.Parameters["p_ma_code"].Value = addressID;

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

        oracon.Close();

        //set the data in the controls
        txtContactname.Text = ds.Tables[0].Rows[0]["contact_name"].ToString();
        txtPOBox.Text = ds.Tables[0].Rows[0]["po_box"].ToString();
        txtEngAdd1.Text = ds.Tables[0].Rows[0]["english_address1"].ToString();
        txtEngAdd2.Text = ds.Tables[0].Rows[0]["english_address2"].ToString();
        txtEngAdd3.Text = ds.Tables[0].Rows[0]["english_address3"].ToString();
        txtArabAdd1.Text = ds.Tables[0].Rows[0]["arabic_address1"].ToString();
        txtArabAdd2.Text = ds.Tables[0].Rows[0]["arabic_address2"].ToString();
        txtArabAdd3.Text = ds.Tables[0].Rows[0]["arabic_address3"].ToString();
        txtPostCode.Text = ds.Tables[0].Rows[0]["post_code"].ToString();
        ddlAddressCity.SelectedValue = ds.Tables[0].Rows[0]["city"].ToString();
        txtTelWork.Text = ds.Tables[0].Rows[0]["tel_work"].ToString();
        txtTelOther.Text = ds.Tables[0].Rows[0]["tel_other"].ToString();
        txtFax.Text = ds.Tables[0].Rows[0]["fax"].ToString();
        txtMobile.Text = ds.Tables[0].Rows[0]["mobile"].ToString();
        txtEmail.Text = ds.Tables[0].Rows[0]["email_address"].ToString();
        ddlAddressCat.SelectedValue = ds.Tables[0].Rows[0]["address_category"].ToString();
        pnlAddress.Visible = true;

        //load the old values
        txtContactnameOld.Text = ds.Tables[0].Rows[0]["contact_name_old"].ToString();
        if (txtContactnameOld.Text == txtContactname.Text)
            txtContactnameOld.Visible = false;
        else
            txtContactnameOld.Visible = true;

        txtPOBoxOld.Text = ds.Tables[0].Rows[0]["po_box_old"].ToString();
        if (txtPOBoxOld.Text == txtPOBox.Text)
            txtPOBoxOld.Visible = false;
        else
            txtPOBoxOld.Visible = true;

        txtEngAdd1Old.Text = ds.Tables[0].Rows[0]["english_address1_old"].ToString();
        if (txtEngAdd1Old.Text == txtEngAdd1.Text)
            txtEngAdd1Old.Visible = false;
        else
            txtEngAdd1Old.Visible = true;

        txtEngAdd2Old.Text = ds.Tables[0].Rows[0]["english_address2_old"].ToString();
        if (txtEngAdd2Old.Text == txtEngAdd2.Text)
            txtEngAdd2Old.Visible = false;
        else
            txtEngAdd2Old.Visible = true;

        txtEngAdd3Old.Text = ds.Tables[0].Rows[0]["english_address3_old"].ToString();
        if (txtEngAdd3Old.Text == txtEngAdd3.Text)
            txtEngAdd3Old.Visible = false;
        else
            txtEngAdd3Old.Visible = true;

        txtArabAdd1Old.Text = ds.Tables[0].Rows[0]["arabic_address1_old"].ToString();
        if (txtArabAdd1Old.Text == txtArabAdd1.Text)
            txtArabAdd1Old.Visible = false;
        else
            txtArabAdd1Old.Visible = true;

        txtArabAdd2Old.Text = ds.Tables[0].Rows[0]["arabic_address2_old"].ToString();
        if (txtArabAdd2Old.Text == txtArabAdd2.Text)
            txtArabAdd2Old.Visible = false;
        else
            txtArabAdd2Old.Visible = true;

        txtArabAdd3Old.Text = ds.Tables[0].Rows[0]["arabic_address3_old"].ToString();
        if (txtArabAdd3Old.Text == txtArabAdd3.Text)
            txtArabAdd3Old.Visible = false;
        else
            txtArabAdd3Old.Visible = true;



        txtPostCodeOld.Text = ds.Tables[0].Rows[0]["post_code_old"].ToString();
        if (txtPostCodeOld.Text == txtPostCode.Text)
            txtPostCodeOld.Visible = false;
        else
            txtPostCodeOld.Visible = true;

        txtTelWorkOld.Text = ds.Tables[0].Rows[0]["tel_work_old"].ToString();
        if (txtTelWorkOld.Text == txtTelWork.Text)
            txtTelWorkOld.Visible = false;
        else
            txtTelWorkOld.Visible = true;

        txtTelOtherOld.Text = ds.Tables[0].Rows[0]["tel_other_old"].ToString();
        if (txtTelOtherOld.Text == txtTelOther.Text)
            txtTelOtherOld.Visible = false;
        else
            txtTelOtherOld.Visible = true;

        txtFaxOld.Text = ds.Tables[0].Rows[0]["fax"].ToString();
        if (txtFaxOld.Text == txtFax.Text)
            txtFaxOld.Visible = false;
        else
            txtFaxOld.Visible = true;

        txtMobileOld.Text = ds.Tables[0].Rows[0]["mobile_old"].ToString();
        if (txtMobileOld.Text == txtMobile.Text)
            txtMobileOld.Visible = false;
        else
            txtMobileOld.Visible = true;

        txtEmailOld.Text = ds.Tables[0].Rows[0]["email_address_old"].ToString();
        if (txtEmailOld.Text == txtEmail.Text)
            txtEmailOld.Visible = false;
        else
            txtEmailOld.Visible = true;

        ddlAddressCityOld.SelectedValue = ds.Tables[0].Rows[0]["city_old"].ToString();
        if (ddlAddressCityOld.SelectedIndex == ddlAddressCity.SelectedIndex)
            ddlAddressCityOld.Visible = false;
        else
            ddlAddressCityOld.Visible = true;

        ddlAddressCatOld.SelectedValue = ds.Tables[0].Rows[0]["address_category_old"].ToString();
        if (ddlAddressCatOld.SelectedIndex == ddlAddressCat.SelectedIndex)
            ddlAddressCatOld.Visible = false;
        else
            ddlAddressCatOld.Visible = true;
    }

    private bool deleteAddress(string addressID, 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 = "MER_ADDRESS_EDITOR.Delete_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_ma_code", OracleType.Number).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["p_ma_code"].Value = addressID;
        oracom.Parameters["p_client_no"].Value = Request.QueryString["clID"];

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

        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;
    }

    protected void gvAddresses_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("u"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvAddresses.DataKeys[index].Value.ToString();
            loadAddressByID(rowID);
            ViewState["mode"] = "u";
            ViewState["rowid"] = rowID;
        }
        if (e.CommandName.Equals("h"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvAddresses.DataKeys[index].Value.ToString();
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=106&p1=" + rowID + "','Report')", true);
        }
        else if (e.CommandName.Equals("d"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvAddresses.DataKeys[index].Value.ToString();
            string error = "";
            bool saved = deleteAddress(rowID, ref error);
            if (saved)
            {
                lblError.Text = "Address deleted";
            }
            else
            {
                lblError.Text = error;
            }
            loadMerchantAddresses(Request.QueryString["clID"], Helper.gridSize(), 1);
        }
    }

    protected void gvAddresses_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // searching through the rows
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int rec = int.Parse(DataBinder.Eval(e.Row.DataItem, "rec_flag").ToString());
            int status = int.Parse(DataBinder.Eval(e.Row.DataItem, "status").ToString());
            if (rec == 1) 
                if(status == 1)
                    e.Row.BackColor = Color.Tan; // is a "new" row
                else
                    e.Row.BackColor = Color.SkyBlue; // is a "new" row
        }
    }

    protected void gvAddresses_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[7].Visible = false;
            e.Row.Cells[8].Visible = false;
        }
    }

    //****************************************    Services   ****************************************\\

    protected void btnAddServices_Click(object sender, EventArgs e)
    {
        pnlServices.Visible = true;
        ViewState["mode"] = "a";
        txtAccNo.Text = txtAccNoGeneral.Text;
        txtPercentB.Text = "0";
        lblPercent.Text = txtPercentM.Text;
        if (ddlServices.SelectedValue == "001")
        {
            txtPercentM.Text = "0";
            lblPercent.Text = txtPercentM.Text;
        }
        else
            txtPercentM.Text = ViewState["cat_com"].ToString();
        lblPercent.Text = txtPercentM.Text;
        ddlServices.Enabled = true;

        //hide the old version
        ddlCurrancyOld.Visible = false;
        txtPercentMOld.Visible = false;
        txtPercentBOld.Visible = false;
        txtAccNoOld.Visible = false;
        chkKeyEntryOld.Visible = false;

    }

    protected void ddlServices_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlServices.SelectedValue == "001")
        {
            txtPercentM.Text = "0";
          lblPercent.Text = txtPercentM.Text;
        }
        else
            txtPercentM.Text = ViewState["cat_com"].ToString();
        lblPercent.Text = txtPercentM.Text;
    }

    protected void btnCancelService_Click(object sender, EventArgs e)
    {
        pnlServices.Visible = false;
        ViewState["mode"] = null;
    }

    protected void btnSaveService_Click(object sender, EventArgs e)
    {
        try
        {
            string mode = ViewState["mode"].ToString();
            string error = "";
            if (mode.Equals("a"))
            {
                string clID = Request.QueryString["clID"];
                bool saved = addService(clID, ref error);
                if (saved)
                {
                    lblError.Text = "Service data Saved";
                }
                else
                {
                    lblError.Text = error;
                }
            }
            else if (mode.Equals("u"))
            {
                string Uid = ViewState["rowid"].ToString();
                bool saved = updateService(Uid, ref error);
                if (saved)
                {
                    lblError.Text = "Service data Saved";
                }
                else
                {
                    lblError.Text = error;
                }
            }
            loadMerchantServices(Request.QueryString["clID"], Helper.gridSize(), 1);
            ViewState["mode"] = null;
            ViewState["rowid"] = null;
            pnlServices.Visible = false;
        }
        catch (Exception ex)
        {
        }
    }

    private bool addService(string clientNo, 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_service.add_merchant_appl_service";

        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_service_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fees_percent", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_base", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_curr", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_rule", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_bank_fee_percent", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_acct_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_key_entry", OracleType.Number).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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_client_no"].Value = clientNo;

        oracom.Parameters["p_service_id"].Value = ddlServices.SelectedValue;
        oracom.Parameters["p_fees_percent"].Value = txtPercentM.Text;
        oracom.Parameters["p_bank_fee_percent"].Value = txtPercentB.Text;
        oracom.Parameters["p_fee_base"].Value = "1";
        oracom.Parameters["p_fee_curr"].Value = ddlCurrancy.SelectedValue;//txtCurrancy.Text;
        oracom.Parameters["p_fee_rule"].Value = "1";
        oracom.Parameters["p_acct_number"].Value = txtAccNo.Text;
        if (chkKeyEntry.Checked)
            oracom.Parameters["p_key_entry"].Value = "1";
        else
            oracom.Parameters["p_key_entry"].Value = "0";


        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 updateService(string serviceID, 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_service.update_appl_service";

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

        oracom.Parameters.Add("p_as_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_percent", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_bank_fee_percent", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_base", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_curr", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_rule", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_acct_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_key_entry", OracleType.Number).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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_as_code"].Value = serviceID;
        oracom.Parameters["p_fee_percent"].Value = txtPercentM.Text;
        oracom.Parameters["p_bank_fee_percent"].Value = txtPercentB.Text;
        oracom.Parameters["p_fee_base"].Value = "1";
        oracom.Parameters["p_fee_curr"].Value = ddlCurrancy.SelectedValue;//txtCurrancy.Text;
        oracom.Parameters["p_fee_rule"].Value = "1";
        oracom.Parameters["p_acct_number"].Value = txtAccNo.Text;
        if (chkKeyEntry.Checked)
            oracom.Parameters["p_key_entry"].Value = "1";
        else
            oracom.Parameters["p_key_entry"].Value = "0";

        oracom.ExecuteNonQuery();
        oracon.Close();
        ddlServices.Enabled = false;
        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 void loadServiceByID(string serviceID)
    {
        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_service.get_appl_serv_by_id";

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

        oracom.Parameters["p_as_code"].Value = serviceID;

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

        oracon.Close();

        //set the data in the controls
        ddlServices.SelectedValue = ds.Tables[0].Rows[0]["service_id"].ToString();
        txtPercentM.Text = ds.Tables[0].Rows[0]["fee_percent"].ToString();
        txtPercentB.Text = ds.Tables[0].Rows[0]["bank_fee_percent"].ToString();
        lblPercent.Text = ds.Tables[0].Rows[0]["def_fee_percent"].ToString();
        ddlCurrancy.SelectedValue = ds.Tables[0].Rows[0]["fee_curr"].ToString();
        txtAccNo.Text = ds.Tables[0].Rows[0]["acct_number"].ToString();
        if (ds.Tables[0].Rows[0]["key_entry_service"].ToString().Equals("1"))
            chkKeyEntry.Checked = true;
        pnlServices.Visible = true;

        //load the old version
        ddlCurrancyOld.SelectedValue = ds.Tables[0].Rows[0]["fee_curr_old"].ToString();
        if (ddlCurrancy.SelectedIndex == ddlCurrancyOld.SelectedIndex)
            ddlCurrancyOld.Visible = false;
        else
            ddlCurrancyOld.Visible = true;

        txtPercentMOld.Text = ds.Tables[0].Rows[0]["fee_percent_old"].ToString();
        if (txtPercentMOld.Text == txtPercentM.Text)
            txtPercentMOld.Visible = false;
        else
            txtPercentMOld.Visible = true;

        txtPercentBOld.Text = ds.Tables[0].Rows[0]["bank_fee_percent_old"].ToString();
        if (txtPercentBOld.Text == txtPercentB.Text)
            txtPercentBOld.Visible = false;
        else
            txtPercentBOld.Visible = true;

        txtAccNoOld.Text = ds.Tables[0].Rows[0]["acct_number_old"].ToString();
        if (txtAccNoOld.Text == txtAccNo.Text)
            txtAccNoOld.Visible = false;
        else
            txtAccNoOld.Visible = true;

        if (ds.Tables[0].Rows[0]["key_entry_service_old"].ToString().Equals("1"))
            chkKeyEntryOld.Checked = true;

        if (ds.Tables[0].Rows[0]["key_entry_service_old"].ToString() == ds.Tables[0].Rows[0]["key_entry_service"].ToString())
            chkKeyEntryOld.Visible = false;
        else
            chkKeyEntryOld.Visible = true;
    }

    protected void gvServices_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("u"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvServices.DataKeys[index].Value.ToString();
            loadServiceByID(rowID);
            ViewState["mode"] = "u";
            ViewState["rowid"] = rowID;
            ddlServices.Enabled = false;
        }
        if (e.CommandName.Equals("h"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvServices.DataKeys[index].Value.ToString();
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=107&p1=" + rowID + "','Report')", true);
        }
        else if (e.CommandName.Equals("d"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvServices.DataKeys[index].Value.ToString();
            string error = "";
            bool saved = deleteService(rowID, ref error);
            if (saved)
            {
                lblError.Text = "Service disabled";
            }
            else
            {
                lblError.Text = error;
            }
            loadMerchantServices(Request.QueryString["clID"], Helper.gridSize(), 1);
        }
    }

    private bool deleteService(string serviceID, 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_service.Disable_appl_service";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_as_code", OracleType.Number).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["p_as_code"].Value = serviceID;

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

        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;
    }

    protected void gvServices_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // searching through the rows
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int rec = int.Parse(DataBinder.Eval(e.Row.DataItem, "rec_flag").ToString());
            int status = int.Parse(DataBinder.Eval(e.Row.DataItem, "status").ToString());
            if (rec == 1)
                if (status == 1)
                    e.Row.BackColor = Color.Tan; // is a "new" row
                else
                    e.Row.BackColor = Color.SkyBlue; // is a "new" row
        }
    }

    protected void gvServices_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[9].Visible = false;
            e.Row.Cells[10].Visible = false;
        }
    }

    //****************************************    Terminals   ****************************************\\

    protected void btnAddTerminal_Click(object sender, EventArgs e)
    {
        pnlTerminals.Visible = true;
        ViewState["mode"] = "a";

        firstrow.Visible = true;
        //dateInstallation.date = getDayofMonth(DateTime.Now.Day);
        //dateSamaConfirm.date  = getDayofMonth(DateTime.Now.Day);

        ddlStatus.SelectedValue = "001";
        loadTerminals();
        rowVendor.Visible = false;

            txtTerminalLocationOld.Visible = false;
            txtPrimHostAccOld.Visible = false;
            txtAltHostAccOld.Visible = false;
            txtPrimPhoneNoOld.Visible = false;
            txtReplacementTerminalOld.Visible = false;
            DropDownList1Old.Visible = false;
    }

    protected void btnCancelTerminal_Click(object sender, EventArgs e)
    {
        pnlTerminals.Visible = false;
        ViewState["mode"] = null;
    }

    protected void btnSaveTerminal_Click(object sender, EventArgs e)
    {
        try
        {
            string mode = ViewState["mode"].ToString();
            string error = "";
            if (mode.Equals("a"))
            {
                if (ddlTerminals.Items.Count > 0)
                {
                    string clID = Request.QueryString["clID"];
                    bool saved = addTerminal(clID, ref error);
                    if (saved)
                    {
                        lblError.Text = "Terminal data Saved";
                    }
                    else
                    {
                        lblError.Text = error;
                    }
                }
                else
                    lblError.Text = "No Terminals Available Now";
            }
            else if (mode.Equals("u"))
            {
                string Uid = ViewState["rowid"].ToString();
                bool saved = updateTerminal(Uid, ref error);
                if (saved)
                {
                    lblError.Text = "Service data Saved";
                }
                else
                {
                    lblError.Text = error;
                }
            }
            loadMerchantTerminals(Request.QueryString["clID"], Helper.gridSize(), 1);
            ViewState["mode"] = null;
            ViewState["rowid"] = null;
            pnlTerminals.Visible = false;
        }
        catch (Exception ex)
        {
        }
    }

    private bool addTerminal(string clientNo, 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 = "MER_DEVICE_LINK_EDITOR.Add_Client_Device_Link";

        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_terminal_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_installed_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_sama_confirm_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_region", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_language", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_terminal_location", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_primary_host_access", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_alternative_host_access", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_primary_phone_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_rental_amount", OracleType.Number).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_tfr_code", OracleType.Number).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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_client_no"].Value = clientNo;

        oracom.Parameters["p_terminal_id"].Value = ddlTerminals.SelectedValue;
        //oracom.Parameters["p_installed_date"].Value = OracleString.Null;//dateInstallation.date;
        //oracom.Parameters["p_sama_confirm_date"].Value = dateSamaConfirm.date;
        oracom.Parameters["p_region"].Value = ddlRegion.SelectedValue;
        oracom.Parameters["p_language"].Value = DropDownList1.SelectedValue;
        oracom.Parameters["p_terminal_location"].Value = txtTerminalLocation.Text;
        oracom.Parameters["p_primary_host_access"].Value = txtPrimHostAcc.Text;
        oracom.Parameters["p_alternative_host_access"].Value = txtAltHostAcc.Text;
        oracom.Parameters["p_primary_phone_number"].Value = txtPrimPhoneNo.Text;

        //oracom.Parameters["p_tfr_code"].Value = OracleNumber.Null;
        //oracom.Parameters["p_rental_amount"].Value = OracleNumber.Null;




        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 updateTerminal(string terminalID, 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 = "MER_DEVICE_LINK_EDITOR.Update_Client_Device_Link";

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

        oracom.Parameters.Add("p_dvl_code", OracleType.Number).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_installed_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_sama_confirm_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_language", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_terminal_location", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_primary_host_access", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_alternative_host_access", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_primary_phone_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_tfr_code", OracleType.Number).Direction = ParameterDirection.Input;
        //oracom.Parameters.Add("p_rental_amount", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_replace_term_id", 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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_dvl_code"].Value = terminalID;

        //oracom.Parameters["p_installed_date"].Value = OracleString.Null;//dateInstallation.date;
        //oracom.Parameters["p_sama_confirm_date"].Value = dateSamaConfirm.date;
        oracom.Parameters["p_language"].Value = DropDownList1.SelectedValue;
        oracom.Parameters["p_terminal_location"].Value = txtTerminalLocation.Text;
        oracom.Parameters["p_primary_host_access"].Value = txtPrimHostAcc.Text;
        oracom.Parameters["p_alternative_host_access"].Value = txtAltHostAcc.Text;
        oracom.Parameters["p_primary_phone_number"].Value = txtPrimPhoneNo.Text;
        oracom.Parameters["p_replace_term_id"].Value = txtReplacementTerminal.Text;

        //oracom.Parameters["p_tfr_code"].Value = OracleNumber.Null;
        //oracom.Parameters["p_rental_amount"].Value = OracleNumber.Null;
    

        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 void loadTerminalByID(string terminalID)
    {
        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_DEVICE_LINK_EDITOR.get_device_link_by_id";

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

        oracom.Parameters["p_dvl_code"].Value = terminalID;

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

        oracon.Close();

        //set the data in the controls
        //ddlTerminals.SelectedValue = ds.Tables[0].Rows[0]["service_id"].ToString();
        lblInstall.Text = ds.Tables[0].Rows[0]["installed_date"].ToString();
        dateSamaConfirm.date = ds.Tables[0].Rows[0]["sama_confirm_date"].ToString();
        txtTerminalIdentityData.Text = ds.Tables[0].Rows[0]["terminal_identity_data"].ToString();
        DropDownList1.SelectedValue = ds.Tables[0].Rows[0]["LANGUAGE"].ToString();
        txtTerminalLocation.Text = ds.Tables[0].Rows[0]["terminal_location"].ToString();
        txtPrimHostAcc.Text = ds.Tables[0].Rows[0]["primary_host_access"].ToString();
        txtAltHostAcc.Text = ds.Tables[0].Rows[0]["alternative_host_access"].ToString();
        txtPrimPhoneNo.Text = ds.Tables[0].Rows[0]["primary_phone_number"].ToString();
        ddlStatus.SelectedValue = ds.Tables[0].Rows[0]["status"].ToString();
        txtoldClientID.Text = ds.Tables[0].Rows[0]["old_client_number"].ToString();
        txtReplacementTerminal.Text = ds.Tables[0].Rows[0]["replacement_term_id"].ToString();
        txtNotifyDate.Text = ds.Tables[0].Rows[0]["vndr_notif_dt"].ToString();
        txtResponseDate.Text = ds.Tables[0].Rows[0]["vndr_resp_dt"].ToString();
        rowVendor.Visible = true;
        oldclientrow.Visible = true;
        pnlTerminals.Visible = true;

        //load the old values

        txtTerminalLocationOld.Text = ds.Tables[0].Rows[0]["terminal_location_old"].ToString();
        if (txtTerminalLocationOld.Text == txtTerminalLocation.Text)
            txtTerminalLocationOld.Visible = false;
        else
            txtTerminalLocationOld.Visible = true;

        txtPrimHostAccOld.Text = ds.Tables[0].Rows[0]["primary_host_access_old"].ToString();
        if (txtPrimHostAccOld.Text == txtPrimHostAcc.Text)
            txtPrimHostAccOld.Visible = false;
        else
            txtPrimHostAccOld.Visible = true;

        txtAltHostAccOld.Text = ds.Tables[0].Rows[0]["alternative_host_access_old"].ToString();
        if (txtAltHostAccOld.Text == txtAltHostAcc.Text)
            txtAltHostAccOld.Visible = false;
        else
            txtAltHostAccOld.Visible = true;

        txtPrimPhoneNoOld.Text = ds.Tables[0].Rows[0]["primary_phone_number_old"].ToString();
        if (txtPrimPhoneNoOld.Text == txtPrimPhoneNo.Text)
            txtPrimPhoneNoOld.Visible = false;
        else
            txtPrimPhoneNoOld.Visible = true;

        txtReplacementTerminalOld.Text = ds.Tables[0].Rows[0]["replacement_term_id_old"].ToString();
        if (txtReplacementTerminalOld.Text == txtReplacementTerminal.Text)
            txtReplacementTerminalOld.Visible = false;
        else
            txtReplacementTerminalOld.Visible = true;

        DropDownList1Old.SelectedValue = ds.Tables[0].Rows[0]["LANGUAGE_old"].ToString();
        if (DropDownList1Old.SelectedIndex == DropDownList1.SelectedIndex)
            DropDownList1Old.Visible = false;
        else
            DropDownList1Old.Visible = true;
    }

    protected void gvTerminals_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("u"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();
            loadTerminalByID(rowID);
            ViewState["mode"] = "u";
            ViewState["rowid"] = rowID;

            firstrow.Visible = false;
        }
        if (e.CommandName.Equals("h"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=108&p1=" + rowID + "','Report')", true);
        }
        else if (e.CommandName.Equals("d"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();

            ViewState["rowid"] = rowID;
            pnlCancel.Visible = true;
            //string error = "";
            
        }
        else if (e.CommandName.Equals("r"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();

            string error = "";
            bool saved = reset(rowID, ref error);
            if (saved)
            {
                lblError.Text = "reset ok";
                loadMerchantTerminals(Request.QueryString["clID"], Helper.gridSize(), 1);
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + Request.QueryString["clID"] + "&action=reset ','MerchantComment','status=1,width=700,height=250')", true);
            }
            else
            {
                lblError.Text = error;
            }
        }
        else if (e.CommandName.Equals("asama"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();

            string error = "";
            bool saved = ApproveSama(rowID, ref error);
            if (saved)
            {
                lblError.Text = "Sama Approved";
                loadMerchantTerminals(Request.QueryString["clID"], Helper.gridSize(), 1);
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + Request.QueryString["clID"] + "&action=Sama Approved Terminal','MerchantComment','status=1,width=700,height=250')", true);
            }
            else
            {
                lblError.Text = error;
            }
        }
        else if (e.CommandName.Equals("dsama"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();

            string error = "";
            bool saved = DeclineSama(rowID, ref error);
            if (saved)
            {
                lblError.Text = "Sama Declined";
                loadMerchantTerminals(Request.QueryString["clID"], Helper.gridSize(), 1);
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + Request.QueryString["clID"] + "&action=Sama Rejected Terminal','MerchantComment','status=1,width=700,height=250')", true);
            }
            else
            {
                lblError.Text = error;
            }
        }
        else if (e.CommandName.Equals("asup"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();
            ViewState["rowid"] = rowID;
            pnlVendor.Visible = true;
        }
        else if (e.CommandName.Equals("dsup"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();

            string error = "";
            bool saved = DeclineSupport(rowID, ref error);
            if (saved)
            {
                lblError.Text = "Support Declined";
                loadMerchantTerminals(Request.QueryString["clID"], Helper.gridSize(), 1);
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + Request.QueryString["clID"] + "&action=Support Rejected Terminal','MerchantComment','status=1,width=700,height=250')", true);
            }
            else
            {
                lblError.Text = error;
            }
        }
        else if (e.CommandName.Equals("v"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();
            loadTerminalCharges(rowID);
            ViewState["rowid"] = rowID;
        }
        else if (e.CommandName.Equals("t"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = gvTerminals.DataKeys[index].Value.ToString();
            ViewState["rowid"] = rowID;
            pnlTransfer.Visible = true;
        }
    }

    protected void gvTerminals_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[15].Visible = false;
            e.Row.Cells[16].Visible = false;
        }
    }

    private bool ApproveSama(string index, 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 = "MER_DEVICE_LINK_EDITOR.approve_sama";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dvl_code", OracleType.Number).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["p_dvl_code"].Value = index;

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

        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 reset(string index, 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 = "MER_DEVICE_LINK_EDITOR.reset_client_device_link";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dvl_code", OracleType.Number).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["p_dvl_code"].Value = index;

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

        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 DeclineSama(string index, 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 = "MER_DEVICE_LINK_EDITOR.decline_sama";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dvl_code", OracleType.Number).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["p_dvl_code"].Value = index;

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

        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 ApproveSupport(string index, 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 = "MER_DEVICE_LINK_EDITOR.approve_support";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dvl_code", OracleType.Number).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["p_dvl_code"].Value = index;

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

        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 DeclineSupport(string index, 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 = "MER_DEVICE_LINK_EDITOR.decline_support";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dvl_code", OracleType.Number).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["p_dvl_code"].Value = index;

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

        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 cancelTerminal(string index, 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 = "MER_DEVICE_LINK_EDITOR.Cancel_Client_Device_Link";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dvl_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_replace_term", 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["p_dvl_code"].Value = index;
        oracom.Parameters["p_replace_term"].Value = txtNewTerminalID.Text;

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

        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 void loadTerminalCharges(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 = "MER_DEVICE_LINK_EDITOR.Display_Term_Charges";

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

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

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

        oracon.Close();

        gvTerminalCharges.DataSource = ds.Tables[0];
        gvTerminalCharges.DataBind();
        pnlChanrges.Visible = true;
    }

    protected void btnCancelTerminalCharge_Click(object sender, EventArgs e)
    {
        pnlChanrges.Visible = false;
        ViewState["mode"] = null;
    }

    protected void btnSaveTerminalCharge_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = ViewState["rowid"].ToString();
        bool saved = addTerminalCharge(clID, ref error);
        if (saved)
        {
            lblError.Text = "Terminal Charge Saved";
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + Request.QueryString["clID"] + "&action=Terminal Charge Added','MerchantComment','status=1,width=700,height=250')", true);
        }
        else
        {
            lblError.Text = error;
        }
        loadTerminalCharges(clID);
    }

    private bool addTerminalCharge(string terID, 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 = "MER_DEVICE_LINK_EDITOR.Add_Term_Charge";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dvl_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_chg_amt", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_chg_reason", OracleType.Number).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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_dvl_code"].Value = terID;

        oracom.Parameters["p_chg_amt"].Value = txtChargeAmount.Text;
        oracom.Parameters["p_chg_reason"].Value = ddlReason.SelectedValue;

        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;
    }

    protected void btnCancelTransfer_Click(object sender, EventArgs e)
    {
        pnlTransfer.Visible = false;
        ViewState["mode"] = null;
    }

    protected void btnSaveTransfer_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = ViewState["rowid"].ToString();
        bool saved = transferTerminal(clID, ref error);
        if (saved)
        {
            lblError.Text = "Terminal Transfer is submitted to Supervisor for approval.";
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + Request.QueryString["clID"] + "&action=Transfering Terminal','MerchantComment','status=1,width=700,height=250')", true);
        }
        else
        {
            lblError.Text = error;
        }
        pnlTransfer.Visible = false;
    }

    private bool transferTerminal(string terID, 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 = "MER_DEVICE_LINK_EDITOR.Transfer_Client_Device_Link";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_dvl_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_new_retailed_id", 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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_dvl_code"].Value = terID;

        oracom.Parameters["p_new_retailed_id"].Value = txtNewClientNo.Text;

        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;
    }

    protected void btnCancelReplace_Click(object sender, EventArgs e)
    {
        pnlCancel.Visible = false;
        ViewState["mode"] = null;
    }

    protected void btnSaveReplace_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = ViewState["rowid"].ToString();
        bool saved = cancelTerminal(clID, ref error);
        if (saved)
        {
            lblError.Text = "Terminal Canceled";
            loadMerchantTerminals(Request.QueryString["clID"], Helper.gridSize(), 1);
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
               "window.open('Comment.aspx?clID=" + Request.QueryString["clID"] + "&action=Cancel Terminal','MerchantComment','status=1,width=700,height=250')", true);
        }
        else
        {
            lblError.Text = error;
        }
        pnlCancel.Visible = false;
    }

    protected void btnSaveResponse_Click(object sender, EventArgs e)
    {
        string error = "", ID = "";
        ID = ViewState["rowid"].ToString();
        bool saved = UpdateVendorResponse(ID, ref error);
        if (saved)
        {
            lblError.Text = "Data saved";
            loadMerchantTerminals(Request.QueryString["clID"], Helper.gridSize(), 1);
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
               "window.open('Comment.aspx?clID=" + Request.QueryString["clID"] + "&action=Support Approved Terminal','MerchantComment','status=1,width=700,height=250')", true);
        }
        else
        {
            lblError.Text = error;
        }
        pnlVendor.Visible = false;
    }

    protected void btnCancelResponse_Click(object sender, EventArgs e)
    {
        pnlVendor.Visible = false;
    }

    private bool UpdateVendorResponse(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 = "DEVICE_VENDOR_NOTIFIER.Update_vendor_response";

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

        oracom.Parameters.Add("p_dvl_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_time", 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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_dvl_code"].Value = ID;
        oracom.Parameters["p_date"].Value = dateVendorResponse.date;
        oracom.Parameters["p_time"].Value = txtTimeResponse.Text;

        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;
    }
    
    protected void gvTerminals_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // searching through the rows
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int rec = int.Parse(DataBinder.Eval(e.Row.DataItem, "rec_flag").ToString());
            string status = DataBinder.Eval(e.Row.DataItem, "status").ToString();
            if (rec == 1 && status == "001")
                    e.Row.BackColor = Color.Tan; // is a "new" row
        }
    }
    
    //***************************************   Submit   ********************************************\\

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string error = "";
        string clID = Request.QueryString["clID"];
        bool saved = submit(clID, ref error);
        if (saved)
        {
            lblError.Text = "Merchant Submitted";
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('Comment.aspx?clID=" + clID + "&action=Submit Merchant','MerchantComment','status=1,width=700,height=250')", true);
        }
        else
        {
            lblError.Text = error;
        }
    }

    private bool submit(string clientNo, 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.Validate_Mer_Submit";

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

        oracom.Parameters.Add("p_client_number", 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["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

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

        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 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;
    }

    protected void btnDuplicate_Click(object sender, EventArgs e)
    {
        pnlDuplicate.Visible = true;
    }

    protected void btnSaveDuplicate_Click(object sender, EventArgs e)
    {
        if (txtNewAcctNo.Text.Length > 0)
        {
            string error = "", newCID = "";
            string clID = Request.QueryString["clID"];
            bool saved = duplicate(clID, ref newCID, ref error);
            if (saved)
            {
                lblError.Text = "Merchant Submitted";
                Response.Redirect("updateMerchant.aspx?clID=" + newCID);
            }
            else
            {
                lblError.Text = error;
            }
        }
        else
            lblError.Text = "You have to enter the new Account No";
    }

    protected void btnCancelDuplicate_Click(object sender, EventArgs e)
    {
        pnlDuplicate.Visible = false;
    }

    private bool duplicate(string clientNo,ref string cID, 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.Duplicate_Merchant";

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

        oracom.Parameters.Add("p_client_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_new_acct_no", 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_new_client_no", 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_number"].Value = clientNo;
        oracom.Parameters["p_new_acct_no"].Value   = txtNewAcctNo.Text;

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

    protected void btnHistory_Click(object sender, EventArgs e)
    {
        string clID = Request.QueryString["clID"];
        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=105&p1=" + clID + "','Report')", true);
    }

    protected void btnAccHistory_Click(object sender, EventArgs e)
    {
        string clID = Request.QueryString["clID"];
        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=109&p1=" + clID + "','Report')", true);
    }

    protected void gvTerminals_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    
}
