From 7f8c26b70649318ae79667ec74ffa717d43cc087 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Mon, 10 Apr 2023 22:52:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A7=D1=82=D0=BE=20=D1=82=D0=BE=20=D1=81?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FishFactory/FormImplementer.Designer.cs | 172 ++++++++++++++++++ FishFactory/FishFactory/FormImplementer.cs | 108 +++++++++++ FishFactory/FishFactory/FormImplementer.resx | 60 ++++++ .../FishFactory/FormImplementers.Designer.cs | 118 ++++++++++++ FishFactory/FishFactory/FormImplementers.cs | 112 ++++++++++++ FishFactory/FishFactory/FormImplementers.resx | 60 ++++++ FishFactory/FishFactory/FormMain.Designer.cs | 52 +++--- FishFactory/FishFactory/FormMain.cs | 81 ++------- FishFactory/FishFactory/Program.cs | 6 + .../BusinessLogic/ImplementerLogic.cs | 121 ++++++++++++ .../BusinessLogic/WorkModeling.cs | 145 +++++++++++++++ .../BindingModels/ImplementerBindingModel.cs | 18 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 20 ++ .../BusinessLogicsContracts/IWorkProcess.cs | 13 ++ .../SearchModels/ImplementerSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 21 +++ .../ViewModels/ImplementerViewModel.cs | 27 +++ .../ViewModels/OrderViewModel.cs | 3 + .../IImplementerModel.cs | 16 ++ .../FishFactoryDataModels/IOrderModel.cs | 1 + .../FishFactoryDatabase.cs | 1 + .../Implements/ImplementerStorage.cs | 106 +++++++++++ .../Models/Implementer.cs | 80 ++++++++ .../Models/Order.cs | 7 + .../FishFactoryFileImplement/Models/Order.cs | 1 + .../DataListSingleton.cs | 3 + .../Models/Implementer.cs | 60 ++++++ .../FishFactoryListImplement/Models/Order.cs | 2 + 30 files changed, 1341 insertions(+), 94 deletions(-) create mode 100644 FishFactory/FishFactory/FormImplementer.Designer.cs create mode 100644 FishFactory/FishFactory/FormImplementer.cs create mode 100644 FishFactory/FishFactory/FormImplementer.resx create mode 100644 FishFactory/FishFactory/FormImplementers.Designer.cs create mode 100644 FishFactory/FishFactory/FormImplementers.cs create mode 100644 FishFactory/FishFactory/FormImplementers.resx create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs create mode 100644 FishFactory/FishFactoryDataModels/IImplementerModel.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Implementer.cs diff --git a/FishFactory/FishFactory/FormImplementer.Designer.cs b/FishFactory/FishFactory/FormImplementer.Designer.cs new file mode 100644 index 0000000..0c73bdb --- /dev/null +++ b/FishFactory/FishFactory/FormImplementer.Designer.cs @@ -0,0 +1,172 @@ +namespace FishFactoryView +{ + 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.textBoxFio = new System.Windows.Forms.TextBox(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxStage = new System.Windows.Forms.TextBox(); + this.textBoxCval = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 17); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(37, 15); + this.label1.TabIndex = 0; + this.label1.Text = "ФИО:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(6, 46); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(52, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Пароль:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 75); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(82, 15); + this.label3.TabIndex = 2; + this.label3.Text = "Стаж работы:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(178, 75); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(91, 15); + this.label4.TabIndex = 3; + this.label4.Text = "Квалификация:"; + // + // textBoxFio + // + this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxFio.Location = new System.Drawing.Point(94, 9); + this.textBoxFio.Name = "textBoxFio"; + this.textBoxFio.Size = new System.Drawing.Size(297, 23); + this.textBoxFio.TabIndex = 4; + // + // textBoxPassword + // + this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxPassword.Location = new System.Drawing.Point(94, 38); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.PasswordChar = '*'; + this.textBoxPassword.Size = new System.Drawing.Size(297, 23); + this.textBoxPassword.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(302, 96); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(89, 33); + this.buttonCancel.TabIndex = 8; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(207, 96); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(89, 33); + this.buttonSave.TabIndex = 9; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + // + // textBoxStage + // + this.textBoxStage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxStage.Location = new System.Drawing.Point(94, 67); + this.textBoxStage.Name = "textBoxStage"; + this.textBoxStage.Size = new System.Drawing.Size(71, 23); + this.textBoxStage.TabIndex = 10; + // + // textBoxCval + // + this.textBoxCval.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxCval.Location = new System.Drawing.Point(275, 67); + this.textBoxCval.Name = "textBoxCval"; + this.textBoxCval.Size = new System.Drawing.Size(116, 23); + this.textBoxCval.TabIndex = 11; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.ClientSize = new System.Drawing.Size(403, 174); + this.Controls.Add(this.textBoxCval); + this.Controls.Add(this.textBoxStage); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFio); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private TextBox textBoxFio; + private TextBox textBoxPassword; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxStage; + private TextBox textBoxCval; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactory/FormImplementer.cs b/FishFactory/FishFactory/FormImplementer.cs new file mode 100644 index 0000000..91b1f2e --- /dev/null +++ b/FishFactory/FishFactory/FormImplementer.cs @@ -0,0 +1,108 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.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 FishFactoryView +{ + 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; + textBoxStage.Text = view.Qualification.ToString(); + textBoxCval.Text = view.WorkExperience.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(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFio.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFio.Text, + Password = textBoxPassword.Text, + Qualification = int.Parse(textBoxStage.Text), + WorkExperience = int.Parse(textBoxCval.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/FishFactory/FormImplementer.resx b/FishFactory/FishFactory/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactory/FormImplementer.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/FishFactory/FormImplementers.Designer.cs b/FishFactory/FishFactory/FormImplementers.Designer.cs new file mode 100644 index 0000000..da7a465 --- /dev/null +++ b/FishFactory/FishFactory/FormImplementers.Designer.cs @@ -0,0 +1,118 @@ +namespace FishFactoryView +{ + 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.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRef.Location = new System.Drawing.Point(575, 127); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(90, 37); + this.buttonRef.TabIndex = 9; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + // + // buttonDel + // + this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDel.Location = new System.Drawing.Point(575, 88); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(90, 33); + this.buttonDel.TabIndex = 8; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + // + // buttonUpd + // + this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUpd.Location = new System.Drawing.Point(575, 48); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(90, 34); + this.buttonUpd.TabIndex = 7; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + // + // buttonAdd + // + this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAdd.Location = new System.Drawing.Point(575, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(90, 30); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(557, 302); + this.dataGridView.TabIndex = 5; + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(677, 319); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + 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 Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactory/FormImplementers.cs b/FishFactory/FishFactory/FormImplementers.cs new file mode 100644 index 0000000..141e142 --- /dev/null +++ b/FishFactory/FishFactory/FormImplementers.cs @@ -0,0 +1,112 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using ProjectFishFactory; +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 FishFactoryView +{ + 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 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/FishFactory/FormImplementers.resx b/FishFactory/FishFactory/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FishFactory/FishFactory/FormImplementers.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/FishFactory/FormMain.Designer.cs b/FishFactory/FishFactory/FormMain.Designer.cs index de191e5..35043d7 100644 --- a/FishFactory/FishFactory/FormMain.Designer.cs +++ b/FishFactory/FishFactory/FormMain.Designer.cs @@ -30,8 +30,6 @@ { this.dataGridView = new System.Windows.Forms.DataGridView(); this.ButtonCreateOrder = new System.Windows.Forms.Button(); - this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); - this.ButtonOrderReady = new System.Windows.Forms.Button(); this.ButtonIssuedOrder = new System.Windows.Forms.Button(); this.ButtonRef = new System.Windows.Forms.Button(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -43,6 +41,8 @@ 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.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -67,29 +67,9 @@ this.ButtonCreateOrder.UseVisualStyleBackColor = true; this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); // - // ButtonTakeOrderInWork - // - this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(786, 83); - this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(186, 23); - this.ButtonTakeOrderInWork.TabIndex = 2; - this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // ButtonOrderReady - // - this.ButtonOrderReady.Location = new System.Drawing.Point(786, 137); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(186, 23); - this.ButtonOrderReady.TabIndex = 3; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // // ButtonIssuedOrder // - this.ButtonIssuedOrder.Location = new System.Drawing.Point(786, 194); + this.ButtonIssuedOrder.Location = new System.Drawing.Point(786, 88); this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; this.ButtonIssuedOrder.Size = new System.Drawing.Size(186, 23); this.ButtonIssuedOrder.TabIndex = 4; @@ -99,7 +79,7 @@ // // ButtonRef // - this.ButtonRef.Location = new System.Drawing.Point(786, 250); + this.ButtonRef.Location = new System.Drawing.Point(786, 144); this.ButtonRef.Name = "ButtonRef"; this.ButtonRef.Size = new System.Drawing.Size(186, 23); this.ButtonRef.TabIndex = 5; @@ -136,7 +116,9 @@ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.изделияToolStripMenuItem, this.отчетыToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); @@ -182,6 +164,20 @@ this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -189,8 +185,6 @@ this.ClientSize = new System.Drawing.Size(978, 446); this.Controls.Add(this.ButtonRef); this.Controls.Add(this.ButtonIssuedOrder); - this.Controls.Add(this.ButtonOrderReady); - this.Controls.Add(this.ButtonTakeOrderInWork); this.Controls.Add(this.ButtonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); @@ -209,8 +203,6 @@ #endregion private DataGridView dataGridView; private Button ButtonCreateOrder; - private Button ButtonTakeOrderInWork; - private Button ButtonOrderReady; private Button ButtonIssuedOrder; private Button ButtonRef; private ToolStripMenuItem изделияToolStripMenuItem; @@ -222,5 +214,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/FishFactory/FishFactory/FormMain.cs b/FishFactory/FishFactory/FormMain.cs index 61ef7fa..2360827 100644 --- a/FishFactory/FishFactory/FormMain.cs +++ b/FishFactory/FishFactory/FormMain.cs @@ -23,12 +23,14 @@ namespace FishFactoryView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + 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) { @@ -81,69 +83,7 @@ namespace FishFactoryView 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 - /*CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), - *//*CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].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) - { - 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, - CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), - /*CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].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) - { - 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) @@ -157,7 +97,6 @@ namespace FishFactoryView { Id = id, CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), - /*CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].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()), @@ -222,5 +161,19 @@ namespace FishFactoryView 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 запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + } } } diff --git a/FishFactory/FishFactory/Program.cs b/FishFactory/FishFactory/Program.cs index 3ae4266..aefabff 100644 --- a/FishFactory/FishFactory/Program.cs +++ b/FishFactory/FishFactory/Program.cs @@ -41,11 +41,15 @@ namespace ProjectFishFactory 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(); @@ -61,6 +65,8 @@ namespace ProjectFishFactory services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..556c2c4 --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,121 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +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 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. ImplementerFIO:{ImplementerFIO}. 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. ImplementerFIO:{ImplementerFIO}. 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 (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + if (model.Qualification <= 0) + { + throw new ArgumentNullException("Квалификация не может быть меньше 0", nameof(model.Qualification)); + } + if (model.WorkExperience <= 0) + { + throw new ArgumentNullException("Стаж работы не модет былть меньше 0", nameof(model.WorkExperience)); + } + _logger.LogInformation("Implementer. ImplementerID:{Id}. ImplementerFIO: {ImplementerFIO}. Password: { Password}. Qualification: {Qualification}. WorkExperience: {WorkExperience}", model.Id, model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой исполнитель уже существует"); + } + + } + } +} diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..d751c9c --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,145 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.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 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.Принят*/ + }); + 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); + 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.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/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..1530f79 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,18 @@ +using FishFactoryDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs index 73975ee..232dfe8 100644 --- a/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs +++ b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,7 @@ namespace FishFactoryContracts.BindingModels public int Id { get; set; } public int CannedId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..4168a02 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..cf878c0 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..d097862 --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs index ed03b0b..17ca48f 100644 --- a/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs +++ b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using FishFactoryDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace FishFactoryContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public List? Statusses { get; set; } } } diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..e5fe382 --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..a14a1ae --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using FishFactoryDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.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/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs index e1d8711..4129795 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -30,5 +30,8 @@ namespace FishFactoryContracts.ViewModels [DisplayName("Фамилия клиента")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; } } diff --git a/FishFactory/FishFactoryDataModels/IImplementerModel.cs b/FishFactory/FishFactoryDataModels/IImplementerModel.cs new file mode 100644 index 0000000..dcc8dbc --- /dev/null +++ b/FishFactory/FishFactoryDataModels/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryDataModels +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/FishFactory/FishFactoryDataModels/IOrderModel.cs b/FishFactory/FishFactoryDataModels/IOrderModel.cs index 583fcee..ff0fcad 100644 --- a/FishFactory/FishFactoryDataModels/IOrderModel.cs +++ b/FishFactory/FishFactoryDataModels/IOrderModel.cs @@ -12,6 +12,7 @@ namespace FishFactoryDataModels.Models { int CannedId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs index 8f351d7..242e900 100644 --- a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs +++ b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs @@ -24,5 +24,6 @@ namespace FishFactoryDatabaseImplement public virtual DbSet CannedComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs b/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..18092cc --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,106 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var element = context.Implementers + .Include(x => x.Orders) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new FishFactoryDatabase(); + if (model.Id.HasValue) + { + return context.Implementers + .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + return context.Implementers + .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password))?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO)) + { + return context.Implementers + .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO))?.GetViewModel; + } + return new(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (!string.IsNullOrEmpty(model.ImplementerFIO)) + { + using var context = new FishFactoryDatabase(); + return context.Implementers + .Include(x => x.Orders) + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new FishFactoryDatabase(); + return context.Implementers + .Include(x => x.Orders) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new FishFactoryDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var client = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + context.SaveChanges(); + return client.GetViewModel; + } + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..b628dc2 --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,80 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels; +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 FishFactoryDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + [Required] + public string ImplementerFIO { get; set; } = String.Empty; + + [Required] + public string Password { get; set; } = String.Empty; + + [Required] + public int WorkExperience { get; set; } + + [Required] + public int Qualification { get; set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public static Implementer Create(ImplementerViewModel model) + { + return new Implementer + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs index cff5b55..d8d0056 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs @@ -20,6 +20,8 @@ namespace FishFactoryDatabaseImplement.Models [Required] public int ClientId { get; set; } [Required] + public int? ImplementerId { get; set; } + [Required] public int Count { get; set; } [Required] public double Sum { get; set; } @@ -30,6 +32,7 @@ namespace FishFactoryDatabaseImplement.Models public DateTime? DateImplement { get; set; } public virtual Canned Canned { get; set; } + public virtual Implementer? Implementer { get; set; } public virtual Client Client { get; set; } public int Id { get; set; } @@ -44,6 +47,7 @@ namespace FishFactoryDatabaseImplement.Models Id = model.Id, CannedId = model.CannedId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -59,6 +63,7 @@ namespace FishFactoryDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -66,6 +71,8 @@ namespace FishFactoryDatabaseImplement.Models Id = Id, CannedId = CannedId, ClientId = ClientId, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, ClientFIO = Client.ClientFIO, Count = Count, Sum = Sum, diff --git a/FishFactory/FishFactoryFileImplement/Models/Order.cs b/FishFactory/FishFactoryFileImplement/Models/Order.cs index 7e0ec53..4051894 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Order.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Order.cs @@ -26,6 +26,7 @@ namespace FishFactoryFileImplement.Models public DateTime? DateImplement { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public static Order? Create(OrderBindingModel? model) { diff --git a/FishFactory/FishFactoryListImplement/DataListSingleton.cs b/FishFactory/FishFactoryListImplement/DataListSingleton.cs index 8161db2..08c9428 100644 --- a/FishFactory/FishFactoryListImplement/DataListSingleton.cs +++ b/FishFactory/FishFactoryListImplement/DataListSingleton.cs @@ -14,12 +14,15 @@ namespace FishFactoryListImplement public List Orders { get; set; } public List Canneds { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Canneds = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/FishFactory/FishFactoryListImplement/Models/Implementer.cs b/FishFactory/FishFactoryListImplement/Models/Implementer.cs new file mode 100644 index 0000000..d2a8edd --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Implementer.cs @@ -0,0 +1,60 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + 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 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, + }; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryListImplement/Models/Order.cs b/FishFactory/FishFactoryListImplement/Models/Order.cs index c136e96..d47711f 100644 --- a/FishFactory/FishFactoryListImplement/Models/Order.cs +++ b/FishFactory/FishFactoryListImplement/Models/Order.cs @@ -27,6 +27,8 @@ namespace FishFactoryListImplement.Models public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + public static Order? Create(OrderBindingModel? model) { if (model == null)