АААААААААААААААААААА

This commit is contained in:
Ctepa 2024-12-16 21:03:03 +04:00
parent f4af6dafbc
commit b44919089b
11 changed files with 309 additions and 80 deletions

View File

@ -1,4 +1,7 @@
namespace Publication.Entites;
using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
using Unity;
namespace Publication.Entites;
public class PrintingHouses
{
@ -13,7 +16,7 @@ public class PrintingHouses
public IEnumerable<PrintingHouseOrders> printingHouseOrder { get; set; } = [];
public static PrintingHouses CreateEntity(int id, string title, string phone, string address,int materialsId,IEnumerable<PrintingHouseOrders> printingHouseOrders)
public static PrintingHouses CreateEntity(int id, string title, string phone, string address,int materialsId, IEnumerable<PrintingHouseOrders> printingHouseOrders)
{
return new PrintingHouses
@ -23,7 +26,22 @@ public class PrintingHouses
Phone = phone,
Address = address,
MaterialsId=materialsId,
Date = DateTime.Now,
printingHouseOrder = printingHouseOrders
};
}
public static PrintingHouses CreateEntity(TempPrintingHouseOrders tempPrintingHouseOrders, IEnumerable<PrintingHouseOrders> _printingHouseOrders)
{
return new PrintingHouses
{
Id = tempPrintingHouseOrders.Id,
Title = tempPrintingHouseOrders.Title,
Phone = tempPrintingHouseOrders.Phone,
Address = tempPrintingHouseOrders.Address,
MaterialsId = tempPrintingHouseOrders.MaterialsId,
Date = tempPrintingHouseOrders.Date,
printingHouseOrder = _printingHouseOrders
};
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Publication.Entites;
public class TempPrintingHouseOrders
{
public int Id { get; set; }
public string Title { get; set; }
public string Phone { get; set; }
public string Address { get; set; }
public int MaterialsId { get; set; }
public DateTime Date { get; set; }
public int OrderId { get; set; }
public int Count { get; set; }
}

View File

@ -29,14 +29,12 @@
private void InitializeComponent()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
textBoxFilePath = new TextBox();
dateTimePickerStartDate = new DateTimePicker();
dateTimePickerEndDate = new DateTimePicker();
buttonSelectFilePath = new Button();
comboBoxProducts = new ComboBox();
buttonMakeReport = new Button();
SuspendLayout();
//
@ -49,19 +47,10 @@
label1.TabIndex = 0;
label1.Text = "Путь до файла:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(22, 72);
label2.Name = "label2";
label2.Size = new Size(69, 20);
label2.TabIndex = 1;
label2.Text = "Продукт:";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(22, 127);
label3.Location = new Point(22, 79);
label3.Name = "label3";
label3.Size = new Size(97, 20);
label3.TabIndex = 2;
@ -70,7 +59,7 @@
// label4
//
label4.AutoSize = true;
label4.Location = new Point(22, 178);
label4.Location = new Point(22, 130);
label4.Name = "label4";
label4.Size = new Size(90, 20);
label4.TabIndex = 3;
@ -86,14 +75,14 @@
//
// dateTimePickerStartDate
//
dateTimePickerStartDate.Location = new Point(188, 127);
dateTimePickerStartDate.Location = new Point(188, 79);
dateTimePickerStartDate.Name = "dateTimePickerStartDate";
dateTimePickerStartDate.Size = new Size(181, 27);
dateTimePickerStartDate.TabIndex = 5;
//
// dateTimePickerEndDate
//
dateTimePickerEndDate.Location = new Point(188, 173);
dateTimePickerEndDate.Location = new Point(188, 125);
dateTimePickerEndDate.Name = "dateTimePickerEndDate";
dateTimePickerEndDate.Size = new Size(181, 27);
dateTimePickerEndDate.TabIndex = 6;
@ -107,42 +96,34 @@
buttonSelectFilePath.TabIndex = 7;
buttonSelectFilePath.Text = "..";
buttonSelectFilePath.UseVisualStyleBackColor = false;
//
// comboBoxProducts
//
comboBoxProducts.FormattingEnabled = true;
comboBoxProducts.Location = new Point(188, 72);
comboBoxProducts.Name = "comboBoxProducts";
comboBoxProducts.Size = new Size(181, 28);
comboBoxProducts.TabIndex = 8;
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
//
// buttonMakeReport
//
buttonMakeReport.BackColor = Color.FromArgb(192, 192, 255);
buttonMakeReport.Location = new Point(22, 234);
buttonMakeReport.Location = new Point(22, 186);
buttonMakeReport.Name = "buttonMakeReport";
buttonMakeReport.Size = new Size(347, 29);
buttonMakeReport.TabIndex = 9;
buttonMakeReport.Text = "Сформировать";
buttonMakeReport.UseVisualStyleBackColor = false;
buttonMakeReport.Click += ButtonMakeReport_Click;
//
// FormProductReport
// FormCountReport
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(409, 302);
ClientSize = new Size(409, 249);
Controls.Add(buttonMakeReport);
Controls.Add(comboBoxProducts);
Controls.Add(buttonSelectFilePath);
Controls.Add(dateTimePickerEndDate);
Controls.Add(dateTimePickerStartDate);
Controls.Add(textBoxFilePath);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormProductReport";
Text = "FormProductReport";
Name = "FormCountReport";
Text = "FormCountReport";
ResumeLayout(false);
PerformLayout();
}
@ -150,14 +131,12 @@
#endregion
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private TextBox textBoxFilePath;
private DateTimePicker dateTimePickerStartDate;
private DateTimePicker dateTimePickerEndDate;
private Button buttonSelectFilePath;
private ComboBox comboBoxProducts;
private Button buttonMakeReport;
}
}

