Ejemplo n.º 1
0
        private void bwBuildReport_DoWork(object sender, DoWorkEventArgs e)
        {
            _log.Print("正在导出报告...");
            var chartBitmap = new Bitmap(mcChart.Width, mcChart.Height);

            Invoke(new Action(() =>
            {
                mcChart.DrawToBitmap(chartBitmap, new Rectangle(0, 0, mcChart.Width, mcChart.Height));
            }));
            //lvChart.DrawToBitmap(ChartBitmap, new Rectangle(0, 0, lvChart.Width, lvChart.Height));
            //chartBitmap.Save(Application.StartupPath + "/report/img.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            var content = _config.Report["Content"];
            var build   = _config.Report["Build"];
            var report  = new PdfReport
            {
                //FilePath =
                //    $"{Application.StartupPath}/report/{DateTime.Now:yyyyMMddHHmmss}.pdf"
                FilePath = $"{build["Path"]}\\{DateTime.Now:yyyyMMddHHmmss}.pdf"
            };

            if ((int)content["ShowTitle"] != 0)
            {
                report.Title = content["Title"].ToString();
                report.AddTitle(content["Title"].ToString());
            }

            if ((int)content["ShowSubject"] != 0)
            {
                report.Subject = content["Subject"].ToString();
                report.AddText($"{content["Subject"]}");
            }

            if ((int)content["ShowAuthor"] != 0)
            {
                report.Creator = content["Author"].ToString();
                report.AddText($"作者: {content["Author"]}");
            }

            report.AddEmptyLine();
            if ((int)content["ShowDate"] != 0)
            {
                report.CreateDate();
                report.AddText($"测量日期: {DateTime.Now}");
            }

            report.AddText($"测量时间: {_slaver.AutoMeasuringTime} 毫秒");
            if ((int)content["ShowTrigger"] != 0)
            {
                switch (_slaver.TriggerMode)
                {
                case TriggerMode.Auto:
                    var triggerChannel = _slaver.PressureTriggerChannel;
                    report.AddText("触发方式: 自动触发");
                    report.AddText($"触发通道: {triggerChannel?.Name}");
                    report.AddText($"触发值: {triggerChannel?.TriggerIncrement} MPa");
                    break;

                case TriggerMode.Manual:
                    report.AddText("触发方式: 手动触发");
                    break;

                case TriggerMode.External:
                    report.AddText("触发方式: 外触发");
                    break;

                default:
                    report.AddText("触发方式: 异常");
                    break;
                }
                report.AddEmptyLine();
            }

            if ((int)content["ShowChart"] != 0)
            {
                report.AddText("测量结果:");
                report.AddImage(chartBitmap);
            }

            if (report.Print())
            {
                _log.Print("导出报告完成,正在打开...");
                report.Open();
            }
            else
            {
                _log.Show("导出报告失败.");
            }
            //var waterMarkPdfPath = $"report/Report{DateTime.Now:yyyyMMddHHmmss}.pdf";
        }