Exemple #1
0
        public ActionResult ExpDocumentExportFilePdf(string productSeriesId, Guid id)
        {
            string    name        = $"Заключение о безопасности и качества.pdf";
            var       serieId     = Convert.ToInt32(productSeriesId);
            var       expDocument = db.OBK_StageExpDocument.FirstOrDefault(o => o.ProductSeriesId == serieId);
            StiReport report      = new StiReport();

            try
            {
                var declaration = db.OBK_AssessmentDeclaration.FirstOrDefault(o => o.Id == id);

                var applicationBlankNumber = expDocument.ExpApplicationNumber != null ? expDocument.ExpApplicationNumber : "";

                if (applicationBlankNumber.Length < 6)
                {
                    for (int c = applicationBlankNumber.Length; c < 6; c++)
                    {
                        applicationBlankNumber = "0" + applicationBlankNumber;
                    }
                }

                if (CodeConstManager.OBK_SA_SERIAL.Equals(declaration.TypeId.ToString()))
                {
                    if (expDocument.ExpApplication == false)
                    {
                        report.Load(Server.MapPath("~/Reports/Mrts/OBKExpDocumentApplicationSerialPdf.mrt"));
                    }
                    else
                    {
                        report.Load(Server.MapPath("~/Reports/Mrts/OBKExpDocumentSerialPdf.mrt"));
                    }

                    var tail       = " согласно приложения КЗП № {" + applicationBlankNumber + "}, серийная";
                    var dictionary = ZBKSpaceHelper.BuildName(expDocument.ExpProductNameRu + " серийный выпуск", 90, 120, 150, expDocument.ExpProductShortNameRu, tail);
                    report.Dictionary.Variables["ProductNameRu1"].ValueObject = dictionary.ContainsKey(1) ? dictionary[1] : "";
                    report.Dictionary.Variables["ProductNameRu2"].ValueObject = dictionary.ContainsKey(2) ? dictionary[2] : "";
                    report.Dictionary.Variables["ProductNameRu3"].ValueObject = dictionary.ContainsKey(3) ? dictionary[3] : "";

                    var tailKaz       = " ҚҚҚ № {" + applicationBlankNumber + "} қосымшаға сәйкес, сериялы шыгарылым";
                    var dictionaryKaz = ZBKSpaceHelper.BuildName(expDocument.ExpProductNameKz + " сериялық", 60, 120, 150, expDocument.ExpProductShortNameKz, tailKaz);
                    report.Dictionary.Variables["ProductNameKz1"].ValueObject  = dictionaryKaz.ContainsKey(1) ? dictionaryKaz[1] : "";
                    report.Dictionary.Variables["ProductNameKz2"].ValueObject  = dictionaryKaz.ContainsKey(2) ? dictionaryKaz[2] : "";
                    report.Dictionary.Variables["ProductNameKz3"].ValueObject  = dictionaryKaz.ContainsKey(3) ? dictionaryKaz[3] : "";
                    report.Dictionary.Variables["productSeriesId"].ValueObject = serieId;

                    var reportOp = db.OBK_AssessmentReportOP.FirstOrDefault(o => o.DeclarationId == id);
                    if (reportOp != null)
                    {
                        var opExecutor = db.OBK_AssessmentReportOPExecutors.OrderByDescending(o => o.Date).FirstOrDefault(o => o.ReportId == reportOp.Id);
                        if (opExecutor != null && opExecutor.Date != null)
                        {
                            report.Dictionary.Variables["OpExecutorDate"].ValueObject = ((DateTime)opExecutor.Date).ToString("dd.MM.yyyy");
                        }
                    }
                }
                else if (CodeConstManager.OBK_SA_PARTY.Equals(declaration.TypeId.ToString()))
                {
                    if (expDocument.ExpApplication == false)
                    {
                        report.Load(Server.MapPath("~/Reports/Mrts/OBKExpDocumentApplicationPartyPdf.mrt"));
                    }
                    else
                    {
                        report.Load(Server.MapPath("~/Reports/Mrts/OBKExpDocumentPartyPdf.mrt"));
                    }

                    var tail       = " согласно приложения КЗП № {" + applicationBlankNumber + "}";
                    var dictionary = ZBKSpaceHelper.BuildName(expDocument.ExpProductNameRu, 90, 120, 170, expDocument.ExpProductShortNameRu, tail);
                    report.Dictionary.Variables["ProductNameRu1"].ValueObject = dictionary.ContainsKey(1) ? dictionary[1] : "";
                    report.Dictionary.Variables["ProductNameRu2"].ValueObject = dictionary.ContainsKey(2) ? dictionary[2] : "";
                    report.Dictionary.Variables["ProductNameRu3"].ValueObject = dictionary.ContainsKey(3) ? dictionary[3] : "";

                    var tailKaz       = " ҚҚҚ № {" + applicationBlankNumber + "} қосымшаға сәйкес";
                    var dictionaryKaz = ZBKSpaceHelper.BuildName(expDocument.ExpProductNameKz, 60, 120, 160, expDocument.ExpProductShortNameKz, tailKaz);
                    report.Dictionary.Variables["ProductNameKz1"].ValueObject  = dictionaryKaz.ContainsKey(1) ? dictionaryKaz[1] : "";
                    report.Dictionary.Variables["ProductNameKz2"].ValueObject  = dictionaryKaz.ContainsKey(2) ? dictionaryKaz[2] : "";
                    report.Dictionary.Variables["ProductNameKz3"].ValueObject  = dictionaryKaz.ContainsKey(3) ? dictionaryKaz[3] : "";
                    report.Dictionary.Variables["productSeriesId"].ValueObject = serieId;
                }
                else
                {
                    if (expDocument.ExpApplication == false)
                    {
                        report.Load(Server.MapPath("~/Reports/Mrts/OBKExpDocumentApplicationPdf.mrt"));
                    }
                    else
                    {
                        report.Load(Server.MapPath("~/Reports/Mrts/OBKExpDocumentPdf.mrt"));
                    }

                    var tail       = " согласно приложения КЗП № {" + applicationBlankNumber + "}";
                    var dictionary = ZBKSpaceHelper.BuildName(expDocument.ExpProductNameRu, 90, 120, 170, expDocument.ExpProductShortNameRu, tail);
                    report.Dictionary.Variables["ProductNameRu1"].ValueObject = dictionary.ContainsKey(1) ? dictionary[1] : "";
                    report.Dictionary.Variables["ProductNameRu2"].ValueObject = dictionary.ContainsKey(2) ? dictionary[2] : "";
                    report.Dictionary.Variables["ProductNameRu3"].ValueObject = dictionary.ContainsKey(3) ? dictionary[3] : "";

                    var tailKaz       = " ҚҚҚ № {" + applicationBlankNumber + "} қосымшаға сәйкес";
                    var dictionaryKaz = ZBKSpaceHelper.BuildName(expDocument.ExpProductNameKz, 60, 120, 160, expDocument.ExpProductShortNameKz, tailKaz);
                    report.Dictionary.Variables["ProductNameKz1"].ValueObject = dictionaryKaz.ContainsKey(1) ? dictionaryKaz[1] : "";
                    report.Dictionary.Variables["ProductNameKz2"].ValueObject = dictionaryKaz.ContainsKey(2) ? dictionaryKaz[2] : "";
                    report.Dictionary.Variables["ProductNameKz3"].ValueObject = dictionaryKaz.ContainsKey(3) ? dictionaryKaz[3] : "";
                }

                foreach (var data in report.Dictionary.Databases.Items.OfType <StiSqlDatabase>())
                {
                    data.ConnectionString = UserHelper.GetCnString();
                }

                report.Dictionary.Variables["StageExpDocumentId"].ValueObject      = Convert.ToInt32(productSeriesId);
                report.Dictionary.Variables["AssessmentDeclarationId"].ValueObject = id;
                report.Dictionary.Variables["StartMonthRu"].ValueObject            = MonthHelper.getMonthRu(expDocument.ExpStartDate);
                report.Dictionary.Variables["StartMonthKz"].ValueObject            = MonthHelper.getMonthKz(expDocument.ExpStartDate);

                if (expDocument.ExpEndDate != null)
                {
                    expDocument.ExpEndDate = ((DateTime)expDocument.ExpEndDate).AddMonths(1);
                }

                report.Dictionary.Variables["EndMonthRu"].ValueObject = MonthHelper.getMonthRu(expDocument.ExpEndDate);
                report.Dictionary.Variables["EndMonthKz"].ValueObject = MonthHelper.getMonthKz(expDocument.ExpEndDate);

                report.Dictionary.Variables["addInfo"].ValueObject   = assessmentRepo.FormExpAdditionalInfo(declaration);
                report.Dictionary.Variables["addInfoKz"].ValueObject = assessmentRepo.FormExpAdditionalInfo(declaration, true);

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

            report.ExportDocument(StiExportFormat.Pdf, stream);
            stream.Position = 0;
            return(File(stream, "application/pdf", name));
        }