antoc0der 2024-05-26 22:30:00 +04:00
commit 9bfbcc4815
25 changed files with 630 additions and 137 deletions

View File

@ -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<ReportPetServicesViewModel> GetPetServices(ReportServicesBindingModel model)
public List<ReportServicesViewModel> GetPetServices(ReportServicesBindingModel model)
{
return _petStorage.GetReportServices(new() { petsIds = model.Pets});
//List<ReportServicesViewModel> ans = new();
//List<ReportServicesViewModel> response = _serviceStorage.GetReportServices(new ReportPetsSearchModel { servicesIds = services });
//List<ReportPetsViewModel> respons = _petStorage.GetReportServices(new ReportServicesSearchModel { petsIds = pets });
//foreach (var service in response)
//{
// Dictionary<int, (PetViewModel, int)> 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<PetViewModel> 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<ReportVisitsDrugsViewModel> 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)
});
}
}
}

View File

@ -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<string> { "4cm", "4cm", "4cm", "4cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата", "Животное", "Название посещения", "Название лекарства" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var pet in info.ReportVisitsDrugs)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", pet.PetName, "", "" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var visit in pet.Visits)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { visit.DateVisit.ToString(), "", "", visit.VisitName },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
}
foreach (var guidance in pet.Drugs)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { 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<string> columns);
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -6,6 +6,6 @@ namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportPetServicesViewModel> PetServices { get; set; } = new();
public List<ReportServicesViewModel> PetServices { get; set; } = new();
}
}

View File

@ -6,6 +6,6 @@ namespace VeterinaryBusinessLogic.OfficePackage.HelperModels
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportPetServicesViewModel> PetServices { get; set; } = new();
public List<ReportServicesViewModel> PetServices { get; set; } = new();
}
}

View File

@ -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;
}
}

View File

@ -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,
};
}
/// <summary>
/// Создание стилей для документа
/// </summary>
/// <param name="document"></param>
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<string> 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);
}
}
}

View File

@ -4,7 +4,9 @@
{
public string FileName { get; set; } = string.Empty;
public List<int> 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; }
}
}

View File

@ -5,9 +5,10 @@ namespace VeterinaryContracts.BusinessLogicContracts
{
public interface IReportLogicOwner
{
List<ReportPetServicesViewModel> GetPetServices(ReportServicesBindingModel model);
List<ReportServicesViewModel> GetPetServices(ReportServicesBindingModel model);
List<ReportVisitsDrugsViewModel> GetVisitsDrugs(ReportVisitsDrugsBindingModel model);
void SaveServicesToWordFile(ReportServicesBindingModel model);
void SaveServicesToExcelFile(ReportServicesBindingModel model);
}
void SavePetsToPdfFile(ReportVisitsDrugsBindingModel model);
}
}

View File

@ -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<int>? servicesIds { get; set; }
}
}

View File

@ -8,7 +8,7 @@ namespace VeterinaryContracts.StorageContracts
{
List<PetViewModel> GetFullList();
List<PetViewModel> GetFilteredList(PetSearchModel model);
List<ReportPetServicesViewModel> GetReportServices(ReportServicesSearchModel model);
List<ReportServicesViewModel> GetReportServices(ReportServicesSearchModel model);
List<ReportVisitsDrugsViewModel> GetReportVisitsDrugs(ReportVisitsDrugsSearchModel model);
PetViewModel? GetElement(PetSearchModel model);
PetViewModel? Insert(PetBindingModel model);

View File

@ -13,6 +13,7 @@ namespace VeterinaryContracts.StorageContracts
{
List<ServiceViewModel> GetFullList();
List<ServiceViewModel> GetFilteredList(ServiceSearchModel model);
//List<ReportServicesViewModel> GetReportServices(ReportPetsSearchModel model);
ServiceViewModel? GetElement(ServiceSearchModel model);
ServiceViewModel? Insert(ServiceBindingModel model);
ServiceViewModel? Update(ServiceBindingModel model);

View File

@ -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<PetViewModel> Pets { get; set; } = new();
}
}

View File

@ -1,6 +1,6 @@
namespace VeterinaryContracts.ViewModels
{
public class ReportPetServicesViewModel
public class ReportServicesViewModel
{
public string PetName { get; set; } = string.Empty;
public List<ServiceViewModel> Services { get; set; } = new();

View File

@ -1,4 +1,5 @@
using VeterinaryContracts.BindingModels;
using Microsoft.EntityFrameworkCore;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;

View File

@ -40,7 +40,7 @@ namespace VeterinaryDatabaseImplement.Implements
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<ReportPetServicesViewModel> GetReportServices(ReportServicesSearchModel model)
public List<ReportServicesViewModel> 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)

View File

@ -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)
//{

View File

@ -49,7 +49,7 @@ namespace VeterinaryRestApi.Controllers
}
}
[HttpGet]
public List<ReportDrugsVisitsViewModel> GetVisitsGuidesReport(string dateFrom, string dateTo, int doctorId)// переименовать
public List<ReportDrugsVisitsViewModel> 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
{

View File

@ -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<ReportController> 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<ReportVisitsDrugsViewModel>? 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;
}
}
}
}

View File

