diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs index 7e49826..9ebc146 100644 --- a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs @@ -19,7 +19,7 @@ namespace UniversityBusinessLogic.OfficePackage ParagraphAlignment = PdfParagraphAlignmentType.Center }); - foreach (var item in info.PlanOfStudyAndStudent) + /*foreach (var item in info.PlanOfStudyAndStudent) { foreach (var studentName in item.StudentName) { @@ -33,6 +33,15 @@ namespace UniversityBusinessLogic.OfficePackage }); } } + }*/ + foreach(var item in info.PlanOfStudyAndStudent) + { + CreateRow(new PdfRowParameters + { + Texts = new List { item.Id.ToString(), item.PlanOfStudyName }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); } SavePdf(info); } diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs index 99cd615..2e43205 100644 --- a/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/PdfInfoWorker.cs @@ -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 ReportObjects { get; set; } = new(); public List PlanOfStudyAndStudent { get; set; } = new(); } } diff --git a/University/UniversityBusinessLogic/OfficePackage/Implements/SaveToPdfWorker.cs b/University/UniversityBusinessLogic/OfficePackage/Implements/SaveToPdfWorker.cs index 94bf731..01a3d74 100644 --- a/University/UniversityBusinessLogic/OfficePackage/Implements/SaveToPdfWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/Implements/SaveToPdfWorker.cs @@ -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); - renderer.RenderDocument(); - renderer.PdfDocument.Save(info.FileName); + try + { + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + catch (NullReferenceException ex) + { + throw new Exception(ex.Message); + } } } } \ No newline at end of file diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index 05e3ff0..552d1b3 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -238,6 +238,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 +260,7 @@ namespace UniversityClientAppWorker.Controllers return View("ReportPlanOfStudys", APIClient.GetRequest>($"api/planofstudys/getplanofstudyanddisciplines?userId={APIClient.User.Id}")); } [HttpPost] - public void ReportPlanOfStudys(string type) + public IActionResult ReportPlanOfStudys(string type) { if (APIClient.User == null) { @@ -264,21 +277,20 @@ namespace UniversityClientAppWorker.Controllers { APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel { - FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\Планы обучений по дисциплинам.docx" + FileName = $"C:\\Users\\{Environment.UserName}\\Downloads\\Планы обучений по дисциплинам.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:\\Users\\{Environment.UserName}\\Downloads\\Планы обучений по дисциплинам.xlsx" }); - Response.Redirect("Index"); - return; + return GetExcelFile(); } + return Redirect("Index"); } [HttpGet] public IActionResult ReportPlanOfStudyAndStudents() diff --git a/University/UniversityClientAppWorker/Program.cs b/University/UniversityClientAppWorker/Program.cs index ae82eb7..a9df2eb 100644 --- a/University/UniversityClientAppWorker/Program.cs +++ b/University/UniversityClientAppWorker/Program.cs @@ -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(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + var app = builder.Build(); APIClient.Connect(builder.Configuration); diff --git a/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj b/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj index 469fd09..50cbca7 100644 --- a/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj +++ b/University/UniversityClientAppWorker/UniversityClientAppWorker.csproj @@ -15,6 +15,7 @@ + diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 07213d0..2b73bad 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -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=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs index d420613..70bd663 100644 --- a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs +++ b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs @@ -108,6 +108,7 @@ namespace UniversityRestApi.Controllers { try { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); _reportLogic.SendPlanOfStudyToEmail(model); } catch (Exception ex)