Репорт ворд Егор готово, но отображение на сайте не работает

This commit is contained in:
GokaPek 2024-05-29 11:30:39 +04:00
parent 27d38f78fc
commit d93f31f42c
8 changed files with 147 additions and 44 deletions

View File

@ -31,11 +31,13 @@ public class ReportLogic : IReportLogic
private readonly AbstractSaveToWordWorker _saveToWordWorker; private readonly AbstractSaveToWordWorker _saveToWordWorker;
//private readonly AbstractSaveToPdfWorker _saveToPdfWorker; //private readonly AbstractSaveToPdfWorker _saveToPdfWorker;
private readonly AbstractSaveToExcelWorker _saveToExcelStorekeeper;
//private readonly AbstractSaveToPdfWorker _saveToPdfWorker;
private readonly AbstractSaveToWordStorekeeper _saveToWordStorekeeper; private readonly AbstractSaveToWordStorekeeper _saveToWordStorekeeper;
public ReportLogic (ITeacherStorage teacherStorage, IDisciplineStorage public ReportLogic (ITeacherStorage teacherStorage, IDisciplineStorage
disciplineStorage, IStudentStorage studentStorage, IStatementStorage statementStorage, disciplineStorage, IStudentStorage studentStorage, IStatementStorage statementStorage,
IPlanOfStudyStorage planOfStudyStorage, AbstractSaveToExcelWorker saveToExcelWorker, AbstractSaveToWordWorker saveToWordWorker IPlanOfStudyStorage planOfStudyStorage, AbstractSaveToExcelWorker saveToExcelWorker, AbstractSaveToWordWorker saveToWordWorker
/* , AbstractSaveToPdfWorker saveToPdfWorker */) /* , AbstractSaveToPdfWorker saveToPdfWorker */, AbstractSaveToWordStorekeeper saveToWordStorekeeper)
{ {
_teacherStorage = teacherStorage; _teacherStorage = teacherStorage;
_disciplineStorage = disciplineStorage; _disciplineStorage = disciplineStorage;
@ -46,10 +48,15 @@ public class ReportLogic : IReportLogic
_saveToExcelWorker = saveToExcelWorker; _saveToExcelWorker = saveToExcelWorker;
_saveToWordWorker = saveToWordWorker; _saveToWordWorker = saveToWordWorker;
// _saveToPdfWorker = saveToPdfWorker; // _saveToPdfWorker = saveToPdfWorker;
_saveToWordStorekeeper = saveToWordStorekeeper ;
} }
public List<ReportTeacherViewModel> GetTeachers() public List<ReportTeacherViewModel> GetTeachers(int userId)
{ {
var teachers = _teacherStorage.GetFullList(); var teachers = _teacherStorage.GetFilteredList(new TeacherSearchModel
{
UserId = userId
});
// Создаем список для результатов // Создаем список для результатов
var result = new List<ReportTeacherViewModel>(); var result = new List<ReportTeacherViewModel>();
@ -235,8 +242,8 @@ public class ReportLogic : IReportLogic
_saveToWordStorekeeper.CreateDoc(new WordInfoStorekeeper _saveToWordStorekeeper.CreateDoc(new WordInfoStorekeeper
{ {
FileName = option.FileName, FileName = option.FileName,
Title = "Список пакетов документов", Title = "Список преподавателей",
TeacherInfo = GetTeachers() TeacherInfo = GetTeachers(0)
}); });
} }

View File

