This commit is contained in:
GokaPek 2024-05-30 00:09:14 +04:00
commit 2c4de39d60
16 changed files with 207 additions and 37 deletions

View File

@ -32,7 +32,7 @@ namespace UniversityBusinessLogic.MailWorker
objMailMessage.Body = info.Text;
objMailMessage.SubjectEncoding = Encoding.UTF8;
objMailMessage.BodyEncoding = Encoding.UTF8;
Attachment attachment = new Attachment($"C:\\Users\\{Environment.UserName}\\Desktop\\Сведения по планам обучения.pdf", new ContentType(MediaTypeNames.Application.Pdf));
Attachment attachment = new Attachment("C:\\ВременныеОтчёты\\Сведения по планам обучения.pdf", new ContentType(MediaTypeNames.Application.Pdf));
objMailMessage.Attachments.Add(attachment);
objSmtpClient.UseDefaultCredentials = false;

View File

@ -22,12 +22,29 @@ namespace UniversityBusinessLogic.OfficePackage
foreach (var item in info.PlanOfStudyAndStudent)
{
foreach (var studentName in item.StudentName)
{
var rowTexts = new List<string> { item.Id.ToString(), item.PlanOfStudyName, studentName };
if (item.DisciplineName.Any())
{
foreach (var disciplineName in item.DisciplineName)
{
rowTexts.Add(disciplineName);
CreateRow(new PdfRowParameters
{
Texts = new List<string> { item.Id.ToString(), item.PlanOfStudyName, studentName, disciplineName },
Texts = rowTexts,
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
rowTexts.RemoveAt(rowTexts.Count - 1);
}
}
else
{
// Если нет дисциплин, добавляем пустую строку
rowTexts.Add("");
CreateRow(new PdfRowParameters
{
Texts = rowTexts,
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});

View File

@ -5,9 +5,7 @@ namespace UniversityBusinessLogic.OfficePackage.HelperModels
public class PdfInfoWorker
{
public string? FileName { get; set; }
public Stream? Stream { get; set; }
public string Title { get; set; } = string.Empty;
public List<object> ReportObjects { get; set; } = new();
public List<ReportPlanOfStudyAndStudentViewModel> PlanOfStudyAndStudent { get; set; } = new();
}
}

View File

@ -103,13 +103,23 @@ namespace UniversityBusinessLogic.OfficePackage.Implements
protected override void SavePdf(PdfInfoWorker info)
{
if (_document == null)
{
throw new InvalidOperationException("Document is not initialized.");
}
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
try
{
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
catch (NullReferenceException ex)
{
throw new Exception(ex.Message);
}
}
}
}

View File

@ -1,3 +1,4 @@
using DocumentFormat.OpenXml.Office2010.Excel;
using Microsoft.AspNetCore.Mvc;
using PlumbingRepairClientApp;
using System.Diagnostics;
@ -149,15 +150,74 @@ namespace UniversityClientAppWorker.Controllers
{
throw new Exception("Ââåäèòå ôîðìó îöåíèâàíèÿ è âûáåðèòå ñòóäåíòà");
}
var Student = APIClient.GetRequest<StudentViewModel>($"api/student/getstudent?userId={APIClient.User.Id}&studentId={student}");
if(Student == null)
{
throw new Exception("Ñòóäåíò íå íàéäåí");
}
APIClient.PostRequest("api/attestation/createattestation", new AttestationBindingModel
{
UserId = APIClient.User.Id,
FormOfEvaluation = formOfEvaluation,
StudentId = student,
StudentName = Student.Name,
Score = score
});
Response.Redirect("Attestations");
}
[HttpGet]
public IActionResult InfoAttestation(int id)
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Students = APIClient.GetRequest<List<StudentViewModel>>($"api/student/getstudents?userId={APIClient.User.Id}");
ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast<AttestationScore>();
var obj = APIClient.GetRequest<AttestationViewModel>($"api/attestation/getattestation?userId={APIClient.User.Id}&id={id}");
return View(obj);
}
[HttpPost]
public void UpdateAttestation(int id, string formOfEvaluation, int student, AttestationScore score)
{
if (APIClient.User == null)
{
throw new Exception("Âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(formOfEvaluation) || student == 0)
{
throw new Exception("Ââåäèòå ôîðìó îöåíèâàíèÿ è âûáåðèòå ñòóäåíòà");
}
var Student = APIClient.GetRequest<StudentViewModel>($"api/student/getstudent?userId={APIClient.User.Id}&studentId={student}");
if (Student == null)
{
throw new Exception("Ñòóäåíò íå íàéäåí");
}
APIClient.PostRequest("api/attestation/updateattestation", new AttestationBindingModel
{
Id = id,
FormOfEvaluation = formOfEvaluation,
StudentId = student,
StudentName = Student.Name,
Score = score
});
Response.Redirect("Attestations");
}
[HttpPost]
public void DeleteAttestation(int id)
{
if (id == 0)
{
throw new Exception("id íå ìîæåò áûòü ðàâåí 0");
}
APIClient.PostRequest("api/attestation/deleteattestation", new PlanOfStudyBindingModel
{
Id = id
});
Response.Redirect("Attestations");
}
[HttpGet]
public async Task<IActionResult> Students()
{
@ -238,6 +298,19 @@ namespace UniversityClientAppWorker.Controllers
return;
}
[HttpGet]
public IActionResult GetWordFile()
{
return PhysicalFile($"C:\\Users\\{Environment.UserName}\\Downloads\\Ïëàíû îáó÷åíèé ïî äèñöèïëèíàì.docx",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"Ïëàíû îáó÷åíèé ïî äèñöèïëèíàì.docx");
}
public IActionResult GetExcelFile()
{
return PhysicalFile($"C:\\Users\\{Environment.UserName}\\Downloads\\Ïëàíû îáó÷åíèé ïî äèñöèïëèíàì.xlsx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Ïëàíû îáó÷åíèé ïî äèñöèïëèíàì.xlsx");
}
[HttpGet]
public IActionResult ReportPlanOfStudys()
{
if (APIClient.User == null)
@ -247,7 +320,7 @@ namespace UniversityClientAppWorker.Controllers
return View("ReportPlanOfStudys", APIClient.GetRequest<List<ReportPlanOfStudyViewModel>>($"api/planofstudys/getplanofstudyanddisciplines?userId={APIClient.User.Id}"));
}
[HttpPost]
public void ReportPlanOfStudys(string type)
public IActionResult ReportPlanOfStudys(string type)
{
if (APIClient.User == null)
{
@ -264,21 +337,20 @@ namespace UniversityClientAppWorker.Controllers
{
APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel
{
FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\Ïëàíû îáó÷åíèé ïî äèñöèïëèíàì.docx"
FileName = "C:\\ÂðåìåííûåÎò÷¸òû\\Ïëàíû îáó÷åíèé ïî äèñöèïëèíàì.docx"
});
Response.Redirect("Index");
return;
return GetWordFile();
}
if (type == "xlsx")
{
APIClient.PostRequest("api/planofstudys/loadreporttoexcel", new ReportBindingModel
{
FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\Ïëàíû îáó÷åíèé ïî äèñöèïëèíàì.xlsx"
FileName = "C:\\ÂðåìåííûåÎò÷¸òû\\Ïëàíû îáó÷åíèé ïî äèñöèïëèíàì.xlsx"
});
Response.Redirect("Index");
return;
return GetExcelFile();
}
return Redirect("Index");
}
[HttpGet]
public IActionResult ReportPlanOfStudyAndStudents()
@ -301,13 +373,13 @@ namespace UniversityClientAppWorker.Controllers
{
APIClient.PostRequest("api/planofstudys/createreporttopdffile", new ReportBindingModel
{
FileName = "C:\\Users\\{Environment.UserName}\\Desktop\\Ñâåäåíèÿ ïî ïëàíàì îáó÷åíèÿ.pdf"
FileName = "C:\\ÂðåìåííûåÎò÷¸òû\\Ñâåäåíèÿ ïî ïëàíàì îáó÷åíèÿ.pdf"
});
APIClient.PostRequest("api/order/sendpdftomail", new MailSendInfoBindingModel
APIClient.PostRequest("api/planofstudys/sendpdftomail", new MailSendInfoBindingModel
{
MailAddress = APIClient.User.Email,
Subject = "Îò÷åò",
Text = "Îò÷åò ïî çàêàçàì"
Text = "Ñâåäåíèÿ ïî ïëàíàì îáó÷åíèÿ"
});
}
Response.Redirect("Index");

View File

@ -1,10 +1,16 @@
using PlumbingRepairClientApp;
using UniversityBusinessLogic.OfficePackage;
using UniversityBusinessLogic.OfficePackage.Implements;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddTransient<AbstractSaveToExcelWorker, SaveToExcelWorker>();
builder.Services.AddTransient<AbstractSaveToWordWorker, SaveToWordWorker>();
builder.Services.AddTransient<AbstractSaveToPdfWorker, SaveToPdfWorker>();
var app = builder.Build();
APIClient.Connect(builder.Configuration);

View File

@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\UniversityBusinessLogic\UniversityBusinessLogic.csproj" />
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
</ItemGroup>

View File

@ -67,7 +67,7 @@
</td>
<td>
<div class="btn-group">
<a asp-controller="Home" asp-action="" asp-route-id="@attestation.Id" class="btn btn-warning">Изменить</a>
<a asp-controller="Home" asp-action="InfoAttestation" asp-route-id="@attestation.Id" class="btn btn-warning">Изменить</a>
<form asp-controller="Home" asp-action="DeleteAttestation" method="post">
<input type="hidden" name="id" value="@attestation.Id" />
<button type="submit" class="btn btn-danger">Удалить</button>

View File

@ -0,0 +1,39 @@
@using UniversityContracts.ViewModels
@model AttestationViewModel
@{
ViewData["Title"] = "План обучения";
}
<div class="text-center">
<h2 class="display-4">@ViewData["Title"]</h2>
</div>
<form asp-action="UpdateAttestation" method="post">
<div class="row">
<div class="col-4">Форма оценивания:</div>
<div class="col-8">
<select name="formOfEvaluation" id="formOfEvaluation" class="form-control" value="@Model.FormOfEvaluation">
<option value="Зачёт">Зачёт</option>
<option value="Экзамен">Экзамен</option>
<option value="Дифферинцируемый зачёт">Дифферинцируемый зачёт</option>
</select>
</div>
</div>
<div class="row">
<div class="col-4">Студент:</div>
<div class="col-8">
<select name="student" id="student" class="form-control" asp-items="@(new SelectList(ViewBag.Students, "Id", "Name", Model.StudentId))"></select>
</div>
</div>
<div class="row">
<div class="col-4">Оценка:</div>
<div class="col-8">
<select id="score" name="score" class="form-control" asp-items="@(new SelectList(ViewBag.AttestationScore, "Score"))"></select>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4 mt-2">
<input type="hidden" name="id" value="@Model.Id" />
<input type="submit" value="Сохранить" class="btn btn-primary" />
</div>
</div>
</form>

View File

@ -4,7 +4,7 @@
ViewData["Title"] = "План обучения";
}
<div class="text-center">
<h2 class="display-4">План обучения</h2>
<h2 class="display-4">@ViewData["Title"]</h2>
</div>
<form asp-action="UpdatePlanOfStudy" method="post">
<div class="row">

View File

@ -12,6 +12,7 @@ namespace UniversityContracts.BusinessLogicsContracts
public interface IAttestationLogic
{
List<AttestationViewModel>? ReadList(AttestationSearchModel? model);
AttestationViewModel? ReadElement(AttestationSearchModel model);
bool CreateAttestation(AttestationBindingModel model);
bool DeleteAttestation(AttestationBindingModel model);
bool UpdateAttestation(AttestationBindingModel model);

View File

@ -5,7 +5,6 @@ namespace UniversityDataModels.Models
public interface IAttestationModel : IId
{
int UserId { get; }
string StudentName { get; }
string FormOfEvaluation { get; }
AttestationScore Score { get; }
int StudentId { get; }

View File

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

View File

@ -32,6 +32,19 @@ namespace UniversityRestApi.Controllers
throw;
}
}
[HttpGet]
public AttestationViewModel? GetAttestation(int userId, int id)
{
try
{
return _logic.ReadElement(new AttestationSearchModel { UserId = userId, Id = id });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения аттестаций пользователя id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateAttestation(AttestationBindingModel model)
{
@ -44,7 +57,7 @@ namespace UniversityRestApi.Controllers
throw;
}
}
[HttpPut]
[HttpPost]
public void UpdateAttestation(AttestationBindingModel model)
{
try
@ -57,7 +70,7 @@ namespace UniversityRestApi.Controllers
throw;
}
}
[HttpDelete]
[HttpPost]
public void DeleteAttestation(AttestationBindingModel model)
{
try

View File

@ -108,6 +108,7 @@ namespace UniversityRestApi.Controllers
{
try
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
_reportLogic.SendPlanOfStudyToEmail(model);
}
catch (Exception ex)

View File

@ -30,6 +30,19 @@ namespace UniversityRestApi.Controllers
throw;
}
}
[HttpGet]
public StudentViewModel? GetStudent(int userId, int studentId)
{
try
{
return _logic.ReadElement(new StudentSearchModel { UserId = userId, Id = studentId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка студентов пользователя id={Id}", userId);
throw;
}
}
[HttpPost]
public void CreateStudent(StudentBindingModel model)
{