using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;
using System.Security.Cryptography;
using System.Text;
using RKLib.ExportData;
using Image = System.Web.UI.WebControls.Image;

public partial class Admin_Report : System.Web.UI.Page
{
    decimal ColumnAmount;
    decimal ColumnMargin;
    decimal ColumnNetAmount;
    string date = DateTime.Now.ToLongDateString();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["AdminEMAILID"] == null)
            {
                Response.Redirect("AdminLogin.aspx");
            }
            if (!IsPostBack)
            {
                //Div_TransactionReport.Visible = false;
                //Div_FundReport.Visible = false;
                div_UserRegistration.Visible = false;
                Div_AccountStatement.Visible = false;
            }
            btnDownload.Visible = false;
            btn_Submit.Visible = true;
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }

    protected void ddl_Report_Type_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_Report_Type.SelectedItem.Text == "Transaction Report")
        {
            //Div_TransactionReport.Visible = true;
            //Div_FundReport.Visible = false;
            div_UserRegistration.Visible = false;
            Div_AccountStatement.Visible = false;       
        }
        else if (ddl_Report_Type.SelectedItem.Text == "Fund Report")
        {
            //Div_TransactionReport.Visible = false;
            //Div_FundReport.Visible = true;
            div_UserRegistration.Visible = false;
            Div_AccountStatement.Visible = false;            
        }
        else if (ddl_Report_Type.SelectedItem.Text == "User Registration Report")
        {
            //Div_TransactionReport.Visible = false;
            //Div_FundReport.Visible = false;
            div_UserRegistration.Visible = true;
            Div_AccountStatement.Visible = false;
        }
        else if (ddl_Report_Type.SelectedItem.Text == "Account Statement")
        {
            getuser();
            //Div_TransactionReport.Visible = false;
            //Div_FundReport.Visible = false;
            div_UserRegistration.Visible = false;
            Div_AccountStatement.Visible = true;
        }
        else if (ddl_Report_Type.SelectedItem.Text == "SMS Report")
        {
            //Div_TransactionReport.Visible = false;
            //Div_FundReport.Visible = false;
            div_UserRegistration.Visible = false;
            Div_AccountStatement.Visible = false;
        }

        else if (ddl_Report_Type.SelectedItem.Text == "Cancle Txn Report")
        {
            Div_PanReport.Visible = true;
            //Div_FundReport.Visible = false;
            div_UserRegistration.Visible = false;
            Div_AccountStatement.Visible = false;
        }
        else if (ddl_Report_Type.SelectedItem.Text == "Money Transfer Report")
        {
            //Div_TransactionReport.Visible = false;
            //Div_FundReport.Visible = false;
            div_UserRegistration.Visible = false;
            Div_AccountStatement.Visible = false;
        }
        else if (ddl_Report_Type.SelectedItem.Text == "Flight Report")
        {
            //Div_TransactionReport.Visible = false;
            //Div_FundReport.Visible = false;
            div_UserRegistration.Visible = false;
            Div_AccountStatement.Visible = false;
        }
        else if (ddl_Report_Type.SelectedItem.Text == "Train Transfer Report")
        {
            //Div_TransactionReport.Visible = false;
            //Div_FundReport.Visible = false;
            div_UserRegistration.Visible = false;
            Div_AccountStatement.Visible = false;
        }
        
        txtToDate.Text = "";
        txtFrmDate.Text = "";
        GridViewRegUser.Visible = false;
        gvAccountReport.Visible = false;
        GridViewAmountReport.Visible = false;
        GridViewSMSPeport.Visible = false;
        GridViewAccountStatement.Visible = false;


    }

    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        try
        {
            if (Convert.ToDateTime(txtFrmDate.Text).Date > Convert.ToDateTime(date))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('From Date must be less then  current date');"), true);
            }
            else if (Convert.ToDateTime(txtToDate.Text).Date > Convert.ToDateTime(date))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('To Date must be less then  current date');"), true);
            }
            else if (Convert.ToDateTime(txtFrmDate.Text).Date > Convert.ToDateTime(txtToDate.Text).Date)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('From date must be less then To date');"), true);
            }
            else
            {
                string datefrom = txtFrmDate.Text.Trim();
                string dateto = txtToDate.Text.Trim();
                string[] datefrom1 = datefrom.Split('-');
                string[] dateto1 = dateto.Split('-');
                string fromdate = string.Empty;
                string todate = string.Empty;
                fromdate = Convert.ToString(datefrom1.GetValue(2));
                todate = Convert.ToString(dateto1.GetValue(2));
                if (Convert.ToInt32(fromdate) > Convert.ToInt32(todate))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('You can not Get data of this date');"), true);
                }
                //if (Convert.ToInt32(fromdate) < Convert.ToInt32(todate))
               // {
             //  Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Invalid Date selection');"), true);
              //  }
                //else if (Convert.ToInt32(fromdate).Equals(Convert.ToInt32(todate)))
               // {
                    if (ddl_Report_Type.SelectedItem.Text == "Transaction Report")
                    {
                        TransactionReport();
                    }
                    else if (ddl_Report_Type.SelectedItem.Text == "Fund Report")
                    {
                        FundReport();
                    }
                    else if (ddl_Report_Type.SelectedItem.Text == "User Registration Report")
                    {
                        RegistrationReport();
                    }
                    else if (ddl_Report_Type.SelectedItem.Text == "Account Statement")
                    {
                        AccountStatement();
                    }
                    else if (ddl_Report_Type.SelectedItem.Text == "SMS Report")
                    {
                        SMSReport();
                    }
                    else if (ddl_Report_Type.SelectedItem.Text == "Cancle Txn Report")
                    {
                        PanCardReport();
                    }
                    else if (ddl_Report_Type.SelectedItem.Text == "Money Transfer Report")
                    {
                        DMRReport();
                    }
                    else if (ddl_Report_Type.SelectedItem.Text == "Flight Report")
                    {
                        FlightReport();
                    }
                    else if (ddl_Report_Type.SelectedItem.Text == "Train Transfer Report")
                    {
                        TrainReport();
                    }
               // }
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    public void TrainReport()
    {
        SqlParameter[] param = new SqlParameter[]
        {
            new SqlParameter("@fromdate",txtFrmDate.Text.Trim()),
            new SqlParameter("@todate",txtToDate.Text.Trim())
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Admin_Report_For_Train", param);
        if (ds.Tables[0].Rows.Count > 0)
        {
            gvAccountReport.Visible = true;
            gvAccountReport.DataSource = ds;
            gvAccountReport.DataBind();
            btnDownload.Visible = true;
            btn_Submit.Visible = false;
            GridViewSMSPeport.Visible = false;
            GridViewAmountReport.Visible = false;
            gv_PancardReport.Visible = false;
            GridViewRegUser.Visible = false;
        }
    }
    public void TransactionReport()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                //new SqlParameter("@TransactionReporType",ddl_Report.SelectedItem.Text),
                new SqlParameter("@TransactionReporType","Recharge Transaction"),
                new SqlParameter("@Date",txtFrmDate.Text.Trim()),
                new SqlParameter("@DateTo",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_get_transactions_All_Type", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                gvAccountReport.Visible = true;
                gvAccountReport.DataSource = ds;
                gvAccountReport.DataBind();
                btnDownload.Visible = true;
                btn_Submit.Visible = false;
                GridViewRegUser.Visible = false;
                GridViewAmountReport.Visible = false;
                GridViewSMSPeport.Visible = false;
                GridViewAccountStatement.Visible = false;
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }            
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void FundReport()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                //new SqlParameter("@TransactionReporType",ddl_FundReport.SelectedItem.Text),
                new SqlParameter("@TransactionReporType","Admin Fund Report"),
                new SqlParameter("@Date",txtFrmDate.Text.Trim()),
                new SqlParameter("@DateTo",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_GET_AMOUNT_REQUEST_PARTNER", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridViewAmountReport.Visible = true;
                GridViewAmountReport.DataSource = ds;
                GridViewAmountReport.DataBind();
                btnDownload.Visible = true;
                btn_Submit.Visible = false;
                GridViewRegUser.Visible = false;
                gvAccountReport.Visible = false;
                GridViewSMSPeport.Visible = false;
                GridViewAccountStatement.Visible = false;
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void RegistrationReport()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@UserType",ddl_UserRegistration.SelectedItem.Text),
                new SqlParameter("@Date",txtFrmDate.Text.Trim()),
                new SqlParameter("@DateTo",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_getregisteredUser", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridViewRegUser.Visible = true;                
                GridViewRegUser.DataSource = ds;
                GridViewRegUser.DataBind();
                btnDownload.Visible = true;
                btn_Submit.Visible = false;
                GridViewAmountReport.Visible = false;
                gvAccountReport.Visible = false;
                GridViewSMSPeport.Visible = false;
                GridViewAccountStatement.Visible = false;
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void AccountStatement()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@loginid",ddl_AccountStatement.SelectedValue.Trim()),
                new SqlParameter("@Fromdate",txtFrmDate.Text.Trim()),
                new SqlParameter("@Todate",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "USP_ALLTRANSACTIONNew", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                GridViewAccountStatement.Visible = true;
                GridViewAccountStatement.DataSource = ds;
                GridViewAccountStatement.DataBind();
                btnDownload.Visible = true;
                btn_Submit.Visible = false;
                GridViewAmountReport.Visible = false;
                gvAccountReport.Visible = false;
                GridViewSMSPeport.Visible = false;
                GridViewRegUser.Visible = false;
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void SMSReport()
    {
        SqlParameter[] param = new SqlParameter[]
        {
            new SqlParameter("@fromdate",txtFrmDate.Text.Trim()),
            new SqlParameter("@todate",txtToDate.Text.Trim())
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_get_SMSTransactions", param);
        if (ds.Tables[0].Rows.Count > 0)
        {
            GridViewSMSPeport.Visible = true;
            GridViewSMSPeport.DataSource = ds;
            GridViewSMSPeport.DataBind();
            btnDownload.Visible = true;
            btn_Submit.Visible = false;
            GridViewAmountReport.Visible = false;
            gvAccountReport.Visible = false;
            GridViewRegUser.Visible = false;
        }
    }

    public void PanCardReport()
    {
        SqlParameter[] param = new SqlParameter[]
        {
            new SqlParameter("@FromDate",txtFrmDate.Text.Trim()),
            new SqlParameter("@ToDate",txtToDate.Text.Trim()),
            new SqlParameter("@Type",ddl_PanReport.SelectedValue)
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_GetRefundTxnRequest", param);
        if (ds.Tables[0].Rows.Count > 0)
        {
            gv_PancardReport.Visible = true;
            gv_PancardReport.DataSource = ds;
            gv_PancardReport.DataBind();
            btnDownload.Visible = true;
            btn_Submit.Visible = false;
            GridViewSMSPeport.Visible = false;
            GridViewAmountReport.Visible = false;
            gvAccountReport.Visible = false;
            GridViewRegUser.Visible = false;
        }
    }

    public void DMRReport()
    {
        SqlParameter[] param = new SqlParameter[]
        {
            new SqlParameter("@fromdate",txtFrmDate.Text.Trim()),
            new SqlParameter("@todate",txtToDate.Text.Trim())
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Admin_Report_For_DMR", param);
        if (ds.Tables[0].Rows.Count > 0)
        {
            gvAccountReport.Visible = true;
            gvAccountReport.DataSource = ds;
            gvAccountReport.DataBind();
            btnDownload.Visible = true;
            btn_Submit.Visible = false;
            GridViewSMSPeport.Visible = false;
            GridViewAmountReport.Visible = false;
            gv_PancardReport.Visible = false;
            GridViewRegUser.Visible = false;
        }
    }
    public void FlightReport()
    {
        SqlParameter[] param = new SqlParameter[]
        {
            new SqlParameter("@fromdate",txtFrmDate.Text.Trim()),
            new SqlParameter("@todate",txtToDate.Text.Trim())
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Admin_Report_For_Flight", param);
        if (ds.Tables[0].Rows.Count > 0)
        {
            gvAccountReport.Visible = true;
            gvAccountReport.DataSource = ds;
            gvAccountReport.DataBind();
            btnDownload.Visible = true;
            btn_Submit.Visible = false;
            GridViewSMSPeport.Visible = false;
            GridViewAmountReport.Visible = false;
            gv_PancardReport.Visible = false;
            GridViewRegUser.Visible = false;
        }
    }
    public void getuser()
    {
        SqlParameter[] param = new SqlParameter[]
        {};
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_login_details", param);
        if (ds.Tables[0].Rows.Count != 0)
        {
            ddl_AccountStatement.DataSource = ds;
            ddl_AccountStatement.DataTextField = "USERNAME";
            ddl_AccountStatement.DataValueField = "LOGINID";
            ddl_AccountStatement.Items.Clear();
            ddl_AccountStatement.Items.Insert(0, new ListItem("Select User Name", "Select User Name"));
            ddl_AccountStatement.DataBind();
        }
    }

    protected void gvAccountReport_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ColumnAmount += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Amount"));
                ColumnMargin += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Margin"));
                ColumnNetAmount = (ColumnAmount - ColumnMargin);
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[7].Text = "Total Rs:";
                e.Row.Cells[8].Text = ColumnAmount.ToString();
                e.Row.Cells[9].Text = ColumnMargin.ToString();
                e.Row.Cells[10].Text = ColumnNetAmount.ToString();
                e.Row.Cells[8].HorizontalAlign = HorizontalAlign.Left;
                e.Row.Cells[9].HorizontalAlign = HorizontalAlign.Left;
                e.Row.Cells[10].HorizontalAlign = HorizontalAlign.Left;
                e.Row.Font.Bold = true;
            }
        }
        catch (Exception ex)
        {
            //lblerror.Text = "error=" + ex;
        }
    }

    protected void btnDownload_Click(object sender, EventArgs e)
    {
        try
        {
            if (ddl_Report_Type.SelectedItem.Text == "Transaction Report")
            {
                TransactionReportD();
            }
            else if (ddl_Report_Type.SelectedItem.Text == "Fund Report")
            {
                FundReportD();
            }
            else if (ddl_Report_Type.SelectedItem.Text == "User Registration Report")
            {
                RegistrationReportD();
            }
            else if (ddl_Report_Type.SelectedItem.Text == "Account Statement")
            {
                AccountStatementD();
            }
            else if (ddl_Report_Type.SelectedItem.Text == "SMS Report")
            {
                SMSReportD();
            }
            else if (ddl_Report_Type.SelectedItem.Text == "Cancle Txn Report")
            {
                PanCardReportD();
            }
            else if (ddl_Report_Type.SelectedItem.Text == "Money Transfer Report")
            {
                DMRReportD();
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }

    public void TransactionReportD()
    {
        try
        {

            SqlParameter[] param = new SqlParameter[]
            {
                //new SqlParameter("@TransactionReporType",ddl_Report.SelectedItem.Text),
                new SqlParameter("@TransactionReporType","Recharge Transaction"),
                new SqlParameter("@Date",txtFrmDate.Text.Trim()),
                new SqlParameter("@DateTo",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_get_transactions_All_Type", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                btn_Submit.Visible = false;
                btnDownload.Visible = true;
                DataTable dtEmployee = ds.Tables["Table"].Copy();
                int[] iColumns = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
                RKLib.ExportData.Export objExport = new
                RKLib.ExportData.Export("Web");
                objExport.ExportDetails(dtEmployee,
                iColumns, Export.ExportFormat.CSV,
                "C:\\TransactionReport.csv");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void FundReportD()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                //new SqlParameter("@TransactionReporType",ddl_FundReport.SelectedItem.Text),
                new SqlParameter("@TransactionReporType","Admin Fund Report"),
                new SqlParameter("@Date",txtFrmDate.Text.Trim()),
                new SqlParameter("@DateTo",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_GET_AMOUNT_REQUEST_PARTNER", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                btn_Submit.Visible = false;
                btnDownload.Visible = true;
                DataTable dtEmployee = ds.Tables["Table"].Copy();
                int[] iColumns = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
                RKLib.ExportData.Export objExport = new
                RKLib.ExportData.Export("Web");
                objExport.ExportDetails(dtEmployee,
                iColumns, Export.ExportFormat.CSV,
                "C:\\FundReport.csv");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void RegistrationReportD()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@UserType",ddl_UserRegistration.SelectedItem.Text),
                new SqlParameter("@Date",txtFrmDate.Text.Trim()),
                new SqlParameter("@DateTo",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_getregisteredUser", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                btn_Submit.Visible = false;
                btnDownload.Visible = true;
                DataTable dtEmployee = ds.Tables["Table"].Copy();
                int[] iColumns = { 0, 1, 2, 3, 4, 5, 6, 7,8,9,10,11,12,13 };
                RKLib.ExportData.Export objExport = new
                RKLib.ExportData.Export("Web");
                objExport.ExportDetails(dtEmployee,
                iColumns, Export.ExportFormat.CSV,
                "C:\\RegistrationReport.csv");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void AccountStatementD()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@loginid",ddl_AccountStatement.SelectedValue.Trim()),
                new SqlParameter("@Fromdate",txtFrmDate.Text.Trim()),
                new SqlParameter("@Todate",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "USP_ALLTRANSACTIONNew", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                btn_Submit.Visible = false;
                btnDownload.Visible = true;
                DataTable dtEmployee = ds.Tables["Table"].Copy();
                int[] iColumns = { 0, 1, 2, 3, 4,5,6,7,8,9,10,11,12,13 };
                RKLib.ExportData.Export objExport = new
                RKLib.ExportData.Export("Web");
                objExport.ExportDetails(dtEmployee,
                iColumns, Export.ExportFormat.CSV,
                "C:\\UserAccountSummery.csv");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void SMSReportD()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@fromdate",txtFrmDate.Text.Trim()),
                new SqlParameter("@todate",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_get_SMSTransactions_of_partners_acc_date", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                btn_Submit.Visible = false;
                btnDownload.Visible = true;
                DataTable dtEmployee = ds.Tables["Table"].Copy();
                int[] iColumns = { 0, 1, 2, 3 };
                RKLib.ExportData.Export objExport = new
                RKLib.ExportData.Export("Web");
                objExport.ExportDetails(dtEmployee,
                iColumns, Export.ExportFormat.CSV,
                "C:\\SMSReport.csv");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }


    public void PanCardReportD()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
               {
                    new SqlParameter("@FromDate",txtFrmDate.Text.Trim()),
                    new SqlParameter("@ToDate",txtToDate.Text.Trim()),
                     new SqlParameter("@Type",ddl_PanReport.SelectedValue)
               };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_GetRefundTxnRequest", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                btn_Submit.Visible = false;
                btnDownload.Visible = true;
                DataTable dtEmployee = ds.Tables["Table"].Copy();
                int[] iColumns = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
                RKLib.ExportData.Export objExport = new
                RKLib.ExportData.Export("Web");
                objExport.ExportDetails(dtEmployee,
                iColumns, Export.ExportFormat.CSV,
                "C:\\CancleTxn.csv");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    public void DMRReportD()
    {
        try
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@fromdate",txtFrmDate.Text.Trim()),
                new SqlParameter("@todate",txtToDate.Text.Trim())
            };
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Admin_Report_For_DMR", param);
            if (ds.Tables[0].Rows.Count > 0)
            {
                btn_Submit.Visible = false;
                btnDownload.Visible = true;
                DataTable dtEmployee = ds.Tables["Table"].Copy();
                int[] iColumns = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
                RKLib.ExportData.Export objExport = new
                RKLib.ExportData.Export("Web");
                objExport.ExportDetails(dtEmployee,
                iColumns, Export.ExportFormat.CSV,
                "C:\\MoneyTransferReport.csv");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Data not availabel');"), true);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem.Please try again');"), true);
        }
    }

    //protected void ddl_Report_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    btnDownload.Visible = false;
    //    gvAccountReport.Visible = false;
    //    GridViewAmountReport.Visible = false;
    //    GridViewRegUser.Visible = false;
    //    GridViewSMSPeport.Visible = false;
    //    GridViewAccountStatement.Visible = false;
    //    txtFrmDate.Text = "";
    //    txtToDate.Text = "";
    //}

    //protected void ddl_FundReport_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    btnDownload.Visible = false;
    //    gvAccountReport.Visible = false;
    //    GridViewAmountReport.Visible = false;
    //    GridViewRegUser.Visible = false;
    //    GridViewSMSPeport.Visible = false;
    //    GridViewAccountStatement.Visible = false;
    //    txtFrmDate.Text = "";
    //    txtToDate.Text = "";
    //}

    protected void ddl_UserRegistration_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnDownload.Visible = false;
        gvAccountReport.Visible = false;
        GridViewAmountReport.Visible = false;
        GridViewRegUser.Visible = false;
        GridViewSMSPeport.Visible = false;
        GridViewAccountStatement.Visible = false;
        txtFrmDate.Text = "";
        txtToDate.Text = "";
    }
    protected void ddl_AccountStatement_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnDownload.Visible = false;
        gvAccountReport.Visible = false;
        GridViewAmountReport.Visible = false;
        GridViewRegUser.Visible = false;
        GridViewSMSPeport.Visible = false;
        GridViewAccountStatement.Visible = false;
        txtFrmDate.Text = "";
        txtToDate.Text = "";
    }
    protected void btnref_Click(object sender, EventArgs e)
    {
        try
        {
            btnDownload.Visible = false;
            gvAccountReport.Visible = false;
            GridViewAmountReport.Visible = false;
            GridViewRegUser.Visible = false;
            GridViewSMSPeport.Visible = false;
            GridViewAccountStatement.Visible = false;
            txtFrmDate.Text = "";
            txtToDate.Text = "";
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }

    protected void gv_PancardReport_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ImageButton btnImage = (ImageButton)e.Row.FindControl("btnImage");
            DataRowView dr = (DataRowView)e.Row.DataItem;
            string imageUrl = "data:image/jpg;base64," + Convert.ToBase64String((byte[])dr["ImageData"]);
            btnImage.ImageUrl= imageUrl;
            Image1.ImageUrl= imageUrl;
            //img.ImageUrl= imageUrl;
        }
    }
}
