все сломалось,

This commit is contained in:
VictoriaPresnyakova 2023-04-17 23:38:44 +04:00
parent 11474146ab
commit 903e904a7a
23 changed files with 1060 additions and 120 deletions

167
JewelryStore/FormImplementer.Designer.cs generated Normal file
View File

@ -0,0 +1,167 @@
namespace JewelryStore
{
partial class FormImplementer
{
/// <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()
{
this.FIOTextBox = new System.Windows.Forms.TextBox();
this.PasswordTextBox = new System.Windows.Forms.TextBox();
this.LabelFIO = new System.Windows.Forms.Label();
this.LabelPassword = new System.Windows.Forms.Label();
this.QualificationNumericUpDown = new System.Windows.Forms.NumericUpDown();
this.WorkExpNumericUpDown = new System.Windows.Forms.NumericUpDown();
this.LabelWorkExperience = new System.Windows.Forms.Label();
this.LabelQualification = new System.Windows.Forms.Label();
this.ButtonCancel = new System.Windows.Forms.Button();
this.ButtonSave = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.QualificationNumericUpDown)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.WorkExpNumericUpDown)).BeginInit();
this.SuspendLayout();
//
// FIOTextBox
//
this.FIOTextBox.Location = new System.Drawing.Point(112, 12);
this.FIOTextBox.Name = "FIOTextBox";
this.FIOTextBox.Size = new System.Drawing.Size(170, 23);
this.FIOTextBox.TabIndex = 0;
//
// PasswordTextBox
//
this.PasswordTextBox.Location = new System.Drawing.Point(112, 49);
this.PasswordTextBox.Name = "PasswordTextBox";
this.PasswordTextBox.Size = new System.Drawing.Size(170, 23);
this.PasswordTextBox.TabIndex = 1;
//
// LabelFIO
//
this.LabelFIO.AutoSize = true;
this.LabelFIO.Location = new System.Drawing.Point(12, 15);
this.LabelFIO.Name = "LabelFIO";
this.LabelFIO.Size = new System.Drawing.Size(40, 15);
this.LabelFIO.TabIndex = 2;
this.LabelFIO.Text = "ФИО: ";
//
// LabelPassword
//
this.LabelPassword.AutoSize = true;
this.LabelPassword.Location = new System.Drawing.Point(12, 52);
this.LabelPassword.Name = "LabelPassword";
this.LabelPassword.Size = new System.Drawing.Size(55, 15);
this.LabelPassword.TabIndex = 3;
this.LabelPassword.Text = "Пароль: ";
//
// QualificationNumericUpDown
//
this.QualificationNumericUpDown.Location = new System.Drawing.Point(112, 131);
this.QualificationNumericUpDown.Name = "QualificationNumericUpDown";
this.QualificationNumericUpDown.Size = new System.Drawing.Size(170, 23);
this.QualificationNumericUpDown.TabIndex = 4;
//
// WorkExpNumericUpDown
//
this.WorkExpNumericUpDown.Location = new System.Drawing.Point(112, 90);
this.WorkExpNumericUpDown.Name = "WorkExpNumericUpDown";
this.WorkExpNumericUpDown.Size = new System.Drawing.Size(170, 23);
this.WorkExpNumericUpDown.TabIndex = 5;
//
// LabelWorkExperience
//
this.LabelWorkExperience.AutoSize = true;
this.LabelWorkExperience.Location = new System.Drawing.Point(12, 92);
this.LabelWorkExperience.Name = "LabelWorkExperience";
this.LabelWorkExperience.Size = new System.Drawing.Size(87, 15);
this.LabelWorkExperience.TabIndex = 6;
this.LabelWorkExperience.Text = "Опыт работы: ";
//
// LabelQualification
//
this.LabelQualification.AutoSize = true;
this.LabelQualification.Location = new System.Drawing.Point(12, 133);
this.LabelQualification.Name = "LabelQualification";
this.LabelQualification.Size = new System.Drawing.Size(94, 15);
this.LabelQualification.TabIndex = 7;
this.LabelQualification.Text = "Квалификация: ";
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(185, 169);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(97, 29);
this.ButtonCancel.TabIndex = 8;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(82, 169);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(97, 29);
this.ButtonSave.TabIndex = 9;
this.ButtonSave.Text = "Сохранить";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// FormImplementer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(306, 214);
this.Controls.Add(this.ButtonSave);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.LabelQualification);
this.Controls.Add(this.LabelWorkExperience);
this.Controls.Add(this.WorkExpNumericUpDown);
this.Controls.Add(this.QualificationNumericUpDown);
this.Controls.Add(this.LabelPassword);
this.Controls.Add(this.LabelFIO);
this.Controls.Add(this.PasswordTextBox);
this.Controls.Add(this.FIOTextBox);
this.Name = "FormImplementer";
this.Text = "Исполнитель";
this.Load += new System.EventHandler(this.FormImplementer_Load);
((System.ComponentModel.ISupportInitialize)(this.QualificationNumericUpDown)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.WorkExpNumericUpDown)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox FIOTextBox;
private TextBox PasswordTextBox;
private Label LabelFIO;
private Label LabelPassword;
private NumericUpDown QualificationNumericUpDown;
private NumericUpDown WorkExpNumericUpDown;
private Label LabelWorkExperience;
private Label LabelQualification;
private Button ButtonCancel;
private Button ButtonSave;
}
}

