コード例 #1
0
        public static string RunReport(ReportListViewModel model)
        {
            _model = model;

            using (var lr = new LocalReport())
            {
                lr.ReportEmbeddedResource = "ConsoleApplication5.Reports.TestReport.rdlc";
                lr.EnableExternalImages   = true;

                lr.SubreportProcessing += lr_SubreportProcessing;

                lr.DataSources.Add(new ReportDataSource("DataSource", _model));

                var renderedBytes = lr.Render
                                    (
                    "Image",
                    "<DeviceInfo><OutputFormat>BMP</OutputFormat></DeviceInfo>",
                    out string _,
                    out string _,
                    out string _,
                    out string[] _,
                    out var warnings
                                    );

                foreach (var w in warnings)
                {
                    _log.Warn($"{w.Code}: {w.Message}");
                }

                const string nm = "Test Report Image";

                var path = Path.Combine(TempPath, nm + ".bmp");

                var idx = 0;
                while (File.Exists(path))
                {
                    idx++;
                    path = Path.Combine(TempPath, string.Format("{0}.{1}.bmp", nm, idx));
                }

                using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write))
                {
                    stream.Write(renderedBytes, 0, renderedBytes.Length);
                    stream.Close();
                }

                path = CropAndSaveAsPng(path); // normally could just show it but if we want to remove all the white space we can do this

                Process.Start(path);
                _log.Info("Generated to " + path);

                return(path);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            GlobalContext.Properties["username"] = Environment.UserName;
            GlobalContext.Properties["version"]  = Assembly.GetExecutingAssembly().GetName().Version;

            var rvm = new ReportListViewModel();

            ReportFactory.RunReport(rvm);

            Console.ReadKey();
        }