diff --git a/FishFactory/Forms/FormCreateOrder.cs b/FishFactory/Forms/FormCreateOrder.cs
index f9cc95d..9d04f7a 100644
--- a/FishFactory/Forms/FormCreateOrder.cs
+++ b/FishFactory/Forms/FormCreateOrder.cs
@@ -82,9 +82,9 @@ namespace FishFactory.Forms
private void buttonSave_Click(object sender, EventArgs e)
{
- if (string.IsNullOrEmpty(textBoxCount.Text))
+ if (comboBoxClient.SelectedValue == null)
{
- MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxCanned.SelectedValue == null)
@@ -92,9 +92,9 @@ namespace FishFactory.Forms
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
- if (comboBoxClient.SelectedValue == null)
+ if (string.IsNullOrEmpty(textBoxCount.Text))
{
- MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
diff --git a/FishFactory/Forms/FormImplementer.Designer.cs b/FishFactory/Forms/FormImplementer.Designer.cs
new file mode 100644
index 0000000..32f1137
--- /dev/null
+++ b/FishFactory/Forms/FormImplementer.Designer.cs
@@ -0,0 +1,168 @@
+namespace FishFactory.Forms
+{
+ 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()
+ {
+ textBoxWorkExperience = new TextBox();
+ textBoxFIO = new TextBox();
+ label2 = new Label();
+ label1 = new Label();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ textBoxQualification = new TextBox();
+ label3 = new Label();
+ textBoxPassword = new TextBox();
+ label4 = new Label();
+ SuspendLayout();
+ //
+ // textBoxWorkExperience
+ //
+ textBoxWorkExperience.Location = new Point(189, 97);
+ textBoxWorkExperience.Margin = new Padding(3, 4, 3, 4);
+ textBoxWorkExperience.Name = "textBoxWorkExperience";
+ textBoxWorkExperience.Size = new Size(305, 26);
+ textBoxWorkExperience.TabIndex = 11;
+ //
+ // textBoxFIO
+ //
+ textBoxFIO.Location = new Point(189, 27);
+ textBoxFIO.Margin = new Padding(3, 4, 3, 4);
+ textBoxFIO.Name = "textBoxFIO";
+ textBoxFIO.Size = new Size(305, 26);
+ textBoxFIO.TabIndex = 10;
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(43, 100);
+ label2.Name = "label2";
+ label2.Size = new Size(95, 19);
+ label2.TabIndex = 9;
+ label2.Text = "Стаж работы:";
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(43, 29);
+ label1.Name = "label1";
+ label1.Size = new Size(127, 19);
+ label1.TabIndex = 8;
+ label1.Text = "ФИО исполнителя:";
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(400, 191);
+ buttonCancel.Margin = new Padding(3, 4, 3, 4);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(98, 32);
+ buttonCancel.TabIndex = 7;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(292, 191);
+ buttonSave.Margin = new Padding(3, 4, 3, 4);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(98, 32);
+ buttonSave.TabIndex = 6;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // textBoxQualification
+ //
+ textBoxQualification.Location = new Point(189, 131);
+ textBoxQualification.Margin = new Padding(3, 4, 3, 4);
+ textBoxQualification.Name = "textBoxQualification";
+ textBoxQualification.Size = new Size(305, 26);
+ textBoxQualification.TabIndex = 13;
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(43, 134);
+ label3.Name = "label3";
+ label3.Size = new Size(104, 19);
+ label3.TabIndex = 12;
+ label3.Text = "Квалификация:";
+ //
+ // textBoxPassword
+ //
+ textBoxPassword.Location = new Point(189, 63);
+ textBoxPassword.Margin = new Padding(3, 4, 3, 4);
+ textBoxPassword.Name = "textBoxPassword";
+ textBoxPassword.Size = new Size(305, 26);
+ textBoxPassword.TabIndex = 15;
+ //
+ // label4
+ //
+ label4.AutoSize = true;
+ label4.Location = new Point(43, 65);
+ label4.Name = "label4";
+ label4.Size = new Size(59, 19);
+ label4.TabIndex = 14;
+ label4.Text = "Пароль:";
+ //
+ // FormImplementer
+ //
+ AutoScaleDimensions = new SizeF(8F, 19F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(536, 238);
+ Controls.Add(textBoxPassword);
+ Controls.Add(label4);
+ Controls.Add(textBoxQualification);
+ Controls.Add(label3);
+ Controls.Add(textBoxWorkExperience);
+ Controls.Add(textBoxFIO);
+ Controls.Add(label2);
+ Controls.Add(label1);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Name = "FormImplementer";
+ Text = "FormImplementer";
+ Load += FormImplementer_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private TextBox textBoxWorkExperience;
+ private TextBox textBoxFIO;
+ private Label label2;
+ private Label label1;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private TextBox textBoxQualification;
+ private Label label3;
+ private TextBox textBoxPassword;
+ private Label label4;
+ }
+}
\ No newline at end of file
diff --git a/FishFactory/Forms/FormImplementer.cs b/FishFactory/Forms/FormImplementer.cs
new file mode 100644
index 0000000..5694413
--- /dev/null
+++ b/FishFactory/Forms/FormImplementer.cs
@@ -0,0 +1,95 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BusinessLogicsContracts;
+using FishFactoryContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+namespace FishFactory.Forms
+{
+ 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 FormImplementer_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение исполнителя");
+ var view = _logic.ReadElement(new ImplementerSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxFIO.Text = view.ImplementerFIO;
+ textBoxPassword.Text = view.Password;
+ textBoxWorkExperience.Text = view.WorkExperience.ToString();
+ textBoxQualification.Text = view.Qualification.ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения исполнителя");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxFIO.Text))
+ {
+ MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxPassword.Text))
+ {
+ MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение исполнителя");
+ try
+ {
+ var model = new ImplementerBindingModel
+ {
+ Id = _id ?? 0,
+ ImplementerFIO = textBoxFIO.Text,
+ Password = textBoxPassword.Text,
+ WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text),
+ Qualification = Convert.ToInt32(textBoxQualification.Text)
+ };
+ 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();
+ }
+ }
+}
diff --git a/FishFactory/Forms/FormImplementer.resx b/FishFactory/Forms/FormImplementer.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/FishFactory/Forms/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/FishFactory/Forms/FormImplementers.Designer.cs b/FishFactory/Forms/FormImplementers.Designer.cs
new file mode 100644
index 0000000..8ccea88
--- /dev/null
+++ b/FishFactory/Forms/FormImplementers.Designer.cs
@@ -0,0 +1,125 @@
+namespace FishFactory.Forms
+{
+ 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()
+ {
+ buttonRef = new Button();
+ buttonDel = new Button();
+ buttonUpd = new Button();
+ buttonAdd = new Button();
+ dataGridView = new DataGridView();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // buttonRef
+ //
+ buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonRef.Location = new Point(622, 175);
+ buttonRef.Margin = new Padding(3, 4, 3, 4);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new Size(125, 33);
+ buttonRef.TabIndex = 9;
+ buttonRef.Text = "Обновить";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += buttonRef_Click;
+ //
+ // buttonDel
+ //
+ buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonDel.Location = new Point(622, 126);
+ buttonDel.Margin = new Padding(3, 4, 3, 4);
+ buttonDel.Name = "buttonDel";
+ buttonDel.Size = new Size(125, 33);
+ buttonDel.TabIndex = 8;
+ buttonDel.Text = "Удалить";
+ buttonDel.UseVisualStyleBackColor = true;
+ buttonDel.Click += buttonDel_Click;
+ //
+ // buttonUpd
+ //
+ buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonUpd.Location = new Point(622, 77);
+ buttonUpd.Margin = new Padding(3, 4, 3, 4);
+ buttonUpd.Name = "buttonUpd";
+ buttonUpd.Size = new Size(125, 33);
+ buttonUpd.TabIndex = 7;
+ buttonUpd.Text = "Изменить";
+ buttonUpd.UseVisualStyleBackColor = true;
+ buttonUpd.Click += buttonUpd_Click;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonAdd.Location = new Point(622, 30);
+ buttonAdd.Margin = new Padding(3, 4, 3, 4);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(125, 33);
+ buttonAdd.TabIndex = 6;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += buttonAdd_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(-2, -2);
+ dataGridView.Margin = new Padding(3, 4, 3, 4);
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 24;
+ dataGridView.Size = new Size(587, 549);
+ dataGridView.TabIndex = 5;
+ //
+ // FormImplementers
+ //
+ AutoScaleDimensions = new SizeF(8F, 19F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(775, 546);
+ Controls.Add(buttonRef);
+ Controls.Add(buttonDel);
+ Controls.Add(buttonUpd);
+ Controls.Add(buttonAdd);
+ Controls.Add(dataGridView);
+ Name = "FormImplementers";
+ Text = "FormImplementers";
+ Load += FormImplementers_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/FishFactory/Forms/FormImplementers.cs b/FishFactory/Forms/FormImplementers.cs
new file mode 100644
index 0000000..50f1271
--- /dev/null
+++ b/FishFactory/Forms/FormImplementers.cs
@@ -0,0 +1,104 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+namespace FishFactory.Forms
+{
+ public partial class FormImplementers : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IImplementerLogic _logic;
+
+ public FormImplementers(ILogger logger, IImplementerLogic implementerLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = implementerLogic;
+ }
+
+ 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);
+ }
+ }
+
+ private void buttonAdd_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 buttonUpd_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 buttonDel_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 buttonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/FishFactory/Forms/FormImplementers.resx b/FishFactory/Forms/FormImplementers.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/FishFactory/Forms/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/FishFactory/Forms/FormMain.Designer.cs b/FishFactory/Forms/FormMain.Designer.cs
index 94fe39f..602d6f6 100644
--- a/FishFactory/Forms/FormMain.Designer.cs
+++ b/FishFactory/Forms/FormMain.Designer.cs
@@ -34,13 +34,13 @@
компонентыToolStripMenuItem = new ToolStripMenuItem();
консервыToolStripMenuItem = new ToolStripMenuItem();
клиентыToolStripMenuItem = new ToolStripMenuItem();
+ исполнителиToolStripMenuItem = new ToolStripMenuItem();
toolStripDropDownButton2 = new ToolStripDropDownButton();
списокКомпонентовToolStripMenuItem = new ToolStripMenuItem();
компонентыПоКонсервамToolStripMenuItem = new ToolStripMenuItem();
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
+ ЗапускРаботToolStripLabel = new ToolStripLabel();
buttonCreateOrder = new Button();
- buttonTakeOrderInWork = new Button();
- buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
dataGridView = new DataGridView();
@@ -51,7 +51,7 @@
// toolStrip1
//
toolStrip1.ImageScalingSize = new Size(20, 20);
- toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripDropDownButton2 });
+ toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripDropDownButton2, ЗапускРаботToolStripLabel });
toolStrip1.Location = new Point(0, 0);
toolStrip1.Name = "toolStrip1";
toolStrip1.Size = new Size(1265, 26);
@@ -61,7 +61,7 @@
// toolStripDropDownButton1
//
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
- toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, клиентыToolStripMenuItem });
+ toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem });
toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image");
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
toolStripDropDownButton1.Name = "toolStripDropDownButton1";
@@ -71,24 +71,31 @@
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- компонентыToolStripMenuItem.Size = new Size(169, 26);
+ компонентыToolStripMenuItem.Size = new Size(171, 26);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click;
//
// консервыToolStripMenuItem
//
консервыToolStripMenuItem.Name = "консервыToolStripMenuItem";
- консервыToolStripMenuItem.Size = new Size(169, 26);
+ консервыToolStripMenuItem.Size = new Size(171, 26);
консервыToolStripMenuItem.Text = "Консервы";
консервыToolStripMenuItem.Click += консервыToolStripMenuItem_Click;
//
// клиентыToolStripMenuItem
//
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
- клиентыToolStripMenuItem.Size = new Size(169, 26);
+ клиентыToolStripMenuItem.Size = new Size(171, 26);
клиентыToolStripMenuItem.Text = "Клиенты";
клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click;
//
+ // исполнителиToolStripMenuItem
+ //
+ исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem";
+ исполнителиToolStripMenuItem.Size = new Size(171, 26);
+ исполнителиToolStripMenuItem.Text = "Исполнители";
+ исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click;
+ //
// toolStripDropDownButton2
//
toolStripDropDownButton2.DisplayStyle = ToolStripItemDisplayStyle.Text;
@@ -120,6 +127,13 @@
списокЗаказовToolStripMenuItem.Text = "Список заказов";
списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click;
//
+ // ЗапускРаботToolStripLabel
+ //
+ ЗапускРаботToolStripLabel.Name = "ЗапускРаботToolStripLabel";
+ ЗапускРаботToolStripLabel.Size = new Size(93, 23);
+ ЗапускРаботToolStripLabel.Text = "Запуск работ";
+ ЗапускРаботToolStripLabel.Click += ЗапускРаботToolStripLabel_Click;
+ //
// buttonCreateOrder
//
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
@@ -132,34 +146,10 @@
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += buttonCreateOrder_Click;
//
- // buttonTakeOrderInWork
- //
- buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
- buttonTakeOrderInWork.Location = new Point(1078, 127);
- buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4);
- buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
- buttonTakeOrderInWork.Size = new Size(161, 30);
- buttonTakeOrderInWork.TabIndex = 2;
- buttonTakeOrderInWork.Text = "Отдать на выполнение";
- buttonTakeOrderInWork.UseVisualStyleBackColor = true;
- buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click;
- //
- // buttonOrderReady
- //
- buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
- buttonOrderReady.Location = new Point(1078, 180);
- buttonOrderReady.Margin = new Padding(3, 4, 3, 4);
- buttonOrderReady.Name = "buttonOrderReady";
- buttonOrderReady.Size = new Size(161, 30);
- buttonOrderReady.TabIndex = 3;
- buttonOrderReady.Text = "Заказ готов";
- buttonOrderReady.UseVisualStyleBackColor = true;
- buttonOrderReady.Click += buttonOrderReady_Click;
- //
// buttonIssuedOrder
//
buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
- buttonIssuedOrder.Location = new Point(1078, 229);
+ buttonIssuedOrder.Location = new Point(1078, 125);
buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(161, 30);
@@ -171,7 +161,7 @@
// buttonRef
//
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
- buttonRef.Location = new Point(1078, 281);
+ buttonRef.Location = new Point(1078, 177);
buttonRef.Margin = new Padding(3, 4, 3, 4);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(161, 30);
@@ -202,8 +192,6 @@
Controls.Add(dataGridView);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
- Controls.Add(buttonOrderReady);
- Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(toolStrip1);
Margin = new Padding(3, 4, 3, 4);
@@ -221,8 +209,6 @@
private ToolStrip toolStrip1;
private Button buttonCreateOrder;
- private Button buttonTakeOrderInWork;
- private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private DataGridView dataGridView;
@@ -234,5 +220,7 @@
private ToolStripMenuItem компонентыПоКонсервамToolStripMenuItem;
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
private ToolStripMenuItem клиентыToolStripMenuItem;
+ private ToolStripLabel ЗапускРаботToolStripLabel;
+ private ToolStripMenuItem исполнителиToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/FishFactory/Forms/FormMain.cs b/FishFactory/Forms/FormMain.cs
index 3530101..a41d81f 100644
--- a/FishFactory/Forms/FormMain.cs
+++ b/FishFactory/Forms/FormMain.cs
@@ -1,5 +1,4 @@
-using FishFactoryBusinessLogic.BusinessLogic;
-using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
@@ -10,6 +9,8 @@ namespace FishFactory.Forms
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
+ private IWorkProcess _workProcess;
+
public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
@@ -35,6 +36,8 @@ namespace FishFactory.Forms
dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ImplementerId"].Visible = false;
+ dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
@@ -70,6 +73,16 @@ namespace FishFactory.Forms
form.ShowDialog();
}
}
+
+ private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
+
+ if (service is FormImplementers form)
+ {
+ form.ShowDialog();
+ }
+ }
private void buttonCreateOrder_Click(object sender, EventArgs e)
{
@@ -80,54 +93,7 @@ namespace FishFactory.Forms
LoadData();
}
}
- private void buttonTakeOrderInWork_Click(object sender, EventArgs e)
- {
- if (dataGridView.SelectedRows.Count == 1)
- {
- int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
- try
- {
- var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
- {
- Id = id,
- });
- if (!operationResult)
- {
- throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
- }
- LoadData();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка передачи заказа в работу");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- private void buttonOrderReady_Click(object sender, EventArgs e)
- {
- if (dataGridView.SelectedRows.Count == 1)
- {
- int id =
- Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
- _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
- try
- {
- var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
- if (!operationResult)
- {
- throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
- }
- LoadData();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка отметки о готовности заказа");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
+
private void buttonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
@@ -190,5 +156,11 @@ namespace FishFactory.Forms
form.ShowDialog();
}
}
+
+ private void ЗапускРаботToolStripLabel_Click(object sender, EventArgs e)
+ {
+ _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
+ MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
}
}
diff --git a/FishFactory/Program.cs b/FishFactory/Program.cs
index d58bbb4..96100d9 100644
--- a/FishFactory/Program.cs
+++ b/FishFactory/Program.cs
@@ -41,12 +41,15 @@ namespace FishFactory
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();
services.AddTransient();
@@ -56,9 +59,12 @@ namespace FishFactory
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+
services.AddTransient();
services.AddTransient();
services.AddTransient();
diff --git a/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs
index 618d327..4b820d4 100644
--- a/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs
+++ b/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs
@@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging;
namespace FishFactoryBusinessLogic.BusinessLogic
{
- public class ImplementerLogic : IImplementerBusinessLogic
+ public class ImplementerLogic : IImplementerLogic
{
private readonly ILogger _logger;
private readonly IImplementerStorage _implementerStorage;
diff --git a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs
index 9ea6392..11a0cae 100644
--- a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs
+++ b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs
@@ -5,20 +5,11 @@ using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Enums;
using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace FishFactoryBusinessLogic.BusinessLogic
{
public class OrderLogic : IOrderLogic
{
- //Класс с логикой для заказов будет отвечать за получение списка заказов,
- //создания заказа и смены его статусов. Следует учитывать, что у заказа можно
- //менять статус на новый, если его текущий статус предшествует новому
-
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
@@ -41,6 +32,24 @@ namespace FishFactoryBusinessLogic.BusinessLogic
return list;
}
+ public OrderViewModel? ReadElement(OrderSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ _logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id);
+ var element = _orderStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
@@ -86,11 +95,16 @@ namespace FishFactoryBusinessLogic.BusinessLogic
}
model.CannedId = element.CannedId;
+ model.ClientId = element.ClientId;
model.DateCreate = element.DateCreate;
model.DateImplement = element.DateImplement;
model.Status = element.Status;
model.Count = element.Count;
model.Sum = element.Sum;
+ if (!model.ImplementerId.HasValue)
+ {
+ model.ImplementerId = element.ImplementerId;
+ }
if (model.Status != orderStatus - 1)
{
diff --git a/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs b/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs
new file mode 100644
index 0000000..73eada3
--- /dev/null
+++ b/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs
@@ -0,0 +1,141 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BusinessLogicsContracts;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.ViewModels;
+using FishFactoryDataModel.Enums;
+using Microsoft.Extensions.Logging;
+
+namespace FishFactoryBusinessLogic.BusinessLogic
+{
+ 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 { Status = OrderStatus.Принят });
+ var processingOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выполняется });
+
+ if (orders == null || processingOrders == null || (orders.Count == 0 && processingOrders.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);
+
+ await Task.Run(() =>
+ {
+ foreach (var order in orders)
+ {
+ try
+ {
+ _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
+ // пытаемся назначить заказ на исполнителя
+ bool result = _orderLogic.TakeOrderInWork(new OrderBindingModel
+ {
+ Id = order.Id,
+ ImplementerId = implementer.Id
+ });
+ if (!result)
+ {
+ _logger.LogDebug("WorkerWorkAsync. Worker {Id} tried to get order {Order} but it's already acquired by other worker", implementer.Id, order.Id);
+ continue;
+ }
+ // делаем работу
+ Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
+ _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
+ _orderLogic.FinishOrder(new OrderBindingModel
+ {
+ Id = order.Id
+ });
+ }
+ // кто-то мог уже перехватить заказ, игнорируем ошибку
+ catch (InvalidOperationException ex)
+ {
+ _logger.LogWarning(ex, "Error try get work");
+ }
+ // заканчиваем выполнение имитации в случае иной ошибки
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error while do work");
+ throw;
+ }
+ // отдыхаем
+ Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
+ }
+ });
+ }
+
+ private async Task RunOrderInWork(ImplementerViewModel implementer)
+ {
+ if (_orderLogic == null || implementer == null)
+ {
+ return;
+ }
+ try
+ {
+ var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
+ {
+ ImplementerId = implementer.Id,
+ 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.FinishOrder(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/FishFactoryContracts/BindingModels/OrderBindingModel.cs b/FishFactoryContracts/BindingModels/OrderBindingModel.cs
index f74e8d3..9ea611f 100644
--- a/FishFactoryContracts/BindingModels/OrderBindingModel.cs
+++ b/FishFactoryContracts/BindingModels/OrderBindingModel.cs
@@ -8,7 +8,7 @@ namespace FishFactoryContracts.BindingModels
public int Id { get; set; }
public int CannedId { get; set; }
public int ClientId { get; set; }
- public int ImplementerId { get; }
+ public int? ImplementerId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
diff --git a/FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs
similarity index 91%
rename from FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs
rename to FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs
index ccb10eb..29bad48 100644
--- a/FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs
+++ b/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs
@@ -4,7 +4,7 @@ using FishFactoryContracts.ViewModels;
namespace FishFactoryContracts.BusinessLogicsContracts
{
- public interface IImplementerBusinessLogic
+ public interface IImplementerLogic
{
List? ReadList(ImplementerSearchModel? model);
ImplementerViewModel? ReadElement(ImplementerSearchModel model);
diff --git a/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs
index 958cdc8..c25ffb3 100644
--- a/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs
+++ b/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -12,6 +12,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts
public interface IOrderLogic
{
List? ReadList(OrderSearchModel? model);
+ OrderViewModel? ReadElement(OrderSearchModel model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
///
diff --git a/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs b/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs
new file mode 100644
index 0000000..02501b8
--- /dev/null
+++ b/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs
@@ -0,0 +1,7 @@
+namespace FishFactoryContracts.BusinessLogicsContracts
+{
+ public interface IWorkProcess
+ {
+ void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
+ }
+}
diff --git a/FishFactoryContracts/SearchModels/OrderSearchModel.cs b/FishFactoryContracts/SearchModels/OrderSearchModel.cs
index aea6adc..38b825e 100644
--- a/FishFactoryContracts/SearchModels/OrderSearchModel.cs
+++ b/FishFactoryContracts/SearchModels/OrderSearchModel.cs
@@ -1,10 +1,14 @@
-namespace FishFactoryContracts.SearchModels
+using FishFactoryDataModel.Enums;
+
+namespace FishFactoryContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
public int? ClientId { get; set; }
+ public int? ImplementerId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
+ public OrderStatus? Status { get; set; }
}
}
diff --git a/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactoryContracts/ViewModels/OrderViewModel.cs
index 03c9099..cfe31f5 100644
--- a/FishFactoryContracts/ViewModels/OrderViewModel.cs
+++ b/FishFactoryContracts/ViewModels/OrderViewModel.cs
@@ -15,9 +15,9 @@ namespace FishFactoryContracts.ViewModels
public int ClientId { get; set; }
[DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty;
- public int ImplementerId { get; set; }
+ public int? ImplementerId { get; set; }
[DisplayName("Исполнитель")]
- public string ImplementerFIO { get; set; } = string.Empty;
+ public string? ImplementerFIO { get; set; } = string.Empty;
public int CannedId { get; set; }
[DisplayName("Изделие")]
public string CannedName { get; set; } = string.Empty;
diff --git a/FishFactoryDataModels/Models/IOrderModel.cs b/FishFactoryDataModels/Models/IOrderModel.cs
index d95bdff..67efaac 100644
--- a/FishFactoryDataModels/Models/IOrderModel.cs
+++ b/FishFactoryDataModels/Models/IOrderModel.cs
@@ -6,7 +6,7 @@ namespace FishFactoryDataModel.Models
{
int CannedId { get; }
int ClientId { get; }
- int ImplementerId { get; }
+ int? ImplementerId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
diff --git a/FishFactoryDatabaseImplement/FishFactoryDatabase.cs b/FishFactoryDatabaseImplement/FishFactoryDatabase.cs
index 359e212..48b39f5 100644
--- a/FishFactoryDatabaseImplement/FishFactoryDatabase.cs
+++ b/FishFactoryDatabaseImplement/FishFactoryDatabase.cs
@@ -9,7 +9,7 @@ namespace FishFactoryDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
- optionsBuilder.UseNpgsql(@"Host=localhost;Database=FishFactory2;Username=postgres;Password=postgres");
+ optionsBuilder.UseNpgsql(@"Host=localhost;Database=FishFactory3;Username=postgres;Password=postgres");
}
base.OnConfiguring(optionsBuilder);
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
diff --git a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs
index 285dac7..3c8d2af 100644
--- a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs
+++ b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs
@@ -32,7 +32,8 @@ namespace FishFactoryDatabaseImplement.Implements
}
using var context = new FishFactoryDatabase();
return context.Implementers.FirstOrDefault(x =>
- (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && (!string.IsNullOrEmpty(model.Password) ? x.Password == model.Password : true)) ||
+ (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO &&
+ (!string.IsNullOrEmpty(model.Password) && x.Password == model.Password)) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
diff --git a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs
index dec4a6a..40ca72a 100644
--- a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs
+++ b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs
@@ -30,9 +30,11 @@ namespace FishFactoryDatabaseImplement.Implements
(!model.Id.HasValue || x.Id == model.Id) &&
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo) &&
- (!model.ClientId.HasValue || x.ClientId == model.ClientId))
+ (!model.ClientId.HasValue || x.ClientId == model.ClientId) &&
+ (!model.Status.HasValue || x.Status == model.Status))
.Select(x => x.GetViewModel)
.ToList();
+
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
@@ -45,7 +47,12 @@ namespace FishFactoryDatabaseImplement.Implements
.Include(x => x.Canned)
.Include(x => x.Client)
.Include(x => x.Implementer)
- .FirstOrDefault(x => x.Id == model.Id)
+ .FirstOrDefault(x =>
+ (!model.Id.HasValue || x.Id == model.Id) &&
+ (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
+ (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) &&
+ (!model.ClientId.HasValue || x.ClientId == model.ClientId) &&
+ (!model.Status.HasValue || x.Status == model.Status))
?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
@@ -69,10 +76,10 @@ namespace FishFactoryDatabaseImplement.Implements
try
{
var order = context.Orders
- .Include(o => o.Canned)
- .Include(o => o.Client)
+ .Include(x => x.Canned)
+ .Include(x => x.Client)
.Include(x => x.Implementer)
- .FirstOrDefault(o => o.Id == model.Id);
+ .FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
@@ -92,10 +99,10 @@ namespace FishFactoryDatabaseImplement.Implements
{
using var context = new FishFactoryDatabase();
var element = context.Orders
- .Include(o => o.Canned)
- .Include(o => o.Client)
+ .Include(x => x.Canned)
+ .Include(x => x.Client)
.Include(x => x.Implementer)
- .FirstOrDefault(o => o.Id == model.Id);
+ .FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
diff --git a/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.Designer.cs
new file mode 100644
index 0000000..28f45e9
--- /dev/null
+++ b/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.Designer.cs
@@ -0,0 +1,255 @@
+//
+using System;
+using FishFactoryDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace FishFactoryDatabaseImplement.Migrations
+{
+ [DbContext(typeof(FishFactoryDatabase))]
+ [Migration("20240513132159_initialcreate")]
+ partial class initialcreate
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.16")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("CannedName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Price")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("Canneds");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("CannedId")
+ .HasColumnType("integer");
+
+ b.Property("ComponentId")
+ .HasColumnType("integer");
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("CannedId");
+
+ b.HasIndex("ComponentId");
+
+ b.ToTable("CannedComponents");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Cost")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("CannedId")
+ .HasColumnType("integer");
+
+ b.Property("ClientId")
+ .HasColumnType("integer");
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("DateCreate")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("DateImplement")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("ImplementerId")
+ .IsRequired()
+ .HasColumnType("integer");
+
+ b.Property("Status")
+ .HasColumnType("integer");
+
+ b.Property("Sum")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.HasIndex("CannedId");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("ImplementerId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b =>
+ {
+ b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
+ .WithMany("Components")
+ .HasForeignKey("CannedId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component")
+ .WithMany("CannedComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Canned");
+
+ b.Navigation("Component");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
+ .WithMany("Orders")
+ .HasForeignKey("CannedId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client")
+ .WithMany()
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Order")
+ .HasForeignKey("ImplementerId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Canned");
+
+ b.Navigation("Client");
+
+ b.Navigation("Implementer");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("CannedComponents");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Order");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.cs b/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.cs
similarity index 81%
rename from FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.cs
rename to FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.cs
index 6fb7665..7dd70b9 100644
--- a/FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.cs
+++ b/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.cs
@@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FishFactoryDatabaseImplement.Migrations
{
///
- public partial class initialdatabase : Migration
+ public partial class initialcreate : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
@@ -56,34 +56,19 @@ namespace FishFactoryDatabaseImplement.Migrations
});
migrationBuilder.CreateTable(
- name: "Orders",
+ name: "Implementers",
columns: table => new
{
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
- CannedId = table.Column(type: "integer", nullable: false),
- ClientId = table.Column(type: "integer", nullable: false),
- Count = table.Column(type: "integer", nullable: false),
- Sum = table.Column(type: "double precision", nullable: false),
- Status = table.Column(type: "integer", nullable: false),
- DateCreate = table.Column(type: "timestamp without time zone", nullable: false),
- DateImplement = table.Column(type: "timestamp without time zone", nullable: true)
+ ImplementerFIO = table.Column(type: "text", nullable: false),
+ Password = table.Column(type: "text", nullable: false),
+ WorkExperience = table.Column(type: "integer", nullable: false),
+ Qualification = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
- table.PrimaryKey("PK_Orders", x => x.Id);
- table.ForeignKey(
- name: "FK_Orders_Canneds_CannedId",
- column: x => x.CannedId,
- principalTable: "Canneds",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
- table.ForeignKey(
- name: "FK_Orders_Clients_ClientId",
- column: x => x.ClientId,
- principalTable: "Clients",
- principalColumn: "Id",
- onDelete: ReferentialAction.Cascade);
+ table.PrimaryKey("PK_Implementers", x => x.Id);
});
migrationBuilder.CreateTable(
@@ -113,6 +98,44 @@ namespace FishFactoryDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
+ migrationBuilder.CreateTable(
+ name: "Orders",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ CannedId = table.Column(type: "integer", nullable: false),
+ ClientId = table.Column(type: "integer", nullable: false),
+ ImplementerId = table.Column(type: "integer", nullable: false),
+ Count = table.Column(type: "integer", nullable: false),
+ Sum = table.Column(type: "double precision", nullable: false),
+ Status = table.Column(type: "integer", nullable: false),
+ DateCreate = table.Column(type: "timestamp without time zone", nullable: false),
+ DateImplement = table.Column(type: "timestamp without time zone", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Orders", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Orders_Canneds_CannedId",
+ column: x => x.CannedId,
+ principalTable: "Canneds",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_Orders_Clients_ClientId",
+ column: x => x.ClientId,
+ principalTable: "Clients",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ column: x => x.ImplementerId,
+ principalTable: "Implementers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
migrationBuilder.CreateIndex(
name: "IX_CannedComponents_CannedId",
table: "CannedComponents",
@@ -132,6 +155,11 @@ namespace FishFactoryDatabaseImplement.Migrations
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId");
}
///
@@ -151,6 +179,9 @@ namespace FishFactoryDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Clients");
+
+ migrationBuilder.DropTable(
+ name: "Implementers");
}
}
}
diff --git a/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.Designer.cs
new file mode 100644
index 0000000..047d932
--- /dev/null
+++ b/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.Designer.cs
@@ -0,0 +1,255 @@
+//
+using System;
+using FishFactoryDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace FishFactoryDatabaseImplement.Migrations
+{
+ [DbContext(typeof(FishFactoryDatabase))]
+ [Migration("20240513152048_add_implementer")]
+ partial class add_implementer
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.16")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("CannedName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Price")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("Canneds");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("CannedId")
+ .HasColumnType("integer");
+
+ b.Property("ComponentId")
+ .HasColumnType("integer");
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("CannedId");
+
+ b.HasIndex("ComponentId");
+
+ b.ToTable("CannedComponents");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Cost")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("CannedId")
+ .HasColumnType("integer");
+
+ b.Property("ClientId")
+ .HasColumnType("integer");
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("DateCreate")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("DateImplement")
+ .HasColumnType("timestamp without time zone");
+
+ b.Property("ImplementerId")
+ .IsRequired()
+ .HasColumnType("integer");
+
+ b.Property("Status")
+ .HasColumnType("integer");
+
+ b.Property("Sum")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.HasIndex("CannedId");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("ImplementerId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b =>
+ {
+ b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
+ .WithMany("Components")
+ .HasForeignKey("CannedId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component")
+ .WithMany("CannedComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Canned");
+
+ b.Navigation("Component");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned")
+ .WithMany("Orders")
+ .HasForeignKey("CannedId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client")
+ .WithMany()
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Order")
+ .HasForeignKey("ImplementerId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Canned");
+
+ b.Navigation("Client");
+
+ b.Navigation("Implementer");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("CannedComponents");
+ });
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Order");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.cs b/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.cs
new file mode 100644
index 0000000..0077077
--- /dev/null
+++ b/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.cs
@@ -0,0 +1,22 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace FishFactoryDatabaseImplement.Migrations
+{
+ ///
+ public partial class add_implementer : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
diff --git a/FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240513170412_create.Designer.cs
similarity index 82%
rename from FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.Designer.cs
rename to FishFactoryDatabaseImplement/Migrations/20240513170412_create.Designer.cs
index eff9cb5..982acdf 100644
--- a/FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.Designer.cs
+++ b/FishFactoryDatabaseImplement/Migrations/20240513170412_create.Designer.cs
@@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FishFactoryDatabaseImplement.Migrations
{
[DbContext(typeof(FishFactoryDatabase))]
- [Migration("20240509142302_initialdatabase")]
- partial class initialdatabase
+ [Migration("20240513170412_create")]
+ partial class create
{
///
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -116,6 +116,33 @@ namespace FishFactoryDatabaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
{
b.Property("Id")
@@ -139,6 +166,9 @@ namespace FishFactoryDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("timestamp without time zone");
+ b.Property("ImplementerId")
+ .HasColumnType("integer");
+
b.Property("Status")
.HasColumnType("integer");
@@ -151,6 +181,8 @@ namespace FishFactoryDatabaseImplement.Migrations
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.ToTable("Orders");
});
@@ -187,9 +219,15 @@ namespace FishFactoryDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Order")
+ .HasForeignKey("ImplementerId");
+
b.Navigation("Canned");
b.Navigation("Client");
+
+ b.Navigation("Implementer");
});
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
@@ -203,6 +241,11 @@ namespace FishFactoryDatabaseImplement.Migrations
{
b.Navigation("CannedComponents");
});
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Order");
+ });
#pragma warning restore 612, 618
}
}
diff --git a/FishFactoryDatabaseImplement/Migrations/20240513170412_create.cs b/FishFactoryDatabaseImplement/Migrations/20240513170412_create.cs
new file mode 100644
index 0000000..c4820f4
--- /dev/null
+++ b/FishFactoryDatabaseImplement/Migrations/20240513170412_create.cs
@@ -0,0 +1,59 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace FishFactoryDatabaseImplement.Migrations
+{
+ ///
+ public partial class create : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders");
+
+ migrationBuilder.AlterColumn(
+ name: "ImplementerId",
+ table: "Orders",
+ type: "integer",
+ nullable: true,
+ oldClrType: typeof(int),
+ oldType: "integer");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId",
+ principalTable: "Implementers",
+ principalColumn: "Id");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders");
+
+ migrationBuilder.AlterColumn(
+ name: "ImplementerId",
+ table: "Orders",
+ type: "integer",
+ nullable: false,
+ defaultValue: 0,
+ oldClrType: typeof(int),
+ oldType: "integer",
+ oldNullable: true);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId",
+ principalTable: "Implementers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+ }
+}
diff --git a/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs b/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs
index 65babc2..06bf944 100644
--- a/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs
+++ b/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs
@@ -113,6 +113,33 @@ namespace FishFactoryDatabaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b =>
{
b.Property("Id")
@@ -136,6 +163,9 @@ namespace FishFactoryDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("timestamp without time zone");
+ b.Property("ImplementerId")
+ .HasColumnType("integer");
+
b.Property("Status")
.HasColumnType("integer");
@@ -148,6 +178,8 @@ namespace FishFactoryDatabaseImplement.Migrations
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.ToTable("Orders");
});
@@ -184,9 +216,15 @@ namespace FishFactoryDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Order")
+ .HasForeignKey("ImplementerId");
+
b.Navigation("Canned");
b.Navigation("Client");
+
+ b.Navigation("Implementer");
});
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
@@ -200,6 +238,11 @@ namespace FishFactoryDatabaseImplement.Migrations
{
b.Navigation("CannedComponents");
});
+
+ modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Order");
+ });
#pragma warning restore 612, 618
}
}
diff --git a/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactoryDatabaseImplement/Models/Implementer.cs
index 55dde5e..efd595b 100644
--- a/FishFactoryDatabaseImplement/Models/Implementer.cs
+++ b/FishFactoryDatabaseImplement/Models/Implementer.cs
@@ -53,7 +53,7 @@ namespace FishFactoryDatabaseImplement.Models
ImplementerFIO = ImplementerFIO,
Password = Password,
Qualification = Qualification,
- ImplementerFIO = ImplementerFIO,
+ WorkExperience = WorkExperience,
};
}
}
diff --git a/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactoryDatabaseImplement/Models/Order.cs
index 495aefe..6dd1c23 100644
--- a/FishFactoryDatabaseImplement/Models/Order.cs
+++ b/FishFactoryDatabaseImplement/Models/Order.cs
@@ -1,5 +1,4 @@
-using System.ComponentModel.DataAnnotations.Schema;
-using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations;
using FishFactoryDataModel.Enums;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
@@ -12,15 +11,14 @@ namespace FishFactoryDatabaseImplement.Models
public int Id { get; private set; }
[Required]
public int CannedId { get; private set; }
- public virtual Canned Canned { get; set; } = new();
+ public virtual Canned Canned { get; set; }
[Required]
public int ClientId { get; private set; }
- public virtual Client Client { get; set; } = new();
+ public virtual Client Client { get; set; }
- [Required]
- public int ImplementerId { get; private set; }
- public virtual Implementer Implementer { get; set; } = new();
+ public int? ImplementerId { get; private set; }
+ public virtual Implementer? Implementer { get; set; } = new();
[Required]
public int Count { get; private set; }
@@ -41,7 +39,7 @@ namespace FishFactoryDatabaseImplement.Models
ClientId = model.ClientId,
Client = context.Clients.First(x => x.Id == model.ClientId),
ImplementerId = model.ImplementerId,
- Implementer = context.Implementers.First(x => x.Id == model.ImplementerId),
+ Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@@ -55,10 +53,13 @@ namespace FishFactoryDatabaseImplement.Models
{
return;
}
+ using var context = new FishFactoryDatabase();
+
Id = model.Id;
CannedId = model.CannedId;
ClientId = model.ClientId;
ImplementerId = model.ImplementerId;
+ Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
@@ -72,7 +73,7 @@ namespace FishFactoryDatabaseImplement.Models
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
ImplementerId = ImplementerId,
- ImplementerFIO = Implementer.ImplementerFIO,
+ ImplementerFIO = Implementer?.ImplementerFIO,
Count = Count,
Sum = Sum,
Status = Status,
diff --git a/FishFactoryFileImplement/Models/Implementer.cs b/FishFactoryFileImplement/Models/Implementer.cs
index 9469378..99afe6d 100644
--- a/FishFactoryFileImplement/Models/Implementer.cs
+++ b/FishFactoryFileImplement/Models/Implementer.cs
@@ -1,6 +1,7 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Models;
+using System.Reflection;
using System.Xml.Linq;
namespace FishFactoryFileImplement.Models
@@ -17,6 +18,22 @@ namespace FishFactoryFileImplement.Models
public int Qualification { 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)
@@ -51,7 +68,7 @@ namespace FishFactoryFileImplement.Models
Password = Password,
ImplementerFIO = ImplementerFIO,
Qualification = Qualification,
- ImplementerFIO = ImplementerFIO,
+ WorkExperience = WorkExperience
};
public XElement GetXElement => new("Implementer",
diff --git a/FishFactoryFileImplement/Models/Order.cs b/FishFactoryFileImplement/Models/Order.cs
index e7aa048..f308eea 100644
--- a/FishFactoryFileImplement/Models/Order.cs
+++ b/FishFactoryFileImplement/Models/Order.cs
@@ -11,7 +11,7 @@ namespace FishFactoryFileImplement.Models
public int Id { get; private set; }
public int CannedId { get; private set; }
public int ClientId { get; private set; }
- public int ImplementerId { get; set; }
+ public int? ImplementerId { get; set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; }
diff --git a/FishFactoryListImplement/Models/Implementer.cs b/FishFactoryListImplement/Models/Implementer.cs
index 4530cce..951eb1e 100644
--- a/FishFactoryListImplement/Models/Implementer.cs
+++ b/FishFactoryListImplement/Models/Implementer.cs
@@ -1,6 +1,7 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Models;
+using System.Reflection;
namespace FishFactoryListImplement.Models
{
@@ -50,7 +51,7 @@ namespace FishFactoryListImplement.Models
Password = Password,
ImplementerFIO = ImplementerFIO,
Qualification = Qualification,
- ImplementerFIO = ImplementerFIO,
+ WorkExperience = WorkExperience
};
}
}
diff --git a/FishFactoryListImplement/Models/Order.cs b/FishFactoryListImplement/Models/Order.cs
index 6b31f26..e1bf253 100644
--- a/FishFactoryListImplement/Models/Order.cs
+++ b/FishFactoryListImplement/Models/Order.cs
@@ -2,7 +2,6 @@
using FishFactoryContracts.ViewModels;
using FishFactoryDataModel.Enums;
using FishFactoryDataModel.Models;
-using System.Reflection;
namespace FishFactoryListImplement.Models
{
@@ -55,7 +54,7 @@ namespace FishFactoryListImplement.Models
Id = Id,
CannedId = CannedId,
ClientId = ClientId,
- ImplementerId = model.ImplementerId,
+ ImplementerId = ImplementerId,
Count = Count,
Sum = Sum,
Status = Status,
diff --git a/FishFactoryRestApi/Controllers/ImplementerController.cs b/FishFactoryRestApi/Controllers/ImplementerController.cs
new file mode 100644
index 0000000..2a20029
--- /dev/null
+++ b/FishFactoryRestApi/Controllers/ImplementerController.cs
@@ -0,0 +1,99 @@
+using FishFactoryContracts.BindingModels;
+using FishFactoryContracts.BusinessLogicsContracts;
+using FishFactoryContracts.SearchModels;
+using FishFactoryContracts.ViewModels;
+using FishFactoryDataModel.Enums;
+using Microsoft.AspNetCore.Mvc;
+
+namespace FishFactoryRestApi.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;
+ }
+ }
+ }
+}