Работает сохранение отчетов в ворд и эксель
This commit is contained in:
parent
34505a9328
commit
f15d160157
@ -63,9 +63,9 @@ namespace PolyclinicBusinessLogic.BusinessLogics
|
|||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ReportMedicamentsByDiagnoseViewModel> GetReportMedicamentsByDiagnoses(List<IDiagnoseModel> diagnoses)
|
public List<ReportMedicamentsByDiagnoseViewModel> GetReportMedicamentsByDiagnoses(int[] diagnosesIds)
|
||||||
{
|
{
|
||||||
List<DiagnoseViewModel> diagnoseViewModels = diagnoses.Select(x => _diagnoseStorage.GetElement(new DiagnoseSearchModel { Id = x.Id })).ToList();
|
List<DiagnoseViewModel> diagnoseViewModels = diagnosesIds.Select(x => _diagnoseStorage.GetElement(new DiagnoseSearchModel { Id = x })).ToList();
|
||||||
|
|
||||||
var symptomes = _symptomStorage.GetFullList();
|
var symptomes = _symptomStorage.GetFullList();
|
||||||
var medicaments = _medicamentStorage.GetFullList();
|
var medicaments = _medicamentStorage.GetFullList();
|
||||||
|
@ -7,7 +7,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts
|
|||||||
public interface IImplementerReportLogic
|
public interface IImplementerReportLogic
|
||||||
{
|
{
|
||||||
ReportDiagnosesByPeriodViewModel GetReportDiagnosesByPeriod(DateTime? dateStart, DateTime? dateEnd);
|
ReportDiagnosesByPeriodViewModel GetReportDiagnosesByPeriod(DateTime? dateStart, DateTime? dateEnd);
|
||||||
List<ReportMedicamentsByDiagnoseViewModel> GetReportMedicamentsByDiagnoses(List<IDiagnoseModel> diagnoses);
|
List<ReportMedicamentsByDiagnoseViewModel> GetReportMedicamentsByDiagnoses(int[] diagnosesIds);
|
||||||
void SaveReportMedicamentsByDiagnosesToWordFile(ReportBindingModel reportInfo, List<ReportMedicamentsByDiagnoseViewModel> reportModel);
|
void SaveReportMedicamentsByDiagnosesToWordFile(ReportBindingModel reportInfo, List<ReportMedicamentsByDiagnoseViewModel> reportModel);
|
||||||
void SaveReportMedicamentsByDiagnosesToExcelFile(ReportBindingModel reportInfo, List<ReportMedicamentsByDiagnoseViewModel> reportModel);
|
void SaveReportMedicamentsByDiagnosesToExcelFile(ReportBindingModel reportInfo, List<ReportMedicamentsByDiagnoseViewModel> reportModel);
|
||||||
void SaveReportDiagnosesByPeriodToPdfFile(ReportBindingModel reportInfo, ReportDiagnosesByPeriodViewModel reportModel);
|
void SaveReportDiagnosesByPeriodToPdfFile(ReportBindingModel reportInfo, ReportDiagnosesByPeriodViewModel reportModel);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using PolyclinicBusinessLogic.OfficePackage.HelperEnums;
|
using PolyclinicBusinessLogic.OfficePackage.HelperEnums;
|
||||||
using PolyclinicContracts.BindingModels;
|
using PolyclinicContracts.BindingModels;
|
||||||
using PolyclinicContracts.BusinessLogicsContracts;
|
using PolyclinicContracts.BusinessLogicsContracts;
|
||||||
|
using PolyclinicContracts.SearchModels;
|
||||||
using PolyclinicContracts.ViewModels;
|
using PolyclinicContracts.ViewModels;
|
||||||
using PolyclinicWebAppImplementer.Models;
|
using PolyclinicWebAppImplementer.Models;
|
||||||
|
|
||||||
@ -68,13 +69,41 @@ namespace PolyclinicWebAppImplementer.Controllers
|
|||||||
{
|
{
|
||||||
return RedirectToAction("Login", "User");
|
return RedirectToAction("Login", "User");
|
||||||
}
|
}
|
||||||
|
var diagnoses = _diagnoseLogic.ReadList(new DiagnoseSearchModel { UserId = currentUser.Id });
|
||||||
|
if (model.SelectedDiagnoses != null)
|
||||||
|
{
|
||||||
|
model.Diagnoses = diagnoses.Select(x => (x, model.SelectedDiagnoses.Contains(x.Id))).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
model.Diagnoses = diagnoses.Select(x => (x, false)).ToList();
|
||||||
|
}
|
||||||
if (HttpContext.Request.Method == "GET")
|
if (HttpContext.Request.Method == "GET")
|
||||||
{
|
{
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return View(model);
|
var reportInfo = new ReportBindingModel();
|
||||||
|
|
||||||
|
var reportModel = _reportLogic.GetReportMedicamentsByDiagnoses(model.SelectedDiagnoses);
|
||||||
|
|
||||||
|
if (model.ReportType == ReportType.Word)
|
||||||
|
{
|
||||||
|
reportInfo.FileName = model.FileName + ".docx";
|
||||||
|
_reportLogic.SaveReportMedicamentsByDiagnosesToWordFile(reportInfo, reportModel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reportInfo.FileName = model.FileName + ".xlsx";
|
||||||
|
_reportLogic.SaveReportMedicamentsByDiagnosesToExcelFile(reportInfo, reportModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
var filePath = Path.Combine(Directory.GetCurrentDirectory(), reportInfo.FileName);
|
||||||
|
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
|
||||||
|
string mimeType = model.ReportType == ReportType.Word ? "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||||
|
|
||||||
|
return File(fileBytes, mimeType, reportInfo.FileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
namespace PolyclinicWebAppImplementer.Models
|
using PolyclinicBusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using PolyclinicContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace PolyclinicWebAppImplementer.Models
|
||||||
{
|
{
|
||||||
public class MedicamentsByDiagnosesFormModel
|
public class MedicamentsByDiagnosesFormModel
|
||||||
{
|
{
|
||||||
|
public string FileName { get; set; }
|
||||||
|
public ReportType ReportType { get; set; }
|
||||||
|
public List<(DiagnoseViewModel Diagnose, bool IsChecked)> Diagnoses { get; set; } = new();
|
||||||
|
public int[]? SelectedDiagnoses { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
@{
|
@using PolyclinicBusinessLogic.OfficePackage.HelperEnums
|
||||||
|
@model MedicamentsByDiagnosesFormModel
|
||||||
|
@{
|
||||||
ViewBag.SelectedSiteMenuItem = SiteMenuItems.MedicamentsByDiagnoses;
|
ViewBag.SelectedSiteMenuItem = SiteMenuItems.MedicamentsByDiagnoses;
|
||||||
}
|
}
|
||||||
<h4>Список лекарств по болезням</h4>
|
<h4>Список лекарств по болезням</h4>
|
||||||
<form class="d-flex flex-column mt-2">
|
<form class="d-flex flex-column mt-2" method="post">
|
||||||
<h5>Выберите болезни</h5>
|
<h5>Выберите болезни</h5>
|
||||||
<div class="mb-3 overflow-auto" style="max-width: 500px; max-height: 300px;">
|
<div class="mb-3 overflow-auto" style="max-width: 500px; max-height: 300px;">
|
||||||
<ul>
|
<ul>
|
||||||
@{
|
@foreach (var item in Model.Diagnoses)
|
||||||
for(int i = 0; i < 10; i++)
|
{
|
||||||
{
|
<li class="mb-2 ps-1 ms-1">
|
||||||
<li class="d-flex mb-2">
|
@if (item.IsChecked)
|
||||||
<input class="me-2" name="diagnose-@i" type="checkbox" id="diagnose-@i"/>
|
{
|
||||||
<label for="diagnose-@i">Название болезни @i</label>
|
<input type="checkbox" id="diagnose-@item.Diagnose.Id" name="SelectedDiagnoses" value="@item.Diagnose.Id" checked />
|
||||||
</li>
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
<input type="checkbox" id="diagnose-@item.Diagnose.Id" name="SelectedDiagnoses" value="@item.Diagnose.Id" />
|
||||||
|
}
|
||||||
|
<label for="diagnose-@item.Diagnose.Id">@item.Diagnose.Name</label>
|
||||||
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@ -21,18 +28,18 @@
|
|||||||
<h5>Укажите формат файла</h5>
|
<h5>Укажите формат файла</h5>
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<div class="d-flex me-3">
|
<div class="d-flex me-3">
|
||||||
<input class="me-2" type="radio" name="fileFormat" value="docx" id="radio-docx"/>
|
<input class="me-2" checked type="radio" asp-for="ReportType" value="@ReportType.Word" id="radio-docx" />
|
||||||
<label for="radio-docx">DOCX</label>
|
<label for="radio-docx">DOCX</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex me-3">
|
<div class="d-flex me-3">
|
||||||
<input class="me-2" type="radio" name="fileFormat" value="xlsx" id="radio-xlsx" />
|
<input class="me-2" type="radio" asp-for="ReportType" value="@ReportType.Excel" id="radio-xlsx" />
|
||||||
<label for="radio-xlsx">XLSX</label>
|
<label for="radio-xlsx">XLSX</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<h5>Укажите название файла</h5>
|
<h5>Укажите название файла</h5>
|
||||||
<input type="text" id="fileName"/>
|
<input required type="text" asp-for="FileName" />
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-primary col-2" type="submit">
|
<button class="btn btn-primary col-2" type="submit">
|
||||||
Скачать отчет
|
Скачать отчет
|
||||||
|
Loading…
Reference in New Issue
Block a user