Merge branch 'Лаб_5' into Лаб_6

This commit is contained in:
Mavrina_Julia 2024-05-25 18:07:51 +04:00
commit c36ca5b1bf
23 changed files with 750 additions and 610 deletions

View File

@ -31,6 +31,8 @@
panel = new Panel(); panel = new Panel();
buttonToPdf = new Button(); buttonToPdf = new Button();
buttonMake = new Button(); buttonMake = new Button();
labelTo = new Label();
labelFrom = new Label();
dateTimePickerTo = new DateTimePicker(); dateTimePickerTo = new DateTimePicker();
dateTimePickerFrom = new DateTimePicker(); dateTimePickerFrom = new DateTimePicker();
labelTo = new Label(); labelTo = new Label();
@ -42,6 +44,8 @@
// //
panel.Controls.Add(buttonToPdf); panel.Controls.Add(buttonToPdf);
panel.Controls.Add(buttonMake); panel.Controls.Add(buttonMake);
panel.Controls.Add(labelTo);
panel.Controls.Add(labelFrom);
panel.Controls.Add(dateTimePickerTo); panel.Controls.Add(dateTimePickerTo);
panel.Controls.Add(dateTimePickerFrom); panel.Controls.Add(dateTimePickerFrom);
panel.Controls.Add(labelTo); panel.Controls.Add(labelTo);
@ -104,6 +108,20 @@
labelFrom.TabIndex = 0; labelFrom.TabIndex = 0;
labelFrom.Text = "С"; labelFrom.Text = "С";
// //
// dateTimePickerTo
//
dateTimePickerTo.Location = new Point(264, 6);
dateTimePickerTo.Name = "dateTimePickerTo";
dateTimePickerTo.Size = new Size(200, 23);
dateTimePickerTo.TabIndex = 1;
//
// dateTimePickerFrom
//
dateTimePickerFrom.Location = new Point(31, 5);
dateTimePickerFrom.Name = "dateTimePickerFrom";
dateTimePickerFrom.Size = new Size(200, 23);
dateTimePickerFrom.TabIndex = 0;
//
// FormReportOrders // FormReportOrders
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -126,5 +144,6 @@
private Button buttonToPdf; private Button buttonToPdf;
private Button buttonMake; private Button buttonMake;
private DateTimePicker dateTimePickerTo; private DateTimePicker dateTimePickerTo;
private DateTimePicker dateTimePickerFrom;
} }
} }

View File

@ -11,6 +11,11 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using RenovationWorkContracts.BindingModels;
using RenovationWorkContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using Microsoft.Reporting.WinForms;
namespace RenovationWorkView namespace RenovationWorkView
{ {
@ -98,3 +103,4 @@ namespace RenovationWorkView
} }
} }
} }

View File

