Не работает созданеи пдф
This commit is contained in:
parent
d7ef2be740
commit
7927b8e1ba
@ -19,7 +19,7 @@ namespace UniversityBusinessLogic.OfficePackage
|
|||||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (var item in info.PlanOfStudyAndStudent)
|
/*foreach (var item in info.PlanOfStudyAndStudent)
|
||||||
{
|
{
|
||||||
foreach (var studentName in item.StudentName)
|
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<string> { item.Id.ToString(), item.PlanOfStudyName },
|
||||||
|
Style = "Normal",
|
||||||
|
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||||
|
});
|
||||||
}
|
}
|
||||||
SavePdf(info);
|
SavePdf(info);
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,7 @@ namespace UniversityBusinessLogic.OfficePackage.HelperModels
|
|||||||
public class PdfInfoWorker
|
public class PdfInfoWorker
|
||||||
{
|
{
|
||||||
public string? FileName { get; set; }
|
public string? FileName { get; set; }
|
||||||
public Stream? Stream { get; set; }
|
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
public List<object> ReportObjects { get; set; } = new();
|
|
||||||
public List<ReportPlanOfStudyAndStudentViewModel> PlanOfStudyAndStudent { get; set; } = new();
|
public List<ReportPlanOfStudyAndStudentViewModel> PlanOfStudyAndStudent { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,13 +103,23 @@ namespace UniversityBusinessLogic.OfficePackage.Implements
|
|||||||
|
|
||||||
protected override void SavePdf(PdfInfoWorker info)
|
protected override void SavePdf(PdfInfoWorker info)
|
||||||
{
|
{
|
||||||
|
if (_document == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Document is not initialized.");
|
||||||
|
}
|
||||||
var renderer = new PdfDocumentRenderer(true)
|
var renderer = new PdfDocumentRenderer(true)
|
||||||
{
|
{
|
||||||
Document = _document
|
Document = _document
|
||||||
};
|
};
|
||||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
try
|
||||||
renderer.RenderDocument();
|
{
|
||||||
renderer.PdfDocument.Save(info.FileName);
|
renderer.RenderDocument();
|
||||||
|
renderer.PdfDocument.Save(info.FileName);
|
||||||
|
}
|
||||||
|
catch (NullReferenceException ex)
|
||||||
|
{
|
||||||
|
throw new Exception(ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -238,6 +238,19 @@ namespace UniversityClientAppWorker.Controllers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[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()
|
public IActionResult ReportPlanOfStudys()
|
||||||
{
|
{
|
||||||
if (APIClient.User == null)
|
if (APIClient.User == null)
|
||||||
@ -247,7 +260,7 @@ namespace UniversityClientAppWorker.Controllers
|
|||||||
return View("ReportPlanOfStudys", APIClient.GetRequest<List<ReportPlanOfStudyViewModel>>($"api/planofstudys/getplanofstudyanddisciplines?userId={APIClient.User.Id}"));
|
return View("ReportPlanOfStudys", APIClient.GetRequest<List<ReportPlanOfStudyViewModel>>($"api/planofstudys/getplanofstudyanddisciplines?userId={APIClient.User.Id}"));
|
||||||
}
|
}
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void ReportPlanOfStudys(string type)
|
public IActionResult ReportPlanOfStudys(string type)
|
||||||
{
|
{
|
||||||
if (APIClient.User == null)
|
if (APIClient.User == null)
|
||||||
{
|
{
|
||||||
@ -264,21 +277,20 @@ namespace UniversityClientAppWorker.Controllers
|
|||||||
{
|
{
|
||||||
APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel
|
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 GetWordFile();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == "xlsx")
|
if (type == "xlsx")
|
||||||
{
|
{
|
||||||
APIClient.PostRequest("api/planofstudys/loadreporttoexcel", new ReportBindingModel
|
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 GetExcelFile();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return Redirect("Index");
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult ReportPlanOfStudyAndStudents()
|
public IActionResult ReportPlanOfStudyAndStudents()
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
using PlumbingRepairClientApp;
|
using PlumbingRepairClientApp;
|
||||||
|
using UniversityBusinessLogic.OfficePackage;
|
||||||
|
using UniversityBusinessLogic.OfficePackage.Implements;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
||||||
|
builder.Services.AddTransient<AbstractSaveToExcelWorker, SaveToExcelWorker>();
|
||||||
|
builder.Services.AddTransient<AbstractSaveToWordWorker, SaveToWordWorker>();
|
||||||
|
builder.Services.AddTransient<AbstractSaveToPdfWorker, SaveToPdfWorker>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
APIClient.Connect(builder.Configuration);
|
APIClient.Connect(builder.Configuration);
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\UniversityBusinessLogic\UniversityBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
|
<ProjectReference Include="..\UniversityDatabaseImplement\UniversityDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
|
<ProjectReference Include="..\UniversityDataModels\UniversityDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -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=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);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
@ -108,6 +108,7 @@ namespace UniversityRestApi.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||||
_reportLogic.SendPlanOfStudyToEmail(model);
|
_reportLogic.SendPlanOfStudyToEmail(model);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user