PIbd-21_Kudrinsky_O.S._LabWork_3 #6

Closed
8floom wants to merge 4 commits from LabWork_3 into LabWork_2
21 changed files with 665 additions and 177 deletions
Showing only changes of commit 4708a26995 - Show all commits

View File

@ -12,7 +12,7 @@ public class AssemblerShift
public DateTime AssemblerShiftDate { get; private set; }
public static AssemblerShift CreateOperation(int id, int workHours, int assemblerID, int shiftID_Shift)
public static AssemblerShift CreateOperation(int id, int workHours, int assemblerID, int shiftID_Shift, DateTime? shiftDate = null)
{
return new AssemblerShift
{
@ -20,7 +20,7 @@ public class AssemblerShift
WorkHours = workHours,
AssemblerID_Assembler = assemblerID,
ShiftID_Shift = shiftID_Shift,
AssemblerShiftDate = DateTime.Now
AssemblerShiftDate = shiftDate ?? DateTime.Now
};
}
}

View File

@ -19,7 +19,7 @@ public class Assembly
return new Assembly
{
ID = id,
Count = count,
Count = count,
AssemblerID_Assembler = assemblerID,
ProductAssembly = productAssembly,
AssemblyDate = assemblyDate ?? DateTime.Now

View File

@ -18,3 +18,4 @@ public class TempProductAssembly
public DateTime AssemblyDate { get; private set; }
}

View File

