diff --git a/VetClinic/VetClinicAdminApp/Controllers/HomeController.cs b/VetClinic/VetClinicAdminApp/Controllers/HomeController.cs index 4087030..5e65cc7 100644 --- a/VetClinic/VetClinicAdminApp/Controllers/HomeController.cs +++ b/VetClinic/VetClinicAdminApp/Controllers/HomeController.cs @@ -5,8 +5,12 @@ using VetClinicContracts.BindingModels; using VetClinicContracts.ViewModels; using VetClinicDataModels.Models; using System.Text; +using System.Globalization; using VetClinicContracts.SearchModels; using System.IO.Pipelines; +using VetClinicContracts.BusinessLogicsContracts; +using VetClinicDataBaseImplement.Implements; +using VetClinicDataBaseImplement.Models; namespace VetClinicAdminApp.Controllers @@ -28,7 +32,8 @@ namespace VetClinicAdminApp.Controllers [HttpGet] public IActionResult Report() { - return View(); + ViewBag.Report = new List(); + return View(); } public IActionResult Index() { @@ -536,13 +541,13 @@ View(res); } [HttpGet] - public Tuple>? GetVisit(int visitId) + public Tuple>>? GetVisit(int visitId) { if (APIAdmin.Admin == null) { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } - var result = APIAdmin.GetRequest>>($"api/visit/getvisit?visitid={visitId}"); + var result = APIAdmin.GetRequest>>>($"api/visit/getvisit?visitid={visitId}"); if (result == null) { return default; @@ -551,13 +556,13 @@ View(res); return result; } [HttpGet] - public Tuple>? GetAnimal(int animalId) + public Tuple>>? GetAnimal(int animalId) { if (APIAdmin.Admin == null) { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } - var result = APIAdmin.GetRequest>>($"api/animal/getanimal?animalid={animalId}"); + var result = APIAdmin.GetRequest>>>($"api/animal/getanimal?animalid={animalId}"); if (result == null) { return default; @@ -595,5 +600,152 @@ View(res); return result; } - } + + [HttpPost] + public void ServiceListReport(List animals, string type) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + if (animals.Count <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + + + if (type == "docx") + { + APIAdmin.PostRequest("api/reportadmin/createservicelistwordfile", new ListServicesBindingModel + { + Animals = animals, + FileName = "C:\\ReportsCourseWork\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIAdmin.PostRequest("api/reportadmin/createservicelistexcelfile", new ListServicesBindingModel + { + Animals = animals, + FileName = "C:\\ReportsCourseWork\\excelfile.xlsx" + }); + Response.Redirect("GetExcelFile"); + } + } + + [HttpGet] + public IActionResult GetWordFile() + { + return new PhysicalFileResult("C:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } + + public IActionResult GetExcelFile() + { + return new PhysicalFileResult("C:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } + [HttpGet] + public string GetServicesReport(DateTime dateFrom, DateTime dateTo) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture); + string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture); + result = APIAdmin.GetRequest> + ($"api/reportadmin/getmedicinesvaccinationsreport?datefrom={dateFromS}&dateto={dateToS}&adminid={APIAdmin.Admin.Id}")!; + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + table += "

Предварительный отчет

"; + table += "
"; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + foreach (var visit in result) + { + table += ""; // Открываем блок данных для каждого визита + + // Строка для визита + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + + // Строки для вакцинаций + foreach (var vaccination in visit.Vaccinations) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + + // Строки для медикаментов + foreach (var medicine in visit.Medicines) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + + table += ""; // Закрываем блок данных для каждого визита + } + + // Конец таблицы + table += "
ДатаНазвание визитаЖивотное прививкиНазвание медикамента
{visit.VisitName}
{vaccination.DateStamp}{vaccination.AnimalName}
{medicine.MedicineName}
"; + table += "
"; + + return table; + } + [HttpPost] + public void Report(DateTime dateFrom, DateTime dateTo) + { + if (APIAdmin.Admin == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIAdmin.PostRequest("api/reportadmin/sendmedicinesvaccinationsreporttoemail", new MedicinesVaccinationsBindingModel + { + FileName = "C:\\ReportsCourseWork\\pdffile.pdf", + AdminId = APIAdmin.Admin.Id, + DateFrom = dateFrom, + DateTo = dateTo, + Email = APIAdmin.Admin.Email + + }); + Response.Redirect("Report"); + + } + + } } diff --git a/VetClinic/VetClinicAdminApp/VetClinicAdminApp.csproj b/VetClinic/VetClinicAdminApp/VetClinicAdminApp.csproj index 779cc0e..f90dd64 100644 --- a/VetClinic/VetClinicAdminApp/VetClinicAdminApp.csproj +++ b/VetClinic/VetClinicAdminApp/VetClinicAdminApp.csproj @@ -16,6 +16,7 @@ + diff --git a/VetClinic/VetClinicAdminApp/Views/Home/Report.cshtml b/VetClinic/VetClinicAdminApp/Views/Home/Report.cshtml index 5b3124a..eafee78 100644 --- a/VetClinic/VetClinicAdminApp/Views/Home/Report.cshtml +++ b/VetClinic/VetClinicAdminApp/Views/Home/Report.cshtml @@ -1,59 +1,65 @@ @{ - ViewData["Title"] = "Report"; + ViewData["Title"] = "Report"; } -
-

Список визитов с расшифровкой по медикаментам и прививкам

+ +
+
+

Отчет по визитам за период

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
-
- @{ - // if (Model == null) - // { - //

Авторизируйтесь!

- // return; - // } -
-
Начальная дата:
-
- -
-
-
-
Конечная дата:
-
- -
-
- - - - - - - - - - - - будет заполняться вьюшками отчета - -
- Номер - - Дата - - Визит - - Медикамент - - Прививка -
-
-
-
-
-
-
-
-
- } -
\ No newline at end of file + +@section Scripts { + +} \ No newline at end of file diff --git a/VetClinic/VetClinicAdminApp/Views/Home/ServiceListReport.cshtml b/VetClinic/VetClinicAdminApp/Views/Home/ServiceListReport.cshtml index 37422e1..fd328d0 100644 --- a/VetClinic/VetClinicAdminApp/Views/Home/ServiceListReport.cshtml +++ b/VetClinic/VetClinicAdminApp/Views/Home/ServiceListReport.cshtml @@ -22,9 +22,18 @@
-
-
-
-
+
+ +
+ + +
+
+ + +
+
+
+
diff --git a/VetClinic/VetClinicAdminApp/Views/Home/Update.cshtml b/VetClinic/VetClinicAdminApp/Views/Home/Update.cshtml index a97c5bb..da04b83 100644 --- a/VetClinic/VetClinicAdminApp/Views/Home/Update.cshtml +++ b/VetClinic/VetClinicAdminApp/Views/Home/Update.cshtml @@ -31,7 +31,7 @@
@@ -60,7 +60,7 @@ $('#date').val(result.item1.dateVisit); $.map(result.item2, function (n) { console.log("#" + n); - $(`option[data-name=${n}]`).attr("selected", "selected") + $(`option[data-name=${n.item2}]`).attr("selected", "selected") }); } }); diff --git a/VetClinic/VetClinicAdminApp/Views/Home/VisitAnimals.cshtml b/VetClinic/VetClinicAdminApp/Views/Home/VisitAnimals.cshtml index c3654fe..1c13e70 100644 --- a/VetClinic/VetClinicAdminApp/Views/Home/VisitAnimals.cshtml +++ b/VetClinic/VetClinicAdminApp/Views/Home/VisitAnimals.cshtml @@ -22,7 +22,7 @@ @@ -50,7 +50,7 @@ $('#family').val(result.item1.family); $.map(result.item2, function (n) { console.log("#" + n); - $(`option[data-name=${n}]`).attr("selected", "selected") + $(`option[data-name=${n.item2}]`).attr("selected", "selected") }); } diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicAdmin.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicAdmin.cs new file mode 100644 index 0000000..c966636 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicAdmin.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage; +using VetClinicBusinessLogic.OfficePackage.HelperModels; +using VetClinicContracts.BindingModels; +using VetClinicContracts.BusinessLogicsContracts; +using VetClinicContracts.SearchModels; +using VetClinicContracts.StoragesContracts; +using VetClinicContracts.ViewModels; +using VetClinicDataBaseImplement.Implements; + +namespace VetClinicBusinessLogic.BusinessLogics +{ + public class ReportLogicAdmin : IReportLogicAdmin + { + private readonly IAnimalStorage _animalStorage; + private readonly IVisitStorage _visitStorage; + private readonly AbstractSaveToExcelAdmin _saveToExcel; + private readonly AbstractSaveToWordAdmin _saveToWord; + private readonly AbstractSaveToPdfAdmin _saveToPdf; + public ReportLogicAdmin(IAnimalStorage animalStorage, IVisitStorage visitStorage, + AbstractSaveToExcelAdmin saveToExcel, AbstractSaveToWordAdmin saveToWord, + AbstractSaveToPdfAdmin saveToPdf) + { + _animalStorage = animalStorage; + _visitStorage = visitStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + + public List GetAnimalServices(List animals) + { + + List ans = new(); + List>>>> response = + _animalStorage.GetReportInfo(new ListServicesSearchModel { animalsIds = animals}); + + foreach (var animal in response) + { + Dictionary counter = new(); + foreach (var medicine in animal.Item2) + { + foreach (var service in medicine.Item2) + { + if (!counter.ContainsKey(service.Id)) + counter.Add(service.Id, (service, 1)); + else + { + counter[service.Id] = (counter[service.Id].Item1, counter[service.Id].Item2 + 1); + } + } + } + List res = new(); + foreach (var cnt in counter) + { + if (cnt.Value.Item2 != animal.Item2.Count) + continue; + res.Add(cnt.Value.Item1); + } + ans.Add(new ListServicesViewModel + { + AnimalName = animal.Item1.AnimalName, + Services = res + }); + } + return ans; + } + + public void SaveServicesToExcelFile(ListServicesBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfoAdmin + { + FileName = model.FileName, + Title = "Список услуг для животных", + AnimalsServices = GetAnimalServices(model.Animals) + }); + } + + public void SaveServicesToWordFile(ListServicesBindingModel model) + { + _saveToWord.CreateDoc(new WordInfoAdmin + { + FileName = model.FileName, + Title = "Список услуг для животных", + AnimalsServices = GetAnimalServices(model.Animals) + }); + } + + public List GetVisitMedicinesAndVaccinations(MedicinesVaccinationsBindingModel model) + { + List ans = new(); + List>>>> responseVaccinations = + _visitStorage.GetVaccinationsInfo(new MedicineVaccinationsSearchModel { DateFrom = model.DateFrom!, DateTo = model.DateTo!, AdminId = model.AdminId!}); + List>>>> responseMedicines = + _visitStorage.GetMedicinesInfo(new MedicineVaccinationsSearchModel { DateFrom = model.DateFrom!, DateTo = model.DateTo!, AdminId = model.AdminId! }); + Dictionary dict = new(); + + foreach(var visit in responseVaccinations) + { + dict.Add(visit.Item1.Id, new()); + dict[visit.Item1.Id].VisitName = visit.Item1.NameVisit; + foreach(var animal in visit.Item2) + { + foreach(var vaccination in animal.Item2) + { + dict[visit.Item1.Id].Vaccinations.Add(vaccination); + } + } + } + + foreach (var visit in responseMedicines) + { + HashSet used = new(); + foreach (var animal in visit.Item2) + { + foreach (var medicine in animal.Item2) + { + if (used.Contains(medicine.Id)) + continue; + dict[visit.Item1.Id].Medicines.Add(medicine); + used.Add(medicine.Id); + } + } + ans.Add(dict[visit.Item1.Id]); + } + return ans; + } + + public void SaveVisitsToPdfFile(MedicinesVaccinationsBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список визитов", + DateFrom = model.DateFrom!, + DateTo = model.DateTo!, + Visits = GetVisitMedicinesAndVaccinations(model) + }); + + } + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToExcelAdmin.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToExcelAdmin.cs new file mode 100644 index 0000000..75925fd --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToExcelAdmin.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage.HelperEnums; +using VetClinicBusinessLogic.OfficePackage.HelperModels; + +namespace VetClinicBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcelAdmin + { + public void CreateReport(ExcelInfoAdmin info) + { + CreateExcel(info); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + + uint rowIndex = 2; + + foreach (var rec in info.AnimalsServices) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = rec.AnimalName, + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + + foreach (var service in rec.Services) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = service.ServiceName, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + rowIndex++; + } + + rowIndex++; + } + + SaveExcel(info); + } + + protected abstract void CreateExcel(ExcelInfoAdmin info); + + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + protected abstract void MergeCells(ExcelMergeParameters excelParams); + + protected abstract void SaveExcel(ExcelInfoAdmin info); + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToPdfAdmin.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToPdfAdmin.cs new file mode 100644 index 0000000..adf2cfc --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToPdfAdmin.cs @@ -0,0 +1,72 @@ +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 AbstractSaveToPdfAdmin + { + 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 { "4cm", "4cm", "4cm", "4cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата", "Название визита", "Животное прививки", "Медикамент"}, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var visit in info.Visits) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "", visit.VisitName, "", "" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach(var medicine in visit.Medicines) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "", "", "", medicine.MedicineName }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + foreach (var vaccination in visit.Vaccinations) + { + CreateRow(new PdfRowParameters + { + Texts = new List { vaccination.DateStamp.ToString(), "", vaccination.AnimalName, "" }, + 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/AbstractSaveToWordAdmin.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToWordAdmin.cs new file mode 100644 index 0000000..bee64a9 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/AbstractSaveToWordAdmin.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage.HelperEnums; +using VetClinicBusinessLogic.OfficePackage.HelperModels; + +namespace VetClinicBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordAdmin + { + public void CreateDoc(WordInfoAdmin info) + { + CreateWord(info); + + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + foreach (var rec in info.AnimalsServices) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { (rec.AnimalName, new WordTextProperties { Size = "24", Bold=true})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + + foreach (var service in rec.Services) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { (service.ServiceName, new WordTextProperties { Size = "20", Bold=false})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }) ; + } + } + SaveWord(info); + } + + protected abstract void CreateWord(WordInfoAdmin info); + protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void SaveWord(WordInfoAdmin info); + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/ExcelInfoAdmin.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/ExcelInfoAdmin.cs new file mode 100644 index 0000000..095c9b2 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/ExcelInfoAdmin.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicContracts.ViewModels; + +namespace VetClinicBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfoAdmin + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List AnimalsServices + { + get; + set; + } = new(); + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 8e21977..bbfac25 100644 --- a/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -14,5 +14,7 @@ namespace VetClinicBusinessLogic.OfficePackage.HelperModels public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } public List Medicines { get; set; } = new(); + + public List Visits { get; set; } = new(); } } diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/WordInfoAdmin.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/WordInfoAdmin.cs new file mode 100644 index 0000000..753977d --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/HelperModels/WordInfoAdmin.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicContracts.ViewModels; + +namespace VetClinicBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfoAdmin + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List AnimalsServices { get; set; } = new(); + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToExcelAdmin.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToExcelAdmin.cs new file mode 100644 index 0000000..30f1e78 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToExcelAdmin.cs @@ -0,0 +1,333 @@ +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage.HelperEnums; +using VetClinicBusinessLogic.OfficePackage.HelperModels; + +namespace VetClinicBusinessLogic.OfficePackage.Implements +{ + public class SaveToExcelAdmin : AbstractSaveToExcelAdmin + { + private SpreadsheetDocument? _spreadsheetDocument; + private SharedStringTablePart? _shareStringPart; + private Worksheet? _worksheet; + + private static void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + fonts.Append(fontUsual); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 2U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); + + fills.Append(fill1); + fills.Append(fill2); + + var borders = new Borders() { Count = 2U }; + + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + + var borderThin = new Border(); + + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; + rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; + bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + + borders.Append(borderNoBorder); + borders.Append(borderThin); + + var cellStyleFormats = new CellStyleFormats() + { + Count = 1U + }; + var cellFormatStyle = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 0U + }; + + cellStyleFormats.Append(cellFormatStyle); + + var cellFormats = new CellFormats() + { + Count = 3U + }; + var cellFormatFont = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + ApplyFont = true + }; + var cellFormatFontAndBorder = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 1U, + FormatId = 0U, + ApplyFont = true, + ApplyBorder = true + }; + var cellFormatTitle = new CellFormat() + { + NumberFormatId = 0U, + FontId = 1U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + Alignment = new Alignment() + { + Vertical = VerticalAlignmentValues.Center, + WrapText = true, + Horizontal = HorizontalAlignmentValues.Center + }, + ApplyFont = true + }; + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + var cellStyles = new CellStyles() { Count = 1U }; + cellStyles.Append(new CellStyle() + { + Name = "Normal", + FormatId = 0U, + BuiltinId = 0U + }); + var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() + { + Count = 0U + }; + + var tableStyles = new TableStyles() + { + Count = 0U, + DefaultTableStyle = "TableStyleMedium2", + DefaultPivotStyle = "PivotStyleLight16" + }; + var stylesheetExtensionList = new StylesheetExtensionList(); + var stylesheetExtension1 = new StylesheetExtension() + { + Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" + }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() + { + DefaultSlicerStyle = "SlicerStyleLight1" + }); + var stylesheetExtension2 = new StylesheetExtension() + { + Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" + }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() + { + DefaultTimelineStyle = "TimeSlicerStyleLight1" + }); + + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBroder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(ExcelInfoAdmin info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); + var workbookpart = _spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + CreateStyles(workbookpart); + _shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() ? _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() : _spreadsheetDocument.WorkbookPart.AddNewPart(); + + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); + } + + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + _worksheet = worksheetPart.Worksheet; + } + + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + + var sheetData = _worksheet.GetFirstChild(); + + if (sheetData == null) + { + return; + } + + Row row; + + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + + Cell cell; + + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + var newCell = new Cell() + { + CellReference = excelParams.CellReference + }; + row.InsertBefore(newCell, refCell); + cell = newCell; + } + + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + + protected override void MergeCells(ExcelMergeParameters excelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells mergeCells; + if (_worksheet.Elements().Any()) + { + mergeCells = _worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(mergeCells, _worksheet.Elements().First()); + } + } + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + + protected override void SaveExcel(ExcelInfoAdmin info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Dispose(); + } + } +} diff --git a/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToPdfAdmin.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToPdfAdmin.cs new file mode 100644 index 0000000..23e0c59 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToPdfAdmin.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 SaveToPdfAdmin : AbstractSaveToPdfAdmin + { + 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/OfficePackage/Implements/SaveToWordAdmin.cs b/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToWordAdmin.cs new file mode 100644 index 0000000..cfff086 --- /dev/null +++ b/VetClinic/VetClinicBusinessLogic/OfficePackage/Implements/SaveToWordAdmin.cs @@ -0,0 +1,117 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VetClinicBusinessLogic.OfficePackage.HelperEnums; +using VetClinicBusinessLogic.OfficePackage.HelperModels; + +namespace VetClinicBusinessLogic.OfficePackage.Implements +{ + public class SaveToWordAdmin : AbstractSaveToWordAdmin + { + 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(WordInfoAdmin 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(WordInfoAdmin info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); + } + } +} diff --git a/VetClinic/VetClinicContracts/BindingModels/MedicineVaccinationsBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/MedicinesVaccinationsBindingModel.cs similarity index 54% rename from VetClinic/VetClinicContracts/BindingModels/MedicineVaccinationsBindingModel.cs rename to VetClinic/VetClinicContracts/BindingModels/MedicinesVaccinationsBindingModel.cs index 75e5cdd..4588bb6 100644 --- a/VetClinic/VetClinicContracts/BindingModels/MedicineVaccinationsBindingModel.cs +++ b/VetClinic/VetClinicContracts/BindingModels/MedicinesVaccinationsBindingModel.cs @@ -6,11 +6,13 @@ using System.Threading.Tasks; namespace VetClinicContracts.BindingModels { - public class MedicineVaccinationsBindingModel + public class MedicinesVaccinationsBindingModel { public string FileName { get; set; } = string.Empty; public List Visits { get; set; } = new(); - DateTime DateFrom { get; set; } = DateTime.Now; - DateTime DateTo { get; set; } = DateTime.Now; + public DateTime DateFrom { get; set; } = DateTime.Now; + public DateTime DateTo { get; set; } = DateTime.Now; + public int? AdminId { get; set; } + public string? Email { get; set; } } } diff --git a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicAdmin.cs b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicAdmin.cs index ee75480..8c691f1 100644 --- a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicAdmin.cs +++ b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicAdmin.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 IReportLogicAdmin //Будет дорабатываться + public interface IReportLogicAdmin { - List GetServiceAnimals(List animals); + List GetAnimalServices(List animals); void SaveServicesToWordFile(ListServicesBindingModel model); void SaveServicesToExcelFile(ListServicesBindingModel model); + List GetVisitMedicinesAndVaccinations(MedicinesVaccinationsBindingModel animals); + void SaveVisitsToPdfFile(MedicinesVaccinationsBindingModel model); } } diff --git a/VetClinic/VetClinicContracts/SearchModels/MedicineVaccinationsSearchModel.cs b/VetClinic/VetClinicContracts/SearchModels/MedicineVaccinationsSearchModel.cs index 7167b63..597d1d4 100644 --- a/VetClinic/VetClinicContracts/SearchModels/MedicineVaccinationsSearchModel.cs +++ b/VetClinic/VetClinicContracts/SearchModels/MedicineVaccinationsSearchModel.cs @@ -11,5 +11,6 @@ namespace VetClinicContracts.SearchModels public List? visitsIds { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? AdminId { get; set; } } } diff --git a/VetClinic/VetClinicContracts/ViewModels/ListServicesViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/ListServicesViewModel.cs index 9232ccd..8f27534 100644 --- a/VetClinic/VetClinicContracts/ViewModels/ListServicesViewModel.cs +++ b/VetClinic/VetClinicContracts/ViewModels/ListServicesViewModel.cs @@ -8,7 +8,7 @@ namespace VetClinicContracts.ViewModels { public class ListServicesViewModel { - public string ServiceName { get; set; } = string.Empty; + public string AnimalName { get; set; } = string.Empty; public List Services { get; set; } = new(); } } diff --git a/VetClinic/VetClinicContracts/ViewModels/MedicineVaccinationViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/MedicinesVaccinationsViewModel.cs similarity index 91% rename from VetClinic/VetClinicContracts/ViewModels/MedicineVaccinationViewModel.cs rename to VetClinic/VetClinicContracts/ViewModels/MedicinesVaccinationsViewModel.cs index 24d7749..2ebbeb8 100644 --- a/VetClinic/VetClinicContracts/ViewModels/MedicineVaccinationViewModel.cs +++ b/VetClinic/VetClinicContracts/ViewModels/MedicinesVaccinationsViewModel.cs @@ -7,7 +7,7 @@ using VetClinicContracts.ViewModels; namespace VetClinicDataBaseImplement.Implements { - public class MedicineVaccinationViewModel + public class MedicinesVaccinationsViewModel { public string VisitName { get; set; } = string.Empty; public List Medicines { get; set; } = new(); diff --git a/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs b/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs index 699045f..806e26d 100644 --- a/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs +++ b/VetClinic/VetClinicDataBaseImplement/Implements/VisitStorage.cs @@ -40,14 +40,10 @@ namespace VetClinicDataBaseImplement.Implements public List>>>> GetVaccinationsInfo(MedicineVaccinationsSearchModel model) { - if (model.visitsIds == null) - { - return new(); - } + using var context = new VetClinicDatabase(); - return context.Visits - .Where(visit => model.visitsIds.Contains(visit.Id)) - .Select(visit => new Tuple>>>(visit.GetViewModel, + return context.Visits.Where(visit => visit.AdminId == model.AdminId) + .Select(visit => new Tuple>>>(visit.GetViewModel, context.VisitAnimals.Include(animal => animal.Animal) .Include(animal => animal.Visit).Where(animal => visit.Id == animal.VisitId). Select(animal => new Tuple>(animal.Animal.GetViewModel, @@ -57,14 +53,10 @@ namespace VetClinicDataBaseImplement.Implements } public List>>>> GetMedicinesInfo(MedicineVaccinationsSearchModel model) { - if (model.visitsIds == null) - { - return new(); - } using var context = new VetClinicDatabase(); return context.Visits - .Where(visit => model.visitsIds.Contains(visit.Id)) - .Select(visit => new Tuple>>>(visit.GetViewModel, + .Where(visit => visit.AdminId == model.AdminId) + .Select(visit => new Tuple>>>(visit.GetViewModel, context.VisitAnimals.Include(animal => animal.Animal) .Include(animal => animal.Visit).Where(animal => visit.Id == animal.VisitId). Select(animal => new Tuple>(animal.Animal.GetViewModel, diff --git a/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs b/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs index 09ab1d2..7fed035 100644 --- a/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs +++ b/VetClinic/VetClinicRestApi/Controllers/AnimalContoller.cs @@ -21,14 +21,14 @@ namespace VetClinicRestApi.Controllers } [HttpGet] - public Tuple>? GetAnimal(int animalId) + public Tuple>>? GetAnimal(int animalId) { try { var elem = _animal.ReadElement(new AnimalSearchModel { Id = animalId }); if (elem == null) return null; - var res = Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.NameVisit).ToList()); + var res = Tuple.Create(elem, elem.VisitAnimals.Select(x => Tuple.Create(x.Value.NameVisit, x.Value.Id)).ToList()); res.Item1.VisitAnimals = null!; return res; } diff --git a/VetClinic/VetClinicRestApi/Controllers/ReportAdminController.cs b/VetClinic/VetClinicRestApi/Controllers/ReportAdminController.cs new file mode 100644 index 0000000..23ad5de --- /dev/null +++ b/VetClinic/VetClinicRestApi/Controllers/ReportAdminController.cs @@ -0,0 +1,93 @@ +using Microsoft.AspNetCore.Mvc; +using VetClinicBusinessLogic.BusinessLogics; +using VetClinicBusinessLogic.MailWorker; +using VetClinicContracts.BindingModels; +using VetClinicContracts.BusinessLogicsContracts; +using VetClinicDataBaseImplement.Implements; + +namespace VetClinicRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportAdminController : Controller + { + private readonly IReportLogicAdmin _reportAdmin; + private readonly AbstractMailWorker _mailWorker; + public ReportAdminController(ILogger logger, IReportLogicAdmin reportAdmin,AbstractMailWorker mailWorker) + { + _reportAdmin = reportAdmin; + _mailWorker = mailWorker; + } + + [Microsoft.AspNetCore.Mvc.HttpGet] + public IActionResult Index(ReportLogicAdmin reportAdmin) + { + return View(); + } + + [HttpPost] + public void CreateServiceListWordFile(ListServicesBindingModel model) + { + try + { + _reportAdmin.SaveServicesToWordFile(model); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void CreateServiceListExcelFile(ListServicesBindingModel model) + { + try + { + _reportAdmin.SaveServicesToExcelFile(model); + } + catch (Exception ex) + { + throw; + } + } + + [HttpGet] + public List GetMedicinesVaccinationsReport(string dateFrom, string dateTo, int adminId) + { + try + { + DateTime DateFrom = DateTime.Parse(dateFrom); + DateTime DateTo = DateTime.Parse(dateTo); + MedicinesVaccinationsBindingModel model = new(); + model.DateFrom = DateFrom; + model.DateTo = DateTo; + model.AdminId = adminId; + return _reportAdmin.GetVisitMedicinesAndVaccinations(model); + } + catch (Exception ex) + { + throw; + } + } + + + [HttpPost] + public void SendMedicinesVaccinationsReportToEmail(MedicinesVaccinationsBindingModel model) + { + try + { + _reportAdmin.SaveVisitsToPdfFile(model); + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = model.Email!, + Subject = "Отчет по визитам", + Text = "Лови" + }); + } + catch (Exception ex) + { + throw; + } + } + } +} diff --git a/VetClinic/VetClinicRestApi/Controllers/ReportController.cs b/VetClinic/VetClinicRestApi/Controllers/ReportController.cs index 50a895b..23c3679 100644 --- a/VetClinic/VetClinicRestApi/Controllers/ReportController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/ReportController.cs @@ -12,12 +12,13 @@ namespace VetClinicRestApi.Controllers public class ReportController : Controller { private readonly IReportLogicPharmacist _reportPharmacist; - private readonly AbstractMailWorker _mailWorker; + private readonly AbstractMailWorker _mailWorker; public ReportController(ILogger logger, IReportLogicPharmacist reportPharmacist,AbstractMailWorker mailWorker) { _reportPharmacist = reportPharmacist; - _mailWorker = mailWorker; + _mailWorker = mailWorker; } + [Microsoft.AspNetCore.Mvc.HttpGet] public IActionResult Index(ReportLogicPharmacist reportPharmacist) { @@ -35,6 +36,7 @@ namespace VetClinicRestApi.Controllers throw; } } + [HttpPost] public void CreateAnimalListExcelFile(ListAnimalsBindingModel model) { @@ -47,6 +49,7 @@ namespace VetClinicRestApi.Controllers throw; } } + [HttpGet] public List GetVisitsGuidesReport(string dateFrom, string dateTo, int pharmacistId) { @@ -65,8 +68,9 @@ namespace VetClinicRestApi.Controllers throw; } } + - [HttpPost] + [HttpPost] public void SendVisitsGuidesReportToEmail(VisitsGuidesBindingModel model) { try @@ -84,5 +88,6 @@ namespace VetClinicRestApi.Controllers throw; } } - } + + } } diff --git a/VetClinic/VetClinicRestApi/Controllers/VisitController.cs b/VetClinic/VetClinicRestApi/Controllers/VisitController.cs index 20e43c5..064f31b 100644 --- a/VetClinic/VetClinicRestApi/Controllers/VisitController.cs +++ b/VetClinic/VetClinicRestApi/Controllers/VisitController.cs @@ -21,14 +21,14 @@ namespace VetClinicRestApi.Controllers } [HttpGet] - public Tuple>? GetVisit(int VisitId) + public Tuple>>? GetVisit(int VisitId) { try { var elem = _visit.ReadElement(new VisitSearchModel { Id = VisitId }); if (elem == null) return null; - var res = Tuple.Create(elem, elem.ServiceVisits.Select(x => x.Value.ServiceName).ToList()); + var res = Tuple.Create(elem, elem.ServiceVisits.Select(x => Tuple.Create(x.Value.ServiceName, x.Value.Id)).ToList()); res.Item1.ServiceVisits = null; return res; } diff --git a/VetClinic/VetClinicRestApi/Program.cs b/VetClinic/VetClinicRestApi/Program.cs index da7360b..1240f63 100644 --- a/VetClinic/VetClinicRestApi/Program.cs +++ b/VetClinic/VetClinicRestApi/Program.cs @@ -35,9 +35,13 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddSingleton();