Esempio n. 1
0
        /// <summary>
        /// 根据文件将html转换为image
        /// SubmissionAndApprovalRecords用recordDetails
        /// SubmissionApprovalRecord用records
        /// </summary>
        /// <param name="templateType"></param>
        /// <param name="values"></param>
        /// <param name="records"></param>
        /// <param name="recordDetails"></param>
        /// <returns></returns>
        public static System.Drawing.Image HtmlConvertToImageObject(HtmlTempalteType templateType, Dictionary <string, string> values, List <SubmissionApprovalRecord> records, List <SubmissionApprovalRecord> recordDetails)
        {
            var html = GenerateHtmlFromTemplate(templateType, values, records, recordDetails);

            System.Drawing.Image image = HtmlRender.RenderToImage(html);
            return(image);
        }
Esempio n. 2
0
        /// <summary>
        /// 将HTML文件转换为PDF字节流
        /// </summary>
        /// <param name="templateFile">模板文件名称</param>
        /// <param name="values">需要填充的值</param>
        /// <param name="impactOnCurrentYearData">表格形式的值</param>
        /// <param name="futureImpactData">表格形式的值</param>
        /// <returns>PDF字节流</returns>
        public static byte[] ConvertToPDFBytesWithComments(HtmlTempalteType templateType, Dictionary <string, string> values, List <SubmissionApprovalRecord> records)
        {
            var html         = GenerateHtmlFromTemplateWithComments(templateType, values, records);
            var pdfConverter = new PdfConverter();
            var bytes        = pdfConverter.GetPdfBytesFromHtmlString(html);

            return(bytes);
        }
Esempio n. 3
0
        /// <summary>
        /// 根据HTML模板和业务数据获取html内容
        /// </summary>
        /// <param name="templateFile">html模板文件</param>
        /// <param name="values">业务数据的键值对</param>
        /// <param name="impactOnCurrentYearData">表格数据</param>
        /// <param name="futureImpactData">表格数据</param>
        /// <returns>html格式的内容</returns>
        public static string GenerateHtmlFromTemplateWithComments(HtmlTempalteType templateType, Dictionary <string, string> values, List <SubmissionApprovalRecord> records)
        {
            values.Add("SubmissionAndApprovalRecords", GenerateTableHtml(records));
            values.Add("SubmissionAndApprovalRecordsWithComments", GenerateTableHtmlAdding(records));
            string file = GetTemplateFile(templateType);
            string html = GenerateHtmlContentByTemplate(file, values);

            return(html);
        }
Esempio n. 4
0
        /// <summary>
        /// 将HTML文件转换为PDF文件流
        /// </summary>
        /// <param name="templateFile">模板文件名称</param>
        /// <param name="values">需要填充的值</param>
        /// <param name="impactOnCurrentYearData">表格形式的值</param>
        /// <param name="futureImpactData">表格形式的值</param>
        /// <returns>PDF文件流</returns>
        public static Stream HtmlConvertToPDFStreamWithComments(HtmlTempalteType templateType, Dictionary <string, string> values, List <SubmissionApprovalRecord> records)
        {
            var    html         = GenerateHtmlFromTemplateWithComments(templateType, values, records);
            var    pdfConverter = new PdfConverter();
            Stream stream       = null;

            pdfConverter.SavePdfFromHtmlStringToStream(html, stream);
            return(stream);
        }
Esempio n. 5
0
        /// <summary>
        /// 根据文件将html转换为image
        /// SubmissionAndApprovalRecords用recordDetails
        /// SubmissionApprovalRecord用records
        /// </summary>
        /// <param name="templateType"></param>
        /// <param name="values"></param>
        /// <param name="records"></param>
        /// <param name="recordDetails"></param>
        /// <returns></returns>
        public static string ConvertToImage(HtmlTempalteType templateType, Dictionary <string, string> values, List <SubmissionApprovalRecord> records, List <SubmissionApprovalRecord> recordDetails)
        {
            var    image            = HtmlConvertToImageObject(templateType, values, records, recordDetails);
            string filePath         = ConfigurationManager.AppSettings["HtmlConversionFolder"];
            string serverPath       = HttpContext.Current.Request.PhysicalApplicationPath + filePath;
            string fileNameWithPath = serverPath + @"\" + Guid.NewGuid().ToString() + ".png";

            image.Save(fileNameWithPath);
            return(fileNameWithPath);
        }