@ -39,6 +39,7 @@
отчетыToolStripMenuItem = new ToolStripMenuItem();
DirectoryReportToolStripMenuItem = new ToolStripMenuItem();
AssembliesReportToolStripMenuItem = new ToolStripMenuItem();
AssemblyDestributionToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
SuspendLayout();
//
@ -48,7 +49,8 @@
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1354, 42);
menuStrip.Padding = new Padding(3, 1, 0, 1);
menuStrip.Size = new Size(729, 24);
menuStrip.TabIndex = 0;
menuStrip.Text = "menuStrip1";
//
@ -56,27 +58,27 @@
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AssemblersToolStripMenuItem, ShiftsToolStripMenuItem, ProductsToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(184, 38);
справочникиToolStripMenuItem.Size = new Size(94, 22);
справочникиToolStripMenuItem.Text = "Справочники";
//
// AssemblersToolStripMenuItem
//
AssemblersToolStripMenuItem.Name = "AssemblersToolStripMenuItem";
AssemblersToolStripMenuItem.Size = new Size(264, 44);
AssemblersToolStripMenuItem.Size = new Size(134, 22);
AssemblersToolStripMenuItem.Text = "Сборщики";
AssemblersToolStripMenuItem.Click += AssemblersToolStripMenuItem_Click;
//
// ShiftsToolStripMenuItem
//
ShiftsToolStripMenuItem.Name = "ShiftsToolStripMenuItem";
ShiftsToolStripMenuItem.Size = new Size(264, 44);
ShiftsToolStripMenuItem.Size = new Size(134, 22);
ShiftsToolStripMenuItem.Text = "Смены";
ShiftsToolStripMenuItem.Click += ShiftsToolStripMenuItem_Click;
//
// ProductsToolStripMenuItem
//
ProductsToolStripMenuItem.Name = "ProductsToolStripMenuItem";
ProductsToolStripMenuItem.Size = new Size(264, 44);
ProductsToolStripMenuItem.Size = new Size(134, 22);
ProductsToolStripMenuItem.Text = "Изделия";
ProductsToolStripMenuItem.Click += ProductsToolStripMenuItem_Click_1;
//
@ -84,35 +86,35 @@
//
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AssemblyToolStripMenuItem, AssemblerShiftToolStripMenuItem });
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
операцииToolStripMenuItem.Size = new Size(147, 38);
операцииToolStripMenuItem.Size = new Size(75, 22);
операцииToolStripMenuItem.Text = "Операции";
//
// AssemblyToolStripMenuItem
//
AssemblyToolStripMenuItem.Name = "AssemblyToolStripMenuItem";
AssemblyToolStripMenuItem.Size = new Size(330, 44);
AssemblyToolStripMenuItem.Size = new Size(165, 22);
AssemblyToolStripMenuItem.Text = "Сборка";
AssemblyToolStripMenuItem.Click += AssemblyToolStripMenuItem_Click;
//
// AssemblerShiftToolStripMenuItem
//
AssemblerShiftToolStripMenuItem.Name = "AssemblerShiftToolStripMenuItem";
AssemblerShiftToolStripMenuItem.Size = new Size(330, 44);
AssemblerShiftToolStripMenuItem.Size = new Size(165, 22);
AssemblerShiftToolStripMenuItem.Text = "Выйти на смену ";
AssemblerShiftToolStripMenuItem.Click += AssemblerShiftToolStripMenuItem_Click;
//
// отчетыToolStripMenuItem
//
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, AssembliesReportToolStripMenuItem });
отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DirectoryReportToolStripMenuItem, AssembliesReportToolStripMenuItem, AssemblyDestributionToolStripMenuItem });
отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
отчетыToolStripMenuItem.Size = new Size(116, 38);
отчетыToolStripMenuItem.Size = new Size(60, 22);
отчетыToolStripMenuItem.Text = "Отчеты";
//
// DirectoryReportToolStripMenuItem
//
DirectoryReportToolStripMenuItem.Name = "DirectoryReportToolStripMenuItem";
DirectoryReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.W;
DirectoryReportToolStripMenuItem.Size = new Size(559, 44);
DirectoryReportToolStripMenuItem.Size = new Size(280, 22);
DirectoryReportToolStripMenuItem.Text = "Документ со справочниками";
DirectoryReportToolStripMenuItem.Click += DirectoryReportToolStripMenuItem_Click;
//
@ -120,19 +122,28 @@
//
AssembliesReportToolStripMenuItem.Name = "AssembliesReportToolStripMenuItem";
AssembliesReportToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.E;
AssembliesReportToolStripMenuItem.Size = new Size(559, 44);
AssembliesReportToolStripMenuItem.Size = new Size(280, 22);
AssembliesReportToolStripMenuItem.Text = "Отчет по сборкам";
AssembliesReportToolStripMenuItem.Click += AssembliesReportToolStripMenuItem_Click;
//
// AssemblyDestributionToolStripMenuItem
//
AssemblyDestributionToolStripMenuItem.Name = "AssemblyDestributionToolStripMenuItem";
AssemblyDestributionToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;
AssemblyDestributionToolStripMenuItem.Size = new Size(280, 22);
AssemblyDestributionToolStripMenuItem.Text = "Распределение сборок";
AssemblyDestributionToolStripMenuItem.Click += AssemblyDestributionToolStripMenuItem_Click;
//
// FormWorkshop
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BackgroundImage = Properties.Resources.цех;
BackgroundImageLayout = ImageLayout.Stretch;
ClientSize = new Size(1354, 785);
ClientSize = new Size(729, 368);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Margin = new Padding(2, 1, 2, 1);
Name = "FormWorkshop";
StartPosition = FormStartPosition.CenterScreen;
Text = "Цех";
@ -155,5 +166,6 @@
private ToolStripMenuItem ProductsToolStripMenuItem;
private ToolStripMenuItem DirectoryReportToolStripMenuItem;
private ToolStripMenuItem AssembliesReportToolStripMenuItem;
private ToolStripMenuItem AssemblyDestributionToolStripMenuItem;
}
}

View File

@ -90,7 +90,7 @@ namespace ProjectWorkshop
{
try
{
_container.Resolve<FormAssembliesReport>().ShowDialog();
_container.Resolve<FormAssemblersReport>().ShowDialog();
}
catch (Exception ex)
{
@ -98,5 +98,17 @@ namespace ProjectWorkshop
}
}
private void AssemblyDestributionToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormAssemblyDistributionReport>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -43,10 +43,14 @@ namespace ProjectWorkshop.Forms
throw new Exception("Имеются незаполненные поля");
}
var selectedShift = (dynamic)comboBoxShiftDate.SelectedItem;
DateTime shiftDate = selectedShift.ShiftDate;
var assemblerShift = AssemblerShift.CreateOperation(0,
(int)numericUpDownWorkHours.Value,
(int)comboBoxAssembler.SelectedValue!,
(int)comboBoxShiftDate.SelectedValue!);
(int)comboBoxShiftDate.SelectedValue!,
shiftDate);
_assemblerShiftRepository.CreateAssemblerShift(assemblerShift);
@ -58,6 +62,7 @@ namespace ProjectWorkshop.Forms
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
Close();

