Compare commits

...

7 Commits

Author SHA1 Message Date
yuliya.mavrina@internet.ru
f858750776 Лаб_5 2024-05-25 17:58:12 +03:00
yuliya.mavrina@internet.ru
7558a84c38 Лаб_4 2024-04-12 09:07:01 +03:00
yuliya.mavrina@internet.ru
34a1c94ca0 лаб_4 2024-04-12 09:03:43 +03:00
yuliya.mavrina@internet.ru
7bfc1d2ebd Лабораторная_4 2024-04-11 22:10:45 +03:00
yuliya.mavrina@internet.ru
132e421d93 Лабораторная_4 2024-04-09 13:22:43 +03:00
yuliya.mavrina@internet.ru
7158b1e529 Лабораторная_4 2024-03-31 20:22:04 +03:00
yuliya.mavrina@internet.ru
e297ffe910 Лабораторная_4 2024-03-29 08:44:55 +03:00
25 changed files with 753 additions and 610 deletions

View File

@ -10,6 +10,7 @@ using System.Windows.Forms;
using RenovationWorkContracts.BindingModels;
using RenovationWorkContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using RenovationWorkBusinessLogic.BusinessLogics;
namespace RenovationWorkView
{

View File

@ -31,6 +31,8 @@
panel = new Panel();
buttonToPdf = new Button();
buttonMake = new Button();
labelTo = new Label();
labelFrom = new Label();
dateTimePickerTo = new DateTimePicker();
dateTimePickerFrom = new DateTimePicker();
labelTo = new Label();
@ -42,6 +44,8 @@
//
panel.Controls.Add(buttonToPdf);
panel.Controls.Add(buttonMake);
panel.Controls.Add(labelTo);
panel.Controls.Add(labelFrom);
panel.Controls.Add(dateTimePickerTo);
panel.Controls.Add(dateTimePickerFrom);
panel.Controls.Add(labelTo);
@ -104,6 +108,20 @@
labelFrom.TabIndex = 0;
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
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -126,5 +144,6 @@
private Button buttonToPdf;
private Button buttonMake;
private DateTimePicker dateTimePickerTo;
private DateTimePicker dateTimePickerFrom;
}
}

View File

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

View File

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

View File

@ -1,4 +1,6 @@
using RenovationWorkBusinessLogic.BusinessLogics;
using RenovationWorkBusinessLogic.OfficePackage.Implements;
using RenovationWorkBusinessLogic.OfficePackage;
using RenovationWorkContracts.BusinessLogicsContracts;
using RenovationWorkContracts.StoragesContracts;
using RenovationWorkDatabaseImplement.Implements;

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.Logging" 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.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
@ -46,4 +47,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="ReportOrders.rdlc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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