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 POS_ReconResult : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["uid"] == null)
            Response.Redirect("../Security/LoginPage.aspx");
        
        int userGroupID = Helper.getCurrentUserGroup(int.Parse(Session["uid"].ToString()));
        
        if (!IsPostBack)
        {
            this.loadPremittedReports(3, userGroupID);
            loadChannels();
            loadEvents();
            loadStatus5();
            loadStatus6();
            loadChType();
            loadStatus8();
            loadStatus9();
            loadChannels11();
            loadServices();
            //loadChannelEvents11();
            loadClaimType5();
            Textproduct.Visible = false;
            ddlChannels5_SelectedIndexChanged(sender, e);
            ddlType20_SelectedIndexChanged(sender, e);
            loadCSProducts();
            this.ddl_contraMatched_events.Enabled = false;
        }
        lblError.Text = "";
        hide();
    }

    private void loadPremittedReports(int reportGroupId, int groupId)
    {
        int resCode;

        string DBConnection = Helper.dbConnection();

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "REPORTS_PERMISSIONS_OPS.GET_ACTIVE_PERMITTED_REPORTS";

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

        oracom.Parameters.Add("p_group_id", OracleType.Number).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_reports_group_id", OracleType.Number).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_lang"].Value = "EN";
        oracom.Parameters["p_group_id"].Value = groupId;
        oracom.Parameters["p_reports_group_id"].Value = reportGroupId;

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

        oracon.Close();

        resCode = int.Parse(oracom.Parameters["p_res_code"].Value.ToString());

        if (resCode == 9)
        {
            Response.Redirect("../Business/default.aspx?err=1");
        }
        else
        {
            this.ddlReports.DataSource = ds;
            this.ddlReports.DataBind();

            this.ddlReports.Items.Insert(0, "------ Reports ------");
        }
    }


    /*IJR Load Services*/
    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_DailyReport";

        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 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 = "poslookup_getter.get_claimchanneltype";

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


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

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

        oracon.Close();
    }

    private void loadEvents()
    {
        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_pos_recon_events";

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

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        oracon.Close();
       // ddlEvents5.DataSource = ds;
       // ddlEvents5.DataBind();
       // ddlEvents6.DataSource = ds;
      //  ddlEvents6.DataBind();
    }

    private void loadStatus5()
    {
        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.rprt_grpclaimstatus";

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

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        oracon.Close();
        ddlStatus5.DataSource = ds;
        ddlStatus5.DataBind();
    }

    private void loadStatus6()
    {
        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_claim_SAMAStatus";

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

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        oracon.Close();
        ddlStatus6.DataSource = ds;
        ddlStatus6.DataBind();
    }

    private void loadStatus5_SAMA()
    {
        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_claim_SAMAStatus";

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

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        oracon.Close();
        //ddlStatus5.Items.Clear()
        ddlStatus5.DataSource = ds;
        ddlStatus5.DataBind();
    }
    private void loadChType()
    {
        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_rpt_channel_types";

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

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        oracon.Close();
        ddlChType7.DataSource = ds;
        ddlChType7.DataBind();
    }

    private void loadStatus8()
    {
        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_posmerchant_status";

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

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);
        oracon.Close();
        ddlStatus8.DataSource = ds;
        ddlStatus8.DataBind();
    }

    private void loadStatus9()
    {
        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);
        oracon.Close();
        ddlStatus9.DataSource = ds;
        ddlStatus9.DataBind();
    }

    private void loadChannels11()
    {
        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_job_channels_rpt";

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


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

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

        //BY Ibrahim Al-Ashqar
        this.ddl_contraMatched_channels.DataSource = ds;
        this.ddl_contraMatched_channels.DataBind();
        this.ddl_contraMatched_channels.Items.Insert(0, "------ Channels ------");

        ddlChannels11.Items.Insert(0, "------ Channels ------");
        oracon.Close();
    }

    private DataSet loadChannelEvents11(string selectedChannelId)
    {
        //ddlEvents11.Items.Clear();
        //if (ddlChannels11.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_Job_Channel_Events";
            oracom.CommandText = "LOOKUP_GETTER.Get_Recon_Channel_Events";

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

            oracom.Parameters["p_rc_code"].Value = selectedChannelId;

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

            return ds;
            
            //ddlEvents11.DataSource = ds;
            //ddlEvents11.DataBind();
        //}
        //ddlEvents11.Items.Insert(0, "------ Events ------");

    }

    private void loadClaimType5()
    {
        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_claimtype";

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

        oracom.Parameters["p_product"].Value = "2";

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

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

        ddlClaimType5.Items.Insert(0, "------ All ------");
        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 = "sama_cps_reports.get_file_id";

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

        ////oracom.Parameters["p_type"].Value = ddlType20.SelectedValue;

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

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

        //oracon.Close();
    }

    protected void ddlChannels11_SelectedIndexChanged(object sender, EventArgs e)
    {
        //loadChannelEvents11();

        //Updated By Ibrahim Al-Ashqar

        int selectedChannelId = int.Parse(this.ddlChannels11.SelectedValue.ToString());

        ddlEvents11.Items.Clear();
        if (ddlChannels11.SelectedIndex > 0)
        {
            this.ddlEvents11.DataSource = loadChannelEvents11(selectedChannelId.ToString());
            this.ddlEvents11.DataBind();

            this.ddlEvents11.Items.Insert(0, "------Event-----");
        }

        //btnSearch.Enabled = false;
    }

    private bool cssSettlement( 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 = "gl_posting_approver.CSSettlement_GlPOST_Rpt";

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

        if (ddlProduct100.SelectedIndex == 0)
            oracom.Parameters["P_Product"].Value = OracleNumber.Null;
        else
            oracom.Parameters["P_Product"].Value = ddlProduct100.SelectedValue;
        oracom.Parameters["p_rc_code"].Value = ddlChannel100.SelectedValue;

        oracom.Parameters["P_FromDate"].Value = date100From.date;
        oracom.Parameters["P_ToDate"].Value = date100To.date;

        //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 btnSearch_Click(object sender, EventArgs e)
    {
        // 100 
        if (ddlReports.SelectedValue == "100")
        {
            if (date100From.date.Length == 0 || date100To.date.Length == 0)
            {
                lblError.Text = "please enter a date";
            }
            else
            {
                string error = "";
                if (!cssSettlement(ref error))
                {
                    lblError.Text = error;
                    return;
                }
                string p1 = ddlChannel100.SelectedValue;
                string p2 = date100From.date;
                string p3 = date100To.date;
                DateTime d1 = new DateTime(int.Parse(date100From.date.Substring(0, 2)) + 2000, int.Parse(date100From.date.Substring(2, 2)), int.Parse(date100From.date.Substring(4, 2)));
                DateTime d2 = new DateTime(int.Parse(date100To.date.Substring(0, 2)) + 2000, int.Parse(date100To.date.Substring(2, 2)), int.Parse(date100To.date.Substring(4, 2)));
                if ((d2 - d1).TotalDays > 30)
                    lblError.Text = "Date range can't be more than 30 days";
                else
                    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                        "window.open('../Reports/Default.aspx?rpt=9000&p1=" + ddlChannel100.SelectedItem.Text + "&p2=" + "From:" + date100From.FormatedDate + " To:" + date100To.FormatedDate + "&p3=" + ddlProduct100.SelectedItem.Text + "','Report')", true);
            }
        }

        if (ddlReports.SelectedValue == "101")
        {
            if (ddtype.SelectedValue == "SR")
            {
                string p1 = rMCBS_sdate.date;

                string UrlString1 = "rpt=1008&p1=" + p1;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                        "window.open('../Reports/Default.aspx?" + UrlString1 + "','Report')", true);
            }
            else if (ddtype.SelectedValue == "DR")
            {
                string p1 = "20" + rMCBS_sdate.date;
                string p2 = "MC BILL";
                string p3 = "11";

                string UrlString1 = "rpt=1009&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                        "window.open('../Reports/Default.aspx?" + UrlString1 + "','Report')", true);
            }
        }

        // 1 
        if (ddlReports.SelectedValue == "21")
        {
            if (fromDate1.date.Length == 0 || toDate1.date.Length == 0)
            {
                lblError.Text = "please enter a date";
            }
            else
            {
                string p1 = fromDate1.date;
                string p3 = toDate1.date;
                string p2 = txtTerminalID1.Text;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=201&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
        }

        // 2 
        if (ddlReports.SelectedValue == "22")
        {
            if (DatePicker2.date.Length == 0)//|| txtTime2.Text.Length == 0)
            {
                lblError.Text = "please enter a date and time";
            }
            else
            {
                string p1 = DatePicker2.date;
                string p2 = txtTerminalID2.Text;
                string p3 = txtTime2.Text;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=202&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
        }

        // 3 
        if (ddlReports.SelectedValue == "23")
        {
            if (fromDate3.date.Length == 0 || toDate3.date.Length == 0)
            {
                lblError.Text = "please enter a date";
            }
            else
            {
                string p1 = fromDate3.date;
                string p3 = toDate3.date;
                string p2 = txtTerminalID3.Text;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=203&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
        }

        // 4 
        if (ddlReports.SelectedValue == "24")
        {
            if (DatePicker4.date.Length == 0 || txtTime4.Text.Length == 0)
            {
                lblError.Text = "please enter a date and time";
            }
            else
            {
                string p1 = DatePicker4.date;
                string p2 = txtTerminalID4.Text;
                string p3 = "235959";
                if (txtTime4.Text.Length > 0)
                    p3 = txtTime4.Text;

                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=204&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
        }

        // 5 
        if (ddlReports.SelectedValue == "25")
        {
            if (fromDate5.date.Length == 0 || toDate5.date.Length == 0)
            {
                lblError.Text = "please enter a date";
            }
            else
            {
                //  string p1 = ddlEvents5.SelectedValue;
                string p2, p3 = "";
                if (ddlChannels5.SelectedValue == "003" && ddlStatus5.SelectedValue == "1")
                {
                    p2 = ddlChannels5.SelectedValue;
                    p3 = "301"; // SAMA Pending Status
                }
                else
                {
                    p2 = ddlChannels5.SelectedValue;
                    p3 = ddlStatus5.SelectedValue;
                }
                string p4 = fromDate5.date;
                string p5 = toDate5.date;
                string p6 = Textproduct.Text;
                string p7 = ddlOrigin.SelectedValue;
                string p8 = "";
                if (ddlClaimType5.SelectedIndex > 0)
                    p8 = ddlClaimType5.SelectedValue;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=205&p2=" + p2 + "&p3=" + p3 + "&p4=" + p4 + "&p5=" + p5 + "&p6=" + p6 + "&p7=" + p7 + "&p8=" + p8 + "','Report')", true);
            }
        }

        //// 6 
        //if (ddlReports.SelectedValue == "6")
        //{
        //    if (fromDate6.date.Length == 0 || toDate6.date.Length == 0)
        //    {
        //        lblError.Text = "please enter a date";
        //    }
        //    else
        //    {
        //        string p1 = ddlEvents6.SelectedValue;
        //        string p2 = ddlStatus6.SelectedValue;
        //        string p3 = fromDate6.date;
        //        string p4 = toDate6.date;
        //        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        //            "window.open('../Reports/Default.aspx?rpt=206&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "&p4=" + p4 + "','Report')", true);
        //    }
        //}

        // 7 
        if (ddlReports.SelectedValue == "26")
        {
            if (procDate7.date.Length == 0)
            {
                lblError.Text = "please enter a date";
            }
            else
            {
                string p1 = ddlChType7.SelectedValue;
                string p2 = procDate7.date;
                string p3 = txtuserid.Text; ;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=207&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
        }

        // 8 
        //if (ddlReports.SelectedValue == "8")
        //{
        //    if (fromDate8.date.Length == 0 || toDate8.date.Length == 0)
        //    {
        //        lblError.Text = "please enter a date";
        //    }
        //    else
        //    {
        //        string p3 = ddlStatus8.SelectedValue;
        //        string p1 = fromDate8.date;
        //        string p2 = toDate8.date;
        //        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        //            "window.open('../Reports/Default.aspx?rpt=208&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
        //    }
        //}


        //// 9 
        //if (ddlReports.SelectedValue == "9")
        //{
        //    if (fromDate9.date.Length == 0 || toDate9.date.Length == 0)
        //    {
        //        lblError.Text = "please enter a date";
        //    }
        //    else
        //    {
        //        string p3 = ddlStatus9.SelectedValue;
        //        string p1 = fromDate9.date;
        //        string p2 = toDate9.date;
        //        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        //            "window.open('../Reports/Default.aspx?rpt=209&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
        //    }
        //}

        //// 10 
        //if (ddlReports.SelectedValue == "10")
        //{
        //    //if (fromDate10.date.Length == 0 || toDate10.date.Length == 0)
        //    //{
        //    //    lblError.Text = "please enter a date";
        //    //}
        //    //else
        //    //{
        //        string p2 = txtClientNo10.Text;
        //        string p1 = txtTermID10.Text;
        //        string p3 = fromDate10.date;
        //        string p4 = toDate10.date;
        //        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        //            "window.open('../Reports/Default.aspx?rpt=210&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "&p4=" + p4 + "','Report')", true);
        //    //}
        //}

        // 11
        if (ddlReports.SelectedValue == "27")
        {
            if (settlDate11.date.Length == 0)
            {
                lblError.Text = "please enter a date";
            }
            else if (ddlChannels11.SelectedIndex == 0)
            {
                lblError.Text = "please select the channel & Event";
            }
            else if (ddlEvents11.SelectedIndex == 0)
            {
                lblError.Text = "please select an Event";
            }
            else
            {
                string p1 = ddlEvents11.SelectedValue;
                string p2 = settlDate11.date;
                string p3 = ddlFinancial.SelectedValue;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=211&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
        }

        // 12
        if (ddlReports.SelectedValue == "28")
        {
            if (settlDate12.date.Length == 0)
            {
                lblError.Text = "please enter a date";
            }
            else
            {
                string p1 = txtClientNo12.Text;
                string p2 = settlDate12.date;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=212&p1=" + p1 + "&p2=" + p2 + "','Report')", true);
            }
        }

        // 13
        //if (ddlReports.SelectedValue == "13")
        //{
        //    string p1 = txtClientNo13.Text;
        //    string p2 = DatePicker13.date;


        //    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        //        "window.open('../Reports/Default.aspx?rpt=213&p1=" + p1 + "&p2=" + p2 + "','Report')", true);
        //}

        // 14
        if (ddlReports.SelectedValue == "29")
        {
            if (txtAccNo14.Text.Length == 0 || dateFrom14.date.Length == 0 || dateTo14.date.Length == 0)
            {
                lblError.Text = "please enter all fields";
            }
            else
            {
                string p1 = txtAccNo14.Text;
                string p2 = dateFrom14.date;
                string p3 = dateTo14.date;
                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=214&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
        }

        //15th report
        if (ddlReports.SelectedValue == "30")
        {
            if (DatePicker15.date.Length == 0 || txtClientNo15.Text.Length == 0)
            {
                lblError.Text = "please enter All fields";
            }
            else
            {
                string p1 = DatePicker15.date;
                string p2 = txtClientNo15.Text;

                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=215&p1=" + p1 + "&p2=" + p2 + "','Report')", true);
            }
        }
        //16th report
        if (ddlReports.SelectedValue == "31")
        {
            if (FromDate16.date.Length == 0 || Todate16.date.Length == 0 || User_ID.Text.Length == 0)
            {
                lblError.Text = "please enter All fields";
            }
            else
            {
                string p1 = User_ID.Text;
                string p2 = FromDate16.date;
                string p3 = Todate16.date;
                string p4 = fromtime.Text;
                string p5 = totime.Text;

                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                    "window.open('../Reports/Default.aspx?rpt=216&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "&p4=" + p4 + "&p5=" + p5 + "','Report')", true);
            }
        }
        // 17
        //if (ddlReports.SelectedValue == "17")
        //{
        //    string p1 = txtClientNo17.Text;
        //    string p2 = DatePicker17.date;


        //    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
        //        "window.open('../Reports/Default.aspx?rpt=217&p1=" + p1 + "&p2=" + p2 + "','Report')", true);
        //}

        // 19
        if (ddlReports.SelectedValue == "32")
        {
            string p1 = ddlType19.SelectedValue;
            string p2 = "2";


            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                "window.open('../Reports/Default.aspx?rpt=219&p1=" + p1 + "&p2=" + p2 + "','Report')", true);
        }

        // 20
        if (ddlReports.SelectedValue == "33")
        {
            string p1 = ddlClaimDate20.date;
            string p2 = "2";


            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                "window.open('../Reports/Default.aspx?rpt=220&p1=" + p1 + "&p2=" + p2 + "','Report')", true);
        }

        // 21
        if (ddlReports.SelectedValue == "34")
        {
            string p1 = ddlType21.SelectedValue;
            string p2 = "2";


            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                "window.open('../Reports/Default.aspx?rpt=221&p1=" + p1 + "&p2=" + p2 + "','Report')", true);
        }

        //By Ibrahim Al-Ashqar
        // Contra Matched Transactions Report
        if (ddlReports.SelectedValue == "42")
        {
            if (this.dtp_contraMatched_date.date != null && this.dtp_contraMatched_date.date.Length != 0)
            {

                if (ddl_contraMatched_channels.SelectedIndex > 0
                    && ddl_contraMatched_events.SelectedIndex > 0)
                {
                    string p1 = this.ddl_contraMatched_channels.SelectedValue;
                    string p2 = this.ddl_contraMatched_events.SelectedValue;
                    string p3 = this.dtp_contraMatched_date.date;
                    string p4 = Session["uid"].ToString();
                    ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                        "window.open('../Reports/Default.aspx?rpt=1041&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "&p4=" + p4 + "','Report')", true);
                }
                else
                {
                    this.lblError.Text = "Please select Channel and Event.";
                }
            }
            else
            {
                this.lblError.Text = "Please select a date.";
            }
        }

        //IJR 25-02-2012
        //POS Daily Tranasctions
        /*  if (ddlReports.SelectedValue == "54")
          {
              if (dtpSettelemetDate.date != null)
              {
                  string p1 = this.dtpSettelemetDate.date;
                  string p2 = this.ddlServices.SelectedValue;
                  string p3 = Session["uid"].ToString();

            
               ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                      "window.open('../Reports/Default.aspx?rpt=501&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 +  "','Report')", true);
              }
              else
              {
                  this.lblError.Text = "Please select a  settelment date.";
              }
          }*/



        //POS Claims With No Action Taken
        if (ddlReports.SelectedValue == "46")
        {
            string fromDate = this.dtp_claimsNoAction_fromDate.date;
            string toDate = this.dtp_claimsNoAction_toDate.date;

            if (fromDate.Length != 0 && toDate.Length != 0)
            {
                fromDate = DateTime.ParseExact(this.dtp_claimsNoAction_fromDate.date, "yyMMdd", null).ToString("yyyyMMdd");
                toDate = DateTime.ParseExact(this.dtp_claimsNoAction_toDate.date, "yyMMdd", null).ToString("yyyyMMdd");

                string p1 = fromDate;
                string p2 = toDate;
                string p3 = Session["uid"].ToString();

                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                            "window.open('../Reports/Default.aspx?rpt=1046&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
            else
            {
                this.lblError.Text = "Please select a period.";
            }
        }

        //POS Debited Claims 
        if (ddlReports.SelectedValue == "48")
        {
            string fromDate = this.dtp_debitedClaims_fromDate.date;
            string toDate = this.dtp_debitedClaims_toDate.date;
            string accountNumber = this.txt_debitedClaims_acctNumber.Text;

            if (accountNumber.Length != 0 && fromDate.Length != 0 && toDate.Length != 0)
            {
                string p1 = accountNumber;
                string p2 = fromDate;
                string p3 = toDate;
                string p4 = Session["uid"].ToString();

                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                            "window.open('../Reports/Default.aspx?rpt=1048&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "&p4=" + p4 + "','Report')", true);
            }
            else if (accountNumber.Length == 0)
            {
                this.lblError.Text = "Please enter an account number.";
            }
            else if (fromDate.Length == 0 || toDate.Length == 0)
            {
                this.lblError.Text = "Please select a period.";
            }
        }

        if (ddlReports.SelectedValue == "58")
        {
            if (dtpProof.date.Length == 0)
                lblError.Text = " Please enter a date";
            else
            {
                string p1 = dtpProof.date;
                string p2 = ddlProofAccountReport.SelectedValue;
                string p3 = dtpProof.FormatedDate;
                DateTime dt = new DateTime(int.Parse(p1.Substring(0, 2)), int.Parse(p1.Substring(2, 2)),
                    int.Parse(p1.Substring(4, 2)));
                dt = dt.AddDays(-1);
                string p4 = dt.ToString("dd-MM-yy");

                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('../Reports/Default.aspx?rpt=510&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "&p4=" + p4 + "','Report')", true);

            }
        }

        if (ddlReports.SelectedValue == "61")
        {
            if (dtpClaimsProof_From.date.Length == 0)
                lblError.Text = " Please enter From date";
            else if (dtpClaimsProof_To.date.Length == 0)
                lblError.Text = " Please enter To date";
            else
            {
                string p1 = dtpClaimsProof_From.date;
                string p2 = dtpClaimsProof_To.date;

                string p3 = ddlClaimsProofPeriod.SelectedValue;


                string p4 = dtpClaimsProof_From.FormatedDate;
                string p5 = dtpClaimsProof_To.FormatedDate;
                string p6 = ddlReportType.SelectedValue;

                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                   "window.open('../Reports/Default.aspx?rpt=513&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "&p4=" + p4 +
                   "&p5=" + p5 + "&p6=" + p6 + "','Report')", true);
            }

        }

        if (ddlReports.SelectedValue == "63")
        {
            string vDate = this.dtUnmatchTerminalRecon.date;
            string v_term_id = this.TextBoxTerm_ID.Text.Trim();

            if (vDate.Length != 0 && !String.IsNullOrWhiteSpace(v_term_id))
            {
                string p1 = vDate;
                string p2 = v_term_id;
                string p3 = Session["uid"].ToString();


                ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                          "window.open('../Reports/Default.aspx?rpt=1054&p1=" + p1 + "&p2=" + p2 + "&p3=" + p3 + "','Report')", true);
            }
            else
            {
                this.lblError.Text = "Please select a Date and Terminal ID";
            }
        }
    }

    protected void ddlReports_SelectedIndexChanged(object sender, EventArgs e)
    {
        hide();
    }

    private void hide()
    {
        row1.Visible = false;
        row2.Visible = false;
        row3.Visible = false;
        row4.Visible = false;
        rMCBS.Visible = false;
        row5.Visible = false;
        row6.Visible = false;
        row7.Visible = false;
        row8.Visible = false;
        row9.Visible = false;
        row10.Visible = false;
        row11.Visible = false;
        row12.Visible = false;
        row13.Visible = false;
        row14.Visible = false;
        row15.Visible = false;
        row16.Visible = false;
        row17.Visible = false;
        row19.Visible = false;
        row20.Visible = false;
        row21.Visible = false;
        row30.Visible = false;
        row100.Visible = false;
        //by Ibrahim Al-Ashqar
        tbl_rpt_contraMatched.Visible = false;
        this.tbl_rpt_claimsNoAction.Visible = false;
        this.tbl_rpt_debitedClaims.Visible = false;

        //IHJ
        this.tblProofAccountReport.Visible = false;
        this.tblClaimsProofPeriod.Visible = false;
        this.tblUnmatchTerminalRecon.Visible = false;

        switch (ddlReports.SelectedValue)
        {
            case "21":
                row1.Visible = true;
                break;
            case "22":
                row2.Visible = true;
                break;
            case "23":
                row3.Visible = true;
                break;
            case "24":
                row4.Visible = true;
                break;
            case "25":
                row5.Visible = true;
                break;
            case "26":
                row7.Visible = true;
                break;
            case "27":
                row11.Visible = true;
                break;
            case "28":
                row12.Visible = true;
                break;
            case "29":
                row14.Visible = true;
                break;
            case "30":
                row15.Visible = true;
                break;
            case "31":
                row16.Visible = true;
                break;
            case "32":
                row19.Visible = true;
                break;
            case "33":
                row20.Visible = true;
                break;
            case "34":
                row21.Visible = true;
                break;
            case "42":
                tbl_rpt_contraMatched.Visible = true;
                break;
            case "46":
                this.tbl_rpt_claimsNoAction.Visible = true;
                break;
            case "48":
                this.tbl_rpt_debitedClaims.Visible = true;
                break;

            case "58":
                this.tblProofAccountReport.Visible = true;
                break;

            case "61":
                this.tblClaimsProofPeriod.Visible = true;
                break;
            case "63":
                this.tblUnmatchTerminalRecon.Visible = true;
                break;
            case "100":
                this.row100.Visible = true;
                break;
            case "101":
                this.rMCBS.Visible = true;
                break;
                /* case "54":
                     row30.Visible = true;
                     break;*/
        }
    }

    protected void ddlChannels5_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlChannels5.SelectedValue.Equals("003"))
        {
            rowOrigin.Visible = true;
        }
        else
        {
            rowOrigin.Visible = false;
        }
    }

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

    //By Ibrahim Al-Ashqar
    protected void ddl_contraMatched_channels_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.btnSearch.Enabled = false;

        string selectedChannelId = this.ddl_contraMatched_channels.SelectedValue;

        if (this.ddl_contraMatched_channels.SelectedIndex > 0)
        {
            this.ddl_contraMatched_events.DataSource = this.loadChannelEvents11(selectedChannelId);
            this.ddl_contraMatched_events.DataBind();

            this.ddl_contraMatched_events.Items.Insert(0, "----------- Select Event -----------");

            this.ddl_contraMatched_events.Enabled = true;
        }
        else
        {
            this.ddl_contraMatched_events.Enabled = false;
            this.ddl_contraMatched_events.Items.Clear();
        }
    }

    protected void ddl_contraMatched_events_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_contraMatched_events.SelectedIndex > 0)
        {
            this.btnSearch.Enabled = true;
        }
        else
        {
            this.btnSearch.Enabled = false;
        }
    }
    protected void ddlChannel100_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadCSProducts();
    }

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

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

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

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "CS_SETTL_INFO_EDITOR.Get_CS_Channel_products";

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

        oracom.Parameters["p_channel"].Value = ddlChannel100.SelectedValue;

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

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

        this.ddlProduct100.Items.Insert(0, "ALL");

        oracon.Close();
    }
}