View File

@ -0,0 +1,107 @@
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.BusinessLogicsContracts;
using JewelryStoreContracts.SearchModels;
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 JewelryStore
{
public partial class FormImplementer : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormImplementer(ILogger<FormImplementer> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(PasswordTextBox.Text))
{
MessageBox.Show("Заполните пароль", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(FIOTextBox.Text))
{
MessageBox.Show("Заполните фио", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение исполнителя");
try
{
var model = new ImplementerBindingModel
{
Id = _id ?? 0,
ImplementerFIO = FIOTextBox.Text,
Password = PasswordTextBox.Text,
Qualification = (int)QualificationNumericUpDown.Value,
WorkExperience = (int)WorkExpNumericUpDown.Value,
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormImplementer_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение исполнителя");
var view = _logic.ReadElement(new ImplementerSearchModel
{
Id = _id.Value
});
if (view != null)
{
FIOTextBox.Text = view.ImplementerFIO;
PasswordTextBox.Text = view.Password;
QualificationNumericUpDown.Value = view.Qualification;
WorkExpNumericUpDown.Value = view.WorkExperience;
}
}
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>

114
JewelryStore/FormImplementers.Designer.cs generated Normal file
View File

@ -0,0 +1,114 @@
namespace JewelryStore
{
partial class FormImplementers
{
/// <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()
{
this.DataGridView = new System.Windows.Forms.DataGridView();
this.AddButton = new System.Windows.Forms.Button();
this.ChangeButton = new System.Windows.Forms.Button();
this.DeleteButton = new System.Windows.Forms.Button();
this.UpdateButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
this.SuspendLayout();
//
// DataGridView
//
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.DataGridView.Location = new System.Drawing.Point(1, 1);
this.DataGridView.Name = "DataGridView";
this.DataGridView.RowTemplate.Height = 25;
this.DataGridView.Size = new System.Drawing.Size(632, 448);
this.DataGridView.TabIndex = 0;
//
// AddButton
//
this.AddButton.Location = new System.Drawing.Point(639, 12);
this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(98, 45);
this.AddButton.TabIndex = 1;
this.AddButton.Text = "Добавить";
this.AddButton.UseVisualStyleBackColor = true;
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
//
// ChangeButton
//
this.ChangeButton.Location = new System.Drawing.Point(639, 63);
this.ChangeButton.Name = "ChangeButton";
this.ChangeButton.Size = new System.Drawing.Size(98, 45);
this.ChangeButton.TabIndex = 2;
this.ChangeButton.Text = "Изменить";
this.ChangeButton.UseVisualStyleBackColor = true;
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
//
// DeleteButton
//
this.DeleteButton.Location = new System.Drawing.Point(639, 114);
this.DeleteButton.Name = "DeleteButton";
this.DeleteButton.Size = new System.Drawing.Size(98, 45);
this.DeleteButton.TabIndex = 3;
this.DeleteButton.Text = "Удалить";
this.DeleteButton.UseVisualStyleBackColor = true;
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
//
// UpdateButton
//
this.UpdateButton.Location = new System.Drawing.Point(639, 165);
this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(98, 45);
this.UpdateButton.TabIndex = 4;
this.UpdateButton.Text = "Обновить";
this.UpdateButton.UseVisualStyleBackColor = true;
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
//
// FormImplementers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(749, 450);
this.Controls.Add(this.UpdateButton);
this.Controls.Add(this.DeleteButton);
this.Controls.Add(this.ChangeButton);
this.Controls.Add(this.AddButton);
this.Controls.Add(this.DataGridView);
this.Name = "FormImplementers";
this.Text = "Исполнители";
this.Load += new System.EventHandler(this.FormImplementers_Load);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView DataGridView;
private Button AddButton;
private Button ChangeButton;
private Button DeleteButton;
private Button UpdateButton;
}
}

View File

@ -0,0 +1,120 @@
using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.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 JewelryStore
{
public partial class FormImplementers : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
public FormImplementers(ILogger<FormImplementers> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void AddButton_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ChangeButton_Click(object sender, EventArgs e)
{
if (DataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void DeleteButton_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 ImplementerBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void UpdateButton_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormImplementers_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["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка исполнителей");
}
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>

View File

@ -39,6 +39,7 @@
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокКомпонентовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -50,11 +51,11 @@
// //
// buttonReady // buttonReady
// //
this.buttonReady.Location = new System.Drawing.Point(1273, 225); this.buttonReady.Location = new System.Drawing.Point(1273, 298);
this.buttonReady.Name = "buttonReady"; this.buttonReady.Name = "buttonReady";
this.buttonReady.Size = new System.Drawing.Size(215, 34); this.buttonReady.Size = new System.Drawing.Size(215, 34);
this.buttonReady.TabIndex = 3; this.buttonReady.TabIndex = 3;
this.buttonReady.Text = "Заказ готов"; this.buttonReady.Text = "Заказ выдан";
this.buttonReady.UseVisualStyleBackColor = true; this.buttonReady.UseVisualStyleBackColor = true;
this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click);
// //
@ -90,11 +91,11 @@
// //
// buttonPut // buttonPut
// //
this.buttonPut.Location = new System.Drawing.Point(1273, 308); this.buttonPut.Location = new System.Drawing.Point(1273, 218);
this.buttonPut.Name = "buttonPut"; this.buttonPut.Name = "buttonPut";
this.buttonPut.Size = new System.Drawing.Size(215, 34); this.buttonPut.Size = new System.Drawing.Size(215, 34);
this.buttonPut.TabIndex = 4; this.buttonPut.TabIndex = 4;
this.buttonPut.Text = "Заказ выдан"; this.buttonPut.Text = "Заказ готов";
this.buttonPut.UseVisualStyleBackColor = true; this.buttonPut.UseVisualStyleBackColor = true;
this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click); this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click);
// //
@ -126,7 +127,8 @@
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem, this.компонентыToolStripMenuItem,
this.изделияToolStripMenuItem, this.изделияToolStripMenuItem,
this.клиентыToolStripMenuItem}); this.клиентыToolStripMenuItem,
this.исполнителиToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
this.справочникиToolStripMenuItem.Text = "Справочники"; this.справочникиToolStripMenuItem.Text = "Справочники";
@ -152,6 +154,13 @@
this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Text = "Клиенты";
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click);
// //
// исполнителиToolStripMenuItem
//
this.исполнителиToolStripMenuItem.Name = сполнителиToolStripMenuItem";
this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(240, 34);
this.исполнителиToolStripMenuItem.Text = "Исполнители";
this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click);
//
// отчетыToolStripMenuItem // отчетыToolStripMenuItem
// //
this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -232,5 +241,6 @@
private ToolStripMenuItem списокЗаказзовToolStripMenuItem; private ToolStripMenuItem списокЗаказзовToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem;
private ToolStripMenuItem запускРаботToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem;
private ToolStripMenuItem исполнителиToolStripMenuItem;
} }
} }

