Сделал отчет на форме

This commit is contained in:
gg12 darfren 2024-05-22 16:31:10 +04:00
parent 324781aa40
commit bb68e9abcc
9 changed files with 159 additions and 93 deletions

View File

@ -2,11 +2,13 @@
using NPOI.SS.UserModel;
using PharmacistApp.Models;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Implements;
using VetClinicDataBaseImplement.Models;
using VetClinicDataModels.Models;
@ -28,8 +30,7 @@ namespace PharmacistApp.Controllers
return Redirect("~/Home/Enter");
}
return
View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines?pharmacistid={
APIPharmacist.Pharmacist.Id}"));
View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines?pharmacistid={APIPharmacist.Pharmacist.Id}"));
}
@ -144,7 +145,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
{
_price = Convert.ToDouble(price);
}
catch(Exception ex)
catch (Exception ex)
{
throw new Exception("Ошибка в введенных данных");
}
@ -158,7 +159,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
MedicineName = name,
Price = Math.Round(_price, 2),
PharmacistId = APIPharmacist.Pharmacist.Id
}) ;
});
Response.Redirect("Index");
}
@ -254,7 +255,7 @@ View(APIPharmacist.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicin
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
StringBuilder st = new StringBuilder(price);
for(int i = 0; i < price.Length; i++)
for (int i = 0; i < price.Length; i++)
{
if (price[i] == '.')
st[i] = ',';
@ -647,8 +648,76 @@ View(res);
[HttpGet]
public IActionResult Report()
{
ViewBag.Report = new List<VisitsGuidesBindingModel>();
return View();
}
[HttpGet]
public string GetAnimalsReport(DateTime dateFrom, DateTime dateTo)
{
if (APIPharmacist.Pharmacist == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
List<VisitsGuidesViewModel> result;
try
{
string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture);
string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture);
result = APIPharmacist.GetRequest<List<VisitsGuidesViewModel>>
($"api/report/getvisitsguidesreport?datefrom={dateFromS}&dateto={dateToS}")!;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
string table = "";
table += "<h2 class=\"text-custom-color-1\">Предварительный отчет</h2>";
table += "<div class=\"table-responsive\">";
table += "<table class=\"table table-striped table-bordered table-hover\">";
table += "<thead class=\"table-dark\">";
table += "<tr>";
table += "<th scope=\"col\">Дата</th>";
table += "<th scope=\"col\">Название медикамента</th>";
table += "<th scope=\"col\">Услуга рекомендации</th>";
table += "<th scope=\"col\">Название визита</th>";
table += "</tr>";
table += "</thead>";
foreach (var medicine in result)
{
table += "<tbody>";
table += "<tr>";
table += $"<td></td>";
table += $"<td>{medicine.MedicineName}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += "</tr>";
foreach(var guidance in medicine.Guidances)
{
table += "<tr>";
table += $"<td>{guidance.Date}</td>";
table += $"<td></td>";
table += $"<td>{guidance.ServiceName}</td>";
table += $"<td></td>";
table += "</tr>";
}
foreach (var visit in medicine.Visits)
{
table += "<tr>";
table += $"<td>{visit.DateVisit}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td>{visit.NameVisit}</td>";
table += "</tr>";
}
table += "</tbody>";
}
table += "</table>";
table += "</div>";
return table;
}
}
}

View File

@ -1,60 +1,67 @@

@{
ViewData["Title"] = "Report";
ViewData["Title"] = "Report";
}
<div class="text-center">
<h1 class="display-4">Список медикаментов с расшифровкой по визитам и рекомендациям</h1>
<div class="container">
<div class="text-center mb-4">
<h2 class="text-custom-color-1">Отчет по медикаментам за период</h2>
</div>
<form method="post">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="dateFrom" class="form-label text-custom-color-1">Начало периода:</label>
<input type="datetime-local" id="dateFrom" name="dateFrom" class="form-control" placeholder="Выберите дату начала периода">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="dateTo" class="form-label text-custom-color-1">Окончание периода:</label>
<input type="datetime-local" id="dateTo" name="dateTo" class="form-control" placeholder="Выберите дату окончания периода">
</div>
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="submit" class="btn btn-outline-dark w-100 text-center d-flex justify-content-md-center">Отправить на почту</button>
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="button" id="demonstrate" class="btn btn-outline-dark w-100 text-center d-flex justify-content-md-center">Продемонстрировать</button>
</div>
</div>
<div id="report"></div>
</form>
</div>
<div class="text-center">
@{
// if (Model == null)
// {
// <h3 class="display-4">Будь добр, дружок, зайди!</h3>
// return;
// }
<div class="row mb-5">
<div class="col-4">Начальная дата:</div>
<div class="col-8">
<input type="date" id="startDate" name="startDate" class="form-control">
</div>
</div>
<div class="row mb-5">
<div class="col-4">Конечная дата:</div>
<div class="col-8">
<input type="date" id="endDate" name="endDate" class="form-control">
</div>
</div>
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Дата
</th>
<th>
Медикамент
</th>
<th>
Визит
</th>
<th>
Рекомендация
</th>
</tr>
</thead>
<tbody>
будет заполняться вьюшками отчета
</tbody>
</table>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать отчет" class="btn btn-primary" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Отправить на почту" class="btn btn-primary" /></div>
</div>
}
</div>
@section Scripts {
<script>
function check() {
var dateFrom = $('#dateFrom').val();
var dateTo = $('#dateTo').val();
if (dateFrom && dateTo) {
$.ajax({
method: "GET",
url: "/Home/GetAnimalsReport",
data: { dateFrom: dateFrom, dateTo: dateTo },
success: function (result) {
if (result != null) {
$('#report').html(result);
}
}
});
};
}
check();
$('#demonstrate').on('click', (e) => check());
</script>
}

