Лабораторная_4

This commit is contained in:
yuliya.mavrina@internet.ru 2024-04-11 22:10:45 +03:00
parent 132e421d93
commit 7bfc1d2ebd
12 changed files with 89 additions and 76 deletions

View File

@ -107,7 +107,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(807, 450);
Controls.Add(panel);
Name = "FormReportOrders";
Text = "Заказы";

View File

@ -29,7 +29,7 @@ namespace RenovationWorkView
{
Dock = DockStyle.Fill
};
reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrder.rdlc", FileMode.Open));
reportViewer.LocalReport.LoadReportDefinition(new FileStream("..\\..\\..\\ReportOrders.rdlc", FileMode.Open));
Controls.Clear();
Controls.Add(reportViewer);
Controls.Add(panel);
@ -96,3 +96,4 @@ 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;
@ -40,6 +42,10 @@ namespace RenovationWorkView
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IRepairLogic, RepairLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
@ -47,6 +53,8 @@ namespace RenovationWorkView
services.AddTransient<FormRepair>();
services.AddTransient<FormRepairComponent>();
services.AddTransient<FormRepairs>();
services.AddTransient<FormReportRepairComponents>();
services.AddTransient<FormReportOrders>();
}
}
}

View File

@ -16,8 +16,10 @@
<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" />
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.19" />
</ItemGroup>
@ -44,4 +46,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="ReportOrders.rdlc">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -7,7 +7,7 @@
<DataProvider>System.Data.DataSet</DataProvider>
<ConnectString>/* Local Connection */</ConnectString>
</ConnectionProperties>
<rd:DataSourceID>10791c83-cee8-4a38-bbd0-245fc17cefb3</rd:DataSourceID>
<rd:DataSourceID>47cb53f0-7dde-4717-ba03-866a0bc4f4dd</rd:DataSourceID>
</DataSource>
</DataSources>
<DataSets>
@ -25,27 +25,23 @@
<DataField>DateCreate</DataField>
<rd:TypeName>System.DateTime</rd:TypeName>
</Field>
<Field Name="Status">
<DataField>Status</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="RepairName">
<DataField>RepairName</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="OrderStatus">
<DataField>OrderStatus</DataField>
<Field Name="ManufactureName">
<DataField>ManufactureName</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="Sum">
<DataField>Sum</DataField>
<rd:TypeName>System.Decimal</rd:TypeName>
</Field>
<Field Name="OrderStatus">
<DataField>OrderStatus</DataField>
<rd:TypeName>RenovationWorkDataModels.OrderStatus</rd:TypeName>
</Field>
</Fields>
<rd:DataSetInfo>
<rd:DataSetName>RenovationWorkContracts.ViewModels</rd:DataSetName>
<rd:TableName>ReportOrdersViewModel</rd:TableName>
<rd:ObjectDataSourceType>RenovationWorkContracts.ViewModels.ReportOrdersViewModel, RenovationWorkContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
<rd:TableName>ReportOrderViewModel</rd:TableName>
<rd:ObjectDataSourceType>RenovationWorkContracts.ViewModels.ReportOrderViewModel, RenovationWorkContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
</rd:DataSetInfo>
</DataSet>
</DataSets>
@ -75,7 +71,7 @@
<rd:DefaultName>ReportParameterPeriod</rd:DefaultName>
<Top>1cm</Top>
<Height>1cm</Height>
<Width>17.4445cm</Width>
<Width>21cm</Width>
<Style>
<Border>
<Style>None</Style>
@ -94,7 +90,7 @@
<Paragraph>
<TextRuns>
<TextRun>
<Value>Заказы</Value>
<Value>Список заказов</Value>
<Style>
<FontSize>16pt</FontSize>
<FontWeight>Bold</FontWeight>
@ -107,7 +103,7 @@
</Paragraph>
</Paragraphs>
<Height>1cm</Height>
<Width>17.4445cm</Width>
<Width>21cm</Width>
<ZIndex>1</ZIndex>
<Style>
<Border>
@ -124,19 +120,19 @@
<TablixBody>
<TablixColumns>
<TablixColumn>
<Width>2.0889cm</Width>
<Width>2.5cm</Width>
</TablixColumn>
<TablixColumn>
<Width>2.80328cm</Width>
<Width>3.21438cm</Width>
</TablixColumn>
<TablixColumn>
<Width>7.82207cm</Width>
<Width>8.23317cm</Width>
</TablixColumn>
<TablixColumn>
<Width>2.0889cm</Width>
<Width>2.5cm</Width>
</TablixColumn>
<TablixColumn>
<Width>2.0889cm</Width>
<Width>2.5cm</Width>
</TablixColumn>
</TablixColumns>
<TablixRows>
@ -184,7 +180,7 @@
<Paragraph>
<TextRuns>
<TextRun>
<Value>Дата создания</Value>
<Value>Дата заказа</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
@ -216,7 +212,7 @@
<Paragraph>
<TextRuns>
<TextRun>
<Value>Ремонт</Value>
<Value>Изделие</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
@ -248,7 +244,7 @@
<Paragraph>
<TextRuns>
<TextRun>
<Value>Status</Value>
<Value>Сумма</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
@ -280,7 +276,7 @@
<Paragraph>
<TextRuns>
<TextRun>
<Value>Сумма</Value>
<Value>Статус</Value>
<Style>
<FontWeight>Bold</FontWeight>
</Style>
@ -402,21 +398,21 @@
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Status">
<Textbox Name="Sum1">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!Status.Value</Value>
<Value>=Fields!Sum.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Status</rd:DefaultName>
<rd:DefaultName>Sum1</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
@ -432,21 +428,21 @@
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Sum">
<Textbox Name="OrderStatus">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!Sum.Value</Value>
<Value>=Fields!OrderStatus.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Sum</rd:DefaultName>
<rd:DefaultName>OrderStatus</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
@ -487,7 +483,7 @@
<Top>2.48391cm</Top>
<Left>0.55245cm</Left>
<Height>1.2cm</Height>
<Width>16.89205cm</Width>
<Width>18.94755cm</Width>
<ZIndex>2</ZIndex>
<Style>
<Border>
@ -562,10 +558,10 @@
</Style>
</Textbox>
</ReportItems>
<Height>6.27908cm</Height>
<Height>5.72875cm</Height>
<Style />
</Body>
<Width>23.52167cm</Width>
<Width>21cm</Width>
<Page>
<PageHeight>29.7cm</PageHeight>
<PageWidth>21cm</PageWidth>
@ -587,7 +583,7 @@
</ReportParameters>
<ReportParametersLayout>
<GridLayoutDefinition>
<NumberOfColumns>4</NumberOfColumns>
<NumberOfColumns>5</NumberOfColumns>
<NumberOfRows>2</NumberOfRows>
<CellDefinitions>
<CellDefinition>
@ -599,5 +595,5 @@
</GridLayoutDefinition>
</ReportParametersLayout>
<rd:ReportUnitType>Cm</rd:ReportUnitType>
<rd:ReportID>2de0031a-4d17-449d-922d-d9fc54572312</rd:ReportID>
<rd:ReportID>1c0c12af-b9e8-41db-8d1f-26d1acbf91cc</rd:ReportID>
</Report>