View File

@ -48,7 +48,7 @@ namespace JewelryStore
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["JewelId"].Visible = false; dataGridView.Columns["JewelId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
} }
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
@ -100,14 +100,14 @@ namespace JewelryStore
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{ {
Id = id, Id = id,
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value),
//ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value),
JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), //Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), //DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
@ -136,13 +136,14 @@ namespace JewelryStore
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{ {
Id = id, Id = id,
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value),
JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), //Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
//DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
@ -171,13 +172,14 @@ namespace JewelryStore
OrderBindingModel OrderBindingModel
{ {
Id = id, Id = id,
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), //JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), //ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value),
JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), //ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), //JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), //Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), //Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), //Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
//DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
@ -250,5 +252,15 @@ namespace JewelryStore
MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
} }
private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
}
} }
} }

View File

@ -42,8 +42,11 @@ namespace JewelryStore
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IJewelStorage, JewelStorage>(); services.AddTransient<IJewelStorage, JewelStorage>();
services.AddTransient<IClientStorage, ClientStorage>(); services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IJewelLogic, JewelLogic>(); services.AddTransient<IJewelLogic, JewelLogic>();
@ -65,7 +68,8 @@ namespace JewelryStore
services.AddTransient<FormReportJewelComponents>(); services.AddTransient<FormReportJewelComponents>();
services.AddTransient<FormReportOrders>(); services.AddTransient<FormReportOrders>();
services.AddTransient<FormClients>(); services.AddTransient<FormClients>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormImplementers>();
} }
} }