Esempio n. 6
0
        /// <summary>
        /// 将HTML文件转换为PDF文件
        /// </summary>
        /// <param name="templateFile">模板文件名称</param>
        /// <param name="values">需要填充的值</param>
        /// <param name="impactOnCurrentYearData">表格形式的值</param>
        /// <param name="futureImpactData">表格形式的值</param>
        /// <returns>PDF文件路径</returns>
        public static string HtmlConvertToPDFWithComments(HtmlTempalteType templateType, Dictionary <string, string> values, List <SubmissionApprovalRecord> records)
        {
            var    html             = GenerateHtmlFromTemplateWithComments(templateType, values, records);
            var    pdfConverter     = new PdfConverter();
            string filePath         = ConfigurationManager.AppSettings["HtmlConversionFolder"];
            string serverPath       = HttpContext.Current.Request.PhysicalApplicationPath + filePath;
            string fileNameWithPath = serverPath + @"\" + Guid.NewGuid().ToString() + ".pdf";

            pdfConverter.SavePdfFromHtmlStringToFile(html, fileNameWithPath);
            return(fileNameWithPath);
        }
Esempio n. 7
0
        private static string GetTemplateFile(HtmlTempalteType templateType)
        {
            string file = string.Empty;

            switch (templateType)
            {
            case HtmlTempalteType.Default:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.DefaultHtmlTemplate;
                break;

            case HtmlTempalteType.DefaultAdding:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.DefaultHtmlTemplateAdding;
                break;

            case HtmlTempalteType.DefaultWithComments:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.DefaultHtmlTemplateWithComments;
                break;

            case HtmlTempalteType.ClosureMemo:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.ClosureMemoHtmlTemplate;
                break;

            case HtmlTempalteType.MajorLease:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.MajorLeaseHtmlTemplate;
                break;

            case HtmlTempalteType.TempClosure:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.TempClosureHtmlTemplate;
                break;

            case HtmlTempalteType.TempClosureReopenMemo:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.TempClosureReopenMemoHtmlTemplate;
                break;

            case HtmlTempalteType.Reimage:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.ReimageHtmlTemplate;
                break;

            case HtmlTempalteType.GBMemo:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.GBMemoHtmlTemplate;
                break;

            case HtmlTempalteType.ReopenMemo:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.ReopenMemoHtmlTemplate;
                break;

            case HtmlTempalteType.Renewal:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.RenewalHtmlTemplate;
                break;

            case HtmlTempalteType.RenewalLegalApproval:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.RenewalLegalApprovalTemplate;
                break;

            case HtmlTempalteType.RebuildPackage:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.RebuildPackageHtmlTemplate;
                break;

            default:
                file = HttpContext.Current.Request.PhysicalApplicationPath + Constants.DefaultHtmlTemplate;
                break;
            }
            return(file);
        }
