diff --git a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/ReportLogicOwner.cs b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/ReportLogicOwner.cs index 3e8e83d..60b0849 100644 --- a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/ReportLogicOwner.cs +++ b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/ReportLogicOwner.cs @@ -7,6 +7,7 @@ using VeterinaryContracts.BusinessLogicContracts; using VeterinaryContracts.SearchModels; using VeterinaryContracts.StorageContracts; using VeterinaryContracts.ViewModels; +using VeterinaryDatabaseImplement.Implements; namespace VeterinaryBusinessLogic.BusinessLogic { @@ -15,17 +16,51 @@ namespace VeterinaryBusinessLogic.BusinessLogic private readonly IPetStorage _petStorage; private readonly AbstractSaveToExcelOwner _saveToExcel; private readonly AbstractSaveToWordOwner _saveToWord; - public ReportLogicOwner(IPetStorage petStorage, - AbstractSaveToExcelOwner saveToExcel, AbstractSaveToWordOwner saveToWord) + private readonly AbstractSaveToPdfDoctor _saveToPdf; + public ReportLogicOwner(IPetStorage petStorage, + AbstractSaveToExcelOwner saveToExcel, AbstractSaveToWordOwner saveToWord, AbstractSaveToPdfDoctor saveToPdf) { _petStorage = petStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; - } + _saveToPdf = saveToPdf; + } - public List GetPetServices(ReportServicesBindingModel model) + public List GetPetServices(ReportServicesBindingModel model) { - return _petStorage.GetReportServices(new() { petsIds = model.Pets}); + //List ans = new(); + //List response = _serviceStorage.GetReportServices(new ReportPetsSearchModel { servicesIds = services }); + //List respons = _petStorage.GetReportServices(new ReportServicesSearchModel { petsIds = pets }); + //foreach (var service in response) + //{ + // Dictionary counter = new(); + // foreach (var visit in service.Services) + // { + // foreach (var pet in visit.ServiceMedications) + // { + // if (!counter.ContainsKey(pet.Id)) + // counter.Add(pet.Id, (pet, 1)); + // else + // { + // counter[pet.Id] = (counter[pet.Id].Item1, counter[pet.Id].Item2 + 1); + // } + // } + // } + // List res = new(); + // foreach (var cnt in counter) + // { + // if (cnt.Value.Item2 != service.Count) + // continue; + // res.Add(cnt.Value.Item1); + // } + // ans.Add(new ReportPetsViewModel + // { + // ServiceName = service.Item1.ServiceName, + // Animals = res + // }); + //} + //return ans; + return _petStorage.GetReportServices(new() { petsIds = model.Pets }); } public List GetVisitsDrugs(ReportVisitsDrugsBindingModel model) { @@ -36,7 +71,7 @@ namespace VeterinaryBusinessLogic.BusinessLogic _saveToExcel.CreateReport(new ExcelInfoOwner { FileName = model.FileName, - Title = "Список услуг для животных", + Title = "Список услуг по животным", PetServices = GetPetServices(model) }); } @@ -46,9 +81,21 @@ namespace VeterinaryBusinessLogic.BusinessLogic _saveToWord.CreateDoc(new WordInfoOwner { FileName = model.FileName, - Title = "Список услуг для животных", + Title = "Список услуг по животным", PetServices = GetPetServices(model) }); } - } + public void SavePetsToPdfFile(ReportVisitsDrugsBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список животных", + DateFrom = model.DateFrom!, + DateTo = model.DateTo!, + ReportVisitsDrugs = GetVisitsDrugs(model) + }); + + } + } } diff --git a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/AbstractSaveToPdfOwner.cs b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/AbstractSaveToPdfOwner.cs new file mode 100644 index 0000000..4bd19d7 --- /dev/null +++ b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/AbstractSaveToPdfOwner.cs @@ -0,0 +1,65 @@ +using VeterinaryBusinessLogic.OfficePackage.HelperEnums; +using VeterinaryBusinessLogic.OfficePackage.HelperModels; + +namespace VeterinaryBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfOwner + { + 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 pet in info.ReportVisitsDrugs) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "", pet.PetName, "", "" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var visit in pet.Visits) + { + CreateRow(new PdfRowParameters + { + Texts = new List { visit.DateVisit.ToString(), "", "", visit.VisitName }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + foreach (var guidance in pet.Drugs) + { + CreateRow(new PdfRowParameters + { + Texts = new List { guidance.DateCreate.ToString(), "", guidance.DrugName, "" }, + 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/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/HelperModels/ExcelInfoOwner.cs b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/HelperModels/ExcelInfoOwner.cs index 5fcd030..ca0b082 100644 --- a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/HelperModels/ExcelInfoOwner.cs +++ b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/HelperModels/ExcelInfoOwner.cs @@ -6,6 +6,6 @@ namespace VeterinaryBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List PetServices { get; set; } = new(); + public List PetServices { get; set; } = new(); } } diff --git a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/HelperModels/WordInfoOwner.cs b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/HelperModels/WordInfoOwner.cs index 5fe03a0..353194b 100644 --- a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/HelperModels/WordInfoOwner.cs +++ b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/HelperModels/WordInfoOwner.cs @@ -6,6 +6,6 @@ namespace VeterinaryBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List PetServices { get; set; } = new(); + public List PetServices { get; set; } = new(); } } diff --git a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToPdf.cs deleted file mode 100644 index b804a26..0000000 --- a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ /dev/null @@ -1,15 +0,0 @@ -using MigraDoc.DocumentObjectModel; -using MigraDoc.DocumentObjectModel.Tables; -using MigraDoc.Rendering; - -namespace VeterinaryBusinessLogic.OfficePackage.Implements -{ - public class SaveToPdf - { - private Document? _document; - - private Section? _section; - - private Table? _table; - } -} diff --git a/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToPdfOwner.cs b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToPdfOwner.cs new file mode 100644 index 0000000..62cc122 --- /dev/null +++ b/VeterinaryView/VeterinaryBusinessLogic/OfficePackage/Implements/SaveToPdfOwner.cs @@ -0,0 +1,101 @@ +using MigraDoc.DocumentObjectModel; +using MigraDoc.Rendering; +using MigraDoc.DocumentObjectModel.Tables; +using VeterinaryBusinessLogic.OfficePackage.HelperEnums; +using VeterinaryBusinessLogic.OfficePackage.HelperModels; + +namespace VeterinaryBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdfOwner : AbstractSaveToPdfOwner + { + 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.Right => 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/VeterinaryView/VeterinaryContracts/BindingModels/ReportVisitsDrugsBindingModel.cs b/VeterinaryView/VeterinaryContracts/BindingModels/ReportVisitsDrugsBindingModel.cs index 2dffabb..35229ed 100644 --- a/VeterinaryView/VeterinaryContracts/BindingModels/ReportVisitsDrugsBindingModel.cs +++ b/VeterinaryView/VeterinaryContracts/BindingModels/ReportVisitsDrugsBindingModel.cs @@ -4,7 +4,9 @@ { public string FileName { get; set; } = string.Empty; public List Pets { get; set; } = new(); - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } - } + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public int? OwnerId { get; set; } + public string? Email { get; set; } + } } diff --git a/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IReportLogicOwner.cs b/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IReportLogicOwner.cs index 263282b..7c93fd0 100644 --- a/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IReportLogicOwner.cs +++ b/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IReportLogicOwner.cs @@ -5,9 +5,10 @@ namespace VeterinaryContracts.BusinessLogicContracts { public interface IReportLogicOwner { - List GetPetServices(ReportServicesBindingModel model); + List GetPetServices(ReportServicesBindingModel model); List GetVisitsDrugs(ReportVisitsDrugsBindingModel model); void SaveServicesToWordFile(ReportServicesBindingModel model); void SaveServicesToExcelFile(ReportServicesBindingModel model); - } + void SavePetsToPdfFile(ReportVisitsDrugsBindingModel model); + } } \ No newline at end of file diff --git a/VeterinaryView/VeterinaryContracts/SearchModels/ReportPetsSearchModel.cs b/VeterinaryView/VeterinaryContracts/SearchModels/ReportPetsSearchModel.cs new file mode 100644 index 0000000..d4cfded --- /dev/null +++ b/VeterinaryView/VeterinaryContracts/SearchModels/ReportPetsSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryContracts.SearchModels +{ + public class ReportPetsSearchModel + { + public List? servicesIds { get; set; } + } +} diff --git a/VeterinaryView/VeterinaryContracts/StorageContracts/IPetStorage.cs b/VeterinaryView/VeterinaryContracts/StorageContracts/IPetStorage.cs index ad20095..d05b750 100644 --- a/VeterinaryView/VeterinaryContracts/StorageContracts/IPetStorage.cs +++ b/VeterinaryView/VeterinaryContracts/StorageContracts/IPetStorage.cs @@ -8,7 +8,7 @@ namespace VeterinaryContracts.StorageContracts { List GetFullList(); List GetFilteredList(PetSearchModel model); - List GetReportServices(ReportServicesSearchModel model); + List GetReportServices(ReportServicesSearchModel model); List GetReportVisitsDrugs(ReportVisitsDrugsSearchModel model); PetViewModel? GetElement(PetSearchModel model); PetViewModel? Insert(PetBindingModel model); diff --git a/VeterinaryView/VeterinaryContracts/StorageContracts/IServiceStorage.cs b/VeterinaryView/VeterinaryContracts/StorageContracts/IServiceStorage.cs index ebfe28e..b7a331d 100644 --- a/VeterinaryView/VeterinaryContracts/StorageContracts/IServiceStorage.cs +++ b/VeterinaryView/VeterinaryContracts/StorageContracts/IServiceStorage.cs @@ -13,6 +13,7 @@ namespace VeterinaryContracts.StorageContracts { List GetFullList(); List GetFilteredList(ServiceSearchModel model); + //List GetReportServices(ReportPetsSearchModel model); ServiceViewModel? GetElement(ServiceSearchModel model); ServiceViewModel? Insert(ServiceBindingModel model); ServiceViewModel? Update(ServiceBindingModel model); diff --git a/VeterinaryView/VeterinaryContracts/ViewModels/ReportPetsViewModel.cs b/VeterinaryView/VeterinaryContracts/ViewModels/ReportPetsViewModel.cs new file mode 100644 index 0000000..8a2eecb --- /dev/null +++ b/VeterinaryView/VeterinaryContracts/ViewModels/ReportPetsViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VeterinaryContracts.ViewModels +{ + public class ReportPetsViewModel + { + public string ServiceName { get; set; } = string.Empty; + public List Pets { get; set; } = new(); + } +} diff --git a/VeterinaryView/VeterinaryContracts/ViewModels/ReportPetServicesViewModel.cs b/VeterinaryView/VeterinaryContracts/ViewModels/ReportServicesViewModel.cs similarity index 80% rename from VeterinaryView/VeterinaryContracts/ViewModels/ReportPetServicesViewModel.cs rename to VeterinaryView/VeterinaryContracts/ViewModels/ReportServicesViewModel.cs index 013fa7a..923e7e6 100644 --- a/VeterinaryView/VeterinaryContracts/ViewModels/ReportPetServicesViewModel.cs +++ b/VeterinaryView/VeterinaryContracts/ViewModels/ReportServicesViewModel.cs @@ -1,6 +1,6 @@ namespace VeterinaryContracts.ViewModels { - public class ReportPetServicesViewModel + public class ReportServicesViewModel { public string PetName { get; set; } = string.Empty; public List Services { get; set; } = new(); diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/OwnerStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/OwnerStorage.cs index 5ce1269..e4b12af 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/OwnerStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/OwnerStorage.cs @@ -1,4 +1,5 @@ -using VeterinaryContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using VeterinaryContracts.BindingModels; using VeterinaryContracts.SearchModels; using VeterinaryContracts.StorageContracts; using VeterinaryContracts.ViewModels; diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Implements/PetStorage.cs b/VeterinaryView/VeterinaryDatabaseImplement/Implements/PetStorage.cs index 7344db6..bc76a54 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Implements/PetStorage.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Implements/PetStorage.cs @@ -40,7 +40,7 @@ namespace VeterinaryDatabaseImplement.Implements (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } - public List GetReportServices(ReportServicesSearchModel model) + public List GetReportServices(ReportServicesSearchModel model) { if (model.petsIds == null) { @@ -49,7 +49,8 @@ namespace VeterinaryDatabaseImplement.Implements using var context = new VeterinaryDatabase(); return context.Pets .Where(pet => model.petsIds == null || model.petsIds.Contains(pet.Id)) - .Select(pet => new ReportPetServicesViewModel() + .Include() + .Select(pet => new ReportServicesViewModel() { PetName = pet.PetName, Services = context.Services.Include(service => service.Visit).ThenInclude(visit => visit.Pets) diff --git a/VeterinaryView/VeterinaryDatabaseImplement/Models/Visit.cs b/VeterinaryView/VeterinaryDatabaseImplement/Models/Visit.cs index e29a0e6..01ace6d 100644 --- a/VeterinaryView/VeterinaryDatabaseImplement/Models/Visit.cs +++ b/VeterinaryView/VeterinaryDatabaseImplement/Models/Visit.cs @@ -69,7 +69,8 @@ namespace VeterinaryDatabaseImplement.Models VisitName = VisitName, DoctorId = DoctorId, DoctorName = Doctor?.DoctorFIO ?? string.Empty, - DateVisit = DateVisit + DateVisit = DateVisit, + //VisitPet = VisitPet, }; //public void UpdateVisits(VeterinaryDatabase context, VisitBindingModel model) //{ diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/ReportController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/ReportController.cs index 5327569..21bbba9 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/ReportController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/ReportController.cs @@ -49,7 +49,7 @@ namespace VeterinaryRestApi.Controllers } } [HttpGet] - public List GetVisitsGuidesReport(string dateFrom, string dateTo, int doctorId)// переименовать + public List GetDrugsVisitsReport(string dateFrom, string dateTo, int doctorId) { try { @@ -68,7 +68,7 @@ namespace VeterinaryRestApi.Controllers } [HttpPost] - public void SendVisitsGuidesReportToEmail(ReportDrugsVisitsBindingModel model)// переименовать + public void SendDrugsVisitsReportToEmail(ReportDrugsVisitsBindingModel model) { try { diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/ReportOwnerController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/ReportOwnerController.cs new file mode 100644 index 0000000..8cb818a --- /dev/null +++ b/VeterinaryView/VeterinaryRestApi/Controllers/ReportOwnerController.cs @@ -0,0 +1,88 @@ +using Microsoft.AspNetCore.Mvc; +using VeterinaryBusinessLogic.BusinessLogic; +using VeterinaryBusinessLogic.MailWorker; +using VeterinaryContracts.BindingModels; +using VeterinaryContracts.BusinessLogicContracts; +using VeterinaryContracts.ViewModels; + +namespace VeterinaryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportOwnerController : Controller + { + private readonly IReportLogicOwner _reportOwner; + private readonly AbstractMailWorker _mailWorker; + public ReportOwnerController(ILogger logger, IReportLogicOwner reportOwner, AbstractMailWorker mailWorker) + { + _reportOwner = reportOwner; + _mailWorker = mailWorker; + } + [Microsoft.AspNetCore.Mvc.HttpGet] + public IActionResult Index(ReportLogicDoctor reportDoctor) + { + return View(); + } + [HttpPost] + public void CreateServiceListWordFile(ReportServicesBindingModel model) + { + try + { + _reportOwner.SaveServicesToWordFile(model); + } + catch (Exception ex) + { + throw; + } + } + [HttpPost] + public void CreateServiceListExcelFile(ReportServicesBindingModel model) + { + try + { + _reportOwner.SaveServicesToExcelFile(model); + } + catch (Exception ex) + { + throw; + } + } + [HttpGet] + public List? GetVisitsDrugsReport(string dateFrom, string dateTo, int ownerId) + { + try + { + DateTime DateFrom = DateTime.Parse(dateFrom); + DateTime DateTo = DateTime.Parse(dateTo); + ReportVisitsDrugsBindingModel model = new(); + model.DateFrom = DateFrom; + model.DateTo = DateTo; + model.OwnerId = ownerId; + return _reportOwner.GetVisitsDrugs(model); + } + catch (Exception ex) + { + throw; + } + } + + [HttpPost] + public void SendVisitsDrugsReportToEmail(ReportVisitsDrugsBindingModel model) + { + try + { + _reportOwner.SavePetsToPdfFile(model); + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = model.Email!, + Subject = "Отчет по животным", + Text = "Лови" + }); + } + catch (Exception ex) + { + throw; + } + } + } +} diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs index 0619ad8..68bd3db 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/VisitController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using DocumentFormat.OpenXml.Wordprocessing; +using Microsoft.AspNetCore.Mvc; using VeterinaryContracts.BindingModels; using VeterinaryContracts.BusinessLogicContracts; using VeterinaryContracts.SearchModels; @@ -19,14 +20,16 @@ namespace VeterinaryRestApi.Controllers _visit = visit; } [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; - return Tuple.Create(elem); + var res = Tuple.Create(elem, elem.VisitPet.Select(x => Tuple.Create(x.Value.PetName, x.Value.Id)).ToList()); + res.Item1.VisitPet = null!; + return res; } catch (Exception ex) { @@ -35,11 +38,18 @@ namespace VeterinaryRestApi.Controllers } } [HttpGet] - public List? GetVisits(int ownerId) + public List? GetVisits(int? ownerId = null) { try { - return _visit.ReadList(new VisitSearchModel { OwnerId = ownerId }); + List res; + if (!ownerId.HasValue) + res = _visit.ReadList(null); + else + res = _visit.ReadList(new VisitSearchModel { OwnerId = ownerId.Value }); + foreach (var service in res) + service.VisitPet = null; + return res; } catch (Exception ex) { diff --git a/VeterinaryView/VeterinaryRestApi/Program.cs b/VeterinaryView/VeterinaryRestApi/Program.cs index 895efe2..28e0f98 100644 --- a/VeterinaryView/VeterinaryRestApi/Program.cs +++ b/VeterinaryView/VeterinaryRestApi/Program.cs @@ -31,9 +31,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(); builder.Services.AddControllers(); diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs index 09cf28b..120d547 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs +++ b/VeterinaryView/VeterinaryShowOwnerApp/Controllers/HomeController.cs @@ -8,6 +8,7 @@ using System.Reflection; using VeterinaryDataModels.Models; using VeterinaryContracts.SearchModels; using Microsoft.Extensions.Hosting; +using System.Globalization; namespace VeterinaryShowOwnerApp.Controllers { @@ -313,18 +314,28 @@ namespace VeterinaryShowOwnerApp.Controllers Response.Redirect("Visits"); } [HttpGet] - public Tuple>? GetVisit(int visitId) + public Tuple>>? GetVisit(int visitId) { if (APIOwner.Owner == null) { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - var result = APIOwner.GetRequest>>($"api/visit/getvisit?visitid={visitId}"); + var result = APIOwner.GetRequest>>>($"api/visit/getvisit?visitid={visitId}"); if (result == null) { return default; } - return result; + string table = ""; + result.Item1.VisitPet.Clear(); + for (int i = 0; i < result.Item2.Count; i++) + { + var pet = result.Item2[i].Item1; + table += ""; + table += $"{pet}"; + table += ""; + } + //return Tuple.Create(result.Item1, table); + return null; } public IActionResult Purchases() { @@ -372,13 +383,11 @@ namespace VeterinaryShowOwnerApp.Controllers }); Response.Redirect("Purchases"); } - // с какого хера ты не работаешь [HttpPost] public double Calc(int count, int drug) { var price = APIOwner.GetRequest($"api/drug/getonedrug?drugId={drug}"); return count * (price?.Price ?? 1); - //return Math.Round(count * (price?.Price ?? 1), 2); } [HttpGet] @@ -396,7 +405,7 @@ namespace VeterinaryShowOwnerApp.Controllers return result; } [HttpGet] - public IActionResult PetListReport() + public IActionResult ServicePetReport() { if (APIOwner.Owner == null) { @@ -405,14 +414,145 @@ namespace VeterinaryShowOwnerApp.Controllers ViewBag.Pets = APIOwner.GetRequest>($"api/pet/getpets?ownerid={APIOwner.Owner.Id}"); return View(); } - [HttpGet] - public IActionResult Report() - { - if (APIOwner.Owner == null) - { - return Redirect("~/Home/Enter"); - } - return View(); - } - } + [HttpPost] + public void ServicePetReport(List pets, string type) + { + if (APIOwner.Owner == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + if (pets.Count <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + if (type == "docx") + { + APIOwner.PostRequest("api/reportowner/createservicelistwordfile", new ReportServicesBindingModel + { + Pets = pets, + FileName = "C:\\ReportsCourseWork\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIOwner.PostRequest("api/reportowner/createservicelistexcelfile", new ReportServicesBindingModel + { + Pets = pets, + 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 IActionResult Report() + { + ViewBag.Report = new List(); + return View(); + } + [HttpGet] + public string GetPetsReport(DateTime dateFrom, DateTime dateTo) + { + if (APIOwner.Owner == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture); + string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture); + result = APIOwner.GetRequest> + ($"api/reportowner/getvisitsdrugsreport?datefrom={dateFromS}&dateto={dateToS}&ownerid={APIOwner.Owner.Id}")!; + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + table += "

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

"; + table += "
"; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + foreach (var medication in result) + { + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + foreach (var visit in medication.Visits) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + foreach (var drug in medication.Drugs) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + table += ""; + } + table += "
ДатаЖивотноеНазвание визитаЛекарство
{medication.PetName}
{visit.DateVisit}{visit.VisitName}
{drug.DateCreate}{drug.DrugName}
"; + table += "
"; + return table; + } + + [HttpPost] + public void Report(DateTime dateFrom, DateTime dateTo) + { + if (APIOwner.Owner == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIOwner.PostRequest("api/report/sendvisitsdrugsreporttoemail", new ReportVisitsDrugsBindingModel + { + FileName = "C:\\ReportsCourseWork\\pdffile.pdf", + OwnerId = APIOwner.Owner.Id, + DateFrom = dateFrom, + DateTo = dateTo, + Email = APIOwner.Owner.Login + + }); + Response.Redirect("Report"); + + } + } } \ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/Report.cshtml b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/Report.cshtml index 6f97fc3..f1d959d 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/Report.cshtml +++ b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/Report.cshtml @@ -1,54 +1,64 @@ @{ ViewData["Title"] = "Report"; } -
-

Список животных с расшифровкой по посещениям и лекарствам

+
+
+

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

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
-
- @{ -
-
Начальная дата:
-
- -
-
-
-
Конечная дата:
-
- -
-
- - - - - - - - - - - - будет заполняться вьюшками отчета - -
- Номер - - Дата - - Животное - - Посещение - - Лекарство -
-
-
-
-
-
-
-
-
- } -
\ No newline at end of file + +@section Scripts { + +} \ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/ServiceListReport.cshtml b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/ServiceListReport.cshtml deleted file mode 100644 index b6538e7..0000000 --- a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/ServiceListReport.cshtml +++ /dev/null @@ -1,27 +0,0 @@ -@using VeterinaryContracts.ViewModels; - -@{ - ViewData["Title"] = "ServiceListReport"; -} - -
-

Создать списки услуг для животных

-
-
-
-
Животные:
-
- -
-
-
-
-
-
-
-
\ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/ServicePetReport.cshtml b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/ServicePetReport.cshtml new file mode 100644 index 0000000..f4173b7 --- /dev/null +++ b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/ServicePetReport.cshtml @@ -0,0 +1,36 @@ +@using VeterinaryContracts.ViewModels; + +@{ + ViewData["Title"] = "ServiceListReport"; +} + +
+

Создать списки услуг для животных

+
+
+
+
Животные:
+
+ +
+
+
+ +
+ + +
+
+ + +
+
+
+ +
+
\ No newline at end of file diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Views/Shared/_Layout.cshtml b/VeterinaryView/VeterinaryShowOwnerApp/Views/Shared/_Layout.cshtml index 6060d39..cc60b84 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Views/Shared/_Layout.cshtml +++ b/VeterinaryView/VeterinaryShowOwnerApp/Views/Shared/_Layout.cshtml @@ -38,7 +38,7 @@ Регистрация