From a5ae5119e5c1be4a164f9fe644babca633b1b299 Mon Sep 17 00:00:00 2001
From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com>
Date: Wed, 10 Apr 2024 01:01:51 +0400
Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D0=BA=D0=BE=D0=BD=D0=B5=D1=86-?=
=?UTF-8?q?=D1=82=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../PlumbingRepair/FormReportOrders.cs | 10 +--
.../PlumbingRepair/PlumbingRepairView.csproj | 1 +
.../BusinessLogics/ReportLogic.cs | 4 +-
.../OfficePackage/AbstractSaveToPdf.cs | 65 +++++++++++--------
.../HelperEnum/PdfParagraphAlignmentType.cs | 2 +-
.../OfficePackage/Implements/SaveToPdf.cs | 30 +++++++--
.../PlumbingRepairBusinessLogic.csproj | 2 +-
.../BindingModels/ReportBindingModel.cs | 2 +-
.../Models/Order.cs | 2 +-
.../Models/Order.cs | 2 +-
.../Models/Order.cs | 2 +-
11 files changed, 76 insertions(+), 46 deletions(-)
diff --git a/PlumbingRepair/PlumbingRepair/FormReportOrders.cs b/PlumbingRepair/PlumbingRepair/FormReportOrders.cs
index 11c62ef..bcabb87 100644
--- a/PlumbingRepair/PlumbingRepair/FormReportOrders.cs
+++ b/PlumbingRepair/PlumbingRepair/FormReportOrders.cs
@@ -11,6 +11,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
+using System.Windows.Forms.Design;
namespace PlumbingRepairView
{
@@ -48,8 +49,8 @@ namespace PlumbingRepairView
{
var dataSource = _logic.GetOrders(new ReportBindingModel
{
- DateFrom = dateTimePickerFrom.Value,
- DateTo = dateTimePickerTo.Value
+ DateFrom = DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc),
+ DateTo = DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc)
});
var source = new ReportDataSource("DataSetOrders", dataSource);
reportViewer.LocalReport.DataSources.Clear();
@@ -80,11 +81,12 @@ namespace PlumbingRepairView
{
try
{
+ System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
_logic.SaveOrdersToPdfFile(new ReportBindingModel
{
FileName = dialog.FileName,
- DateFrom = dateTimePickerFrom.Value,
- DateTo = dateTimePickerTo.Value
+ DateFrom = DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc),
+ DateTo = DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc)
});
_logger.LogInformation("Saving list of orders for period {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString());
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
diff --git a/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj b/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj
index 494c042..ea30674 100644
--- a/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj
+++ b/PlumbingRepair/PlumbingRepair/PlumbingRepairView.csproj
@@ -20,6 +20,7 @@
+
diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ReportLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ReportLogic.cs
index 1a7f4e3..e2e4ad0 100644
--- a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ReportLogic.cs
+++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ReportLogic.cs
@@ -94,8 +94,8 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
{
FileName = model.FileName,
Title = "Список заказов",
- DateFrom = model.DateFrom!.Value,
- DateTo = model.DateTo!.Value,
+ DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc),
+ DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc),
Orders = GetOrders(model)
});
}
diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/AbstractSaveToPdf.cs
index 7def3ee..cf84be0 100644
--- a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/AbstractSaveToPdf.cs
+++ b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/AbstractSaveToPdf.cs
@@ -1,10 +1,5 @@
using PlumbingRepairBusinessLogic.OfficePackage.HelperEnum;
using PlumbingRepairBusinessLogic.OfficePackage.HelperModels;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace PlumbingRepairBusinessLogic.OfficePackage
{
@@ -13,48 +8,62 @@ namespace PlumbingRepairBusinessLogic.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 { "2cm", "3cm", "6cm", "3cm" });
+ 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 { "2cm", "3cm", "6cm", "3cm", "4 cm" });
+
CreateRow(new PdfRowParameters
{
- Texts = new List { "Номер", "Дата заказа", "Изделие", "Сумма" },
+ Texts = new List { "Номер", "Дата заказа", "Работа", "Статус", "Сумма" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
+
foreach (var order in info.Orders)
{
CreateRow(new PdfRowParameters
{
- Texts = new List { order.Id.ToString(),
- order.DateCreate.ToShortDateString(), order.WorkName, order.Sum.ToString() },
+ Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.WorkName, order.OrderStatus.ToString(), order.Sum.ToString() },
Style = "Normal",
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);
}
+
+ ///
+ /// Создание doc-файла
+ ///
+ ///
protected abstract void CreatePdf(PdfInfo info);
+
+ ///
+ /// Создание параграфа с текстом
+ ///
+ ///
+ ///
protected abstract void CreateParagraph(PdfParagraph paragraph);
+
+ ///
+ /// Создание таблицы
+ ///
+ ///
+ ///
protected abstract void CreateTable(List columns);
+
+ ///
+ /// Создание и заполнение строки
+ ///
+ ///
protected abstract void CreateRow(PdfRowParameters rowParameters);
+
+ ///
+ /// Сохранение файла
+ ///
+ ///
protected abstract void SavePdf(PdfInfo info);
}
}
diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/HelperEnum/PdfParagraphAlignmentType.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/HelperEnum/PdfParagraphAlignmentType.cs
index df42756..beccd1c 100644
--- a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/HelperEnum/PdfParagraphAlignmentType.cs
+++ b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/HelperEnum/PdfParagraphAlignmentType.cs
@@ -12,6 +12,6 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.HelperEnum
Left,
- Rigth
+ Right
}
}
diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/Implements/SaveToPdf.cs
index 8365fbe..a2dd2e7 100644
--- a/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/Implements/SaveToPdf.cs
+++ b/PlumbingRepair/PlumbingRepairBusinessLogic/OfficePackage/Implements/SaveToPdf.cs
@@ -9,32 +9,44 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
public class SaveToPdf : AbstractSaveToPdf
{
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)
@@ -43,10 +55,10 @@ namespace PlumbingRepairBusinessLogic.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 columns)
{
if (_document == null)
@@ -54,11 +66,13 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
return;
}
_table = _document.LastSection.AddTable();
+
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
+
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
@@ -69,20 +83,24 @@ namespace PlumbingRepairBusinessLogic.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)
@@ -93,4 +111,4 @@ namespace PlumbingRepairBusinessLogic.OfficePackage.Implements
renderer.PdfDocument.Save(info.FileName);
}
}
-}
+}
\ No newline at end of file
diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj
index 80fd720..6967efd 100644
--- a/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj
+++ b/PlumbingRepair/PlumbingRepairBusinessLogic/PlumbingRepairBusinessLogic.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/ReportBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ReportBindingModel.cs
index abb81f9..48a4154 100644
--- a/PlumbingRepair/PlumbingRepairContracts/BindingModels/ReportBindingModel.cs
+++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ReportBindingModel.cs
@@ -9,7 +9,7 @@ namespace PlumbingRepairContracts.BindingModels
public class ReportBindingModel
{
public string FileName { get; set; } = string.Empty;
- public DateTime? DateFrom { get; set; } = DateTime.SpecifyKind(, DateTimeKind.Utc);
+ public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
diff --git a/PlumbingRepair/PlumbingRepairDataBaseImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairDataBaseImplement/Models/Order.cs
index 36eb4b6..48ea02f 100644
--- a/PlumbingRepair/PlumbingRepairDataBaseImplement/Models/Order.cs
+++ b/PlumbingRepair/PlumbingRepairDataBaseImplement/Models/Order.cs
@@ -29,7 +29,7 @@ namespace PlumbingRepairDataBaseImplement.Models
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
[Required]
- public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
+ public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs
index f0922dc..cd4fc92 100644
--- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs
+++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs
@@ -19,7 +19,7 @@ namespace PlumbingRepairFileImplement.Models
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
- public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
+ public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs
index d519d79..1a2420e 100644
--- a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs
+++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs
@@ -18,7 +18,7 @@ namespace PlumbingRepairListImplement.Models
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
- public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
+ public DateTime DateCreate { get; private set; }
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{