コード例 #1
0
        private static void GenerateReport(GenerateReportSettings generateReportSettings, bool CommentColumnInsertTable, double ImageWidth, double ImageHeight, string templateFile, string outputFile, int CompressImageFlag, ObservableCollection <DamageSummary> _bridgeDeckListDamageSummary, ObservableCollection <DamageSummary> _superSpaceListDamageSummary, ObservableCollection <DamageSummary> _subSpaceListDamageSummary)
        {
            var w = new ProgressBarWindow();

            w.Top  = 0.4 * (App.ScreenHeight - w.Height);
            w.Left = 0.4 * (App.ScreenWidth - w.Width);

            var progressBarModel = new ProgressBarModel
            {
                ProgressValue = 0
            };

            w.progressBarNumberTextBlock.DataContext = progressBarModel;
            w.progressBar.DataContext = progressBarModel;
            w.progressBarContentTextBlock.DataContext = progressBarModel;

            var progressSleepTime = 500;    //进度条停顿时间

            List <DamageSummary> l1 = _bridgeDeckListDamageSummary.ToList();
            List <DamageSummary> l2 = _superSpaceListDamageSummary.ToList();
            List <DamageSummary> l3 = _subSpaceListDamageSummary.ToList();

            DamageSummaryServices.InitListDamageSummary1(l1);
            DamageSummaryServices.InitListDamageSummary1(l2, 2_000_000);
            DamageSummaryServices.InitListDamageSummary1(l3, 3_000_000);

            var thread = new Thread(new ThreadStart(() =>
            {
                //progressBarModel.ProgressValue = 0;    //测试数据
                //生成报告前先验证照片的有效性
                int totalInvalidPictureCounts = PictureServices.ValidatePictures(l1, l2, l3, out List <string> bridgeDeckValidationResult, out List <string> superSpaceValidationResult, out List <string> subSpaceValidationResult);
                if (totalInvalidPictureCounts > 0)
                {
                    try
                    {
                        WriteInvalidPicturesResultToTxt(totalInvalidPictureCounts, bridgeDeckValidationResult, superSpaceValidationResult, subSpaceValidationResult);
                        MessageBox.Show($"存在无效照片,无法生成报告,共计{totalInvalidPictureCounts}张,详见根目录{App.InvalidPicturesStoreFile}");
                        return;
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.Message);
                        //throw;
                    }
                }

                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Show(); });
                Document doc      = new Document(templateFile);
                var asposeService = new AsposeWordsServices(ref doc, generateReportSettings, l1, l2, l3);
                asposeService.GenerateReport(ref progressBarModel, CommentColumnInsertTable, ImageWidth, ImageHeight, CompressImageFlag);

                doc.Save(outputFile, SaveFormat.Docx);

                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Close(); });
                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { MessageBox.Show("成功生成报告!"); });
            }));

            thread.Start();
        }
コード例 #2
0
        private static void GenerateReport(bool CommentColumnInsertTable, double ImageWidth, double ImageHeight, string templateFile, string outputFile, int CompressImageFlag, ObservableCollection <DamageSummary> _bridgeDeckListDamageSummary, ObservableCollection <DamageSummary> _superSpaceListDamageSummary, ObservableCollection <DamageSummary> _subSpaceListDamageSummary)
        {
            var w = new ProgressBarWindow();

            w.Top  = 0.4 * (App.ScreenHeight - w.Height);
            w.Left = 0.4 * (App.ScreenWidth - w.Width);

            var progressBarModel = new ProgressBarModel
            {
                ProgressValue = 0
            };

            w.progressBarNumberTextBlock.DataContext = progressBarModel;
            w.progressBar.DataContext = progressBarModel;
            w.progressBarContentTextBlock.DataContext = progressBarModel;

            var progressSleepTime = 500;    //进度条停顿时间

            List <DamageSummary> l1 = _bridgeDeckListDamageSummary.ToList();
            List <DamageSummary> l2 = _superSpaceListDamageSummary.ToList();
            List <DamageSummary> l3 = _subSpaceListDamageSummary.ToList();

            DamageSummaryServices.InitListDamageSummary1(l1);
            DamageSummaryServices.InitListDamageSummary1(l2, 2_000_000);
            DamageSummaryServices.InitListDamageSummary1(l3, 3_000_000);



            var thread = new Thread(new ThreadStart(() =>
            {
                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Show(); });
                //progressBarModel.ProgressValue = 0;    //测试数据

                var doc           = new Document(templateFile);
                var asposeService = new AsposeWordsServices(ref doc, l1, l2, l3);
                asposeService.GenerateSummaryTableAndPictureTable(ref progressBarModel, CommentColumnInsertTable, ImageWidth, ImageHeight, CompressImageFlag);

                //两次更新域,1次更新序号,1次更新序号对应的交叉引用
                doc.UpdateFields();
                doc.UpdateFields();

                doc.Save(outputFile, SaveFormat.Docx);
                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Close(); });
                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { MessageBox.Show("成功生成报告!"); });
            }));

            thread.Start();
        }