15
JewelryStore/nlog.config Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="tofile" />
</rules>
</nlog>
</configuration>

View File

@ -15,13 +15,9 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
{ {
public class OrderLogic : IOrderLogic //TODO реализовать интерфейс public class OrderLogic : IOrderLogic //TODO реализовать интерфейс
{ {
// Класс с логикой для заказов будет отвечать за получение списка заказов,
//создания заказа и смены его статусов.Следует учитывать, что у заказа можно
//менять статус на новый, если его текущий статус предшествует новому
//(например, в статус «Готов» можно переводить, если заказ находится в статусе
//«Выполняется»).
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{ {
_logger = logger; _logger = logger;
@ -31,100 +27,140 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
if (model.Status != OrderStatus.Неизвестен)
{
_logger.LogWarning("Insert operation failed. Order status incorrect.");
return false;
}
model.Status = OrderStatus.Принят; model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null) if (_orderStorage.Insert(model) == null)
{ {
model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
return true; return true;
} }
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{
var vmodel = _orderStorage.GetElement(new() { Id = model.Id });
if (vmodel == null)
{
throw new ArgumentNullException(nameof(model));
}
if ((int)vmodel.Status + 1 != (int)newStatus)
{
throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " +
$"Текущий статус: {vmodel.Status} \n" +
$"Планируемый статус: {newStatus} \n" +
$"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}");
}
model.Status = newStatus;
model.DateCreate = vmodel.DateCreate;
if (model.DateImplement == null)
model.DateImplement = vmodel.DateImplement;
if (vmodel.ImplementerId.HasValue)
model.ImplementerId = vmodel.ImplementerId;
model.JewelId = vmodel.JewelId;
model.Sum = vmodel.Sum;
model.Count = vmodel.Count;
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public bool DeliveryOrder(OrderBindingModel model) public bool DeliveryOrder(OrderBindingModel model)
{ {
CheckModel(model);
if (model.Status != OrderStatus.Готов) return false;
model.Status = OrderStatus.Выдан;
model.DateImplement = DateTime.Now; model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null) return StatusUpdate(model, OrderStatus.Готов);
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
} }
public bool FinishOrder(OrderBindingModel model) public bool FinishOrder(OrderBindingModel model)
{ {
CheckModel(model); return StatusUpdate(model, OrderStatus.Выдан);
if (model.Status != OrderStatus.Выполняется) return false;
model.Status = OrderStatus.Готов;
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
} }
public List<OrderViewModel>? ReadList(OrderSearchModel? model) public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{ {
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); _logger.LogInformation("Order. OrderId:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
_logger.LogWarning("ReadList return null list"); _logger.LogWarning("ReadList return null list");
return null; return null;
} }
_logger.LogInformation("ReadList. Count:{Count}", list.Count); _logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list; return list;
} }
public bool TakeOrderInWork(OrderBindingModel model) private bool CheckModel(OrderBindingModel model)
{ {
CheckModel(model); if (model == null)
if (model.Status != OrderStatus.Принят) return false;
model.Status = OrderStatus.Выполняется;
if (_orderStorage.Update(model) == null)
{ {
_logger.LogWarning("Update operation failed"); throw new ArgumentNullException(nameof(model));
return false;
} }
if (model.Count <= 0)
{
throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
}
if (model.Sum <= 0)
{
throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum));
}
if (model.DateCreate > model.DateImplement)
{
throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement));
}
return true; return true;
} }
private void CheckModel(OrderBindingModel model, bool withParams = true) public OrderViewModel? ReadElement(OrderSearchModel model)
{ {
if (model == null) if (model == null)
{ {
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
if (!withParams) _logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _orderStorage.GetElement(model);
if (element == null)
{ {
return; _logger.LogWarning("ReadElement element not found");
return null;
} }
if (model.JewelId < 0) _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
{
throw new ArgumentNullException("Некорректный идентификатор драгоценности", nameof(model.JewelId));
}
if (model.Count <= 0) return element;
{
throw new ArgumentNullException("Количество драгоценностей в заказе должно быть больше 0", nameof(model.Count));
} }
if (model.Sum <= 0)
{
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
}
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. JewelId: { JewelId}", model.Id, model.Sum, model.JewelId);
}
} }
} }

