Example #1
0
        private byte[] InternalGenerateReport(string reportFile, Dictionary <string, string> parameters)
        {
            FastReport.Report report = new FastReport.Report();
            report.Load(Path.Combine("Reports", reportFile));
            if (string.IsNullOrWhiteSpace(_appSettings.ConnectionString))
            {
                throw new NotSupportedException("Connectionstring não informada");
            }

            report.Dictionary.Connections[0].ConnectionString = _appSettings.ConnectionString;
            //report.SetParameterValue("initialDate", "2019-01-01");
            //report.SetParameterValue("finalDate", "2019-01-07");

            foreach (var parameter in parameters)
            {
                report.SetParameterValue(parameter.Key, parameter.Value);
            }

            report.Prepare();

            // report.Parameters[0].Value = 143;
            //report.Refresh();

            PDFSimpleExport export = new PDFSimpleExport();

            using (MemoryStream ms = new MemoryStream())
            {
                report.Export(export, ms);
                ms.Flush();
                return(ms.ToArray());
            }
        }
        public ActionResult getReport(string from, string to, string prod)
        {
            string    lang = Session["T_LANG"].ToString();
            DataTable dt   = repository.getReport(lang, from, to, prod);

            dt.TableName = "R12016";
            //dt.WriteXmlSchema(Server.MapPath("~/Report/xml/R12016.xml"));
            //return View();
            using (var Report = new FastReport.Report())
            {
                Report.Report.Load(Server.MapPath("~/Report/Report/R12016.frx"));
                Report.Report.RegisterData(dt, "R12016");
                Report.Report.Prepare();
                using (var strm = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    Report.Export(pdfExport, strm);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(strm.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = Report;
            }

            return(View());
        }
Example #3
0
        public static void GenereteReport(ReportParams reportParams)
        {
            if (reportParams == null)
            {
                throw new ArgumentNullException($"{nameof(reportParams)} cannot be null.");
            }

            // create report instance
            using (FastReport.Report report = new FastReport.Report())
            {
                // load the existing report
                report.Load(reportParams.FrxPath);

                // register datasource's
                if (reportParams.DataSource != null)
                {
                    foreach (var pair in reportParams.DataSource)
                    {
                        report.RegisterData(pair.Value, pair.Key);
                    }
                }

                if (reportParams.Parameters != null)
                {
                    foreach (var pair in reportParams.Parameters)
                    {
                        report.SetParameterValue(pair.Key, pair.Value);
                    }
                }

                // prepare the report
                report.Prepare();

                ExportBase export = null;
                switch (reportParams.OutputType)
                {
                case 0:     // export to html
                    export = new HTMLExport();
                    (export as HTMLExport).Format = HTMLExportFormat.HTML;
                    break;

                case 1:
                    export = new ImageExport();
                    (export as ImageExport).ImageFormat = ImageExportFormat.Png;
                    break;

                default:
                    throw new ArgumentException($"O parametro {reportParams.OutputType} é inválido");
                }

                report.Export(export, reportParams.OutStream);
            }

            reportParams.OutStream.Position = 0;
        }
        //getDate
        public ActionResult getReport(string fromDate, string toDate)
        {
            var    site = Session["T_SITE_CODE"].ToString();
            string lang = Session["T_LANG"].ToString();

            DataTable dtInfor   = repository.GetInforData(site, lang);
            DataTable dtDetails = repository.GetDetails(site, fromDate, toDate);

            //DataTable dtUnitInfo = repository.GetR12215CollectedUnit(site, entryDate);

            dtInfor.TableName   = "R12260Infor";
            dtDetails.TableName = "R12260Details";
            // dtUnitInfo.TableName = "R12215UnitInfo";

            DataSet dSet = new DataSet();

            dSet.Tables.Add(dtInfor);
            dSet.Tables.Add(dtDetails);
            // dSet.Tables.Add(dtUnitInfo);


            // dSet.WriteXmlSchema(Server.MapPath("~/Report/xml/R12260.xml"));

            // return View();
            using (var webReport = new FastReport.Report())
            {
                webReport.Report.Load(Server.MapPath("~/Report/Report/R12260.frx"));
                //webReport.Report.Load(Server.MapPath("~/Report/Report/R12260_Test.frx"));
                webReport.RegisterData(dtInfor, "R12260Infor");
                webReport.RegisterData(dtDetails, "R12260Details");
                webReport.Report.SetParameterValue("FromDate", fromDate);
                webReport.Report.SetParameterValue("ToDate", toDate);
                // webReport.RegisterData(dtUnitInfo, "R12215UnitInfo");

                webReport.Report.Prepare();

                using (var report = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    webReport.Export(pdfExport, report);

                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(report.ToArray());
                    Response.End();
                }

                ViewBag.ReportR12215 = webReport;
            }

            return(View());
        }
        public ActionResult getR12065_Report(string patno)
        {
            // string siteCode = Session["T_SITE_CODE"].ToString();
            DataTable dt = repository.getR12065_Report(patno);


            dt.TableName = "R12065";
            //dt_1.TableName = "R12302_xmatchHistory";
            //T12302_Site_.TableName = "R12302_Site";

            // DataSet ds = new DataSet();
            // ds.Tables.Add(dt);
            // ds.Tables.Add(dt_1);
            //ds.Tables.Add(T12302_Site_);
            //foreach (DataTable V in dt.Rows)
            //{

            //}
            //----------- for barcode start-----------------
            dt.Columns.Add("Pat_BarCode", typeof(Bitmap));
            Image myimg = Code128Rendering.MakeBarcodeImage(dt.Rows[0]["T_UNIT_NO"].ToString(), int.Parse("2"), true);

            dt.Rows[0]["Pat_BarCode"] = myimg;
            //----------- for barcode end-----------------


            //dt.WriteXmlSchema(Server.MapPath("~/Report/xml/R12065.xml"));
            // return View();
            using (var Report = new FastReport.Report())
            {
                Report.Report.Load(Server.MapPath("~/Report/Report/R12065.frx"));
                System.Data.DataSet dataSet = new System.Data.DataSet();
                Report.Report.RegisterData(dt, "R12065");

                //Report.Report.RegisterData(dt_1, "R12302_xmatchHistory");
                // Report.Report.RegisterData(T12302_Site_, "R12302_Site");
                Report.Report.Prepare();
                using (var strm = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    Report.Export(pdfExport, strm);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(strm.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = Report;
            }

            return(View());
        }
        public ActionResult UNIT_Report_R12219(string entryDate)
        {
            int    site = Convert.ToInt32(Session["T_SITE_CODE"].ToString());
            string lang = Session["T_LANG"].ToString();

            DataTable dtSite     = repository_R12215.GetR12215SiteCode(site, lang);
            DataTable dtSummery  = repository_R12215.GetR12215Summery(entryDate, site, entryDate);
            DataTable dtUnitInfo = repository_R12215.GetR12215CollectedUnit(site, entryDate);

            dtSite.TableName     = "R12215Site";
            dtSummery.TableName  = "R12215Summery";
            dtUnitInfo.TableName = "R12215UnitInfo";

            DataSet dSet = new DataSet();

            dSet.Tables.Add(dtSite);
            dSet.Tables.Add(dtSummery);
            dSet.Tables.Add(dtUnitInfo);


            //dSet.WriteXmlSchema(Server.MapPath("~/Report/xml/R12215.xml"));


            using (var webReport = new FastReport.Report())
            {
                webReport.Report.Load(Server.MapPath("~/Report/Report/R12215.frx"));

                webReport.RegisterData(dtSite, "R12215Site");
                webReport.RegisterData(dtSummery, "R12215Summery");
                webReport.RegisterData(dtUnitInfo, "R12215UnitInfo");

                webReport.Report.Prepare();

                using (var report = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    webReport.Export(pdfExport, report);

                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(report.ToArray());
                    Response.End();
                }

                ViewBag.ReportR12215 = webReport;
            }

            return(View());
        }
        //------------------------------------Report----------------------------
        public ActionResult getR12046_Report(string reqno)
        {
            string site = Session["T_SITE_CODE"].ToString();
            string lang = Session["T_LANG"].ToString();

            DataTable dt_site   = repository.GetSite(site);
            DataTable dt_xMatch = repository.getR12046_xMatch(reqno, site, lang);
            DataTable dt_issue  = repository.getR12046_Issue(reqno, site, lang);

            dt_site.TableName   = "R12046_Site";
            dt_xMatch.TableName = "R12046";
            dt_issue.TableName  = "R12046i";


            DataSet ds = new DataSet();

            ds.Tables.Add(dt_site);
            ds.Tables.Add(dt_xMatch);
            ds.Tables.Add(dt_issue);


            //ds.WriteXmlSchema(Server.MapPath("~/Report/xml/R12046.xml"));


            using (var webReport = new FastReport.Report())
            {
                webReport.Report.Load(Server.MapPath("~/Report/Report/R12046.frx"));

                webReport.Report.RegisterData(dt_site, "R12046_Site");
                webReport.Report.RegisterData(dt_xMatch, "R12046");
                webReport.Report.RegisterData(dt_issue, "R12046i");


                webReport.Report.Prepare();
                using (var Report = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    webReport.Export(pdfExport, Report);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(Report.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = webReport;
            }

            return(View());
        }
        public ActionResult GetReport(string donTiFrom, string donTiTo, string siteCode, string bloodGrp, string product)
        {
            var dtT12025 = repository.GetReport(Session["T_LANG"].ToString(), donTiFrom, donTiTo, siteCode, bloodGrp, product);

            dtT12025.TableName = "T12025";

            //----------- for barcode start-----------------
            // dtT12025.Columns.Add("Pat_BarCode", typeof(Bitmap));
            // Image myimg = Code128Rendering.MakeBarcodeImage(dtT12204.Rows[0]["T_BAG_BARCODE"].ToString(), int.Parse("2"), true);
            //  dtT12025.Rows[0]["Pat_BarCode"] = myimg;
            //----------- for barcode end-----------------

            // dtT12204.Columns.Add("Time", typeof(string));
            //dtT12204.Rows[0]["Time"] = Session["Hou_Min"].ToString();

            // dtT12025.WriteXmlSchema(Server.MapPath("~/Report/xml/T12025.xml"));
            //  return View();
            using (var webReport = new FastReport.Report())
            {
                webReport.Report.Load(Server.MapPath("~/Report/Report/R12025.frx"));
                System.Data.DataSet dataSet = new System.Data.DataSet();
                webReport.Report.RegisterData(dtT12025, "T12025");
                webReport.Report.Prepare();
                using (var Report = new MemoryStream())
                {
                    // var excelExport = new Excel2007Export();
                    // webReport.Report.Export(excelExport, strm);
                    // var pdfExport = new PDFExport();
                    // webReport.Report.Export(pdfExport, strm);
                    // Response.ClearContent();
                    // Response.ClearHeaders();
                    // Response.Buffer = true;
                    //// Response.ContentType = "Application/vnd.ms-excel";
                    //  Response.ContentType = "Application/PDF";
                    // Response.BinaryWrite(strm.ToArray());
                    // Response.End();
                    var pdfExport = new PDFExport();
                    webReport.Export(pdfExport, Report);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(Report.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = webReport;
            }

            return(View());
        }
        public ActionResult TAT_Report_R12219(string dateFrom)
        {
            //string lang = Session["T_LANG"].ToString();
            //dt.TableName = "R12006";

            string site = Session["T_SITE_CODE"].ToString();
            string lang = Session["T_LANG"].ToString();
            //DataTable dt = repository.getReport(lang, patNo);
            DataTable dtReportInfo = repository.GetReportInfo();
            DataTable dtReportData = repository.GetReportData();

            dtReportInfo.TableName = "Table1";
            dtReportData.TableName = "Table2";

            DataSet ds = new DataSet();

            ds.DataSetName = "R12219";
            ds.Tables.Add(dtReportInfo);
            ds.Tables.Add(dtReportData);


            //ds.WriteXmlSchema(Server.MapPath("~/Report/xml/R12219.xml"));


            using (var webReport = new FastReport.Report())
            {
                webReport.Report.Load(Server.MapPath("~/Report/Report/R12219.frx"));

                webReport.Report.RegisterData(dtReportInfo, "Table1");
                webReport.Report.RegisterData(dtReportData, "Table2");


                webReport.Report.Prepare();
                using (var report = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    webReport.Export(pdfExport, report);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(report.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = webReport;
            }

            return(View());
        }
        //getR12036A_Report
        public ActionResult getR12012_Report(string reqno)
        {
            string    site    = Session["T_SITE_CODE"].ToString();
            string    lang    = Session["T_LANG"].ToString();
            DataTable dt      = repository.getR12012_Report(reqno, site, lang);
            DataTable dt_site = repository.GetSite(site);

            dt.TableName      = "R12012";
            dt_site.TableName = "R12012_site";

            DataSet ds = new DataSet();

            ds.Tables.Add(dt);
            ds.Tables.Add(dt_site);


            //ds.WriteXmlSchema(Server.MapPath("~/Report/xml/R12012.xml"));


            using (var webReport = new FastReport.Report())
            {
                webReport.Report.Load(Server.MapPath("~/Report/Report/R12012.frx"));

                webReport.Report.RegisterData(dt, "R12012");
                webReport.Report.RegisterData(dt_site, "R12012_site");


                var HijriDTFI = new CultureInfo("ar-SA", false).DateTimeFormat;
                HijriDTFI.Calendar = new HijriCalendar();
                webReport.SetParameterValue("RequestDate_H", Convert.ToDateTime(dt.Rows[0]["T_REQUEST_DATE"].ToString()).ToString("dd/MM/yyyy", HijriDTFI));

                webReport.Report.Prepare();
                using (var Report = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    webReport.Export(pdfExport, Report);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(Report.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = webReport;
            }

            return(View());
        }
        public ActionResult getReportxmatch(string patno)
        {
            string    siteCode     = Session["T_SITE_CODE"].ToString();
            DataTable dt           = repository.getPatInfo(patno);
            DataTable dt_1         = repository.geHistoryData(patno, siteCode);
            DataTable T12302_Site_ = repository.GetSite(siteCode);

            dt.TableName           = "R12302_xmatchinfo";
            dt_1.TableName         = "R12302_xmatchHistory";
            T12302_Site_.TableName = "R12302_Site";

            DataSet ds = new DataSet();

            ds.Tables.Add(dt);
            ds.Tables.Add(dt_1);
            ds.Tables.Add(T12302_Site_);
            //ds.WriteXmlSchema(Server.MapPath("~/Report/xml/R12302xmatch.xml"));
            //return View();
            using (var Report = new FastReport.Report())
            {
                Report.Report.Load(Server.MapPath("~/Report/Report/R12049.frx"));
                Report.Report.RegisterData(dt, "R12302_xmatchinfo");
                Report.Report.RegisterData(dt_1, "R12302_xmatchHistory");
                Report.Report.RegisterData(T12302_Site_, "R12302_Site");
                Report.Report.Prepare();
                using (var strm = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    Report.Export(pdfExport, strm);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(strm.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = Report;
            }

            return(View());
        }
Example #12
0
        public static void Print(DataSet dsData, string frxPath, string path)
        {
            FastReport.Report report = new FastReport.Report();
            report.RegisterData(dsData);
            using (FileStream fs = new FileStream(frxPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                report.Load(fs);
            }
            report.Prepare();

            PDFExport export = new PDFExport();

            export.SetReport(report);
            export.Compressed      = true;
            export.Background      = false;
            export.PrintOptimized  = false;
            export.OpenAfterExport = false;
            export.EmbeddingFonts  = true;
            report.Export(export, path);
            report.Dispose();
        }
        public ActionResult GRAPH_Report_R12219(string dateFrom)
        {
            //string lang = Session["T_LANG"].ToString();
            //DataTable dt = repository.getReport(lang, nationalId);
            //dt.TableName = "R12006";

            string site = Session["T_SITE_CODE"].ToString();
            string lang = Session["T_LANG"].ToString();

            //DataTable dt = repository.getReport(lang, patNo);
            //DataTable dtSite = repository.GetR12006Site(site);
            //DataTable dtProfile = repository.GetR12006PatProfile(lang, patNo);

            //DataTable dtAgreement = repository.GetR12006Agreement(lang, patNo);
            //DataTable dtConfirmation = repository.GetR12006Confirmation(lang);


            //dt.TableName = "R12006_Ques";
            //dtSite.TableName = "R12006_Site";
            //dtProfile.TableName = "R12006_Profile";
            //dtAgreement.TableName = "R12006_Agreement";
            ////dtConfirmation.TableName = "R12006_Confirmation";

            //DataSet ds = new DataSet();
            //ds.Tables.Add(dt);
            //ds.Tables.Add(dtSite);
            //ds.Tables.Add(dtProfile);
            //ds.Tables.Add(dtAgreement);
            ////ds.Tables.Add(dtConfirmation);

            ////ds.WriteXmlSchema(Server.MapPath("~/Report/xml/R12251A.xml"));


            using (var webReport = new FastReport.Report())
            {
                webReport.Report.Load(Server.MapPath("~/Report/Report/R12219.frx"));

                //webReport.Report.RegisterData(dtSite, "R12006_Site");
                //webReport.Report.RegisterData(dt, "R12006_Ques");
                //webReport.Report.RegisterData(dtProfile, "R12006_Profile");
                //webReport.Report.RegisterData(dtAgreement, "R12006_Agreement");
                //webReport.Report.RegisterData(dtConfirmation, "R12006_Confirmation");


                webReport.Report.Prepare();
                using (var report = new MemoryStream())
                {
                    var pdfExport = new PDFExport();
                    webReport.Export(pdfExport, report);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(report.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = webReport;
            }

            return(View());
        }
Example #14
0
        public static string GetReportString(string reportFilePath, string dataSetName, IEnumerable <object> data, string exportFormat)
        {
            FastReport.Report report = new FastReport.Report();
            string            result = string.Empty;

            if (FileHelper.IsExistFile(reportFilePath))
            {
                try
                {
                    report.Load(reportFilePath);            // Download the report
                    report.RegisterData(data, dataSetName); // Register data in the report
                }
                catch
                {
                    //var log = LogFactory.GetLogger("FastReportHelper");
                    //log.Error(ex.Message);
                    return(result);
                }
                using (MemoryStream stream = new MemoryStream())
                {
                    if (exportFormat.Equals("pdf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //FastReport.Export.Pdf.PDFExport pdf = new FastReport.Export.Pdf.PDFExport {
                        //    Producer = "",
                        //    AllowPrint=true,
                        //    AllowModify=true,
                        //    PrintScaling=true,

                        //    RichTextQuality=100,
                        //    Compressed=false
                        //};
                        //report.Export(pdf, stream);

                        //FileHelper.CreateFile("\\log\\PDF" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg", stream.ToArray());
                    }
                    else if (exportFormat.Equals("Jpeg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat   = FastReport.Export.Image.ImageExportFormat.Jpeg,
                            SeparateFiles = false,
                            JpegQuality   = 100
                        };
                        report.Prepare();
                        report.Export(image, stream);
                        FileHelper.CreateFile("\\log\\JPG" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg", stream.ToArray());

                        //foreach (var item in image.GeneratedFiles)
                        //{
                        //    var temp = item;
                        //    var log = LogFactory.GetLogger("FastReportHelper");
                        //    log.Info(temp);
                        //}
                        //return report.SaveToStringBase64();
                    }
                    else if (exportFormat.Equals("Bmp", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat = FastReport.Export.Image.ImageExportFormat.Bmp
                        };
                        report.Prepare();
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Gif", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat = FastReport.Export.Image.ImageExportFormat.Gif
                        };
                        report.Prepare();
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Png", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat   = FastReport.Export.Image.ImageExportFormat.Png,
                            SeparateFiles = false
                        };
                        report.Prepare();
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Tiff", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat = FastReport.Export.Image.ImageExportFormat.Tiff
                        };
                        report.Prepare();
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("html", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Html.HTMLExport image = new FastReport.Export.Html.HTMLExport
                        {
                            EnableMargins = false,
                            Pictures      = true,
                            EmbedPictures = true,
                            ImageFormat   = ImageFormat.Png
                        };
                        report.Prepare();
                        report.Export(image, stream);
                        return(System.Text.Encoding.UTF8.GetString(stream.ToArray()));
                    }


                    result = Convert.ToBase64String(stream.ToArray());
                }
            }
            else
            {
                //var log = LogFactory.GetLogger("FastReportHelper");
                //log.Error(reportFilePath + ",目录不存在!");
            }
            return(result);
        }
Example #15
0
        public static Stream GetReportStream(string reportFilePath, string dataSetName, DataSet data, string exportFormat)
        {
            FastReport.Report report = new FastReport.Report();
            MemoryStream      result = new MemoryStream();

            if (FileHelper.IsExistFile(reportFilePath))
            {
                try
                {
                    report.Load(reportFilePath);            // Download the report
                    report.RegisterData(data, dataSetName); // Register data in the report
                }
                catch
                {
                    //var log = LogFactory.GetLogger("FastReportHelper");
                    return(result);
                }
                using (MemoryStream stream = new MemoryStream())
                {
                    if (exportFormat.Equals("pdf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //FastReport.Export.Pdf.PDFExport pdf = new FastReport.Export.Pdf.PDFExport();
                        //report.Export(pdf, stream);
                    }
                    else if (exportFormat.Equals("Jpeg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                        image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Jpeg;
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Bmp", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                        image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Bmp;
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Gif", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                        image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Gif;
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Png", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport();
                        image.ImageFormat = FastReport.Export.Image.ImageExportFormat.Png;
                        report.Export(image, stream);
                    }
                    else if (exportFormat.Equals("Tiff", StringComparison.InvariantCultureIgnoreCase))
                    {
                        FastReport.Export.Image.ImageExport image = new FastReport.Export.Image.ImageExport
                        {
                            ImageFormat = FastReport.Export.Image.ImageExportFormat.Tiff
                        };
                        report.Export(image, stream);
                    }
                    result = stream;
                }
            }
            else
            {
                //var log = LogFactory.GetLogger("FastReportHelper");
                //log.Error(reportFilePath + ",目录不存在!");
            }
            return(result);
        }
Example #16
0
        /// <summary>
        /// 导出
        /// </summary>
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtCompanyCode.Text))
            {
                MessageBox.Show("请选择公司。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (string.IsNullOrEmpty(txtFilePath.Text))
            {
                MessageBox.Show("请选择保存路径。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            BaseCompanyTable    companyTable  = bCompany.GetModel(txtCompanyCode.Text.Trim());
            BllOrderHeaderTable orderTable    = bOrderH.GetModel(_slipNumber);
            BaseCustomerTable   customerTable = bCustomer.GetModel(orderTable.ENDER_CUSTOMER_CODE);

            report.Preview = previewControl1;
            DataTable dt = new DataTable();

            dt.TableName = "ds";
            dt.Columns.Add("i", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("SPEC", System.Type.GetType("System.String"));
            dt.Columns.Add("QUANTITY", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("PRICE", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("DISCOUNT", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("AMOUNT", System.Type.GetType("System.Decimal"));
            dt.Columns.Add("MATERIAL", System.Type.GetType("System.String"));
            dt.Columns.Add("MEMO", System.Type.GetType("System.String"));
            dt.Columns.Add("DESCRIPTION", System.Type.GetType("System.String"));
            dt.Columns.Add("DESCRIPTION1", System.Type.GetType("System.String"));
            int j = 1;

            foreach (BllOrderLineTable lineModel in orderTable.Items)
            {
                if (lineModel.PRICE_DISCOUNT.ToString().Equals("0.00"))
                {
                    object[] rows = { j++, lineModel.SPEC, lineModel.QUANTITY, lineModel.PRICE, null, lineModel.AMOUNT, lineModel.METERIAL, lineModel.MEMO, lineModel.DESCRIPTION, lineModel.DESCRIPTION1 };

                    dt.Rows.Add(rows);
                }
                else
                {
                    object[] rows = { j++, lineModel.SPEC, lineModel.QUANTITY, lineModel.PRICE, 0 - lineModel.PRICE_DISCOUNT, lineModel.AMOUNT, lineModel.METERIAL, lineModel.MEMO, lineModel.DESCRIPTION, lineModel.DESCRIPTION1 };
                    dt.Rows.Add(rows);
                }
            }

            DataSet ds = new DataSet();

            ds.Tables.Add(dt);

            string fileName   = "";
            string amountName = "";

            if (CConstant.LANGUAGE_CN.Equals(cboLanguage.SelectedValue))
            {
                fileName   = @"Reports\Proforma_Invoice.frx";
                amountName = NumberConvert.NumberToEnglish(CConvert.ToString(orderTable.AMOUNT_INCLUDED_TAX), false);
            }
            else if (CConstant.LANGUAGE_EN.Equals(cboLanguage.SelectedValue))
            {
                fileName   = @"Reports\Order_EN.frx";
                amountName = NumberConvert.NumberToEnglish(CConvert.ToString(orderTable.AMOUNT_INCLUDED_TAX), false);
            }

            try
            {
                if (File.Exists(fileName))
                {
                    report.Load(fileName);
                    report.SetParameterValue("CompanyName", companyTable.NAME);
                    report.SetParameterValue("EnglishCompanyName", companyTable.NAME_ENGLISH);
                    report.SetParameterValue("CompanyTel", companyTable.PHONE_NUMBER);
                    report.SetParameterValue("CompanyFax", companyTable.FAX_NUMBER);
                    report.SetParameterValue("CompanyAddress", companyTable.ADDRESS_MIDDLE);
                    report.SetParameterValue("CompanyUrl", companyTable.URL);
                    report.SetParameterValue("CompanyEmail", companyTable.EMAIL);
                    report.SetParameterValue("SlipNumber", _slipNumber);
                    report.SetParameterValue("SlipDate", CConvert.ToDateTime(orderTable.SLIP_DATE).ToString("yyyy/MM/dd"));
                    report.SetParameterValue("Currency", orderTable.CURRENCY_NAME);
                    report.SetParameterValue("CustomerName", customerTable.NAME);
                    int COUNT = 0;
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        if (dr["DISCOUNT"].ToString() != "")
                        {
                            COUNT++;
                        }
                    }
                    if (COUNT > 0)
                    {
                        report.SetParameterValue("DISCOUNT", "Discount");
                    }

                    if (customerTable.PHONE_NUMBER.ToString() != "")
                    {
                        report.SetParameterValue("CustomerTel", "Tel:" + customerTable.PHONE_NUMBER);
                    }
                    if (customerTable.FAX_NUMBER.ToString() != "")
                    {
                        report.SetParameterValue("CustomerFax", "Fax:" + customerTable.FAX_NUMBER);
                    }
                    if (customerTable.ADDRESS_FIRST.ToString() != "")
                    {
                        report.SetParameterValue("CustomerAddress", "Address:" + customerTable.ADDRESS_FIRST);
                    }
                    report.SetParameterValue("CustomerMessage", txtMessage.Text);
                    report.SetParameterValue("DeliveryTerms", orderTable.DELIVERY_TERMS);
                    report.SetParameterValue("PaymentTerms", orderTable.PAYMENT_TERMS);
                    if (orderTable.DISCOUNT_RATE > 0)
                    {
                        report.SetParameterValue("DiscountRate", "-" + orderTable.DISCOUNT_RATE + "%");
                        report.SetParameterValue("DiscountAmount", orderTable.AMOUNT_INCLUDED_TAX);
                    }
                    report.SetParameterValue("AmountName", amountName);

                    report.SetParameterValue("FullNameEn", txtBankEn.Text);
                    report.SetParameterValue("DetailEn", rtxtDetail.Text);
                    if (companyTable.COMPANY_PICTURE != null)
                    {
                        MemoryStream ms    = new MemoryStream((byte[])companyTable.COMPANY_PICTURE);
                        Image        image = Image.FromStream(ms);
                        ((FastReport.PictureObject)report.FindObject("CompanyPicture")).Image = image;
                    }
                    if (companyTable.LOGO != null)
                    {
                        MemoryStream ms1    = new MemoryStream((byte[])companyTable.LOGO);
                        Image        image1 = Image.FromStream(ms1);
                        ((FastReport.PictureObject)report.FindObject("Logo")).Image = image1;
                    }
                    report.RegisterData(ds);
                    report.Prepare();
                    if (fileName.Equals(@"Reports\Proforma_Invoice.frx"))
                    {
                        report.Export(new FastReport.Export.Pdf.PDFExport(), this.txtFilePath.Text + "\\Proforma_Invoice" + _slipNumber + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf");
                    }
                    else
                    {
                        report.Export(new FastReport.Export.Pdf.PDFExport(), this.txtFilePath.Text + "\\Order_" + _slipNumber + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf");
                    }
                    MessageBox.Show("导出成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }

            catch (Exception ex)
            {
                Logger.Error("", ex);
            }
        }
        public HttpResponseMessage PostReport(JObject JsonRequest)
        {
            int    status = 0;
            string error  = "";

            try
            {
                String className  = "FastReport." + JsonRequest["ClassName"].ToString();
                string rootPath   = System.Environment.CurrentDirectory;
                string outputPath = Path.Combine(rootPath, "output.pdf");
                //FastReport.Report report = new FastReport.Report();
                //string filename = @"C:\Users\lipan\Desktop\report3.frx";
                //report.Load(filename);
                FastReport.Report report = (FastReport.Report)Activator.CreateInstance(System.Type.GetType(className));
                DataSet           data   = new DataSet();
                DataTable         table  = new DataTable();
                int num = 0;
                foreach (var item in JsonRequest)
                {
                    if (item.Key.StartsWith("ClassName"))
                    {
                        continue;
                    }
                    if (item.Key.StartsWith("Signature"))
                    {
                        DataTable dt = new DataTable();
                        dt.TableName = item.Key;
                        dt.Columns.Add(item.Key, typeof(byte[]));
                        WebClient wc = new WebClient();
                        byte[]    bytes;
                        if (item.Value.ToString() == "")
                        {
                            //此处留空时处理;
                            bytes = wc.DownloadData(Path.Combine(rootPath, "EmptySignature.PNG"));
                        }
                        else
                        {
                            bytes = wc.DownloadData(item.Value.ToString());
                        }
                        MemoryStream msIMG = new MemoryStream(bytes);
                        Image        img   = System.Drawing.Image.FromStream(msIMG);
                        //Image img = Image.FromFile(folderPath + item.Key + ".PNG");
                        DataRow      row = dt.NewRow();
                        MemoryStream ms  = new MemoryStream();
                        img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                        row[item.Key] = ms.ToArray();
                        dt.Rows.Add(row);
                        data.Tables.Add(dt);
                        continue;
                    }
                    table           = CSVHelper.ConvertJsonToDatatable(JsonRequest.ToString(), num);
                    table.TableName = item.Key;
                    data.Tables.Add(table);
                    num++;
                }
                report.RegisterData(data);
                int tableNum = data.Tables.Count;
                for (int i = 0; i < tableNum; i++)
                {
                    report.GetDataSource(data.Tables[i].TableName).Enabled = true;
                }
                report.Prepare();
                FastReport.Export.Pdf.PDFExport export = new FastReport.Export.Pdf.PDFExport();
                report.Export(export, outputPath);
                System.Diagnostics.Process.Start(outputPath);
            }
            catch (Exception e)
            {
                status = -1;
                error  = e.ToString();
            }

            String returnValue = JsonConvert.SerializeObject(new
            {
                status = status.ToString(), error = error
            });

            return(ResultToJson.toJson(returnValue));
        }
        public ActionResult getReportbloodGroup(string from, string to, string prod)
        {
            string    siteCode       = Session["T_SITE_CODE"].ToString();
            DataTable T12302_        = repository.GetReport(siteCode);
            DataTable T12302_PatInf_ = repository.GetPatInf();
            DataTable T12302_Site_   = repository.GetSite(siteCode);

            T12302_.TableName        = "R12302";
            T12302_PatInf_.TableName = "R12302_PatInf";
            T12302_Site_.TableName   = "R12302_Site";

            DataSet ds = new DataSet();

            ds.Tables.Add(T12302_);
            ds.Tables.Add(T12302_PatInf_);
            ds.Tables.Add(T12302_Site_);

            // dtT12302.TableName = "T12302";

            //----------- for barcode start-----------------
            // dtT12025.Columns.Add("Pat_BarCode", typeof(Bitmap));
            // Image myimg = Code128Rendering.MakeBarcodeImage(dtT12204.Rows[0]["T_BAG_BARCODE"].ToString(), int.Parse("2"), true);
            //  dtT12025.Rows[0]["Pat_BarCode"] = myimg;
            //----------- for barcode end-----------------

            // dtT12204.Columns.Add("Time", typeof(string));
            //dtT12204.Rows[0]["Time"] = Session["Hou_Min"].ToString();

            // ds.WriteXmlSchema(Server.MapPath("~/Report/xml/T12050.xml"));
            //  return View();
            using (var webReport = new FastReport.Report())
            {
                webReport.Report.Load(Server.MapPath("~/Report/Report/R12050.frx"));

                webReport.Report.RegisterData(T12302_, "R12302");
                webReport.Report.RegisterData(T12302_PatInf_, "R12302_PatInf");
                webReport.Report.RegisterData(T12302_Site_, "R12302_Site");

                // System.Data.DataSet dataSet = new System.Data.DataSet();
                //webReport.Report.RegisterData(dtT12302, "T12302");
                webReport.Report.Prepare();
                using (var Report = new MemoryStream())
                {
                    // var excelExport = new Excel2007Export();
                    // webReport.Report.Export(excelExport, strm);
                    // var pdfExport = new PDFExport();
                    // webReport.Report.Export(pdfExport, strm);
                    // Response.ClearContent();
                    // Response.ClearHeaders();
                    // Response.Buffer = true;
                    //// Response.ContentType = "Application/vnd.ms-excel";
                    //  Response.ContentType = "Application/PDF";
                    // Response.BinaryWrite(strm.ToArray());
                    // Response.End();
                    var pdfExport = new PDFExport();
                    webReport.Export(pdfExport, Report);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer      = true;
                    Response.ContentType = "Application/PDF";
                    Response.BinaryWrite(Report.ToArray());
                    Response.End();
                }
                ViewBag.WebReport = webReport;
            }

            return(View());
        }