View File

@ -1,6 +1,6 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssembliesReport
partial class FormAssemblersReport
{
/// <summary>
/// Required designer variable.
@ -36,56 +36,62 @@
buttonBuild = new Button();
dateTimePickerEnd = new DateTimePicker();
labelDateTo = new Label();
labelAssembly = new Label();
comboBoxAssembly = new ComboBox();
labelAssembler = new Label();
comboBoxAssembler = new ComboBox();
SuspendLayout();
//
// labelFilePath
//
labelFilePath.AutoSize = true;
labelFilePath.Location = new Point(51, 48);
labelFilePath.Location = new Point(27, 22);
labelFilePath.Margin = new Padding(2, 0, 2, 0);
labelFilePath.Name = "labelFilePath";
labelFilePath.Size = new Size(178, 32);
labelFilePath.Size = new Size(90, 15);
labelFilePath.TabIndex = 0;
labelFilePath.Text = "Путь до файла:";
//
// labelDateFrom
//
labelDateFrom.AutoSize = true;
labelDateFrom.Location = new Point(51, 200);
labelDateFrom.Location = new Point(27, 94);
labelDateFrom.Margin = new Padding(2, 0, 2, 0);
labelDateFrom.Name = "labelDateFrom";
labelDateFrom.Size = new Size(154, 32);
labelDateFrom.Size = new Size(77, 15);
labelDateFrom.TabIndex = 1;
labelDateFrom.Text = "Дата начала:";
//
// dateTimePickerStart
//
dateTimePickerStart.Location = new Point(255, 195);
dateTimePickerStart.Location = new Point(137, 91);
dateTimePickerStart.Margin = new Padding(2, 1, 2, 1);
dateTimePickerStart.Name = "dateTimePickerStart";
dateTimePickerStart.Size = new Size(400, 39);
dateTimePickerStart.Size = new Size(217, 23);
dateTimePickerStart.TabIndex = 2;
//
// textBoxFilePath
//
textBoxFilePath.Location = new Point(255, 48);
textBoxFilePath.Location = new Point(137, 22);
textBoxFilePath.Margin = new Padding(2, 1, 2, 1);
textBoxFilePath.Name = "textBoxFilePath";
textBoxFilePath.Size = new Size(400, 39);
textBoxFilePath.Size = new Size(217, 23);
textBoxFilePath.TabIndex = 3;
//
// buttonSelectFilePath
//
buttonSelectFilePath.Location = new Point(661, 48);
buttonSelectFilePath.Location = new Point(356, 22);
buttonSelectFilePath.Margin = new Padding(2, 1, 2, 1);
buttonSelectFilePath.Name = "buttonSelectFilePath";
buttonSelectFilePath.Size = new Size(43, 39);
buttonSelectFilePath.Size = new Size(23, 18);
buttonSelectFilePath.TabIndex = 4;
buttonSelectFilePath.UseVisualStyleBackColor = true;
buttonSelectFilePath.Click += ButtonSelectFilePath_Click;
//
// buttonBuild
//
buttonBuild.Location = new Point(255, 373);
buttonBuild.Location = new Point(137, 175);
buttonBuild.Margin = new Padding(2, 1, 2, 1);
buttonBuild.Name = "buttonBuild";
buttonBuild.Size = new Size(192, 54);
buttonBuild.Size = new Size(103, 25);
buttonBuild.TabIndex = 5;
buttonBuild.Text = "Сформировать";
buttonBuild.UseVisualStyleBackColor = true;
@ -93,44 +99,48 @@
//
// dateTimePickerEnd
//
dateTimePickerEnd.Location = new Point(255, 277);
dateTimePickerEnd.Location = new Point(137, 130);
dateTimePickerEnd.Margin = new Padding(2, 1, 2, 1);
dateTimePickerEnd.Name = "dateTimePickerEnd";
dateTimePickerEnd.Size = new Size(400, 39);
dateTimePickerEnd.Size = new Size(217, 23);
dateTimePickerEnd.TabIndex = 7;
//
// labelDateTo
//
labelDateTo.AutoSize = true;
labelDateTo.Location = new Point(51, 282);
labelDateTo.Location = new Point(27, 132);
labelDateTo.Margin = new Padding(2, 0, 2, 0);
labelDateTo.Name = "labelDateTo";
labelDateTo.Size = new Size(143, 32);
labelDateTo.Size = new Size(71, 15);
labelDateTo.TabIndex = 6;
labelDateTo.Text = "Дата конца:";
//
// labelAssembly
// labelAssembler
//
labelAssembly.AutoSize = true;
labelAssembly.Location = new Point(78, 129);
labelAssembly.Name = "labelAssembly";
labelAssembly.Size = new Size(100, 32);
labelAssembly.TabIndex = 8;
labelAssembly.Text = "Сборка:";
labelAssembler.AutoSize = true;
labelAssembler.Location = new Point(42, 60);
labelAssembler.Margin = new Padding(2, 0, 2, 0);
labelAssembler.Name = "labelAssembler";
labelAssembler.Size = new Size(63, 15);
labelAssembler.TabIndex = 8;
labelAssembler.Text = "Сборщик:";
//
// comboBoxAssembly
// comboBoxAssembler
//
comboBoxAssembly.FormattingEnabled = true;
comboBoxAssembly.Location = new Point(255, 126);
comboBoxAssembly.Name = "comboBoxAssembly";
comboBoxAssembly.Size = new Size(400, 40);
comboBoxAssembly.TabIndex = 9;
comboBoxAssembler.FormattingEnabled = true;
comboBoxAssembler.Location = new Point(137, 59);
comboBoxAssembler.Margin = new Padding(2, 1, 2, 1);
comboBoxAssembler.Name = "comboBoxAssembler";
comboBoxAssembler.Size = new Size(217, 23);
comboBoxAssembler.TabIndex = 9;
//
// FormAssembliesReport
// FormAssemblersReport
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(comboBoxAssembly);
Controls.Add(labelAssembly);
ClientSize = new Size(431, 211);
Controls.Add(comboBoxAssembler);
Controls.Add(labelAssembler);
Controls.Add(dateTimePickerEnd);
Controls.Add(labelDateTo);
Controls.Add(buttonBuild);
@ -139,8 +149,9 @@
Controls.Add(dateTimePickerStart);
Controls.Add(labelDateFrom);
Controls.Add(labelFilePath);
Name = "FormAssembliesReport";
Text = "Отчет по сборкам";
Margin = new Padding(2, 1, 2, 1);
Name = "FormAssemblersReport";
Text = "Отчет по сборщикам";
ResumeLayout(false);
PerformLayout();
}
@ -155,7 +166,7 @@
private Button buttonBuild;
private DateTimePicker dateTimePickerEnd;
private Label labelDateTo;
private Label labelAssembly;
private ComboBox comboBoxAssembly;
private Label labelAssembler;
private ComboBox comboBoxAssembler;
}
}

