private static ExportFormatType GetExportFormatType(ParamReport paramReport)
        {
            ExportFormatType formatType;

            switch (paramReport.FormatType)
            {
            case ReportType.Pdf:
                formatType = ExportFormatType.PortableDocFormat;
                break;

            case ReportType.Word:
                formatType = ExportFormatType.WordForWindows;
                break;

            case ReportType.Excel:
                formatType = ExportFormatType.Excel;
                break;

            default:
                formatType = ExportFormatType.PortableDocFormat;
                break;
            }

            return(formatType);
        }
        private static string GetFileExt(ParamReport paramReport)
        {
            var filename = Guid.NewGuid().ToString();

            switch (paramReport.FormatType)
            {
            case ReportType.Pdf:
                filename += ".pdf";
                break;

            case ReportType.Word:
                filename += ".doc";
                break;

            case ReportType.Excel:
                filename += ".xls";
                break;

            default:
                filename += ".pdf";
                break;
            }

            return(filename);
        }
        private void ExportReport(ParamReport paramReport)
        {
            var conInfo = new ConnectionInfo
            {
                ServerName   = _builder.DataSource,
                DatabaseName = _builder.InitialCatalog,
                UserID       = _builder.UserID,
                Password     = _builder.Password
            };

            using (var rd = new ReportDocument())
            {
                rd.Load(Path.Combine(Server.MapPath("~/Reports"), paramReport.ReportName));

                rd.DataSourceConnections[0]
                .SetConnection(conInfo.ServerName, conInfo.DatabaseName, conInfo.UserID, conInfo.Password);

                if (paramReport.Parameters.Any())
                {
                    foreach (var param in paramReport.Parameters)
                    {
                        rd.SetParameterValue(param.Key, param.Value);
                    }
                }

                var formatType = GetExportFormatType(paramReport);

                var path = Path.Combine(Server.MapPath("~/Reports/tmp"), GetFileExt(paramReport));

                rd.ExportToDisk(formatType, path);
            }
        }
示例#4
0
        public ActionResult PrintBM02(ParamReport model)
        {
            ReportViewer reportViewer = new ReportViewer();

            //if (model != null)
            //{
            //    reportViewer.ProcessingMode = ProcessingMode.Local;
            //    reportViewer.SizeToReportContent = true;
            //    reportViewer.Width = Unit.Percentage(1800);
            //    reportViewer.Height = Unit.Percentage(1800);
            //    reportViewer.ShowPrintButton = true;
            //    List<rptBM02_Result> lst = db.rptBM02(Convert.ToDateTime(model.TuNgay), Convert.ToDateTime(model.DenNgay), model.MaDonVi).ToList();

            //    //DateTime? ngayphathien = lst.First().NgayPhatHien;
            //    //DM_DONVI a = db.DM_DONVI.Where(b => b.MA_DVIQLY == madv).First();
            //    //string c = "";
            //    //if (a.MA_DVIQLY.Length > 4)
            //    //{
            //    //    c = a.TEN_DVIQLY;
            //    //}
            //    reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", lst));

            //    reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\BM02.rdlc";

            //    ViewBag.ReportViewer = reportViewer;
            //    //ViewBag.Model = new SelectList(db.DM_DONVI, "MA_DVIQLY", "TEN_DVIQLY");
            //}

            return(PartialView("Print"));
        }
示例#5
0
        protected override Control CreateUIControl()
        {
            ParamReport paramReport = new ParamReport();

            paramReport.ParameterName = base.DisplayName;
            this.UpdateUIControl(paramReport);
            return(paramReport);
        }
示例#6
0
        protected override void UpdateUIControl(Control control)
        {
            ParamReport paramReport = (ParamReport)control;

            if (!string.IsNullOrEmpty(this.ValidationName))
            {
                paramReport.ParameterName = base.DisplayName + ": " + this.ValidationName;
            }
            paramReport.UpdateUI(this.m_value);
        }
        public ActionResult GetReport(ParamReport paramReport)
        {
            var fileName = GetFileExt(paramReport);

            try
            {
                if (!ModelState.IsValid)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                Task.Factory.StartNew(() => { ExportReport(paramReport); });

                var returnPath = $"Reports/tmp/{fileName}";

                return(new ContentResult {
                    Content = $"<a href=\"${returnPath}\">File</a>"
                });
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.InnerException?.Message ?? ex.Message));
            }
        }
示例#8
0
        public ActionResult PrintBM04(ParamReport model)
        {
            ReportViewer reportViewer = new ReportViewer();

            //if (model != null)
            //{
            //    reportViewer.ProcessingMode = ProcessingMode.Local;
            //    reportViewer.SizeToReportContent = true;
            //    reportViewer.Width = Unit.Percentage(1800);
            //    reportViewer.Height = Unit.Percentage(1800);
            //    reportViewer.ShowPrintButton = true;
            //    List<rptBM04_Result> lst = db.rptBM04(Convert.ToDateTime(model.TuNgay), Convert.ToDateTime(model.DenNgay), model.MaDonVi).ToList();


            //    reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", lst));

            //    reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\BM04.rdlc";

            //    ViewBag.ReportViewer = reportViewer;
            //    //ViewBag.Model = new SelectList(db.DM_DONVI, "MA_DVIQLY", "TEN_DVIQLY");
            //}

            return(PartialView("Print"));
        }