From f1a112715c46b216595e222f7482869464eab364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Wed, 29 May 2024 01:12:32 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B0=20?= =?UTF-8?q?=D0=BE=D1=82=D1=87=D0=B5=D1=82=20=D0=B4=D0=BB=D1=8F=20=D0=BA?= =?UTF-8?q?=D1=83=D1=80=D1=81=D0=BE=D0=B2=20=D0=BF=D0=BE=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=86=D0=B5=D0=B4=D1=83=D1=80=D0=B5=20=D0=B2=20=D0=B2?= =?UTF-8?q?=D0=BE=D1=80=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/SuretorReportLogic.cs | 32 ++--- .../Word/WordCoursesByProceduresInfo.cs | 1 + .../SaveToWordCoursesByProcedure.cs | 122 ++++++++++++++++++ .../PolyclinicBusinessLogic.csproj | 1 + .../ISuretorReportLogic.cs | 4 +- .../ReportCoursesByProcedureViewModel.cs | 8 +- .../Controllers/HomeController.cs | 55 ++++++-- Polyclinic/PolyclinicWebAppSuretor/Program.cs | 5 + .../Views/Home/ListCoursesByProcedures.cshtml | 32 ++--- Polyclinic/PolyclinicWebAppSuretor/jopa.docx | Bin 0 -> 1268 bytes Polyclinic/PolyclinicWebAppSuretor/qwerty | Bin 0 -> 1268 bytes .../PolyclinicWebAppSuretor/qwerty.docx | Bin 0 -> 1268 bytes 12 files changed, 209 insertions(+), 51 deletions(-) create mode 100644 Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToWordCoursesByProcedure.cs create mode 100644 Polyclinic/PolyclinicWebAppSuretor/jopa.docx create mode 100644 Polyclinic/PolyclinicWebAppSuretor/qwerty create mode 100644 Polyclinic/PolyclinicWebAppSuretor/qwerty.docx diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SuretorReportLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SuretorReportLogic.cs index e33f432..a7d132b 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SuretorReportLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SuretorReportLogic.cs @@ -1,4 +1,6 @@ -using PolyclinicContracts.BindingModels; +using PolyclinicBusinessLogic.OfficePackage; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; @@ -15,34 +17,30 @@ namespace PolyclinicBusinessLogic.BusinessLogics private readonly ICourseStorage courseStorage; private readonly ISymptomStorage symptomStorage; private readonly IRecipeStorage recipeStorage; + + private readonly AbstractSaveToWordCoursesByProcedures saveToWord; public SuretorReportLogic(IProcedureStorage procedureStorage, IMedicamentStorage medicamentStorage, - ICourseStorage courseStorage, ISymptomStorage symptomStorage, IRecipeStorage recipeStorage) + ICourseStorage courseStorage, ISymptomStorage symptomStorage, IRecipeStorage recipeStorage, AbstractSaveToWordCoursesByProcedures saveToWord) { this.procedureStorage = procedureStorage; this.medicamentStorage = medicamentStorage; this.courseStorage = courseStorage; this.symptomStorage = symptomStorage; this.recipeStorage = recipeStorage; + this.saveToWord = saveToWord; } - public List GetProcedureCourses(ProcedureSearchModel model) + public List GetProcedureCourses(ProcedureSearchModel model) { var procedure = procedureStorage.GetElement(model); var courses = courseStorage.GetFullList(); var recipes = recipeStorage.GetFullList(); - var list = new List(); - - var record = new ReportCoursesByProcedureViewModel - { - Name = procedure!.Name, - Courses = new List<(int countDays, int pillsPerDay, string comment)>() - }; + var list = new List(); using var context = new PolyclinicDatabase(); var recipeProcedureId = context.RecipeProcedures .Where(x => x.ProcedureId == model.Id).Select(x => x.RecipeId).ToList(); - foreach (var recipe in recipes) { @@ -54,13 +52,12 @@ namespace PolyclinicBusinessLogic.BusinessLogics { if(recipe.CourseId == course.Id) { - record.Courses.Add((course.DaysCount, course.PillsPerDay, course.Comment)); + list.Add(course); } } } } } - list.Add(record); return list; } @@ -103,9 +100,14 @@ namespace PolyclinicBusinessLogic.BusinessLogics throw new NotImplementedException(); } - public void SaveCoursesByProcedureToWordFile(ReportBindingModel model) + public void SaveCoursesByProcedureToWordFile(ReportBindingModel model, ProcedureSearchModel procedureSearchMode) { - throw new NotImplementedException(); + saveToWord.CreateDoc(new WordCoursesByProceduresInfo + { + FileName = model.FileName, + Title = "Курсы по процедурам", + Courses = GetProcedureCourses(procedureSearchMode) + }); } public void SaveProceduresToPdfFile(ReportBindingModel model) diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordCoursesByProceduresInfo.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordCoursesByProceduresInfo.cs index a503fbd..8f35c8a 100644 --- a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordCoursesByProceduresInfo.cs +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/HelperModels/Word/WordCoursesByProceduresInfo.cs @@ -6,6 +6,7 @@ namespace PolyclinicBusinessLogic.OfficePackage.HelperModels.Word { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; + public string ProcedureName { get; set; } = string.Empty; public List Courses { get; set; } = new(); } } diff --git a/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToWordCoursesByProcedure.cs b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToWordCoursesByProcedure.cs new file mode 100644 index 0000000..1cfcb72 --- /dev/null +++ b/Polyclinic/PolyclinicBusinessLogic/OfficePackage/Implements/SaveToWordCoursesByProcedure.cs @@ -0,0 +1,122 @@ +using PolyclinicBusinessLogic.OfficePackage.HelperEnums; +using PolyclinicBusinessLogic.OfficePackage.HelperModels.Word; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace PolyclinicBusinessLogic.OfficePackage.Implements +{ + public class SaveToWordCoursesByProcedure : AbstractSaveToWordCoursesByProcedures + { + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + /// + /// Настройки страницы + /// + /// + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + properties.AppendChild(pageSize); + return properties; + } + /// + /// Задание форматирования для абзаца + /// + /// + /// + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + var properties = new ParagraphProperties(); + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + properties.AppendChild(new Indentation()); + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize + { + Val = paragraphProperties.Size + }); + } + properties.AppendChild(paragraphMarkRunProperties); + return properties; + } + protected override void CreateWord(WordCoursesByProceduresInfo info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + docRun.AppendChild(new Text + { + Text = run.Item1, + Space = SpaceProcessingModeValues.Preserve + }); + docParagraph.AppendChild(docRun); + } + _docBody.AppendChild(docParagraph); + } + protected override void SaveWord(WordCoursesByProceduresInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); + } + } +} + + + diff --git a/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj b/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj index f5e1d5c..ee32ea1 100644 --- a/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj +++ b/Polyclinic/PolyclinicBusinessLogic/PolyclinicBusinessLogic.csproj @@ -7,6 +7,7 @@ + diff --git a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISuretorReportLogic.cs b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISuretorReportLogic.cs index ccfba9d..789b597 100644 --- a/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISuretorReportLogic.cs +++ b/Polyclinic/PolyclinicContracts/BusinessLogicsContracts/ISuretorReportLogic.cs @@ -15,7 +15,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts /// Получение данных (списка) курсов по выбранным процедурам /// /// - List GetProcedureCourses(ProcedureSearchModel model); + List GetProcedureCourses(ProcedureSearchModel model); /// /// Получение списка процедур @@ -28,7 +28,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts /// Сохранение курсов по процедурам в файл-Word /// /// - void SaveCoursesByProcedureToWordFile(ReportBindingModel model); + void SaveCoursesByProcedureToWordFile(ReportBindingModel model, ProcedureSearchModel procedureSearchMode); /// /// Сохранение курсов по процедурам в файл-Excel diff --git a/Polyclinic/PolyclinicContracts/ViewModels/ReportCoursesByProcedureViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/ReportCoursesByProcedureViewModel.cs index 7362ded..ba3df1f 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/ReportCoursesByProcedureViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/ReportCoursesByProcedureViewModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PolyclinicContracts.ViewModels +namespace PolyclinicContracts.ViewModels { public class ReportCoursesByProcedureViewModel { diff --git a/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs b/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs index 680ed67..f7c7b88 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs +++ b/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using PolyclinicBusinessLogic.BusinessLogics; +using PolyclinicBusinessLogic.OfficePackage; using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; @@ -18,13 +19,15 @@ namespace PolyclinicWebAppSuretor.Controllers private readonly IRecipeLogic _recipeLogic; private readonly ISymptomLogic _symptomLogic; private readonly ICourseLogic _courseLogic; + private readonly ISuretorReportLogic _suretorReportLogic; public HomeController(ILogger logger, IProcedureLogic procedureLogic, IMedicamentLogic medicamentLogic, IRecipeLogic recipeLogic, ISymptomLogic symptomLogic, - ICourseLogic courseLogic) + ICourseLogic courseLogic, + ISuretorReportLogic suretorReportLogic) { _logger = logger; _procedureLogic = procedureLogic; @@ -32,6 +35,7 @@ namespace PolyclinicWebAppSuretor.Controllers _recipeLogic = recipeLogic; _symptomLogic = symptomLogic; _courseLogic = courseLogic; + _suretorReportLogic = suretorReportLogic; } public IActionResult Index() @@ -74,9 +78,9 @@ namespace PolyclinicWebAppSuretor.Controllers RecipeBindingModel recipe = new RecipeBindingModel { - ProceduresCount = model.RecipeViewModel.ProceduresCount, - Comment = model.RecipeViewModel.Comment, - RecipeProcedures = selectedProcedures + ProceduresCount = model.RecipeViewModel.ProceduresCount, + Comment = model.RecipeViewModel.Comment, + RecipeProcedures = selectedProcedures .ToDictionary( x => x, x => allProcedures.Where(y => y.Id == x) as IProcedureModel @@ -276,11 +280,7 @@ namespace PolyclinicWebAppSuretor.Controllers return RedirectToAction("Procedures"); } - public IActionResult ListCoursesByProcedures() - { - List procedures = _procedureLogic.ReadList(null); - return View(procedures); - } + public IActionResult AddSymptomToMedicament(AddSymptomToMedicamentModel model) { @@ -292,6 +292,43 @@ namespace PolyclinicWebAppSuretor.Controllers return View(model); } + public IActionResult ListCoursesByProcedures() + { + ViewBag.Procedures = _procedureLogic.ReadList(null); + return View(); + } + + [HttpPost] + public IActionResult CreateWordFile(int procedureId, string fileName, string fileFormat) + { + var procedure = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = procedureId}); + ViewBag.Procedures = procedure; + + fileName = fileName + $".{fileFormat}"; + + if(procedure == null) + { + return NotFound(" "); + } + + var report = new ReportBindingModel + { + FileName = fileName, + }; + + var procedureSearch = new ProcedureSearchModel { Id = procedureId}; + + if (fileFormat == "docx") + { + _suretorReportLogic.SaveCoursesByProcedureToWordFile(report,procedureSearch); + } + + var filePath = Path.Combine(Directory.GetCurrentDirectory(), fileName); + byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); + string mimeType = fileFormat.ToLower() == "docx" ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + return File(fileBytes, mimeType, fileName); + } + [HttpGet] [HttpPost] public IActionResult ProceduresReport() diff --git a/Polyclinic/PolyclinicWebAppSuretor/Program.cs b/Polyclinic/PolyclinicWebAppSuretor/Program.cs index d66e48c..86ff5bf 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Program.cs +++ b/Polyclinic/PolyclinicWebAppSuretor/Program.cs @@ -1,4 +1,6 @@ using PolyclinicBusinessLogic.BusinessLogics; +using PolyclinicBusinessLogic.OfficePackage; +using PolyclinicBusinessLogic.OfficePackage.Implements; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.StoragesContracts; using PolyclinicDatabaseImplement.Implements; @@ -17,6 +19,9 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/ListCoursesByProcedures.cshtml b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/ListCoursesByProcedures.cshtml index bffad41..0e77b27 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/ListCoursesByProcedures.cshtml +++ b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/ListCoursesByProcedures.cshtml @@ -1,5 +1,5 @@ @using PolyclinicContracts.ViewModels -@model List +@model ProcedureViewModel @{ ViewData["Title"] = "ListCoursesByProcedures"; } @@ -13,19 +13,15 @@

Выберите процедуру/ы из списка

-
-
    - @{ - foreach (var item in Model) - { -
  • - - -
  • - } - } -
-
+ + +
@@ -34,20 +30,20 @@

- +

- Как назовем файл? + Как назовем файл?

- +
- +
diff --git a/Polyclinic/PolyclinicWebAppSuretor/jopa.docx b/Polyclinic/PolyclinicWebAppSuretor/jopa.docx new file mode 100644 index 0000000000000000000000000000000000000000..104bfb0efb19b114ec81232b53e199941a2753de GIT binary patch literal 1268 zcmWIWW@Zs#U|`^2@L<>*vH4(@y#ylz!(Jd31d5jD7p3T@j`ZrnG zWB!S4`+DE8iQb)lgUy!f>GYM;-Lx(j2X3r!{mC5w4MqlVFg|itexL;mLJ;N#24j3t zYEH4f9*BIud%ul6Fd!AmQ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cmV?d00001 diff --git a/Polyclinic/PolyclinicWebAppSuretor/qwerty.docx b/Polyclinic/PolyclinicWebAppSuretor/qwerty.docx new file mode 100644 index 0000000000000000000000000000000000000000..317db0aa1784aecc3cbe450dd7b48a99544c8da1 GIT binary patch literal 1268 zcmWIWW@Zs#U|`^2P~EpDV)MZ)dkIDchP^;62ox>PFG|r*$xklLP0cIOtH{kMo#^Oy z*g(K_y-=lptX50Fl_lX01x$~9f)^jzcFd1yP1l4Q1}lBvZROo!Th6bD-(90|<6!md z;&)FNqaKDGYf{V2-yk|~TEypr38@!73i=9i51YUKs+!+=Nk{3u&sT}fa}SvwE79Mq z_}(?xz%#8u=W*ffNJUP^sKq9CN_a(lO75N6bSYHJAn?v*r<*Z8x;4`@&bw*;x$L+3 zudV5m%UhRgp17f8aX>CY^4{_3A1&4DW z$NUr9_VvDF6TLhA2AeI{)9EXxyJ=l64%}Gd`ja~V8jK9!U`$$^m8As?LJ;N#24j3t zYEH4f9*BIud%ul6Fd!AmQj3Z+^Yd(#4D}3@6jJk&^HVbO(ruMWOVV^LlLu5 zOMohhGcpT`6@XguifxrLN=gc>^!1CAGg5OCi}msgQuBZ^Y57IDi6ua8QM!IXVsdt3 zdaAyWfq|Jm&_;wAN~mTkgj5!!5@TY1T3TjustYs~U@=%9RfUp5NMccXYKg6qK1TXc zQt(W%RSGgPGcz_?E42}x@vb+?uc+-W1A3UFdLam@EKRLCy7?>n-bM)Xcxrv#1+F;{>;f2L!Pzoc> zYG`r+rA