View File

@ -13,17 +13,17 @@ using Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormAssembliesReport : Form
public partial class FormAssemblersReport : Form
{
private readonly IUnityContainer _container;
public FormAssembliesReport(IUnityContainer container, IAssemblyRepository assemblyRepository)
public FormAssemblersReport(IUnityContainer container, IAssemblerRepository assemblerRepository)
{
InitializeComponent();
_container = container ?? throw new ArgumentNullException(nameof(container));
comboBoxAssembly.DataSource = assemblyRepository.ReadAssemblies();
comboBoxAssembly.DisplayMember = "Name";
comboBoxAssembly.ValueMember = "ID";
comboBoxAssembler.DataSource = assemblerRepository.ReadAssemblers();
comboBoxAssembler.DisplayMember = "Name";
comboBoxAssembler.ValueMember = "ID";
}
private void ButtonSelectFilePath_Click(object sender, EventArgs e)
{
@ -52,12 +52,12 @@ namespace ProjectWorkshop.Forms
{
throw new Exception("Дата начала должна быть раньше даты окончания");
}
if (comboBoxAssembly.SelectedIndex < 0)
if (comboBoxAssembler.SelectedIndex < 0)
{
throw new Exception("Не выбрана сборка");
throw new Exception("Не выбран сборщик");
}
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxAssembly.SelectedValue!,
if (_container.Resolve<TableReport>().CreateTable(textBoxFilePath.Text, (int)comboBoxAssembler.SelectedValue!,
dateTimePickerStart.Value, dateTimePickerEnd.Value))
{
MessageBox.Show("Документ сформирован", "Формирование документа", MessageBoxButtons.OK, MessageBoxIcon.Information);

View File

@ -51,7 +51,7 @@ namespace ProjectWorkshop.Forms
}
var totalCount = productAssemblies.Sum(pa => pa.Count);
var assemblyDate = dateTimePickerAssemblyDate.Value; // Получение выбранной даты
var assemblyDate = dateTimePickerAssemblyDate.Value;
_assemblyRepository.CreateAssembly(Assembly.CreateOperation(
id: 0,
@ -94,17 +94,7 @@ namespace ProjectWorkshop.Forms
}
return list
.GroupBy(
x => x.ProductID_Product,
x => x.Count,
(id, counts) => ProductAssembly.CreateElement(
id: 0,
productID: id,
assemblyID: 0,
count: counts.Sum()
))
.ToList();
return list;
}
}
}

