Репорт ворд Егор готово, но отображение на сайте не работает
This commit is contained in:
parent
27d38f78fc
commit
d93f31f42c
@ -31,11 +31,13 @@ public class ReportLogic : IReportLogic
|
||||
private readonly AbstractSaveToWordWorker _saveToWordWorker;
|
||||
//private readonly AbstractSaveToPdfWorker _saveToPdfWorker;
|
||||
|
||||
private readonly AbstractSaveToExcelWorker _saveToExcelStorekeeper;
|
||||
//private readonly AbstractSaveToPdfWorker _saveToPdfWorker;
|
||||
private readonly AbstractSaveToWordStorekeeper _saveToWordStorekeeper;
|
||||
public ReportLogic (ITeacherStorage teacherStorage, IDisciplineStorage
|
||||
disciplineStorage, IStudentStorage studentStorage, IStatementStorage statementStorage,
|
||||
IPlanOfStudyStorage planOfStudyStorage, AbstractSaveToExcelWorker saveToExcelWorker, AbstractSaveToWordWorker saveToWordWorker
|
||||
/* , AbstractSaveToPdfWorker saveToPdfWorker */)
|
||||
/* , AbstractSaveToPdfWorker saveToPdfWorker */, AbstractSaveToWordStorekeeper saveToWordStorekeeper)
|
||||
{
|
||||
_teacherStorage = teacherStorage;
|
||||
_disciplineStorage = disciplineStorage;
|
||||
@ -46,10 +48,15 @@ public class ReportLogic : IReportLogic
|
||||
_saveToExcelWorker = saveToExcelWorker;
|
||||
_saveToWordWorker = saveToWordWorker;
|
||||
// _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>();
|
||||
@ -235,8 +242,8 @@ public class ReportLogic : IReportLogic
|
||||
_saveToWordStorekeeper.CreateDoc(new WordInfoStorekeeper
|
||||
{
|
||||
FileName = option.FileName,
|
||||
Title = "Список пакетов документов",
|
||||
TeacherInfo = GetTeachers()
|
||||
Title = "Список преподавателей",
|
||||
TeacherInfo = GetTeachers(0)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -174,9 +174,47 @@ namespace UniversityClientApp.Controllers
|
||||
});
|
||||
Response.Redirect("Teachers");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
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}"));
|
||||
}
|
||||
|
||||
[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)]
|
||||
|
@ -1,5 +1,7 @@
|
||||
@{
|
||||
ViewData["Title"] = "Student List by Teacher";
|
||||
@using UniversityContracts.ViewModels
|
||||
@model List<ReportTeacherViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "Report by teachers and students";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
@ -8,33 +10,59 @@
|
||||
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Teachers:</div>
|
||||
<div class="col-8">
|
||||
<select id="teachers" name="teachers" class="form-control" multiple asp-items="ViewBag.Teachers"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">File Format:</div>
|
||||
<div class="col-8">
|
||||
<select id="fileFormat" name="fileFormat" class="form-control" asp-items="ViewBag.FileFormats"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">File Name:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="fileName" id="fileName" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">File Location:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="fileLocation" id="fileLocation" class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Get Student List" class="btn btn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-8 btn-group"></div>
|
||||
<div class="col-4 mt-2">
|
||||
<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>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Teacher name</th>
|
||||
<th>Student</th>
|
||||
<th>Student</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.TeacherId)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.TeacherName)
|
||||
</td>
|
||||
<td>
|
||||
@foreach (var st in item.Students)
|
||||
{
|
||||
<div>
|
||||
@Html.DisplayFor(modelItem => st)
|
||||
</div>
|
||||
}
|
||||
</td>
|
||||
@foreach (var student in item.Students)
|
||||
{
|
||||
<td>
|
||||
@student.Name
|
||||
</td>
|
||||
<td>
|
||||
@student.PhoneNumber
|
||||
</td>
|
||||
}
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
@ -16,7 +16,7 @@ namespace UniversityContracts.BusinessLogicContracts
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<ReportTeacherViewModel> GetTeachers();
|
||||
List<ReportTeacherViewModel> GetTeachers(int userId);
|
||||
List<ReportDisciplineViewModel> GetDisciplines(ReportBindingModel model);
|
||||
List<ReportPlanOfStudyViewModel> GetPlanOfStudyAndDisciplines(int userId);
|
||||
List<ReportPlanOfStudyAndStudentViewModel> GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model);
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace University.ViewModels
|
||||
namespace UniversityContracts.ViewModels
|
||||
{
|
||||
public class ReportTeacherViewModel
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
//Возможно понадобится писать вместо (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);
|
||||
}
|
||||
|
@ -88,11 +88,11 @@ namespace UniversityRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ReportTeacherViewModel>? GetDisciplinesReport()
|
||||
public List<ReportTeacherViewModel>? GetTeachersReport(int userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _reportLogic.GetTeachers();
|
||||
return _reportLogic.GetTeachers(userId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -100,5 +100,32 @@ namespace UniversityRestApi.Controllers
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ builder.Services.AddTransient<IStudentStorage, StudentStorage>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcelWorker, SaveToExcelWorker>();
|
||||
builder.Services.AddTransient<AbstractSaveToWordWorker, SaveToWordWorker>();
|
||||
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<IUserLogic, UserLogic>();
|
||||
builder.Services.AddTransient<IDisciplineLogic, DisciplineLogic>();
|
||||
|
Loading…
Reference in New Issue
Block a user