@ -174,12 +174,50 @@ namespace UniversityClientApp.Controllers
}); });
Response.Redirect("Teachers"); Response.Redirect("Teachers");
} }
[HttpGet]
public IActionResult Report() { public IActionResult Report() {
return View(); if (APIStorekeeper.Client == null)
{
return Redirect("~/Home/Enter");
}
return View("Report", APIStorekeeper.GetRequest<List<ReportTeacherViewModel>>($"api/teacher/getteachersreport?userId={APIStorekeeper.Client.Id}"));
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [HttpPost]
public void Report(string type)
{
if (APIStorekeeper.Client == null)
{
Redirect("~/Home/Enter");
}
if (string.IsNullOrEmpty(type))
{
throw new Exception("Error, wrong type");
}
if (type == "docx")
{
APIStorekeeper.PostRequest("api/teacher/loadreporttoword", new ReportBindingModel
{
FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\TeachersAndStudents{Environment.TickCount}.docx"
});
Response.Redirect("Report");
return;
}
if (type == "xlsx")
{
APIStorekeeper.PostRequest("api/teacher/loadreporttoexcel", new ReportBindingModel
{
FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\TeachersAndStudents{Environment.TickCount}.xlsx"
});
Response.Redirect("Report");
return;
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });

View File

@ -1,5 +1,7 @@
@{ @using UniversityContracts.ViewModels
ViewData["Title"] = "Student List by Teacher"; @model List<ReportTeacherViewModel>
@{
ViewData["Title"] = "Report by teachers and students";
} }
<div class="text-center"> <div class="text-center">
@ -8,33 +10,59 @@
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Teachers:</div> <div class="col-8 btn-group"></div>
<div class="col-8"> <div class="col-4 mt-2">
<select id="teachers" name="teachers" class="form-control" multiple asp-items="ViewBag.Teachers"></select> <form method="post">
<input type="hidden" name="type" value="docx" />
<input type="submit" value="Save in Word" class="btn btn-primary" />
</form>
<form method="post">
<input type="hidden" name="type" value="xlsx" />
<input type="submit" value="Save in Excel" class="btn btn-success" />
</form>
</div>
<div class="col-4 mt-2">
</div> </div>
</div> </div>
<div class="row"> <table class="table">
<div class="col-4">File Format:</div> <thead>
<div class="col-8"> <tr>
<select id="fileFormat" name="fileFormat" class="form-control" asp-items="ViewBag.FileFormats"></select> <th>Id</th>
</div> <th>Teacher name</th>
</div> <th>Student</th>
<div class="row"> <th>Student</th>
<div class="col-4">File Name:</div> </tr>
<div class="col-8"> </thead>
<input type="text" name="fileName" id="fileName" class="form-control" /> <tbody>
</div> @foreach (var item in Model)
</div> {
<div class="row"> <tr>
<div class="col-4">File Location:</div> <td>
<div class="col-8"> @Html.DisplayFor(modelItem => item.TeacherId)
<input type="text" name="fileLocation" id="fileLocation" class="form-control" /> </td>
</div> <td>
</div> @Html.DisplayFor(modelItem => item.TeacherName)
<div class="row"> </td>
<div class="col-8"></div> <td>
<div class="col-4"> @foreach (var st in item.Students)
<input type="submit" value="Get Student List" class="btn btn-primary" /> {
</div> <div>
</div> @Html.DisplayFor(modelItem => st)
</form> </div>
}
</td>
@foreach (var student in item.Students)
{
<td>
@student.Name
</td>
<td>
@student.PhoneNumber
</td>
}
</tr>
}
</tbody>
</table>
</form>

View File

@ -16,7 +16,7 @@ namespace UniversityContracts.BusinessLogicContracts
/// </summary> /// </summary>
/// <param name="model"></param> /// <param name="model"></param>
/// <returns></returns> /// <returns></returns>
List<ReportTeacherViewModel> GetTeachers(); List<ReportTeacherViewModel> GetTeachers(int userId);
List<ReportDisciplineViewModel> GetDisciplines(ReportBindingModel model); List<ReportDisciplineViewModel> GetDisciplines(ReportBindingModel model);
List<ReportPlanOfStudyViewModel> GetPlanOfStudyAndDisciplines(int userId); List<ReportPlanOfStudyViewModel> GetPlanOfStudyAndDisciplines(int userId);
List<ReportPlanOfStudyAndStudentViewModel> GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model); List<ReportPlanOfStudyAndStudentViewModel> GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model);

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace University.ViewModels namespace UniversityContracts.ViewModels
{ {
public class ReportTeacherViewModel public class ReportTeacherViewModel
{ {

View File

@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR
optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -88,11 +88,11 @@ namespace UniversityRestApi.Controllers
} }
[HttpGet] [HttpGet]
public List<ReportTeacherViewModel>? GetDisciplinesReport() public List<ReportTeacherViewModel>? GetTeachersReport(int userId)
{ {
try try
{ {
return _reportLogic.GetTeachers(); return _reportLogic.GetTeachers(userId);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -100,5 +100,32 @@ namespace UniversityRestApi.Controllers
throw; throw;
} }
} }
[HttpPost]
public void LoadReportToWord(ReportBindingModel model)
{
try
{
_reportLogic.SaveTeachersToWord(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
[HttpPost]
public void LoadReportToExcel(ReportBindingModel model)
{
try
{
_reportLogic.SaveTeachersToExcel(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания отчета");
throw;
}
}
} }
} }

View File

@ -26,6 +26,9 @@ builder.Services.AddTransient<IStudentStorage, StudentStorage>();
builder.Services.AddTransient<AbstractSaveToExcelWorker, SaveToExcelWorker>(); builder.Services.AddTransient<AbstractSaveToExcelWorker, SaveToExcelWorker>();
builder.Services.AddTransient<AbstractSaveToWordWorker, SaveToWordWorker>(); builder.Services.AddTransient<AbstractSaveToWordWorker, SaveToWordWorker>();
builder.Services.AddTransient<AbstractSaveToPdfWorker, SaveToPdfWorker>(); builder.Services.AddTransient<AbstractSaveToPdfWorker, SaveToPdfWorker>();
// builder.Services.AddTransient<AbstractSaveToExcelStorekeeper, SaveToExcelStorekeeper>();
builder.Services.AddTransient<AbstractSaveToWordStorekeeper, SaveToWordStorekeeper>();
// builder.Services.AddTransient<AbstractSaveToPdfStorekeeper, SaveToPdfStorekeeper>();
builder.Services.AddTransient<IReportLogic, ReportLogic>(); builder.Services.AddTransient<IReportLogic, ReportLogic>();
builder.Services.AddTransient<IUserLogic, UserLogic>(); builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IDisciplineLogic, DisciplineLogic>(); builder.Services.AddTransient<IDisciplineLogic, DisciplineLogic>();