From ae96bb65a2a78072c7faf71759e440398884b493 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Tue, 21 May 2024 20:51:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=AF=20=D1=81=D0=BD=D0=BE=D0=B2=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B4=D0=B5=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogicPharmacist.cs | 38 +++++++ .../AbstractSaveToPdfPharmacist.cs | 105 +++++++++++++++++ .../HelperEnums/PdfParagraphAlignmentType.cs | 16 +++ .../OfficePackage/HelperModels/PdfInfo.cs | 18 +++ .../HelperModels/PdfParagraph.cs | 17 +++ .../HelperModels/PdfRowParameters.cs | 17 +++ .../Implements/SaveToPdfPharmacist.cs | 107 ++++++++++++++++++ .../VetClinicBusinessLogic.csproj | 1 + .../IReportLogicPharmacist.cs | 5 +- 9 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToPdfPharmacist.cs create mode 100644 VetClinic/VetClinicBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs create mode 100644 VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToPdfPharmacist.cs diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs index 407b670..68b3293 100644 --- a/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs @@ -85,5 +85,43 @@ namespace VetClinicBusinessLogic.BusinessLogics ServicesAnimals = GetServiceAnimals(model.Services) }); } + + public List GetMedicineVisitsAndGuidances(List services) + { + + List ans = new(); + List>>>> response = + _serviceStorage.GetReportInfo(new ListAnimalsSearchModel { servicesIds = services }); + + foreach (var service in response) + { + Dictionary counter = new(); + foreach (var medicine in service.Item2) + { + foreach (var animal in medicine.Item2) + { + if (!counter.ContainsKey(animal.Id)) + counter.Add(animal.Id, (animal, 1)); + else + { + counter[animal.Id] = (counter[animal.Id].Item1, counter[animal.Id].Item2 + 1); + } + } + } + List res = new(); + foreach (var cnt in counter) + { + if (cnt.Value.Item2 != service.Item2.Count) + continue; + res.Add(cnt.Value.Item1); + } + ans.Add(new ListAnimalsViewModel + { + ServiceName = service.Item1.ServiceName, + Animals = res + }); + } + return ans; + } } } diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToPdfPharmacist.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToPdfPharmacist.cs new file mode 100644 index 0000000..f739cd7 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToPdfPharmacist.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage.HelperEnums; +using VetClinicBusinessLogic.OfficePackage.HelperModels; +using VetClinicDataBaseImplement.Implements; + +namespace VetClinicBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfPharmacist + { + public void CreateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = + "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateParagraph(new PdfParagraph + { + Text = $"с { info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style + = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "2cm", "3cm", "6cm", "3cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата заказа", "Изделие", +"Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var medicine in info.Medicines) + { + CreateParagraph(new PdfParagraph + { + Text = medicine.MedicineName, + Style + = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + + CreateParagraph(new PdfParagraph + { + Text = "Визиты", + Style + = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + CreateTable(new List { "4cm", "4cm", "6cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата визита", "Навзание визита"}, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach(var visit in medicine.Visits) + { + CreateRow(new PdfRowParameters + { + Texts = new List { visit.Id.ToString(), visit.DateVisit.ToString(), visit.NameVisit}, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + + CreateParagraph(new PdfParagraph + { + Text = "Рекомендации", + Style + = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "4cm", "4cm", "6cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата рекомендации", "Название услуги" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var guidance in medicine.Guidances) + { + CreateRow(new PdfRowParameters + { + Texts = new List { guidance.Id.ToString(), guidance.Date.ToString(), guidance.ServiceName }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + } + SavePdf(info); + } + protected abstract void CreatePdf(PdfInfo info); + protected abstract void CreateParagraph(PdfParagraph paragraph); + protected abstract void CreateTable(List columns); + protected abstract void CreateRow(PdfRowParameters rowParameters); + protected abstract void SavePdf(PdfInfo info); + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..aa7a867 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VetClinicBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Rigth + } + +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..8e21977 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicDataBaseImplement.Implements; + +namespace VetClinicBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Medicines { get; set; } = new(); + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..44d63f2 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage.HelperEnums; + +namespace VetClinicBusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..93fadaa --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage.HelperEnums; + +namespace VetClinicBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToPdfPharmacist.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToPdfPharmacist.cs new file mode 100644 index 0000000..7229c03 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToPdfPharmacist.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage.HelperEnums; +using VetClinicBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; + +namespace VetClinicBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdfPharmacist : AbstractSaveToPdfPharmacist + { + private Document? _document; + private Section? _section; + private Table? _table; + private static ParagraphAlignment + GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + /// + /// Создание стилей для документа + /// + /// + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected override void CreatePdf(PdfInfo info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = + GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = + GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + protected override void SavePdf(PdfInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } + +} diff --git a/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj b/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj index 53d9c2b..237dc55 100644 --- a/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj +++ b/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj @@ -16,6 +16,7 @@ + diff --git a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicPharmacist.cs b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicPharmacist.cs index 46d6def..ae02b76 100644 --- a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicPharmacist.cs +++ b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicPharmacist.cs @@ -5,13 +5,16 @@ using System.Text; using System.Threading.Tasks; using VetClinicContracts.BindingModels; using VetClinicContracts.ViewModels; +using VetClinicDataBaseImplement.Implements; namespace VetClinicContracts.BusinessLogicsContracts { - public interface IReportLogicPharmacist //Будет дорабатываться + public interface IReportLogicPharmacist { List GetServiceAnimals(List services); void SaveAnimalsToWordFile(ListAnimalsBindingModel model); void SaveAnimalsToExcelFile(ListAnimalsBindingModel model); + List GetMedicineVisitsAndGuidances(List services); + void SaveMedicinesToPdfFile(VisitsGuidesBindingModel model); } }