Все реализовано, но есть баг: не сохраняются изделия и компоненты

This commit is contained in:
Никита Потапов 2024-02-26 00:26:47 +04:00
parent ea0854e950
commit a204cc5e69
6 changed files with 364 additions and 21 deletions

View File

@ -38,8 +38,8 @@
//
// dataGridViewComponents
//
dataGridViewComponents.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewComponents.Dock = DockStyle.Left;
dataGridViewComponents.Location = new Point(0, 0);
dataGridViewComponents.MultiSelect = false;
dataGridViewComponents.Name = "dataGridViewComponents";
@ -48,12 +48,13 @@
dataGridViewComponents.RowHeadersWidth = 51;
dataGridViewComponents.RowTemplate.Height = 29;
dataGridViewComponents.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewComponents.Size = new Size(539, 450);
dataGridViewComponents.Size = new Size(637, 450);
dataGridViewComponents.TabIndex = 0;
//
// buttonAddComponent
//
buttonAddComponent.Location = new Point(562, 23);
buttonAddComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonAddComponent.Location = new Point(660, 23);
buttonAddComponent.Name = "buttonAddComponent";
buttonAddComponent.Size = new Size(94, 29);
buttonAddComponent.TabIndex = 1;
@ -63,7 +64,8 @@
//
// buttonEditComponent
//
buttonEditComponent.Location = new Point(562, 75);
buttonEditComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonEditComponent.Location = new Point(660, 75);
buttonEditComponent.Name = "buttonEditComponent";
buttonEditComponent.Size = new Size(94, 29);
buttonEditComponent.TabIndex = 2;
@ -73,7 +75,8 @@
//
// buttonDeleteComponent
//
buttonDeleteComponent.Location = new Point(562, 125);
buttonDeleteComponent.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonDeleteComponent.Location = new Point(660, 125);
buttonDeleteComponent.Name = "buttonDeleteComponent";
buttonDeleteComponent.Size = new Size(94, 29);
buttonDeleteComponent.TabIndex = 3;
@ -83,7 +86,8 @@
//
// buttonRefreshComponents
//
buttonRefreshComponents.Location = new Point(562, 173);
buttonRefreshComponents.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRefreshComponents.Location = new Point(660, 173);
buttonRefreshComponents.Name = "buttonRefreshComponents";
buttonRefreshComponents.Size = new Size(94, 29);
buttonRefreshComponents.TabIndex = 4;
@ -95,7 +99,7 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(684, 450);
ClientSize = new Size(775, 450);
Controls.Add(buttonRefreshComponents);
Controls.Add(buttonDeleteComponent);
Controls.Add(buttonEditComponent);

View File

@ -30,8 +30,8 @@
{
menuStrip = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
изделияToolStripMenuItem = new ToolStripMenuItem();
ComponentsToolStripMenuItem = new ToolStripMenuItem();
SecuresToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
@ -54,22 +54,24 @@
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem });
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, SecuresToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(117, 24);
справочникиToolStripMenuItem.Text = "Справочники";
//
// компонентыToolStripMenuItem
// ComponentsToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(182, 26);
компонентыToolStripMenuItem.Text = "Компоненты";
ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
ComponentsToolStripMenuItem.Size = new Size(224, 26);
ComponentsToolStripMenuItem.Text = "Компоненты";
ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
//
// изделияToolStripMenuItem
// SecuresToolStripMenuItem
//
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
изделияToolStripMenuItem.Size = new Size(182, 26);
изделияToolStripMenuItem.Text = "Изделия";
SecuresToolStripMenuItem.Name = "SecuresToolStripMenuItem";
SecuresToolStripMenuItem.Size = new Size(224, 26);
SecuresToolStripMenuItem.Text = "Изделия";
SecuresToolStripMenuItem.Click += SecuresToolStripMenuItem_Click;
//
// dataGridView
//
@ -163,8 +165,8 @@
private MenuStrip menuStrip;
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделияToolStripMenuItem;
private ToolStripMenuItem ComponentsToolStripMenuItem;
private ToolStripMenuItem SecuresToolStripMenuItem;
private DataGridView dataGridView;
private Button buttonCreateOrder;
private Button buttonTakeOrderInWork;

View File

@ -0,0 +1,120 @@
namespace SecuritySystemView
{
partial class FormSecures
{
/// <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();
buttonRefresh = new Button();
buttonDelete = new Button();
buttonEdit = new Button();
buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(3, 3);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(705, 296);
dataGridView.TabIndex = 0;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRefresh.Location = new Point(739, 162);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(94, 29);
buttonRefresh.TabIndex = 8;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefreshSecures_Click;
//
// buttonDelete
//
buttonDelete.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonDelete.Location = new Point(739, 114);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(94, 29);
buttonDelete.TabIndex = 7;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += ButtonDeleteSecure_Click;
//
// buttonEdit
//
buttonEdit.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonEdit.Location = new Point(739, 64);
buttonEdit.Name = "buttonEdit";
buttonEdit.Size = new Size(94, 29);
buttonEdit.TabIndex = 6;
buttonEdit.Text = "Изменить";
buttonEdit.UseVisualStyleBackColor = true;
buttonEdit.Click += ButtonEditSecure_Click;
//
// buttonAdd
//
buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonAdd.Location = new Point(739, 12);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(94, 29);
buttonAdd.TabIndex = 5;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAddSecure_Click;
//
// FormSecures
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(853, 311);
Controls.Add(buttonRefresh);
Controls.Add(buttonDelete);
Controls.Add(buttonEdit);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "FormSecures";
Text = "Иделия";
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonRefresh;
private Button buttonDelete;
private Button buttonEdit;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,97 @@
using Microsoft.Extensions.Logging;
using SecuritySystemContracts.BindingModels;
using SecuritySystemContracts.BusinessLogicsContracts;
namespace SecuritySystemView
{
public partial class FormSecures : Form
{
private readonly ILogger _logger;
private readonly ISecureLogic _logic;
public FormSecures(ILogger<FormSecures> logger, ISecureLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormSecures_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SecureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка изделий");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAddSecure_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSecure));
if (service is FormSecure form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonEditSecure_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSecure));
if (service is FormSecure form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDeleteSecure_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление изделия");
try
{
if (!_logic.Delete(new SecureBindingModel { Id = id }))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления изделия");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRefreshSecures_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

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

@ -45,7 +45,7 @@ namespace SecuritySystemView
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormSecure>();
services.AddTransient<FormSecureComponent>();
//services.AddTransient<FormSecures>();
services.AddTransient<FormSecures>();
}
}
}