View File

@ -2,6 +2,7 @@
using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.BusinessLogicsContracts;
using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.SearchModels;
using JewelryStoreContracts.ViewModels; using JewelryStoreContracts.ViewModels;
using JewelryStoreDataModels.Enums;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -34,31 +35,29 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
_logger.LogWarning("DoWork. Implementers is null"); _logger.LogWarning("DoWork. Implementers is null");
return; return;
} }
var orders = _orderLogic.ReadList(new OrderSearchModel { /*Status = OrderStatus.Принят*/ });
var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } });
if (orders == null || orders.Count == 0) if (orders == null || orders.Count == 0)
{ {
_logger.LogWarning("DoWork. Orders is null or empty"); _logger.LogWarning("DoWork. Orders is null or empty");
return; return;
} }
_logger.LogDebug("DoWork for {Count} orders", orders.Count); _logger.LogDebug("DoWork for {Count} orders", orders.Count);
foreach (var implementer in implementers) foreach (var implementer in implementers)
{ {
Task.Run(() => WorkerWorkAsync(implementer, orders)); Task.Run(() => WorkerWorkAsync(implementer, orders));
} }
} }
/// <summary>
/// Иммитация работы исполнителя
/// </summary>
/// <param name="implementer"></param>
/// <param name="orders"></param>
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders) private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
{ {
if (_orderLogic == null || implementer == null) if (_orderLogic == null || implementer == null)
{ {
return; return;
} }
await RunOrderInWork(implementer); await RunOrderInWork(implementer, orders);
await Task.Run(() => await Task.Run(() =>
{ {
@ -67,77 +66,69 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
try try
{ {
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
// пытаемся назначить заказ на исполнителя
_orderLogic.TakeOrderInWork(new OrderBindingModel _orderLogic.TakeOrderInWork(new OrderBindingModel
{ {
Id = order.Id, Id = order.Id,
// ImplementerId = implementer.Id ImplementerId = implementer.Id
}); });
// делаем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.FinishOrder(new OrderBindingModel
_orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = order.Id Id = order.Id
}); });
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
} }
// кто-то мог уже перехватить заказ, игнорируем ошибку
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
_logger.LogWarning(ex, "Error try get work"); _logger.LogWarning(ex, "Error try get work");
} }
// заканчиваем выполнение имитации в случае иной ошибки
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error while do work"); _logger.LogError(ex, "Error while do work");
throw; throw;
} }
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
} }
}); });
} }
/// <summary> private async Task RunOrderInWork(ImplementerViewModel implementer, List<OrderViewModel> allOrders)
/// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
/// </summary>
/// <param name="implementer"></param>
/// <returns></returns>
private async Task RunOrderInWork(ImplementerViewModel implementer)
{ {
if (_orderLogic == null || implementer == null) if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0)
{ {
return; return;
} }
try try
{ {
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется));
{
// ImplementerId = implementer.Id,
// Status = OrderStatus.Выполняется
}));
if (runOrder == null) if (runOrder == null)
{ {
return; return;
} }
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
// доделываем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
_orderLogic.FinishOrder(new OrderBindingModel _orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = runOrder.Id Id = runOrder.Id
}); });
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
} }
// заказа может не быть, просто игнорируем ошибку
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
_logger.LogWarning(ex, "Error try get work"); _logger.LogWarning(ex, "Error try get work");
} }
// а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error while do work"); _logger.LogError(ex, "Error while do work");

