Exemplo n.º 1
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))
            }));
        }
Exemplo n.º 2
0
        private void GenerateCover(string projectId, string refTableName)
        {
            string coverPath      = string.Empty;
            string coverName      = "Cover";
            string coverTempPath  = SiteFilePath.UploadFiles_DIRECTORY + "\\" + Guid.NewGuid() + ".xlsx";
            string coverExtention = Path.GetExtension(coverTempPath);

            switch (refTableName)
            {
            case "MajorLeaseChangePackage":
                coverPath = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.MajorLeaseChangeCove_Template;
                var majorLeaseChangePackage = MajorLeaseChangePackage.GetMajorPackageInfo(projectId);
                majorLeaseChangePackage.GenerateCoverEexcel(coverPath, coverTempPath);
                break;

            case "ReimagePackage":
                var rmgPackage = ReimagePackage.Get(projectId);
                if (rmgPackage == null)
                {
                    return;
                }
                if (!Attachment.Any(i => i.TypeCode == "Cover" && i.RefTableName == ReimagePackage.TableName && i.RefTableID.ToString() == rmgPackage.Id.ToString()))
                {
                    var reimageInfoEntity = ReimageInfo.GetReimageInfo(projectId);
                    //生成cover文件
                    coverPath = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.Store_Reimage_Cover_Template;
                    var store = StoreBasicInfo.FirstOrDefault(e => e.StoreCode == reimageInfoEntity.USCode);

                    File.Copy(coverPath, coverTempPath);
                    var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(coverTempPath), ExcelDataInputType.ReimageCover);
                    var inputInfo           = new ExcelInputDTO
                    {
                        Region    = store.Region,
                        Province  = store.ProvinceENUS,
                        City      = store.CityENUS,
                        StoreName = store.NameENUS,
                        USCode    = reimageInfoEntity.USCode,
                        OpenDate  = store.OpenDate
                    };
                    excelOutputDirector.Input(inputInfo);

                    var coverItem = new Attachment();
                    coverItem.Name         = coverName + coverExtention;
                    coverItem.InternalName = Path.GetFileName(coverTempPath);
                    coverItem.RefTableName = ReimagePackage.TableName;
                    coverItem.RefTableID   = rmgPackage.Id.ToString();
                    coverItem.RelativePath = "//";
                    coverItem.Extension    = coverExtention;
                    coverItem.CreateTime   = DateTime.Now;

                    coverItem.TypeCode        = coverName;
                    coverItem.CreatorID       = ClientCookie.UserCode;
                    coverItem.RequirementId   = AttachmentRequirement.FirstOrDefault(e => e.FlowCode == FlowCode.Reimage_Package && e.NameENUS == "Cover").Id;
                    coverItem.CreatorNameENUS = ClientCookie.UserNameENUS;
                    coverItem.CreatorNameZHCN = ClientCookie.UserNameZHCN;

                    using (FileStream stream = new FileStream(coverTempPath, FileMode.Open))
                    {
                        coverItem.Length = (int)stream.Length;
                    }
                    Attachment.SaveSigleFile(coverItem);
                }
                break;

            case "TempClosurePackage":
                var tempClosurePackage = TempClosurePackage.Get(projectId);
                if (tempClosurePackage == null)
                {
                    return;
                }
                if (!Attachment.Any(i => i.TypeCode == "Cover" && i.RefTableName == tempClosurePackage.TableName && i.RefTableID.ToString() == tempClosurePackage.Id.ToString()))
                {
                    var tempClosureInfoEntity = TempClosureInfo.Get(projectId);
                    //生成cover文件
                    coverPath = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.Store_TempClosure_Cover_Template;
                    var store = StoreBasicInfo.FirstOrDefault(e => e.StoreCode == tempClosureInfoEntity.USCode);

                    File.Copy(coverPath, coverTempPath);
                    var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(coverTempPath), ExcelDataInputType.TempClosureCover);
                    var inputInfo           = new ExcelInputDTO
                    {
                        StoreNameEN     = store.NameENUS,
                        USCode          = tempClosureInfoEntity.USCode,
                        City            = store.CityENUS,
                        Market          = store.MarketENUS,
                        ActualCloseDate = tempClosureInfoEntity.ActualTempClosureDate.ToString("yyyy-MM-dd")
                    };
                    excelOutputDirector.Input(inputInfo);

                    var coverItem = new Attachment();
                    coverItem.Name         = coverName + coverExtention;
                    coverItem.InternalName = Path.GetFileName(coverTempPath);
                    coverItem.RefTableName = tempClosurePackage.TableName;
                    coverItem.RefTableID   = tempClosurePackage.Id.ToString();
                    coverItem.RelativePath = "//";
                    coverItem.Extension    = coverExtention;
                    coverItem.CreateTime   = DateTime.Now;

                    coverItem.TypeCode  = coverName;
                    coverItem.CreatorID = ClientCookie.UserCode;
                    //coverItem.RequirementId = AttachmentRequirement.FirstOrDefault(e => e.FlowCode == FlowCode.TempClosure_ClosurePackage && e.NameENUS == "Cover").Id;
                    coverItem.CreatorNameENUS = ClientCookie.UserNameENUS;
                    coverItem.CreatorNameZHCN = ClientCookie.UserNameZHCN;

                    using (FileStream stream = new FileStream(coverTempPath, FileMode.Open))
                    {
                        coverItem.Length = (int)stream.Length;
                    }
                    Attachment.SaveSigleFile(coverItem);
                }
                break;

            case "ClosurePackage":
                var closurePackage = ClosurePackage.Get(projectId);
                if (closurePackage == null)
                {
                    return;
                }
                if (!Attachment.Any(i => i.TypeCode == "Cover" && i.RefTableName == ClosurePackage.TableName && i.RefTableID.ToString() == closurePackage.Id.ToString()))
                {
                    var closureInfoEntity = ClosureInfo.GetByProjectId(projectId);
                    //生成cover文件
                    coverPath = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.Store_Closure_Cover_Template;
                    var store = StoreBasicInfo.FirstOrDefault(e => e.StoreCode == closureInfoEntity.USCode);

                    File.Copy(coverPath, coverTempPath);
                    var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(coverTempPath), ExcelDataInputType.ClosureCover);
                    var inputInfo           = new ExcelInputDTO
                    {
                        StoreNameEN     = store.NameENUS,
                        USCode          = closureInfoEntity.USCode,
                        City            = store.CityENUS,
                        Market          = store.MarketENUS,
                        ActualCloseDate = closureInfoEntity.ActualCloseDate.Value.ToString("yyyy-MM-dd")
                    };
                    excelOutputDirector.Input(inputInfo);

                    var coverItem = new Attachment();
                    coverItem.Name         = coverName + coverExtention;
                    coverItem.InternalName = Path.GetFileName(coverTempPath);
                    coverItem.RefTableName = ClosurePackage.TableName;
                    coverItem.RefTableID   = closurePackage.Id.ToString();
                    coverItem.RelativePath = "//";
                    coverItem.Extension    = coverExtention;
                    coverItem.CreateTime   = DateTime.Now;

                    coverItem.TypeCode  = coverName;
                    coverItem.CreatorID = ClientCookie.UserCode;
                    //coverItem.RequirementId = AttachmentRequirement.FirstOrDefault(e => e.FlowCode == FlowCode.TempClosure_ClosurePackage && e.NameENUS == "Cover").Id;
                    coverItem.CreatorNameENUS = ClientCookie.UserNameENUS;
                    coverItem.CreatorNameZHCN = ClientCookie.UserNameZHCN;

                    using (FileStream stream = new FileStream(coverTempPath, FileMode.Open))
                    {
                        coverItem.Length = (int)stream.Length;
                    }
                    Attachment.SaveSigleFile(coverItem);
                }
                break;
            }
        }