From 34d374a60559448b964166db3a58b954f621b277 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 8 Apr 2023 13:43:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormImplementer.Designer.cs | 167 ++++++++++++++++++ LawFirm/LawFirm/FormImplementer.cs | 101 +++++++++++ LawFirm/LawFirm/FormImplementer.resx | 60 +++++++ LawFirm/LawFirm/FormImplementers.Designer.cs | 115 ++++++++++++ LawFirm/LawFirm/FormImplementers.cs | 115 ++++++++++++ LawFirm/LawFirm/FormImplementers.resx | 60 +++++++ LawFirm/LawFirm/FormMain.Designer.cs | 40 +++-- LawFirm/LawFirm/FormMain.cs | 21 ++- LawFirm/LawFirm/Program.cs | 5 + .../BusinessLogics/OrderLogic.cs | 20 +++ .../BusinessLogics/WorkModeling.cs | 137 ++++++++++++++ .../BusinessLogicContracts/IOrderLogic.cs | 1 + .../BusinessLogicContracts/IWorkProcess.cs | 13 ++ .../LawFirmDatabaseImplement/Models/Order.cs | 2 +- .../Controllers/ImplementerController.cs | 108 +++++++++++ 15 files changed, 953 insertions(+), 12 deletions(-) create mode 100644 LawFirm/LawFirm/FormImplementer.Designer.cs create mode 100644 LawFirm/LawFirm/FormImplementer.cs create mode 100644 LawFirm/LawFirm/FormImplementer.resx create mode 100644 LawFirm/LawFirm/FormImplementers.Designer.cs create mode 100644 LawFirm/LawFirm/FormImplementers.cs create mode 100644 LawFirm/LawFirm/FormImplementers.resx create mode 100644 LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 LawFirm/LawFirmContracts/BusinessLogicContracts/IWorkProcess.cs create mode 100644 LawFirm/LawFirmRestApi/Controllers/ImplementerController.cs diff --git a/LawFirm/LawFirm/FormImplementer.Designer.cs b/LawFirm/LawFirm/FormImplementer.Designer.cs new file mode 100644 index 0000000..da319b6 --- /dev/null +++ b/LawFirm/LawFirm/FormImplementer.Designer.cs @@ -0,0 +1,167 @@ +namespace LawFirmView +{ + 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.labelFIO = new System.Windows.Forms.Label(); + this.labelPassword = new System.Windows.Forms.Label(); + this.labelWorkExp = new System.Windows.Forms.Label(); + this.labelQualification = new System.Windows.Forms.Label(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.numericUpDownWorkExp = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExp)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + this.SuspendLayout(); + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(24, 47); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(49, 20); + this.labelFIO.TabIndex = 0; + this.labelFIO.Text = "ФИО: "; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(24, 92); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(65, 20); + this.labelPassword.TabIndex = 1; + this.labelPassword.Text = "Пароль:"; + // + // labelWorkExp + // + this.labelWorkExp.AutoSize = true; + this.labelWorkExp.Location = new System.Drawing.Point(24, 134); + this.labelWorkExp.Name = "labelWorkExp"; + this.labelWorkExp.Size = new System.Drawing.Size(102, 20); + this.labelWorkExp.TabIndex = 2; + this.labelWorkExp.Text = "Стаж работы:"; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(24, 177); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(114, 20); + this.labelQualification.TabIndex = 3; + this.labelQualification.Text = "Квалификация:"; + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(155, 47); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(371, 27); + this.textBoxFIO.TabIndex = 4; + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(155, 85); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(182, 27); + this.textBoxPassword.TabIndex = 5; + // + // numericUpDownWorkExp + // + this.numericUpDownWorkExp.Location = new System.Drawing.Point(155, 132); + this.numericUpDownWorkExp.Name = "numericUpDownWorkExp"; + this.numericUpDownWorkExp.Size = new System.Drawing.Size(182, 27); + this.numericUpDownWorkExp.TabIndex = 6; + // + // numericUpDownQualification + // + this.numericUpDownQualification.Location = new System.Drawing.Point(155, 175); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(182, 27); + this.numericUpDownQualification.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(324, 233); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(103, 29); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(433, 233); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(106, 29); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(551, 274); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.numericUpDownWorkExp); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.labelWorkExp); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExp)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFIO; + private Label labelPassword; + private Label labelWorkExp; + private Label labelQualification; + private TextBox textBoxFIO; + private TextBox textBoxPassword; + private NumericUpDown numericUpDownWorkExp; + private NumericUpDown numericUpDownQualification; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormImplementer.cs b/LawFirm/LawFirm/FormImplementer.cs new file mode 100644 index 0000000..753317e --- /dev/null +++ b/LawFirm/LawFirm/FormImplementer.cs @@ -0,0 +1,101 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + 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; + numericUpDownWorkExp.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)numericUpDownWorkExp.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/LawFirm/LawFirm/FormImplementer.resx b/LawFirm/LawFirm/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/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/LawFirm/LawFirm/FormImplementers.Designer.cs b/LawFirm/LawFirm/FormImplementers.Designer.cs new file mode 100644 index 0000000..c7123db --- /dev/null +++ b/LawFirm/LawFirm/FormImplementers.Designer.cs @@ -0,0 +1,115 @@ +namespace LawFirmView +{ + 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.buttonCreate = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(667, 12); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(121, 29); + this.buttonCreate.TabIndex = 0; + this.buttonCreate.Text = "Добавить"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(667, 47); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(121, 29); + this.buttonEdit.TabIndex = 1; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(667, 82); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(121, 29); + this.buttonDelete.TabIndex = 2; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(667, 117); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(121, 29); + this.buttonRefresh.TabIndex = 3; + this.buttonRefresh.Text = "Обновить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(649, 426); + this.dataGridView.TabIndex = 4; + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonCreate); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonCreate; + private Button buttonEdit; + private Button buttonDelete; + private Button buttonRefresh; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormImplementers.cs b/LawFirm/LawFirm/FormImplementers.cs new file mode 100644 index 0000000..c37b690 --- /dev/null +++ b/LawFirm/LawFirm/FormImplementers.cs @@ -0,0 +1,115 @@ +using LawFirm; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonCreate_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 buttonEdit_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 buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/LawFirm/LawFirm/FormImplementers.resx b/LawFirm/LawFirm/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/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/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index 70c2693..51a0fbf 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -32,6 +32,8 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиПоДокументамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -42,7 +44,7 @@ this.buttonSetToDone = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); - this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -52,7 +54,8 @@ this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, - this.отчетыToolStripMenuItem}); + this.отчетыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1139, 28); @@ -64,7 +67,8 @@ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.бланкиToolStripMenuItem, this.документыToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -72,17 +76,31 @@ // бланкиToolStripMenuItem // this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; - this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(185, 26); this.бланкиToolStripMenuItem.Text = "Бланки"; this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.бланкиToolStripMenuItem_Click); // // документыToolStripMenuItem // this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; - this.документыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.документыToolStripMenuItem.Size = new System.Drawing.Size(185, 26); this.документыToolStripMenuItem.Text = "Документы"; this.документыToolStripMenuItem.Click += new System.EventHandler(this.документыToolStripMenuItem_Click); // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(185, 26); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(185, 26); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -174,12 +192,12 @@ this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); // - // клиентыToolStripMenuItem + // запускРаботToolStripMenuItem // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(114, 24); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); // // FormMain // @@ -222,5 +240,7 @@ private ToolStripMenuItem бланкиПоДокументамToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 91bff9a..59a8af9 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -22,12 +22,14 @@ namespace LawFirmView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -45,6 +47,7 @@ namespace LawFirmView dataGridView.DataSource = list; dataGridView.Columns["DocumentId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -82,6 +85,15 @@ namespace LawFirmView } } + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + private void бланкиПоДокументамToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReportDocumentBlanks)); @@ -208,5 +220,12 @@ namespace LawFirmView { LoadData(); } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + + } } } diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 1cd6118..b336e9b 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -44,12 +44,15 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -65,6 +68,8 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs index 36422a4..1fcae27 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs @@ -65,6 +65,10 @@ namespace LawFirmBusinessLogic.BusinessLogics Count = viewModel.Count, Sum = viewModel.Sum }; + if (rawModel.ImplementerId.HasValue) + { + model.ImplementerId = rawModel.ImplementerId; + } CheckModel(model, false); if (model.Status + 1 != newStatus) @@ -110,6 +114,22 @@ namespace LawFirmBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", 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 void CheckModel(OrderBindingModel model, bool withParams = true) { diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..963cdfd --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,137 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer, orders); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer, 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.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IOrderLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IOrderLogic.cs index 557d867..ea473b6 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IOrderLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace LawFirmContracts.BusinessLogicContracts 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/LawFirm/LawFirmContracts/BusinessLogicContracts/IWorkProcess.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IWorkProcess.cs new file mode 100644 index 0000000..e4bdae8 --- /dev/null +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.BusinessLogicContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Order.cs b/LawFirm/LawFirmDatabaseImplement/Models/Order.cs index 451da42..f74aa49 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Order.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Order.cs @@ -82,7 +82,7 @@ namespace LawFirmDatabaseImplement.Models Status = Status, DocumentName = context.Documents.FirstOrDefault(x => x.Id == DocumentId)?.DocumentName ?? string.Empty, ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, - ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, + ImplementerFIO = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO?? string.Empty, }; } } diff --git a/LawFirm/LawFirmRestApi/Controllers/ImplementerController.cs b/LawFirm/LawFirmRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..ffe3bd1 --- /dev/null +++ b/LawFirm/LawFirmRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,108 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace LawFirmRestApi.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 + { + Statuses = 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; + } + } + + } +}