View File

@ -12,6 +12,8 @@ namespace JewelryStoreContracts.BusinessLogicsContracts
public interface IOrderLogic public interface IOrderLogic
{ {
List<OrderViewModel>? ReadList(OrderSearchModel? model); List<OrderViewModel>? ReadList(OrderSearchModel? model);
OrderViewModel? ReadElement(OrderSearchModel model);
bool CreateOrder(OrderBindingModel model); bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model); bool FinishOrder(OrderBindingModel model);

View File

@ -12,7 +12,7 @@ namespace JewelryStoreDataModels.Models
{ {
int JewelId { get; } int JewelId { get; }
string JewelName { get; } string JewelName { get; }
int? ImplementerId { get; }
int ClientId { get; } int ClientId { get; }
int Count { get; } int Count { get; }
double Sum { get; } double Sum { get; }

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace JewelryStoreDatabaseImplement.Migrations namespace JewelryStoreDatabaseImplement.Migrations
{ {
[DbContext(typeof(JewelryStoreDataBase))] [DbContext(typeof(JewelryStoreDataBase))]
[Migration("20230403133347_InitialCreate")] [Migration("20230417191656_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -70,6 +70,33 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.ToTable("Components"); b.ToTable("Components");
}); });
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Qualification")
.HasColumnType("int");
b.Property<int>("WorkExperience")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -136,6 +163,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("JewelId") b.Property<int>("JewelId")
.HasColumnType("int"); .HasColumnType("int");
@ -153,6 +183,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasIndex("ClientId"); b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("JewelId"); b.HasIndex("JewelId");
b.ToTable("Orders"); b.ToTable("Orders");
@ -185,6 +217,10 @@ namespace JewelryStoreDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("JewelId") .HasForeignKey("JewelId")
@ -193,6 +229,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Jewel"); b.Navigation("Jewel");
}); });
@ -206,6 +244,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("JewelComponents"); b.Navigation("JewelComponents");
}); });
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
{ {
b.Navigation("Components"); b.Navigation("Components");

View File

@ -40,6 +40,22 @@ namespace JewelryStoreDatabaseImplement.Migrations
table.PrimaryKey("PK_Components", x => x.Id); table.PrimaryKey("PK_Components", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "Implementers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
WorkExperience = table.Column<int>(type: "int", nullable: false),
Qualification = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Implementers", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Jewels", name: "Jewels",
columns: table => new columns: table => new
@ -89,6 +105,7 @@ namespace JewelryStoreDatabaseImplement.Migrations
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
JewelId = table.Column<int>(type: "int", nullable: false), JewelId = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false), ClientId = table.Column<int>(type: "int", nullable: false),
ImplementerId = table.Column<int>(type: "int", nullable: true),
JewelName = table.Column<string>(type: "nvarchar(max)", nullable: false), JewelName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Count = table.Column<int>(type: "int", nullable: false), Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false), Sum = table.Column<double>(type: "float", nullable: false),
@ -105,6 +122,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
principalTable: "Clients", principalTable: "Clients",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Implementers_ImplementerId",
column: x => x.ImplementerId,
principalTable: "Implementers",
principalColumn: "Id");
table.ForeignKey( table.ForeignKey(
name: "FK_Orders_Jewels_JewelId", name: "FK_Orders_Jewels_JewelId",
column: x => x.JewelId, column: x => x.JewelId,
@ -128,6 +150,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
table: "Orders", table: "Orders",
column: "ClientId"); column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ImplementerId",
table: "Orders",
column: "ImplementerId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Orders_JewelId", name: "IX_Orders_JewelId",
table: "Orders", table: "Orders",
@ -149,6 +176,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Clients"); name: "Clients");
migrationBuilder.DropTable(
name: "Implementers");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Jewels"); name: "Jewels");
} }