@ -10,6 +10,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Extensions.Logging;
using RenovationWorkContracts.BindingModels;
using RenovationWorkContracts.BusinessLogicsContracts;
namespace RenovationWorkView namespace RenovationWorkView
{ {

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="IComponentLogic" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>RenovationWorkContracts.BusinessLogicsContracts.IComponentLogic, RenovationWorkContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>

View File

@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="MigraDocCore.Rendering" Version="1.3.63" />
<PackageReference Include="NLog" Version="5.2.8" /> <PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" /> <PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" /> <PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
@ -46,4 +47,10 @@
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="ReportOrders.rdlc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -21,12 +21,14 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf; private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IRepairStorage repairStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, public ReportLogic(IRepairStorage repairStorage, IComponentStorage componentStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
{ {
_repairStorage = repairStorage; _repairStorage = repairStorage;
_componentStorage = componentStorage; _componentStorage = componentStorage;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_saveToExcel = saveToExcel; _saveToExcel = saveToExcel;
_saveToWord = saveToWord; _saveToWord = saveToWord;
_saveToPdf = saveToPdf; _saveToPdf = saveToPdf;
@ -40,6 +42,7 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
TotalCount = x.RepairComponents.Select(x => x.Value.Item2).Sum() TotalCount = x.RepairComponents.Select(x => x.Value.Item2).Sum()
}).ToList(); }).ToList();
} }
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model) public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
{ {
return _orderStorage.GetFilteredList(new OrderSearchModel return _orderStorage.GetFilteredList(new OrderSearchModel
@ -56,6 +59,7 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
}).ToList(); }).ToList();
} }
public void SaveRepairsToWordFile(ReportBindingModel model) public void SaveRepairsToWordFile(ReportBindingModel model)
{ {
_saveToWord.CreateDoc(new WordInfo _saveToWord.CreateDoc(new WordInfo
@ -65,6 +69,7 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
Repairs = _repairStorage.GetFullList() Repairs = _repairStorage.GetFullList()
}); });
} }
public void SaveRepairComponentToExcelFile(ReportBindingModel model) public void SaveRepairComponentToExcelFile(ReportBindingModel model)
{ {
_saveToExcel.CreateReport(new ExcelInfo _saveToExcel.CreateReport(new ExcelInfo
@ -74,6 +79,7 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
RepairComponents = GetRepairComponent() RepairComponents = GetRepairComponent()
}); });
} }
public void SaveOrdersToPdfFile(ReportBindingModel model) public void SaveOrdersToPdfFile(ReportBindingModel model)
{ {
_saveToPdf.CreateDoc(new PdfInfo _saveToPdf.CreateDoc(new PdfInfo

View File

@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
using RenovationWorkBusinessLogic.OfficePackage.HelperModels;
namespace RenovationWorkBusinessLogic.OfficePackage namespace RenovationWorkBusinessLogic.OfficePackage
{ {
@ -17,6 +19,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage
public void CreateReport(ExcelInfo info) public void CreateReport(ExcelInfo info)
{ {
CreateExcel(info); CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "A", ColumnName = "A",
@ -24,11 +27,13 @@ namespace RenovationWorkBusinessLogic.OfficePackage
Text = info.Title, Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title StyleInfo = ExcelStyleInfoType.Title
}); });
MergeCells(new ExcelMergeParameters MergeCells(new ExcelMergeParameters
{ {
CellFromName = "A1", CellFromName = "A1",
CellToName = "C1" CellToName = "C1"
}); });
uint rowIndex = 2; uint rowIndex = 2;
foreach (var pc in info.RepairComponents) foreach (var pc in info.RepairComponents)
{ {
@ -40,6 +45,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage
StyleInfo = ExcelStyleInfoType.Text StyleInfo = ExcelStyleInfoType.Text
}); });
rowIndex++; rowIndex++;
foreach (var (Component, Count) in pc.Components) foreach (var (Component, Count) in pc.Components)
{ {
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
@ -49,6 +55,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage
Text = Component, Text = Component,
StyleInfo = ExcelStyleInfoType.TextWithBroder StyleInfo = ExcelStyleInfoType.TextWithBroder
}); });
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "C", ColumnName = "C",
@ -57,8 +64,10 @@ namespace RenovationWorkBusinessLogic.OfficePackage
StyleInfo = StyleInfo =
ExcelStyleInfoType.TextWithBroder ExcelStyleInfoType.TextWithBroder
}); });
rowIndex++; rowIndex++;
} }
InsertCellInWorksheet(new ExcelCellParameters InsertCellInWorksheet(new ExcelCellParameters
{ {
ColumnName = "A", ColumnName = "A",
@ -75,6 +84,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage
}); });
rowIndex++; rowIndex++;
} }
SaveExcel(info); SaveExcel(info);
} }
protected abstract void CreateExcel(ExcelInfo info); protected abstract void CreateExcel(ExcelInfo info);

View File

@ -1,4 +1,6 @@
using System; using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
using RenovationWorkBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,6 +8,8 @@ using System.Threading.Tasks;
using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
using RenovationWorkBusinessLogic.OfficePackage.HelperModels; using RenovationWorkBusinessLogic.OfficePackage.HelperModels;
namespace RenovationWorkBusinessLogic.OfficePackage namespace RenovationWorkBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToPdf public abstract class AbstractSaveToPdf

View File

@ -5,6 +5,10 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
using RenovationWorkBusinessLogic.OfficePackage.HelperModels;
using System.Collections.Generic;
namespace RenovationWorkBusinessLogic.OfficePackage namespace RenovationWorkBusinessLogic.OfficePackage
{ {
@ -42,5 +46,6 @@ namespace RenovationWorkBusinessLogic.OfficePackage
protected abstract void CreateParagraph(WordParagraph paragraph); protected abstract void CreateParagraph(WordParagraph paragraph);
protected abstract void SaveWord(WordInfo info); protected abstract void SaveWord(WordInfo info);
} }
}
} }

