From 8fda3c5c07db59aa683922d9bd1cff92b31159c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Wed, 19 Apr 2023 19:47:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ImplementerLogic.cs | 122 +++++++++++++ .../FormImplementer.Designer.cs | 170 ++++++++++++++++++ .../AutomobilePlant/FormImplementer.cs | 121 +++++++++++++ .../AutomobilePlant/FormImplementer.resx | 60 +++++++ .../FormImplementers.Designer.cs | 121 +++++++++++++ .../AutomobilePlant/FormImplementers.cs | 116 ++++++++++++ .../AutomobilePlant/FormImplementers.resx | 60 +++++++ .../AutomobilePlant/FormMain.Designer.cs | 68 ++++--- AutomobilePlant/AutomobilePlant/FormMain.cs | 21 ++- AutomobilePlant/AutomobilePlant/Program.cs | 5 + 10 files changed, 825 insertions(+), 39 deletions(-) create mode 100644 AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormImplementer.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormImplementer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormImplementer.resx create mode 100644 AutomobilePlant/AutomobilePlant/FormImplementers.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormImplementers.cs create mode 100644 AutomobilePlant/AutomobilePlant/FormImplementers.resx diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ImplementerLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..a6760e8 --- /dev/null +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,122 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModel; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage + implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerName:{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 ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerName:{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 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.WorkExperience <0) + { + throw new ArgumentNullException("Нет стажа исполнителя", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentNullException("Нет квалификации исполнителя", nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); + } + _logger.LogInformation("Implementer. ImplementerName:{ImplementerName}. Id: { Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким логином уже есть"); + } + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormImplementer.Designer.cs b/AutomobilePlant/AutomobilePlant/FormImplementer.Designer.cs new file mode 100644 index 0000000..ef84f92 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormImplementer.Designer.cs @@ -0,0 +1,170 @@ +namespace AutomobilePlant +{ + 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.ImplementerNameLabel = new System.Windows.Forms.Label(); + this.ImplementerNameTextBox = new System.Windows.Forms.TextBox(); + this.PasswordLabel = new System.Windows.Forms.Label(); + this.PasswordTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.WorkExLabel = new System.Windows.Forms.Label(); + this.WorkExtextBox = new System.Windows.Forms.TextBox(); + this.QualificationLabel = new System.Windows.Forms.Label(); + this.QualificationtextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // ImplementerNameLabel + // + this.ImplementerNameLabel.AutoSize = true; + this.ImplementerNameLabel.Location = new System.Drawing.Point(46, 19); + this.ImplementerNameLabel.Name = "ImplementerNameLabel"; + this.ImplementerNameLabel.Size = new System.Drawing.Size(45, 20); + this.ImplementerNameLabel.TabIndex = 0; + this.ImplementerNameLabel.Text = "ФИО:"; + // + // ImplementerNameTextBox + // + this.ImplementerNameTextBox.Location = new System.Drawing.Point(103, 16); + this.ImplementerNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ImplementerNameTextBox.Name = "ImplementerNameTextBox"; + this.ImplementerNameTextBox.Size = new System.Drawing.Size(238, 27); + this.ImplementerNameTextBox.TabIndex = 2; + // + // PasswordLabel + // + this.PasswordLabel.AutoSize = true; + this.PasswordLabel.Location = new System.Drawing.Point(46, 72); + this.PasswordLabel.Name = "PasswordLabel"; + this.PasswordLabel.Size = new System.Drawing.Size(73, 20); + this.PasswordLabel.TabIndex = 3; + this.PasswordLabel.Text = "Пароль: "; + // + // PasswordTextBox + // + this.PasswordTextBox.Location = new System.Drawing.Point(103, 68); + this.PasswordTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.PasswordTextBox.Name = "PasswordTextBox"; + this.PasswordTextBox.Size = new System.Drawing.Size(238, 27); + this.PasswordTextBox.TabIndex = 4; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(151, 206); + this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 31); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(265, 206); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(86, 31); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // WorkExLabel + // + this.WorkExLabel.AutoSize = true; + this.WorkExLabel.Location = new System.Drawing.Point(29, 131); + this.WorkExLabel.Name = "WorkExLabel"; + this.WorkExLabel.Size = new System.Drawing.Size(46, 20); + this.WorkExLabel.TabIndex = 7; + this.WorkExLabel.Text = "Стаж:"; + // + // WorkExtextBox + // + this.WorkExtextBox.Location = new System.Drawing.Point(103, 124); + this.WorkExtextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.WorkExtextBox.Name = "WorkExtextBox"; + this.WorkExtextBox.Size = new System.Drawing.Size(238, 27); + this.WorkExtextBox.TabIndex = 8; + // + // QualificationLabel + // + this.QualificationLabel.AutoSize = true; + this.QualificationLabel.Location = new System.Drawing.Point(12, 174); + this.QualificationLabel.Name = "QualificationLabel"; + this.QualificationLabel.Size = new System.Drawing.Size(114, 20); + this.QualificationLabel.TabIndex = 9; + this.QualificationLabel.Text = "Квалификация:"; + // + // QualificationtextBox + // + this.QualificationtextBox.Location = new System.Drawing.Point(132, 171); + this.QualificationtextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.QualificationtextBox.Name = "QualificationtextBox"; + this.QualificationtextBox.Size = new System.Drawing.Size(238, 27); + this.QualificationtextBox.TabIndex = 10; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(418, 262); + this.Controls.Add(this.QualificationtextBox); + this.Controls.Add(this.QualificationLabel); + this.Controls.Add(this.WorkExtextBox); + this.Controls.Add(this.WorkExLabel); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.PasswordTextBox); + this.Controls.Add(this.PasswordLabel); + this.Controls.Add(this.ImplementerNameTextBox); + this.Controls.Add(this.ImplementerNameLabel); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label ImplementerNameLabel; + private TextBox ImplementerNameTextBox; + private Label PasswordLabel; + private TextBox PasswordTextBox; + private Button SaveButton; + private Button ButtonCancel; + private Label WorkExLabel; + private TextBox WorkExtextBox; + private Label QualificationLabel; + private TextBox QualificationtextBox; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormImplementer.cs b/AutomobilePlant/AutomobilePlant/FormImplementer.cs new file mode 100644 index 0000000..082b1c7 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormImplementer.cs @@ -0,0 +1,121 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModel; +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 AutomobilePlant +{ + 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) + { + ImplementerNameTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password.ToString(); + WorkExtextBox.Text = view.WorkExperience.ToString(); + QualificationtextBox.Text = view.Qualification.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(ImplementerNameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(WorkExtextBox.Text)) + { + MessageBox.Show("Заполните стаж", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(QualificationtextBox.Text)) + { + MessageBox.Show("Заполните квалификацию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение исполнителя"); + + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = ImplementerNameTextBox.Text, + Password = PasswordTextBox.Text, + WorkExperience=Convert.ToInt32(WorkExtextBox.Text), + Qualification=Convert.ToInt32(QualificationtextBox.Text) + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormImplementer.resx b/AutomobilePlant/AutomobilePlant/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/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/AutomobilePlant/AutomobilePlant/FormImplementers.Designer.cs b/AutomobilePlant/AutomobilePlant/FormImplementers.Designer.cs new file mode 100644 index 0000000..98b9fa0 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormImplementers.Designer.cs @@ -0,0 +1,121 @@ +namespace AutomobilePlant +{ + 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.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(2, 0); + this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowHeadersWidth = 51; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(630, 735); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(653, 35); + this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(162, 60); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(653, 124); + this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(162, 60); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(653, 216); + this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(162, 60); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(653, 307); + this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(162, 60); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(829, 736); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormImplementers.cs b/AutomobilePlant/AutomobilePlant/FormImplementers.cs new file mode 100644 index 0000000..9a38047 --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/FormImplementers.cs @@ -0,0 +1,116 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlant +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic + logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + LoadData(); + } + 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 AddButton_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 ChangeButton_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 DeleteButton_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 UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlant/FormImplementers.resx b/AutomobilePlant/AutomobilePlant/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AutomobilePlant/AutomobilePlant/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/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs index e6999ab..35da257 100644 --- a/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlant/FormMain.Designer.cs @@ -36,13 +36,13 @@ this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentCarsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ordersToolStripMenuItem = 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(); @@ -53,7 +53,9 @@ this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.СправочникиToolStripMenuItem, this.отчетыToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem, + this.начатьРаботуToolStripMenuItem}); this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); @@ -115,6 +117,27 @@ this.ordersToolStripMenuItem.Text = "Список заказов"; this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(83, 24); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(116, 24); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // + // начатьРаботуToolStripMenuItem + // + this.начатьРаботуToolStripMenuItem.Name = "начатьРаботуToolStripMenuItem"; + this.начатьРаботуToolStripMenuItem.Size = new System.Drawing.Size(124, 24); + this.начатьРаботуToolStripMenuItem.Text = "Начать работу"; + this.начатьРаботуToolStripMenuItem.Click += new System.EventHandler(this.начатьРаботуToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -128,7 +151,7 @@ // // CreateOrderButton // - this.CreateOrderButton.Location = new System.Drawing.Point(832, 37); + this.CreateOrderButton.Location = new System.Drawing.Point(831, 199); this.CreateOrderButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.CreateOrderButton.Name = "CreateOrderButton"; this.CreateOrderButton.Size = new System.Drawing.Size(143, 44); @@ -137,28 +160,6 @@ this.CreateOrderButton.UseVisualStyleBackColor = true; this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click); // - // TakeOrderInWorkButton - // - this.TakeOrderInWorkButton.Location = new System.Drawing.Point(832, 111); - this.TakeOrderInWorkButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.TakeOrderInWorkButton.Name = "TakeOrderInWorkButton"; - this.TakeOrderInWorkButton.Size = new System.Drawing.Size(143, 52); - 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(832, 195); - this.OrderReadyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.OrderReadyButton.Name = "OrderReadyButton"; - this.OrderReadyButton.Size = new System.Drawing.Size(143, 44); - 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(832, 272); @@ -181,13 +182,6 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // - // клиентыToolStripMenuItem - // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(83, 24); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); - // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -195,8 +189,6 @@ this.ClientSize = new System.Drawing.Size(989, 600); 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); @@ -221,8 +213,6 @@ private ToolStripMenuItem КомпонентыToolStripMenuItem; private DataGridView DataGridView; private Button CreateOrderButton; - private Button TakeOrderInWorkButton; - private Button OrderReadyButton; private Button IssuedOrderButton; private Button UpdateListButton; private ToolStripMenuItem отчетыToolStripMenuItem; @@ -230,5 +220,7 @@ private ToolStripMenuItem componentCarsToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem начатьРаботуToolStripMenuItem; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlant/FormMain.cs b/AutomobilePlant/AutomobilePlant/FormMain.cs index 9e598b9..0130c0e 100644 --- a/AutomobilePlant/AutomobilePlant/FormMain.cs +++ b/AutomobilePlant/AutomobilePlant/FormMain.cs @@ -21,13 +21,15 @@ namespace AutomobilePlant 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 +50,7 @@ namespace AutomobilePlant DataGridView.DataSource = list; DataGridView.Columns["CarId"].Visible = false; DataGridView.Columns["ClientId"].Visible = false; + DataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); @@ -237,5 +240,21 @@ namespace AutomobilePlant form.ShowDialog(); } } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void начатьРаботуToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } diff --git a/AutomobilePlant/AutomobilePlant/Program.cs b/AutomobilePlant/AutomobilePlant/Program.cs index 790ca0c..425ad8d 100644 --- a/AutomobilePlant/AutomobilePlant/Program.cs +++ b/AutomobilePlant/AutomobilePlant/Program.cs @@ -41,12 +41,15 @@ namespace AutomobilePlant 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(); @@ -62,6 +65,8 @@ namespace AutomobilePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } }