Compare commits

..

2 Commits

Author SHA1 Message Date
GokaPek
6f0ef7d77c Слияние чреслами 2024-05-28 21:43:50 +04:00
GokaPek
deb726ff1b Середина разработки Егор отчёт ворд 2024-05-28 21:41:10 +04:00
5 changed files with 157 additions and 12 deletions

View File

@ -5,6 +5,7 @@ using UniversityContracts.BusinessLogicContracts;
using UniversityContracts.SearchModels;
using UniversityContracts.StorageContracts;
using UniversityContracts.ViewModels;
using DocumentFormat.OpenXml.EMMA;
using UniversityBusinessLogic.OfficePackage.HelperModels;
namespace UniversityBusinessLogics.BusinessLogics;
@ -29,6 +30,8 @@ public class ReportLogic : IReportLogic
private readonly AbstractSaveToExcelWorker _saveToExcelWorker;
private readonly AbstractSaveToWordWorker _saveToWordWorker;
private readonly AbstractSaveToPdfWorker _saveToPdfWorker;
private readonly AbstractSaveToWordStorekeeper _saveToWordStorekeeper;
public ReportLogic (ITeacherStorage teacherStorage, IDisciplineStorage
disciplineStorage, IStudentStorage studentStorage, IStatementStorage statementStorage,
IPlanOfStudyStorage planOfStudyStorage, AbstractSaveToExcelWorker saveToExcelWorker, AbstractSaveToWordWorker saveToWordWorker,
@ -225,7 +228,12 @@ public class ReportLogic : IReportLogic
public void SaveTeachersToWord(ReportBindingModel option)
{
_saveToWordStorekeeper.CreateDoc(new WordInfoStorekeeper
{
FileName = option.FileName,
Title = "Список пакетов документов",
TeacherInfo = GetTeachers()
});
}
public void SendDisciplinesToEmail(ReportDateRangeBindingModel option, string email)

View File

@ -24,7 +24,7 @@ namespace UniversityBusinessLogic.OfficePackage
}
});
foreach (var discipline in info.Disciplines)
foreach (var discipline in info.TeacherInfo)
{
CreateParagraph(new WordParagraph
{
@ -38,16 +38,15 @@ namespace UniversityBusinessLogic.OfficePackage
JustificationType = WordJustificationType.Both
}
});
foreach (var assembly in discipline.StudentDisciplines)
foreach (var student in discipline.Students)
{
/*if (!string.IsNullOrEmpty(assembly.AssemblyName) && !string.IsNullOrEmpty(assembly.AssemblyCategory) && assembly.AssemblyPrice != 0)
if (!string.IsNullOrEmpty(student.Name) && !string.IsNullOrEmpty(student.PhoneNumber))
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(assembly.AssemblyName + " - ", new WordTextProperties { Size = "24" }),
(assembly.AssemblyCategory + " - ", new WordTextProperties { Size = "24" }),
(assembly.AssemblyPrice.ToString(), new WordTextProperties { Size = "24" })
(student.Name + " - ", new WordTextProperties { Size = "24" }),
(student.PhoneNumber + " - ", new WordTextProperties { Size = "24" })
},
TextProperties = new WordTextProperties
{
@ -55,7 +54,7 @@ namespace UniversityBusinessLogic.OfficePackage
JustificationType = WordJustificationType.Both
}
});
}*/
}
}
}

View File

@ -1,4 +1,5 @@
using UniversityContracts.ViewModels;
using University.ViewModels;
using UniversityContracts.ViewModels;
namespace UniversityBusinessLogic.OfficePackage.HelperModels
{
@ -8,6 +9,6 @@ namespace UniversityBusinessLogic.OfficePackage.HelperModels
public Stream? Stream { get; set; }
public string Title { get; set; } = string.Empty;
public List<object> ReportObjects { get; set; } = new();
public List<DisciplineViewModel> Disciplines{ get; set; } = new();
public List<ReportTeacherViewModel> TeacherInfo{ get; set; } = new();
}
}

View File

@ -0,0 +1,136 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using UniversityBusinessLogic.OfficePackage.HelperModels;
using UniversityBusinessLogic.OfficePackage;
using UniversityBusinessLogics.OfficePackage.HelperEnums;
namespace UniversityBusinessLogic.OfficePackage.Implements
{
public class SaveToWordStorekeeper : AbstractSaveToWordStorekeeper
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
/// <summary>
/// Получение типа выравнивания
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
{
WordJustificationType.Both => JustificationValues.Both,
WordJustificationType.Center => JustificationValues.Center,
_ => JustificationValues.Left,
};
}
/// <summary>
/// Настройки страницы
/// </summary>
/// <returns></returns>
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
var pageSize = new PageSize
{
Orient = PageOrientationValues.Portrait
};
properties.AppendChild(pageSize);
return properties;
}
/// <summary>
/// Задание форматирования для абзаца
/// </summary>
/// <param name="paragraphProperties"></param>
/// <returns></returns>
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
{
if (paragraphProperties == null)
{
return null;
}
var properties = new ParagraphProperties();
properties.AppendChild(new Justification()
{
Val = GetJustificationValues(paragraphProperties.JustificationType)
});
properties.AppendChild(new SpacingBetweenLines
{
LineRule = LineSpacingRuleValues.Auto
});
properties.AppendChild(new Indentation());
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
if (!string.IsNullOrEmpty(paragraphProperties.Size))
{
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
}
properties.AppendChild(paragraphMarkRunProperties);
return properties;
}
protected override void CreateWord(WordInfoStorekeeper info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
}
protected override void CreateParagraph(WordParagraph paragraph)
{
if (_docBody == null || paragraph == null)
{
return;
}
var docParagraph = new Paragraph();
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
foreach (var run in paragraph.Texts)
{
var docRun = new Run();
var properties = new RunProperties();
properties.AppendChild(new FontSize { Val = run.Item2.Size });
if (run.Item2.Bold)
{
properties.AppendChild(new Bold());
}
docRun.AppendChild(properties);
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
docParagraph.AppendChild(docRun);
}
_docBody.AppendChild(docParagraph);
}
protected override void SaveWord(WordInfoStorekeeper info)
{
if (_docBody == null || _wordDocument == null)
{
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Dispose();
}
}
}

View File

@ -8,7 +8,8 @@ namespace University.ViewModels
{
public class ReportTeacherViewModel
{
public int TeacherId { get; set; }
public string TeacherName { get; set; } = string.Empty;
public List<(string Student, string PhoneNumber)> Students { get; set; } = new();
public List<(string Name, string PhoneNumber)> Students { get; set; } = new();
}
}