diff --git a/JewelryStore/FormImplementer.Designer.cs b/JewelryStore/FormImplementer.Designer.cs
new file mode 100644
index 0000000..e29f282
--- /dev/null
+++ b/JewelryStore/FormImplementer.Designer.cs
@@ -0,0 +1,167 @@
+namespace JewelryStore
+{
+ partial class FormImplementer
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/JewelryStore/FormImplementer.cs b/JewelryStore/FormImplementer.cs
new file mode 100644
index 0000000..241fcfa
--- /dev/null
+++ b/JewelryStore/FormImplementer.cs
@@ -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 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);
+ }
+ }
+ }
+ }
+}
+
diff --git a/JewelryStore/FormImplementer.resx b/JewelryStore/FormImplementer.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/JewelryStore/FormImplementer.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/JewelryStore/FormImplementers.Designer.cs b/JewelryStore/FormImplementers.Designer.cs
new file mode 100644
index 0000000..cf210bf
--- /dev/null
+++ b/JewelryStore/FormImplementers.Designer.cs
@@ -0,0 +1,114 @@
+namespace JewelryStore
+{
+ partial class FormImplementers
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/JewelryStore/FormImplementers.cs b/JewelryStore/FormImplementers.cs
new file mode 100644
index 0000000..22fa746
--- /dev/null
+++ b/JewelryStore/FormImplementers.cs
@@ -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 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);
+ }
+ }
+ }
+}
diff --git a/JewelryStore/FormImplementers.resx b/JewelryStore/FormImplementers.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/JewelryStore/FormImplementers.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs
index b1d7cdc..251d535 100644
--- a/JewelryStore/FormMain.Designer.cs
+++ b/JewelryStore/FormMain.Designer.cs
@@ -28,180 +28,198 @@
///
private void InitializeComponent()
{
- this.buttonReady = new System.Windows.Forms.Button();
- this.dataGridView = new System.Windows.Forms.DataGridView();
- this.buttonCreate = new System.Windows.Forms.Button();
- this.buttonToWork = new System.Windows.Forms.Button();
- this.buttonPut = new System.Windows.Forms.Button();
- this.buttonRefresh = new System.Windows.Forms.Button();
- this.menuStrip = new System.Windows.Forms.MenuStrip();
- 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();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
- this.menuStrip.SuspendLayout();
- this.SuspendLayout();
- //
- // buttonReady
- //
- this.buttonReady.Location = new System.Drawing.Point(1273, 225);
- this.buttonReady.Name = "buttonReady";
- this.buttonReady.Size = new System.Drawing.Size(215, 34);
- this.buttonReady.TabIndex = 3;
- this.buttonReady.Text = "Заказ готов";
- this.buttonReady.UseVisualStyleBackColor = true;
- this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click);
- //
- // dataGridView
- //
- this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView.Location = new System.Drawing.Point(9, 52);
- this.dataGridView.Name = "dataGridView";
- this.dataGridView.RowHeadersWidth = 62;
- this.dataGridView.RowTemplate.Height = 33;
- this.dataGridView.Size = new System.Drawing.Size(1227, 386);
- this.dataGridView.TabIndex = 0;
- //
- // buttonCreate
- //
- this.buttonCreate.Location = new System.Drawing.Point(1273, 52);
- this.buttonCreate.Name = "buttonCreate";
- this.buttonCreate.Size = new System.Drawing.Size(215, 34);
- this.buttonCreate.TabIndex = 1;
- this.buttonCreate.Text = "Создать заказ";
- this.buttonCreate.UseVisualStyleBackColor = true;
- this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
- //
- // buttonToWork
- //
- this.buttonToWork.Location = new System.Drawing.Point(1273, 137);
- this.buttonToWork.Name = "buttonToWork";
- this.buttonToWork.Size = new System.Drawing.Size(215, 34);
- this.buttonToWork.TabIndex = 2;
- this.buttonToWork.Text = "Отдать на выполнение";
- this.buttonToWork.UseVisualStyleBackColor = true;
- this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click);
- //
- // buttonPut
- //
- this.buttonPut.Location = new System.Drawing.Point(1273, 308);
- this.buttonPut.Name = "buttonPut";
- this.buttonPut.Size = new System.Drawing.Size(215, 34);
- this.buttonPut.TabIndex = 4;
- this.buttonPut.Text = "Заказ выдан";
- this.buttonPut.UseVisualStyleBackColor = true;
- this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click);
- //
- // buttonRefresh
- //
- this.buttonRefresh.Location = new System.Drawing.Point(1273, 389);
- this.buttonRefresh.Name = "buttonRefresh";
- this.buttonRefresh.Size = new System.Drawing.Size(215, 34);
- this.buttonRefresh.TabIndex = 5;
- this.buttonRefresh.Text = "Обновить список";
- this.buttonRefresh.UseVisualStyleBackColor = true;
- this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click);
- //
- // menuStrip
- //
- this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
- this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.buttonReady = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.buttonCreate = new System.Windows.Forms.Button();
+ this.buttonToWork = new System.Windows.Forms.Button();
+ this.buttonPut = new System.Windows.Forms.Button();
+ this.buttonRefresh = new System.Windows.Forms.Button();
+ this.menuStrip = new System.Windows.Forms.MenuStrip();
+ 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();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.menuStrip.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // buttonReady
+ //
+ this.buttonReady.Location = new System.Drawing.Point(1273, 298);
+ this.buttonReady.Name = "buttonReady";
+ this.buttonReady.Size = new System.Drawing.Size(215, 34);
+ this.buttonReady.TabIndex = 3;
+ this.buttonReady.Text = "Заказ выдан";
+ this.buttonReady.UseVisualStyleBackColor = true;
+ this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(9, 52);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 62;
+ this.dataGridView.RowTemplate.Height = 33;
+ this.dataGridView.Size = new System.Drawing.Size(1227, 386);
+ this.dataGridView.TabIndex = 0;
+ //
+ // buttonCreate
+ //
+ this.buttonCreate.Location = new System.Drawing.Point(1273, 52);
+ this.buttonCreate.Name = "buttonCreate";
+ this.buttonCreate.Size = new System.Drawing.Size(215, 34);
+ this.buttonCreate.TabIndex = 1;
+ this.buttonCreate.Text = "Создать заказ";
+ this.buttonCreate.UseVisualStyleBackColor = true;
+ this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
+ //
+ // buttonToWork
+ //
+ this.buttonToWork.Location = new System.Drawing.Point(1273, 137);
+ this.buttonToWork.Name = "buttonToWork";
+ this.buttonToWork.Size = new System.Drawing.Size(215, 34);
+ this.buttonToWork.TabIndex = 2;
+ this.buttonToWork.Text = "Отдать на выполнение";
+ this.buttonToWork.UseVisualStyleBackColor = true;
+ this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click);
+ //
+ // buttonPut
+ //
+ this.buttonPut.Location = new System.Drawing.Point(1273, 218);
+ this.buttonPut.Name = "buttonPut";
+ this.buttonPut.Size = new System.Drawing.Size(215, 34);
+ this.buttonPut.TabIndex = 4;
+ this.buttonPut.Text = "Заказ готов";
+ this.buttonPut.UseVisualStyleBackColor = true;
+ this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click);
+ //
+ // buttonRefresh
+ //
+ this.buttonRefresh.Location = new System.Drawing.Point(1273, 389);
+ this.buttonRefresh.Name = "buttonRefresh";
+ this.buttonRefresh.Size = new System.Drawing.Size(215, 34);
+ this.buttonRefresh.TabIndex = 5;
+ this.buttonRefresh.Text = "Обновить список";
+ this.buttonRefresh.UseVisualStyleBackColor = true;
+ this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click);
+ //
+ // menuStrip
+ //
+ this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
+ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem,
- this.отчетыToolStripMenuItem});
- this.menuStrip.Location = new System.Drawing.Point(0, 0);
- this.menuStrip.Name = "menuStrip";
- this.menuStrip.Size = new System.Drawing.Size(1530, 33);
- this.menuStrip.TabIndex = 6;
- this.menuStrip.Text = "menuStrip1";
- //
- // справочникиToolStripMenuItem
- //
- this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.отчетыToolStripMenuItem,
+ this.запускРаботToolStripMenuItem});
+ this.menuStrip.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip.Name = "menuStrip";
+ this.menuStrip.Size = new System.Drawing.Size(1530, 33);
+ this.menuStrip.TabIndex = 6;
+ this.menuStrip.Text = "menuStrip1";
+ //
+ // справочникиToolStripMenuItem
+ //
+ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem,
this.изделияToolStripMenuItem,
- this.клиентыToolStripMenuItem});
- this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
- this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
- this.справочникиToolStripMenuItem.Text = "Справочники";
- //
- // компонентыToolStripMenuItem
- //
- this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
- this.компонентыToolStripMenuItem.Text = "Компоненты";
- this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click);
- //
- // изделияToolStripMenuItem
- //
- this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
- this.изделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
- this.изделияToolStripMenuItem.Text = "Драгоценности";
- this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click);
- //
- // отчетыToolStripMenuItem
- //
- this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.клиентыToolStripMenuItem,
+ this.исполнителиToolStripMenuItem});
+ this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
+ this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
+ this.справочникиToolStripMenuItem.Text = "Справочники";
+ //
+ // компоненты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
+ //
+ 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
+ //
+ 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
+ //
+ 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
+ //
+ this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.списокКомпонентовToolStripMenuItem,
this.компонентыПоИзделиямToolStripMenuItem,
this.списокЗаказзовToolStripMenuItem});
- this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
- this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29);
- this.отчетыToolStripMenuItem.Text = "Отчеты";
- //
- // списокКомпонентовToolStripMenuItem
- //
- this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
- this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
- this.списокКомпонентовToolStripMenuItem.Text = "Список изделий";
- this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.списокКомпонентовToolStripMenuItem_Click);
- //
- // компонентыПоИзделиямToolStripMenuItem
- //
- this.компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem";
- this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
- this.компонентыПоИзделиямToolStripMenuItem.Text = "Изделия по компонентам";
- this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоИзделиямToolStripMenuItem_Click);
- //
- // списокЗаказзовToolStripMenuItem
- //
- this.списокЗаказзовToolStripMenuItem.Name = "списокЗаказзовToolStripMenuItem";
- this.списокЗаказзовToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
- this.списокЗаказзовToolStripMenuItem.Text = "Список заказов";
- this.списокЗаказзовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказзовToolStripMenuItem_Click);
- //
- // клиентыToolStripMenuItem
- //
- this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
- this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
- this.клиентыToolStripMenuItem.Text = "Клиенты";
- this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click);
- //
- // FormMain
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1530, 450);
- this.Controls.Add(this.buttonRefresh);
- this.Controls.Add(this.buttonPut);
- this.Controls.Add(this.buttonReady);
- this.Controls.Add(this.buttonToWork);
- this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.dataGridView);
- this.Controls.Add(this.menuStrip);
- this.MainMenuStrip = this.menuStrip;
- this.Name = "FormMain";
- this.Text = "Изготовление Драгоценностей";
- this.Load += new System.EventHandler(this.FormMain_Load);
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
- this.menuStrip.ResumeLayout(false);
- this.menuStrip.PerformLayout();
- this.ResumeLayout(false);
- this.PerformLayout();
+ this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
+ this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29);
+ this.отчетыToolStripMenuItem.Text = "Отчеты";
+ //
+ // списокКомпонентовToolStripMenuItem
+ //
+ this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
+ this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
+ this.списокКомпонентовToolStripMenuItem.Text = "Список изделий";
+ this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.списокКомпонентовToolStripMenuItem_Click);
+ //
+ // компонентыПоИзделиямToolStripMenuItem
+ //
+ this.компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem";
+ this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
+ this.компонентыПоИзделиямToolStripMenuItem.Text = "Изделия по компонентам";
+ this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоИзделиямToolStripMenuItem_Click);
+ //
+ // списокЗаказзовToolStripMenuItem
+ //
+ this.списокЗаказзовToolStripMenuItem.Name = "списокЗаказзовToolStripMenuItem";
+ this.списокЗаказзовToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
+ this.списокЗаказзовToolStripMenuItem.Text = "Список заказов";
+ this.списокЗаказзовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказзовToolStripMenuItem_Click);
+ //
+ // запускРаботToolStripMenuItem
+ //
+ this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
+ this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(136, 29);
+ this.запускРаботToolStripMenuItem.Text = "Запуск работ";
+ this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1530, 450);
+ this.Controls.Add(this.buttonRefresh);
+ this.Controls.Add(this.buttonPut);
+ this.Controls.Add(this.buttonReady);
+ this.Controls.Add(this.buttonToWork);
+ this.Controls.Add(this.buttonCreate);
+ this.Controls.Add(this.dataGridView);
+ this.Controls.Add(this.menuStrip);
+ this.MainMenuStrip = this.menuStrip;
+ this.Name = "FormMain";
+ this.Text = "Изготовление Драгоценностей";
+ this.Load += new System.EventHandler(this.FormMain_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.menuStrip.ResumeLayout(false);
+ this.menuStrip.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
}
@@ -222,5 +240,7 @@
private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem;
private ToolStripMenuItem списокЗаказзовToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
- }
+ private ToolStripMenuItem запускРаботToolStripMenuItem;
+ private ToolStripMenuItem исполнителиToolStripMenuItem;
+ }
}
\ No newline at end of file
diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs
index c37b157..1c1f900 100644
--- a/JewelryStore/FormMain.cs
+++ b/JewelryStore/FormMain.cs
@@ -20,15 +20,16 @@ namespace JewelryStore
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
+ private readonly IWorkProcess _workProcess;
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
-
+ _workProcess = workProcess;
}
private void FormMain_Load(object sender, EventArgs e)
@@ -47,10 +48,10 @@ namespace JewelryStore
dataGridView.DataSource = list;
dataGridView.Columns["JewelId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
+ dataGridView.Columns["ImplementerId"].Visible = false;
+ }
- }
-
- _logger.LogInformation("Загрузка заказов");
+ _logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
@@ -99,14 +100,6 @@ namespace JewelryStore
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = id,
- JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
- ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value),
-
- JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
@@ -135,13 +128,6 @@ namespace JewelryStore
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
Id = id,
- JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
- ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value),
- JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
@@ -170,13 +156,6 @@ namespace JewelryStore
OrderBindingModel
{
Id = id,
- JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
- ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value),
- JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
@@ -231,13 +210,33 @@ namespace JewelryStore
}
}
- private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormClients));
- if (service is FormClients form)
- {
- form.ShowDialog();
- }
- }
- }
+ private void клиентыToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormClients));
+ if (service is FormClients form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ {
+
+ _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
+ MessageBox.Show("Процесс обработки запущен", "Сообщение",
+ 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();
+ }
+ }
+ }
}
diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs
index 344d316..50bf9fa 100644
--- a/JewelryStore/Program.cs
+++ b/JewelryStore/Program.cs
@@ -42,13 +42,17 @@ namespace JewelryStore
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -64,7 +68,8 @@ namespace JewelryStore
services.AddTransient();
services.AddTransient();
services.AddTransient();
-
+ services.AddTransient();
+ services.AddTransient();
}
}
diff --git a/JewelryStore/nlog.config b/JewelryStore/nlog.config
new file mode 100644
index 0000000..609afe6
--- /dev/null
+++ b/JewelryStore/nlog.config
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs
new file mode 100644
index 0000000..5f2dfdd
--- /dev/null
+++ b/JewelryStoreBusinessLogic/BusinessLogics/ImplementerLogic.cs
@@ -0,0 +1,130 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.BusinessLogicsContracts;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreBusinessLogic.BusinessLogics
+{
+ public class ImplementerLogic : IImplementerLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IImplementerStorage _implementerStorage;
+
+ public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage)
+ {
+ _logger = logger;
+ _implementerStorage = implementerStorage;
+ }
+
+ public bool Create(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(ImplementerBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_implementerStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}",
+ model.ImplementerFIO, model.Id);
+ var element = _implementerStorage.GetElement(model);
+
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public List? ReadList(ImplementerSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id);
+ var list = (model == null) ? _implementerStorage.GetFullList() :
+ _implementerStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public bool Update(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(ImplementerBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.WorkExperience < 0)
+ {
+ throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience));
+ }
+ if (model.Qualification < 0)
+ {
+ throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification));
+ }
+ if (string.IsNullOrEmpty(model.Password))
+ {
+ throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO));
+ }
+ if (string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO));
+ }
+ _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO);
+ var element = _implementerStorage.GetElement(new ImplementerSearchModel
+ {
+ ImplementerFIO = model.ImplementerFIO,
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
+ }
+ }
+ }
+}
diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs
index 6bcfa52..7010a87 100644
--- a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -15,13 +15,9 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic //TODO реализовать интерфейс
{
- // Класс с логикой для заказов будет отвечать за получение списка заказов,
- //создания заказа и смены его статусов.Следует учитывать, что у заказа можно
- //менять статус на новый, если его текущий статус предшествует новому
- //(например, в статус «Готов» можно переводить, если заказ находится в статусе
- //«Выполняется»).
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
+
public OrderLogic(ILogger logger, IOrderStorage orderStorage)
{
_logger = logger;
@@ -31,100 +27,140 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
public bool CreateOrder(OrderBindingModel 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.Принят;
+
if (_orderStorage.Insert(model) == null)
{
+ model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed");
return false;
}
+
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)
{
- CheckModel(model);
- if (model.Status != OrderStatus.Готов) return false;
-
- model.Status = OrderStatus.Выдан;
model.DateImplement = DateTime.Now;
- if (_orderStorage.Update(model) == null)
- {
- _logger.LogWarning("Update operation failed");
- return false;
- }
- return true;
+ return StatusUpdate(model, OrderStatus.Готов);
}
public bool FinishOrder(OrderBindingModel model)
{
- CheckModel(model);
- if (model.Status != OrderStatus.Выполняется) return false;
-
- model.Status = OrderStatus.Готов;
- if (_orderStorage.Update(model) == null)
- {
- _logger.LogWarning("Update operation failed");
- return false;
- }
- return true;
+ return StatusUpdate(model, OrderStatus.Выдан);
}
public List? 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);
+
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
+
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
- public bool TakeOrderInWork(OrderBindingModel model)
+ private bool CheckModel(OrderBindingModel model)
{
- CheckModel(model);
- if (model.Status != OrderStatus.Принят) return false;
- model.Status = OrderStatus.Выполняется;
- if (_orderStorage.Update(model) == null)
+ if (model == null)
{
- _logger.LogWarning("Update operation failed");
- return false;
+ throw new ArgumentNullException(nameof(model));
}
+ 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;
}
- private void CheckModel(OrderBindingModel model, bool withParams = true)
+ public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
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)
- {
- throw new ArgumentNullException("Некорректный идентификатор драгоценности", nameof(model.JewelId));
- }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
- if (model.Count <= 0)
- {
- 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);
+ return element;
}
-
}
}
diff --git a/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs
new file mode 100644
index 0000000..433fe50
--- /dev/null
+++ b/JewelryStoreBusinessLogic/BusinessLogics/WorkModeling.cs
@@ -0,0 +1,139 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.BusinessLogicsContracts;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Enums;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreBusinessLogic.BusinessLogics
+{
+ public class WorkModeling : IWorkProcess
+ {
+ private readonly ILogger _logger;
+
+ private readonly Random _rnd;
+
+ private IOrderLogic? _orderLogic;
+
+ public WorkModeling(ILogger logger)
+ {
+ _logger = logger;
+ _rnd = new Random(1000);
+ }
+
+ public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
+ {
+ _orderLogic = orderLogic;
+ var implementers = implementerLogic.ReadList(null);
+ if (implementers == null)
+ {
+ _logger.LogWarning("DoWork. Implementers is null");
+ return;
+ }
+
+ var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } });
+ if (orders == null || orders.Count == 0)
+ {
+ _logger.LogWarning("DoWork. Orders is null or empty");
+ return;
+ }
+
+ _logger.LogDebug("DoWork for {Count} orders", orders.Count);
+
+ foreach (var implementer in implementers)
+ {
+ Task.Run(() => WorkerWorkAsync(implementer, orders));
+ }
+ }
+
+ private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders)
+ {
+ if (_orderLogic == null || implementer == null)
+ {
+ return;
+ }
+ await RunOrderInWork(implementer, orders);
+
+ await Task.Run(() =>
+ {
+ foreach (var order in orders)
+ {
+ try
+ {
+ _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
+
+ _orderLogic.TakeOrderInWork(new OrderBindingModel
+ {
+ Id = order.Id,
+ ImplementerId = implementer.Id
+ });
+
+ Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
+ _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
+
+ _orderLogic.DeliveryOrder(new OrderBindingModel
+ {
+ Id = order.Id
+ });
+
+ Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
+ }
+
+ catch (InvalidOperationException ex)
+ {
+ _logger.LogWarning(ex, "Error try get work");
+ }
+
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error while do work");
+ throw;
+ }
+ }
+ });
+ }
+
+ private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders)
+ {
+ if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0)
+ {
+ return;
+ }
+ try
+ {
+ var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется));
+ if (runOrder == null)
+ {
+ return;
+ }
+
+ _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
+
+ Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
+ _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
+ _orderLogic.DeliveryOrder(new OrderBindingModel
+ {
+ Id = runOrder.Id
+ });
+
+ Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
+ }
+
+ catch (InvalidOperationException ex)
+ {
+ _logger.LogWarning(ex, "Error try get work");
+ }
+
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error while do work");
+ throw;
+ }
+ }
+ }
+}
diff --git a/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs b/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs
new file mode 100644
index 0000000..5d9c8e3
--- /dev/null
+++ b/JewelryStoreContracts/BindingModels/ImplementerBindingModel.cs
@@ -0,0 +1,22 @@
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.BindingModels
+{
+ public class ImplementerBindingModel : IImplementerModel
+ {
+ public int Id { get; set; }
+
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ public string Password { get; set; } = string.Empty;
+
+ public int WorkExperience { get; set; }
+
+ public int Qualification { get; set; }
+ }
+}
diff --git a/JewelryStoreContracts/BindingModels/OrderBindingModel.cs b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs
index 77ed89e..9ec08a4 100644
--- a/JewelryStoreContracts/BindingModels/OrderBindingModel.cs
+++ b/JewelryStoreContracts/BindingModels/OrderBindingModel.cs
@@ -20,6 +20,7 @@ namespace JewelryStoreContracts.BindingModels
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
+ public int? ImplementerId { get; set; }
}
}
diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs
new file mode 100644
index 0000000..342b189
--- /dev/null
+++ b/JewelryStoreContracts/BusinessLogicsContracts/IImplementerLogic.cs
@@ -0,0 +1,24 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.BusinessLogicsContracts
+{
+ public interface IImplementerLogic
+ {
+ List? ReadList(ImplementerSearchModel? model);
+
+ ImplementerViewModel? ReadElement(ImplementerSearchModel model);
+
+ bool Create(ImplementerBindingModel model);
+
+ bool Update(ImplementerBindingModel model);
+
+ bool Delete(ImplementerBindingModel model);
+ }
+}
diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs
index a403f30..5a905c5 100644
--- a/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs
+++ b/JewelryStoreContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -12,6 +12,8 @@ namespace JewelryStoreContracts.BusinessLogicsContracts
public interface IOrderLogic
{
List? ReadList(OrderSearchModel? model);
+ OrderViewModel? ReadElement(OrderSearchModel model);
+
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs b/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs
new file mode 100644
index 0000000..60b4065
--- /dev/null
+++ b/JewelryStoreContracts/BusinessLogicsContracts/IWorkProcess.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.BusinessLogicsContracts
+{
+ public interface IWorkProcess
+ {
+ ///
+ /// Запуск работ
+ ///
+ void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
+
+ }
+}
diff --git a/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs b/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs
new file mode 100644
index 0000000..72d4a52
--- /dev/null
+++ b/JewelryStoreContracts/SearchModels/ImplementerSearchModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.SearchModels
+{
+ public class ImplementerSearchModel
+ {
+ public int? Id { get; set; }
+
+ public string? ImplementerFIO { get; set; }
+
+ public string? Password { get; set; }
+ }
+}
diff --git a/JewelryStoreContracts/SearchModels/OrderSearchModel.cs b/JewelryStoreContracts/SearchModels/OrderSearchModel.cs
index 4d22d58..2d0a8f4 100644
--- a/JewelryStoreContracts/SearchModels/OrderSearchModel.cs
+++ b/JewelryStoreContracts/SearchModels/OrderSearchModel.cs
@@ -1,4 +1,5 @@
-using System;
+using JewelryStoreDataModels.Enums;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -13,5 +14,7 @@ namespace JewelryStoreContracts.SearchModels
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
+ public int? ImplementerId { get; set; }
+ public List? Statuses { get; set; }
}
}
diff --git a/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs b/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs
new file mode 100644
index 0000000..da83b5f
--- /dev/null
+++ b/JewelryStoreContracts/StoragesContracts/IImplementerStorage.cs
@@ -0,0 +1,26 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.StoragesContracts
+{
+ public interface IImplementerStorage
+ {
+ List GetFullList();
+
+ List GetFilteredList(ImplementerSearchModel model);
+
+ ImplementerViewModel? GetElement(ImplementerSearchModel model);
+
+ ImplementerViewModel? Insert(ImplementerBindingModel model);
+
+ ImplementerViewModel? Update(ImplementerBindingModel model);
+
+ ImplementerViewModel? Delete(ImplementerBindingModel model);
+ }
+}
diff --git a/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs b/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs
new file mode 100644
index 0000000..f84e6f7
--- /dev/null
+++ b/JewelryStoreContracts/ViewModels/ImplementerViewModel.cs
@@ -0,0 +1,27 @@
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.ViewModels
+{
+ public class ImplementerViewModel : IImplementerModel
+ {
+ public int Id { get; set; }
+
+ [DisplayName("ФИО исполнителя")]
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ [DisplayName("Пароль")]
+ public string Password { get; set; } = string.Empty;
+
+ [DisplayName("Стаж работы")]
+ public int WorkExperience { get; set; }
+
+ [DisplayName("Квалификация")]
+ public int Qualification { get; set; }
+ }
+}
diff --git a/JewelryStoreContracts/ViewModels/OrderViewModel.cs b/JewelryStoreContracts/ViewModels/OrderViewModel.cs
index 2d03e3c..fcb9cce 100644
--- a/JewelryStoreContracts/ViewModels/OrderViewModel.cs
+++ b/JewelryStoreContracts/ViewModels/OrderViewModel.cs
@@ -19,7 +19,10 @@ namespace JewelryStoreContracts.ViewModels
[DisplayName("Драгоценность")]
public string JewelName { get; set; } = string.Empty;
- [DisplayName("Клиент")]
+ [DisplayName("ФИО исполнителя")]
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ [DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Количество")]
@@ -33,6 +36,8 @@ namespace JewelryStoreContracts.ViewModels
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
- }
+ public int? ImplementerId { get; set; }
+
+ }
}
diff --git a/JewelryStoreDataModels/Models/IImplementerModel.cs b/JewelryStoreDataModels/Models/IImplementerModel.cs
new file mode 100644
index 0000000..5a48419
--- /dev/null
+++ b/JewelryStoreDataModels/Models/IImplementerModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreDataModels.Models
+{
+ public interface IImplementerModel : IId
+ {
+ string ImplementerFIO { get; }
+ string Password { get; }
+ int WorkExperience { get; }
+ int Qualification { get; }
+
+ }
+}
diff --git a/JewelryStoreDataModels/Models/IOrderModel.cs b/JewelryStoreDataModels/Models/IOrderModel.cs
index 62b66af..dafe1e6 100644
--- a/JewelryStoreDataModels/Models/IOrderModel.cs
+++ b/JewelryStoreDataModels/Models/IOrderModel.cs
@@ -12,8 +12,8 @@ namespace JewelryStoreDataModels.Models
{
int JewelId { get; }
string JewelName { get; }
-
- int ClientId { get; }
+ int? ImplementerId { get; }
+ int ClientId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
diff --git a/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs b/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..886b090
--- /dev/null
+++ b/JewelryStoreDatabaseImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,122 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDatabaseImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreDatabaseImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ using var context = new JewelryStoreDataBase();
+
+ var res = context.Implementers
+ .FirstOrDefault(x => x.Id == model.Id);
+
+ if (res != null)
+ {
+ context.Implementers.Remove(res);
+ context.SaveChanges();
+ }
+
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ using var context = new JewelryStoreDataBase();
+
+ if (model.Id.HasValue)
+ return context.Implementers
+ .FirstOrDefault(x => x.Id == model.Id)
+ ?.GetViewModel;
+
+ if (model.ImplementerFIO != null && model.Password != null)
+ return context.Implementers
+ .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
+ && x.Password.Equals(model.Password))
+ ?.GetViewModel;
+
+ if (model.ImplementerFIO != null)
+ return context.Implementers
+ .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
+ ?.GetViewModel;
+
+ return null;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+
+ return res != null ? new() { res } : new();
+ }
+
+ if (model.ImplementerFIO != null)
+ {
+ using var context = new JewelryStoreDataBase();
+
+ return context.Implementers
+ .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ using var context = new JewelryStoreDataBase();
+
+ return context.Implementers
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ using var context = new JewelryStoreDataBase();
+
+ var res = Implementer.Create(model);
+
+ if (res != null)
+ {
+ context.Implementers.Add(res);
+ context.SaveChanges();
+ }
+
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ using var context = new JewelryStoreDataBase();
+
+ var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
+
+ if (res != null)
+ {
+ res.Update(model);
+ context.SaveChanges();
+ }
+
+ return res?.GetViewModel;
+ }
+ }
+}
+
diff --git a/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs b/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs
index 7c3cb80..f2c1d57 100644
--- a/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs
+++ b/JewelryStoreDatabaseImplement/Implements/OrderStorage.cs
@@ -19,7 +19,7 @@ namespace JewelryStoreDatabaseImplement.Implements
using var context = new JewelryStoreDataBase();
var element = context.Orders.Include(x => x.Jewel)
- .Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id);
+ .Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
@@ -41,39 +41,55 @@ namespace JewelryStoreDatabaseImplement.Implements
using var context = new JewelryStoreDataBase();
- return context.Orders.Include(x => x.Jewel)
- .Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ return context.Orders
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x =>
+ (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) &&
+ model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId ||
+ model.Id.HasValue && x.Id == model.Id
+ )
+ ?.GetViewModel;
}
public List GetFilteredList(OrderSearchModel model)
{
- if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
+ if (model.Id.HasValue)
+ {
+ var result = GetElement(model);
+ return result != null ? new() { result } : new();
+ }
+
+ using var context = new JewelryStoreDataBase();
+ IQueryable? queryWhere = null;
+
+ if (model.DateFrom.HasValue && model.DateTo.HasValue)
+ {
+ queryWhere = context.Orders
+ .Where(x => model.DateFrom <= x.DateCreate.Date &&
+ x.DateCreate.Date <= model.DateTo);
+ }
+
+ else if (model.Statuses != null)
+ {
+ queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status));
+ }
+
+ else if (model.ClientId.HasValue)
+ {
+ queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId);
+ }
+
+ else
{
return new();
}
- using var context = new JewelryStoreDataBase();
- if (model.DateFrom.HasValue)
- {
- return context.Orders
- .Include(x => x.Jewel)
- .Include(x => x.Client)
- .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
- .Select(x => x.GetViewModel)
- .ToList();
- }
- else if (model.ClientId.HasValue)
- return context.Orders
- .Include(x => x.Jewel)
+
+ return queryWhere
.Include(x => x.Client)
- .Where(x => x.ClientId == model.ClientId)
+ .Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
- return context.Orders
- .Include(x => x.Jewel)
- .Include(x => x.Client)
- .Where(x => x.Id == model.Id)
- .Select(x => x.GetViewModel)
- .ToList();
}
public List GetFullList()
@@ -81,7 +97,7 @@ namespace JewelryStoreDatabaseImplement.Implements
using var context = new JewelryStoreDataBase();
return context.Orders.Include(x => x.Jewel)
- .Include(x => x.Client).Select(x => x.GetViewModel).ToList();
+ .Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
@@ -98,7 +114,11 @@ namespace JewelryStoreDatabaseImplement.Implements
context.Orders.Add(newOrder);
context.SaveChanges();
- return newOrder.GetViewModel;
+ return context.Orders.Include(x => x.Jewel)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x => x.Id == newOrder.Id)
+ ?.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
@@ -106,7 +126,7 @@ namespace JewelryStoreDatabaseImplement.Implements
using var context = new JewelryStoreDataBase();
var order = context.Orders.Include(x => x.Jewel)
- .Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id);
+ .Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
diff --git a/JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs b/JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs
index cff4fa7..244174f 100644
--- a/JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs
+++ b/JewelryStoreDatabaseImplement/JewelryStoreDataBase.cs
@@ -25,7 +25,9 @@ namespace JewelryStoreDatabaseImplement
public virtual DbSet Jewels { set; get; }
public virtual DbSet JewelComponents { set; get; }
public virtual DbSet Orders { set; get; }
- public virtual DbSet Clients { set; get; }
+ public virtual DbSet Clients { set; get; }
+ public virtual DbSet Implementers { set; get; }
+
}
}
diff --git a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs b/JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.Designer.cs
similarity index 82%
rename from JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs
rename to JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.Designer.cs
index c279e65..6fff767 100644
--- a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.Designer.cs
+++ b/JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.Designer.cs
@@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace JewelryStoreDatabaseImplement.Migrations
{
[DbContext(typeof(JewelryStoreDataBase))]
- [Migration("20230403133347_InitialCreate")]
+ [Migration("20230418091905_InitialCreate")]
partial class InitialCreate
{
///
@@ -70,6 +70,33 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Qualification")
+ .HasColumnType("int");
+
+ b.Property("WorkExperience")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
{
b.Property("Id")
@@ -136,6 +163,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("datetime2");
+ b.Property("ImplementerId")
+ .HasColumnType("int");
+
b.Property("JewelId")
.HasColumnType("int");
@@ -153,6 +183,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.HasIndex("JewelId");
b.ToTable("Orders");
@@ -185,6 +217,10 @@ namespace JewelryStoreDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
.WithMany("Orders")
.HasForeignKey("JewelId")
@@ -193,6 +229,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("Client");
+ b.Navigation("Implementer");
+
b.Navigation("Jewel");
});
@@ -206,6 +244,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("JewelComponents");
});
+ modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
{
b.Navigation("Components");
diff --git a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs b/JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.cs
similarity index 82%
rename from JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs
rename to JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.cs
index 6702f40..3435bf1 100644
--- a/JewelryStoreDatabaseImplement/Migrations/20230403133347_InitialCreate.cs
+++ b/JewelryStoreDatabaseImplement/Migrations/20230418091905_InitialCreate.cs
@@ -40,6 +40,22 @@ namespace JewelryStoreDatabaseImplement.Migrations
table.PrimaryKey("PK_Components", x => x.Id);
});
+ migrationBuilder.CreateTable(
+ name: "Implementers",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false),
+ Password = table.Column(type: "nvarchar(max)", nullable: false),
+ WorkExperience = table.Column(type: "int", nullable: false),
+ Qualification = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Implementers", x => x.Id);
+ });
+
migrationBuilder.CreateTable(
name: "Jewels",
columns: table => new
@@ -89,6 +105,7 @@ namespace JewelryStoreDatabaseImplement.Migrations
.Annotation("SqlServer:Identity", "1, 1"),
JewelId = table.Column(type: "int", nullable: false),
ClientId = table.Column(type: "int", nullable: false),
+ ImplementerId = table.Column(type: "int", nullable: true),
JewelName = table.Column(type: "nvarchar(max)", nullable: false),
Count = table.Column(type: "int", nullable: false),
Sum = table.Column(type: "float", nullable: false),
@@ -105,6 +122,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ column: x => x.ImplementerId,
+ principalTable: "Implementers",
+ principalColumn: "Id");
table.ForeignKey(
name: "FK_Orders_Jewels_JewelId",
column: x => x.JewelId,
@@ -128,6 +150,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
table: "Orders",
column: "ClientId");
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId");
+
migrationBuilder.CreateIndex(
name: "IX_Orders_JewelId",
table: "Orders",
@@ -149,6 +176,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Clients");
+ migrationBuilder.DropTable(
+ name: "Implementers");
+
migrationBuilder.DropTable(
name: "Jewels");
}
diff --git a/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs b/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs
index ec2bacf..599816d 100644
--- a/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs
+++ b/JewelryStoreDatabaseImplement/Migrations/JewelryStoreDataBaseModelSnapshot.cs
@@ -67,6 +67,33 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Qualification")
+ .HasColumnType("int");
+
+ b.Property("WorkExperience")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
{
b.Property("Id")
@@ -133,6 +160,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("datetime2");
+ b.Property("ImplementerId")
+ .HasColumnType("int");
+
b.Property("JewelId")
.HasColumnType("int");
@@ -150,6 +180,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.HasIndex("JewelId");
b.ToTable("Orders");
@@ -182,6 +214,10 @@ namespace JewelryStoreDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("JewelryStoreDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
.WithMany("Orders")
.HasForeignKey("JewelId")
@@ -190,6 +226,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("Client");
+ b.Navigation("Implementer");
+
b.Navigation("Jewel");
});
@@ -203,6 +241,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("JewelComponents");
});
+ modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
{
b.Navigation("Components");
diff --git a/JewelryStoreDatabaseImplement/Models/Implementer.cs b/JewelryStoreDatabaseImplement/Models/Implementer.cs
new file mode 100644
index 0000000..71b05b5
--- /dev/null
+++ b/JewelryStoreDatabaseImplement/Models/Implementer.cs
@@ -0,0 +1,71 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreDatabaseImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ [Required]
+ public string ImplementerFIO { get; private set; } = string.Empty;
+
+ [Required]
+ public string Password { get; private set; } = string.Empty;
+
+ [Required]
+ public int WorkExperience { get; private set; }
+
+ [Required]
+ public int Qualification { get; private set; }
+
+ public int Id { get; private set; }
+
+ [ForeignKey("ImplementerId")]
+ public virtual List Orders { get; private set; } = new();
+
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Password = model.Password,
+ Qualification = model.Qualification,
+ ImplementerFIO = model.ImplementerFIO,
+ WorkExperience = model.WorkExperience
+ };
+ }
+
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Password = model.Password;
+ Qualification = model.Qualification;
+ ImplementerFIO = model.ImplementerFIO;
+ WorkExperience = model.WorkExperience;
+ }
+
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Password = Password,
+ Qualification = Qualification,
+ ImplementerFIO = ImplementerFIO,
+ WorkExperience = WorkExperience
+ };
+ }
+}
+
diff --git a/JewelryStoreDatabaseImplement/Models/Order.cs b/JewelryStoreDatabaseImplement/Models/Order.cs
index 0e297d5..97d4cfe 100644
--- a/JewelryStoreDatabaseImplement/Models/Order.cs
+++ b/JewelryStoreDatabaseImplement/Models/Order.cs
@@ -20,6 +20,7 @@ namespace JewelryStoreDatabaseImplement.Models
[Required]
public int ClientId { get; set; }
+ public int? ImplementerId { get; private set; }
public string JewelName { get; private set; } = string.Empty;
@@ -39,6 +40,7 @@ namespace JewelryStoreDatabaseImplement.Models
public virtual Jewel Jewel { get; set; }
public virtual Client Client { get; set; }
+ public Implementer? Implementer { get; set; }
public static Order? Create(OrderBindingModel? model)
{
@@ -52,6 +54,7 @@ namespace JewelryStoreDatabaseImplement.Models
Id = model.Id,
JewelId = model.JewelId,
ClientId = model.ClientId,
+ ImplementerId = model.ImplementerId,
JewelName = model.JewelName,
Count = model.Count,
Sum = model.Sum,
@@ -75,6 +78,8 @@ namespace JewelryStoreDatabaseImplement.Models
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
+ ImplementerId = model.ImplementerId;
+
}
public OrderViewModel GetViewModel
@@ -87,13 +92,15 @@ namespace JewelryStoreDatabaseImplement.Models
Id = Id,
JewelId = JewelId,
ClientId = ClientId,
+ ImplementerId = ImplementerId,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
JewelName = context.Jewels.FirstOrDefault(x => x.Id == JewelId)?.JewelName ?? string.Empty,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
- DateImplement = DateImplement
+ DateImplement = DateImplement,
+ ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
};
}
}
diff --git a/JewelryStoreFileImplement/DataFileSingleton.cs b/JewelryStoreFileImplement/DataFileSingleton.cs
index 4479672..40f68f9 100644
--- a/JewelryStoreFileImplement/DataFileSingleton.cs
+++ b/JewelryStoreFileImplement/DataFileSingleton.cs
@@ -15,11 +15,14 @@ namespace JewelryStoreFileImplement
private readonly string OrderFileName = "Order.xml";
private readonly string JewelFileName = "Jewel.xml";
private readonly string ClientFileName = "Client.xml";
+ private readonly string ImplementerFileName = "Implementer.xml";
+
public List Components { get; private set; }
public List Orders { get; private set; }
public List Jewels { get; private set; }
public List Clients { get; private set; }
+ public List Implementers { get; private set; }
public static DataFileSingleton GetInstance()
{
@@ -33,6 +36,8 @@ namespace JewelryStoreFileImplement
public void SaveJewels() => SaveData(Jewels, JewelFileName, "Jewels", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
+ public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement);
+
private DataFileSingleton()
{
@@ -40,6 +45,8 @@ namespace JewelryStoreFileImplement
Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
+ Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
+
}
private static List? LoadData(string filename, string xmlNodeName, Func selectFunction)
diff --git a/JewelryStoreFileImplement/Implements/ImplementerStorage.cs b/JewelryStoreFileImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..16ff71e
--- /dev/null
+++ b/JewelryStoreFileImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,109 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreFileImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataFileSingleton _source;
+ public ImplementerStorage()
+ {
+ _source = DataFileSingleton.GetInstance();
+ }
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+
+ if (res != null)
+ {
+ _source.Implementers.Remove(res);
+ _source.SaveImplementers();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ if (model.Id.HasValue)
+ return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+
+ if (model.ImplementerFIO != null && model.Password != null)
+ return _source.Implementers
+ .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
+ && x.Password.Equals(model.Password))
+ ?.GetViewModel;
+
+ if (model.ImplementerFIO != null)
+ return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
+
+ return null;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+
+ return res != null ? new() { res } : new();
+ }
+
+ if (model.ImplementerFIO != null)
+ {
+ return _source.Implementers
+ .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ return _source.Implementers.Select(x => x.GetViewModel).ToList();
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
+
+ var res = Implementer.Create(model);
+
+ if (res != null)
+ {
+ _source.Implementers.Add(res);
+ _source.SaveImplementers();
+ }
+
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+
+ if (res != null)
+ {
+ res.Update(model);
+ _source.SaveImplementers();
+ }
+
+ return res?.GetViewModel;
+ }
+ }
+}
+
diff --git a/JewelryStoreFileImplement/Models/Implementer.cs b/JewelryStoreFileImplement/Models/Implementer.cs
new file mode 100644
index 0000000..e6b305f
--- /dev/null
+++ b/JewelryStoreFileImplement/Models/Implementer.cs
@@ -0,0 +1,86 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace JewelryStoreFileImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public string ImplementerFIO { get; private set; } = string.Empty;
+
+ public string Password { get; private set; } = string.Empty;
+
+ public int WorkExperience { get; private set; }
+
+ public int Qualification { get; private set; }
+
+ public int Id { get; private set; }
+
+ public static Implementer? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ ImplementerFIO = element.Element("FIO")!.Value,
+ Password = element.Element("Password")!.Value,
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
+ WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
+ };
+ }
+
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Password = model.Password,
+ Qualification = model.Qualification,
+ ImplementerFIO = model.ImplementerFIO,
+ WorkExperience = model.WorkExperience,
+ };
+ }
+
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Password = model.Password;
+ Qualification = model.Qualification;
+ ImplementerFIO = model.ImplementerFIO;
+ WorkExperience = model.WorkExperience;
+ }
+
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Password = Password,
+ Qualification = Qualification,
+ ImplementerFIO = ImplementerFIO,
+ WorkExperience = WorkExperience
+ };
+
+ public XElement GetXElement => new("Client",
+ new XAttribute("Id", Id),
+ new XElement("Password", Password),
+ new XElement("FIO", ImplementerFIO),
+ new XElement("Qualification", Qualification),
+ new XElement("WorkExperience", WorkExperience)
+ );
+ }
+}
diff --git a/JewelryStoreFileImplement/Models/Order.cs b/JewelryStoreFileImplement/Models/Order.cs
index 627c3d0..23bcf7c 100644
--- a/JewelryStoreFileImplement/Models/Order.cs
+++ b/JewelryStoreFileImplement/Models/Order.cs
@@ -18,6 +18,7 @@ namespace JewelryStoreFileImplement.Models
public int ClientId { get; private set; }
public string JewelName { get; private set; } = string.Empty;
+ public int? ImplementerId { get; private set; }
public int Count { get; private set; }
diff --git a/JewelryStoreListImplement/DataListSingleton.cs b/JewelryStoreListImplement/DataListSingleton.cs
index f3f9afa..a9b35b4 100644
--- a/JewelryStoreListImplement/DataListSingleton.cs
+++ b/JewelryStoreListImplement/DataListSingleton.cs
@@ -14,12 +14,14 @@ namespace JewelryStoreListImplement
public List Orders { get; set; }
public List Jewels { get; set; }
public List Clients { get; set; }
+ public List Implementers { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Jewels = new List();
+ Implementers = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/JewelryStoreListImplement/Implements/ImplementerStorage.cs b/JewelryStoreListImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..42077eb
--- /dev/null
+++ b/JewelryStoreListImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,131 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreListImplement.Implements
+{
+ public class ImplementerStorage
+ {
+ private readonly DataListSingleton _source;
+ public ImplementerStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ for (int i = 0; i < _source.Implementers.Count; ++i)
+ {
+ if (_source.Implementers[i].Id == model.Id)
+ {
+ var element = _source.Implementers[i];
+ _source.Implementers.RemoveAt(i);
+
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ foreach (var x in _source.Implementers)
+ {
+ if (model.Id.HasValue && x.Id == model.Id)
+ return x.GetViewModel;
+
+ if (model.ImplementerFIO != null && model.Password != null &&
+ x.ImplementerFIO.Equals(model.ImplementerFIO) &&
+ x.Password.Equals(model.Password))
+ return x.GetViewModel;
+
+ if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
+ return x.GetViewModel;
+ }
+ return null;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+
+ return res != null ? new() { res } : new();
+ }
+
+ List result = new();
+
+ if (model.ImplementerFIO != null)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
+ {
+ result.Add(implementer.GetViewModel);
+ }
+ }
+ }
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach (var implementer in _source.Implementers)
+ {
+ result.Add(implementer.GetViewModel);
+ }
+
+ return result;
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach (var implementer in _source.Implementers)
+ {
+ if (model.Id <= implementer.Id)
+ {
+ model.Id = implementer.Id + 1;
+ }
+ }
+
+ var res = Implementer.Create(model);
+
+ if (res != null)
+ {
+ _source.Implementers.Add(res);
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.Id == model.Id)
+ {
+ implementer.Update(model);
+
+ return implementer.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
+
diff --git a/JewelryStoreListImplement/Models/Implementer.cs b/JewelryStoreListImplement/Models/Implementer.cs
new file mode 100644
index 0000000..d8c279a
--- /dev/null
+++ b/JewelryStoreListImplement/Models/Implementer.cs
@@ -0,0 +1,62 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreListImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public string ImplementerFIO { get; private set; } = string.Empty;
+
+ public string Password { get; private set; } = string.Empty;
+
+ public int WorkExperience { get; private set; }
+
+ public int Qualification { get; private set; }
+
+ public int Id { get; private set; }
+
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Password = model.Password,
+ Qualification = model.Qualification,
+ ImplementerFIO = model.ImplementerFIO,
+ WorkExperience = model.WorkExperience,
+ };
+ }
+
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Password = model.Password;
+ Qualification = model.Qualification;
+ ImplementerFIO = model.ImplementerFIO;
+ WorkExperience = model.WorkExperience;
+ }
+
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Password = Password,
+ Qualification = Qualification,
+ ImplementerFIO = ImplementerFIO,
+ WorkExperience = WorkExperience
+ };
+ }
+}
+
diff --git a/JewelryStoreListImplement/Models/Order.cs b/JewelryStoreListImplement/Models/Order.cs
index 23c1fbb..18c0bbf 100644
--- a/JewelryStoreListImplement/Models/Order.cs
+++ b/JewelryStoreListImplement/Models/Order.cs
@@ -15,6 +15,8 @@ namespace JewelryStoreListImplement.Models
public int JewelId { get; private set; }
public string JewelName { get; private set; }
public int ClientId { get; private set; }
+ public int? ImplementerId { get; private set; }
+
public int Count { get; private set; }
public double Sum { get; private set; }
@@ -71,5 +73,6 @@ namespace JewelryStoreListImplement.Models
DateCreate = DateCreate,
DateImplement = DateImplement
};
+
}
}
diff --git a/JewelryStoreRestApi/Controllers/ImplementerController.cs b/JewelryStoreRestApi/Controllers/ImplementerController.cs
new file mode 100644
index 0000000..82ae8e5
--- /dev/null
+++ b/JewelryStoreRestApi/Controllers/ImplementerController.cs
@@ -0,0 +1,106 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.BusinessLogicsContracts;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.ViewModels;
+using Microsoft.AspNetCore.Mvc;
+
+namespace JewelryStoreRestApi.Controllers
+{
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class ImplementerController : Controller
+ {
+ private readonly ILogger _logger;
+
+ private readonly IOrderLogic _order;
+
+ private readonly IImplementerLogic _logic;
+
+ public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger)
+ {
+ _logger = logger;
+ _order = order;
+ _logic = logic;
+ }
+
+ [HttpGet]
+ public ImplementerViewModel? Login(string login, string password)
+ {
+ try
+ {
+ return _logic.ReadElement(new ImplementerSearchModel
+ {
+ ImplementerFIO = login,
+ Password = password
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка авторизации сотрудника");
+ throw;
+ }
+ }
+
+ [HttpGet]
+ public List? GetNewOrders()
+ {
+ try
+ {
+ return _order.ReadList(new OrderSearchModel
+ {
+ //Status = OrderStatus.Принят
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения новых заказов");
+ throw;
+ }
+ }
+
+ [HttpGet]
+ public OrderViewModel? GetImplementerOrder(int implementerId)
+ {
+ try
+ {
+ return _order.ReadElement(new OrderSearchModel
+ {
+ ImplementerId = implementerId
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
+ throw;
+ }
+ }
+
+ [HttpPost]
+ public void TakeOrderInWork(OrderBindingModel model)
+ {
+ try
+ {
+ _order.TakeOrderInWork(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id);
+ throw;
+ }
+ }
+
+ [HttpPost]
+ public void FinishOrder(OrderBindingModel model)
+ {
+ try
+ {
+ _order.FinishOrder(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id);
+ throw;
+ }
+ }
+ }
+}