Monday, February 16, 2015

RDLC report using xsd in c# with drill down report



using Microsoft.Reporting.WebForms;
using ImprisonmentTypeTableAdapters;
protected void Page_Load(object sender, EventArgs e)
    {
     
        String userAgent = Request.ServerVariables.Get("HTTP_USER_AGENT");
        if (userAgent.Contains("MSIE 7.0"))
        {
            ReportViewer1.Style.Add("margin-bottom", "30px");
        }
    }

protected void btnReport_Click(object sender, EventArgs e)
    {
        ViewState["level"] = 0;
        getReportData();
    }
    private void getReportData()
    {

        int JailCode = Convert.ToInt32(ddlJail.SelectedValue);
        int DistCode = Convert.ToInt32(ddlDistName.SelectedValue);
        Report_ImprisonmentTimeTableAdapter ta = new Report_ImprisonmentTimeTableAdapter();
        ImprisonmentType.Report_ImprisonmentTimeDataTable dt = new ImprisonmentType.Report_ImprisonmentTimeDataTable();

        try
        {
            ta.Fill(dt, Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue), Convert.ToInt32(ddlDay.SelectedValue), JailCode,DistCode);
        }
        catch
        {
            DataRow[] dr = null;
            dr = dt.GetErrors();
        }
        ReportViewer1.Visible = true;
        ReportDataSource rds = new ReportDataSource();
        ReportViewer1.Reset();
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        LocalReport rep = ReportViewer1.LocalReport;
        rep.Refresh();
        rep.ReportPath = "RDLCReport/rdlc/State_Prisoner_ImprisonmentTime.rdlc";



        rds.Name = "ImprisonmentType_Report_ImprisonmentTime";
        rds.Value = dt;
        rep.DataSources.Add(rds);


        ReportParameter[] parms = new ReportParameter[4];
        parms[0] = new ReportParameter("Year", ddlYear.SelectedValue, true);
        parms[1] = new ReportParameter("Month", ddlMonth.SelectedValue, true);
        parms[2] = new ReportParameter("Day", ddlDay.SelectedValue, true);
        parms[3] = new ReportParameter("JailName", ddlJail.SelectedItem.Text, true);
        this.ReportViewer1.LocalReport.SetParameters(parms);
        rep.Refresh();
    }


    protected void DemoDrillthroughEventHandler(object sender, DrillthroughEventArgs e)
    {
        try
        {
            if (ViewState["level"] != null)
            {
                int level = Convert.ToInt32(ViewState["level"]);
                ViewState["level"] = ++level;
                btnBack.Visible = true;
            }
            LocalReport localreport = (LocalReport)e.Report;
            ReportViewer1.Visible = true;
            ReportViewer1.Reset();
            ReportViewer1.ProcessingMode = ProcessingMode.Local;
            localreport.Refresh();
            ReportParameterInfoCollection DrillThroughValues = e.Report.GetParameters();
            string Year = DrillThroughValues["Year"].Values[0];
            string Month = DrillThroughValues["Month"].Values[0];
            string Day = DrillThroughValues["Day"].Values[0];
            string JailCode = DrillThroughValues["JailCode"].Values[0];

            Report_ImprisonmentTime_DrillTableAdapter ta = new Report_ImprisonmentTime_DrillTableAdapter();
            ImprisonmentType.Report_ImprisonmentTime_DrillDataTable dt = new ImprisonmentType.Report_ImprisonmentTime_DrillDataTable();
            try
            {
                ta.Fill(dt, Convert.ToInt32(Year), Convert.ToInt32(Month), Convert.ToInt32(Day), int.Parse(JailCode));
            }
            catch
            {
                DataRow[] dr = null;
                dr = dt.GetErrors();
            }
            ReportDataSource level1datasource = new ReportDataSource();
            localreport.ReportPath = "RDLCReport/rdlc/State_Prisoner_ImprisonmentTime_Drill.rdlc";
            level1datasource = new ReportDataSource("ImprisonmentType_Report_ImprisonmentTime_Drill", dt);
            localreport.DataSources.Clear();
            localreport.DataSources.Add(level1datasource);
            localreport.Refresh();
        }
        catch (Exception ex)
        {
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        if (ViewState["level"] != null)
        {
            int level = Convert.ToInt32(ViewState["level"]);
            if (level == 1)
            {
                getReportData();
                btnBack.Visible = false;
            }
            ViewState["level"] = --level;
        }
    }

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>


                    ShowPrintButton="true" Visible="false" ZoomMode="Percent" OnDrillthrough="DemoDrillthroughEventHandler" >
               





No comments:

Post a Comment

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...