View File

@ -15,18 +15,25 @@ namespace RenovationWorkBusinessLogic.OfficePackage
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateTable(new List<string> { "2cm", "3cm", "6cm", "3cm", "3cm" });
CreateRow(new PdfRowParameters
CreateParagraph(new PdfParagraph
{
Texts = new List<string> { "Номер", "Дата заказа", "Пицца", "Статус", "Сумма" },
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "4cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Номер", "Дата заказа", "Изделие", "Статус", "Сумма" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.Orders)
{
CreateRow(new PdfRowParameters
@ -36,8 +43,12 @@ namespace RenovationWorkBusinessLogic.OfficePackage
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth });
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info);
@ -46,4 +57,5 @@ namespace RenovationWorkBusinessLogic.OfficePackage
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -10,7 +10,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.HelperEnums
{
Center,
Left,
Rigth
Right
}
}

View File

@ -281,8 +281,10 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
return;
}
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
_spreadsheetDocument.Close();
_spreadsheetDocument.Dispose();
}
}
}

View File

@ -7,11 +7,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RenovationWorkBusinessLogic.OfficePackage.HelperEnums;
using RenovationWorkBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
namespace RenovationWorkBusinessLogic.OfficePackage.Implements
@ -21,36 +17,30 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
private Document? _document;
private Section? _section;
private Table? _table;
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_section == null)
@ -59,10 +49,10 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Format.Alignment =
GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
protected override void CreateTable(List<string> columns)
{
if (_document == null)
@ -70,13 +60,11 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
return;
}
_table = _document.LastSection.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
@ -87,24 +75,20 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
if (!string.IsNullOrEmpty(rowParameters.Style))
{
row.Cells[i].Style = rowParameters.Style;
}
Unit borderWidth = 0.5;
row.Cells[i].Borders.Left.Width = borderWidth;
row.Cells[i].Borders.Right.Width = borderWidth;
row.Cells[i].Borders.Top.Width = borderWidth;
row.Cells[i].Borders.Bottom.Width = borderWidth;
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].Format.Alignment =
GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
}
}
protected override void SavePdf(PdfInfo info)
{
var renderer = new PdfDocumentRenderer(true)
@ -116,3 +100,4 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
}
}
}

View File

@ -114,7 +114,7 @@ namespace RenovationWorkBusinessLogic.OfficePackage.Implements
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Close();
_wordDocument.Dispose();
}
}
}

View File

@ -9,7 +9,8 @@
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.9" />
<PackageReference Include="PDFsharp-MigraDoc" Version="6.0.0" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup>
<ItemGroup>

View File

@ -10,6 +10,6 @@ namespace RenovationWorkContracts.ViewModels
{
public string RepairName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<(string Component, int Count)> Components { get; set; } = new();
public List<(string, int)> Components { get; set; } = new();
}
}