View File

@ -13,3 +13,4 @@ namespace RenovationWorkBusinessLogic.OfficePackage.HelperEnums
TextWithBroder TextWithBroder
} }
} }

View File

@ -13,3 +13,4 @@ namespace RenovationWorkBusinessLogic.OfficePackage.HelperEnums
Rigth Rigth
} }
} }

View File

@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels namespace RenovationWorkBusinessLogic.OfficePackage.HelperModels
{ {
public class PdfParagraph public class PdfParagraph

View File

@ -1,4 +1,5 @@
using System; using RenovationWorkContracts.ViewModels;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;

View File

@ -1,4 +1,5 @@
using System; using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;

View File

@ -1,4 +1,9 @@
using DocumentFormat.OpenXml.Office2010.Excel; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel; using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Office2016.Excel; using DocumentFormat.OpenXml.Office2016.Excel;
using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Packaging;
@ -19,11 +24,14 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
private SpreadsheetDocument? _spreadsheetDocument; private SpreadsheetDocument? _spreadsheetDocument;
private SharedStringTablePart? _shareStringPart; private SharedStringTablePart? _shareStringPart;
private Worksheet? _worksheet; private Worksheet? _worksheet;
private static void CreateStyles(WorkbookPart workbookpart) private static void CreateStyles(WorkbookPart workbookpart)
{ {
var sp = workbookpart.AddNewPart<WorkbookStylesPart>(); var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
sp.Stylesheet = new Stylesheet(); sp.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2U, KnownFonts = true }; var fonts = new Fonts() { Count = 2U, KnownFonts = true };
var fontUsual = new Font(); var fontUsual = new Font();
fontUsual.Append(new FontSize() { Val = 12D }); fontUsual.Append(new FontSize() { Val = 12D });
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
@ -31,6 +39,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
fontUsual.Append(new FontName() { Val = "Times New Roman" }); fontUsual.Append(new FontName() { Val = "Times New Roman" });
fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
var fontTitle = new Font(); var fontTitle = new Font();
fontTitle.Append(new Bold()); fontTitle.Append(new Bold());
fontTitle.Append(new FontSize() { Val = 14D }); fontTitle.Append(new FontSize() { Val = 14D });
@ -39,11 +48,15 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
fontTitle.Append(new FontName() { Val = "Times New Roman" }); fontTitle.Append(new FontName() { Val = "Times New Roman" });
fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
fonts.Append(fontUsual); fonts.Append(fontUsual);
fonts.Append(fontTitle); fonts.Append(fontTitle);
var fills = new Fills() { Count = 2U }; var fills = new Fills() { Count = 2U };
var fill1 = new Fill(); var fill1 = new Fill();
fill1.Append(new PatternFill() { PatternType = PatternValues.None }); fill1.Append(new PatternFill() { PatternType = PatternValues.None });
var fill2 = new Fill(); var fill2 = new Fill();
fill2.Append(new PatternFill() fill2.Append(new PatternFill()
{ {
@ -51,14 +64,18 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
}); });
fills.Append(fill1); fills.Append(fill1);
fills.Append(fill2); fills.Append(fill2);
var borders = new Borders() { Count = 2U }; var borders = new Borders() { Count = 2U };
var borderNoBorder = new Border(); var borderNoBorder = new Border();
borderNoBorder.Append(new LeftBorder()); borderNoBorder.Append(new LeftBorder());
borderNoBorder.Append(new RightBorder()); borderNoBorder.Append(new RightBorder());
borderNoBorder.Append(new TopBorder()); borderNoBorder.Append(new TopBorder());
borderNoBorder.Append(new BottomBorder()); borderNoBorder.Append(new BottomBorder());
borderNoBorder.Append(new DiagonalBorder()); borderNoBorder.Append(new DiagonalBorder());
var borderThin = new Border(); var borderThin = new Border();
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Indexed = 64U }); { Indexed = 64U });
@ -82,8 +99,10 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
borderThin.Append(topBorder); borderThin.Append(topBorder);
borderThin.Append(bottomBorder); borderThin.Append(bottomBorder);
borderThin.Append(new DiagonalBorder()); borderThin.Append(new DiagonalBorder());
borders.Append(borderNoBorder); borders.Append(borderNoBorder);
borders.Append(borderThin); borders.Append(borderThin);
var cellStyleFormats = new CellStyleFormats() { Count = 1U }; var cellStyleFormats = new CellStyleFormats() { Count = 1U };
var cellFormatStyle = new CellFormat() var cellFormatStyle = new CellFormat()
{ {
@ -93,6 +112,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
BorderId = 0U BorderId = 0U
}; };
cellStyleFormats.Append(cellFormatStyle); cellStyleFormats.Append(cellFormatStyle);
var cellFormats = new CellFormats() { Count = 3U }; var cellFormats = new CellFormats() { Count = 3U };
var cellFormatFont = new CellFormat() var cellFormatFont = new CellFormat()
{ {
@ -131,6 +151,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
cellFormats.Append(cellFormatFont); cellFormats.Append(cellFormatFont);
cellFormats.Append(cellFormatFontAndBorder); cellFormats.Append(cellFormatFontAndBorder);
cellFormats.Append(cellFormatTitle); cellFormats.Append(cellFormatTitle);
var cellStyles = new CellStyles() { Count = 1U }; var cellStyles = new CellStyles() { Count = 1U };
cellStyles.Append(new CellStyle() cellStyles.Append(new CellStyle()
{ {
@ -169,6 +190,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
}); });
stylesheetExtensionList.Append(stylesheetExtension1); stylesheetExtensionList.Append(stylesheetExtension1);
stylesheetExtensionList.Append(stylesheetExtension2); stylesheetExtensionList.Append(stylesheetExtension2);
sp.Stylesheet.Append(fonts); sp.Stylesheet.Append(fonts);
sp.Stylesheet.Append(fills); sp.Stylesheet.Append(fills);
sp.Stylesheet.Append(borders); sp.Stylesheet.Append(borders);
@ -179,6 +201,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
sp.Stylesheet.Append(tableStyles); sp.Stylesheet.Append(tableStyles);
sp.Stylesheet.Append(stylesheetExtensionList); sp.Stylesheet.Append(stylesheetExtensionList);
} }
private static uint GetStyleValue(ExcelStyleInfoType styleInfo) private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
{ {
return styleInfo switch return styleInfo switch
@ -189,6 +212,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
_ => 0U, _ => 0U,
}; };
} }
protected override void CreateExcel(ExcelInfo info) protected override void CreateExcel(ExcelInfo info)
{ {
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName,
@ -196,7 +220,9 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
// Создаем книгу (в ней хранятся листы) // Создаем книгу (в ней хранятся листы)
var workbookpart = _spreadsheetDocument.AddWorkbookPart(); var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook(); workbookpart.Workbook = new Workbook();
CreateStyles(workbookpart); CreateStyles(workbookpart);
// Получаем/создаем хранилище текстов для книги // Получаем/создаем хранилище текстов для книги
_shareStringPart = _shareStringPart =
_spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any() _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
@ -209,9 +235,11 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
{ {
_shareStringPart.SharedStringTable = new SharedStringTable(); _shareStringPart.SharedStringTable = new SharedStringTable();
} }
// Создаем лист в книгу // Создаем лист в книгу
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>(); var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData()); worksheetPart.Worksheet = new Worksheet(new SheetData());
// Добавляем лист в книгу // Добавляем лист в книгу
var sheets = var sheets =
_spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
@ -223,6 +251,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
Name = "Лист" Name = "Лист"
}; };
sheets.Append(sheet); sheets.Append(sheet);
_worksheet = worksheetPart.Worksheet; _worksheet = worksheetPart.Worksheet;
} }
protected override void InsertCellInWorksheet(ExcelCellParameters protected override void InsertCellInWorksheet(ExcelCellParameters
@ -237,6 +266,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
{ {
return; return;
} }
// Ищем строку, либо добавляем ее // Ищем строку, либо добавляем ее
Row row; Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == if (sheetData.Elements<Row>().Where(r => r.RowIndex! ==
@ -250,6 +280,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
row = new Row() { RowIndex = excelParams.RowIndex }; row = new Row() { RowIndex = excelParams.RowIndex };
sheetData.Append(row); sheetData.Append(row);
} }
// Ищем нужную ячейку // Ищем нужную ячейку
Cell cell; Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == if (row.Elements<Cell>().Where(c => c.CellReference!.Value ==
@ -278,8 +309,10 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
excelParams.CellReference excelParams.CellReference
}; };
row.InsertBefore(newCell, refCell); row.InsertBefore(newCell, refCell);
cell = newCell; cell = newCell;
} }
// вставляем новый текст // вставляем новый текст
_shareStringPart.SharedStringTable.AppendChild(new _shareStringPart.SharedStringTable.AppendChild(new
SharedStringItem(new Text(excelParams.Text))); SharedStringItem(new Text(excelParams.Text)));
@ -290,6 +323,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString); cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
} }
protected override void MergeCells(ExcelMergeParameters excelParams) protected override void MergeCells(ExcelMergeParameters excelParams)
{ {
if (_worksheet == null) if (_worksheet == null)
@ -297,6 +331,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
return; return;
} }
MergeCells mergeCells; MergeCells mergeCells;
if (_worksheet.Elements<MergeCells>().Any()) if (_worksheet.Elements<MergeCells>().Any())
{ {
mergeCells = _worksheet.Elements<MergeCells>().First(); mergeCells = _worksheet.Elements<MergeCells>().First();
@ -304,6 +339,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
else else
{ {
mergeCells = new MergeCells(); mergeCells = new MergeCells();
if (_worksheet.Elements<CustomSheetView>().Any()) if (_worksheet.Elements<CustomSheetView>().Any())
{ {
_worksheet.InsertAfter(mergeCells, _worksheet.InsertAfter(mergeCells,
@ -315,12 +351,14 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
_worksheet.Elements<SheetData>().First()); _worksheet.Elements<SheetData>().First());
} }
} }
var mergeCell = new MergeCell() var mergeCell = new MergeCell()
{ {
Reference = new StringValue(excelParams.Merge) Reference = new StringValue(excelParams.Merge)
}; };
mergeCells.Append(mergeCell); mergeCells.Append(mergeCell);
} }
protected override void SaveExcel(ExcelInfo info) protected override void SaveExcel(ExcelInfo info)
{ {
if (_spreadsheetDocument == null) if (_spreadsheetDocument == null)
@ -332,3 +370,5 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
} }
} }
} }