View File

@ -1,4 +1,5 @@
using System;
using Publication.Reports;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -7,14 +8,59 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Unity;
namespace Publication.Forms
{
public partial class FormCountReport : Form
{
public FormCountReport()
IUnityContainer _container;
public FormCountReport(IUnityContainer container)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
}
private void ButtonSelectFilePath_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog()
{
Filter = "Excel Files | *.xlsx"
};
if (sfd.ShowDialog() != DialogResult.OK)
{
return;
}
textBoxFilePath.Text = sfd.FileName;
}
private void ButtonMakeReport_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(textBoxFilePath.Text))
{
throw new Exception("Отсутствует имя файла для отчета");
}
if (dateTimePickerEndDate.Value <= dateTimePickerStartDate.Value)
{
throw new Exception("Дата начала должна быть раньше даты окончания");
}
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, dateTimePickerStartDate.Value, dateTimePickerEndDate.Value))
{
MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Возникли ошибки при формировании документа.Подробности в логах", "Формирование документа",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при создании очета", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -82,7 +82,8 @@ MessageBoxButtons.OK, MessageBoxIcon.Error);
)
);
}
return list;
return list.GroupBy(x => x.OrderId, x => x.Count, (id, counts) =>
PrintingHouseOrders.CreateEntity(0, id, counts.Sum())).ToList();
}
private void ButtonBreak_Click(object sender, EventArgs e) => Close();

View File

@ -38,6 +38,8 @@
CreateOrderToolStripMenuItem = new ToolStripMenuItem();
PrintingToolStripMenuItem = new ToolStripMenuItem();
ReportsToolStripMenuItem = new ToolStripMenuItem();
DirectoryReportToolStripMenuItem = new ToolStripMenuItem();
CountReportToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
SuspendLayout();
//
@ -92,9 +94,22 @@
//
// ReportsToolStripMenuItem
//
ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, CountReportToolStripMenuItem });
ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem";
resources.ApplyResources(ReportsToolStripMenuItem, "ReportsToolStripMenuItem");
//
// DirectoryReportToolStripMenuItem
//
DirectoryReportToolStripMenuItem.Name = "DirectoryReportToolStripMenuItem";
resources.ApplyResources(DirectoryReportToolStripMenuItem, "DirectoryReportToolStripMenuItem");
DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
//
// CountReportToolStripMenuItem
//
CountReportToolStripMenuItem.Name = "CountReportToolStripMenuItem";
resources.ApplyResources(CountReportToolStripMenuItem, "CountReportToolStripMenuItem");
CountReportToolStripMenuItem.Click += CountReportToolStripMenuItem_Click;
//
// Publication
//
resources.ApplyResources(this, "$this");
@ -119,5 +134,7 @@
private ToolStripMenuItem CreateOrderToolStripMenuItem;
private ToolStripMenuItem PrintingToolStripMenuItem;
private ToolStripMenuItem ReportsToolStripMenuItem;
private ToolStripMenuItem DirectoryReportToolStripMenuItem;
private ToolStripMenuItem CountReportToolStripMenuItem;
}
}

View File

@ -81,4 +81,28 @@ public partial class Publication : Form
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void DirectoryReportToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
unityContainer.Resolve<FormDirectoryReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CountReportToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
unityContainer.Resolve<FormCountReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè çàãðóçêå", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

View File