View File

@ -67,6 +67,33 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.ToTable("Components"); b.ToTable("Components");
}); });
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Qualification")
.HasColumnType("int");
b.Property<int>("WorkExperience")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -133,6 +160,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("JewelId") b.Property<int>("JewelId")
.HasColumnType("int"); .HasColumnType("int");
@ -150,6 +180,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasIndex("ClientId"); b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("JewelId"); b.HasIndex("JewelId");
b.ToTable("Orders"); b.ToTable("Orders");
@ -182,6 +214,10 @@ namespace JewelryStoreDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel") b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("JewelId") .HasForeignKey("JewelId")
@ -190,6 +226,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Jewel"); b.Navigation("Jewel");
}); });
@ -203,6 +241,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("JewelComponents"); b.Navigation("JewelComponents");
}); });
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b => modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
{ {
b.Navigation("Components"); b.Navigation("Components");

View File

@ -78,6 +78,8 @@ namespace JewelryStoreDatabaseImplement.Models
Status = model.Status; Status = model.Status;
DateCreate = model.DateCreate; DateCreate = model.DateCreate;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
} }
public OrderViewModel GetViewModel public OrderViewModel GetViewModel

View File

@ -18,6 +18,7 @@ namespace JewelryStoreFileImplement.Models
public int ClientId { get; private set; } public int ClientId { get; private set; }
public string JewelName { get; private set; } = string.Empty; public string JewelName { get; private set; } = string.Empty;
public int? ImplementerId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }

View File

@ -128,4 +128,4 @@ namespace JewelryStoreListImplement.Implements
} }
} }
} }
}

View File

@ -15,6 +15,8 @@ namespace JewelryStoreListImplement.Models
public int JewelId { get; private set; } public int JewelId { get; private set; }
public string JewelName { get; private set; } public string JewelName { get; private set; }
public int ClientId { get; private set; } public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
@ -71,5 +73,6 @@ namespace JewelryStoreListImplement.Models
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement DateImplement = DateImplement
}; };
} }
} }

View File

@ -65,7 +65,7 @@ namespace JewelryStoreRestApi.Controllers
{ {
return _order.ReadElement(new OrderSearchModel return _order.ReadElement(new OrderSearchModel
{ {
//ImplementerId = implementerId ImplementerId = implementerId
}); });
} }
catch (Exception ex) catch (Exception ex)