Example #1
0
        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (!IsPostBack)
        //        {
        //            DateTime Sdt = Convert.ToDateTime(Request.QueryString["startdate"].ToString());
        //            DateTime Edt = Convert.ToDateTime(Request.QueryString["enddate"].ToString());
        //            int useridd = Convert.ToInt32(Request.QueryString["userid"].ToString());
        //            ReportViewer1.Reset();
        //            ReportViewer1.LocalReport.ReportPath = "Report/empReport.rdlc";
        //            ReportViewer1.LocalReport.SetParameters(new ReportParameter("EmpID", useridd.ToString()));
        //            ReportViewer1.LocalReport.DataSources.Clear();
        //            ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", objEmpModelService.GetEmployeeAttendanceInfo(useridd, Sdt, Edt)));
        //            ReportViewer1.DataBind();

        //            this.ReportViewer1.LocalReport.Refresh();
        //        }
        //        ReportViewer1.Drillthrough += new DrillthroughEventHandler(ReportViewer1_Drillthrough); ;
        //    }
        //    catch (Exception ex)
        //    {
        //    }
        //}

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    DateTime Sdt    = Convert.ToDateTime(Request.QueryString["startdate"].ToString());
                    DateTime Edt    = Convert.ToDateTime(Request.QueryString["enddate"].ToString());
                    int      userid = Convert.ToInt32(Request.QueryString["userid"].ToString());
                    ReportViewer1.Reset();
                    ReportViewer1.ShowPrintButton        = false;
                    ReportViewer1.LocalReport.ReportPath = "Report/mainreport.rdlc";
                    ReportViewer1.LocalReport.DataSources.Clear();
                    ReportViewer1.LocalReport.SetParameters(new ReportParameter("startdate", Sdt.ToString()));
                    ReportViewer1.LocalReport.SetParameters(new ReportParameter("enddate", Edt.ToString()));
                    ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", objEmpModelService.GetEmployeeInfo(userid)));
                    ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
                    ReportViewer1.DataBind();
                    this.ReportViewer1.LocalReport.Refresh();
                }
                ReportViewer1.Drillthrough += new DrillthroughEventHandler(ReportViewer1_Drillthrough);
            }
            catch (Exception ex)
            {
            }
        }
Example #2
0
        public void GenerateReport(ReportParam rp)
        {
            LocalReport lr   = new LocalReport();
            string      path = Path.Combine(Server.MapPath("~/Report"), "mainreport.rdlc");

            if (System.IO.File.Exists(path))
            {
                lr.ReportPath = path;
            }

            EmployeeModelService objEmpModelService = new EmployeeModelService();
            var    cm           = objEmpModelService.GetEmployeeInfo(rp.EmpListID);
            var    data         = cm.FirstOrDefault(x => x.Id == rp.EmpListID);
            var    employeename = data == null ? "All" : data.Name;
            string filename     = employeename + "_" + rp.StartDate.ToString("yyyyMMdd") + "_" + rp.EndDate.ToString("yyyyMMdd") + ".zip";

            using (var compressedFileStream = new MemoryStream())
            {
                //Create an archive and store the stream in memory.
                using (var zipArchive = new ZipArchive(compressedFileStream, ZipArchiveMode.Update, false))
                {
                    foreach (var user in cm.Select(x => new { id = x.Id, name = x.Name }).Distinct())
                    {
                        //Create a zip entry for each attachment
                        var zipEntry        = zipArchive.CreateEntry(user.name + ".pdf");
                        var dataset         = cm.Where(x => x.Id == user.id).ToList();
                        ReportDataSource rd = new ReportDataSource("DataSet1", dataset);
                        lr.SetParameters(new ReportParameter("startdate", rp.StartDate.ToString()));
                        lr.SetParameters(new ReportParameter("enddate", rp.EndDate.ToString()));
                        lr.DataSources.Clear();
                        lr.DataSources.Add(rd);
                        lr.SubreportProcessing += new SubreportProcessingEventHandler(Lr_SubreportProcessing);;
                        string reportType = "PDF";
                        string mimeType;
                        string encoding;
                        string fileNameExtension;

                        Warning[] warning;
                        string[]  streams;
                        byte[]    renderedBytes;

                        renderedBytes = lr.Render(
                            reportType,
                            null,
                            out mimeType,
                            out encoding,
                            out fileNameExtension,
                            out streams,
                            out warning);

                        //Get the stream of the attachment
                        using (var originalFileStream = new MemoryStream(renderedBytes))
                        {
                            using (var zipEntryStream = zipEntry.Open())
                            {
                                //Copy the attachment stream to the zip entry stream
                                originalFileStream.CopyTo(zipEntryStream);
                            }
                        }
                    }
                }
                sendOutZIP(compressedFileStream.ToArray(), filename);
            }
        }