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

            try
            {
                report.Load(obkRepo.GetContractTemplatePath(id));
                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;

                var priceKz = new OBKContractRepository().GetPriceCountNumber(id);
                report.Dictionary.Variables["PriceCountNameKz"].ValueObject = PriceHelperKz.ConvertKzNumbers(priceKz);
                var signData = db.OBK_ContractSignedDatas.FirstOrDefault(x => x.ContractId == id);
                if (signData?.ApplicantSign != null) //&& signData.CeoSign != null
                {
                    report.RegBusinessObject("appSign", obkRepo.GetContractApplicantData(id));
                    report.RegBusinessObject("ceoSign", obkRepo.GetContractCeoData(id));
                }
                report.Render(false);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error("ex: " + ex.Message + " \r\nstack: " + ex.StackTrace);
            }

            Stream stream = new MemoryStream();

            report.ExportDocument(StiExportFormat.Pdf, stream);
            stream.Position = 0;
            return(new FileStreamResult(stream, "application/pdf"));

            //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)
            //        doc.InserQrCodesToEnd("ApplicantSign", signData.ApplicantSign);
            //    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(file, "application/pdf");
        }