PIbd-22. Stroev V.M. Lab Work 04 #4
@ -88,7 +88,8 @@
|
|||||||
//
|
//
|
||||||
списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
|
списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
|
||||||
списокКомпонентовToolStripMenuItem.Size = new Size(268, 26);
|
списокКомпонентовToolStripMenuItem.Size = new Size(268, 26);
|
||||||
списокКомпонентовToolStripMenuItem.Text = "Список компонентов";
|
списокКомпонентовToolStripMenuItem.Text = "Список работ";
|
||||||
|
списокКомпонентовToolStripMenuItem.Click += списокРаботToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// компонентыПоРаботамToolStripMenuItem
|
// компонентыПоРаботамToolStripMenuItem
|
||||||
//
|
//
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PlumbingRepairBusinessLogic.BusinessLogics;
|
||||||
using PlumbingRepairContracts.BindingModels;
|
using PlumbingRepairContracts.BindingModels;
|
||||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||||
using PlumbingRepairDataModels.Enums;
|
using PlumbingRepairDataModels.Enums;
|
||||||
@ -18,12 +19,14 @@ namespace PlumbingRepairView
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderLogic _orderLogic;
|
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();
|
InitializeComponent();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderLogic = orderLogic;
|
_orderLogic = orderLogic;
|
||||||
|
_reportLogic = reportLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormMain_Load(object sender, EventArgs e)
|
private void FormMain_Load(object sender, EventArgs e)
|
||||||
@ -213,5 +216,20 @@ namespace PlumbingRepairView
|
|||||||
form.ShowDialog();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
|||||||
_saveToWord.CreateDoc(new WordInfo
|
_saveToWord.CreateDoc(new WordInfo
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
FileName = model.FileName,
|
||||||
Title = "Список компонент",
|
Title = "Список работ",
|
||||||
Works = _workStorage.GetFullList()
|
Works = _workStorage.GetFullList()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
|||||||
_saveToExcel.CreateReport(new ExcelInfo
|
_saveToExcel.CreateReport(new ExcelInfo
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
FileName = model.FileName,
|
||||||
Title = "Список компонент",
|
Title = "Список работ",
|
||||||
WorkComponents = GetWorkComponent()
|
WorkComponents = GetWorkComponent()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,8 @@ WordTextProperties { Bold = true, Size = "24", }) },
|
|||||||
CreateParagraph(new WordParagraph
|
CreateParagraph(new WordParagraph
|
||||||
{
|
{
|
||||||
Texts = new List<(string, WordTextProperties)> {
|
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
|
TextProperties = new WordTextProperties
|
||||||
{
|
{
|
||||||
Size = "24",
|
Size = "24",
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
using PlumbingRepairBusinessLogic.OfficePackage.HelperEnum;
|
using DocumentFormat.OpenXml;
|
||||||
using PlumbingRepairBusinessLogic.OfficePackage.HelperModels;
|
|
||||||
using DocumentFormat.OpenXml;
|
|
||||||
using DocumentFormat.OpenXml.Packaging;
|
using DocumentFormat.OpenXml.Packaging;
|
||||||
using DocumentFormat.OpenXml.Wordprocessing;
|
using DocumentFormat.OpenXml.Wordprocessing;
|
||||||
|
using PlumbingRepairBusinessLogic.OfficePackage.HelperEnum;
|
||||||
|
using PlumbingRepairBusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using PlumbingRepairBusinessLogic.OfficePackage;
|
||||||
|
|
||||||
namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
|
namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
|
||||||
{
|
{
|
||||||
public class SaveToWord : AbstractSaveToWord
|
public class SaveToWord : AbstractSaveToWord
|
||||||
{
|
{
|
||||||
private WordprocessingDocument? _wordDocument;
|
private WordprocessingDocument? _wordDocument;
|
||||||
|
|
||||||
private Body? _docBody;
|
private Body? _docBody;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение типа выравнивания
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <returns></returns>
|
||||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||||
{
|
{
|
||||||
return type switch
|
return type switch
|
||||||
@ -21,54 +28,68 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Настройки страницы
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
private static SectionProperties CreateSectionProperties()
|
private static SectionProperties CreateSectionProperties()
|
||||||
{
|
{
|
||||||
var properties = new SectionProperties();
|
var properties = new SectionProperties();
|
||||||
|
|
||||||
var pageSize = new PageSize
|
var pageSize = new PageSize
|
||||||
{
|
{
|
||||||
Orient = PageOrientationValues.Portrait
|
Orient = PageOrientationValues.Portrait
|
||||||
};
|
};
|
||||||
|
|
||||||
properties.AppendChild(pageSize);
|
properties.AppendChild(pageSize);
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Задание форматирования для абзаца
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="paragraphProperties"></param>
|
||||||
|
/// <returns></returns>
|
||||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||||
{
|
{
|
||||||
if (paragraphProperties == null)
|
if (paragraphProperties == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var properties = new ParagraphProperties();
|
var properties = new ParagraphProperties();
|
||||||
|
|
||||||
properties.AppendChild(new Justification()
|
properties.AppendChild(new Justification()
|
||||||
{
|
{
|
||||||
Val =
|
Val = GetJustificationValues(paragraphProperties.JustificationType)
|
||||||
GetJustificationValues(paragraphProperties.JustificationType)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
properties.AppendChild(new SpacingBetweenLines
|
properties.AppendChild(new SpacingBetweenLines
|
||||||
{
|
{
|
||||||
LineRule = LineSpacingRuleValues.Auto
|
LineRule = LineSpacingRuleValues.Auto
|
||||||
});
|
});
|
||||||
|
|
||||||
properties.AppendChild(new Indentation());
|
properties.AppendChild(new Indentation());
|
||||||
|
|
||||||
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
|
||||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||||
{
|
{
|
||||||
paragraphMarkRunProperties.AppendChild(new FontSize
|
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
|
||||||
{
|
|
||||||
Val =
|
|
||||||
paragraphProperties.Size
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
properties.AppendChild(paragraphMarkRunProperties);
|
properties.AppendChild(paragraphMarkRunProperties);
|
||||||
|
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CreateWord(WordInfo info)
|
protected override void CreateWord(WordInfo info)
|
||||||
{
|
{
|
||||||
_wordDocument = WordprocessingDocument.Create(info.FileName,
|
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
||||||
WordprocessingDocumentType.Document);
|
|
||||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||||
mainPart.Document = new Document();
|
mainPart.Document = new Document();
|
||||||
_docBody = mainPart.Document.AppendChild(new Body());
|
_docBody = mainPart.Document.AppendChild(new Body());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void CreateParagraph(WordParagraph paragraph)
|
protected override void CreateParagraph(WordParagraph paragraph)
|
||||||
{
|
{
|
||||||
if (_docBody == null || paragraph == null)
|
if (_docBody == null || paragraph == null)
|
||||||
@ -78,9 +99,11 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
|
|||||||
var docParagraph = new Paragraph();
|
var docParagraph = new Paragraph();
|
||||||
|
|
||||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
|
||||||
|
|
||||||
foreach (var run in paragraph.Texts)
|
foreach (var run in paragraph.Texts)
|
||||||
{
|
{
|
||||||
var docRun = new Run();
|
var docRun = new Run();
|
||||||
|
|
||||||
var properties = new RunProperties();
|
var properties = new RunProperties();
|
||||||
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
properties.AppendChild(new FontSize { Val = run.Item2.Size });
|
||||||
if (run.Item2.Bold)
|
if (run.Item2.Bold)
|
||||||
@ -88,16 +111,15 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
|
|||||||
properties.AppendChild(new Bold());
|
properties.AppendChild(new Bold());
|
||||||
}
|
}
|
||||||
docRun.AppendChild(properties);
|
docRun.AppendChild(properties);
|
||||||
docRun.AppendChild(new Text
|
|
||||||
{
|
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||||
Text = run.Item1,
|
|
||||||
Space =
|
|
||||||
SpaceProcessingModeValues.Preserve
|
|
||||||
});
|
|
||||||
docParagraph.AppendChild(docRun);
|
docParagraph.AppendChild(docRun);
|
||||||
}
|
}
|
||||||
|
|
||||||
_docBody.AppendChild(docParagraph);
|
_docBody.AppendChild(docParagraph);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SaveWord(WordInfo info)
|
protected override void SaveWord(WordInfo info)
|
||||||
{
|
{
|
||||||
if (_docBody == null || _wordDocument == null)
|
if (_docBody == null || _wordDocument == null)
|
||||||
@ -105,8 +127,10 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_docBody.AppendChild(CreateSectionProperties());
|
_docBody.AppendChild(CreateSectionProperties());
|
||||||
|
|
||||||
_wordDocument.MainDocumentPart!.Document.Save();
|
_wordDocument.MainDocumentPart!.Document.Save();
|
||||||
|
|
||||||
_wordDocument.Dispose();
|
_wordDocument.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user