PIbd-22. Stroev V.M. Lab Work 04 #4

Closed
StroevVladimir wants to merge 7 commits from Lab4 into Lab3
5 changed files with 68 additions and 24 deletions
Showing only changes of commit 528ecdc229 - Show all commits

View File

@ -88,7 +88,8 @@
//
списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
списокКомпонентовToolStripMenuItem.Size = new Size(268, 26);
списокКомпонентовToolStripMenuItem.Text = "Список компонентов";
списокКомпонентовToolStripMenuItem.Text = "Список работ";
списокКомпонентовToolStripMenuItem.Click += списокРаботToolStripMenuItem_Click;
//
// компонентыПоРаботамToolStripMenuItem
//

View File

@ -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<FormMain> logger, IOrderLogic orderLogic)
public FormMain(ILogger<FormMain> 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);
}
}
}
}

View File

@ -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()
});
}

View File

@ -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",

View File

@ -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;
/// <summary>
/// Получение типа выравнивания
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
@ -21,54 +28,68 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
};
}
/// <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)
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,7 +127,9 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Dispose();
}
}