View File

@ -0,0 +1,107 @@
namespace ProjectWorkshop.Forms
{
partial class FormAssemblyDistributionReport
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonSelectFileName = new Button();
labelFileName = new Label();
labelDate = new Label();
dateTimePickerDate = new DateTimePicker();
buttonCreate = new Button();
SuspendLayout();
//
// buttonSelectFileName
//
buttonSelectFileName.Location = new Point(37, 29);
buttonSelectFileName.Name = "buttonSelectFileName";
buttonSelectFileName.Size = new Size(75, 23);
buttonSelectFileName.TabIndex = 0;
buttonSelectFileName.Text = "Выбрать";
buttonSelectFileName.UseVisualStyleBackColor = true;
buttonSelectFileName.Click += ButtonSelectFileName_Click;
//
// labelFileName
//
labelFileName.AutoSize = true;
labelFileName.Location = new Point(132, 33);
labelFileName.Name = "labelFileName";
labelFileName.Size = new Size(36, 15);
labelFileName.TabIndex = 1;
labelFileName.Text = "Файл";
//
// labelDate
//
labelDate.AutoSize = true;
labelDate.Location = new Point(37, 83);
labelDate.Name = "labelDate";
labelDate.Size = new Size(35, 15);
labelDate.TabIndex = 2;
labelDate.Text = "Дата:";
//
// dateTimePickerDate
//
dateTimePickerDate.Location = new Point(89, 77);
dateTimePickerDate.Name = "dateTimePickerDate";
dateTimePickerDate.Size = new Size(200, 23);
dateTimePickerDate.TabIndex = 3;
//
// buttonCreate
//
buttonCreate.Location = new Point(105, 141);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(110, 23);
buttonCreate.TabIndex = 4;
buttonCreate.Text = "Сформировать";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// FormAssemblyDistributionReport
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(333, 193);
Controls.Add(buttonCreate);
Controls.Add(dateTimePickerDate);
Controls.Add(labelDate);
Controls.Add(labelFileName);
Controls.Add(buttonSelectFileName);
Name = "FormAssemblyDistributionReport";
Text = "Распределение сборок";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonSelectFileName;
private Label labelFileName;
private Label labelDate;
private DateTimePicker dateTimePickerDate;
private Button buttonCreate;
}
}

View File

