Merge branch 'Worker'

This commit is contained in:
goblinrf 2024-05-26 12:44:06 +04:00
commit 9fa5930444
27 changed files with 1312 additions and 98 deletions

View File

@ -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<MedicinesVaccinationsBindingModel>();
return View();
}
public IActionResult Index()
{
@ -536,13 +541,13 @@ View(res);
}
[HttpGet]
public Tuple<VisitViewModel, List<string>>? GetVisit(int visitId)
public Tuple<VisitViewModel, List<Tuple<string, int>>>? GetVisit(int visitId)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
var result = APIAdmin.GetRequest<Tuple<VisitViewModel, List<string>>>($"api/visit/getvisit?visitid={visitId}");
var result = APIAdmin.GetRequest<Tuple<VisitViewModel, List<Tuple<string, int>>>>($"api/visit/getvisit?visitid={visitId}");
if (result == null)
{
return default;
@ -551,13 +556,13 @@ View(res);
return result;
}
[HttpGet]
public Tuple<AnimalViewModel, List<string>>? GetAnimal(int animalId)
public Tuple<AnimalViewModel, List<Tuple<string, int>>>? GetAnimal(int animalId)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
var result = APIAdmin.GetRequest<Tuple<AnimalViewModel, List<string>>>($"api/animal/getanimal?animalid={animalId}");
var result = APIAdmin.GetRequest<Tuple<AnimalViewModel, List<Tuple<string, int>>>>($"api/animal/getanimal?animalid={animalId}");
if (result == null)
{
return default;
@ -595,5 +600,152 @@ View(res);
return result;
}
}
[HttpPost]
public void ServiceListReport(List<int> 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<MedicinesVaccinationsViewModel> result;
try
{
string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture);
string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture);
result = APIAdmin.GetRequest<List<MedicinesVaccinationsViewModel>>
($"api/reportadmin/getmedicinesvaccinationsreport?datefrom={dateFromS}&dateto={dateToS}&adminid={APIAdmin.Admin.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 visit in result)
{
table += "<tbody>"; // Открываем блок данных для каждого визита
// Строка для визита
table += "<tr>";
table += $"<td></td>";
table += $"<td>{visit.VisitName}</td>";
table += $"<td></td>";
table += $"<td></td>";
table += "</tr>";
// Строки для вакцинаций
foreach (var vaccination in visit.Vaccinations)
{
table += "<tr>";
table += $"<td>{vaccination.DateStamp}</td>";
table += $"<td></td>";
table += $"<td>{vaccination.AnimalName}</td>";
table += $"<td></td>";
table += "</tr>";
}
// Строки для медикаментов
foreach (var medicine in visit.Medicines)
{
table += "<tr>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td></td>";
table += $"<td>{medicine.MedicineName}</td>";
table += "</tr>";
}
table += "</tbody>"; // Закрываем блок данных для каждого визита
}
// Конец таблицы
table += "</table>";
table += "</div>";
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");
}
}
}

View File

@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\VetClinicContracts\VetClinicContracts.csproj" />
<ProjectReference Include="..\VetClinicRestApi\VetClinicRestApi.csproj" />
</ItemGroup>
</Project>

View File

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

View File

@ -22,9 +22,18 @@
</select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Word" class="btn btn-primary" /></div>
<div class="col-4"><input type="submit" value="Excel" class="btn btn-primary" /></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

@ -31,7 +31,7 @@
<select name="services" class="form-control" multiple size="5" id="services">
@foreach (var service in ViewBag.Services)
{
<option value="@service.Id" data-name="@service.ServiceName">@service.ServiceName</option>
<option value="@service.Id" data-name="@service.Id">@service.ServiceName</option>
}
</select>
</div>
@ -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")
});
}
});

View File

@ -22,7 +22,7 @@
<select name="visits" class="form-control" multiple size="5" id="visits">
@foreach (var visit in ViewBag.Visits)
{
<option value="@visit.Id" data-name="@visit.NameVisit">@visit.NameVisit</option>
<option value="@visit.Id" data-name="@visit.Id">@visit.NameVisit</option>
}
</select>
</div>
@ -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")
});
}

View File

@ -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<ListServicesViewModel> GetAnimalServices(List<int> animals)
{
List<ListServicesViewModel> ans = new();
List<Tuple<AnimalViewModel, List<Tuple<MedicineViewModel, List<ServiceViewModel>>>>> response =
_animalStorage.GetReportInfo(new ListServicesSearchModel { animalsIds = animals});
foreach (var animal in response)
{
Dictionary<int, (ServiceViewModel, int)> 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<ServiceViewModel> 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<MedicinesVaccinationsViewModel> GetVisitMedicinesAndVaccinations(MedicinesVaccinationsBindingModel model)
{
List<MedicinesVaccinationsViewModel> ans = new();
List<Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<VaccinationViewModel>>>>> responseVaccinations =
_visitStorage.GetVaccinationsInfo(new MedicineVaccinationsSearchModel { DateFrom = model.DateFrom!, DateTo = model.DateTo!, AdminId = model.AdminId!});
List<Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<MedicineViewModel>>>>> responseMedicines =
_visitStorage.GetMedicinesInfo(new MedicineVaccinationsSearchModel { DateFrom = model.DateFrom!, DateTo = model.DateTo!, AdminId = model.AdminId! });
Dictionary<int, MedicinesVaccinationsViewModel> 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<int> 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)
});
}
}
}

View File

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

View File