View File

@ -1,4 +1,6 @@
using RenovationWorkBusinessLogic.OfficePackage.HelperEnums; using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
using RenovationWorkBusinessLogic.OfficePackage.HelperModels; using RenovationWorkBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.DocumentObjectModel.Tables;
@ -8,6 +10,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using MigraDoc.DocumentObjectModel.Tables;
namespace RenovationWorkBusinessLogic.OfficePackage.Implements namespace RenovationWorkBusinessLogic.OfficePackage.Implements
{ {
@ -99,3 +103,4 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
} }
} }
} }

View File

@ -8,6 +8,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
using RenovationWorkBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace RenovationWorkBusinessLogic.OfficePackage.Implements namespace RenovationWorkBusinessLogic.OfficePackage.Implements
{ {
@ -28,11 +33,14 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
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;
} }
private static ParagraphProperties? private static ParagraphProperties?
@ -42,17 +50,22 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
{ {
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))
{ {
@ -62,6 +75,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
}); });
} }
properties.AppendChild(paragraphMarkRunProperties); properties.AppendChild(paragraphMarkRunProperties);
return properties; return properties;
} }
protected override void CreateWord(WordInfo info) protected override void CreateWord(WordInfo info)
@ -81,9 +95,11 @@ namespace RenovationWorkBusinessLogic.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)
@ -99,6 +115,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
}); });
docParagraph.AppendChild(docRun); docParagraph.AppendChild(docRun);
} }
_docBody.AppendChild(docParagraph); _docBody.AppendChild(docParagraph);
} }
protected override void SaveWord(WordInfo info) protected override void SaveWord(WordInfo info)
@ -108,6 +125,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
return; return;
} }
_docBody.AppendChild(CreateSectionProperties()); _docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Close(); _wordDocument.Close();
} }

View File

@ -1,4 +1,6 @@
using System; using RenovationWorkContracts.BindingModels;
using RenovationWorkContracts.ViewModels;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;