Exemple #1
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();
        }