From 541c3de44226fa35ff7254522d0667f91e23db0e Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Sun, 5 May 2024 23:58:51 +0400 Subject: [PATCH 1/3] enough --- .../FormCreateImplementer.Designer.cs | 166 ++++++++++++ .../FormCreateImplementer.cs | 109 ++++++++ .../FormCreateImplementer.resx | 120 +++++++++ .../FormCreateOrder.Designer.cs | 180 ++++++++----- .../FurnitureAssembly/FormCreateOrder.cs | 43 ++- .../FurnitureAssembly/FormCreateOrder.resx | 62 ++++- .../FormImplementers.Designer.cs | 114 ++++++++ .../FurnitureAssembly/FormImplementers.cs | 120 +++++++++ .../FurnitureAssembly/FormImplementers.resx | 120 +++++++++ .../FurnitureAssembly/FormMain.Designer.cs | 62 ++--- .../FurnitureAssembly/FormMain.cs | 20 +- .../FurnitureAssembly/Program.cs | 5 + .../BusinessLogic/ImplementerLogic.cs | 131 +++++++++ .../BusinessLogic/OrderLogic.cs | 16 ++ .../BusinessLogic/WorkModeling.cs | 156 +++++++++++ .../FurnitureLogic.cs | 147 ---------- .../OrderLogic.cs | 158 ----------- .../WorkpieceLogic.cs | 111 -------- .../BindingModels/ImplementerBindingModel.cs | 18 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 13 + .../SearchModels/ImplementerSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 21 ++ .../ViewModels/ImplementerViewModel.cs | 23 ++ .../ViewModels/OrderViewModel.cs | 3 + .../Models/IImplementerModel.cs | 16 ++ .../Models/IOrderModel.cs | 1 + .../FurnitureAssemblyDatabase.cs | 4 +- .../Implements/ImplementerStorage.cs | 101 +++++++ .../Implements/OrderStorage.cs | 43 ++- .../20240505193918_lab6.Designer.cs | 252 ++++++++++++++++++ .../Migrations/20240505193918_lab6.cs | 68 +++++ .../FurnitureAssemblyDatabaseModelSnapshot.cs | 45 +++- .../Models/Implementer.cs | 65 +++++ .../Models/Order.cs | 11 +- .../DataFileSingleton.cs | 9 +- .../Implements/ImplementerStorage.cs | 104 ++++++++ .../Implements/OrderStorage.cs | 51 ++-- .../Models/Implementer.cs | 84 ++++++ .../Models/Order.cs | 14 +- .../DataListSingleton.cs | 2 + .../FurnitureAssemblyListImplement.csproj | 1 + .../Implements/ImplementerStorage.cs | 122 +++++++++ .../Implements/OrderStorage.cs | 104 +++----- .../Models/Implementer.cs | 59 ++++ .../Models/Order.cs | 9 +- .../Controllers/ImplementerController.cs | 102 +++++++ 50 files changed, 2563 insertions(+), 664 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.resx create mode 100644 FurnitureAssembly/FurnitureAssembly/FormImplementers.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormImplementers.cs create mode 100644 FurnitureAssembly/FurnitureAssembly/FormImplementers.resx create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/ImplementerLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/WorkModeling.cs delete mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureLogic.cs delete mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs delete mode 100644 FurnitureAssembly/FurnitureAssemblyBusinessLogic/WorkpieceLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDataModels/Models/IImplementerModel.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240505193918_lab6.Designer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240505193918_lab6.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ImplementerStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Implementer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ImplementerStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyListImplement/Models/Implementer.cs create mode 100644 FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ImplementerController.cs diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.Designer.cs new file mode 100644 index 0000000..3ee2fdf --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.Designer.cs @@ -0,0 +1,166 @@ +namespace FurnitureAssemblyView +{ + partial class FormCreateImplementer + { + /// + /// 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() + { + numericUpDownQual = new NumericUpDown(); + numericUpDownWE = new NumericUpDown(); + label3 = new Label(); + label2 = new Label(); + label1 = new Label(); + labelName = new Label(); + textBoxPassword = new TextBox(); + textBoxFIO = new TextBox(); + ButtonCancel = new Button(); + ButtonSave = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownQual).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWE).BeginInit(); + SuspendLayout(); + // + // numericUpDownQual + // + numericUpDownQual.Location = new Point(268, 94); + numericUpDownQual.Name = "numericUpDownQual"; + numericUpDownQual.Size = new Size(80, 23); + numericUpDownQual.TabIndex = 37; + // + // numericUpDownWE + // + numericUpDownWE.Location = new Point(92, 94); + numericUpDownWE.Name = "numericUpDownWE"; + numericUpDownWE.Size = new Size(61, 23); + numericUpDownWE.TabIndex = 36; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(174, 96); + label3.Name = "label3"; + label3.Size = new Size(88, 15); + label3.TabIndex = 35; + label3.Text = "Квалификация"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(9, 96); + label2.Name = "label2"; + label2.Size = new Size(79, 15); + label2.TabIndex = 34; + label2.Text = "Стаж работы"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(9, 56); + label1.Name = "label1"; + label1.Size = new Size(49, 15); + label1.TabIndex = 33; + label1.Text = "Пароль"; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(9, 15); + labelName.Name = "labelName"; + labelName.Size = new Size(34, 15); + labelName.TabIndex = 32; + labelName.Text = "ФИО"; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(67, 53); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(281, 23); + textBoxPassword.TabIndex = 31; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(67, 12); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(281, 23); + textBoxFIO.TabIndex = 30; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(273, 131); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(75, 23); + ButtonCancel.TabIndex = 29; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // ButtonSave + // + ButtonSave.Location = new Point(174, 131); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(75, 23); + ButtonSave.TabIndex = 28; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // FormCreateImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(365, 170); + Controls.Add(numericUpDownQual); + Controls.Add(numericUpDownWE); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(labelName); + Controls.Add(textBoxPassword); + Controls.Add(textBoxFIO); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Name = "FormCreateImplementer"; + Text = "Создать исполнителя"; + Load += ImplementerForm_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownQual).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWE).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private NumericUpDown numericUpDownQual; + private NumericUpDown numericUpDownWE; + private Label label3; + private Label label2; + private Label label1; + private Label labelName; + private TextBox textBoxPassword; + private TextBox textBoxFIO; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.cs new file mode 100644 index 0000000..76ddf8c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.cs @@ -0,0 +1,109 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.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 FurnitureAssemblyView +{ + public partial class FormCreateImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormCreateImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ImplementerForm_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; + numericUpDownWE.Value = view.WorkExperience; + numericUpDownQual.Value = view.Qualification; + } + } + 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(numericUpDownWE.Value), + Qualification = Convert.ToInt32(numericUpDownQual.Value), + + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.resx b/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateImplementer.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/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.Designer.cs index 1dd1ebe..c46553e 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.Designer.cs @@ -28,107 +28,137 @@ /// private void InitializeComponent() { - this.ButtonSave = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.comboBoxFurniture = new System.Windows.Forms.ComboBox(); - this.textBoxCount = new System.Windows.Forms.TextBox(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.textBoxSum = new System.Windows.Forms.TextBox(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.SuspendLayout(); + ButtonSave = new Button(); + label1 = new Label(); + comboBoxFurniture = new ComboBox(); + textBoxCount = new TextBox(); + label2 = new Label(); + label3 = new Label(); + textBoxSum = new TextBox(); + ButtonCancel = new Button(); + clientBox = new ComboBox(); + clientLabel = new Label(); + SuspendLayout(); // // ButtonSave // - this.ButtonSave.Location = new System.Drawing.Point(313, 212); - this.ButtonSave.Name = "ButtonSave"; - this.ButtonSave.Size = new System.Drawing.Size(150, 46); - this.ButtonSave.TabIndex = 0; - this.ButtonSave.Text = "Сохранить"; - this.ButtonSave.UseVisualStyleBackColor = true; - this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + ButtonSave.Location = new Point(168, 120); + ButtonSave.Margin = new Padding(2, 1, 2, 1); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(81, 22); + ButtonSave.TabIndex = 0; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; // // label1 // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(31, 36); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(114, 32); - this.label1.TabIndex = 1; - this.label1.Text = "Изделие:"; + label1.AutoSize = true; + label1.Location = new Point(16, 38); + label1.Margin = new Padding(2, 0, 2, 0); + label1.Name = "label1"; + label1.Size = new Size(56, 15); + label1.TabIndex = 1; + label1.Text = "Изделие:"; // // comboBoxFurniture // - this.comboBoxFurniture.FormattingEnabled = true; - this.comboBoxFurniture.Location = new System.Drawing.Point(188, 33); - this.comboBoxFurniture.Name = "comboBoxFurniture"; - this.comboBoxFurniture.Size = new System.Drawing.Size(441, 40); - this.comboBoxFurniture.TabIndex = 2; + comboBoxFurniture.FormattingEnabled = true; + comboBoxFurniture.Location = new Point(100, 36); + comboBoxFurniture.Margin = new Padding(2, 1, 2, 1); + comboBoxFurniture.Name = "comboBoxFurniture"; + comboBoxFurniture.Size = new Size(239, 23); + comboBoxFurniture.TabIndex = 2; // // textBoxCount // - this.textBoxCount.Location = new System.Drawing.Point(188, 90); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(441, 39); - this.textBoxCount.TabIndex = 3; - this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + textBoxCount.Location = new Point(100, 63); + textBoxCount.Margin = new Padding(2, 1, 2, 1); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(239, 23); + textBoxCount.TabIndex = 3; + textBoxCount.TextChanged += TextBoxCount_TextChanged; // // label2 // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(31, 97); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(149, 32); - this.label2.TabIndex = 4; - this.label2.Text = "Количество:"; + label2.AutoSize = true; + label2.Location = new Point(16, 66); + label2.Margin = new Padding(2, 0, 2, 0); + label2.Name = "label2"; + label2.Size = new Size(75, 15); + label2.TabIndex = 4; + label2.Text = "Количество:"; // // label3 // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(31, 155); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(92, 32); - this.label3.TabIndex = 6; - this.label3.Text = "Сумма:"; + label3.AutoSize = true; + label3.Location = new Point(16, 94); + label3.Margin = new Padding(2, 0, 2, 0); + label3.Name = "label3"; + label3.Size = new Size(48, 15); + label3.TabIndex = 6; + label3.Text = "Сумма:"; // // textBoxSum // - this.textBoxSum.Location = new System.Drawing.Point(188, 152); - this.textBoxSum.Name = "textBoxSum"; - this.textBoxSum.ReadOnly = true; - this.textBoxSum.Size = new System.Drawing.Size(441, 39); - this.textBoxSum.TabIndex = 5; - this.textBoxSum.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); + textBoxSum.Location = new Point(100, 92); + textBoxSum.Margin = new Padding(2, 1, 2, 1); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(239, 23); + textBoxSum.TabIndex = 5; // // ButtonCancel // - this.ButtonCancel.Location = new System.Drawing.Point(479, 212); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(150, 46); - this.ButtonCancel.TabIndex = 7; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + ButtonCancel.Location = new Point(257, 120); + ButtonCancel.Margin = new Padding(2, 1, 2, 1); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(81, 22); + ButtonCancel.TabIndex = 7; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // clientBox + // + clientBox.FormattingEnabled = true; + clientBox.Location = new Point(100, 5); + clientBox.Margin = new Padding(2); + clientBox.Name = "clientBox"; + clientBox.Size = new Size(239, 23); + clientBox.TabIndex = 12; + // + // clientLabel + // + clientLabel.AutoSize = true; + clientLabel.Location = new Point(18, 8); + clientLabel.Name = "clientLabel"; + clientLabel.RightToLeft = RightToLeft.No; + clientLabel.Size = new Size(46, 15); + clientLabel.TabIndex = 11; + clientLabel.Text = "Клиент"; // // FormCreateOrder // - this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(650, 278); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.label3); - this.Controls.Add(this.textBoxSum); - this.Controls.Add(this.label2); - this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.comboBoxFurniture); - this.Controls.Add(this.label1); - this.Controls.Add(this.ButtonSave); - this.Name = "FormCreateOrder"; - this.Text = "Заказ"; - this.Load += new System.EventHandler(this.FormCreateOrder_Load); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(352, 154); + Controls.Add(clientBox); + Controls.Add(clientLabel); + Controls.Add(ButtonCancel); + Controls.Add(label3); + Controls.Add(textBoxSum); + Controls.Add(label2); + Controls.Add(textBoxCount); + Controls.Add(comboBoxFurniture); + Controls.Add(label1); + Controls.Add(ButtonSave); + Margin = new Padding(2, 1, 2, 1); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); } #endregion @@ -141,5 +171,7 @@ private Label label3; private TextBox textBoxSum; private Button ButtonCancel; + private ComboBox clientBox; + private Label clientLabel; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs index b0d432f..45e10b8 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs @@ -21,36 +21,53 @@ namespace FurnitureAssemblyView private readonly IFurnitureLogic _logicM; private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicC; - public FormCreateOrder(ILogger logger, IFurnitureLogic logicM, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, IFurnitureLogic logicM, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicM = logicM; _logicO = logicO; + _logicC = logicC; } private void FormCreateOrder_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка изделий для заказа"); - try { var list = _logicM.ReadList(null); - if (list != null) { - comboBoxFurniture.DisplayMember = "FurnitureName"; + comboBoxFurniture.DisplayMember = "Furniture"; comboBoxFurniture.ValueMember = "Id"; - comboBoxFurniture.DataSource = list; + comboBoxFurniture.DataSource = list.Select(c => c.FurnitureName).ToList(); comboBoxFurniture.SelectedItem = null; } } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделий для заказа"); + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Загрузка клиентов для заказа"); + try + { + var clientList = _logicC.ReadList(null); + if (clientList != null) + { + clientBox.DisplayMember = "Client"; + clientBox.ValueMember = "Id"; + clientBox.DataSource = clientList.Select(c => c.ClientFIO).ToList(); + clientBox.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка клиентов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -61,17 +78,16 @@ namespace FurnitureAssemblyView { try { - int id = Convert.ToInt32(comboBoxFurniture.SelectedValue); - + var list = _logicM.ReadList(null); + int id = list.Where(l => l.FurnitureName == comboBoxFurniture.SelectedValue.ToString()) + .Select(l => l.Id).First(); var furniture = _logicM.ReadElement(new FurnitureSearchModel { - Id = id + Id = id, + FurnitureName = comboBoxFurniture.Text }); - int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (furniture?.Price ?? 0), 2).ToString(); - _logger.LogInformation("Расчет суммы заказа"); } catch (Exception ex) @@ -116,7 +132,8 @@ namespace FurnitureAssemblyView { FurnitureId = Convert.ToInt32(comboBoxFurniture.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text) + Sum = Convert.ToDouble(textBoxSum.Text), + ClientId = Convert.ToInt32(clientBox.SelectedValue) }); if (!operationResult) diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.resx b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.resx index f298a7b..a395bff 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.resx +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.resx @@ -1,4 +1,64 @@ - + + + diff --git a/FurnitureAssembly/FurnitureAssembly/FormImplementers.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormImplementers.Designer.cs new file mode 100644 index 0000000..750c9ea --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormImplementers.Designer.cs @@ -0,0 +1,114 @@ +namespace FurnitureAssemblyView +{ + 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() + { + ButtonRefresh = new Button(); + ButtonDelete = new Button(); + ButtonUpd = new Button(); + ButtonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // ButtonRefresh + // + ButtonRefresh.Location = new Point(512, 194); + ButtonRefresh.Name = "ButtonRefresh"; + ButtonRefresh.Size = new Size(105, 29); + ButtonRefresh.TabIndex = 21; + ButtonRefresh.Text = "Обновить"; + ButtonRefresh.UseVisualStyleBackColor = true; + ButtonRefresh.Click += ButtonRefresh_Click; + // + // ButtonDelete + // + ButtonDelete.Location = new Point(512, 136); + ButtonDelete.Name = "ButtonDelete"; + ButtonDelete.Size = new Size(105, 29); + ButtonDelete.TabIndex = 20; + ButtonDelete.Text = "Удалить"; + ButtonDelete.UseVisualStyleBackColor = true; + ButtonDelete.Click += ButtonDelete_Click; + // + // ButtonUpd + // + ButtonUpd.Location = new Point(512, 79); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(105, 29); + ButtonUpd.TabIndex = 19; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonUpd_Click; + // + // ButtonAdd + // + ButtonAdd.Location = new Point(512, 23); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(105, 29); + ButtonAdd.TabIndex = 18; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(1, 1); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(495, 324); + dataGridView.TabIndex = 17; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(633, 325); + Controls.Add(ButtonRefresh); + Controls.Add(ButtonDelete); + Controls.Add(ButtonUpd); + Controls.Add(ButtonAdd); + Controls.Add(dataGridView); + Name = "FormImplementers"; + Text = "Исполнители"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button ButtonRefresh; + private Button ButtonDelete; + private Button ButtonUpd; + private Button ButtonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs b/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs new file mode 100644 index 0000000..f7d5f89 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormImplementers.cs @@ -0,0 +1,120 @@ +using FurnitureAssembly; +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureAssemblyView +{ + 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(FormCreateImplementer)); + if (service is FormCreateImplementer 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(FormCreateImplementer)); + if (service is FormCreateImplementer form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_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 ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormImplementers.resx b/FurnitureAssembly/FurnitureAssembly/FormImplementers.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/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/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index da2603d..2c0dd88 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -33,14 +33,14 @@ заготовкиToolStripMenuItem = new ToolStripMenuItem(); мебельToolStripMenuItem = new ToolStripMenuItem(); клиентыToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); списокМебелиToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); ButtonCreateOrder = new Button(); - ButtonTakeOrderInWork = new Button(); - ButtonOrderReady = new Button(); ButtonIssuedOrder = new Button(); ButtonRef = new Button(); menuStrip1.SuspendLayout(); @@ -50,7 +50,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(32, 32); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Padding = new Padding(3, 1, 0, 1); @@ -60,7 +60,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заготовкиToolStripMenuItem, мебельToolStripMenuItem, клиентыToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заготовкиToolStripMenuItem, мебельToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(94, 22); справочникиToolStripMenuItem.Text = "Справочники"; @@ -68,24 +68,31 @@ // заготовкиToolStripMenuItem // заготовкиToolStripMenuItem.Name = "заготовкиToolStripMenuItem"; - заготовкиToolStripMenuItem.Size = new Size(180, 22); + заготовкиToolStripMenuItem.Size = new Size(149, 22); заготовкиToolStripMenuItem.Text = "Заготовки"; заготовкиToolStripMenuItem.Click += заготовкиToolStripMenuItem_Click; // // мебельToolStripMenuItem // мебельToolStripMenuItem.Name = "мебельToolStripMenuItem"; - мебельToolStripMenuItem.Size = new Size(180, 22); + мебельToolStripMenuItem.Size = new Size(149, 22); мебельToolStripMenuItem.Text = "Мебель"; мебельToolStripMenuItem.Click += мебельToolStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(180, 22); + клиентыToolStripMenuItem.Size = new Size(149, 22); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(149, 22); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокМебелиToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); @@ -114,6 +121,13 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(92, 22); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += doWorkToolStripMenuItem_Click; + // // dataGridView // dataGridView.AllowUserToAddRows = false; @@ -143,34 +157,10 @@ ButtonCreateOrder.UseVisualStyleBackColor = true; ButtonCreateOrder.Click += ButtonCreateOrder_Click; // - // ButtonTakeOrderInWork - // - ButtonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonTakeOrderInWork.Location = new Point(682, 56); - ButtonTakeOrderInWork.Margin = new Padding(2, 1, 2, 1); - ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - ButtonTakeOrderInWork.Size = new Size(180, 22); - ButtonTakeOrderInWork.TabIndex = 3; - ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // ButtonOrderReady - // - ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonOrderReady.Location = new Point(682, 92); - ButtonOrderReady.Margin = new Padding(2, 1, 2, 1); - ButtonOrderReady.Name = "ButtonOrderReady"; - ButtonOrderReady.Size = new Size(180, 22); - ButtonOrderReady.TabIndex = 4; - ButtonOrderReady.Text = "Заказ готов"; - ButtonOrderReady.UseVisualStyleBackColor = true; - ButtonOrderReady.Click += ButtonOrderReady_Click; - // // ButtonIssuedOrder // ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonIssuedOrder.Location = new Point(682, 118); + ButtonIssuedOrder.Location = new Point(682, 67); ButtonIssuedOrder.Margin = new Padding(2, 1, 2, 1); ButtonIssuedOrder.Name = "ButtonIssuedOrder"; ButtonIssuedOrder.Size = new Size(180, 22); @@ -182,7 +172,7 @@ // ButtonRef // ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - ButtonRef.Location = new Point(682, 158); + ButtonRef.Location = new Point(682, 107); ButtonRef.Margin = new Padding(2, 1, 2, 1); ButtonRef.Name = "ButtonRef"; ButtonRef.Size = new Size(180, 22); @@ -198,8 +188,6 @@ ClientSize = new Size(878, 278); Controls.Add(ButtonRef); Controls.Add(ButtonIssuedOrder); - Controls.Add(ButtonOrderReady); - Controls.Add(ButtonTakeOrderInWork); Controls.Add(ButtonCreateOrder); Controls.Add(dataGridView); Controls.Add(menuStrip1); @@ -223,8 +211,6 @@ private ToolStripMenuItem мебельToolStripMenuItem; private DataGridView dataGridView; private Button ButtonCreateOrder; - private Button ButtonTakeOrderInWork; - private Button ButtonOrderReady; private Button ButtonIssuedOrder; private Button ButtonRef; private ToolStripMenuItem отчетыToolStripMenuItem; @@ -232,5 +218,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/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index a98be7f..af90d9d 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -1,5 +1,6 @@ using DocumentFormat.OpenXml.Office2010.ExcelAc; using FurnitureAssembly; +using FurnitureAssemblyBusinessLogic.BusinessLogic; using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContracts; using FurnitureAssemblyDataModels.Enums; @@ -21,12 +22,15 @@ namespace FurnitureAssemblyView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workModeling; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workModeling) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workModeling = workModeling; + _workModeling = workModeling; } private void MainForm_Load(object sender, EventArgs e) @@ -238,5 +242,19 @@ namespace FurnitureAssemblyView form.ShowDialog(); } } + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + private void doWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workModeling.DoWork(( + Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + _orderLogic); + } } } diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index dfba2ab..191b3a6 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -42,18 +42,23 @@ namespace FurnitureAssembly 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(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/ImplementerLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..4f93f67 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,131 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.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 (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", + nameof(model.Password)); + } + + if (model.WorkExperience < 0) + { + throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification)); + } + + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Id: { Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel { ImplementerFIO = model.ImplementerFIO }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким логином уже есть"); + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/OrderLogic.cs index 150475d..3dbee2b 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/OrderLogic.cs @@ -127,5 +127,21 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogic _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. PackageId: { PackageId}", model.Id, model.Sum, model.FurnitureId); } + public OrderViewModel? ReadElement(OrderSearchModel? model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Status: {Status}. ImplementerId: {ImplementerId} Id:{ Id}", model.Status, model.ImplementerId, 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; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/WorkModeling.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..e820a5b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,156 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyBusinessLogic.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(50, + 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order{ Order} ", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + + + } + }); + } + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + 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(50, 300) * + runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", + implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id, + ImplementerId = implementer.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/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureLogic.cs deleted file mode 100644 index 3fbaf5f..0000000 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/FurnitureLogic.cs +++ /dev/null @@ -1,147 +0,0 @@ -using FurnitureAssemblyContracts.BindingModels; -using FurnitureAssemblyContracts.BusinessLogicsContracts; -using FurnitureAssemblyContracts.SearchModels; -using FurnitureAssemblyContracts.StoragesContracts; -using FurnitureAssemblyContracts.ViewModels; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FurnitureAssemblyBusinessLogic -{ - public class FurnitureLogic : IFurnitureLogic - { - private readonly ILogger _logger; - - private readonly IFurnitureStorage _furnitureStorage; - - public FurnitureLogic(ILogger logger, IFurnitureStorage furnitureStorage) - { - _logger = logger; - _furnitureStorage = furnitureStorage; - } - - public List? ReadList(FurnitureSearchModel? model) - { - _logger.LogInformation("ReadList. FurnitureName: {FurnitureName}. Id:{Id}", model?.FurnitureName, model?.Id); - - var list = model == null ? _furnitureStorage.GetFullList() : _furnitureStorage.GetFilteredList(model); - - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - - return null; - } - - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - - return list; - } - - public FurnitureViewModel? ReadElement(FurnitureSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - - _logger.LogInformation("ReadElement. FurnitureName: {FurnitureName}. Id:{Id}", model.FurnitureName, model.Id); - - var element = _furnitureStorage.GetElement(model); - - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - - return null; - } - - _logger.LogInformation("Readelement find. Id:{Id}", model.Id); - - return element; - } - - public bool Create(FurnitureBindingModel model) - { - CheckModel(model); - - if (_furnitureStorage.Insert(model) == null) - { - _logger.LogWarning("Create operation failed"); - - return false; - } - - return true; - } - - public bool Update(FurnitureBindingModel model) - { - CheckModel(model); - - if (_furnitureStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - - return true; - } - - public bool Delete(FurnitureBindingModel model) - { - CheckModel(model, false); - - _logger.LogInformation("Delete, Id:{Id}", model.Id); - - if (_furnitureStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - - return false; - } - - return true; - } - - private void CheckModel(FurnitureBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - - if (!withParams) - { - return; - } - - if (string.IsNullOrEmpty(model.FurnitureName)) - { - throw new ArgumentNullException("Нет названия заготовки", nameof(model.FurnitureName)); - } - - if (model.Price <= 0) - { - throw new ArgumentNullException("Цена заготовки должна быть больше 0", nameof(model.Price)); - } - - _logger.LogInformation("Furniture. FurnitureName:{FurnitureName}. Price:{Price}. Id:{Id}", - model.FurnitureName, model.Price, model.Id); - - var element = _furnitureStorage.GetElement(new FurnitureSearchModel - { - FurnitureName = model.FurnitureName, - }); - - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Изделие с таким названием уже есть"); - } - } - } -} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs deleted file mode 100644 index 7f45e76..0000000 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs +++ /dev/null @@ -1,158 +0,0 @@ -using FurnitureAssemblyContracts.BindingModels; -using FurnitureAssemblyContracts.BusinessLogicsContracts; -using FurnitureAssemblyContracts.SearchModels; -using FurnitureAssemblyContracts.StoragesContracts; -using FurnitureAssemblyContracts.ViewModels; -using FurnitureAssemblyDataModels.Enums; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FurnitureAssemblyBusinessLogic -{ - public class OrderLogic : IOrderLogic - { - private readonly ILogger _logger; - - private readonly IOrderStorage _orderStorage; - - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } - - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. Id:{Id}", model?.Id); - - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - - return null; - } - - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - - return list; - } - - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); - - if (model.Status != OrderStatus.Неизвестен) - { - _logger.LogWarning("Insert operation failed, incorrect order status"); - return false; - } - - model.Status = OrderStatus.Принят; - - if (_orderStorage.Insert(model) == null) - { - model.Status = OrderStatus.Неизвестен; - _logger.LogWarning("Insert operation failed"); - return false; - } - - return true; - } - - public bool TakeOrderInWork(OrderBindingModel model) - { - return StatusUpdate(model, OrderStatus.Выполняется); - } - - public bool FinishOrder(OrderBindingModel model) - { - return StatusUpdate(model, OrderStatus.Готов); - } - - public bool DeliveryOrder(OrderBindingModel model) - { - return StatusUpdate(model, OrderStatus.Выдан); - } - - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - - if (!withParams) - { - return; - } - - if (model.Count <= 0) - { - throw new ArgumentNullException("В заказе не может быть 0 заготовок", nameof(model.Count)); - } - - if (model.Sum <= 0) - { - throw new ArgumentNullException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); - } - - if (model.FurnitureId < 0) - { - throw new ArgumentNullException("Некорректный id у заготовки", nameof(model.FurnitureId)); - } - - if (model.DateCreate > model.DateImplement) - { - throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения"); - } - - _logger.LogInformation("Order. OrderId:{Id}, Sum:{Sum}. FurnitureId:{Id}", model.Id, model.Sum, model.FurnitureId); - } - - public bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) - { - var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - - if (viewModel == null) - { - throw new ArgumentNullException(nameof(model)); - } - - if (viewModel.Status + 1 != newOrderStatus) - { - _logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + "incorrect"); - return false; - } - - model.Status = newOrderStatus; - - if (model.Status == OrderStatus.Выдан) - { - model.DateImplement = DateTime.Now.ToUniversalTime(); - } - else - { - model.DateImplement = viewModel.DateImplement; - } - - CheckModel(model, false); - - if (_orderStorage.Update(model) == null) - { - model.Status--; - - _logger.LogWarning("Update operation failed"); - - return false; - } - - return true; - } - } -} diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/WorkpieceLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/WorkpieceLogic.cs deleted file mode 100644 index 53552ef..0000000 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/WorkpieceLogic.cs +++ /dev/null @@ -1,111 +0,0 @@ -using FurnitureAssemblyContracts.BindingModels; -using FurnitureAssemblyContracts.BusinessLogicsContracts; -using FurnitureAssemblyContracts.SearchModels; -using FurnitureAssemblyContracts.StoragesContracts; -using FurnitureAssemblyContracts.ViewModels; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FurnitureAssemblyBusinessLogic.BusinessLogics -{ - public class WorkpieceLogic : IWorkpieceLogic - { - private readonly ILogger _logger; - private readonly IWorkpieceStorage _workpieceStorage; - public WorkpieceLogic(ILogger logger, IWorkpieceStorage workpieceStorage) - { - _logger = logger; - _workpieceStorage = workpieceStorage; - } - public List? ReadList(WorkpieceSearchModel? model) - { - _logger.LogInformation("ReadList. WorkpieceName:{WorkpieceName}.Id:{ Id} ", model?.WorkpieceName, model?.Id); - var list = model == null ? _workpieceStorage.GetFullList() : _workpieceStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public WorkpieceViewModel? ReadElement(WorkpieceSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. WorkpieceName:{WorkpieceName}.Id:{ Id}", model.WorkpieceName, model.Id); - var element = _workpieceStorage.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 Create(WorkpieceBindingModel model) - { - CheckModel(model); - if (_workpieceStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(WorkpieceBindingModel model) - { - CheckModel(model); - if (_workpieceStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(WorkpieceBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_workpieceStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - private void CheckModel(WorkpieceBindingModel model, bool withParams = - true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.WorkpieceName)) - { - throw new ArgumentNullException("Нет названия компонента", - nameof(model.WorkpieceName)); - } - if (model.Cost <= 0) - { - throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); - } - _logger.LogInformation("Workpiece. WorkpieceName:{WorkpieceName}.Cost:{ Cost}. Id: { Id}", model.WorkpieceName, model.Cost, model.Id); - var element = _workpieceStorage.GetElement(new WorkpieceSearchModel {WorkpieceName = model.WorkpieceName}); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Компонент с таким названием уже есть"); - } - } - } -} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ImplementerBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..fca4d03 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,18 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.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/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs index 18b9cb0..a0b7c9c 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs @@ -18,5 +18,6 @@ namespace FurnitureAssemblyContracts.BindingModels public DateTime DateCreate { get; set; } = DateTime.Now.ToUniversalTime(); public DateTime? DateImplement { get; set; } = null; public int ClientId { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IImplementerLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..14e4628 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.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/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IOrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IOrderLogic.cs index 179f3f7..84068b1 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel? model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IWorkProcess.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..9dd53b7 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ImplementerSearchModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..a59ebd2 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/OrderSearchModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/OrderSearchModel.cs index c562ecb..2205d99 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/OrderSearchModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using FurnitureAssemblyDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,5 +14,7 @@ namespace FurnitureAssemblyContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public OrderStatus? Status { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IImplementerStorage.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..c6519d4 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.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/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..e1033fc --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,23 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.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/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs index f825dd5..3e1fbea 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/OrderViewModel.cs @@ -29,5 +29,8 @@ namespace FurnitureAssemblyContracts.ViewModels public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string? ImplementerFIO { get; set; } = string.Empty; } } diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IImplementerModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..d48bdac --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IOrderModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IOrderModel.cs index af2e15e..e7c2477 100644 --- a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IOrderModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IOrderModel.cs @@ -16,5 +16,6 @@ namespace FurnitureAssemblyDataModels.Models DateTime DateCreate { get; } DateTime? DateImplement { get; } int ClientId { get; } + int? ImplementerId { get; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs index 4abc158..006f05f 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs @@ -22,12 +22,10 @@ namespace FurnitureAssemblyDatabaseImplement } public virtual DbSet Workpieces { set; get; } - public virtual DbSet Furnitures { set; get; } - public virtual DbSet FurnitureWorkpieces { set; get; } - public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ImplementerStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..caf30cb --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,101 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password)) + { + return null; + } + using var context = new FurnitureAssemblyDatabase(); + if (model.Id.HasValue) + { + return context.Implementers + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + if (model.ImplementerFIO != null && model.Password != null) + { + return context.Implementers + .FirstOrDefault(x => + x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password)) + ?.GetViewModel; + } + return context.Implementers + .FirstOrDefault(x => + x.ImplementerFIO.Equals(model.ImplementerFIO)) + ?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new FurnitureAssemblyDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new FurnitureAssemblyDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new FurnitureAssemblyDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + var client = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + context.SaveChanges(); + return client.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new FurnitureAssemblyDatabase(); + var element = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs index 2dd1aa0..2a849a1 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/OrderStorage.cs @@ -22,34 +22,57 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { context.Orders.Remove(order); context.SaveChanges(); - return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; + return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } return null; } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) { return null; } using var context = new FurnitureAssemblyDatabase(); - return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + if (model.Id.HasValue) + { + return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + return context.Orders + .Include(x => x.Furniture) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.ImplementerId.Equals(model.ImplementerId) && x.Status.Equals(model.Status)) + ?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) { return new(); } using var context = new FurnitureAssemblyDatabase(); + if (model.Id.HasValue) + { + return context.Orders + .Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + return context.Orders .Include(x => x.Furniture) .Include(x => x.Client) - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || model.ClientId == x.ClientId) + .Include(x => x.Implementer) + .Where(x => !( + (((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + || (model.ClientId.HasValue && !x.ClientId.Equals(model.ClientId)) + || (model.Status.HasValue && !x.Status.Equals(model.Status)))) + ) .Select(x => x.GetViewModel) .ToList(); } @@ -60,6 +83,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements return context.Orders .Include(x => x.Furniture) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -74,8 +98,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; - + return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -88,7 +111,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; + return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240505193918_lab6.Designer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240505193918_lab6.Designer.cs new file mode 100644 index 0000000..67068ab --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240505193918_lab6.Designer.cs @@ -0,0 +1,252 @@ +// +using System; +using FurnitureAssemblyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + [DbContext(typeof(FurnitureAssemblyDatabase))] + [Migration("20240505193918_lab6")] + partial class lab6 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.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("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FurnitureName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Furnitures"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("FurnitureId") + .HasColumnType("integer"); + + b.Property("WorkpieceId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("FurnitureId"); + + b.HasIndex("WorkpieceId"); + + b.ToTable("FurnitureWorkpieces"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.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("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp with time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp with time zone"); + + b.Property("FurnitureId") + .HasColumnType("integer"); + + b.Property("ImplementerId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("FurnitureId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("WorkpieceName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Workpieces"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureWorkpiece", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Workpieces") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Workpiece", "Workpiece") + .WithMany("FurnitureWorkpieces") + .HasForeignKey("WorkpieceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Furniture"); + + b.Navigation("Workpiece"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b => + { + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture") + .WithMany("Orders") + .HasForeignKey("FurnitureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Client"); + + b.Navigation("Furniture"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => + { + b.Navigation("Orders"); + + b.Navigation("Workpieces"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b => + { + b.Navigation("FurnitureWorkpieces"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240505193918_lab6.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240505193918_lab6.cs new file mode 100644 index 0000000..efd8206 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240505193918_lab6.cs @@ -0,0 +1,68 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FurnitureAssemblyDatabaseImplement.Migrations +{ + /// + public partial class lab6 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "integer", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + 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_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + 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.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs index e2bdf7e..6ec35cc 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/FurnitureAssemblyDatabaseModelSnapshot.cs @@ -17,7 +17,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.7") + .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -93,6 +93,33 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.ToTable("FurnitureWorkpieces"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.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("FurnitureAssemblyDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -116,6 +143,9 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Property("FurnitureId") .HasColumnType("integer"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("Status") .HasColumnType("integer"); @@ -128,6 +158,8 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.HasIndex("FurnitureId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -184,9 +216,15 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.Navigation("Client"); b.Navigation("Furniture"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b => @@ -196,6 +234,11 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations b.Navigation("Workpieces"); }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Workpiece", b => { b.Navigation("FurnitureWorkpieces"); diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..57b94a1 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,65 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FurnitureAssemblyContracts.ViewModels; + +namespace FurnitureAssemblyDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; private set; } = string.Empty; + [Required] + public int WorkExperience { get; private set; } + [Required] + public int Qualification { get; private set; } + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private 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 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/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs index 2cc8d16..8f84dcf 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Order.cs @@ -31,10 +31,11 @@ namespace FurnitureAssemblyDatabaseImplement.Models public int Id { get; set; } [Required] public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public virtual Client Client { get; set; } public virtual Furniture Furniture { get; set; } - + public virtual Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { return new Order() @@ -46,7 +47,8 @@ namespace FurnitureAssemblyDatabaseImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ClientId = model.ClientId + ClientId = model.ClientId, + ImplementerId = model.ImplementerId }; } @@ -60,6 +62,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models Sum = model.Sum; Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -73,7 +76,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models DateCreate = DateCreate, DateImplement = DateImplement, ClientId = ClientId, - ClientFIO = Client.ClientFIO + ClientFIO = Client.ClientFIO, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer?.ImplementerFIO }; } diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs index 1c7097c..a044656 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/DataFileSingleton.cs @@ -11,15 +11,18 @@ namespace FurnitureAssemblyFileImplement { public class DataFileSingleton { - private static DataFileSingleton? instance; + private static DataFileSingleton? instance; private readonly string WorkpieceFileName = "Workpiece.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string FurnitureFileName = "Furniture.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Workpieces { get; private set; } public List Orders { get; private set; } public List Furnitures { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -32,12 +35,14 @@ namespace FurnitureAssemblyFileImplement public void SaveFurnitures() => SaveData(Furnitures, FurnitureFileName, "Furnitures", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Workpieces = LoadData(WorkpieceFileName, "Workpiece", x => Workpiece.Create(x)!)!; Furnitures = LoadData(FurnitureFileName, "Furniture", x => Furniture.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) @@ -48,7 +53,7 @@ namespace FurnitureAssemblyFileImplement } return new List(); } - private static void SaveData(List data, string filename, + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) { if (data != null) diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ImplementerStorage.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..323c7ff --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,104 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password)) + { + return null; + } + + if (model.Id.HasValue) + { + return source.Implementers + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + if (model.ImplementerFIO != null && model.Password != null) + { + return source.Implementers + .FirstOrDefault(x => + x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password)) + ?.GetViewModel; + } + return source.Implementers + .FirstOrDefault(x => + x.ImplementerFIO.Equals(model.ImplementerFIO)) + ?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImpl = Implementer.Create(model); + if (newImpl == null) + { + return null; + } + source.Implementers.Add(newImpl); + source.SaveWorkpieces(); + return newImpl.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveWorkpieces(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveWorkpieces(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/OrderStorage.cs index e20c26d..e786a56 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Implements/OrderStorage.cs @@ -14,7 +14,6 @@ namespace FurnitureAssemblyFileImplement.Implements public class OrderStorage : IOrderStorage { private readonly DataFileSingleton source; - public OrderStorage() { source = DataFileSingleton.GetInstance(); @@ -22,84 +21,76 @@ namespace FurnitureAssemblyFileImplement.Implements public List GetFullList() { - return source.Orders.Select(x => GetViewModel(x)).ToList(); + return source.Orders.Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && !model.Status.HasValue) { return new(); } - - return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + return source.Orders + .Where(x => !(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + || ((model.ClientId.HasValue) && !(x.ClientId.Equals(model.ClientId))) + || ((model.Status.HasValue) && !(x.Status.Equals(model.Status))) + )) + .Select(x => x.GetViewModel) + .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) { return null; } - return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } + return source.Orders + .FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; - // Для загрузки названий изделия в заказе - private OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; - - var furniture = source.Furnitures.FirstOrDefault(x => x.Id == order.FurnitureId); - - viewModel.FurnitureName = furniture?.FurnitureName; - return viewModel; + var order = source.Orders + .FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id) || (x.ImplementerId.Equals(model.ImplementerId) && x.Status.Equals(model.Status))); + return order?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; - var newOrder = Order.Create(model); - if (newOrder == null) { return null; } - source.Orders.Add(newOrder); source.SaveOrders(); - - return GetViewModel(newOrder); + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) { return null; } - order.Update(model); source.SaveOrders(); - - return GetViewModel(order); + return order.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (element != null) { source.Orders.Remove(element); source.SaveOrders(); - - return GetViewModel(element); + return element.GetViewModel; } - return null; } } diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..2b0d7a7 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Implementer.cs @@ -0,0 +1,84 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace FurnitureAssemblyFileImplement.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 Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) + }; + } + + 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 + }; + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience.ToString()), + new XElement("Qualification", Qualification.ToString()) + ); + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs index 73e1d3e..80c1fea 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Order.cs @@ -28,6 +28,7 @@ namespace FurnitureAssemblyFileImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now.ToUniversalTime(); public DateTime? DateImplement { get; private set; } + public int? ImplementerId { get; private set; } = null; public static Order? Create(OrderBindingModel model) { @@ -45,7 +46,8 @@ namespace FurnitureAssemblyFileImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ClientId = model.ClientId + ClientId = model.ClientId, + ImplementerId = model.ImplementerId }; } @@ -66,7 +68,8 @@ namespace FurnitureAssemblyFileImplement.Models DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value), - ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value) + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")?.Value) }; } @@ -79,6 +82,7 @@ namespace FurnitureAssemblyFileImplement.Models Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -90,7 +94,8 @@ namespace FurnitureAssemblyFileImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - ClientId = ClientId + ClientId = ClientId, + ImplementerId = ImplementerId }; public XElement GetXElement => new("Order", @@ -101,6 +106,7 @@ namespace FurnitureAssemblyFileImplement.Models new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), new XElement("DateImplement", DateImplement.ToString()), - new XElement("ClientId", ClientId.ToString())); + new XElement("ClientId", ClientId.ToString()), + new XElement("ImplemwenterId", ImplementerId.ToString())); } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs index 70bdb0b..f372ab9 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/DataListSingleton.cs @@ -14,6 +14,7 @@ namespace FurnitureAssemblyListImplement public List Orders { get; set; } public List Furnitures { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { @@ -21,6 +22,7 @@ namespace FurnitureAssemblyListImplement Orders = new List(); Furnitures = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj b/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj index e35b19b..1b8ba63 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/FurnitureAssemblyListImplement.csproj @@ -8,6 +8,7 @@ + diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ImplementerStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..eaca3ba --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,122 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password)) + { + return null; + } + + foreach (var impl in _source.Implementers) + { + if (model.Id.HasValue && impl.Id == model.Id) + { + return impl.GetViewModel; + } + + if (model.ImplementerFIO != null && model.Password != null + && impl.ImplementerFIO.Equals(model.ImplementerFIO) && impl.Password.Equals(model.Password)) + { + return impl.GetViewModel; + } + + if (model.ImplementerFIO != null && impl.ImplementerFIO.Equals(model.ImplementerFIO)) + { + return impl.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var impl in _source.Implementers) + { + if (impl.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(impl.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Implementers) + { + result.Add(component.GetViewModel); + } + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var impl in _source.Implementers) + { + if (model.Id <= impl.Id) + { + model.Id = impl.Id + 1; + } + } + var newImpl = Implementer.Create(model); + if (newImpl == null) + { + return null; + } + _source.Implementers.Add(newImpl); + return newImpl.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var impl in _source.Implementers) + { + if (impl.Id == model.Id) + { + impl.Update(model); + return impl.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs index e0355bb..e586be1 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs @@ -18,78 +18,72 @@ namespace FurnitureAssemblyListImplement.Implements { _source = DataListSingleton.GetInstance(); } - - public List GetFullList() + public OrderViewModel? Delete(OrderBindingModel model) { - var result = new List(); + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) + { + return null; + } foreach (var order in _source.Orders) { - result.Add(GetViewModel(order)); + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + else if (order.ImplementerId.Equals(model.ImplementerId) && order.Status.Equals(model.Status)) + { + return order.GetViewModel; + } } - - return result; + return null; } public List GetFilteredList(OrderSearchModel model) { var result = new List(); - - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) { return result; } - foreach (var order in _source.Orders) { - if (order.Id == model.Id) + if (!(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo) + || ((model.ClientId.HasValue) && !(order.ClientId.Equals(model.ClientId))) + || ((model.Status.HasValue) && !(order.Status.Equals(model.Status))))) { - result.Add(GetViewModel(order)); + result.Add(order.GetViewModel); } } - return result; } - public OrderViewModel? GetElement(OrderSearchModel model) + public List GetFullList() { - if (!model.Id.HasValue) - { - return null; - } - + var result = new List(); foreach (var order in _source.Orders) { - if (model.Id.HasValue && order.Id == model.Id) - { - return GetViewModel(order); - } + result.Add(order.GetViewModel); } - - return null; - } - - private OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; - - foreach (var furniture in _source.Furnitures) - { - if (furniture.Id == order.FurnitureId) - { - viewModel.FurnitureName = furniture.FurnitureName; - - break; - } - } - - return viewModel; + return result; } public OrderViewModel? Insert(OrderBindingModel model) { model.Id = 1; - foreach (var order in _source.Orders) { if (model.Id <= order.Id) @@ -97,17 +91,13 @@ namespace FurnitureAssemblyListImplement.Implements model.Id = order.Id + 1; } } - var newOrder = Order.Create(model); - if (newOrder == null) { return null; } - _source.Orders.Add(newOrder); - - return GetViewModel(newOrder); + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -117,27 +107,9 @@ namespace FurnitureAssemblyListImplement.Implements if (order.Id == model.Id) { order.Update(model); - - return GetViewModel(order); + return order.GetViewModel; } } - - return null; - } - - public OrderViewModel? Delete(OrderBindingModel model) - { - for (int i = 0; i < _source.Orders.Count; i++) - { - if (_source.Orders[i].Id == model.Id) - { - var element = _source.Orders[i]; - _source.Orders.RemoveAt(i); - - return GetViewModel(element); - } - } - return null; } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Implementer.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Implementer.cs new file mode 100644 index 0000000..c11b447 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Implementer.cs @@ -0,0 +1,59 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyListImplement.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 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/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs index 7464d87..7c692cd 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs @@ -1,5 +1,6 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDatabaseImplement.Models; using FurnitureAssemblyDataModels.Enums; using FurnitureAssemblyDataModels.Models; using System; @@ -27,6 +28,7 @@ namespace FurnitureAssemblyListImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now.ToUniversalTime(); public DateTime? DateImplement { get; private set; } + public int? ImplementerId { get; private set; } public static Order? Create(OrderBindingModel? model) { @@ -44,7 +46,8 @@ namespace FurnitureAssemblyListImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ClientId = model.ClientId + ClientId = model.ClientId, + ImplementerId = model.ImplementerId }; } public void Update(OrderBindingModel? model) @@ -55,6 +58,7 @@ namespace FurnitureAssemblyListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -66,7 +70,8 @@ namespace FurnitureAssemblyListImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - ClientId = ClientId + ClientId = ClientId, + ImplementerId = ImplementerId }; } } diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ImplementerController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..7158f3e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,102 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContracts; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace FurnitureAssemblyRestApi.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; + } + } + } +} -- 2.25.1 From 2b4db4f5f42e67b0498c820d8f75c4f218a3adf8 Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Sun, 5 May 2024 23:58:51 +0400 Subject: [PATCH 2/3] done --- .../FurnitureAssembly/FormCreateOrder.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs index 45e10b8..c680e78 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs @@ -31,6 +31,7 @@ namespace FurnitureAssemblyView _logicM = logicM; _logicO = logicO; _logicC = logicC; + } private void FormCreateOrder_Load(object sender, EventArgs e) @@ -41,9 +42,9 @@ namespace FurnitureAssemblyView var list = _logicM.ReadList(null); if (list != null) { - comboBoxFurniture.DisplayMember = "Furniture"; + comboBoxFurniture.DisplayMember = "FurnitureName"; comboBoxFurniture.ValueMember = "Id"; - comboBoxFurniture.DataSource = list.Select(c => c.FurnitureName).ToList(); + comboBoxFurniture.DataSource = list; comboBoxFurniture.SelectedItem = null; } @@ -70,6 +71,24 @@ namespace FurnitureAssemblyView _logger.LogError(ex, "Ошибка загрузки списка клиентов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + try + { + var list = _logicC.ReadList(null); + + if (list != null) + { + clientBox.DisplayMember = "ClientFIO"; + clientBox.ValueMember = "Id"; + clientBox.DataSource = list; + clientBox.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов для заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void CalcSum() -- 2.25.1 From 9b6e58a26579b7fec53aa1e4f2c6f2dbbdde2ceb Mon Sep 17 00:00:00 2001 From: vladimir_zinovev Date: Sun, 12 May 2024 16:26:49 +0400 Subject: [PATCH 3/3] done --- .../FurnitureAssembly/FormCreateOrder.cs | 30 ++++--------------- .../FurnitureAssembly/FormMain.cs | 1 + 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs index c680e78..9e6bcc2 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs @@ -17,9 +17,7 @@ namespace FurnitureAssemblyView public partial class FormCreateOrder : Form { private readonly ILogger _logger; - private readonly IFurnitureLogic _logicM; - private readonly IOrderLogic _logicO; private readonly IClientLogic _logicC; @@ -31,7 +29,6 @@ namespace FurnitureAssemblyView _logicM = logicM; _logicO = logicO; _logicC = logicC; - } private void FormCreateOrder_Load(object sender, EventArgs e) @@ -56,22 +53,6 @@ namespace FurnitureAssemblyView } _logger.LogInformation("Загрузка клиентов для заказа"); try - { - var clientList = _logicC.ReadList(null); - if (clientList != null) - { - clientBox.DisplayMember = "Client"; - clientBox.ValueMember = "Id"; - clientBox.DataSource = clientList.Select(c => c.ClientFIO).ToList(); - clientBox.SelectedItem = null; - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки списка клиентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - try { var list = _logicC.ReadList(null); @@ -97,16 +78,17 @@ namespace FurnitureAssemblyView { try { - var list = _logicM.ReadList(null); - int id = list.Where(l => l.FurnitureName == comboBoxFurniture.SelectedValue.ToString()) - .Select(l => l.Id).First(); + int id = Convert.ToInt32(comboBoxFurniture.SelectedValue); + var furniture = _logicM.ReadElement(new FurnitureSearchModel { - Id = id, - FurnitureName = comboBoxFurniture.Text + Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (furniture?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); } catch (Exception ex) diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index af90d9d..2c6203d 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -49,6 +49,7 @@ namespace FurnitureAssemblyView dataGridView.DataSource = list; dataGridView.Columns["FurnitureId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); -- 2.25.1