예제 #1
0
        public ActionResult GetContractTemplatePdf(Guid id)
        {
            string templatePath;
            Dictionary <string, string> templateData;
            var actualContractFile = _contractRepository.GetActualContractFile(id);
            var isContract         = db.Contracts.Any(e => e.Id == id && e.ContractId == null);

            if (actualContractFile != null && actualContractFile.Extension == ".pdf")
            {
                var fileName =
                    FileHelper.GetFilePath(actualContractFile.DocumentId.Value.ToString(),
                                           actualContractFile.CategoryId.Value.ToString(), null,
                                           string.Format("{0}{1}", actualContractFile.Id, actualContractFile.Extension));
                return(new FileStreamResult(System.IO.File.OpenRead(fileName), "application/pdf"));
            }
            if (actualContractFile != null)
            {
                templatePath = FileHelper.GetFilePath(actualContractFile.DocumentId.Value.ToString(),
                                                      actualContractFile.CategoryId.Value.ToString(), null,
                                                      string.Format("{0}{1}", actualContractFile.Id, actualContractFile.Extension));
            }
            else
            {
                templatePath = isContract ? _contractRepository.GetContractTemplatePath(id) : _contractRepository.GetContractAdditionTemplatePath(id);
            }
            templateData = isContract ? _contractRepository.GetContractTemplateData(id) : _contractRepository.GetContractAdditionTemplateData(id);
            Aspose.Words.Document doc = new Aspose.Words.Document(templatePath);
            doc.ReplaceText(templateData);
            var file = new MemoryStream();

            doc.Save(file, SaveFormat.Pdf);
            file.Position = 0;
            return(new FileStreamResult(file, "application/pdf"));
        }
예제 #2
0
        public static void ReplaceText(string objectId, string name, string from, string to)
        {
            string fileName = Path.Combine(PathRoot, Root, objectId, name);

            if (File.Exists(fileName))
            {
                string filePdf            = Path.Combine(PathRoot, Root, objectId, name + RootPreview, Extension);
                Aspose.Words.Document doc = new Aspose.Words.Document(fileName);
                doc.Range.Replace(from, to, false, true);
                doc.Save(fileName);
                doc.Save(filePdf, SaveFormat.Pdf);
            }
        }
예제 #3
0
        public ActionResult GetContractTemplate(Guid id)
        {
            var actualContractFile = _contractRepository.GetActualContractFile(id);
            var templatePath       = actualContractFile == null
                ? _contractRepository.GetContractAdditionTemplatePath(id)
                : FileHelper.GetFilePath(actualContractFile.DocumentId.Value.ToString(),
                                         actualContractFile.CategoryId.Value.ToString(), null,
                                         string.Format("{0}{1}", actualContractFile.Id, actualContractFile.Extension));

            Aspose.Words.Document doc = new Aspose.Words.Document(templatePath);
            doc.ReplaceText(_contractRepository.GetContractAdditionTemplateData(id));
            var file = new MemoryStream();

            doc.Save(file, SaveFormat.Docx);
            file.Position = 0;
            return(new FileStreamResult(file, "application/msword"));
        }
예제 #4
0
        public ActionResult GetFilledTemplate(Guid contractId)
        {
            var    actualFileLink = _contractRepository.GetActualContractFile(contractId);
            string templatePath   = FileHelper.GetFilePath(actualFileLink.DocumentId.Value.ToString(), actualFileLink.CategoryId.Value.ToString(),
                                                           null, string.Format("{0}{1}", actualFileLink.Id, Path.GetExtension(actualFileLink.FileName)));;
            Dictionary <string, string> templateData;

            if (db.Contracts.Any(e => e.Id == contractId && e.ContractId != null))
            {
                templateData = _contractRepository.GetContractAdditionTemplateData(contractId);
            }
            else
            {
                templateData = _contractRepository.GetContractTemplateData(contractId);
            }
            Aspose.Words.Document doc = new Aspose.Words.Document(templatePath);
            doc.ReplaceText(templateData);
            var file = new MemoryStream();

            doc.Save(file, SaveFormat.Docx);
            file.Position = 0;
            return(File(file, "application/msword", actualFileLink.FileName));
        }
예제 #5
0
        private void ConvertSignedContractToPdf(Guid contractId, Dictionary <string, string> templateData)
        {
            var contractFile = GetActualContractFile(contractId);

            Aspose.Words.Document doc = new Aspose.Words.Document(FileHelper.GetFilePath(contractId.ToString(), contractFile.CategoryId.Value.ToString(),
                                                                                         null, string.Format("{0}{1}", contractFile.Id, contractFile.Extension)));
            if (templateData != null)
            {
                doc.ReplaceText(templateData);
            }
            var contractSign = AppContext.ContractSignedDatas.FirstOrDefault(e => e.ContractId == contractId);

            doc.InserQrCodes("applicantDigSign", contractSign != null ? contractSign.ApplicantSig : null);
            doc.InserQrCodes("ceoDigSign", contractSign != null ? contractSign.CeoSign : null);
            doc.InsertDocUrl(string.Format("{0}FileStorage/Download?id={1}&fileType=Contract", ConfigurationManager.AppSettings["ServerBaseUrl"], contractId));
            var file = new MemoryStream();

            doc.Save(file, SaveFormat.Pdf);
            file.Position = 0;
            FileHelper.SaveAttachNewVersion(contractFile.CategoryId.Value.ToString(), contractId.ToString(),
                                            contractFile.Id.ToString(),
                                            string.Format("{0}.pdf", Path.GetFileNameWithoutExtension(contractFile.FileName)), file, AppContext);
            file.Close();
        }
예제 #6
0
        public void TakeToWork(Guid contractId, Guid executorId)
        {
            var contract = AppContext.Contracts.Include(e => e.HolderType).FirstOrDefault(e => e.Id == contractId);

            contract.StatusId = DictionaryHelper.GetDicIdByCode(Dictionary.ContractStatus.DicCode,
                                                                Database.DataModel.Contract.StatusInWork);
            var contractDoc = AppContext.Documents.FirstOrDefault(e => e.Id == contractId);

            contractDoc.ExecutorsId = executorId.ToString();
            var executor = AppContext.Employees.FirstOrDefault(e => e.Id == executorId);

            contractDoc.ExecutorsValue = executor.DisplayName;
            if (contract.ContractId == null)
            {
                string templateName;
                if (contract.HolderType.Code == Dictionary.ContractHolderType.Holder)
                {
                    templateName = "ContractWithHolder.docx";
                }
                else
                {
                    templateName = "Contract.docx";
                }
                var templatePath =
                    System.Web.HttpContext.Current.Server.MapPath("~/Content/DocxTemplates/" + templateName);
                Aspose.Words.Document doc = new Aspose.Words.Document(templatePath);
                var file = new MemoryStream();
                doc.Save(file, SaveFormat.Docx);
                file.Position = 0;
                FileHelper.SaveFile(
                    DictionaryHelper.GetDicIdByCode(Dictionary.SysAttachContract.DicCode,
                                                    Dictionary.SysAttachContract.Contract).ToString(),
                    contractId.ToString(), "договор.docx", file, AppContext);
            }
            AppContext.SaveChanges();
        }