@ -127,24 +127,31 @@
<data name="DictionsToolStripMenuItem.Text" xml:space="preserve">
<value>Справочники</value>
</data>
<data name="CreateOrderToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>224, 26</value>
</data>
<data name="CreateOrderToolStripMenuItem.Text" xml:space="preserve">
<value>Создать заказ</value>
</data>
<data name="PrintingToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>224, 26</value>
</data>
<data name="PrintingToolStripMenuItem.Text" xml:space="preserve">
<value>Печать</value>
</data>
<data name="OperationsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>95, 24</value>
</data>
<data name="OperationsToolStripMenuItem.Text" xml:space="preserve">
<value>Операции</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="DirectoryReportToolStripMenuItem.ShortcutKeys" type="System.Windows.Forms.Keys, System.Windows.Forms">
<value>Ctrl+W</value>
</data>
<data name="DirectoryReportToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>350, 26</value>
</data>
<data name="DirectoryReportToolStripMenuItem.Text" xml:space="preserve">
<value>Документ со справочниками</value>
</data>
<data name="CountReportToolStripMenuItem.ShortcutKeys" type="System.Windows.Forms.Keys, System.Windows.Forms">
<value>Ctrl+E</value>
</data>
<data name="CountReportToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>350, 26</value>
</data>
<data name="CountReportToolStripMenuItem.Text" xml:space="preserve">
<value>Движение заказов</value>
</data>
<data name="ReportsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>73, 24</value>
</data>
@ -183,17 +190,29 @@
<value>Заказчики</value>
</data>
<data name="MaterialsToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>224, 26</value>
<value>185, 26</value>
</data>
<data name="MaterialsToolStripMenuItem.Text" xml:space="preserve">
<value>Материалы</value>
</data>
<data name="PublishingHousesToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>224, 26</value>
<value>185, 26</value>
</data>
<data name="PublishingHousesToolStripMenuItem.Text" xml:space="preserve">
<value>Издательства</value>
</data>
<data name="CreateOrderToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 26</value>
</data>
<data name="CreateOrderToolStripMenuItem.Text" xml:space="preserve">
<value>Создать заказ</value>
</data>
<data name="PrintingToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>188, 26</value>
</data>
<data name="PrintingToolStripMenuItem.Text" xml:space="preserve">
<value>Печать</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@ -2156,7 +2175,6 @@
Gg8Vxln/2Q==
</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="$this.BackgroundImageLayout" type="System.Windows.Forms.ImageLayout, System.Windows.Forms">
<value>Stretch</value>
</data>
@ -2217,6 +2235,18 @@
<data name="&gt;&gt;ReportsToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;DirectoryReportToolStripMenuItem.Name" xml:space="preserve">
<value>DirectoryReportToolStripMenuItem</value>
</data>
<data name="&gt;&gt;DirectoryReportToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;CountReportToolStripMenuItem.Name" xml:space="preserve">
<value>CountReportToolStripMenuItem</value>
</data>
<data name="&gt;&gt;CountReportToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>Publication</value>
</data>

View File

@ -0,0 +1,86 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Publication.Reports;
public class PdfBuilder
{
/*private readonly string _filePath;
private readonly Document _document;
public PdfBuilder(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
throw new ArgumentNullException(nameof(filePath));
}
if (File.Exists(filePath))
{
File.Delete(filePath);
}
_filePath = filePath;
_document = new Document();
DefineStyles();
}
public PdfBuilder AddHeader(string header)
{
_document.AddSection().AddParagraph(header, "NormalBold");
return this;
}
public PdfBuilder AddPieChart(string title, List<(string Caption, double Value)> data)
{
if (data == null || data.Count == 0)
{
return this;
}
var chart = new Chart(ChartType.Pie2D);
var series = chart.SeriesCollection.AddSeries();
series.Add(data.Select(x => x.Value).ToArray());
var xseries = chart.XValues.AddXSeries();
xseries.Add(data.Select(x => x.Caption).ToArray());
chart.DataLabel.Type = DataLabelType.Percent;
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
chart.Width = Unit.FromCentimeter(16);
chart.Height = Unit.FromCentimeter(12);
chart.TopArea.AddParagraph(title);
chart.XAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.HasMajorGridlines = true;
chart.PlotArea.LineFormat.Width = 1;
chart.PlotArea.LineFormat.Visible = true;
chart.TopArea.AddLegend();
_document.LastSection.Add(chart);
return this;
}
public void Build()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(_filePath);
}
private void DefineStyles()
{
var headerStyle = _document.AddStyle("NormalBold", "Normal");
headerStyle.Font.Bold = true;
headerStyle.Font.Size = 14;
headerStyle.Font.Color = Colors.DeepPink;
}*/
}

View File

@ -3,6 +3,7 @@ using Newtonsoft.Json;
using Npgsql;
using Publication.Entites;
using Dapper;
using Unity;
namespace Publication.Repositories.Implementations;
@ -75,10 +76,15 @@ public class PrintingHouseRepository : IPrintingHouseRepository
try
{
using var connection = new NpgsqlConnection(connectionRepository.GetConnection);
var querySelect = "SELECT * FROM PrintingHouses";
var printingHouses = connection.Query<PrintingHouses>(querySelect);
var querySelect = @"SELECT ph.*, pho.OrderId, pho.Count
FROM PrintingHouses ph
INNER JOIN PrintingHouseOrders pho ON pho.PrintingHouseId = ph.Id";
var printingHouses = connection.Query<TempPrintingHouseOrders>(querySelect);
logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(printingHouses));
return printingHouses;
return printingHouses.GroupBy(x => x.Id, y => y,
(key, value) => PrintingHouses.CreateEntity(value.First(),
value.Select(z => PrintingHouseOrders.CreateEntity(0, z.OrderId, z.Count)))).ToList();
}
catch (Exception ex)
{