@ -0,0 +1,71 @@
using ProjectWorkshop.Reports;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Unity;
namespace ProjectWorkshop.Forms
{
public partial class FormAssemblyDistributionReport : Form
{
private string _fileName = string.Empty;
private readonly IUnityContainer _container;
public FormAssemblyDistributionReport(IUnityContainer container)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void ButtonSelectFileName_Click(object sender, EventArgs e)
{
var sfd = new SaveFileDialog()
{
Filter = "Pdf Files | *.pdf"
};
if (sfd.ShowDialog() == DialogResult.OK)
{
_fileName = sfd.FileName;
labelFileName.Text = Path.GetFileName(_fileName);
}
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrWhiteSpace(_fileName))
{
throw new Exception("Отсутствует имя файла для отчета");
}
if
(_container.Resolve<ChartReport>().CreateChart(_fileName, dateTimePickerDate.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

@ -0,0 +1,120 @@
<?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
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<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
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
mimetype set.
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
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: 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
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />

View File

@ -0,0 +1,68 @@
using Microsoft.Extensions.Logging;
using ProjectWorkshop.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProjectWorkshop.Reports
{
internal class ChartReport
{
private readonly IAssemblyRepository _assemblyRepository;
private readonly IAssemblerRepository _assemblerRepository;
private readonly ILogger<ChartReport> _logger;
public ChartReport(IAssemblyRepository assemblyRepository, IAssemblerRepository assemblerRepository, ILogger<ChartReport> logger)
{
_assemblyRepository = assemblyRepository ??
throw new ArgumentNullException(nameof(assemblyRepository));
_assemblerRepository = assemblerRepository ??
throw new ArgumentNullException(nameof(assemblerRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public bool CreateChart(string filePath, DateTime dateTime)
{
try
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var data = GetData(dateTime);
new PdfBuilder(filePath)
.AddHeader("Сборки изделий")
.AddPieChart("Количество сборок по сборщикам", data)
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
private List<(string Caption, double Value)> GetData(DateTime dateTime)
{
var assemblies = _assemblyRepository
.ReadAssemblies()
.Where(x => x.AssemblyDate.Date == dateTime.Date)
.GroupBy(x => x.AssemblerID_Assembler)
.Select(group => new
{
AssemblerId = group.Key,
AssemblyCount = group.Count()
})
.ToList();
var assemblerNames = _assemblerRepository.ReadAssemblers()
.ToDictionary(a => a.ID, a => a.FullName);
return assemblies
.Select(x => (assemblerNames.ContainsKey(x.AssemblerId) ? assemblerNames[x.AssemblerId] : $"Сборщик {x.AssemblerId}", (double)x.AssemblyCount))
.ToList();
}
}
}

View File

@ -15,7 +15,7 @@ internal class DocReport
private readonly IShiftRepository _shiftRepository;
private readonly ILogger<DocReport> _logger;
public DocReport(IAssemblerRepository assemblerRepository, IProductRepository productRepository,IShiftRepository shiftRepository ,ILogger<DocReport> logger)
public DocReport(IAssemblerRepository assemblerRepository, IProductRepository productRepository, IShiftRepository shiftRepository, ILogger<DocReport> logger)
{
_assemblerRepository = assemblerRepository ?? throw new ArgumentNullException(nameof(assemblerRepository));
_productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
@ -55,12 +55,13 @@ internal class DocReport
{
return [
["Название изделия", "Стоимость", "Дата сборки"],
.. _productRepository
.ReadProducts()
.Select(x => new string[] { x.ProductName, x.Price.ToString()}),
];
.. _productRepository
.ReadProducts()
.Select(x => new string[] { x.ProductName, x.Price.ToString(), x.ProductType.ToString()}), // Добавьте пустую строку для "Дата сборки" или заполните реальным значением
];
}
private List<string[]> GetAssemblers()
{
return [

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Reports;
namespace ProjectLibrary.Reports;
internal class ExcelBuilder
{

View File

@ -0,0 +1,71 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MigraDoc.Rendering;
namespace ProjectWorkshop.Reports;
internal 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()
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(_filePath);
}
private void DefineStyles()
{
var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal");
headerStyle.Font.Bold = true;
headerStyle.Font.Size = 14;
}
}

View File

@ -1,99 +1,123 @@
using Microsoft.Extensions.Logging;
using ProjectLibrary.Reports;
using ProjectWorkshop.Repositories;
using ProjectWorkshop.Repositories.Implementations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectWorkshop.Reports;
internal class TableReport
namespace ProjectWorkshop.Reports
{
private readonly IAssemblyRepository _assemblyRepository;
private readonly IAssemblerShiftRepository _assemblerShiftRepository;
private readonly ILogger<TableReport> _logger;
internal static readonly string[] Headers = { "Дата", "Описание", "Количество сборок", "Количество часов смен" };
public TableReport(IAssemblyRepository assemblyRepository,
IAssemblerShiftRepository assemblerShiftRepository,
ILogger<TableReport> logger)
internal class TableReport
{
_assemblyRepository = assemblyRepository ?? throw new ArgumentNullException(nameof(assemblyRepository));
_assemblerShiftRepository = assemblerShiftRepository ?? throw new ArgumentNullException(nameof(assemblerShiftRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
private readonly IAssemblerRepository _assemblerRepository;
private readonly IAssemblerShiftRepository _assemblerShiftRepository;
private readonly IAssemblyRepository _assemblyRepository;
private readonly ILogger<TableReport> _logger;
public bool CreateTable(string filePath, int assemblerId, DateTime startDate, DateTime endDate)
{
try
internal static readonly string[] Headers = { "Сборщик", "Стаж", "Разряд", "Кол-во сборок", "Собрано изделий", "Смены" };
public TableReport(IAssemblerRepository assemblerRepository,
IAssemblerShiftRepository assemblerShiftRepository,
ILogger<TableReport> logger,
IAssemblyRepository assemblyRepository)
{
var data = GetData(assemblerId, startDate, endDate);
new ExcelBuilder(filePath)
.AddHeader("Сводка по сборкам", 0, Headers.Length)
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
.AddTable(new[] { 15, 40, 20, 20 }, data)
.Build();
return true;
_assemblerRepository = assemblerRepository ?? throw new ArgumentNullException(nameof(assemblerRepository));
_assemblerShiftRepository = assemblerShiftRepository ?? throw new ArgumentNullException(nameof(assemblerShiftRepository));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_assemblyRepository = assemblyRepository ?? throw new ArgumentNullException(nameof(assemblyRepository));
}
catch (Exception ex)
public bool CreateTable(string filePath, int assemblerID, DateTime startDate, DateTime endDate)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
try
{
var data = GetData(assemblerID, startDate, endDate);
new ExcelBuilder(filePath)
.AddHeader("Сводка по сборкам", 0, Headers.Length)
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
.AddTable(new[] { 25, 15, 15, 20, 20, 20 }, data)
.Build();
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка при формировании документа");
return false;
}
}
}
private List<string[]> GetData(int assemblerId, DateTime startDate, DateTime endDate)
private List<string[]> GetData(int assemblerID, DateTime startDate, DateTime endDate)
{
var assembler = _assemblerRepository.ReadAssemblers().FirstOrDefault(a => a.ID == assemblerID);
if (assembler == null)
throw new Exception($"Сборщик с ID {assemblerID} не найден.");
var shiftData = _assemblerShiftRepository
.ReadAssemblerShifts()
.Where(x => x.AssemblerShiftDate >= startDate && x.AssemblerShiftDate <= endDate && x.AssemblerID_Assembler == assemblerID)
.OrderBy(x => x.AssemblerShiftDate)
.ToList();
var result = new List<string[]>
{
// Данные о сборках
var assemblyData = _assemblyRepository
.ReadAssemblies()
.Where(x => x.AssemblyDate >= startDate && x.AssemblyDate <= endDate && x.AssemblerID_Assembler == assemblerId)
.Select(x => new
Headers
};
int totalAssemblies = 0;
int totalProducts = 0;
foreach (var shift in shiftData)
{
Date = x.AssemblyDate,
Description = $"Сборка ID {x.ID}",
CountAssemblies = x.Count.ToString("N0"),
WorkHours = "-"
});
var assemblyDataForDay = _assemblyRepository
.ReadAssemblies()
.Where(x => x.AssemblyDate.Date == shift.AssemblerShiftDate.Date && x.AssemblerID_Assembler == assemblerID)
.ToList();
// Данные о сменах
var shiftData = _assemblerShiftRepository
.ReadAssemblerShifts()
.Where(x => x.AssemblerShiftDate >= startDate && x.AssemblerShiftDate <= endDate && x.AssemblerID_Assembler == assemblerId)
.Select(x => new
int totalAssembliesForDay = assemblyDataForDay.Count();
int totalProductsForDay = assemblyDataForDay.Sum(x => x.Count);
result.Add(new[]
{
assembler.FullName,
assembler.WorkExperience.ToString("F"),
assembler.AssemblerRank.ToString("G"),
totalAssembliesForDay.ToString("N0"),
totalProductsForDay.ToString("N0"),
shift.AssemblerShiftDate.ToString("dd.MM.yyyy")
});
totalAssemblies += totalAssembliesForDay;
totalProducts += totalProductsForDay;
}
if (!shiftData.Any())
{
Date = x.AssemblerShiftDate,
Description = $"Смена ID {x.ShiftID_Shift}",
CountAssemblies = "-",
WorkHours = x.WorkHours.ToString("N0")
});
result.Add(new[]
{
assembler.FullName,
assembler.WorkExperience.ToString("F"),
assembler.AssemblerRank.ToString("G"),
"0",
"0",
"Нет смен"
});
}
// Объединение и сортировка
var combinedData = assemblyData
.Union(shiftData)
.OrderBy(x => x.Date);
// Итоговые данные
var totalAssemblies = assemblyData.Sum(x => int.TryParse(x.CountAssemblies, out var count) ? count : 0);
var totalWorkHours = shiftData.Sum(x => int.TryParse(x.WorkHours, out var hours) ? hours : 0);
// Формирование таблицы
return new List<string[]> { Headers }
.Union(combinedData.Select(x => new[]
result.Add(new[]
{
x.Date.ToString("dd.MM.yyyy"),
x.Description,
x.CountAssemblies,
x.WorkHours
}))
.Union(new List<string[]> { new[] { "Всего", "", totalAssemblies.ToString("N0"), totalWorkHours.ToString("N0") } })
.ToList();
"ИТОГО",
"",
"",
totalAssemblies.ToString("N0"),
totalProducts.ToString("N0"),
""
});
return result;
}
}
}

View File

@ -28,8 +28,8 @@ public class AssemblerShiftRepository : IAssemblerShiftRepository
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var queryInsert = @"
INSERT INTO AssemblerShift (WorkHours, AssemblerID_Assembler, ShiftID_Shift)
VALUES (@WorkHours, @AssemblerID_Assembler, @ShiftID_Shift)";
INSERT INTO AssemblerShift (WorkHours, AssemblerID_Assembler, ShiftID_Shift, AssemblerShiftDate)
VALUES (@WorkHours, @AssemblerID_Assembler, @ShiftID_Shift, @AssemblerShiftDate)";
connection.Execute(queryInsert, assemblerShift);
}
catch (Exception ex)

View File

@ -32,7 +32,6 @@ public class AssemblyRepository : IAssemblyRepository
connection.Open();
using var transaction = connection.BeginTransaction();
// Добавляем дату сборки в запрос
var queryInsert = @"
INSERT INTO Assembly (Count, AssemblerID_Assembler, AssemblyDate)
VALUES (@Count, @AssemblerID_Assembler, @AssemblyDate)
@ -41,7 +40,7 @@ public class AssemblyRepository : IAssemblyRepository
{
assembly.Count,
assembly.AssemblerID_Assembler,
assembly.AssemblyDate // Передаём дату сборки
assembly.AssemblyDate
}, transaction);
var querySubInsert = @"
@ -93,16 +92,10 @@ public class AssemblyRepository : IAssemblyRepository
try
{
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT fr.*, ffr.AssemblyID_Assembly, ffr.Count, a.AssemblyDate
FROM ProductAssembly fr
INNER JOIN ProductAssembly ffr ON ffr.AssemblyID_Assembly = fr.Id
INNER JOIN Assembly a ON fr.AssemblyID_Assembly = a.ID";
var assemblies = connection.Query<TempProductAssembly>(querySelect);
_logger.LogDebug("Полученные объекты: {json}",
JsonConvert.SerializeObject(assemblies));
return assemblies.GroupBy(x => x.ID, y => y, (key, value) => Assembly.CreateOperation(value.First(), value.Select(
z => ProductAssembly.CreateElement(0, z.ProductID_Product, z.AssemblyID_Assembly, z.Count)))).ToList();
var selectQuery = @"SELECT * FROM Assembly";
var assemblies = connection.Query<Assembly>(selectQuery);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(assemblies));
return assemblies;
}
catch (Exception ex)
{
@ -110,4 +103,5 @@ INNER JOIN Assembly a ON fr.AssemblyID_Assembly = a.ID";
throw;
}
}
}