diff --git a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs index 5bbc006..3d7cbd2 100644 --- a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs +++ b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs @@ -88,7 +88,8 @@ // списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; списокКомпонентовToolStripMenuItem.Size = new Size(268, 26); - списокКомпонентовToolStripMenuItem.Text = "Список компонентов"; + списокКомпонентовToolStripMenuItem.Text = "Список работ"; + списокКомпонентовToolStripMenuItem.Click += списокРаботToolStripMenuItem_Click; // // компонентыПоРаботамToolStripMenuItem // diff --git a/PlumbingRepair/PlumbingRepair/FormMain.cs b/PlumbingRepair/PlumbingRepair/FormMain.cs index 1cbd34b..dc66c2e 100644 --- a/PlumbingRepair/PlumbingRepair/FormMain.cs +++ b/PlumbingRepair/PlumbingRepair/FormMain.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using PlumbingRepairBusinessLogic.BusinessLogics; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairDataModels.Enums; @@ -18,12 +19,14 @@ namespace PlumbingRepairView { private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; + _reportLogic = reportLogic; } private void FormMain_Load(object sender, EventArgs e) @@ -213,5 +216,20 @@ namespace PlumbingRepairView form.ShowDialog(); } } + + private void списокРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveWorksToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + + } } } diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ReportLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ReportLogic.cs index e2e4ad0..a9f8858 100644 --- a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ReportLogic.cs @@ -75,7 +75,7 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics _saveToWord.CreateDoc(new WordInfo { FileName = model.FileName, - Title = "Список компонент", + Title = "Список работ", Works = _workStorage.GetFullList() }); } @@ -84,7 +84,7 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics _saveToExcel.CreateReport(new ExcelInfo { FileName = model.FileName, - Title = "Список компонент", + Title = "Список работ", WorkComponents = GetWorkComponent() }); } diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 11a7759..e49a752 100644 --- a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -28,7 +28,8 @@ WordTextProperties { Bold = true, Size = "24", }) }, CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> { -(work.WorkName, new WordTextProperties { Size = "24", }) }, +(work.WorkName + " - ", new WordTextProperties { Size = "24", Bold = true, }), + (work.Price.ToString(), new WordTextProperties { Size = "24", }) }, TextProperties = new WordTextProperties { Size = "24", diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 6e85e61..22e3e43 100644 --- a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -1,16 +1,23 @@ -using PlumbingRepairBusinessLogic.OfficePackage.HelperEnum; -using PlumbingRepairBusinessLogic.OfficePackage.HelperModels; -using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; +using PlumbingRepairBusinessLogic.OfficePackage.HelperEnum; +using PlumbingRepairBusinessLogic.OfficePackage.HelperModels; +using PlumbingRepairBusinessLogic.OfficePackage; namespace PlumbingRepairBusinessLogic.OfficePackage.Implements { public class SaveToWord : AbstractSaveToWord { private WordprocessingDocument? _wordDocument; + private Body? _docBody; + /// + /// Получение типа выравнивания + /// + /// + /// private static JustificationValues GetJustificationValues(WordJustificationType type) { return type switch @@ -21,54 +28,68 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements }; } + /// + /// Настройки страницы + /// + /// private static SectionProperties CreateSectionProperties() { var properties = new SectionProperties(); + var pageSize = new PageSize { Orient = PageOrientationValues.Portrait }; + properties.AppendChild(pageSize); + return properties; } + /// + /// Задание форматирования для абзаца + /// + /// + /// private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) { if (paragraphProperties == null) { return null; } + var properties = new ParagraphProperties(); + properties.AppendChild(new Justification() { - Val = - GetJustificationValues(paragraphProperties.JustificationType) + 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 - }); + paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size }); } properties.AppendChild(paragraphMarkRunProperties); + return properties; } + protected override void CreateWord(WordInfo info) { - _wordDocument = WordprocessingDocument.Create(info.FileName, - WordprocessingDocumentType.Document); + _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) @@ -78,9 +99,11 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements 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) @@ -88,16 +111,15 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements properties.AppendChild(new Bold()); } docRun.AppendChild(properties); - docRun.AppendChild(new Text - { - Text = run.Item1, - Space = - SpaceProcessingModeValues.Preserve - }); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + docParagraph.AppendChild(docRun); } + _docBody.AppendChild(docParagraph); } + protected override void SaveWord(WordInfo info) { if (_docBody == null || _wordDocument == null) @@ -105,8 +127,10 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements return; } _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); } } -} +} \ No newline at end of file