예제 #1
0
        public ActionResult GetContractTemplatePdf(Guid id)
        {
            var       db     = new ncelsEntities();
            string    name   = "Договор_на_проведение_оценки_безопасности_и_качества.pdf";
            StiReport report = new StiReport();

            try
            {
                report.Load(obkRepo.GetContractTemplatePath(id));//(Server.MapPath("~/Reports/Mrts/OBK/ObkContractDec.mrt"));
                foreach (var data in report.Dictionary.Databases.Items.OfType <StiSqlDatabase>())
                {
                    data.ConnectionString = UserHelper.GetCnString();
                }

                report.Dictionary.Variables["ContractId"].ValueObject = id;

                var price = new OBKContractRepository().GetPriceCount(id);
                report.Dictionary.Variables["PriceCount"].ValueObject = price;

                var priceText = RuDateAndMoneyConverter.ToTextTenge(Convert.ToDouble(price), false);
                report.Dictionary.Variables["PriceCountName"].ValueObject = priceText;

                report.Render(false);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error("ex: " + ex.Message + " \r\nstack: " + ex.StackTrace);
            }

            Stream stream = new MemoryStream();

            report.ExportDocument(StiExportFormat.Word2007, stream);
            stream.Position = 0;

            Aspose.Words.Document doc = new Aspose.Words.Document(stream);

            try
            {
                var signData = db.OBK_ContractSignedDatas.Where(x => x.ContractId == id).FirstOrDefault();
                if (signData != null && signData.ApplicantSign != null && signData.CeoSign != null)
                {
                    doc.InserQrCodesToEnd("ApplicantSign", signData.ApplicantSign);
                    doc.InserQrCodesToEnd("CeoSign", signData.CeoSign);
                }
            }
            catch (Exception ex)
            {
            }

            var file = new MemoryStream();

            doc.Save(file, Aspose.Words.SaveFormat.Pdf);
            file.Position = 0;

            //return new FileStreamResult(stream, "application/pdf");
            return(File(file, "application/pdf", name));
        }
예제 #2
0
        public ActionResult GetAdditionalContractTemplatePdf(Guid id, bool?isStream, string contractAdditionTypeCode)
        {
            var       db     = new ncelsEntities();
            StiReport report = new StiReport();

            try
            {
                report.Load(obkRepo.GetContractAdditionalTemplatePath(id, contractAdditionTypeCode.Trim()));//(Server.MapPath("~/Reports/Mrts/OBK/ObkContractDec.mrt"));
                foreach (var data in report.Dictionary.Databases.Items.OfType <StiSqlDatabase>())
                {
                    data.ConnectionString = UserHelper.GetCnString();
                }

                report.Dictionary.Variables["addContractNumber"].ValueObject = id;

                report.Render(false);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error("ex: " + ex.Message + " \r\nstack: " + ex.StackTrace);
            }

            Stream stream = new MemoryStream();

            report.ExportDocument(StiExportFormat.Word2007, stream);
            stream.Position = 0;

            Aspose.Words.Document doc = new Aspose.Words.Document(stream);

            try
            {
                var signData = db.OBK_ContractSignedDatas.Where(x => x.ContractId == id).FirstOrDefault();
                if (signData != null && signData.ApplicantSign != null && signData.CeoSign != null)
                {
                    doc.InserQrCodesToEnd("ApplicantSign", signData.ApplicantSign);
                    doc.InserQrCodesToEnd("CeoSign", signData.CeoSign);
                }
            }
            catch (Exception ex)
            {
            }

            var file = new MemoryStream();

            doc.Save(file, Aspose.Words.SaveFormat.Pdf);
            file.Position = 0;

            if (isStream != null && isStream.Value)
            {
                return(new FileStreamResult(file, "application/pdf"));
            }
            else
            {
                return(File(file, "application/pdf", ""));
            }
        }