@ -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<string> { "4cm", "4cm", "4cm", "4cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата", "Название визита", "Животное прививки", "Медикамент"},
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var visit in info.Visits)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", visit.VisitName, "", "" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach(var medicine in visit.Medicines)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", "", "", medicine.MedicineName },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
}
foreach (var vaccination in visit.Vaccinations)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { 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<string> columns);
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void SavePdf(PdfInfo info);
}
}

View File

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

View File

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

View File

@ -14,5 +14,7 @@ namespace VetClinicBusinessLogic.OfficePackage.HelperModels
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<VisitsGuidesViewModel> Medicines { get; set; } = new();
public List<MedicinesVaccinationsViewModel> Visits { get; set; } = new();
}
}

View File

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

View File

@ -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<WorkbookStylesPart>();
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<SharedStringTablePart>().Any() ? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First() : _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
if (_shareStringPart.SharedStringTable == null)
{
_shareStringPart.SharedStringTable = new SharedStringTable();
}
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
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<SheetData>();
if (sheetData == null)
{
return;
}
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
}
else
{
row = new Row() { RowIndex = excelParams.RowIndex };
sheetData.Append(row);
}
Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
{
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
}
else
{
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
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<SharedStringItem>().Count() - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
}
protected override void MergeCells(ExcelMergeParameters excelParams)
{
if (_worksheet == null)
{
return;
}
MergeCells mergeCells;
if (_worksheet.Elements<MergeCells>().Any())
{
mergeCells = _worksheet.Elements<MergeCells>().First();
}
else
{
mergeCells = new MergeCells();
if (_worksheet.Elements<CustomSheetView>().Any())
{
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
}
else
{
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().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();
}
}
}

View File

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

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

View File

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

View File

@ -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<ListAnimalsViewModel> GetServiceAnimals(List<int> animals);
List<ListServicesViewModel> GetAnimalServices(List<int> animals);
void SaveServicesToWordFile(ListServicesBindingModel model);
void SaveServicesToExcelFile(ListServicesBindingModel model);
List<MedicinesVaccinationsViewModel> GetVisitMedicinesAndVaccinations(MedicinesVaccinationsBindingModel animals);
void SaveVisitsToPdfFile(MedicinesVaccinationsBindingModel model);
}
}

View File

@ -11,5 +11,6 @@ namespace VetClinicContracts.SearchModels
public List<int>? visitsIds { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? AdminId { get; set; }
}
}

View File

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

View File

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

View File

@ -40,14 +40,10 @@ namespace VetClinicDataBaseImplement.Implements
public List<Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<VaccinationViewModel>>>>> 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<VisitViewModel, List<Tuple<AnimalViewModel, List<VaccinationViewModel>>>>(visit.GetViewModel,
return context.Visits.Where(visit => visit.AdminId == model.AdminId)
.Select(visit => new Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<VaccinationViewModel>>>>(visit.GetViewModel,
context.VisitAnimals.Include(animal => animal.Animal)
.Include(animal => animal.Visit).Where(animal => visit.Id == animal.VisitId).
Select(animal => new Tuple<AnimalViewModel, List<VaccinationViewModel>>(animal.Animal.GetViewModel,
@ -57,14 +53,10 @@ namespace VetClinicDataBaseImplement.Implements
}
public List<Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<MedicineViewModel>>>>> 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<VisitViewModel, List<Tuple<AnimalViewModel, List<MedicineViewModel>>>>(visit.GetViewModel,
.Where(visit => visit.AdminId == model.AdminId)
.Select(visit => new Tuple<VisitViewModel, List<Tuple<AnimalViewModel, List<MedicineViewModel>>>>(visit.GetViewModel,
context.VisitAnimals.Include(animal => animal.Animal)
.Include(animal => animal.Visit).Where(animal => visit.Id == animal.VisitId).
Select(animal => new Tuple<AnimalViewModel, List<MedicineViewModel>>(animal.Animal.GetViewModel,

View File

@ -21,14 +21,14 @@ namespace VetClinicRestApi.Controllers
}
[HttpGet]
public Tuple<AnimalViewModel, List<string>>? GetAnimal(int animalId)
public Tuple<AnimalViewModel, List<Tuple<string, int>>>? 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;
}

View File

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

View File

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

View File

@ -21,14 +21,14 @@ namespace VetClinicRestApi.Controllers
}
[HttpGet]
public Tuple<VisitViewModel, List<string>>? 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;
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;
}

View File

@ -35,9 +35,13 @@ builder.Services.AddTransient<IServiceLogic, ServiceLogic>();
builder.Services.AddTransient<IMedicineLogic, MedicineLogic>();
builder.Services.AddTransient<IGuidanceLogic, GuidanceLogic>();
builder.Services.AddTransient<IReportLogicPharmacist, ReportLogicPharmacist>();
builder.Services.AddTransient<IReportLogicAdmin, ReportLogicAdmin>();
builder.Services.AddTransient<AbstractSaveToExcelPharmacist, SaveToExcelPharmacist>();
builder.Services.AddTransient<AbstractSaveToWordPharmacist, SaveToWordPharmacist>();
builder.Services.AddTransient<AbstractSaveToPdfPharmacist, SaveToPdfPharmacist>();
builder.Services.AddTransient<AbstractSaveToExcelAdmin, SaveToExcelAdmin>();
builder.Services.AddTransient<AbstractSaveToWordAdmin, SaveToWordAdmin>();
builder.Services.AddTransient<AbstractSaveToPdfAdmin, SaveToPdfAdmin>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();