lab-4 add FormReportManufactureComponents

This commit is contained in:
Zakharov_Rostislav 2024-03-27 13:15:50 +04:00
parent adac6bc64d
commit b0584bb0f5
5 changed files with 345 additions and 1 deletions

View File

@ -27,6 +27,7 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog" Version="5.2.8" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.19" />
</ItemGroup>
</Project>

View File

@ -38,13 +38,17 @@
buttonIssued = new Button();
buttonReady = new Button();
buttonTakeInWork = new Button();
ReportsToolStripMenuItem = new ToolStripMenuItem();
ComponentsListToolStripMenuItem = new ToolStripMenuItem();
ManufacturesListToolStripMenuItem = new ToolStripMenuItem();
OrdersListToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip
//
menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem });
menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem, ReportsToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1011, 24);
@ -131,6 +135,31 @@
buttonTakeInWork.UseVisualStyleBackColor = true;
buttonTakeInWork.Click += TakeInWorkButton_Click;
//
// ReportsToolStripMenuItem
//
ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsListToolStripMenuItem, ManufacturesListToolStripMenuItem, OrdersListToolStripMenuItem });
ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem";
ReportsToolStripMenuItem.Size = new Size(60, 20);
ReportsToolStripMenuItem.Text = "Отчёты";
//
// ComponentsListToolStripMenuItem
//
ComponentsListToolStripMenuItem.Name = "ComponentsListToolStripMenuItem";
ComponentsListToolStripMenuItem.Size = new Size(218, 22);
ComponentsListToolStripMenuItem.Text = "Список компонентов";
//
// ManufacturesListToolStripMenuItem
//
ManufacturesListToolStripMenuItem.Name = "ManufacturesListToolStripMenuItem";
ManufacturesListToolStripMenuItem.Size = new Size(218, 22);
ManufacturesListToolStripMenuItem.Text = "Компоненты по изделиям";
//
// OrdersListToolStripMenuItem
//
OrdersListToolStripMenuItem.Name = "OrdersListToolStripMenuItem";
OrdersListToolStripMenuItem.Size = new Size(218, 22);
OrdersListToolStripMenuItem.Text = "Список заказов";
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -167,5 +196,9 @@
private Button buttonIssued;
private Button buttonReady;
private Button buttonTakeInWork;
private ToolStripMenuItem ReportsToolStripMenuItem;
private ToolStripMenuItem ComponentsListToolStripMenuItem;
private ToolStripMenuItem ManufacturesListToolStripMenuItem;
private ToolStripMenuItem OrdersListToolStripMenuItem;
}
}

View File

@ -0,0 +1,106 @@
namespace BlacksmithWorkshop
{
partial class FormReportManufactureComponents
{
/// <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()
{
dataGridView = new DataGridView();
SaveButton = new Button();
ComponentColumn = new DataGridViewTextBoxColumn();
ManufactureColumn = new DataGridViewTextBoxColumn();
CountColumn = new DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ComponentColumn, ManufactureColumn, CountColumn });
dataGridView.Location = new Point(14, 61);
dataGridView.Margin = new Padding(3, 4, 3, 4);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(651, 523);
dataGridView.TabIndex = 0;
//
// SaveButton
//
SaveButton.Location = new Point(14, 23);
SaveButton.Margin = new Padding(3, 4, 3, 4);
SaveButton.Name = "SaveButton";
SaveButton.Size = new Size(193, 31);
SaveButton.TabIndex = 1;
SaveButton.Text = "Сохранить в Excel";
SaveButton.UseVisualStyleBackColor = true;
SaveButton.Click += SaveButton_Click;
//
// ComponentColumn
//
ComponentColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
ComponentColumn.HeaderText = "Компьютер";
ComponentColumn.MinimumWidth = 6;
ComponentColumn.Name = "ComponentColumn";
//
// ManufactureColumn
//
ManufactureColumn.HeaderText = "Компонент";
ManufactureColumn.MinimumWidth = 6;
ManufactureColumn.Name = "ManufactureColumn";
ManufactureColumn.Width = 200;
//
// CountColumn
//
CountColumn.HeaderText = "Количество";
CountColumn.MinimumWidth = 6;
CountColumn.Name = "CountColumn";
CountColumn.Width = 130;
//
// FormReportManufactureComponents
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(679, 600);
Controls.Add(SaveButton);
Controls.Add(dataGridView);
Margin = new Padding(3, 4, 3, 4);
Name = "FormReportManufactureComponents";
Text = "Компоненты по компьютерам";
Load += ReportManufactureComponentForm_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button SaveButton;
private DataGridViewTextBoxColumn ComponentColumn;
private DataGridViewTextBoxColumn ManufactureColumn;
private DataGridViewTextBoxColumn CountColumn;
}
}

View File

@ -0,0 +1,84 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
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;
namespace BlacksmithWorkshop
{
public partial class FormReportManufactureComponents : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportManufactureComponents(
ILogger<FormReportManufactureComponents> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ReportManufactureComponentForm_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetManufactureComponent();
if (dict != null)
{
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.ManufactureName, "", "" });
foreach (var listElem in elem.Components)
{
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
}
dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount });
dataGridView.Rows.Add(Array.Empty<object>());
}
}
_logger.LogInformation("Загрузка списка компьютеров по компонентам");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка компьютеров по компонентам");
MessageBox.Show(
ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void SaveButton_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveManufactureComponentToExcelFile(
new ReportBindingModel
{
FileName = dialog.FileName
});
_logger.LogInformation("Сохранение списка компьютеров по компонентам");
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(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>