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;

public partial class Business_GLS1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SecurityAgent.AuthenticateArchive();
            loadChannels();
            loadEvents();
            loadTables();
        }
    }

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "LOOKUP_GETTER.Get_Bus_Rules_Tables";

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

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

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

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

        oracon.Close();
    }

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "LOOKUP_GETTER.Get_Master_File_Names";

        oracom.Parameters.Add("p_master_table", OracleType.VarChar, 250).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_files", OracleType.Cursor).Direction = ParameterDirection.Output;

        oracom.Parameters["p_master_table"].Value = ddlMaster.SelectedValue;
        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

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

        oracon.Close();
    }

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "LOOKUP_GETTER.Get_Recon_Channels";

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

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

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

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

        ddlChannels.Items.Insert(0, "------ Channels ------");
        
        //To Remove The Finacle Channle
        //ddlChannels.Items.RemoveAt(1);
        oracon.Close();
    }

    private void loadEvents()
    {
        ddlEvents.Items.Clear();
        if (ddlChannels.SelectedIndex > 0)
        {
            string DBConnection = Helper.dbConnection();

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

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

            oracom.CommandType = CommandType.StoredProcedure;
            oracom.CommandText = "LOOKUP_GETTER.Get_Recon_Channel_Events";

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

            oracom.Parameters["p_rc_code"].Value = ddlChannels.SelectedValue;

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

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

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

            
            oracon.Close();
        }
        ddlEvents.Items.Insert(0, "------ Events ------");
    }

    private void loadResult(string channelID, string eventID, 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 = "BUSINESS_RULES_EDITOR.Get_Business_Rules";

        oracom.Parameters.Add("p_current_uid", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rc_code", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_re_code", 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;

        if (channelID.Length != 0)
            oracom.Parameters["p_rc_code"].Value = channelID;
        else
            oracom.Parameters["p_rc_code"].Value = OracleNumber.Null;
        if (eventID.Length != 0)
            oracom.Parameters["p_re_code"].Value = eventID;
        else
            oracom.Parameters["p_re_code"].Value = OracleNumber.Null;

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

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

    protected void Button1_Click(object sender, EventArgs e)
    {
        string channelID = "", EventID = "";
        if (ddlChannels.SelectedIndex > 0)
            channelID = ddlChannels.SelectedValue;
        if (ddlEvents.SelectedIndex > 0)
            EventID = ddlEvents.SelectedValue;
        pnlResult.Visible = true;
        pnlBR.Visible = false;
        loadResult(channelID, EventID, Helper.gridSize(), 1);
    }

    protected void ddlPages_SelectedIndexChanged(object sender, EventArgs e)
    {
        string channelID = "", EventID = "";
        if (ddlChannels.SelectedIndex > 0)
            channelID = ddlChannels.SelectedValue;
        if (ddlEvents.SelectedIndex > 0)
            EventID = ddlEvents.SelectedValue;
        pnlBR.Visible = false;
        loadResult(channelID, EventID, Helper.gridSize(), int.Parse(ddlPages.SelectedValue));
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("e"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            pnlBR.Visible = true;
            pnlBR.Enabled = true;
            loadBR(rowID);
            ViewState["rowid"] = rowID;
            ViewState["mode"] = "u";
            addrow.Visible = false;
        }
        else if (e.CommandName.Equals("v"))
        {
            int index = int.Parse(e.CommandArgument.ToString());
            string rowID = GridView1.DataKeys[index].Value.ToString();
            pnlBR.Visible = true;
            pnlBR.Enabled = false;
            loadBR(rowID);
            addrow.Visible = false;
        }
    }

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "BUSINESS_RULES_EDITOR.Get_Rule_Details";

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

        oracom.Parameters["p_br_code"].Value = rowID;

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

        lblRecordDate.Text = ds.Tables[0].Rows[0]["record_date"].ToString();

        txtcos.Text = ds.Tables[0].Rows[0]["cut_off_start"].ToString();
        txtcoe.Text = ds.Tables[0].Rows[0]["cut_off_end"].ToString();

        int intChecked = int.Parse(ds.Tables[0].Rows[0]["cut_off_rule"].ToString());
        if (intChecked == 1)
            CheckBox1.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_date"].ToString());
        if (intChecked == 1)
            CheckBox2.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_time"].ToString());
        if (intChecked == 1)
            CheckBox3.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["card_number"].ToString());
        if (intChecked == 1)
            CheckBox4.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["rrn"].ToString());
        if (intChecked == 1)
            CheckBox5.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["trace_id"].ToString());
        if (intChecked == 1)
            CheckBox6.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["local_date"].ToString());
        if (intChecked == 1)
            CheckBox7.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["local_time"].ToString());
        if (intChecked == 1)
            CheckBox8.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["currency"].ToString());
        if (intChecked == 1)
            CheckBox9.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_amount"].ToString());
        if (intChecked == 1)
            CheckBox10.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["settlement_amount"].ToString());
        if (intChecked == 1)
            CheckBox11.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["fee_amount"].ToString());
        if (intChecked == 1)
            CheckBox12.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["auth_code"].ToString());
        if (intChecked == 1)
            CheckBox13.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["message_type"].ToString());
        if (intChecked == 1)
            CheckBox14.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_source"].ToString());
        if (intChecked == 1)
            CheckBox15.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["tran_destination"].ToString());
        if (intChecked == 1)
            CheckBox16.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["term_id"].ToString());
        if (intChecked == 1)
            CheckBox17.Checked = true;

        intChecked = int.Parse(ds.Tables[0].Rows[0]["acct_number"].ToString());
        if (intChecked == 1)
            CheckBox19.Checked = true;

        ddlMaster.SelectedValue = ds.Tables[0].Rows[0]["master_table"].ToString();
        ddlSlave.SelectedValue = ds.Tables[0].Rows[0]["slave_table"].ToString();

        txtBefore.Text = ds.Tables[0].Rows[0]["days_before"].ToString();
        txtAfter.Text = ds.Tables[0].Rows[0]["days_after"].ToString();

        loadFileNames();
        ddlFileName.SelectedValue = ds.Tables[0].Rows[0]["FILE_NAME"].ToString();
        //ddlFileName.SelectedItem .Text  = ds.Tables[0].Rows[0]["FILE_NAME"].ToString();

        intChecked = int.Parse(ds.Tables[0].Rows[0]["active"].ToString());
        if (intChecked == 1)
            CheckBox18.Checked = true;
    }
    
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        pnlBR.Visible = false;
        pnlResult.Enabled = true;
    }
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string mode = ViewState["mode"].ToString();
        string error = "";

        if (mode.Equals("a"))
        {
            bool saved = addBR(ref error);
            if (saved)
            {
                lblError.ForeColor = System.Drawing.Color.DarkGreen;
                lblError.Text = "Business Rule saved";
            }
            else
            {
                lblError.Text = error;
            }
        }
        else if (mode.Equals("u"))
        {
            string rowID = ViewState["rowid"].ToString();
            bool saved = saveBR(rowID, ref error);
            if (saved)
            {
                lblError.ForeColor = System.Drawing.Color.DarkGreen;
                lblError.Text = "Business Rule saved";
            }
            else
            {
                lblError.Text = error;
            }
        }

        //loading the grid again
        string channelID = "", EventID = "";
        if (ddlChannels.SelectedIndex > 0)
            channelID = ddlChannels.SelectedValue;
        if (ddlEvents.SelectedIndex > 0)
            EventID = ddlEvents.SelectedValue;
        pnlResult.Visible = true;
        pnlResult.Enabled = true;
        pnlBR.Visible = false;
        loadResult(channelID, EventID, Helper.gridSize(), 1);


    }

    private bool saveBR(string rowID, 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 = "BUSINESS_RULES_EDITOR.Update_Business_Rules";

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

        oracom.Parameters.Add("p_cut_off_start", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cut_off_end", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cut_off_rule", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_card_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_trace_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_local_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_local_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_currency", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_settlement_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_auth_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_message_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_source", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_destination", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_master_table", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_slave_table", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_acct_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_days_before", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_days_after", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_file_name", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_active", 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_br_code"].Value = rowID;
        oracom.Parameters["p_lang"].Value = "EN";
        oracom.Parameters["p_current_uid"].Value = Session["uid"].ToString();

        oracom.Parameters["p_cut_off_start"].Value = txtcos.Text.Replace(":","");
        oracom.Parameters["p_cut_off_end"].Value = txtcoe.Text.Replace(":", "");
        oracom.Parameters["p_cut_off_rule"].Value = CheckBox1.Checked?"1":"0";
        oracom.Parameters["p_tran_date"].Value = CheckBox2.Checked?"1":"0";
        oracom.Parameters["p_tran_time"].Value = CheckBox3.Checked?"1":"0";
        oracom.Parameters["p_card_number"].Value = CheckBox4.Checked?"1":"0";
        oracom.Parameters["p_rrn"].Value = CheckBox5.Checked?"1":"0";
        oracom.Parameters["p_trace_id"].Value = CheckBox6.Checked?"1":"0";
        oracom.Parameters["p_local_date"].Value = CheckBox7.Checked?"1":"0";
        oracom.Parameters["p_local_time"].Value = CheckBox8.Checked?"1":"0";
        oracom.Parameters["p_currency"].Value = CheckBox9.Checked?"1":"0";
        oracom.Parameters["p_tran_amount"].Value = CheckBox10.Checked?"1":"0";
        oracom.Parameters["p_settlement_amount"].Value = CheckBox11.Checked?"1":"0";
        oracom.Parameters["p_fee_amount"].Value = CheckBox12.Checked?"1":"0";
        oracom.Parameters["p_auth_code"].Value = CheckBox13.Checked?"1":"0";
        oracom.Parameters["p_message_type"].Value = CheckBox14.Checked?"1":"0";
        oracom.Parameters["p_tran_source"].Value = CheckBox15.Checked?"1":"0";
        oracom.Parameters["p_tran_destination"].Value = CheckBox16.Checked?"1":"0";
        oracom.Parameters["p_master_table"].Value = ddlMaster.SelectedValue;
        oracom.Parameters["p_slave_table"].Value = ddlSlave.SelectedValue;
        oracom.Parameters["p_term_id"].Value = CheckBox17.Checked ? "1" : "0";
        oracom.Parameters["p_acct_number"].Value = CheckBox19.Checked ? "1" : "0";
        oracom.Parameters["p_days_before"].Value = txtBefore.Text;
        oracom.Parameters["p_days_after"].Value = txtAfter.Text;
        oracom.Parameters["p_file_name"].Value = ddlFileName.SelectedValue;
        oracom.Parameters["p_active"].Value = CheckBox18.Checked ? "1" : "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;
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        pnlBR.Visible = true;
        pnlResult.Enabled = false;
        ViewState["mode"] = "a";

        lblRecordDate.Text = "";

        txtcos.Text = "";
        txtcoe.Text = "";

        CheckBox1.Checked = false;

        CheckBox2.Checked = false;

        CheckBox3.Checked = false;

        CheckBox4.Checked = false;

        CheckBox5.Checked = false;

        CheckBox6.Checked = false;

        CheckBox7.Checked = false;

        CheckBox8.Checked = false;

        CheckBox9.Checked = false;

        CheckBox10.Checked = false;

        CheckBox11.Checked = false;

        CheckBox12.Checked = false;

        CheckBox13.Checked = false;

        CheckBox14.Checked = false;

        CheckBox15.Checked = false;

        CheckBox16.Checked = false;

        CheckBox17.Checked = false;

        ddlMaster.SelectedIndex = 0;
        ddlSlave.SelectedIndex = 0;

        if (ddlChannels.SelectedIndex > 0)
            ddlChannels0.SelectedValue = ddlChannels.SelectedValue;

        if (ddlEvents.SelectedIndex > 0)
            ddlEvents0.SelectedValue = ddlEvents.SelectedValue;

        loadFileNames();
        txtBefore.Text = "";
        txtAfter.Text = "";

        loadFileNames();
        ddlFileName.SelectedIndex = 0;

        CheckBox18.Checked = false;

        addrow.Visible = true;
    }

    protected void ddlMaster_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadFileNames();
    }

    private bool addBR(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 = "BUSINESS_RULES_EDITOR.Add_Business_Rules";

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

        oracom.Parameters.Add("p_re_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rc_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        
        oracom.Parameters.Add("p_cut_off_start", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cut_off_end", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_cut_off_rule", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_card_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_rrn", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_trace_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_local_date", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_local_time", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_currency", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_settlement_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_fee_amount", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_auth_code", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_message_type", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_source", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_tran_destination", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_master_table", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_slave_table", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_term_id", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_acct_number", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_days_before", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_days_after", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_file_name", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_active", 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_re_code"].Value = ddlEvents0.SelectedValue;
        oracom.Parameters["p_rc_code"].Value = ddlChannels0.SelectedValue;

        oracom.Parameters["p_cut_off_start"].Value = txtcos.Text.Replace(":", "");
        oracom.Parameters["p_cut_off_end"].Value = txtcoe.Text.Replace(":", "");
        oracom.Parameters["p_cut_off_rule"].Value = CheckBox1.Checked ? "1" : "0";
        oracom.Parameters["p_tran_date"].Value = CheckBox2.Checked ? "1" : "0";
        oracom.Parameters["p_tran_time"].Value = CheckBox3.Checked ? "1" : "0";
        oracom.Parameters["p_card_number"].Value = CheckBox4.Checked ? "1" : "0";
        oracom.Parameters["p_rrn"].Value = CheckBox5.Checked ? "1" : "0";
        oracom.Parameters["p_trace_id"].Value = CheckBox6.Checked ? "1" : "0";
        oracom.Parameters["p_local_date"].Value = CheckBox7.Checked ? "1" : "0";
        oracom.Parameters["p_local_time"].Value = CheckBox8.Checked ? "1" : "0";
        oracom.Parameters["p_currency"].Value = CheckBox9.Checked ? "1" : "0";
        oracom.Parameters["p_tran_amount"].Value = CheckBox10.Checked ? "1" : "0";
        oracom.Parameters["p_settlement_amount"].Value = CheckBox11.Checked ? "1" : "0";
        oracom.Parameters["p_fee_amount"].Value = CheckBox12.Checked ? "1" : "0";
        oracom.Parameters["p_auth_code"].Value = CheckBox13.Checked ? "1" : "0";
        oracom.Parameters["p_message_type"].Value = CheckBox14.Checked ? "1" : "0";
        oracom.Parameters["p_tran_source"].Value = CheckBox15.Checked ? "1" : "0";
        oracom.Parameters["p_tran_destination"].Value = CheckBox16.Checked ? "1" : "0";
        oracom.Parameters["p_master_table"].Value = ddlMaster.SelectedValue;
        oracom.Parameters["p_slave_table"].Value = ddlSlave.SelectedValue;
        oracom.Parameters["p_term_id"].Value = CheckBox17.Checked ? "1" : "0";
        oracom.Parameters["p_acct_number"].Value = CheckBox19.Checked ? "1" : "0"; 
        oracom.Parameters["p_days_before"].Value = txtBefore.Text;
        oracom.Parameters["p_days_after"].Value = txtAfter.Text;
        oracom.Parameters["p_file_name"].Value = ddlFileName.SelectedValue;
        oracom.Parameters["p_active"].Value = CheckBox18.Checked ? "1" : "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;
    }
    protected void ddlChannels_SelectedIndexChanged(object sender, EventArgs e)
    {
        pnlBR.Visible = false;
        pnlResult.Visible = false;
        loadEvents();
    }
    protected void ddlEvents_SelectedIndexChanged(object sender, EventArgs e)
    {
        pnlBR.Visible = false;
        pnlResult.Visible = false;
    }
}