@ -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<VisitViewModel>? GetVisit(int visitId)
public Tuple<VisitViewModel, List<Tuple<string, int>>>? 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<VisitViewModel>? GetVisits(int ownerId)
public List<VisitViewModel>? GetVisits(int? ownerId = null)
{
try
{
return _visit.ReadList(new VisitSearchModel { OwnerId = ownerId });
List<VisitViewModel> 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)
{

View File

@ -31,9 +31,13 @@ builder.Services.AddTransient<IServiceLogic, ServiceLogic>();
builder.Services.AddTransient<IMedicationLogic, MedicationLogic>();
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
builder.Services.AddTransient<IReportLogicDoctor, ReportLogicDoctor>();
builder.Services.AddTransient<IReportLogicOwner, ReportLogicOwner>();
builder.Services.AddTransient<AbstractSaveToExcelDoctor, SaveToExcelDoctor>();
builder.Services.AddTransient<AbstractSaveToWordDoctor, SaveToWordDoctor>();
builder.Services.AddTransient<AbstractSaveToPdfDoctor, SaveToPdfDoctor>();
builder.Services.AddTransient<AbstractSaveToExcelOwner, SaveToExcelOwner>();
builder.Services.AddTransient<AbstractSaveToWordOwner, SaveToWordOwner>();
builder.Services.AddTransient<AbstractSaveToPdfOwner, SaveToPdfOwner>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddControllers();

View File

@ -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<VisitViewModel, List<string>>? GetVisit(int visitId)
public Tuple<VisitViewModel, List<Tuple<string, int>>>? GetVisit(int visitId)
{
if (APIOwner.Owner == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
var result = APIOwner.GetRequest<Tuple<VisitViewModel, List<string>>>($"api/visit/getvisit?visitid={visitId}");
var result = APIOwner.GetRequest<Tuple<VisitViewModel, List<Tuple<string>>>>($"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 += "<tr>";
table += $"<td>{pet}</td>";
table += "</tr>";
}
//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<DrugViewModel>($"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<List<PetViewModel>>($"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<int> 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<ReportVisitsDrugsBindingModel>();
return View();
}
[HttpGet]
public string GetPetsReport(DateTime dateFrom, DateTime dateTo)
{
if (APIOwner.Owner == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
List<ReportVisitsDrugsViewModel> result;
try
{
string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture);
string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture);
result = APIOwner.GetRequest<List<ReportVisitsDrugsViewModel>>
($"api/reportowner/getvisitsdrugsreport?datefrom={dateFromS}&dateto={dateToS}&ownerid={APIOwner.Owner.Id}")!;
}
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 medication in result)
{
table += "<tbody>";
table += "<tr>";
table += $"<td></td>";
table += $"<td>{medication.PetName}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += "</tr>";
foreach (var visit in medication.Visits)
{
table += "<tr>";
table += $"<td>{visit.DateVisit}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td>{visit.VisitName}</td>";
table += "</tr>";
}
foreach (var drug in medication.Drugs)
{
table += "<tr>";
table += $"<td>{drug.DateCreate}</td>";
table += $"<td></td>";
table += $"<td>{drug.DrugName}</td>";
table += $"<td></td>";
table += "</tr>";
}
table += "</tbody>";
}
table += "</table>";
table += "</div>";
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");
}
}
}

View File

@ -1,54 +1,64 @@
@{
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">
@{
<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/GetPetsReport",
data: { dateFrom: dateFrom, dateTo: dateTo },
success: function (result) {
if (result != null) {
$('#report').html(result);
}
}
});
};
}
check();
$('#demonstrate').on('click', (e) => check());
</script>
}

View File

@ -1,27 +0,0 @@
@using VeterinaryContracts.ViewModels;
@{
ViewData["Title"] = "ServiceListReport";
}
<div class="text-center">
<h2 class="display-4">Создать списки услуг для животных</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Животные:</div>
<div class="col-8">
<select name="pets" class="form-control" multiple size="5" id="pets">
@foreach (var service in ViewBag.Pets)
{
<option value="@service.Id">@service.PetName</option>
}
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-2"><input type="submit" value="Word" class="btn btn-primary" /></div>
<div class="col-1"><input type="submit" value="Excel" class="btn btn-primary" /></div>
</div>
</form>

View File

@ -0,0 +1,36 @@
@using VeterinaryContracts.ViewModels;
@{
ViewData["Title"] = "ServiceListReport";
}
<div class="text-center">
<h2 class="display-4">Создать списки услуг для животных</h2>
</div>
<form method="post">
<div class="row">
<div class="col-4">Животные:</div>
<div class="col-8">
<select name="pets" class="form-control" multiple size="5" id="pets">
@foreach (var service in ViewBag.Pets)
{
<option value="@service.Id">@service.PetName</option>
}
</select>
</div>
</div>
<div class="file-format">
<label class="form-label">Выберите формат файла:</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="docx" id="docx">
<label class="form-check-label" for="docx">Word-файл</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx" checked>
<label class="form-check-label" for="xlsx">Excel-файл</label>
</div>
</div>
<div class="d-flex justify-content-center">
<button type="submit" class="btn btn-block btn-outline-dark w-100">Создать</button>
</div>
</form>

View File

@ -38,7 +38,7 @@
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="ServiceListReport">Выгрузка списка</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="ServicePetReport">Выгрузка списка</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Report">Отчет</a>