diff --git a/VetClinic/PharmacistApp/Controllers/HomeController.cs b/VetClinic/PharmacistApp/Controllers/HomeController.cs index 8c73825..853f532 100644 --- a/VetClinic/PharmacistApp/Controllers/HomeController.cs +++ b/VetClinic/PharmacistApp/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using PharmacistApp.Models; using System.Diagnostics; using System.Text; using VetClinicContracts.BindingModels; +using VetClinicContracts.BusinessLogicsContracts; using VetClinicContracts.SearchModels; using VetClinicContracts.ViewModels; using VetClinicDataBaseImplement.Models; @@ -592,6 +593,57 @@ View(res); ViewBag.Services = APIPharmacist.GetRequest>($"api/service/getservices?pharmacistid={APIPharmacist.Pharmacist.Id}"); return View(); } + + [HttpPost] + public void AnimalListReport(List services, string type) + { + if (APIPharmacist.Pharmacist == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + if (services.Count <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + + + if (type == "docx") + { + APIPharmacist.PostRequest("api/report/createanimallistwordfile", new ListAnimalsBindingModel + { + Services = services, + FileName = "C:\\ReportsCourseWork\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIPharmacist.PostRequest("api/report/createanimallistexcelfile", new ListAnimalsBindingModel + { + Services = services, + 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() { diff --git a/VetClinic/PharmacistApp/Views/Home/AnimalListReport.cshtml b/VetClinic/PharmacistApp/Views/Home/AnimalListReport.cshtml index 2cec407..fc17311 100644 --- a/VetClinic/PharmacistApp/Views/Home/AnimalListReport.cshtml +++ b/VetClinic/PharmacistApp/Views/Home/AnimalListReport.cshtml @@ -19,9 +19,18 @@ -
-
-
-
+
+ +
+ + +
+
+ + +
+
+
+
diff --git a/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs b/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs index 68b3293..9e77022 100644 --- a/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs +++ b/VetClinic/VetClinicBusinessLogic/BusinessLogics/ReportLogicPharmacist.cs @@ -10,6 +10,7 @@ using VetClinicContracts.BusinessLogicsContracts; using VetClinicContracts.SearchModels; using VetClinicContracts.StoragesContracts; using VetClinicContracts.ViewModels; +using VetClinicDataBaseImplement.Implements; namespace VetClinicBusinessLogic.BusinessLogics { @@ -19,13 +20,16 @@ namespace VetClinicBusinessLogic.BusinessLogics private readonly IMedicineStorage _medicineStorage; private readonly AbstractSaveToExcelPharmacist _saveToExcel; private readonly AbstractSaveToWordPharmacist _saveToWord; + private readonly AbstractSaveToPdfPharmacist _saveToPdf; public ReportLogicPharmacist(IServiceStorage serviceStorage, IMedicineStorage medicineStorage, - AbstractSaveToExcelPharmacist saveToExcel, AbstractSaveToWordPharmacist saveToWord) + AbstractSaveToExcelPharmacist saveToExcel, AbstractSaveToWordPharmacist saveToWord, + AbstractSaveToPdfPharmacist saveToPdf) { _serviceStorage = serviceStorage; _medicineStorage = medicineStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; + _saveToPdf = saveToPdf; } public List GetServiceAnimals(List services) @@ -86,42 +90,57 @@ namespace VetClinicBusinessLogic.BusinessLogics }); } - public List GetMedicineVisitsAndGuidances(List services) + public List GetMedicineVisitsAndGuidances(VisitsGuidesBindingModel model) { + var medicines = model.Medicines; + List ans = new(); + List>>>> responseGuides = + _medicineStorage.GetGuidancesInfo(new VisitGuidesSearchModel { medicinesIds = medicines, DateFrom = model.DateFrom!, DateTo = model.DateTo!}); + List>>>> responseVisits = + _medicineStorage.GetVisitsInfo(new VisitGuidesSearchModel { medicinesIds = medicines, DateFrom = model.DateFrom!, DateTo = model.DateTo! }); + Dictionary dict = new(); - List ans = new(); - List>>>> response = - _serviceStorage.GetReportInfo(new ListAnimalsSearchModel { servicesIds = services }); - - foreach (var service in response) + foreach(var medicine in responseGuides) { - Dictionary counter = new(); - foreach (var medicine in service.Item2) + dict.Add(medicine.Item1.Id, new()); + dict[medicine.Item1.Id].MedicineName = medicine.Item1.MedicineName; + foreach(var service in medicine.Item2) { - foreach (var animal in medicine.Item2) + foreach(var guidance in service.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); - } + dict[medicine.Item1.Id].Guidances.Add(guidance); } } - List res = new(); - foreach (var cnt in counter) + } + + foreach (var medicine in responseVisits) + { + HashSet used = new(); + foreach (var service in medicine.Item2) { - if (cnt.Value.Item2 != service.Item2.Count) - continue; - res.Add(cnt.Value.Item1); + foreach (var visit in service.Item2) + { + if (used.Contains(visit.Id)) + continue; + dict[medicine.Item1.Id].Visits.Add(visit); + } } - ans.Add(new ListAnimalsViewModel - { - ServiceName = service.Item1.ServiceName, - Animals = res - }); + ans.Add(dict[medicine.Item1.Id]); } return ans; } + + public void SaveMedicinesToPdfFile(VisitsGuidesBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список медикаментов", + DateFrom = model.DateFrom!, + DateTo = model.DateTo!, + Medicines = GetMedicineVisitsAndGuidances(model) + }); + + } } } diff --git a/VetClinic/VetClinicContracts/BindingModels/VisitsGuidesBindingModel.cs b/VetClinic/VetClinicContracts/BindingModels/VisitsGuidesBindingModel.cs index 33d5ed9..53f1908 100644 --- a/VetClinic/VetClinicContracts/BindingModels/VisitsGuidesBindingModel.cs +++ b/VetClinic/VetClinicContracts/BindingModels/VisitsGuidesBindingModel.cs @@ -10,7 +10,7 @@ namespace VetClinicContracts.BindingModels { public string FileName { get; set; } = string.Empty; public List Medicines { 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; } } diff --git a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicPharmacist.cs b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicPharmacist.cs index ae02b76..f6611d8 100644 --- a/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicPharmacist.cs +++ b/VetClinic/VetClinicContracts/BusinessLogicsContracts/IReportLogicPharmacist.cs @@ -14,7 +14,7 @@ namespace VetClinicContracts.BusinessLogicsContracts List GetServiceAnimals(List services); void SaveAnimalsToWordFile(ListAnimalsBindingModel model); void SaveAnimalsToExcelFile(ListAnimalsBindingModel model); - List GetMedicineVisitsAndGuidances(List services); + List GetMedicineVisitsAndGuidances(VisitsGuidesBindingModel services); void SaveMedicinesToPdfFile(VisitsGuidesBindingModel model); } } diff --git a/VetClinic/VetClinicContracts/ViewModels/VisitsGuidesViewModel.cs b/VetClinic/VetClinicContracts/ViewModels/VisitsGuidesViewModel.cs index f6235fb..230dbcb 100644 --- a/VetClinic/VetClinicContracts/ViewModels/VisitsGuidesViewModel.cs +++ b/VetClinic/VetClinicContracts/ViewModels/VisitsGuidesViewModel.cs @@ -12,7 +12,5 @@ namespace VetClinicDataBaseImplement.Implements public string MedicineName { get; set; } = string.Empty; public List Visits { get; set; } = new(); public List Guidances { get; set; } = new(); - public DateTime DateFrom { get; set; } = DateTime.Now; - public DateTime DateTo { get; set; } = DateTime.Now; } } diff --git a/VetClinic/VetClinicDataBaseImplement/VetClinicDatabase .cs b/VetClinic/VetClinicDataBaseImplement/VetClinicDatabase .cs index 1d9e6df..3aa2bb9 100644 --- a/VetClinic/VetClinicDataBaseImplement/VetClinicDatabase .cs +++ b/VetClinic/VetClinicDataBaseImplement/VetClinicDatabase .cs @@ -11,7 +11,7 @@ namespace VetClinicDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS02;Initial Catalog=VetClinicDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=VetClinicDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/VetClinic/VetClinicRestApi/Controllers/ReportController.cs b/VetClinic/VetClinicRestApi/Controllers/ReportController.cs new file mode 100644 index 0000000..34ed130 --- /dev/null +++ b/VetClinic/VetClinicRestApi/Controllers/ReportController.cs @@ -0,0 +1,46 @@ +using Microsoft.AspNetCore.Mvc; +using VetClinicBusinessLogic.BusinessLogics; +using VetClinicContracts.BindingModels; +using VetClinicContracts.BusinessLogicsContracts; + +namespace VetClinicRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportController : Controller + { + private readonly IReportLogicPharmacist _reportPharmacist; + public ReportController(ILogger logger, IReportLogicPharmacist reportPharmacist) + { + _reportPharmacist = reportPharmacist; + } + public IActionResult Index(ReportLogicPharmacist reportPharmacist) + { + return View(); + } + [HttpPost] + public void CreateAnimalListWordFile(ListAnimalsBindingModel model) + { + try + { + _reportPharmacist.SaveAnimalsToWordFile(model); + } + catch (Exception ex) + { + throw; + } + } + [HttpPost] + public void CreateAnimalListExcelFile(ListAnimalsBindingModel model) + { + try + { + _reportPharmacist.SaveAnimalsToExcelFile(model); + } + catch (Exception ex) + { + throw; + } + } + } +} diff --git a/VetClinic/VetClinicRestApi/Program.cs b/VetClinic/VetClinicRestApi/Program.cs index ac29eb0..0c7aa45 100644 --- a/VetClinic/VetClinicRestApi/Program.cs +++ b/VetClinic/VetClinicRestApi/Program.cs @@ -4,6 +4,8 @@ using VetClinicContracts.StoragesContracts; using VetClinicDataBaseImplement.Implements; using Microsoft.OpenApi.Models; using VetClinicBaseImplement.Implements; +using VetClinicBusinessLogic.OfficePackage; +using VetClinicBusinessLogic.OfficePackage.Implements; var builder = WebApplication.CreateBuilder(args); @@ -30,6 +32,10 @@ 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.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj b/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj index 51ac888..9c5ed23 100644 --- a/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj +++ b/VetClinic/VetClinicRestApi/VetClinicRestApi.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -17,4 +17,8 @@ + + + +