예제 #3
0
        public ActionResult DocumentExportFilePdf(string contractId)
        {
            string    name   = "Счет на оплату.pdf";
            StiReport report = new StiReport();

            try
            {
                report.Load(Server.MapPath("~/Reports/Mrts/OBK/1c/ObkInvoicePayment.mrt"));
                foreach (var data in report.Dictionary.Databases.Items.OfType <StiSqlDatabase>())
                {
                    data.ConnectionString = UserHelper.GetCnString();
                }

                report.Dictionary.Variables["ContractId"].ValueObject = contractId;
                //итого
                var totalPriceWithCount = payRepo.GetTotalPriceCount(Guid.Parse(contractId));
                report.Dictionary.Variables["TotalPriceWithCount"].ValueObject = totalPriceWithCount;
                //в том числе НДС
                var totalPriceNDS = payRepo.GetTotalPriceNDS(totalPriceWithCount);
                report.Dictionary.Variables["TotalPriceNDS"].ValueObject = totalPriceNDS;
                //прописью
                var priceText = RuDateAndMoneyConverter.CurrencyToTxtTenge(Convert.ToDouble(totalPriceWithCount), false);
                report.Dictionary.Variables["TotalPriceWithCountName"].ValueObject = priceText;
                report.Dictionary.Variables["ChiefAccountant"].ValueObject         = null; //payRepo.GetEmpoloyee(Guid.Parse("E1EE3658-0C35-41EB-99FD-FDDC4D07CEC4"))?.ShortName;
                report.Dictionary.Variables["Executor"].ValueObject = null;                //payRepo.GetEmpoloyee(Guid.Parse("55377FAC-A5F0-4093-BBB6-18BD28E53BE1"))?.ShortName;
                report.Render(false);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error("ex: " + ex.Message + " \r\nstack: " + ex.StackTrace);
            }
            var stream             = new MemoryStream();
            var directionToPayment = payRepo.GetDirectionToPayments(Guid.Parse(contractId));
            var signPayment        = payRepo.GetDirectionSignData(directionToPayment.Id);

            if (signPayment.ChiefAccountantSign != null && signPayment.ExecutorSign != null)
            {
                try
                {
                    report.ExportDocument(StiExportFormat.Word2007, stream);
                    stream.Position = 0;
                    Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                    doc.InserQrCodesToEnd("ChiefAccountantSign", signPayment.ChiefAccountantSign);
                    var pdfFile = new MemoryStream();
                    doc.Save(pdfFile, Aspose.Words.SaveFormat.Pdf);
                    pdfFile.Position = 0;
                    stream.Close();
                    return(File(pdfFile, "application/pdf", name));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            report.ExportDocument(StiExportFormat.Pdf, stream);
            stream.Position = 0;
            return(File(stream, "application/pdf", name));
        }
예제 #4
0
        /// <summary>
        /// формирование печатной формы
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult ExportFilePdf(Guid id)
        {
            var db = new ncelsEntities();
            var assessmentDeclaration = db.OBK_AssessmentDeclaration.FirstOrDefault(dd => dd.Id == id);
            var fileName = assessmentDeclaration.OBK_Ref_Type.Code == "1"
                ? "SafetyAssessmentDeclaration.mrt"
                : "SafetyAssessmentDeclaration.mrt";
            string    name   = "Заявление на проведение оценки безопасности и качества лс.pdf";
            StiReport report = new StiReport();

            try
            {
                report.Load(Server.MapPath("~/Reports/Mrts/" + fileName));
                foreach (var data in report.Dictionary.Databases.Items.OfType <StiSqlDatabase>())
                {
                    data.ConnectionString = UserHelper.GetCnString();
                }

                report.Dictionary.Variables["AssessmentDeclarationId"].ValueObject = id;
                report.Dictionary.Variables["ExecutorSign"].ValueObject            = null;

                report.Render(false);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error("ex: " + ex.Message + " \r\nstack: " + ex.StackTrace);
            }
            Stream stream = new MemoryStream();

            var assessmentDeclarationHistory = assessmentDeclaration.OBK_AssessmentDeclarationHistory.Where(dh => dh.XmlSign != null)
                                               .OrderByDescending(dh => dh.DateCreate).FirstOrDefault();

            if (assessmentDeclarationHistory != null)
            {
                try
                {
                    report.ExportDocument(StiExportFormat.Word2007, stream);
                    stream.Position = 0;
                    Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                    doc.InserQrCodesToEnd("ExecutorSign", assessmentDeclarationHistory.XmlSign);
                    var pdfFile = new MemoryStream();
                    doc.Save(pdfFile, Aspose.Words.SaveFormat.Pdf);
                    pdfFile.Position = 0;
                    stream.Close();

                    return(new FileStreamResult(pdfFile, "application/pdf"));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            report.ExportDocument(StiExportFormat.Pdf, stream);
            stream.Position = 0;
            return(new FileStreamResult(stream, "application/pdf"));
        }