예제 #1
0
        public static string GeneratePdf(Inspection inspection, ReportOptionsModel model = null)
        {
            if (model == null)
            {
                model = new ReportOptionsModel();
            }
            IGeneratePdf pdfMaker        = DependencyService.Get <IGeneratePdf>();
            string       fileName        = pdfMaker.Initialize(inspection);
            int          numCommentPages = 0;

            //draw comment pages
            if (model.Comments)
            {
                foreach (Comment comment in inspection.comments)
                {
                    numCommentPages++;
                    pdfMaker.CreateCommentPage(comment);
                    if (comment != inspection.comments.Last())
                    {
                        pdfMaker.NewPage();
                    }
                }
            }
            //draw question listing
            List <ReportSection> reportSections = PrepareInspectionForScoring(inspection);

            if (model.Questions)
            {
                pdfMaker.NewPageIfNotEmpty();
                foreach (ReportSection section in reportSections)
                {
                    if (model.ScoredSectionsOnly && section.section.availablePoints == 0)
                    {
                        continue;
                    }
                    pdfMaker.CreateQuestionSection(section);
                    if (section != reportSections.Last())
                    {
                        pdfMaker.NewPage();
                    }
                }
            }

            //draw section totals
            if (model.Totals)
            {
                pdfMaker.NewPageIfNotEmpty();
                pdfMaker.CreateSectionTotals();
            }

            //draw checklist structure
            if (model.Structure)
            {
                pdfMaker.NewPageIfNotEmpty();
                pdfMaker.CreateStructure();
            }

            //draw scoresheet
            if (model.ScoreSheet)
            {
                pdfMaker.NewPageIfNotEmpty();
                pdfMaker.CreateScoreSheet();
            }

            //draw scores graph
            if (model.GraphSheet)
            {
                pdfMaker.NewPageIfNotEmpty();
                pdfMaker.CreateScoreGraph();
            }
            pdfMaker.Finish();
            pdfMaker.StampFooter(numCommentPages);

            return(fileName);
        }