From bdd2e18fc3b08eeb65d89871430a6b0e765530cd Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 19 Apr 2023 22:48:32 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=BB=D1=806=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormImplementer.Designer.cs | 178 ++++++++++ PrecastConcretePlant/FormImplementer.cs | 100 ++++++ PrecastConcretePlant/FormImplementer.resx | 60 ++++ .../FormImplementers.Designer.cs | 121 +++++++ PrecastConcretePlant/FormImplementers.cs | 103 ++++++ PrecastConcretePlant/FormImplementers.resx | 60 ++++ PrecastConcretePlant/FormMain.Designer.cs | 319 +++++++++--------- PrecastConcretePlant/FormMain.cs | 23 +- PrecastConcretePlant/Program.cs | 6 +- .../BusinessLogic/IWorkProcess.cs | 17 + .../BusinessLogic/ImplementerLogic.cs | 127 +++++++ .../BusinessLogic/OrderLogic.cs | 51 ++- .../BusinessLogic/WorkModeling.cs | 141 ++++++++ .../BindingModels/ImplementerBindingModel.cs | 21 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 24 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../SearchModels/ImplementerSearchModel.cs | 17 + .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 26 ++ .../ViewModels/ImplementerViewModel.cs | 27 ++ .../ViewModels/OrderViewModel.cs | 4 + .../Implements/ImplementerStorage.cs | 89 +++++ .../Implements/OrderStorage.cs | 106 +++--- .../20230419193952_implementeradd.Designer.cs | 257 ++++++++++++++ .../20230419193952_implementeradd.cs | 67 ++++ ...ecastConcretePlantDatabaseModelSnapshot.cs | 43 +++ .../Models/Implementer.cs | 66 ++++ .../Models/Order.cs | 46 ++- .../PrecastConcretePlantDatabase.cs | 3 +- .../Models/IImplementerModel.cs | 16 + .../Controllers/ImplementerController.cs | 104 ++++++ 32 files changed, 2002 insertions(+), 227 deletions(-) create mode 100644 PrecastConcretePlant/FormImplementer.Designer.cs create mode 100644 PrecastConcretePlant/FormImplementer.cs create mode 100644 PrecastConcretePlant/FormImplementer.resx create mode 100644 PrecastConcretePlant/FormImplementers.Designer.cs create mode 100644 PrecastConcretePlant/FormImplementers.cs create mode 100644 PrecastConcretePlant/FormImplementers.resx create mode 100644 PrecastConcretePlantBusinessLogic/BusinessLogic/IWorkProcess.cs create mode 100644 PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs create mode 100644 PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs create mode 100644 PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs create mode 100644 PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs create mode 100644 PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.Designer.cs create mode 100644 PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.cs create mode 100644 PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs create mode 100644 PrecastConcretePlantDataModels/Models/IImplementerModel.cs create mode 100644 PrecastConcretePlantRestApi/Controllers/ImplementerController.cs diff --git a/PrecastConcretePlant/FormImplementer.Designer.cs b/PrecastConcretePlant/FormImplementer.Designer.cs new file mode 100644 index 0000000..ff1dbf1 --- /dev/null +++ b/PrecastConcretePlant/FormImplementer.Designer.cs @@ -0,0 +1,178 @@ +namespace PrecastConcretePlantView +{ + partial class FormImplementer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.textBoxFio = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(108, 151); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(89, 33); + this.buttonSave.TabIndex = 19; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(219, 151); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(89, 33); + this.buttonCancel.TabIndex = 18; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // numericUpDownQualification + // + this.numericUpDownQualification.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownQualification.Location = new System.Drawing.Point(116, 97); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(264, 23); + this.numericUpDownQualification.TabIndex = 17; + // + // numericUpDownWorkExperience + // + this.numericUpDownWorkExperience.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownWorkExperience.Location = new System.Drawing.Point(116, 68); + this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + this.numericUpDownWorkExperience.Size = new System.Drawing.Size(264, 23); + this.numericUpDownWorkExperience.TabIndex = 16; + // + // textBoxPassword + // + this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxPassword.Location = new System.Drawing.Point(116, 40); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.PasswordChar = '*'; + this.textBoxPassword.Size = new System.Drawing.Size(264, 23); + this.textBoxPassword.TabIndex = 15; + // + // textBoxFio + // + this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxFio.Location = new System.Drawing.Point(116, 11); + this.textBoxFio.Name = "textBoxFio"; + this.textBoxFio.Size = new System.Drawing.Size(264, 23); + this.textBoxFio.TabIndex = 14; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(14, 99); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(91, 15); + this.label4.TabIndex = 13; + this.label4.Text = "Квалификация:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(67, 70); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(38, 15); + this.label3.TabIndex = 12; + this.label3.Text = "Стаж:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(58, 43); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(52, 15); + this.label2.TabIndex = 11; + this.label2.Text = "Пароль:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(68, 14); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(37, 15); + this.label1.TabIndex = 10; + this.label1.Text = "ФИО:"; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(402, 196); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.numericUpDownWorkExperience); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFio); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormImplementer"; + this.Text = "FormImplementer"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private NumericUpDown numericUpDownQualification; + private NumericUpDown numericUpDownWorkExperience; + private TextBox textBoxPassword; + private TextBox textBoxFio; + private Label label4; + private Label label3; + private Label label2; + private Label label1; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/FormImplementer.cs b/PrecastConcretePlant/FormImplementer.cs new file mode 100644 index 0000000..2aa54fd --- /dev/null +++ b/PrecastConcretePlant/FormImplementer.cs @@ -0,0 +1,100 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; + +namespace PrecastConcretePlantView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFio.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExperience.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFio.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFio.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExperience.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/PrecastConcretePlant/FormImplementer.resx b/PrecastConcretePlant/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/FormImplementer.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/FormImplementers.Designer.cs b/PrecastConcretePlant/FormImplementers.Designer.cs new file mode 100644 index 0000000..b9269a9 --- /dev/null +++ b/PrecastConcretePlant/FormImplementers.Designer.cs @@ -0,0 +1,121 @@ +namespace PrecastConcretePlantView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRef.Location = new System.Drawing.Point(532, 149); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(90, 37); + this.buttonRef.TabIndex = 14; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDel.Location = new System.Drawing.Point(532, 110); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(90, 33); + this.buttonDel.TabIndex = 13; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUpd.Location = new System.Drawing.Point(532, 70); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(90, 34); + this.buttonUpd.TabIndex = 12; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAdd.Location = new System.Drawing.Point(532, 34); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(90, 30); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(469, 290); + this.dataGridView.TabIndex = 10; + // + // FormViewImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(634, 314); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormViewImplementers"; + this.Text = "FormViewImplementers"; + this.Load += new System.EventHandler(this.FormViewImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/FormImplementers.cs b/PrecastConcretePlant/FormImplementers.cs new file mode 100644 index 0000000..81fb05c --- /dev/null +++ b/PrecastConcretePlant/FormImplementers.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlant; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; + +namespace PrecastConcretePlantView +{ + 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 FormViewImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/FormImplementers.resx b/PrecastConcretePlant/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/FormImplementers.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/FormMain.Designer.cs index ed11cf3..c86141e 100644 --- a/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/FormMain.Designer.cs @@ -28,179 +28,186 @@ /// private void InitializeComponent() { - this.MenuStrip = new System.Windows.Forms.MenuStrip(); - this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокЖБИToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.DataGridView = new System.Windows.Forms.DataGridView(); - this.CreateOrderButton = new System.Windows.Forms.Button(); - this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); - this.OrderReadyButton = new System.Windows.Forms.Button(); - this.IssuedOrderButton = new System.Windows.Forms.Button(); - this.UpdateListButton = new System.Windows.Forms.Button(); - this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.MenuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); - this.SuspendLayout(); + MenuStrip = new MenuStrip(); + Справочники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(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); + DataGridView = new DataGridView(); + CreateOrderButton = new Button(); + TakeOrderInWorkButton = new Button(); + OrderReadyButton = new Button(); + IssuedOrderButton = new Button(); + UpdateListButton = new Button(); + MenuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); // // MenuStrip // - this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.СправочникиToolStripMenuItem, - this.отчетыToolStripMenuItem}); - this.MenuStrip.Location = new System.Drawing.Point(0, 0); - this.MenuStrip.Name = "MenuStrip"; - this.MenuStrip.Size = new System.Drawing.Size(953, 24); - this.MenuStrip.TabIndex = 0; - this.MenuStrip.Text = "menuStrip1"; + MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); + MenuStrip.Location = new Point(0, 0); + MenuStrip.Name = "MenuStrip"; + MenuStrip.Size = new Size(953, 24); + MenuStrip.TabIndex = 0; + MenuStrip.Text = "menuStrip1"; // // СправочникиToolStripMenuItem // - this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.ИзделияToolStripMenuItem, - this.КомпонентыToolStripMenuItem, - this.клиентыToolStripMenuItem}); - this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; - this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.СправочникиToolStripMenuItem.Text = "Cправочники"; + СправочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ИзделияToolStripMenuItem, КомпонентыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); + СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; + СправочникиToolStripMenuItem.Size = new Size(94, 20); + СправочникиToolStripMenuItem.Text = "Cправочники"; // // ИзделияToolStripMenuItem // - this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.ИзделияToolStripMenuItem.Text = "ЖБИ"; - this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; + ИзделияToolStripMenuItem.Size = new Size(180, 22); + ИзделияToolStripMenuItem.Text = "ЖБИ"; + ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // // КомпонентыToolStripMenuItem // - this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.КомпонентыToolStripMenuItem.Text = "Компоненты"; - this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); - // - // отчетыToolStripMenuItem - // - this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.списокЖБИToolStripMenuItem, - this.компонентыПоИзделиямToolStripMenuItem, - this.списокЗаказовToolStripMenuItem}); - this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); - this.отчетыToolStripMenuItem.Text = "Отчеты"; - // - // списокЖБИToolStripMenuItem - // - this.списокЖБИToolStripMenuItem.Name = "списокЖБИToolStripMenuItem"; - this.списокЖБИToolStripMenuItem.Size = new System.Drawing.Size(197, 22); - this.списокЖБИToolStripMenuItem.Text = "Список ЖБИ"; - this.списокЖБИToolStripMenuItem.Click += new System.EventHandler(this.списокИзделийToolStripMenuItem_Click); - // - // компонентыПоИзделиямToolStripMenuItem - // - this.компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; - this.компонентыПоИзделиямToolStripMenuItem.Size = new System.Drawing.Size(197, 22); - this.компонентыПоИзделиямToolStripMenuItem.Text = "ЖБИ по компонентам"; - this.компонентыПоИзделиямToolStripMenuItem.Click += new System.EventHandler(this.компонентыПоИзделиямToolStripMenuItem_Click); - // - // списокЗаказовToolStripMenuItem - // - this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(197, 22); - this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; - this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); - // - // DataGridView - // - this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.DataGridView.Location = new System.Drawing.Point(0, 27); - this.DataGridView.Name = "DataGridView"; - this.DataGridView.RowTemplate.Height = 25; - this.DataGridView.Size = new System.Drawing.Size(805, 421); - this.DataGridView.TabIndex = 1; - // - // CreateOrderButton - // - this.CreateOrderButton.Location = new System.Drawing.Point(825, 27); - this.CreateOrderButton.Name = "CreateOrderButton"; - this.CreateOrderButton.Size = new System.Drawing.Size(104, 33); - this.CreateOrderButton.TabIndex = 2; - this.CreateOrderButton.Text = "Создать заказ"; - this.CreateOrderButton.UseVisualStyleBackColor = true; - this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click); - // - // TakeOrderInWorkButton - // - this.TakeOrderInWorkButton.Location = new System.Drawing.Point(825, 66); - this.TakeOrderInWorkButton.Name = "TakeOrderInWorkButton"; - this.TakeOrderInWorkButton.Size = new System.Drawing.Size(104, 39); - this.TakeOrderInWorkButton.TabIndex = 3; - this.TakeOrderInWorkButton.Text = "Отдать на выполнение"; - this.TakeOrderInWorkButton.UseVisualStyleBackColor = true; - this.TakeOrderInWorkButton.Click += new System.EventHandler(this.TakeOrderInWorkButton_Click); - // - // OrderReadyButton - // - this.OrderReadyButton.Location = new System.Drawing.Point(825, 111); - this.OrderReadyButton.Name = "OrderReadyButton"; - this.OrderReadyButton.Size = new System.Drawing.Size(104, 33); - this.OrderReadyButton.TabIndex = 4; - this.OrderReadyButton.Text = "Заказ готов"; - this.OrderReadyButton.UseVisualStyleBackColor = true; - this.OrderReadyButton.Click += new System.EventHandler(this.OrderReadyButton_Click); - // - // IssuedOrderButton - // - this.IssuedOrderButton.Location = new System.Drawing.Point(825, 150); - this.IssuedOrderButton.Name = "IssuedOrderButton"; - this.IssuedOrderButton.Size = new System.Drawing.Size(104, 33); - this.IssuedOrderButton.TabIndex = 5; - this.IssuedOrderButton.Text = "Заказ выдан"; - this.IssuedOrderButton.UseVisualStyleBackColor = true; - this.IssuedOrderButton.Click += new System.EventHandler(this.IssuedOrderButton_Click); - // - // UpdateListButton - // - this.UpdateListButton.Location = new System.Drawing.Point(825, 189); - this.UpdateListButton.Name = "UpdateListButton"; - this.UpdateListButton.Size = new System.Drawing.Size(104, 33); - this.UpdateListButton.TabIndex = 6; - this.UpdateListButton.Text = "Обновить список"; - this.UpdateListButton.UseVisualStyleBackColor = true; - this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); + КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(180, 22); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // // клиентыToolStripMenuItem // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(180, 22); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(180, 22); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокЖБИToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокЖБИToolStripMenuItem + // + списокЖБИToolStripMenuItem.Name = "списокЖБИToolStripMenuItem"; + списокЖБИToolStripMenuItem.Size = new Size(197, 22); + списокЖБИToolStripMenuItem.Text = "Список ЖБИ"; + списокЖБИToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click; + // + // компонентыПоИзделиямToolStripMenuItem + // + компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem"; + компонентыПоИзделиямToolStripMenuItem.Size = new Size(197, 22); + компонентыПоИзделиямToolStripMenuItem.Text = "ЖБИ по компонентам"; + компонентыПоИзделиямToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click; + // + // списокЗаказовToolStripMenuItem + // + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(197, 22); + списокЗаказовToolStripMenuItem.Text = "Список заказов"; + списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; + // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(92, 20); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(0, 27); + DataGridView.Name = "DataGridView"; + DataGridView.RowTemplate.Height = 25; + DataGridView.Size = new Size(805, 421); + DataGridView.TabIndex = 1; + // + // CreateOrderButton + // + CreateOrderButton.Location = new Point(825, 27); + CreateOrderButton.Name = "CreateOrderButton"; + CreateOrderButton.Size = new Size(104, 33); + CreateOrderButton.TabIndex = 2; + CreateOrderButton.Text = "Создать заказ"; + CreateOrderButton.UseVisualStyleBackColor = true; + CreateOrderButton.Click += CreateOrderButton_Click; + // + // TakeOrderInWorkButton + // + TakeOrderInWorkButton.Location = new Point(825, 66); + TakeOrderInWorkButton.Name = "TakeOrderInWorkButton"; + TakeOrderInWorkButton.Size = new Size(104, 39); + TakeOrderInWorkButton.TabIndex = 3; + TakeOrderInWorkButton.Text = "Отдать на выполнение"; + TakeOrderInWorkButton.UseVisualStyleBackColor = true; + TakeOrderInWorkButton.Click += TakeOrderInWorkButton_Click; + // + // OrderReadyButton + // + OrderReadyButton.Location = new Point(825, 111); + OrderReadyButton.Name = "OrderReadyButton"; + OrderReadyButton.Size = new Size(104, 33); + OrderReadyButton.TabIndex = 4; + OrderReadyButton.Text = "Заказ готов"; + OrderReadyButton.UseVisualStyleBackColor = true; + OrderReadyButton.Click += OrderReadyButton_Click; + // + // IssuedOrderButton + // + IssuedOrderButton.Location = new Point(825, 150); + IssuedOrderButton.Name = "IssuedOrderButton"; + IssuedOrderButton.Size = new Size(104, 33); + IssuedOrderButton.TabIndex = 5; + IssuedOrderButton.Text = "Заказ выдан"; + IssuedOrderButton.UseVisualStyleBackColor = true; + IssuedOrderButton.Click += IssuedOrderButton_Click; + // + // UpdateListButton + // + UpdateListButton.Location = new Point(825, 189); + UpdateListButton.Name = "UpdateListButton"; + UpdateListButton.Size = new Size(104, 33); + UpdateListButton.TabIndex = 6; + UpdateListButton.Text = "Обновить список"; + UpdateListButton.UseVisualStyleBackColor = true; + UpdateListButton.Click += UpdateListButton_Click; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(953, 450); - this.Controls.Add(this.UpdateListButton); - this.Controls.Add(this.IssuedOrderButton); - this.Controls.Add(this.OrderReadyButton); - this.Controls.Add(this.TakeOrderInWorkButton); - this.Controls.Add(this.CreateOrderButton); - this.Controls.Add(this.DataGridView); - this.Controls.Add(this.MenuStrip); - this.MainMenuStrip = this.MenuStrip; - this.Name = "FormMain"; - this.Text = "Завод ЖБИ"; - this.Load += new System.EventHandler(this.FormMain_Load); - this.MenuStrip.ResumeLayout(false); - this.MenuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(953, 450); + Controls.Add(UpdateListButton); + Controls.Add(IssuedOrderButton); + Controls.Add(OrderReadyButton); + Controls.Add(TakeOrderInWorkButton); + Controls.Add(CreateOrderButton); + Controls.Add(DataGridView); + Controls.Add(MenuStrip); + MainMenuStrip = MenuStrip; + Name = "FormMain"; + Text = "Завод ЖБИ"; + Load += FormMain_Load; + MenuStrip.ResumeLayout(false); + MenuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -220,5 +227,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/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/FormMain.cs index 8283c70..4210dbb 100644 --- a/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/FormMain.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using PrecastConcretePlant; +using PrecastConcretePlantBusinessLogic.BusinessLogic; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantDataModels.Enums; @@ -21,13 +22,15 @@ namespace PrecastConcretePlantView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -48,6 +51,7 @@ namespace PrecastConcretePlantView DataGridView.DataSource = list; DataGridView.Columns["ReinforcedId"].Visible = false; DataGridView.Columns["ClientId"].Visible = false; + DataGridView.Columns["ImplementerId"].Visible = false; DataGridView.Columns["DateImplement"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } @@ -220,5 +224,22 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic + )) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/Program.cs index 2002fe6..8f6683e 100644 --- a/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/Program.cs @@ -44,6 +44,9 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -59,7 +62,8 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); - + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/IWorkProcess.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/IWorkProcess.cs new file mode 100644 index 0000000..d69bed0 --- /dev/null +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/IWorkProcess.cs @@ -0,0 +1,17 @@ +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogic +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..c2d8ca7 --- /dev/null +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,127 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.BusinessLogic +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + 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 Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update 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; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО", nameof(model.ImplementerFIO)); + } + if (model.Qualification <= 0) + { + throw new ArgumentNullException("Квалификация должна быть больше 0", nameof(model.Qualification)); + } + if (model.WorkExperience <= 0) + { + throw new ArgumentNullException("Стаж должен быть больше 0", nameof(model.WorkExperience)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля", nameof(model.Password)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. Qualification:{Qualification}. WorkExperience:{WorkExperience}. Id:{Id}", + model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs index 37c66e3..0b1c5f5 100644 --- a/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -46,30 +46,57 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic return true; } - public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + public OrderViewModel? ReadElement(OrderSearchModel model) { - CheckModel(model); - - if (model.Status + 1 != newStatus) + if (model == null) { - _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); - return false; + throw new ArgumentNullException(nameof(model)); } + _logger.LogInformation("ReadElement. DateFrom:{DateFrom}. DateTo:{DateTo}. Id:{Id}", model.DateFrom, model.DateTo, model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed"); + throw new InvalidOperationException(); + } model.Status = newStatus; - - if (model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) + { model.DateImplement = DateTime.Now; - + } + else + { + model.DateImplement = viewModel.DateImplement; + } + if (viewModel.ImplementerId.HasValue) + { + model.ImplementerId = viewModel.ImplementerId.Value; + } + CheckModel(model, false); if (_orderStorage.Update(model) == null) { - model.Status--; - _logger.LogWarning("Update operation failed"); + _logger.LogWarning("Change status operation failed"); return false; } - return true; } + public bool TakeOrderInWork(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выполняется); diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..5e3da1e --- /dev/null +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,141 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.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 = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer, orders); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = order.Id + }); + + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) + { + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) + { + return; + } + try + { + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs b/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..1c55a14 --- /dev/null +++ b/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BindingModels +{ + public class ImplementerBindingModel + { + 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/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs b/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs index 7b2701e..d903ac4 100644 --- a/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs +++ b/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs @@ -18,5 +18,6 @@ namespace PrecastConcretePlantContracts.BindingModels public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs b/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..37fbec9 --- /dev/null +++ b/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs b/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs index 5b3c94b..3895100 100644 --- a/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace PrecastConcretePlantContracts.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/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs b/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..8e9b321 --- /dev/null +++ b/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs b/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs index 1897b6b..015ba65 100644 --- a/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs +++ b/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using PrecastConcretePlantDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,8 +11,10 @@ namespace PrecastConcretePlantContracts.SearchModels { public int? Id { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public List? Status { get; set; } } } diff --git a/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs b/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..a0c0e80 --- /dev/null +++ b/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs b/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..b41daf9 --- /dev/null +++ b/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs index a37bd83..8ca2a5d 100644 --- a/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs +++ b/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs @@ -16,6 +16,10 @@ namespace PrecastConcretePlantContracts.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; + [DisplayName("Количество")] public int ReinforcedId { get; set; } [DisplayName("ЖБИ")] public string ReinforcedName { get; set; } = string.Empty; diff --git a/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs b/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..c337f92 --- /dev/null +++ b/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs @@ -0,0 +1,89 @@ +using Microsoft.EntityFrameworkCore; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new PrecastConcretePlantDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + using var context = new PrecastConcretePlantDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new PrecastConcretePlantDatabase(); + return context.Implementers + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new PrecastConcretePlantDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return context.Implementers + .FirstOrDefault(x => x.Id == newImplementer.Id) + ?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new PrecastConcretePlantDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return context.Implementers + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new PrecastConcretePlantDatabase(); + var implementer = context.Implementers + .FirstOrDefault(rec => rec.Id == model.Id); + if (implementer != null) + { + context.Implementers.Remove(implementer); + context.SaveChanges(); + return implementer.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs b/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs index a968731..79eb72b 100644 --- a/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs +++ b/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs @@ -17,19 +17,21 @@ namespace PrecastConcretePlantDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new PrecastConcretePlantDatabase(); + var element = context.Orders + .Include(x => x.Reinforced) + .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) { - var deletedElement = context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; context.Orders.Remove(element); context.SaveChanges(); + return element.GetViewModel; } + return null; } @@ -39,90 +41,112 @@ namespace PrecastConcretePlantDatabaseImplement.Implements { return null; } + using var context = new PrecastConcretePlantDatabase(); - return context.Orders.Include(x => x.Reinforced).Include(x => x.Client) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; + + return context.Orders + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + (model.Status == null || model.Status != null && model.Status.Contains(x.Status)) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || + model.Id.HasValue && x.Id == model.Id + ) + ?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - using var context = new PrecastConcretePlantDatabase(); if (model.Id.HasValue) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + var result = GetElement(model); + return result != null ? new() { result } : new(); } - else if (model.DateFrom != null && model.DateTo != null) + + using var context = new PrecastConcretePlantDatabase(); + IQueryable? queryWhere = null; + + if (model.DateFrom.HasValue && model.DateTo.HasValue) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); + queryWhere = context.Orders + .Where(x => model.DateFrom <= x.DateCreate.Date && + x.DateCreate.Date <= model.DateTo); } + + else if (model.Status != null) + { + queryWhere = context.Orders.Where(x => model.Status.Contains(x.Status)); + } + else if (model.ClientId.HasValue) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); + queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId); } + else { return new(); } + + return queryWhere + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { using var context = new PrecastConcretePlantDatabase(); + return context.Orders .Include(x => x.Reinforced) .Include(x => x.Client) - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Implementer) + .Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) { var newOrder = Order.Create(model); + if (newOrder == null) { return null; } + using var context = new PrecastConcretePlantDatabase(); + context.Orders.Add(newOrder); context.SaveChanges(); + return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == newOrder.Id) - ?.GetViewModel; + .Include(x => x.Reinforced) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == newOrder.Id) + ?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { using var context = new PrecastConcretePlantDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + + var order = context.Orders + .Include(x => x.Reinforced) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id); + if (order == null) { return null; } + order.Update(model); context.SaveChanges(); - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; + + return order.GetViewModel; } } -} +} \ No newline at end of file diff --git a/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.Designer.cs b/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.Designer.cs new file mode 100644 index 0000000..f93519f --- /dev/null +++ b/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PrecastConcretePlantDatabaseImplement; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + [DbContext(typeof(PrecastConcretePlantDatabase))] + [Migration("20230419193952_implementeradd")] + partial class implementeradd + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ReinforcedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Reinforceds"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ReinforcedId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReinforcedId"); + + b.ToTable("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Orders") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => + { + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") + .WithMany("ReinforcedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") + .WithMany("Components") + .HasForeignKey("ReinforcedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Reinforced"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => + { + b.Navigation("ReinforcedComponents"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.cs b/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.cs new file mode 100644 index 0000000..a67685a --- /dev/null +++ b/PrecastConcretePlantDataBaseImplemet/Migrations/20230419193952_implementeradd.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PrecastConcretePlantDatabaseImplement.Migrations +{ + /// + public partial class implementeradd : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.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/PrecastConcretePlantDataBaseImplemet/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs b/PrecastConcretePlantDataBaseImplemet/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs index f4a5a4d..d08d6bf 100644 --- a/PrecastConcretePlantDataBaseImplemet/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs +++ b/PrecastConcretePlantDataBaseImplemet/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ReinforcedId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ReinforcedId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") .WithMany("Orders") .HasForeignKey("ReinforcedId") @@ -167,6 +203,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Reinforced"); }); @@ -199,6 +237,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("ReinforcedComponents"); }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => { b.Navigation("Components"); diff --git a/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs b/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs new file mode 100644 index 0000000..aed2a84 --- /dev/null +++ b/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs @@ -0,0 +1,66 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.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; 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) + { + 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/PrecastConcretePlantDataBaseImplemet/Models/Order.cs b/PrecastConcretePlantDataBaseImplemet/Models/Order.cs index cdca361..224cb5a 100644 --- a/PrecastConcretePlantDataBaseImplemet/Models/Order.cs +++ b/PrecastConcretePlantDataBaseImplemet/Models/Order.cs @@ -20,6 +20,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models public int ReinforcedId { get; private set; } [Required] public int Count { get; private set; } + public int? ImplementerId { get; set; } + [Required] public double Sum { get; private set; } [Required] @@ -29,8 +31,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models public DateTime? DateImplement { get; private set; } public virtual Reinforced Reinforced { get; set; } public virtual Client Client { get; set; } - - public static Order? Create(OrderBindingModel model) + public virtual Implementer? Implementer { get; set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) { @@ -41,6 +43,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models Id = model.Id, ClientId=model.ClientId, ReinforcedId = model.ReinforcedId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -57,20 +60,33 @@ namespace PrecastConcretePlantDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + if (model.ImplementerId.HasValue) + { + ImplementerId = model.ImplementerId; + } } - public OrderViewModel GetViewModel => new() - { - Id = Id, - ClientId=ClientId, - ClientFIO=Client.ClientFIO, - ReinforcedId = ReinforcedId, - ReinforcedName = Reinforced.ReinforcedName, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - }; + public OrderViewModel GetViewModel + { + get + { + using var context = new PrecastConcretePlantDatabase(); + return new OrderViewModel + { + Id = Id, + ReinforcedId = ReinforcedId, + ClientId = ClientId, + ImplementerId = ImplementerId, + ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, + ReinforcedName = context.Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty + }; + } + } } } diff --git a/PrecastConcretePlantDataBaseImplemet/PrecastConcretePlantDatabase.cs b/PrecastConcretePlantDataBaseImplemet/PrecastConcretePlantDatabase.cs index 37066ae..60b3cda 100644 --- a/PrecastConcretePlantDataBaseImplemet/PrecastConcretePlantDatabase.cs +++ b/PrecastConcretePlantDataBaseImplemet/PrecastConcretePlantDatabase.cs @@ -15,7 +15,7 @@ namespace PrecastConcretePlantDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-EJNKGL2;Initial Catalog= PrecastConcretePlantDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-0IOO2C0;Initial Catalog= PrecastConcretePlantDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } @@ -24,5 +24,6 @@ namespace PrecastConcretePlantDatabaseImplement public virtual DbSet ReinforcedComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/PrecastConcretePlantDataModels/Models/IImplementerModel.cs b/PrecastConcretePlantDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..7386da8 --- /dev/null +++ b/PrecastConcretePlantDataModels/Models/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs b/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..c2a7709 --- /dev/null +++ b/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,104 @@ +using Microsoft.AspNetCore.Mvc; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; + +namespace PrecastConcretePlantRestApi.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 = new() { 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; + } + } + } +} From bf3a4908ef26b6859a475f6827f8cc5d4c1f5340 Mon Sep 17 00:00:00 2001 From: Kate Date: Thu, 20 Apr 2023 12:44:42 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=BB=D1=806=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogicsContracts}/IWorkProcess.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {PrecastConcretePlantBusinessLogic/BusinessLogic => PrecastConcretePlantContracts/BusinessLogicsContracts}/IWorkProcess.cs (100%) diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/IWorkProcess.cs b/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs similarity index 100% rename from PrecastConcretePlantBusinessLogic/BusinessLogic/IWorkProcess.cs rename to PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs From c6d13da0f3811a3cd226e774582eec7719c683a8 Mon Sep 17 00:00:00 2001 From: Kate Date: Fri, 28 Apr 2023 21:24:51 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=BB=D1=806=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataFileSingleton.cs | 5 + .../Implements/ImplementerStorage.cs | 103 ++++++++++++++ .../Implements/OrderStorage.cs | 14 ++ .../Models/Implementer.cs | 82 +++++++++++ PrecastConcreteFileImplement/Models/Order.cs | 9 +- .../ViewModels/OrderViewModel.cs | 1 - .../Implements/ImplementerStorage.cs | 83 +++++++---- .../Models/Implementer.cs | 4 + .../Models/Order.cs | 5 +- .../DataListSingleton.cs | 2 + .../Implements/ImplementerStorage.cs | 130 ++++++++++++++++++ .../Implements/OrderStorage.cs | 21 +++ 12 files changed, 424 insertions(+), 35 deletions(-) create mode 100644 PrecastConcreteFileImplement/Implements/ImplementerStorage.cs create mode 100644 PrecastConcreteFileImplement/Models/Implementer.cs create mode 100644 PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs diff --git a/PrecastConcreteFileImplement/DataFileSingleton.cs b/PrecastConcreteFileImplement/DataFileSingleton.cs index c9d656c..0a20983 100644 --- a/PrecastConcreteFileImplement/DataFileSingleton.cs +++ b/PrecastConcreteFileImplement/DataFileSingleton.cs @@ -15,10 +15,12 @@ namespace PrecastConcretePlantFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string ReinforcedFileName = "Reinforced.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Reinforceds { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -35,6 +37,8 @@ namespace PrecastConcretePlantFileImplement => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x + => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => @@ -43,6 +47,7 @@ namespace PrecastConcretePlantFileImplement Reinforced.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers=LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/PrecastConcreteFileImplement/Implements/ImplementerStorage.cs b/PrecastConcreteFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..e16961c --- /dev/null +++ b/PrecastConcreteFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null) + return _source.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + + if (model.ImplementerFIO != null) + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + + return res?.GetViewModel; + } + } +} diff --git a/PrecastConcreteFileImplement/Implements/OrderStorage.cs b/PrecastConcreteFileImplement/Implements/OrderStorage.cs index 5e98405..d6a7c66 100644 --- a/PrecastConcreteFileImplement/Implements/OrderStorage.cs +++ b/PrecastConcreteFileImplement/Implements/OrderStorage.cs @@ -37,6 +37,20 @@ namespace PrecastConcretePlantFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { + if (model.ImplementerId.HasValue && model.Statuses != null) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && + model.Statuses.Contains(x.Status)) + ?.GetViewModel; + } + + if (model.ImplementerId.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) + ?.GetViewModel; + } if (!model.Id.HasValue) { return null; diff --git a/PrecastConcreteFileImplement/Models/Implementer.cs b/PrecastConcreteFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..cb887cb --- /dev/null +++ b/PrecastConcreteFileImplement/Models/Implementer.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/PrecastConcreteFileImplement/Models/Order.cs b/PrecastConcreteFileImplement/Models/Order.cs index c7db726..9447a29 100644 --- a/PrecastConcreteFileImplement/Models/Order.cs +++ b/PrecastConcreteFileImplement/Models/Order.cs @@ -13,6 +13,7 @@ namespace PrecastConcretePlantFileImplement.Models { public class Order : IOrderModel { + public int? ImplementerId { get; set; } public int ClientId { get; private set; } public int ReinforcedId { get; private set; } public int Count { get; private set; } @@ -36,6 +37,7 @@ namespace PrecastConcretePlantFileImplement.Models return new Order() { Id = model.Id, + ImplementerId = model.ImplementerId, ClientId = model.ClientId, ReinforcedId = model.ReinforcedId, Count = model.Count, @@ -56,8 +58,9 @@ namespace PrecastConcretePlantFileImplement.Models var order = new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value) ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value), - ClientId=Convert.ToInt32(element.Element("ClientId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -85,6 +88,7 @@ namespace PrecastConcretePlantFileImplement.Models { Id = Id, ClientId = ClientId, + ImplementerId = ImplementerId, ReinforcedId = ReinforcedId, Count = Count, Sum = Sum, @@ -95,7 +99,8 @@ namespace PrecastConcretePlantFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), - new XAttribute("ClientId",ClientId.ToString()), + new XAttribute("ClientId", ClientId.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("ReinforcedId", ReinforcedId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), diff --git a/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs index 8ca2a5d..4ef43de 100644 --- a/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs +++ b/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs @@ -19,7 +19,6 @@ namespace PrecastConcretePlantContracts.ViewModels public int? ImplementerId { get; set; } [DisplayName("ФИО исполнителя")] public string? ImplementerFIO { get; set; } = string.Empty; - [DisplayName("Количество")] public int ReinforcedId { get; set; } [DisplayName("ЖБИ")] public string ReinforcedName { get; set; } = string.Empty; diff --git a/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs b/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs index c337f92..7027c5d 100644 --- a/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs +++ b/PrecastConcretePlantDataBaseImplemet/Implements/ImplementerStorage.cs @@ -24,52 +24,80 @@ namespace PrecastConcretePlantDatabaseImplement.Implements public List GetFilteredList(ImplementerSearchModel model) { - using var context = new PrecastConcretePlantDatabase(); - return context.Implementers + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var implementer = GetElement(model); + + return implementer != null ? new() { implementer } : new(); + } + + if (model.ImplementerFIO != null) + { + using var context = new SoftwareInstallationDataBase(); + + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) .Select(x => x.GetViewModel) .ToList(); + } + + return new(); } public ImplementerViewModel? GetElement(ImplementerSearchModel model) { - if (!model.Id.HasValue) - { - return null; - } using var context = new PrecastConcretePlantDatabase(); - return context.Implementers - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + if (model.Id.HasValue) + return context.Implementers + .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + + if (model.ImplementerFIO != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + ?.GetViewModel; + + return null; } public ImplementerViewModel? Insert(ImplementerBindingModel model) { - var newImplementer = Implementer.Create(model); - if (newImplementer == null) - { - return null; - } using var context = new PrecastConcretePlantDatabase(); - context.Implementers.Add(newImplementer); - context.SaveChanges(); - return context.Implementers - .FirstOrDefault(x => x.Id == newImplementer.Id) - ?.GetViewModel; + var implementer = Implementer.Create(model); + + if (implementer != null) + { + context.Implementers.Add(implementer); + context.SaveChanges(); + } + + return implementer?.GetViewModel; } public ImplementerViewModel? Update(ImplementerBindingModel model) { using var context = new PrecastConcretePlantDatabase(); - var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); - if (implementer == null) + var implementer = context.Implementers + .FirstOrDefault(x => x.Id == model.Id); + + if (implementer != null) { - return null; + implementer.Update(model); + context.SaveChanges(); } - implementer.Update(model); - context.SaveChanges(); - return context.Implementers - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; + + return implementer?.GetViewModel; } public ImplementerViewModel? Delete(ImplementerBindingModel model) @@ -81,9 +109,8 @@ namespace PrecastConcretePlantDatabaseImplement.Implements { context.Implementers.Remove(implementer); context.SaveChanges(); - return implementer.GetViewModel; } - return null; + return implementer?.GetViewModel; } } } \ No newline at end of file diff --git a/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs b/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs index aed2a84..0db20f3 100644 --- a/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs +++ b/PrecastConcretePlantDataBaseImplemet/Models/Implementer.cs @@ -48,6 +48,10 @@ namespace PrecastConcretePlantDatabaseImplement.Models public void Update(ImplementerBindingModel model) { + if (model == null) + { + return; + } ImplementerFIO = model.ImplementerFIO; Password = model.Password; WorkExperience = model.WorkExperience; diff --git a/PrecastConcretePlantDataBaseImplemet/Models/Order.cs b/PrecastConcretePlantDataBaseImplemet/Models/Order.cs index 224cb5a..2ecc9a1 100644 --- a/PrecastConcretePlantDataBaseImplemet/Models/Order.cs +++ b/PrecastConcretePlantDataBaseImplemet/Models/Order.cs @@ -60,10 +60,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; - if (model.ImplementerId.HasValue) - { - ImplementerId = model.ImplementerId; - } + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel diff --git a/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlantListImplement/DataListSingleton.cs index 1a9a863..cd739ac 100644 --- a/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -14,12 +14,14 @@ namespace PrecastConcretePlantListImplement public List Orders { get; set; } public List Reinforceds { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Reinforceds = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs b/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..fdb06d6 --- /dev/null +++ b/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,130 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && + x.Password.Equals(model.Password)) + return x.GetViewModel; + + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + List result = new(); + + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + + return implementer.GetViewModel; + } + } + return null; + } + } +} diff --git a/PrecastConcretePlantListImplement/Implements/OrderStorage.cs b/PrecastConcretePlantListImplement/Implements/OrderStorage.cs index f368705..3ededc3 100644 --- a/PrecastConcretePlantListImplement/Implements/OrderStorage.cs +++ b/PrecastConcretePlantListImplement/Implements/OrderStorage.cs @@ -47,6 +47,18 @@ namespace PrecastConcretePlantListImplement.Implements { return order.GetViewModel; } + else if (model.ImplementerId.HasValue && model.Statuses != null && + order.ImplementerId == model.ImplementerId && + model.Statuses.Contains(order.Status)) + { + return GetViewModel(order); + } + + else if (model.ImplementerId.HasValue && + model.ImplementerId == order.ImplementerId) + { + return GetViewModel(order); + } } return null; @@ -69,6 +81,15 @@ namespace PrecastConcretePlantListImplement.Implements { result.Add(order.GetViewModel); } + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + result.Add(order.GetViewModel); + } + + else if (model.Status != null && model.Status.Contains(order.Status)) + { + result.Add(order.GetViewModel); + } } } else if (model.DateFrom != null && model.DateTo != null) From de4c8fe78ff7548f0be2f958f149700bec573811 Mon Sep 17 00:00:00 2001 From: Kate Date: Tue, 2 May 2023 23:45:39 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=BB=D1=806?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrecastConcreteFileImplement/Models/Order.cs | 2 +- .../BusinessLogic/ImplementerLogic.cs | 4 +- .../BusinessLogic/OrderLogic.cs | 1 + .../BusinessLogic/WorkModeling.cs | 3 +- .../SearchModels/OrderSearchModel.cs | 2 +- .../Implements/OrderStorage.cs | 21 ++----- .../Models/IOrderModel.cs | 1 + .../Models/Implementer.cs | 60 +++++++++++++++++++ .../Models/Order.cs | 5 +- 9 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 PrecastConcretePlantListImplement/Models/Implementer.cs diff --git a/PrecastConcreteFileImplement/Models/Order.cs b/PrecastConcreteFileImplement/Models/Order.cs index 9447a29..b0f336a 100644 --- a/PrecastConcreteFileImplement/Models/Order.cs +++ b/PrecastConcreteFileImplement/Models/Order.cs @@ -58,7 +58,7 @@ namespace PrecastConcretePlantFileImplement.Models var order = new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value) + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs index c2d8ca7..619aeb9 100644 --- a/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -104,9 +104,9 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { throw new ArgumentNullException("Квалификация должна быть больше 0", nameof(model.Qualification)); } - if (model.WorkExperience <= 0) + if (model.WorkExperience < 0) { - throw new ArgumentNullException("Стаж должен быть больше 0", nameof(model.WorkExperience)); + throw new ArgumentNullException("Стаж должен быть не меньше 0", nameof(model.WorkExperience)); } if (string.IsNullOrEmpty(model.Password)) { diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs index 0b1c5f5..d415da2 100644 --- a/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs @@ -108,6 +108,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic public bool FinishOrder(OrderBindingModel model) { + model.DateImplement=DateTime.Now; return StatusUpdate(model, OrderStatus.Выдан); } public List? ReadList(OrderSearchModel? model) diff --git a/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs b/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs index 5e3da1e..ed20a97 100644 --- a/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs +++ b/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs @@ -82,6 +82,7 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic Id = order.Id }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } catch (InvalidOperationException ex) @@ -94,8 +95,6 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic _logger.LogError(ex, "Error while do work"); throw; } - - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } }); } diff --git a/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs b/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs index 015ba65..7748c55 100644 --- a/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs +++ b/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs @@ -14,7 +14,7 @@ namespace PrecastConcretePlantContracts.SearchModels public int? ImplementerId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } - public List? Status { get; set; } + public List? Statuses { get; set; } } } diff --git a/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs b/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs index 79eb72b..0f0b757 100644 --- a/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs +++ b/PrecastConcretePlantDataBaseImplemet/Implements/OrderStorage.cs @@ -44,15 +44,11 @@ namespace PrecastConcretePlantDatabaseImplement.Implements using var context = new PrecastConcretePlantDatabase(); - return context.Orders - .Include(x => x.Client) - .Include(x => x.Implementer) - .FirstOrDefault(x => - (model.Status == null || model.Status != null && model.Status.Contains(x.Status)) && + return context.Orders.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => + (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || model.Id.HasValue && x.Id == model.Id - ) - ?.GetViewModel; + )?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) @@ -73,9 +69,9 @@ namespace PrecastConcretePlantDatabaseImplement.Implements x.DateCreate.Date <= model.DateTo); } - else if (model.Status != null) + else if (model.Statuses != null) { - queryWhere = context.Orders.Where(x => model.Status.Contains(x.Status)); + queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status)); } else if (model.ClientId.HasValue) @@ -120,12 +116,7 @@ namespace PrecastConcretePlantDatabaseImplement.Implements context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Include(x => x.Implementer) - .FirstOrDefault(x => x.Id == newOrder.Id) - ?.GetViewModel; + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) diff --git a/PrecastConcretePlantDataModels/Models/IOrderModel.cs b/PrecastConcretePlantDataModels/Models/IOrderModel.cs index d1aa7b0..0c0b46f 100644 --- a/PrecastConcretePlantDataModels/Models/IOrderModel.cs +++ b/PrecastConcretePlantDataModels/Models/IOrderModel.cs @@ -11,6 +11,7 @@ namespace PrecastConcretePlantDataModels.Models { int ReinforcedId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/PrecastConcretePlantListImplement/Models/Implementer.cs b/PrecastConcretePlantListImplement/Models/Implementer.cs new file mode 100644 index 0000000..132554e --- /dev/null +++ b/PrecastConcretePlantListImplement/Models/Implementer.cs @@ -0,0 +1,60 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} diff --git a/PrecastConcretePlantListImplement/Models/Order.cs b/PrecastConcretePlantListImplement/Models/Order.cs index 66b52a6..ad64030 100644 --- a/PrecastConcretePlantListImplement/Models/Order.cs +++ b/PrecastConcretePlantListImplement/Models/Order.cs @@ -14,6 +14,7 @@ namespace PrecastConcretePlantListImplement.Models { public int ClientId { get; private set; } public int ReinforcedId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -41,7 +42,8 @@ namespace PrecastConcretePlantListImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId }; } @@ -64,6 +66,7 @@ namespace PrecastConcretePlantListImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, + ImplementerId= ImplementerId, DateImplement = DateImplement }; }