diff --git a/PlumbingRepair/PlumbingRepair/FormImplementer.Designer.cs b/PlumbingRepair/PlumbingRepair/FormImplementer.Designer.cs
new file mode 100644
index 0000000..6b30b2a
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepair/FormImplementer.Designer.cs
@@ -0,0 +1,173 @@
+namespace PlumbingRepair
+{
+ 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()
+ {
+ FIOTextBox = new TextBox();
+ PasswordTextBox = new TextBox();
+ LabelFIO = new Label();
+ LabelPassword = new Label();
+ QualificationNumericUpDown = new NumericUpDown();
+ WorkExpNumericUpDown = new NumericUpDown();
+ LabelWorkExperience = new Label();
+ LabelQualification = new Label();
+ ButtonCancel = new Button();
+ ButtonSave = new Button();
+ ((System.ComponentModel.ISupportInitialize)QualificationNumericUpDown).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)WorkExpNumericUpDown).BeginInit();
+ SuspendLayout();
+ //
+ // FIOTextBox
+ //
+ FIOTextBox.Location = new Point(128, 16);
+ FIOTextBox.Margin = new Padding(3, 4, 3, 4);
+ FIOTextBox.Name = "FIOTextBox";
+ FIOTextBox.Size = new Size(194, 27);
+ FIOTextBox.TabIndex = 0;
+ //
+ // PasswordTextBox
+ //
+ PasswordTextBox.Location = new Point(128, 65);
+ PasswordTextBox.Margin = new Padding(3, 4, 3, 4);
+ PasswordTextBox.Name = "PasswordTextBox";
+ PasswordTextBox.Size = new Size(194, 27);
+ PasswordTextBox.TabIndex = 1;
+ //
+ // LabelFIO
+ //
+ LabelFIO.AutoSize = true;
+ LabelFIO.Location = new Point(14, 20);
+ LabelFIO.Name = "LabelFIO";
+ LabelFIO.Size = new Size(49, 20);
+ LabelFIO.TabIndex = 2;
+ LabelFIO.Text = "ФИО: ";
+ //
+ // LabelPassword
+ //
+ LabelPassword.AutoSize = true;
+ LabelPassword.Location = new Point(14, 69);
+ LabelPassword.Name = "LabelPassword";
+ LabelPassword.Size = new Size(69, 20);
+ LabelPassword.TabIndex = 3;
+ LabelPassword.Text = "Пароль: ";
+ //
+ // QualificationNumericUpDown
+ //
+ QualificationNumericUpDown.Location = new Point(128, 175);
+ QualificationNumericUpDown.Margin = new Padding(3, 4, 3, 4);
+ QualificationNumericUpDown.Name = "QualificationNumericUpDown";
+ QualificationNumericUpDown.Size = new Size(194, 27);
+ QualificationNumericUpDown.TabIndex = 4;
+ //
+ // WorkExpNumericUpDown
+ //
+ WorkExpNumericUpDown.Location = new Point(128, 120);
+ WorkExpNumericUpDown.Margin = new Padding(3, 4, 3, 4);
+ WorkExpNumericUpDown.Name = "WorkExpNumericUpDown";
+ WorkExpNumericUpDown.Size = new Size(194, 27);
+ WorkExpNumericUpDown.TabIndex = 5;
+ //
+ // LabelWorkExperience
+ //
+ LabelWorkExperience.AutoSize = true;
+ LabelWorkExperience.Location = new Point(14, 123);
+ LabelWorkExperience.Name = "LabelWorkExperience";
+ LabelWorkExperience.Size = new Size(109, 20);
+ LabelWorkExperience.TabIndex = 6;
+ LabelWorkExperience.Text = "Опыт работы: ";
+ //
+ // LabelQualification
+ //
+ LabelQualification.AutoSize = true;
+ LabelQualification.Location = new Point(5, 177);
+ LabelQualification.Name = "LabelQualification";
+ LabelQualification.Size = new Size(118, 20);
+ LabelQualification.TabIndex = 7;
+ LabelQualification.Text = "Квалификация: ";
+ //
+ // ButtonCancel
+ //
+ ButtonCancel.Location = new Point(211, 225);
+ ButtonCancel.Margin = new Padding(3, 4, 3, 4);
+ ButtonCancel.Name = "ButtonCancel";
+ ButtonCancel.Size = new Size(111, 39);
+ ButtonCancel.TabIndex = 8;
+ ButtonCancel.Text = "Отмена";
+ ButtonCancel.UseVisualStyleBackColor = true;
+ ButtonCancel.Click += ButtonCancel_Click;
+ //
+ // ButtonSave
+ //
+ ButtonSave.Location = new Point(94, 225);
+ ButtonSave.Margin = new Padding(3, 4, 3, 4);
+ ButtonSave.Name = "ButtonSave";
+ ButtonSave.Size = new Size(111, 39);
+ ButtonSave.TabIndex = 9;
+ ButtonSave.Text = "Сохранить";
+ ButtonSave.UseVisualStyleBackColor = true;
+ ButtonSave.Click += ButtonSave_Click;
+ //
+ // FormImplementer
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(350, 285);
+ Controls.Add(ButtonSave);
+ Controls.Add(ButtonCancel);
+ Controls.Add(LabelQualification);
+ Controls.Add(LabelWorkExperience);
+ Controls.Add(WorkExpNumericUpDown);
+ Controls.Add(QualificationNumericUpDown);
+ Controls.Add(LabelPassword);
+ Controls.Add(LabelFIO);
+ Controls.Add(PasswordTextBox);
+ Controls.Add(FIOTextBox);
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormImplementer";
+ Text = "Исполнитель";
+ Load += FormImplementer_Load;
+ ((System.ComponentModel.ISupportInitialize)QualificationNumericUpDown).EndInit();
+ ((System.ComponentModel.ISupportInitialize)WorkExpNumericUpDown).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private TextBox FIOTextBox;
+ private TextBox PasswordTextBox;
+ private Label LabelFIO;
+ private Label LabelPassword;
+ private NumericUpDown QualificationNumericUpDown;
+ private NumericUpDown WorkExpNumericUpDown;
+ private Label LabelWorkExperience;
+ private Label LabelQualification;
+ private Button ButtonCancel;
+ private Button ButtonSave;
+ }
+}
\ No newline at end of file
diff --git a/PlumbingRepair/PlumbingRepair/FormImplementer.cs b/PlumbingRepair/PlumbingRepair/FormImplementer.cs
new file mode 100644
index 0000000..daad2de
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepair/FormImplementer.cs
@@ -0,0 +1,106 @@
+using Microsoft.Extensions.Logging;
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.BusinessLogicsContracts;
+using PlumbingRepairContracts.SearchModels;
+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 PlumbingRepair
+{
+ 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 ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(PasswordTextBox.Text))
+ {
+ MessageBox.Show("Заполните пароль", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(FIOTextBox.Text))
+ {
+ MessageBox.Show("Заполните фио", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение исполнителя");
+ try
+ {
+ var model = new ImplementerBindingModel
+ {
+ Id = _id ?? 0,
+ ImplementerFIO = FIOTextBox.Text,
+ Password = PasswordTextBox.Text,
+ Qualification = (int)QualificationNumericUpDown.Value,
+ WorkExperience = (int)WorkExpNumericUpDown.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();
+ }
+
+ 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)
+ {
+ FIOTextBox.Text = view.ImplementerFIO;
+ PasswordTextBox.Text = view.Password;
+ QualificationNumericUpDown.Value = view.Qualification;
+ WorkExpNumericUpDown.Value = view.WorkExperience;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения исполнителя");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepair/FormImplementer.resx b/PlumbingRepair/PlumbingRepair/FormImplementer.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepair/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/PlumbingRepair/PlumbingRepair/FormImplementers.Designer.cs b/PlumbingRepair/PlumbingRepair/FormImplementers.Designer.cs
new file mode 100644
index 0000000..6c36b91
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepair/FormImplementers.Designer.cs
@@ -0,0 +1,114 @@
+namespace PlumbingRepair
+{
+ 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(1, 1);
+ this.DataGridView.Name = "DataGridView";
+ this.DataGridView.RowTemplate.Height = 25;
+ this.DataGridView.Size = new System.Drawing.Size(632, 448);
+ this.DataGridView.TabIndex = 0;
+ //
+ // AddButton
+ //
+ this.AddButton.Location = new System.Drawing.Point(639, 12);
+ this.AddButton.Name = "AddButton";
+ this.AddButton.Size = new System.Drawing.Size(98, 45);
+ 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(639, 63);
+ this.ChangeButton.Name = "ChangeButton";
+ this.ChangeButton.Size = new System.Drawing.Size(98, 45);
+ 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(639, 114);
+ this.DeleteButton.Name = "DeleteButton";
+ this.DeleteButton.Size = new System.Drawing.Size(98, 45);
+ 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(639, 165);
+ this.UpdateButton.Name = "UpdateButton";
+ this.UpdateButton.Size = new System.Drawing.Size(98, 45);
+ 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(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(749, 450);
+ 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.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/PlumbingRepair/PlumbingRepair/FormImplementers.cs b/PlumbingRepair/PlumbingRepair/FormImplementers.cs
new file mode 100644
index 0000000..cd29385
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepair/FormImplementers.cs
@@ -0,0 +1,120 @@
+using Microsoft.Extensions.Logging;
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.BusinessLogicsContracts;
+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 PlumbingRepair
+{
+ 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 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();
+ }
+
+ 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);
+ }
+ }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepair/FormImplementers.resx b/PlumbingRepair/PlumbingRepair/FormImplementers.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepair/FormImplementers.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs
index 2bd0bce..1b475cf 100644
--- a/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs
+++ b/PlumbingRepair/PlumbingRepair/FormMain.Designer.cs
@@ -1,225 +1,215 @@
namespace PlumbingRepair
{
- partial class FormMain
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
+ partial class FormMain
+ {
+ ///
+ /// 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);
- }
+ ///
+ /// 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
+ #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()
- {
- MenuStrip = new MenuStrip();
- СправочникиToolStripMenuItem = new ToolStripMenuItem();
- ИзделияToolStripMenuItem = new ToolStripMenuItem();
- КомпонентыToolStripMenuItem = new ToolStripMenuItem();
- КлиентыToolStripMenuItem = new ToolStripMenuItem();
- отчетыToolStripMenuItem = new ToolStripMenuItem();
- WorksToolStripMenuItem = new ToolStripMenuItem();
- WorkComponentToolStripMenuItem = new ToolStripMenuItem();
- OrdersToolStripMenuItem = 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
- //
- MenuStrip.ImageScalingSize = new Size(20, 20);
- MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem });
- MenuStrip.Location = new Point(0, 0);
- MenuStrip.Name = "MenuStrip";
- MenuStrip.Padding = new Padding(7, 3, 0, 3);
- MenuStrip.Size = new Size(989, 30);
- MenuStrip.TabIndex = 0;
- MenuStrip.Text = "menuStrip1";
- //
- // СправочникиToolStripMenuItem
- //
- СправочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ИзделияToolStripMenuItem, КомпонентыToolStripMenuItem, КлиентыToolStripMenuItem });
- СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
- СправочникиToolStripMenuItem.Size = new Size(117, 24);
- СправочникиToolStripMenuItem.Text = "Cправочники";
- //
- // ИзделияToolStripMenuItem
- //
- ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
- ИзделияToolStripMenuItem.Size = new Size(182, 26);
- ИзделияToolStripMenuItem.Text = "Изделия";
- ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
- //
- // КомпонентыToolStripMenuItem
- //
- КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
- КомпонентыToolStripMenuItem.Size = new Size(182, 26);
- КомпонентыToolStripMenuItem.Text = "Компоненты";
- КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
- //
- // КлиентыToolStripMenuItem
- //
- КлиентыToolStripMenuItem.Name = "КлиентыToolStripMenuItem";
- КлиентыToolStripMenuItem.Size = new Size(182, 26);
- КлиентыToolStripMenuItem.Text = "Клиенты";
- КлиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click;
- //
- // отчетыToolStripMenuItem
- //
- отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { WorksToolStripMenuItem, WorkComponentToolStripMenuItem, OrdersToolStripMenuItem });
- отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
- отчетыToolStripMenuItem.Size = new Size(73, 24);
- отчетыToolStripMenuItem.Text = "Отчеты";
- //
- // WorksToolStripMenuItem
- //
- WorksToolStripMenuItem.Name = "WorksToolStripMenuItem";
- WorksToolStripMenuItem.Size = new Size(273, 26);
- WorksToolStripMenuItem.Text = "Список изделий";
- WorksToolStripMenuItem.Click += WorksToolStripMenuItem_Click;
- //
- // WorkComponentToolStripMenuItem
- //
- WorkComponentToolStripMenuItem.Name = "WorkComponentToolStripMenuItem";
- WorkComponentToolStripMenuItem.Size = new Size(273, 26);
- WorkComponentToolStripMenuItem.Text = "Изделия по компонентам";
- WorkComponentToolStripMenuItem.Click += WorkComponentToolStripMenuItem_Click;
- //
- // OrdersToolStripMenuItem
- //
- OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem";
- OrdersToolStripMenuItem.Size = new Size(273, 26);
- OrdersToolStripMenuItem.Text = "Список заказов";
- OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
- //
- // DataGridView
- //
- DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- DataGridView.Location = new Point(0, 36);
- DataGridView.Margin = new Padding(3, 4, 3, 4);
- DataGridView.Name = "DataGridView";
- DataGridView.RowHeadersWidth = 51;
- DataGridView.RowTemplate.Height = 25;
- DataGridView.Size = new Size(825, 561);
- DataGridView.TabIndex = 1;
- //
- // CreateOrderButton
- //
- CreateOrderButton.Location = new Point(832, 37);
- CreateOrderButton.Margin = new Padding(3, 4, 3, 4);
- CreateOrderButton.Name = "CreateOrderButton";
- CreateOrderButton.Size = new Size(143, 44);
- CreateOrderButton.TabIndex = 2;
- CreateOrderButton.Text = "Создать заказ";
- CreateOrderButton.UseVisualStyleBackColor = true;
- CreateOrderButton.Click += CreateOrderButton_Click;
- //
- // TakeOrderInWorkButton
- //
- TakeOrderInWorkButton.Location = new Point(832, 111);
- TakeOrderInWorkButton.Margin = new Padding(3, 4, 3, 4);
- TakeOrderInWorkButton.Name = "TakeOrderInWorkButton";
- TakeOrderInWorkButton.Size = new Size(143, 52);
- TakeOrderInWorkButton.TabIndex = 3;
- TakeOrderInWorkButton.Text = "Отдать на выполнение";
- TakeOrderInWorkButton.UseVisualStyleBackColor = true;
- TakeOrderInWorkButton.Click += TakeOrderInWorkButton_Click;
- //
- // OrderReadyButton
- //
- OrderReadyButton.Location = new Point(832, 195);
- OrderReadyButton.Margin = new Padding(3, 4, 3, 4);
- OrderReadyButton.Name = "OrderReadyButton";
- OrderReadyButton.Size = new Size(143, 44);
- OrderReadyButton.TabIndex = 4;
- OrderReadyButton.Text = "Заказ готов";
- OrderReadyButton.UseVisualStyleBackColor = true;
- OrderReadyButton.Click += OrderReadyButton_Click;
- //
- // IssuedOrderButton
- //
- IssuedOrderButton.Location = new Point(832, 272);
- IssuedOrderButton.Margin = new Padding(3, 4, 3, 4);
- IssuedOrderButton.Name = "IssuedOrderButton";
- IssuedOrderButton.Size = new Size(143, 44);
- IssuedOrderButton.TabIndex = 5;
- IssuedOrderButton.Text = "Заказ выдан";
- IssuedOrderButton.UseVisualStyleBackColor = true;
- IssuedOrderButton.Click += IssuedOrderButton_Click;
- //
- // UpdateListButton
- //
- UpdateListButton.Location = new Point(832, 349);
- UpdateListButton.Margin = new Padding(3, 4, 3, 4);
- UpdateListButton.Name = "UpdateListButton";
- UpdateListButton.Size = new Size(143, 44);
- UpdateListButton.TabIndex = 6;
- UpdateListButton.Text = "Обновить список";
- UpdateListButton.UseVisualStyleBackColor = true;
- UpdateListButton.Click += UpdateListButton_Click;
- //
- // FormMain
- //
- AutoScaleDimensions = new SizeF(8F, 20F);
- AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(989, 600);
- Controls.Add(UpdateListButton);
- Controls.Add(IssuedOrderButton);
- Controls.Add(OrderReadyButton);
- Controls.Add(TakeOrderInWorkButton);
- Controls.Add(CreateOrderButton);
- Controls.Add(DataGridView);
- Controls.Add(MenuStrip);
- MainMenuStrip = MenuStrip;
- Margin = new Padding(3, 4, 3, 4);
- Name = "FormMain";
- Text = "Ремонт сантехники";
- Load += FormMain_Load;
- MenuStrip.ResumeLayout(false);
- MenuStrip.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
- ResumeLayout(false);
- PerformLayout();
- }
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ MenuStrip = new MenuStrip();
+ СправочникиToolStripMenuItem = new ToolStripMenuItem();
+ ИзделияToolStripMenuItem = new ToolStripMenuItem();
+ КомпонентыToolStripMenuItem = new ToolStripMenuItem();
+ КлиентыToolStripMenuItem = new ToolStripMenuItem();
+ исполнителиToolStripMenuItem = new ToolStripMenuItem();
+ отчетыToolStripMenuItem = new ToolStripMenuItem();
+ WorksToolStripMenuItem = new ToolStripMenuItem();
+ WorkComponentToolStripMenuItem = new ToolStripMenuItem();
+ OrdersToolStripMenuItem = new ToolStripMenuItem();
+ запускРаботToolStripMenuItem = new ToolStripMenuItem();
+ CreateOrderButton = new Button();
+ IssuedOrderButton = new Button();
+ UpdateListButton = new Button();
+ DataGridView = new DataGridView();
+ MenuStrip.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // MenuStrip
+ //
+ MenuStrip.ImageScalingSize = new Size(20, 20);
+ MenuStrip.Items.AddRange(new ToolStripItem[] { СправочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem });
+ MenuStrip.Location = new Point(0, 0);
+ MenuStrip.Name = "MenuStrip";
+ MenuStrip.Padding = new Padding(7, 3, 0, 3);
+ MenuStrip.Size = new Size(989, 30);
+ MenuStrip.TabIndex = 0;
+ MenuStrip.Text = "menuStrip1";
+ //
+ // СправочникиToolStripMenuItem
+ //
+ СправочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ИзделияToolStripMenuItem, КомпонентыToolStripMenuItem, КлиентыToolStripMenuItem, исполнителиToolStripMenuItem });
+ СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
+ СправочникиToolStripMenuItem.Size = new Size(117, 24);
+ СправочникиToolStripMenuItem.Text = "Cправочники";
+ //
+ // ИзделияToolStripMenuItem
+ //
+ ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
+ ИзделияToolStripMenuItem.Size = new Size(185, 26);
+ ИзделияToolStripMenuItem.Text = "Изделия";
+ ИзделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
+ //
+ // КомпонентыToolStripMenuItem
+ //
+ КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
+ КомпонентыToolStripMenuItem.Size = new Size(185, 26);
+ КомпонентыToolStripMenuItem.Text = "Компоненты";
+ КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
+ //
+ // КлиентыToolStripMenuItem
+ //
+ КлиентыToolStripMenuItem.Name = "КлиентыToolStripMenuItem";
+ КлиентыToolStripMenuItem.Size = new Size(185, 26);
+ КлиентыToolStripMenuItem.Text = "Клиенты";
+ КлиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click;
+ //
+ // исполнителиToolStripMenuItem
+ //
+ исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem";
+ исполнителиToolStripMenuItem.Size = new Size(185, 26);
+ исполнителиToolStripMenuItem.Text = "Исполнители";
+ исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click;
+ //
+ // отчетыToolStripMenuItem
+ //
+ отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { WorksToolStripMenuItem, WorkComponentToolStripMenuItem, OrdersToolStripMenuItem });
+ отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
+ отчетыToolStripMenuItem.Size = new Size(73, 24);
+ отчетыToolStripMenuItem.Text = "Отчеты";
+ //
+ // WorksToolStripMenuItem
+ //
+ WorksToolStripMenuItem.Name = "WorksToolStripMenuItem";
+ WorksToolStripMenuItem.Size = new Size(273, 26);
+ WorksToolStripMenuItem.Text = "Список изделий";
+ WorksToolStripMenuItem.Click += WorksToolStripMenuItem_Click;
+ //
+ // WorkComponentToolStripMenuItem
+ //
+ WorkComponentToolStripMenuItem.Name = "WorkComponentToolStripMenuItem";
+ WorkComponentToolStripMenuItem.Size = new Size(273, 26);
+ WorkComponentToolStripMenuItem.Text = "Изделия по компонентам";
+ WorkComponentToolStripMenuItem.Click += WorkComponentToolStripMenuItem_Click;
+ //
+ // OrdersToolStripMenuItem
+ //
+ OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem";
+ OrdersToolStripMenuItem.Size = new Size(273, 26);
+ OrdersToolStripMenuItem.Text = "Список заказов";
+ OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
+ //
+ // запускРаботToolStripMenuItem
+ //
+ запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
+ запускРаботToolStripMenuItem.Size = new Size(114, 24);
+ запускРаботToolStripMenuItem.Text = "Запуск работ";
+ запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click;
+ //
+ // CreateOrderButton
+ //
+ CreateOrderButton.Location = new Point(832, 37);
+ CreateOrderButton.Margin = new Padding(3, 4, 3, 4);
+ CreateOrderButton.Name = "CreateOrderButton";
+ CreateOrderButton.Size = new Size(143, 44);
+ CreateOrderButton.TabIndex = 2;
+ CreateOrderButton.Text = "Создать заказ";
+ CreateOrderButton.UseVisualStyleBackColor = true;
+ CreateOrderButton.Click += CreateOrderButton_Click;
+ //
+ // IssuedOrderButton
+ //
+ IssuedOrderButton.Location = new Point(831, 149);
+ IssuedOrderButton.Margin = new Padding(3, 4, 3, 4);
+ IssuedOrderButton.Name = "IssuedOrderButton";
+ IssuedOrderButton.Size = new Size(143, 44);
+ IssuedOrderButton.TabIndex = 5;
+ IssuedOrderButton.Text = "Заказ выдан";
+ IssuedOrderButton.UseVisualStyleBackColor = true;
+ IssuedOrderButton.Click += IssuedOrderButton_Click;
+ //
+ // UpdateListButton
+ //
+ UpdateListButton.Location = new Point(831, 269);
+ UpdateListButton.Margin = new Padding(3, 4, 3, 4);
+ UpdateListButton.Name = "UpdateListButton";
+ UpdateListButton.Size = new Size(143, 44);
+ UpdateListButton.TabIndex = 6;
+ UpdateListButton.Text = "Обновить список";
+ UpdateListButton.UseVisualStyleBackColor = true;
+ UpdateListButton.Click += UpdateListButton_Click;
+ //
+ // DataGridView
+ //
+ DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ DataGridView.Location = new Point(0, 36);
+ DataGridView.Margin = new Padding(3, 4, 3, 4);
+ DataGridView.Name = "DataGridView";
+ DataGridView.RowHeadersWidth = 51;
+ DataGridView.RowTemplate.Height = 25;
+ DataGridView.Size = new Size(825, 561);
+ DataGridView.TabIndex = 1;
+ //
+ // FormMain
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(989, 600);
+ Controls.Add(UpdateListButton);
+ Controls.Add(IssuedOrderButton);
+ Controls.Add(CreateOrderButton);
+ Controls.Add(DataGridView);
+ Controls.Add(MenuStrip);
+ MainMenuStrip = MenuStrip;
+ Margin = new Padding(3, 4, 3, 4);
+ Name = "FormMain";
+ Text = "Ремонт сантехники";
+ Load += FormMain_Load;
+ MenuStrip.ResumeLayout(false);
+ MenuStrip.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
- #endregion
+ #endregion
- private MenuStrip MenuStrip;
- private ToolStripMenuItem СправочникиToolStripMenuItem;
- private ToolStripMenuItem ИзделияToolStripMenuItem;
- private ToolStripMenuItem КомпонентыToolStripMenuItem;
- private ToolStripMenuItem КлиентыToolStripMenuItem;
- private DataGridView DataGridView;
- private Button CreateOrderButton;
- private Button TakeOrderInWorkButton;
- private Button OrderReadyButton;
- private Button IssuedOrderButton;
- private Button UpdateListButton;
- private ToolStripMenuItem отчетыToolStripMenuItem;
- private ToolStripMenuItem WorksToolStripMenuItem;
- private ToolStripMenuItem WorkComponentToolStripMenuItem;
- private ToolStripMenuItem OrdersToolStripMenuItem;
- }
+ private MenuStrip MenuStrip;
+ private ToolStripMenuItem СправочникиToolStripMenuItem;
+ private ToolStripMenuItem ИзделияToolStripMenuItem;
+ private ToolStripMenuItem КомпонентыToolStripMenuItem;
+ private ToolStripMenuItem КлиентыToolStripMenuItem;
+ private Button CreateOrderButton;
+ private Button IssuedOrderButton;
+ private Button UpdateListButton;
+ private ToolStripMenuItem отчетыToolStripMenuItem;
+ private ToolStripMenuItem WorksToolStripMenuItem;
+ private ToolStripMenuItem WorkComponentToolStripMenuItem;
+ private ToolStripMenuItem OrdersToolStripMenuItem;
+ private ToolStripMenuItem исполнителиToolStripMenuItem;
+ private ToolStripMenuItem запускРаботToolStripMenuItem;
+ private DataGridView DataGridView;
+ }
}
\ No newline at end of file
diff --git a/PlumbingRepair/PlumbingRepair/FormMain.cs b/PlumbingRepair/PlumbingRepair/FormMain.cs
index e13fdd4..8931aa8 100644
--- a/PlumbingRepair/PlumbingRepair/FormMain.cs
+++ b/PlumbingRepair/PlumbingRepair/FormMain.cs
@@ -7,211 +7,171 @@ using System.Windows.Forms;
namespace PlumbingRepair
{
- public partial class FormMain : Form
- {
- private readonly ILogger _logger;
- private readonly IOrderLogic _orderLogic;
+ public partial class FormMain : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderLogic _orderLogic;
- private readonly IReportLogic _reportLogic;
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
- {
- InitializeComponent();
- _logger = logger;
- _orderLogic = orderLogic;
- _reportLogic = reportLogic;
- }
+ private readonly IReportLogic _reportLogic;
+ private readonly IWorkProcess _workProcess;
+ public FormMain(ILogger logger, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _orderLogic = orderLogic;
+ _reportLogic = reportLogic;
+ _workProcess = workProcess;
+ }
- private void FormMain_Load(object sender, EventArgs e)
- {
- LoadData();
- }
+ private void FormMain_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
- private void LoadData()
- {
- _logger.LogInformation("Загрузка заказов");
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка заказов");
- try
- {
- var list = _orderLogic.ReadList(null);
+ try
+ {
+ var list = _orderLogic.ReadList(null);
- if (list != null)
- {
- DataGridView.DataSource = list;
- DataGridView.Columns["WorkId"].Visible = false;
- DataGridView.Columns["ClientId"].Visible = false;
- DataGridView.Columns["DateImplement"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
- }
+ if (list != null)
+ {
+ DataGridView.DataSource = list;
+ DataGridView.Columns["WorkId"].Visible = false;
+ DataGridView.Columns["ClientId"].Visible = false;
+ DataGridView.Columns["ImplementerId"].Visible = false;
+ }
- _logger.LogInformation("Загрузка заказов");
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка загрузки заказов");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
+ _logger.LogInformation("Загрузка заказов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки заказов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
- private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
+ private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
- if (service is FormComponents form)
- {
- form.ShowDialog();
- }
- }
+ if (service is FormComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
- private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormWorks));
+ private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormWorks));
- if (service is FormWorks form)
- {
- form.ShowDialog();
- }
- }
- private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormClients));
- if (service is FormClients form)
- {
- form.ShowDialog();
- }
- }
+ if (service is FormWorks form)
+ {
+ form.ShowDialog();
+ }
+ }
+ private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormClients));
+ if (service is FormClients form)
+ {
+ form.ShowDialog();
+ }
+ }
- private void CreateOrderButton_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
+ private void CreateOrderButton_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
- if (service is FormCreateOrder form)
- {
- form.ShowDialog();
- LoadData();
- }
- }
+ if (service is FormCreateOrder form)
+ {
+ form.ShowDialog();
+ LoadData();
+ }
+ }
- private void TakeOrderInWorkButton_Click(object sender, EventArgs e)
- {
- if (DataGridView.SelectedRows.Count == 1)
- {
- int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
- _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
+ private void IssuedOrderButton_Click(object sender, EventArgs e)
+ {
+ if (DataGridView.SelectedRows.Count == 1)
+ {
+ int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
- try
- {
- var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
- {
- Id = id
- });
+ try
+ {
+ var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
+ {
+ Id = id
+ });
- if (!operationResult)
- {
- throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
- }
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
- LoadData();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка передачи заказа в работу");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
+ _logger.LogInformation("Заказ №{id} выдан", id);
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
- private void IssuedOrderButton_Click(object sender, EventArgs e)
- {
- if (DataGridView.SelectedRows.Count == 1)
- {
- int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
- _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
+ private void UpdateListButton_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
- try
- {
- var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
- {
- Id = id
- });
+ private void WorksToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ _reportLogic.SaveWorksToWordFile(new ReportBindingModel
+ {
+ FileName = dialog.FileName
+ });
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
- if (!operationResult)
- {
- throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
- }
+ private void WorkComponentToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormReportWorkComponents));
+ if (service is FormReportWorkComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
- LoadData();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка отметки о готовности заказа");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
+ private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
+ if (service is FormReportOrders form)
+ {
+ form.ShowDialog();
+ }
+ }
- private void OrderReadyButton_Click(object sender, EventArgs e)
- {
- if (DataGridView.SelectedRows.Count == 1)
- {
- int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
- _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
+ private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
+ MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
- try
- {
- var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
- {
- Id = id
- });
+ private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
- if (!operationResult)
- {
- throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
- }
-
- _logger.LogInformation("Заказ №{id} выдан", id);
- LoadData();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
-
- private void UpdateListButton_Click(object sender, EventArgs e)
- {
- LoadData();
- }
-
- private void WorksToolStripMenuItem_Click(object sender, EventArgs e)
- {
- using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
- if (dialog.ShowDialog() == DialogResult.OK)
- {
- _reportLogic.SaveWorksToWordFile(new ReportBindingModel
- {
- FileName = dialog.FileName
- });
- MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
-
- private void WorkComponentToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormReportWorkComponents));
- if (service is FormReportWorkComponents form)
- {
- form.ShowDialog();
- }
- }
-
- private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
- if (service is FormReportOrders form)
- {
- form.ShowDialog();
- }
- }
- }
+ if (service is FormImplementers form)
+ {
+ form.ShowDialog();
+ }
+ }
+ }
}
diff --git a/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj b/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj
index 4b959e7..e1d3bc5 100644
--- a/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj
+++ b/PlumbingRepair/PlumbingRepair/PlumbingRepair.csproj
@@ -13,6 +13,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
@@ -26,4 +27,10 @@
+
+
+ Always
+
+
+
\ No newline at end of file
diff --git a/PlumbingRepair/PlumbingRepair/Program.cs b/PlumbingRepair/PlumbingRepair/Program.cs
index 36bc9dc..5fa1c75 100644
--- a/PlumbingRepair/PlumbingRepair/Program.cs
+++ b/PlumbingRepair/PlumbingRepair/Program.cs
@@ -39,12 +39,15 @@ namespace PlumbingRepair
services.AddTransient();
services.AddTransient();
services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
- services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -57,6 +60,8 @@ namespace PlumbingRepair
services.AddTransient();
services.AddTransient();
services.AddTransient();
- }
+ services.AddTransient();
+ services.AddTransient();
+ }
}
}
\ No newline at end of file
diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/ImplementerLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/ImplementerLogic.cs
new file mode 100644
index 0000000..ae0c413
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/ImplementerLogic.cs
@@ -0,0 +1,125 @@
+using Microsoft.Extensions.Logging;
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.BusinessLogicsContracts;
+using PlumbingRepairContracts.SearchModels;
+using PlumbingRepairContracts.StoragesContracts;
+using PlumbingRepairContracts.ViewModels;
+
+namespace PlumbingRepairBusinessLogic.BusinessLogic
+{
+ public class ImplementerLogic : IImplementerLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IImplementerStorage _implementerStorage;
+
+ public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage)
+ {
+ _logger = logger;
+ _implementerStorage = implementerStorage;
+ }
+
+ public bool Create(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(ImplementerBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_implementerStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. FIO:{FIO}.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. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id);
+ var list = (model == null) ? _implementerStorage.GetFullList() :
+ _implementerStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public bool Update(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(ImplementerBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.WorkExperience < 0)
+ {
+ throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience));
+ }
+ if (model.Qualification < 0)
+ {
+ throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification));
+ }
+ if (string.IsNullOrEmpty(model.Password))
+ {
+ throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO));
+ }
+ if (string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO));
+ }
+ _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO);
+ var element = _implementerStorage.GetElement(new ImplementerSearchModel
+ {
+ ImplementerFIO = model.ImplementerFIO,
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
+ }
+ }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/OrderLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/OrderLogic.cs
index a58a17a..bdb6d72 100644
--- a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/OrderLogic.cs
+++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/OrderLogic.cs
@@ -40,45 +40,56 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
return true;
}
+ public 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("Update operation failed. Order status incorrect.");
+ return false;
+ }
+ model.Status = newStatus;
+ model.DateCreate = viewModel.DateCreate;
+ model.Sum = viewModel.Sum;
+ model.Count = viewModel.Count;
+ model.DateImplement = viewModel.DateImplement;
+ model.WorkId = viewModel.WorkId;
+ if (viewModel.ImplementerId.HasValue)
+ {
+ model.ImplementerId = viewModel.ImplementerId;
+ }
+ if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
+ else
+ {
+ model.DateImplement = viewModel.DateImplement;
+ }
+ CheckModel(model);
+ if (_orderStorage.Update(model) == null)
+ {
+ model.Status--;
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
- public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
- {
- CheckModel(model);
-
- if (model.Status + 1 != newStatus)
- {
- _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
- return false;
- }
-
- model.Status = newStatus;
-
- if (model.Status == OrderStatus.Выдан)
- model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
-
- if (_orderStorage.Update(model) == null)
- {
- model.Status--;
- _logger.LogWarning("Update operation failed");
- return false;
- }
-
- return true;
- }
-
- public bool TakeOrderInWork(OrderBindingModel model)
+ public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public bool DeliveryOrder(OrderBindingModel model)
{
- return StatusUpdate(model, OrderStatus.Готов);
- }
+ return StatusUpdate(model, OrderStatus.Выдан);
+ }
public bool FinishOrder(OrderBindingModel model)
{
- return StatusUpdate(model, OrderStatus.Выдан);
+ return StatusUpdate(model, OrderStatus.Готов);
}
public List? ReadList(OrderSearchModel? model)
@@ -126,5 +137,22 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId);
}
- }
+
+ 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;
+ }
+ }
}
diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/WorkModeling.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/WorkModeling.cs
new file mode 100644
index 0000000..41b24d2
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogic/WorkModeling.cs
@@ -0,0 +1,136 @@
+using Microsoft.Extensions.Logging;
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.BusinessLogicsContracts;
+using PlumbingRepairContracts.SearchModels;
+using PlumbingRepairContracts.ViewModels;
+using PlumbingRepairDataModels.Enums;
+
+namespace PlumbingRepairBusinessLogic.BusinessLogic
+{
+ public class WorkModeling : IWorkProcess
+ {
+ private readonly ILogger _logger;
+ private readonly Random _rnd;
+ private IOrderLogic? _orderLogic;
+ public WorkModeling(ILogger logger)
+ {
+ _logger = logger;
+ _rnd = new Random(1000);
+ }
+ public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
+ {
+ _orderLogic = orderLogic;
+ var implementers = implementerLogic.ReadList(null);
+ if (implementers == null)
+ {
+ _logger.LogWarning("DoWork. Implementers is null");
+ return;
+ }
+ var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят });
+ if (orders == null || orders.Count == 0)
+ {
+ _logger.LogWarning("DoWork. Orders is null or empty");
+ return;
+ }
+ _logger.LogDebug("DoWork for {Count} orders", orders.Count);
+ foreach (var implementer in implementers)
+ {
+ Task.Run(() => WorkerWorkAsync(implementer, orders));
+ }
+ }
+ ///
+ /// Иммитация работы исполнителя
+ ///
+ ///
+ ///
+ private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders)
+ {
+ if (_orderLogic == null || implementer == null)
+ {
+ return;
+ }
+ await RunOrderInWork(implementer);
+ await Task.Run(() =>
+ {
+ foreach (var order in orders)
+ {
+ try
+ {
+ _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
+ // пытаемся назначить заказ на исполнителя
+ _orderLogic.TakeOrderInWork(new OrderBindingModel
+ {
+ Id = order.Id,
+ ImplementerId = implementer.Id
+ });
+ // делаем работу
+ Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
+ _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
+ _orderLogic.FinishOrder(new OrderBindingModel
+ {
+ Id = order.Id
+ });
+ // отдыхаем
+ Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
+ }
+ // кто-то мог уже перехватить заказ, игнорируем ошибку
+ catch (InvalidOperationException ex)
+ {
+ _logger.LogWarning(ex, "Error try get work");
+ }
+ // заканчиваем выполнение имитации в случае иной ошибки
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error while do work");
+ throw;
+ }
+ }
+ });
+ }
+ ///
+ /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
+ ///
+ ///
+ ///
+ private async Task RunOrderInWork(ImplementerViewModel implementer)
+ {
+ if (_orderLogic == null || implementer == null)
+ {
+ return;
+ }
+ try
+ {
+ var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
+ {
+ ImplementerId = implementer.Id,
+ Status = OrderStatus.Выполняется
+ }));
+ if (runOrder == null)
+ {
+ return;
+ }
+ _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
+ // доделываем работу
+ Thread.Sleep(implementer.WorkExperience * _rnd.Next(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/PlumbingRepair/PlumbingRepairContracts/BindingModels/ImplementerBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ImplementerBindingModel.cs
new file mode 100644
index 0000000..5cd56fa
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ImplementerBindingModel.cs
@@ -0,0 +1,18 @@
+using PlumbingRepairDataModels.Models;
+
+namespace PlumbingRepairContracts.BindingModels
+{
+ public class ImplementerBindingModel : IImplementerModel
+ {
+
+ public int Id { get; set; }
+
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ public string Password { get; set; } = string.Empty;
+
+ public int WorkExperience { get; set; }
+
+ public int Qualification { get; set; }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs
index 541b689..203f25e 100644
--- a/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs
+++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs
@@ -8,7 +8,8 @@ namespace PlumbingRepairContracts.BindingModels
public int Id { get; set; }
public int WorkId { get; set; }
public int ClientId { get; set; }
- public int Count { get; set; }
+ public int? ImplementerId { get; set; }
+ public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IImplementerLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IImplementerLogic.cs
new file mode 100644
index 0000000..aeba6dd
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IImplementerLogic.cs
@@ -0,0 +1,19 @@
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.SearchModels;
+using PlumbingRepairContracts.ViewModels;
+
+namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs
index f694d80..dbbe1c2 100644
--- a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs
+++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -7,7 +7,8 @@ namespace PlumbingRepairContracts.BusinessLogicsContracts
public interface IOrderLogic
{
List? ReadList(OrderSearchModel? model);
- bool CreateOrder(OrderBindingModel model);
+ OrderViewModel? ReadElement(OrderSearchModel model);
+ bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs
new file mode 100644
index 0000000..e29c45d
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs
@@ -0,0 +1,7 @@
+namespace PlumbingRepairContracts.BusinessLogicsContracts
+{
+ public interface IWorkProcess
+ {
+ void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/ImplementerSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ImplementerSearchModel.cs
new file mode 100644
index 0000000..3738380
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ImplementerSearchModel.cs
@@ -0,0 +1,11 @@
+namespace PlumbingRepairContracts.SearchModels
+{
+ public class ImplementerSearchModel
+ {
+ public int? Id { get; set; }
+
+ public string? ImplementerFIO { get; set; }
+
+ public string? Password { get; set; }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs
index 558c523..d5e6b35 100644
--- a/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs
+++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs
@@ -1,4 +1,6 @@
-namespace PlumbingRepairContracts.SearchModels
+using PlumbingRepairDataModels.Enums;
+
+namespace PlumbingRepairContracts.SearchModels
{
public class OrderSearchModel
{
@@ -6,5 +8,7 @@
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
- }
+ public int? ImplementerId { get; set; }
+ public OrderStatus? Status { get; set; }
+ }
}
diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IImplementerStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IImplementerStorage.cs
new file mode 100644
index 0000000..c22612b
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IImplementerStorage.cs
@@ -0,0 +1,21 @@
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.SearchModels;
+using PlumbingRepairContracts.ViewModels;
+
+namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs
new file mode 100644
index 0000000..9632d3a
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs
@@ -0,0 +1,22 @@
+using PlumbingRepairDataModels.Models;
+using System.ComponentModel;
+
+namespace PlumbingRepairContracts.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/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs
index 1a6f8ce..8aa9bc9 100644
--- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs
+++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs
@@ -9,12 +9,15 @@ namespace PlumbingRepairContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
public int WorkId { get; set; }
- [DisplayName("Название изделия")]
+ [DisplayName("Название изделия")]
public string WorkName { get; set; } = string.Empty;
public int ClientId { get; set; }
[DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty;
- [DisplayName("Количество")]
+ public int? ImplementerId { get; set; }
+ [DisplayName("Исполнитель")]
+ public string ImplementerFIO { get; set; } = string.Empty;
+ [DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IImplementerModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IImplementerModel.cs
new file mode 100644
index 0000000..a9bd55c
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IImplementerModel.cs
@@ -0,0 +1,10 @@
+namespace PlumbingRepairDataModels.Models
+{
+ public interface IImplementerModel : IId
+ {
+ string ImplementerFIO { get; }
+ string Password { get; }
+ int WorkExperience { get; }
+ int Qualification { get; }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs
index 113b612..683a9b3 100644
--- a/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs
+++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IOrderModel.cs
@@ -6,7 +6,8 @@ namespace PlumbingRepairDataModels.Models
{
int WorkId { get; }
int ClientId { get; }
- string WorkName { get; }
+ int? ImplementerId { get; }
+ string WorkName { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..744e8b8
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,96 @@
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.SearchModels;
+using PlumbingRepairContracts.StoragesContracts;
+using PlumbingRepairContracts.ViewModels;
+using PlumbingRepairDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace PlumbingRepairDatabaseImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ using var context = new PlumbingRepairDataBase();
+ var element = context.Implementers
+ .Include(x => x.Orders)
+ .FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Implementers.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ImplementerFIO) &&
+ string.IsNullOrEmpty(model.Password) &&
+ !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new PlumbingRepairDataBase();
+ return context.Implementers
+ .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) &&
+ (string.IsNullOrEmpty(model.Password) || x.Password == model.Password) &&
+ (!model.Id.HasValue || x.Id == model.Id))
+ ?.GetViewModel;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+ if (!string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ using var context = new PlumbingRepairDataBase();
+ return context.Implementers
+ .Include(x => x.Orders)
+ .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ using var context = new PlumbingRepairDataBase();
+ return context.Implementers
+ .Include(x => x.Orders)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ var newImplementer = Implementer.Create(model);
+ if (newImplementer == null)
+ {
+ return null;
+ }
+ using var context = new PlumbingRepairDataBase();
+ context.Implementers.Add(newImplementer);
+ context.SaveChanges();
+ return newImplementer.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ using var context = new PlumbingRepairDataBase();
+ var client = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ context.SaveChanges();
+ return client.GetViewModel;
+ }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs
index 41f3db4..b320120 100644
--- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs
+++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs
@@ -16,59 +16,80 @@ namespace PlumbingRepairDatabaseImplement.Implements
return context.Orders
.Include(x => x.Work)
.Include(x => x.Client)
- .Select(x => x.GetViewModel)
+ .Include(x => x.Implementer)
+ .Select(x => x.GetViewModel)
.ToList();
}
public List GetFilteredList(OrderSearchModel model)
{
- using var context = new PlumbingRepairDataBase();
- if (model.Id.HasValue)
- {
- return context.Orders
- .Include(x => x.Work)
- .Include(x => x.Client)
- .Where(x => x.Id == model.Id)
- .Select(x => x.GetViewModel)
- .ToList();
- }
- else if (model.DateFrom != null && model.DateTo != null)
- {
- return context.Orders
- .Include(x => x.Work)
- .Include(x => x.Client)
- .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
- .Select(x => x.GetViewModel)
- .ToList();
- }
- else if (model.ClientId.HasValue)
- {
- return context.Orders
- .Include(x => x.Work)
- .Include(x => x.Client)
- .Where(x => x.ClientId == model.ClientId)
- .Select(x => x.GetViewModel)
- .ToList();
- }
-
- return new();
- }
+ using var context = new PlumbingRepairDataBase();
+ if (model.Id.HasValue)
+ {
+ return context.Orders
+ .Include(x => x.Work)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .Where(x => x.Id == model.Id)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ else if (model.DateFrom != null && model.DateTo != null)
+ {
+ return context.Orders
+ .Include(x => x.Work)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ else if (model.ClientId.HasValue)
+ {
+ return context.Orders
+ .Include(x => x.Work)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .Where(x => x.ClientId == model.ClientId)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ else if (model.ImplementerId.HasValue)
+ {
+ return context.Orders
+ .Include(x => x.Work)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .Where(x => x.ImplementerId == model.ImplementerId)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ return context.Orders
+ .Include(x => x.Work)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .Where(x => model.Status == x.Status)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
public OrderViewModel? GetElement(OrderSearchModel model)
{
- if (!model.Id.HasValue)
- {
- return null;
- }
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
- using var context = new PlumbingRepairDataBase();
+ using var context = new PlumbingRepairDataBase();
- return context.Orders
- .Include(x => x.Work)
- .Include(x => x.Client)
- .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
- ?.GetViewModel;
- }
+ return context.Orders
+ .Include(x => x.Work)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x => (!model.ImplementerId.HasValue || x.ImplementerId == model.ImplementerId) &&
+ (!model.Status.HasValue || x.Status == model.Status) &&
+ (!model.Id.HasValue || x.Id == model.Id))?.GetViewModel;
+ }
public OrderViewModel? Insert(OrderBindingModel model)
{
@@ -87,7 +108,8 @@ namespace PlumbingRepairDatabaseImplement.Implements
return context.Orders
.Include(x => x.Work)
.Include(x => x.Client)
- .FirstOrDefault(x => x.Id == newOrder.Id)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
}
@@ -108,7 +130,8 @@ namespace PlumbingRepairDatabaseImplement.Implements
return context.Orders
.Include(x => x.Work)
.Include(x => x.Client)
- .FirstOrDefault(x => x.Id == model.Id)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
@@ -123,7 +146,8 @@ namespace PlumbingRepairDatabaseImplement.Implements
var deletedElement = context.Orders
.Include(x => x.Work)
.Include(x => x.Client)
- .FirstOrDefault(x => x.Id == model.Id)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(element);
context.SaveChanges();
diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230416153751_WithImplementer.Designer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230416153751_WithImplementer.Designer.cs
new file mode 100644
index 0000000..df3f092
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230416153751_WithImplementer.Designer.cs
@@ -0,0 +1,261 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+using PlumbingRepairDatabaseImplement;
+
+#nullable disable
+
+namespace PlumbingRepairDatabaseImplement.Migrations
+{
+ [DbContext(typeof(PlumbingRepairDataBase))]
+ [Migration("20230416153751_WithImplementer")]
+ partial class WithImplementer
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Cost")
+ .HasColumnType("double precision");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ClientId")
+ .HasColumnType("integer");
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("DateCreate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("DateImplement")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property("ImplementerId")
+ .HasColumnType("integer");
+
+ b.Property("Status")
+ .HasColumnType("integer");
+
+ b.Property("Sum")
+ .HasColumnType("double precision");
+
+ b.Property("WorkId")
+ .HasColumnType("integer");
+
+ b.Property("WorkName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("ImplementerId");
+
+ b.HasIndex("WorkId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Price")
+ .HasColumnType("double precision");
+
+ b.Property("WorkName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Works");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.WorkComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ComponentId")
+ .HasColumnType("integer");
+
+ b.Property("Count")
+ .HasColumnType("integer");
+
+ b.Property("WorkId")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComponentId");
+
+ b.HasIndex("WorkId");
+
+ b.ToTable("WorkComponents");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("PlumbingRepairDatabaseImplement.Models.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("PlumbingRepairDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
+ b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
+ .WithMany("Orders")
+ .HasForeignKey("WorkId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Client");
+
+ b.Navigation("Implementer");
+
+ b.Navigation("Work");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.WorkComponent", b =>
+ {
+ b.HasOne("PlumbingRepairDatabaseImplement.Models.Component", "Component")
+ .WithMany("WorkComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
+ .WithMany("Components")
+ .HasForeignKey("WorkId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Component");
+
+ b.Navigation("Work");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Client", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("WorkComponents");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230416153751_WithImplementer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230416153751_WithImplementer.cs
new file mode 100644
index 0000000..7e184c1
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230416153751_WithImplementer.cs
@@ -0,0 +1,68 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace PlumbingRepairDatabaseImplement.Migrations
+{
+ ///
+ public partial class WithImplementer : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "ImplementerId",
+ table: "Orders",
+ type: "integer",
+ nullable: true);
+
+ migrationBuilder.CreateTable(
+ name: "Implementers",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ ImplementerFIO = table.Column(type: "text", nullable: false),
+ Password = table.Column(type: "text", nullable: false),
+ WorkExperience = table.Column(type: "integer", nullable: false),
+ Qualification = table.Column(type: "integer", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Implementers", x => x.Id);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId",
+ principalTable: "Implementers",
+ principalColumn: "Id");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders");
+
+ migrationBuilder.DropTable(
+ name: "Implementers");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders");
+
+ migrationBuilder.DropColumn(
+ name: "ImplementerId",
+ table: "Orders");
+ }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDataBaseModelSnapshot.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDataBaseModelSnapshot.cs
index c29dfce..c224fc5 100644
--- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDataBaseModelSnapshot.cs
+++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDataBaseModelSnapshot.cs
@@ -67,6 +67,33 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
{
b.Property("Id")
@@ -87,6 +114,9 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("timestamp with time zone");
+ b.Property("ImplementerId")
+ .HasColumnType("integer");
+
b.Property("Status")
.HasColumnType("integer");
@@ -104,6 +134,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.HasIndex("WorkId");
b.ToTable("Orders");
@@ -163,6 +195,10 @@ namespace PlumbingRepairDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("PlumbingRepairDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
.WithMany("Orders")
.HasForeignKey("WorkId")
@@ -171,6 +207,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.Navigation("Client");
+ b.Navigation("Implementer");
+
b.Navigation("Work");
});
@@ -203,6 +241,11 @@ namespace PlumbingRepairDatabaseImplement.Migrations
b.Navigation("WorkComponents");
});
+ modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b =>
{
b.Navigation("Components");
diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs
new file mode 100644
index 0000000..593de71
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs
@@ -0,0 +1,63 @@
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.ViewModels;
+using PlumbingRepairDataModels.Models;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
+
+namespace PlumbingRepairDatabaseImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public int Id { get; set; }
+
+ [Required]
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ [Required]
+ public string Password { get; set; } = string.Empty;
+
+ [Required]
+ public int WorkExperience { get; set; }
+
+ [Required]
+ public int Qualification { get; set; }
+
+ [ForeignKey("ImplementerId")]
+ public virtual List Orders { get; set; } = new();
+
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Implementer()
+ {
+ Id = model.Id,
+ ImplementerFIO = model.ImplementerFIO,
+ Password = model.Password,
+ WorkExperience = model.WorkExperience,
+ Qualification = model.Qualification
+ };
+ }
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ImplementerFIO = model.ImplementerFIO;
+ Password = model.Password;
+ WorkExperience = model.WorkExperience;
+ Qualification = model.Qualification;
+ }
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ImplementerFIO = ImplementerFIO,
+ Password = Password,
+ WorkExperience = WorkExperience,
+ Qualification = Qualification
+ };
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs
index 307935d..722be22 100644
--- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs
+++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs
@@ -16,8 +16,9 @@ namespace PlumbingRepairDatabaseImplement.Models
[Required]
public int ClientId { get; private set; }
- [Required]
- public int Count { get; private set; }
+ public int? ImplementerId { get; set; }
+ [Required]
+ public int Count { get; private set; }
[Required]
public double Sum { get; private set; }
@@ -32,8 +33,9 @@ namespace PlumbingRepairDatabaseImplement.Models
public virtual Work Work { get; set; }
public virtual Client Client { get; set; }
+ public virtual Implementer? Implementer { get; set; }
- public static Order? Create(OrderBindingModel? model)
+ public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
@@ -46,7 +48,8 @@ namespace PlumbingRepairDatabaseImplement.Models
WorkId = model.WorkId,
WorkName = model.WorkName,
ClientId = model.ClientId,
- Count = model.Count,
+ ImplementerId = model.ImplementerId,
+ Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
@@ -63,7 +66,8 @@ namespace PlumbingRepairDatabaseImplement.Models
Status = model.Status;
DateImplement = model.DateImplement;
- }
+ ImplementerId = model.ImplementerId;
+ }
public OrderViewModel GetViewModel => new()
{
@@ -72,7 +76,9 @@ namespace PlumbingRepairDatabaseImplement.Models
WorkName = Work.WorkName,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
- Count = Count,
+ ImplementerId = ImplementerId,
+ ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
+ Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDataBase.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDataBase.cs
index dc6bfb6..22e69ea 100644
--- a/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDataBase.cs
+++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDataBase.cs
@@ -18,5 +18,6 @@ namespace PlumbingRepairDatabaseImplement
public virtual DbSet WorkComponents { set; get; }
public virtual DbSet Orders { set; get; }
public virtual DbSet Clients { set; get; }
- }
+ public virtual DbSet Implementers { set; get; }
+ }
}
diff --git a/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs
index c058534..1cff867 100644
--- a/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs
+++ b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs
@@ -9,14 +9,16 @@ namespace PlumbingRepairListImplement
public List Orders { get; set; }
public List Works { get; set; }
public List Clients { get; set; }
+ public List Implementers { get; set; }
- private DataListSingleton()
+ private DataListSingleton()
{
Components = new List();
Orders = new List();
Works = new List();
Clients = new List();
- }
+ Implementers = new List();
+ }
public static DataListSingleton GetInstance()
{
diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/ImplementerStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..6984b4f
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,115 @@
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.SearchModels;
+using PlumbingRepairContracts.StoragesContracts;
+using PlumbingRepairContracts.ViewModels;
+using PlumbingRepairListImplement.Models;
+
+namespace PlumbingRepairListImplement.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)
+ {
+ if (model.Id.HasValue)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.Id == model.Id)
+ {
+ return implementer.GetViewModel;
+ }
+ }
+ }
+ else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password))
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.ImplementerFIO == model.ImplementerFIO && implementer.Password == model.Password)
+ {
+ return implementer.GetViewModel;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ return result;
+ }
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.ImplementerFIO.Contains(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 newImplementer = Implementer.Create(model);
+ if (newImplementer == null)
+ {
+ return null;
+ }
+ _source.Implementers.Add(newImplementer);
+ return newImplementer.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/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs
index 5e7eabb..da9bacd 100644
--- a/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs
+++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs
@@ -60,7 +60,17 @@ namespace PlumbingRepairListImplement.Implements
}
}
}
- return result;
+ else if (model.ImplementerId.HasValue)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.ImplementerId == model.ImplementerId)
+ {
+ result.Add(order.GetViewModel);
+ }
+ }
+ }
+ return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs
new file mode 100644
index 0000000..c67a161
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs
@@ -0,0 +1,54 @@
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.ViewModels;
+using PlumbingRepairDataModels.Models;
+
+namespace PlumbingRepairListImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ public string Password { get; set; } = string.Empty;
+
+ public int WorkExperience { get; set; }
+
+ public int Qualification { get; set; }
+
+ public int Id { get; set; }
+ public static Implementer? Create(ImplementerBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Implementer()
+ {
+ Id = model.Id,
+ ImplementerFIO = model.ImplementerFIO,
+ Password = model.Password,
+ WorkExperience = model.WorkExperience,
+ Qualification = model.Qualification
+ };
+ }
+
+ public void Update(ImplementerBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ImplementerFIO = model.ImplementerFIO;
+ Password = model.Password;
+ WorkExperience = model.WorkExperience;
+ Qualification = model.Qualification;
+ }
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ImplementerFIO = ImplementerFIO,
+ Password = Password,
+ WorkExperience = WorkExperience,
+ Qualification = Qualification
+ };
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs
index 0afff36..cff3824 100644
--- a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs
+++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs
@@ -11,7 +11,8 @@ namespace PlumbingRepairListImplement.Models
public int WorkId { get; private set; }
public string WorkName { get; private set; }
public int ClientId { get; private set; }
- public int Count { get; private set; }
+ public int? ImplementerId { get; private set; }
+ public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
@@ -29,7 +30,8 @@ namespace PlumbingRepairListImplement.Models
WorkId = model.WorkId,
WorkName = model.WorkName,
ClientId = model.ClientId,
- Count = model.Count,
+ ImplementerId = model.ImplementerId,
+ Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
@@ -45,7 +47,8 @@ namespace PlumbingRepairListImplement.Models
}
Status = model.Status;
DateImplement = model.DateImplement;
- }
+ ImplementerId = model.ImplementerId;
+ }
public OrderViewModel GetViewModel => new()
{
@@ -53,7 +56,8 @@ namespace PlumbingRepairListImplement.Models
WorkId = WorkId,
WorkName = WorkName,
ClientId = ClientId,
- Count = Count,
+ ImplementerId = ImplementerId,
+ Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
diff --git a/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs b/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs
new file mode 100644
index 0000000..1964028
--- /dev/null
+++ b/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs
@@ -0,0 +1,99 @@
+using Microsoft.AspNetCore.Mvc;
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.BusinessLogicsContracts;
+using PlumbingRepairContracts.SearchModels;
+using PlumbingRepairContracts.ViewModels;
+using PlumbingRepairDataModels.Enums;
+
+namespace PlumbingRepairRestApi.Controllers
+{
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class ImplementerController : Controller
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderLogic _order;
+ private readonly IImplementerLogic _logic;
+ public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger)
+ {
+ _logger = logger;
+ _order = order;
+ _logic = logic;
+ }
+ [HttpGet]
+ public ImplementerViewModel? Login(string login, string password)
+ {
+ try
+ {
+ return _logic.ReadElement(new ImplementerSearchModel
+ {
+ ImplementerFIO = login,
+ Password = password
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка авторизации сотрудника");
+ throw;
+ }
+ }
+ [HttpGet]
+ public List? GetNewOrders()
+ {
+ try
+ {
+ return _order.ReadList(new OrderSearchModel
+ {
+ Status = OrderStatus.Принят
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения новых заказов");
+ throw;
+ }
+ }
+ [HttpGet]
+ public OrderViewModel? GetImplementerOrder(int implementerId)
+ {
+ try
+ {
+ return _order.ReadElement(new OrderSearchModel
+ {
+ ImplementerId = implementerId
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
+ throw;
+ }
+ }
+ [HttpPost]
+ public void TakeOrderInWork(OrderBindingModel model)
+ {
+ try
+ {
+ _order.TakeOrderInWork(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id);
+ throw;
+ }
+ }
+ [HttpPost]
+ public void FinishOrder(OrderBindingModel model)
+ {
+ try
+ {
+ _order.FinishOrder(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id);
+ throw;
+ }
+ }
+ }
+}
diff --git a/PlumbingRepair/PlumbingRepairRestApi/Program.cs b/PlumbingRepair/PlumbingRepairRestApi/Program.cs
index e2c3ca3..e2b6384 100644
--- a/PlumbingRepair/PlumbingRepairRestApi/Program.cs
+++ b/PlumbingRepair/PlumbingRepairRestApi/Program.cs
@@ -13,8 +13,10 @@ builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
+builder.Services.AddTransient();
builder.Services.AddTransient();
+builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
diff --git a/PlumbingRepair/PlumpingRepairFileImplement/DataFileSingleton.cs b/PlumbingRepair/PlumpingRepairFileImplement/DataFileSingleton.cs
index f2df4f6..dbf8387 100644
--- a/PlumbingRepair/PlumpingRepairFileImplement/DataFileSingleton.cs
+++ b/PlumbingRepair/PlumpingRepairFileImplement/DataFileSingleton.cs
@@ -11,13 +11,15 @@ namespace PlumbingRepairFileImplement
private readonly string OrderFileName = "Order.xml";
private readonly string WorkFileName = "Work.xml";
private readonly string ClientFileName = "Client.xml";
+ private readonly string ImplementerFileName = "Implementer.xml";
- public List Components { get; private set; }
+ public List Components { get; private set; }
public List Orders { get; private set; }
public List Works { get; private set; }
public List Clients { get; private set; }
+ public List Implementers { get; private set; }
- public static DataFileSingleton GetInstance()
+ public static DataFileSingleton GetInstance()
{
if (instance == null)
{
@@ -30,14 +32,16 @@ namespace PlumbingRepairFileImplement
public void SaveWorks() => SaveData(Works, WorkFileName, "Works", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
+ public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
- private DataFileSingleton()
+ private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Works = LoadData(WorkFileName, "Work", x => Work.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/PlumbingRepair/PlumpingRepairFileImplement/Implements/ImplementerStorage.cs b/PlumbingRepair/PlumpingRepairFileImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..0f146b9
--- /dev/null
+++ b/PlumbingRepair/PlumpingRepairFileImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,83 @@
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.SearchModels;
+using PlumbingRepairContracts.StoragesContracts;
+using PlumbingRepairContracts.ViewModels;
+using PlumbingRepairFileImplement.Models;
+
+namespace PlumbingRepairFileImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataFileSingleton source;
+ public ImplementerStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ source.Implementers.Remove(element);
+ source.SaveImplementers();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ if (model.Id.HasValue)
+ {
+ return source.Implementers
+ .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel;
+ }
+ else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password))
+ {
+ return source.Implementers
+ .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password))?.GetViewModel;
+ }
+ return new();
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ return new();
+ }
+ return source.Implementers.Where(x =>
+ x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList();
+ }
+
+ public List GetFullList()
+ {
+ return source.Implementers.Select(x => x.GetViewModel).ToList();
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1;
+ var newImplementer = Implementer.Create(model);
+ if (newImplementer == null)
+ {
+ return null;
+ }
+ source.Implementers.Add(newImplementer);
+ source.SaveImplementers();
+ return newImplementer.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (implementer == null)
+ {
+ return null;
+ }
+ implementer.Update(model);
+ source.SaveImplementers();
+ return implementer.GetViewModel;
+ }
+ }
+}
diff --git a/PlumbingRepair/PlumpingRepairFileImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumpingRepairFileImplement/Implements/OrderStorage.cs
index d78f954..d11309f 100644
--- a/PlumbingRepair/PlumpingRepairFileImplement/Implements/OrderStorage.cs
+++ b/PlumbingRepair/PlumpingRepairFileImplement/Implements/OrderStorage.cs
@@ -43,8 +43,15 @@ namespace PlumbingRepairFileImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
+ else if (model.ImplementerId.HasValue)
+ {
+ return source.Orders
+ .Where(x => x.ImplementerId == model.ImplementerId)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
- return new();
+ return new();
}
public OrderViewModel? GetElement(OrderSearchModel model)
diff --git a/PlumbingRepair/PlumpingRepairFileImplement/Models/Implementer.cs b/PlumbingRepair/PlumpingRepairFileImplement/Models/Implementer.cs
new file mode 100644
index 0000000..8644896
--- /dev/null
+++ b/PlumbingRepair/PlumpingRepairFileImplement/Models/Implementer.cs
@@ -0,0 +1,76 @@
+using PlumbingRepairContracts.BindingModels;
+using PlumbingRepairContracts.ViewModels;
+using PlumbingRepairDataModels.Models;
+using System.Xml.Linq;
+
+namespace PlumbingRepairFileImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ public string Password { get; set; } = string.Empty;
+
+ public int WorkExperience { get; set; }
+
+ public int Qualification { get; set; }
+
+ public int Id { get; set; }
+
+ public static Implementer? Create(ImplementerBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Implementer()
+ {
+ Id = model.Id,
+ ImplementerFIO = model.ImplementerFIO,
+ Password = model.Password,
+ WorkExperience = model.WorkExperience,
+ Qualification = model.Qualification
+ };
+ }
+ public static Implementer? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Implementer()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ImplementerFIO = element.Element("ImplementerFIO")!.Value,
+ Password = element.Element("Password")!.Value,
+ WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
+ Qualification = Convert.ToInt32(element.Element("Qualification")!.Value)
+ };
+ }
+ public void Update(ImplementerBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ImplementerFIO = model.ImplementerFIO;
+ Password = model.Password;
+ WorkExperience = model.WorkExperience;
+ Qualification = model.Qualification;
+ }
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ImplementerFIO = ImplementerFIO,
+ Password = Password,
+ WorkExperience = WorkExperience,
+ Qualification = Qualification
+ };
+ public XElement GetXElement => new("Implementer",
+ new XAttribute("Id", Id),
+ new XElement("ImplementerFIO", ImplementerFIO),
+ new XElement("Password", Password),
+ new XElement("WorkExperience", WorkExperience),
+ new XElement("Qualification", Qualification));
+ }
+}
diff --git a/PlumbingRepair/PlumpingRepairFileImplement/Models/Order.cs b/PlumbingRepair/PlumpingRepairFileImplement/Models/Order.cs
index 7d2615c..49e261f 100644
--- a/PlumbingRepair/PlumpingRepairFileImplement/Models/Order.cs
+++ b/PlumbingRepair/PlumpingRepairFileImplement/Models/Order.cs
@@ -11,7 +11,8 @@ namespace PlumbingRepairFileImplement.Models
public int Id { get; private set; }
public int WorkId { get; private set; }
public int ClientId { get; private set; }
- public string WorkName { get; private set; } = string.Empty;
+ public int? ImplementerId { get; private set; }
+ public string WorkName { get; private set; } = string.Empty;
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
@@ -30,7 +31,8 @@ namespace PlumbingRepairFileImplement.Models
WorkId = model.WorkId,
WorkName = model.WorkName,
ClientId = model.ClientId,
- Count = model.Count,
+ ImplementerId = model.ImplementerId,
+ Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
@@ -51,7 +53,8 @@ namespace PlumbingRepairFileImplement.Models
WorkId = Convert.ToInt32(element.Element("WorkId")!.Value),
WorkName = element.Element("WorkName")!.Value,
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
- Count = Convert.ToInt32(element.Element("Count")!.Value),
+ ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.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),
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null)
@@ -71,7 +74,8 @@ namespace PlumbingRepairFileImplement.Models
}
Status = model.Status;
DateImplement = model.DateImplement;
- }
+ ImplementerId = model.ImplementerId;
+ }
public OrderViewModel GetViewModel => new()
{
@@ -79,7 +83,8 @@ namespace PlumbingRepairFileImplement.Models
WorkId = WorkId,
WorkName = WorkName,
ClientId = ClientId,
- Count = Count,
+ ImplementerId = ImplementerId,
+ Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
@@ -91,7 +96,8 @@ namespace PlumbingRepairFileImplement.Models
new XElement("WorkName", WorkName),
new XElement("WorkId", WorkId.ToString()),
new XElement("ClientId", ClientId.ToString()),
- new XElement("Count", Count.ToString()),
+ new XElement("ImplementerId", ImplementerId),
+ new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),