Esempio n. 8
0
        public IHttpActionResult PreparePackDownload(string refTableName, string projectId)
        {
            string pdfPath    = string.Empty;
            string refTableId = ProjectInfo.GetRefTableId(refTableName, projectId);
            Dictionary <string, string> templateFileds = new Dictionary <string, string>();
            HtmlTempalteType            templateType   = HtmlTempalteType.Default;
            string flowName = string.Empty;
            string flowCode = string.Empty;

            switch (refTableName)
            {
            case "MajorLeaseChangePackage":
            {
                templateType = HtmlTempalteType.MajorLease;
                flowName     = FlowCode.MajorLease;
                flowCode     = FlowCode.MajorLease_Package;
                var majorLeaseChangePkg = MajorLeaseChangePackage.GetMajorPackageInfo(projectId);
                templateFileds = majorLeaseChangePkg.GetPrintTemplateFields();
            }
            break;

            case "TempClosurePackage":
            {
                templateType = HtmlTempalteType.TempClosure;
                flowName     = FlowCode.TempClosure;
                flowCode     = FlowCode.TempClosure_ClosurePackage;
                var tempClosurePackage = TempClosurePackage.Get(projectId);
                if (tempClosurePackage == null)
                {
                    tempClosurePackage           = new TempClosurePackage();
                    tempClosurePackage.ProjectId = projectId;
                }
                templateFileds = tempClosurePackage.GetPrintTemplateFields();
            }
            break;

            case "ReimagePackage":
            {
                var entity = ReimagePackage.GetReimagePackageInfo(projectId);
                templateType = HtmlTempalteType.Reimage;
                flowName     = FlowCode.Reimage;
                flowCode     = FlowCode.Reimage_Package;
                if (entity == null || entity.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"))
                {
                    entity           = new ReimagePackage();
                    entity.ProjectId = projectId;
                }
                templateFileds = entity.GetPrintTemplateFields();
            }
            break;

            case "RenewalLegalApproval":
            {
                templateType = HtmlTempalteType.RenewalLegalApproval;
                flowName     = FlowCode.Renewal;
                flowCode     = FlowCode.Renewal_LegalApproval;
                var legal = RenewalLegalApproval.Get(projectId);
                if (legal == null)
                {
                    legal           = new RenewalLegalApproval();
                    legal.ProjectId = projectId;
                }
                templateFileds = legal.GetPrintTemplateFields();
            }
            break;

            case "RenewalPackage":
            {
                templateType = HtmlTempalteType.Renewal;
                flowName     = FlowCode.Renewal;
                flowCode     = FlowCode.Renewal_Package;
                var package = RenewalPackage.Get(projectId);
                if (package == null)
                {
                    package           = new RenewalPackage();
                    package.ProjectId = projectId;
                }
                templateFileds = package.GetPrintTemplateFields();
            }
            break;

            case "ClosurePackage":
            {
                templateType = HtmlTempalteType.Default;
                flowName     = FlowCode.Closure;
                flowCode     = FlowCode.Closure_ClosurePackage;
                var closurePackage = ClosurePackage.Get(projectId);
                if (closurePackage == null)
                {
                    closurePackage           = new ClosurePackage();
                    closurePackage.ProjectId = projectId;
                }
                templateFileds = closurePackage.GetPrintTemplateFields();
            }
            break;

            default:
                break;
            }
            List <Attachment> attachments = Attachment.GetAllAttachmentsIncludeRequire(refTableName, projectId, flowCode).Where(att => att.ID != Guid.Empty &&
                                                                                                                                (att.RequirementId.HasValue || att.TypeCode == "Cover")).ToList();
            //Submission and Approval Records - 只显示通过意见
            List <SubmissionApprovalRecord> recordList = new List <SubmissionApprovalRecord>();
            //Submission and Approval Records Details — 所有意见
            List <SubmissionApprovalRecord> recordDetailList = new List <SubmissionApprovalRecord>();
            ProjectCommentCondition         condition        = new ProjectCommentCondition();

            condition.RefTableName = refTableName;
            condition.RefTableId   = Guid.Parse(refTableId);
            condition.Status       = ProjectCommentStatus.Submit;

            var commentList       = condition.RefTableId == Guid.Empty ? new List <VProjectComment>() : VProjectComment.SearchVListForPDF(condition);
            var commentDetailList = condition.RefTableId == Guid.Empty ? new List <VProjectComment>() : VProjectComment.SearchVList(condition);

            SubmissionApprovalRecord record = null;

            foreach (var item in commentList)
            {
                record            = new SubmissionApprovalRecord();
                record.ActionName = item.ActionDesc;
                if (item.CreateTime != null)
                {
                    record.OperationDate = item.CreateTime.Value;
                }
                record.OperatorID    = item.UserAccount;
                record.OperatorName  = item.UserNameENUS;
                record.OperatorTitle = item.PositionName;
                record.Comments      = item.Content;
                recordList.Add(record);
            }
            recordList = recordList.OrderBy(i => i.OperationDate).ToList();

            foreach (var item in commentDetailList)
            {
                record            = new SubmissionApprovalRecord();
                record.ActionName = item.ActionDesc;
                if (item.CreateTime != null)
                {
                    record.OperationDate = item.CreateTime.Value;
                }
                record.OperatorID    = item.UserAccount;
                record.OperatorName  = item.UserNameENUS;
                record.OperatorTitle = item.PositionName;
                record.Comments      = item.Content;
                recordDetailList.Add(record);
            }
            recordDetailList = recordDetailList.OrderBy(i => i.OperationDate).ToList();

            pdfPath = HtmlConversionUtility.HtmlConvertToPDF(templateType, templateFileds, recordList, recordDetailList);
            var pdfFileName  = Path.GetFileName(pdfPath);
            var pdfExtension = Path.GetExtension(pdfPath);

            attachments.Add(new Attachment {
                InternalName = pdfFileName, Name = flowName + " Print", Extension = pdfExtension
            });

            if (refTableName == "RenewalLegalApproval")
            {
                SaveRenewalLegalApprovalPDF("RenewalLegalApproval", projectId,
                                            new Guid("870BD738-A512-4B27-9FDB-C18058BFA817"), pdfPath);
                return(Ok());
            }
            string packFileUrl = ZipHandle.ExeFiles(attachments);

            return(Ok(new
            {
                PackUrl = string.Concat("~/", "Temp/", Path.GetFileName(packFileUrl))
            }));
        }