Работает сохранение отчетов в ворд и эксель
This commit is contained in:
parent
34505a9328
commit
f15d160157
@ -63,9 +63,9 @@ namespace PolyclinicBusinessLogic.BusinessLogics
|
||||
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 medicaments = _medicamentStorage.GetFullList();
|
||||
|
@ -7,7 +7,7 @@ namespace PolyclinicContracts.BusinessLogicsContracts
|
||||
public interface IImplementerReportLogic
|
||||
{
|
||||
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 SaveReportMedicamentsByDiagnosesToExcelFile(ReportBindingModel reportInfo, List<ReportMedicamentsByDiagnoseViewModel> reportModel);
|
||||
void SaveReportDiagnosesByPeriodToPdfFile(ReportBindingModel reportInfo, ReportDiagnosesByPeriodViewModel reportModel);
|
||||
|
@ -2,6 +2,7 @@
|
||||
using PolyclinicBusinessLogic.OfficePackage.HelperEnums;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
using PolyclinicWebAppImplementer.Models;
|
||||
|
||||
@ -68,13 +69,41 @@ namespace PolyclinicWebAppImplementer.Controllers
|
||||
{
|
||||
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")
|
||||
{
|
||||
return View(model);
|
||||
}
|
||||
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 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;
|
||||
}
|
||||
<h4>Список лекарств по болезням</h4>
|
||||
<form class="d-flex flex-column mt-2">
|
||||
<form class="d-flex flex-column mt-2" method="post">
|
||||
<h5>Выберите болезни</h5>
|
||||
<div class="mb-3 overflow-auto" style="max-width: 500px; max-height: 300px;">
|
||||
<ul>
|
||||
@{
|
||||
for(int i = 0; i < 10; i++)
|
||||
@foreach (var item in Model.Diagnoses)
|
||||
{
|
||||
<li class="d-flex mb-2">
|
||||
<input class="me-2" name="diagnose-@i" type="checkbox" id="diagnose-@i"/>
|
||||
<label for="diagnose-@i">Название болезни @i</label>
|
||||
</li>
|
||||
<li class="mb-2 ps-1 ms-1">
|
||||
@if (item.IsChecked)
|
||||
{
|
||||
<input type="checkbox" id="diagnose-@item.Diagnose.Id" name="SelectedDiagnoses" value="@item.Diagnose.Id" checked />
|
||||
}
|
||||
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>
|
||||
</div>
|
||||
@ -21,18 +28,18 @@
|
||||
<h5>Укажите формат файла</h5>
|
||||
<div class="d-flex">
|
||||
<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>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="mb-3">
|
||||
<h5>Укажите название файла</h5>
|
||||
<input type="text" id="fileName"/>
|
||||
<input required type="text" asp-for="FileName" />
|
||||
</div>
|
||||
<button class="btn btn-primary col-2" type="submit">
|
||||
Скачать отчет
|
||||
|
Loading…
Reference in New Issue
Block a user