View File

@ -92,12 +92,11 @@ namespace VetClinicBusinessLogic.BusinessLogics
public List<VisitsGuidesViewModel> GetMedicineVisitsAndGuidances(VisitsGuidesBindingModel model)
{
var medicines = model.Medicines;
List<VisitsGuidesViewModel> ans = new();
List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<GuidanceViewModel>>>>> responseGuides =
_medicineStorage.GetGuidancesInfo(new VisitGuidesSearchModel { medicinesIds = medicines, DateFrom = model.DateFrom!, DateTo = model.DateTo!});
_medicineStorage.GetGuidancesInfo(new VisitGuidesSearchModel { DateFrom = model.DateFrom!, DateTo = model.DateTo!});
List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<VisitViewModel>>>>> responseVisits =
_medicineStorage.GetVisitsInfo(new VisitGuidesSearchModel { medicinesIds = medicines, DateFrom = model.DateFrom!, DateTo = model.DateTo! });
_medicineStorage.GetVisitsInfo(new VisitGuidesSearchModel { DateFrom = model.DateFrom!, DateTo = model.DateTo! });
Dictionary<int, VisitsGuidesViewModel> dict = new();
foreach(var medicine in responseGuides)

View File

@ -9,7 +9,6 @@ namespace VetClinicContracts.BindingModels
public class VisitsGuidesBindingModel
{
public string FileName { get; set; } = string.Empty;
public List<int> Medicines { get; set; } = new();
public DateTime DateFrom { get; set; } = DateTime.Now;
public DateTime DateTo { get; set; } = DateTime.Now;
}

View File

@ -35,13 +35,8 @@ namespace VetClinicDataBaseImplement.Implements
}
public List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<GuidanceViewModel>>>>> GetGuidancesInfo(VisitGuidesSearchModel model)
{
if (model.medicinesIds == null)
{
return new();
}
using var context = new VetClinicDatabase();
return context.Medicines
.Where(medicine => model.medicinesIds.Contains(medicine.Id))
.Select(medicine => new Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<GuidanceViewModel>>>>(medicine.GetViewModel,
context.ServiceMedicines.Include(service => service.Service)
.Include(service => service.Medicine).Where(service => medicine.Id == service.MedicineId).
@ -52,13 +47,8 @@ namespace VetClinicDataBaseImplement.Implements
}
public List<Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<VisitViewModel>>>>> GetVisitsInfo(VisitGuidesSearchModel model)
{
if (model.medicinesIds == null)
{
return new();
}
using var context = new VetClinicDatabase();
return context.Medicines
.Where(medicine => model.medicinesIds.Contains(medicine.Id))
.Select(medicine => new Tuple<MedicineViewModel, List<Tuple<ServiceViewModel, List<VisitViewModel>>>>(medicine.GetViewModel,
context.ServiceMedicines.Include(service => service.Service)
.Include(service => service.Medicine).Where(service => medicine.Id == service.MedicineId).

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.ViewModels;
namespace VetClinicDataBaseImplement.Implements
{
public class VisitsGuidesViewModel
{
string MedicineName { get; set; } = string.Empty;
List<VisitViewModel> Visits { get; set; } = new();
List<GuidanceViewModel> Guidances { get; set; } = new();
}
}

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using VetClinicDataBaseImplement;
using VetClinicContracts.ViewModels;
#nullable disable

View File

@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using VetClinicDataBaseImplement;
using VetClinicContracts.ViewModels;
#nullable disable

View File

@ -2,6 +2,7 @@
using VetClinicBusinessLogic.BusinessLogics;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicDataBaseImplement.Implements;
namespace VetClinicRestApi.Controllers
{
@ -42,5 +43,22 @@ namespace VetClinicRestApi.Controllers
throw;
}
}
[HttpGet]
public List<VisitsGuidesViewModel> GetVisitsGuidesReport(string dateFrom, string dateTo)
{
try
{
DateTime DateFrom = DateTime.Parse(dateFrom);
DateTime DateTo = DateTime.Parse(dateTo);
VisitsGuidesBindingModel model = new();
model.DateFrom = DateFrom;
model.DateTo = DateTo;
return _reportPharmacist.GetMedicineVisitsAndGuidances(model);
}
catch (Exception ex)
{
throw;
}
}
}
}