diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementer.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementer.Designer.cs
new file mode 100644
index 0000000..74c7f79
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementer.Designer.cs
@@ -0,0 +1,165 @@
+namespace BlacksmithWorkshopView
+{
+ partial class FormImplementer
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.labelQualification = new System.Windows.Forms.Label();
+ this.labelWorkExperience = new System.Windows.Forms.Label();
+ this.labelPassword = new System.Windows.Forms.Label();
+ this.labelName = new System.Windows.Forms.Label();
+ this.textBoxQualification = new System.Windows.Forms.TextBox();
+ this.textBoxWorkExperience = new System.Windows.Forms.TextBox();
+ this.textBoxPassword = new System.Windows.Forms.TextBox();
+ this.textBoxName = new System.Windows.Forms.TextBox();
+ this.SuspendLayout();
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonCancel.Location = new System.Drawing.Point(249, 122);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 11;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // buttonSave
+ //
+ this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonSave.Location = new System.Drawing.Point(168, 122);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(75, 23);
+ this.buttonSave.TabIndex = 12;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // labelQualification
+ //
+ this.labelQualification.AutoSize = true;
+ this.labelQualification.Location = new System.Drawing.Point(12, 96);
+ this.labelQualification.Name = "labelQualification";
+ this.labelQualification.Size = new System.Drawing.Size(88, 15);
+ this.labelQualification.TabIndex = 7;
+ this.labelQualification.Text = "Квалификация";
+ //
+ // labelWorkExperience
+ //
+ this.labelWorkExperience.AutoSize = true;
+ this.labelWorkExperience.Location = new System.Drawing.Point(12, 67);
+ this.labelWorkExperience.Name = "labelWorkExperience";
+ this.labelWorkExperience.Size = new System.Drawing.Size(37, 15);
+ this.labelWorkExperience.TabIndex = 8;
+ this.labelWorkExperience.Text = "Опыт";
+ //
+ // labelPassword
+ //
+ this.labelPassword.AutoSize = true;
+ this.labelPassword.Location = new System.Drawing.Point(12, 38);
+ this.labelPassword.Name = "labelPassword";
+ this.labelPassword.Size = new System.Drawing.Size(49, 15);
+ this.labelPassword.TabIndex = 9;
+ this.labelPassword.Text = "Пароль";
+ //
+ // labelName
+ //
+ this.labelName.AutoSize = true;
+ this.labelName.Location = new System.Drawing.Point(12, 9);
+ this.labelName.Name = "labelName";
+ this.labelName.Size = new System.Drawing.Size(34, 15);
+ this.labelName.TabIndex = 10;
+ this.labelName.Text = "ФИО";
+ //
+ // textBoxQualification
+ //
+ this.textBoxQualification.Location = new System.Drawing.Point(106, 93);
+ this.textBoxQualification.Name = "textBoxQualification";
+ this.textBoxQualification.Size = new System.Drawing.Size(218, 23);
+ this.textBoxQualification.TabIndex = 3;
+ //
+ // textBoxWorkExperience
+ //
+ this.textBoxWorkExperience.Location = new System.Drawing.Point(106, 64);
+ this.textBoxWorkExperience.Name = "textBoxWorkExperience";
+ this.textBoxWorkExperience.Size = new System.Drawing.Size(218, 23);
+ this.textBoxWorkExperience.TabIndex = 4;
+ //
+ // textBoxPassword
+ //
+ this.textBoxPassword.Location = new System.Drawing.Point(106, 35);
+ this.textBoxPassword.Name = "textBoxPassword";
+ this.textBoxPassword.Size = new System.Drawing.Size(218, 23);
+ this.textBoxPassword.TabIndex = 5;
+ //
+ // textBoxName
+ //
+ this.textBoxName.Location = new System.Drawing.Point(106, 6);
+ this.textBoxName.Name = "textBoxName";
+ this.textBoxName.Size = new System.Drawing.Size(218, 23);
+ this.textBoxName.TabIndex = 6;
+ //
+ // FormImplementer
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(337, 167);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.labelQualification);
+ this.Controls.Add(this.labelWorkExperience);
+ this.Controls.Add(this.labelPassword);
+ this.Controls.Add(this.labelName);
+ this.Controls.Add(this.textBoxQualification);
+ this.Controls.Add(this.textBoxWorkExperience);
+ this.Controls.Add(this.textBoxPassword);
+ this.Controls.Add(this.textBoxName);
+ this.Name = "FormImplementer";
+ this.Text = "Исполнитель";
+ this.Load += new System.EventHandler(this.FormImplementer_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonSave;
+ private Label labelQualification;
+ private Label labelWorkExperience;
+ private Label labelPassword;
+ private Label labelName;
+ private TextBox textBoxQualification;
+ private TextBox textBoxWorkExperience;
+ private TextBox textBoxPassword;
+ private TextBox textBoxName;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementer.cs
new file mode 100644
index 0000000..b338381
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementer.cs
@@ -0,0 +1,87 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopView
+{
+ public partial class FormImplementer : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IImplementerLogic _implementerLogic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+ public FormImplementer(ILogger logger, IImplementerLogic implementerLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _implementerLogic = implementerLogic;
+ }
+ private void FormImplementer_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение сотрудника");
+ var view = _implementerLogic.ReadElement(new ImplementerSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxName.Text = view.ImplementerFIO;
+ textBoxPassword.Text = view.Password;
+ textBoxQualification.Text = view.Qualification.ToString();
+ textBoxWorkExperience.Text = view.WorkExperience.ToString();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения сотрудника");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение сотрудника");
+ try
+ {
+ var model = new ImplementerBindingModel()
+ {
+ Id = _id ?? 0,
+ ImplementerFIO = textBoxName.Text,
+ Password = textBoxPassword.Text,
+ Qualification = Convert.ToInt32(textBoxQualification.Text),
+ WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text)
+ };
+ var operationResult = _id.HasValue ? _implementerLogic.Update(model) : _implementerLogic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения сотрудника");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementer.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementer.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/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/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.Designer.cs
new file mode 100644
index 0000000..eeb564a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.Designer.cs
@@ -0,0 +1,115 @@
+namespace BlacksmithWorkshopView
+{
+ 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()
+ {
+ System.Windows.Forms.Button buttonRef;
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ buttonRef = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonRef
+ //
+ buttonRef.Location = new System.Drawing.Point(620, 99);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new System.Drawing.Size(174, 23);
+ buttonRef.TabIndex = 3;
+ buttonRef.Text = "Обновить";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Location = new System.Drawing.Point(620, 70);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(174, 23);
+ this.buttonDel.TabIndex = 4;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Location = new System.Drawing.Point(620, 41);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(174, 23);
+ this.buttonUpd.TabIndex = 5;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(620, 12);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(174, 23);
+ this.buttonAdd.TabIndex = 6;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(6, 0);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(608, 450);
+ this.dataGridView.TabIndex = 2;
+ //
+ // FormImplementers
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ 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 Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs
new file mode 100644
index 0000000..ca1e4c3
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.cs
@@ -0,0 +1,98 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopView
+{
+ public partial class FormImplementers : Form
+ {
+ IImplementerLogic _implementerLogic;
+ ILogger _logger;
+ public FormImplementers(IImplementerLogic implementerLogic, ILogger logger)
+ {
+ _implementerLogic= implementerLogic;
+ _logger = logger;
+ InitializeComponent();
+ }
+ private void FormImplementers_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void LoadData()
+ {
+ try
+ {
+ var list = _implementerLogic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ //dataGridView.Columns["Id"].Visible = false;
+ //dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Загрузка сотрудников");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки сотрудников");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
+ if (service is FormImplementer form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
+ if (service is FormImplementer form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление сотрудника");
+ try
+ {
+ if (!_implementerLogic.Delete(new ImplementerBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления сотрудника");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.resx
new file mode 100644
index 0000000..fa1d9b6
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormImplementers.resx
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ False
+
+
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
index b761df5..892e72d 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs
@@ -33,14 +33,14 @@
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.manufacturesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.implementersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportManufactureComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.doWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
- this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
- this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.menuStrip.SuspendLayout();
@@ -51,10 +51,11 @@
//
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.refbooksToolStripMenuItem,
- this.reportsToolStripMenuItem});
+ this.reportsToolStripMenuItem,
+ this.doWorkToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
- this.menuStrip.Size = new System.Drawing.Size(1294, 24);
+ this.menuStrip.Size = new System.Drawing.Size(1795, 24);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStrip1";
//
@@ -63,7 +64,8 @@
this.refbooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.componentsToolStripMenuItem,
this.manufacturesToolStripMenuItem,
- this.clientsToolStripMenuItem});
+ this.clientsToolStripMenuItem,
+ this.implementersToolStripMenuItem});
this.refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem";
this.refbooksToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.refbooksToolStripMenuItem.Text = "Справочники";
@@ -71,24 +73,31 @@
// componentsToolStripMenuItem
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
- this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.componentsToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
this.componentsToolStripMenuItem.Text = "Компоненты";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// manufacturesToolStripMenuItem
//
this.manufacturesToolStripMenuItem.Name = "manufacturesToolStripMenuItem";
- this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
this.manufacturesToolStripMenuItem.Text = "Изделия";
this.manufacturesToolStripMenuItem.Click += new System.EventHandler(this.ManufacturesToolStripMenuItem_Click);
//
// clientsToolStripMenuItem
//
this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
- this.clientsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
+ this.clientsToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
this.clientsToolStripMenuItem.Text = "Клиенты";
this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
//
+ // implementersToolStripMenuItem
+ //
+ this.implementersToolStripMenuItem.Name = "implementersToolStripMenuItem";
+ this.implementersToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
+ this.implementersToolStripMenuItem.Text = "Исполнители";
+ this.implementersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
+ //
// reportsToolStripMenuItem
//
this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -120,6 +129,13 @@
this.reportOrdersToolStripMenuItem.Text = "Список заказов";
this.reportOrdersToolStripMenuItem.Click += new System.EventHandler(this.ReportOrdersToolStripMenuItem_Click);
//
+ // doWorkToolStripMenuItem
+ //
+ this.doWorkToolStripMenuItem.Name = "doWorkToolStripMenuItem";
+ this.doWorkToolStripMenuItem.Size = new System.Drawing.Size(92, 20);
+ this.doWorkToolStripMenuItem.Text = "Запуск работ";
+ this.doWorkToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click);
+ //
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
@@ -127,12 +143,12 @@
this.dataGridView.Location = new System.Drawing.Point(12, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
- this.dataGridView.Size = new System.Drawing.Size(981, 456);
+ this.dataGridView.Size = new System.Drawing.Size(1482, 456);
this.dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
- this.buttonCreateOrder.Location = new System.Drawing.Point(999, 27);
+ this.buttonCreateOrder.Location = new System.Drawing.Point(1500, 27);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonCreateOrder.Size = new System.Drawing.Size(283, 23);
@@ -141,31 +157,9 @@
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
- // buttonTakeOrderInWork
- //
- this.buttonTakeOrderInWork.Location = new System.Drawing.Point(999, 56);
- this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
- this.buttonTakeOrderInWork.RightToLeft = System.Windows.Forms.RightToLeft.No;
- this.buttonTakeOrderInWork.Size = new System.Drawing.Size(283, 23);
- this.buttonTakeOrderInWork.TabIndex = 2;
- this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
- this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
- this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
- //
- // buttonOrderReady
- //
- this.buttonOrderReady.Location = new System.Drawing.Point(999, 85);
- this.buttonOrderReady.Name = "buttonOrderReady";
- this.buttonOrderReady.RightToLeft = System.Windows.Forms.RightToLeft.No;
- this.buttonOrderReady.Size = new System.Drawing.Size(283, 23);
- this.buttonOrderReady.TabIndex = 2;
- this.buttonOrderReady.Text = "Заказ готов";
- this.buttonOrderReady.UseVisualStyleBackColor = true;
- this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
- //
// buttonIssuedOrder
//
- this.buttonIssuedOrder.Location = new System.Drawing.Point(1000, 114);
+ this.buttonIssuedOrder.Location = new System.Drawing.Point(1500, 56);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonIssuedOrder.Size = new System.Drawing.Size(283, 23);
@@ -176,7 +170,7 @@
//
// buttonRef
//
- this.buttonRef.Location = new System.Drawing.Point(999, 143);
+ this.buttonRef.Location = new System.Drawing.Point(1499, 85);
this.buttonRef.Name = "buttonRef";
this.buttonRef.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonRef.Size = new System.Drawing.Size(283, 23);
@@ -189,11 +183,9 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1294, 504);
+ this.ClientSize = new System.Drawing.Size(1795, 504);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
- this.Controls.Add(this.buttonOrderReady);
- this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip);
@@ -217,8 +209,6 @@
private ToolStripMenuItem manufacturesToolStripMenuItem;
private DataGridView dataGridView;
private Button buttonCreateOrder;
- private Button buttonTakeOrderInWork;
- private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem reportsToolStripMenuItem;
@@ -226,5 +216,7 @@
private ToolStripMenuItem reportManufactureComponentsToolStripMenuItem;
private ToolStripMenuItem reportOrdersToolStripMenuItem;
private ToolStripMenuItem clientsToolStripMenuItem;
- }
+ private ToolStripMenuItem implementersToolStripMenuItem;
+ private ToolStripMenuItem doWorkToolStripMenuItem;
+ }
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
index 226a780..6d248c0 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs
@@ -11,12 +11,16 @@ namespace BlacksmithWorkshopView
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
+ private readonly IImplementerLogic _implementerLogic;
+ private readonly IWorkProcess _workProcess;
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess, IImplementerLogic implementerLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
+ _workProcess = workProcess;
+ _implementerLogic = implementerLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
@@ -32,8 +36,9 @@ namespace BlacksmithWorkshopView
{
dataGridView.DataSource = list;
dataGridView.Columns["ManufactureId"].Visible = false;
- dataGridView.Columns["ClientId"].Visible = false;
- dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ImplementerId"].Visible = false;
+ dataGridView.Columns["ClientId"].Visible = false;
+ dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
@@ -186,5 +191,18 @@ namespace BlacksmithWorkshopView
LoadData();
}
}
- }
+ private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
+ if (service is FormImplementers form)
+ {
+ form.ShowDialog();
+ LoadData();
+ }
+ }
+ private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ _workProcess.DoWork(_implementerLogic, _orderLogic);
+ }
+ }
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
index 83c781a..83f6bd9 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs
@@ -38,12 +38,15 @@ namespace BlacksmithWorkshopView
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();
@@ -56,6 +59,8 @@ namespace BlacksmithWorkshopView
services.AddTransient();
services.AddTransient();
services.AddTransient();
- }
+ services.AddTransient();
+ services.AddTransient();
+ }
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs
new file mode 100644
index 0000000..a10ac5e
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs
@@ -0,0 +1,115 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
+{
+ public class ImplementerLogic : IImplementerLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IImplementerStorage _implementerStorage;
+ public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage)
+ {
+ _logger = logger;
+ _implementerStorage = implementerStorage;
+ }
+ public List? ReadList(ImplementerSearchModel? model)
+ {
+ _logger.LogInformation("Readlist. Id: {Id}", model?.Id);
+ var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("Readlist. Count: {Count}", list.Count);
+ return list;
+ }
+ public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. Id: {Id}", model.Id);
+ var element = _implementerStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
+ return element;
+ }
+ public bool Create(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(ImplementerBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_implementerStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(ImplementerBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (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/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
index 007c1c7..c17cb9a 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -29,7 +29,23 @@ namespace BlacksmithWorkShopBusinessLogic.BusinessLogics
_logger.LogInformation("Readlist. Count: {Count}", list.Count);
return list;
}
- public bool SetNewStatus(OrderBindingModel model, OrderStatus newstatus)
+ 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;
+ }
+ public bool SetNewStatus(OrderBindingModel model, OrderStatus newstatus)
{
CheckModel(model, false);
OrderViewModel? vm = _orderStorage.GetElement(new()
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs
new file mode 100644
index 0000000..46f7f9a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs
@@ -0,0 +1,140 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Enums;
+using Microsoft.Extensions.Logging;
+
+namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
+{
+ public class WorkModeling : IWorkProcess
+ {
+ private readonly ILogger _logger;
+ private readonly Random _rnd;
+ private IOrderLogic? _orderLogic;
+ public WorkModeling(ILogger logger)
+ {
+ _logger = logger;
+ _rnd = new Random(1000);
+ }
+ public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
+ {
+ _orderLogic = orderLogic;
+ var implementers = implementerLogic.ReadList(null);
+ if (implementers == null || implementers.Count == 0)
+ {
+ _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
+ });
+ }
+ // кто-то мог уже перехватить заказ, игнорируем ошибку
+ catch (InvalidOperationException ex)
+ {
+ _logger.LogWarning(ex, "Error try get work");
+ }
+ // заканчиваем выполнение имитации в случае иной ошибки
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error while do work");
+ throw;
+ }
+ // отдыхаем
+ Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
+ }
+ });
+ }
+ ///
+ /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
+ ///
+ ///
+ ///
+ private async Task RunOrderInWork(ImplementerViewModel implementer)
+ {
+ 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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs
new file mode 100644
index 0000000..a36c211
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs
@@ -0,0 +1,13 @@
+using BlacksmithWorkshopDataModels.Models;
+
+namespace BlacksmithWorkshopContracts.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; }
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs
index f428f9b..d5b2dce 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel.cs
@@ -13,5 +13,6 @@ namespace BlacksmithWorkshopContracts.BindingModels
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
public int ClientId { get; set; }
+ public int? ImplementerId { get; set; }
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs
new file mode 100644
index 0000000..6a8a152
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs
@@ -0,0 +1,15 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.ViewModels;
+
+namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs
index b228496..60e6e98 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -7,6 +7,7 @@ namespace BlacksmithWorkshopContracts.BusinessLogicContracts
public interface IOrderLogic
{
List? ReadList(OrderSearchModel? model);
+ OrderViewModel? ReadElement (OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs
new file mode 100644
index 0000000..30f02a4
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs
@@ -0,0 +1,12 @@
+using BlacksmithWorkshopContracts.BusinessLogicContracts;
+
+namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
+{
+ public interface IWorkProcess
+ {
+ ///
+ /// Запуск работ
+ ///
+ void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs
new file mode 100644
index 0000000..b1931c2
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs
@@ -0,0 +1,9 @@
+namespace BlacksmithWorkshopContracts.SearchModels
+{
+ public class ImplementerSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ImplementerFIO { get; set; }
+ public string? Password { get; set; }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs
index ba03a28..5614a1b 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs
@@ -1,4 +1,6 @@
-namespace BlacksmithWorkshopContracts.SearchModels
+using BlacksmithWorkshopDataModels.Enums;
+
+namespace BlacksmithWorkshopContracts.SearchModels
{
public class OrderSearchModel
{
@@ -6,5 +8,7 @@
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? ClientId { get; set; }
+ public OrderStatus? Status { get; set; }
+ public int? ImplementerId { get; set; }
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs
new file mode 100644
index 0000000..81f633f
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs
@@ -0,0 +1,16 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.ViewModels;
+
+namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs
new file mode 100644
index 0000000..4a9acfd
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs
@@ -0,0 +1,18 @@
+using BlacksmithWorkshopDataModels.Models;
+using System.ComponentModel;
+
+namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
index 70bebf2..8e6e8e3 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs
@@ -24,5 +24,8 @@ namespace BlacksmithWorkshopContracts.ViewModels
public DateTime? DateImplement { get; set; }
[DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty;
- }
+ public int? ImplementerId { get; set; }
+ [DisplayName("Исполнитель")]
+ public string ImplementerFIO { get; set; } = string.Empty;
+ }
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs
new file mode 100644
index 0000000..5ea4b4f
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs
@@ -0,0 +1,10 @@
+namespace BlacksmithWorkshopDataModels.Models
+{
+ public interface IImplementerModel : IId
+ {
+ string ImplementerFIO { get; }
+ string Password { get; }
+ int WorkExperience { get; }
+ int Qualification { get; }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs
index 99d9e5c..56ae017 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs
@@ -11,5 +11,6 @@ namespace BlacksmithWorkshopDataModels.Models
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
+ int? ImplementerId { get; }
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabase.cs
index 430af4d..fe27582 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabase.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/BlacksmithWorkshopDatabase.cs
@@ -25,5 +25,6 @@ namespace BlacksmithWorkshopDatabaseImplement
public virtual DbSet ManufactureComponents { set; get; }
public virtual DbSet Orders { set; get; }
public virtual DbSet Clients { set; get; }
+ public virtual DbSet Implementers { set; get; }
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..7c34e75
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,87 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDatabaseImplement.Models;
+
+namespace BlacksmithWorkshopDatabaseImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ return context.Implementers.Select(x => x.GetViewModel).ToList();
+ }
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ return new();
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ if (model.Id.HasValue)
+ {
+ return context.Implementers
+ .Where(x => x.Id == model.Id)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ return context.Implementers
+ .Where(x => x.ImplementerFIO == model.ImplementerFIO)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ if (!model.Id.HasValue && (string.IsNullOrEmpty(model.ImplementerFIO) || string.IsNullOrEmpty(model.Password)))
+ {
+ return new();
+ }
+ using var context = new BlacksmithWorkshopDatabase();
+ if (model.Id.HasValue)//Сначала ищем по Id
+ {
+ return context.Implementers
+ .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ }
+ return context.Implementers//Затем по логину и паролю
+ .FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel;
+ }
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ var newImplementer = Implementer.Create(model);
+ if (newImplementer == null)
+ {
+ return null;
+ }
+ context.Implementers.Add(newImplementer);
+ context.SaveChanges();
+ return newImplementer.GetViewModel;
+ }
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (implementer == null)
+ {
+ return null;
+ }
+ implementer.Update(model);
+ context.SaveChanges();
+ return implementer.GetViewModel;
+ }
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ using var context = new BlacksmithWorkshopDatabase();
+ var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (implementer == null)
+ {
+ return null;
+ }
+ context.Implementers.Remove(implementer);
+ context.SaveChanges();
+ return implementer.GetViewModel;
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs
index d6e4e38..71e12f7 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Implements/OrderStorage.cs
@@ -14,6 +14,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
using var context = new BlacksmithWorkshopDatabase();
List orderList = context.Orders
.Include(x => x.Client)
+ .Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
foreach (var order in orderList)
@@ -26,10 +27,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
}
public List GetFilteredList(OrderSearchModel model)
{
- if (!model.Id.HasValue && !model.ClientId.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
- {
- return new();
- }
using var context = new BlacksmithWorkshopDatabase();
List orderList = new();
if (model.Id.HasValue) //сначала ищем по Id
@@ -37,7 +34,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
orderList = context.Orders
.Where(x => x.Id == model.Id)
.Include(x => x.Client)
- .Select(x => x.GetViewModel)
+ .Include(x => x.Implementer)
+ .Select(x => x.GetViewModel)
.ToList();
}
else if (model.DateFrom.HasValue && model.DateTo.HasValue) //если у модели нет Id, ищем по датам
@@ -45,17 +43,28 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
orderList = context.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Include(x => x.Client)
+ .Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
}
- else if (model.ClientId.HasValue)
+ else if (model.ClientId.HasValue)//далее ищем по клиенту
{
orderList = context.Orders
.Where(x => x.ClientId == model.ClientId)
.Include(x => x.Client)
+ .Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
}
+ else if (model.Status.HasValue)//далее ищем по статусу
+ {
+ orderList = context.Orders
+ .Where(x => x.Status == model.Status)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
foreach (var order in orderList)
{
string manufactureName = context.Manufactures
@@ -66,13 +75,27 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
- if (!model.Id.HasValue)
+ if (!model.Id.HasValue && !model.ImplementerId.HasValue)
{
return null;
}
using var context = new BlacksmithWorkshopDatabase();
- return context.Orders
- .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ if (model.Id.HasValue)//Сначала ищем по Id
+ {
+ return context.Orders
+ .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ }
+ if (model.ImplementerId.HasValue && !model.Status.HasValue)//Затем только по исполнителю
+ {
+ return context.Orders
+ .FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
+ }
+ if (model.ImplementerId.HasValue && model.Status.HasValue)//Затем по исполнителю и статусу
+ {
+ return context.Orders
+ .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)?.GetViewModel;
+ }
+ return null;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230425172721_AddingImplementerMigration.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230425172721_AddingImplementerMigration.Designer.cs
new file mode 100644
index 0000000..f58564a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230425172721_AddingImplementerMigration.Designer.cs
@@ -0,0 +1,255 @@
+//
+using System;
+using BlacksmithWorkshopDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace BlacksmithWorkshopDatebaseImplement.Migrations
+{
+ [DbContext(typeof(BlacksmithWorkshopDatabase))]
+ [Migration("20230425172721_AddingImplementerMigration")]
+ partial class AddingImplementerMigration
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.4")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Qualification")
+ .HasColumnType("int");
+
+ b.Property("WorkExperience")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ManufactureName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Price")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Manufactures");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("ManufactureId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComponentId");
+
+ b.HasIndex("ManufactureId");
+
+ b.ToTable("ManufactureComponents");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateImplement")
+ .HasColumnType("datetime2");
+
+ b.Property("ImplementerId")
+ .HasColumnType("int");
+
+ b.Property("ManufactureId")
+ .HasColumnType("int");
+
+ b.Property("Status")
+ .HasColumnType("int");
+
+ b.Property("Sum")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("ImplementerId");
+
+ b.HasIndex("ManufactureId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b =>
+ {
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component")
+ .WithMany("ManufactureComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture")
+ .WithMany("Components")
+ .HasForeignKey("ManufactureId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Component");
+
+ b.Navigation("Manufacture");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null)
+ .WithMany("Orders")
+ .HasForeignKey("ManufactureId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Client");
+
+ b.Navigation("Implementer");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("ManufactureComponents");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230425172721_AddingImplementerMigration.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230425172721_AddingImplementerMigration.cs
new file mode 100644
index 0000000..6e9e434
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/20230425172721_AddingImplementerMigration.cs
@@ -0,0 +1,67 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace BlacksmithWorkshopDatebaseImplement.Migrations
+{
+ ///
+ public partial class AddingImplementerMigration : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "ImplementerId",
+ table: "Orders",
+ type: "int",
+ nullable: true);
+
+ migrationBuilder.CreateTable(
+ name: "Implementers",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false),
+ Password = table.Column(type: "nvarchar(max)", nullable: false),
+ WorkExperience = table.Column(type: "int", nullable: false),
+ Qualification = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Implementers", x => x.Id);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId",
+ principalTable: "Implementers",
+ principalColumn: "Id");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ table: "Orders");
+
+ migrationBuilder.DropTable(
+ name: "Implementers");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders");
+
+ migrationBuilder.DropColumn(
+ name: "ImplementerId",
+ table: "Orders");
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs
index e82000e..bc3bddb 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Migrations/BlacksmithWorkshopDatabaseModelSnapshot.cs
@@ -67,6 +67,33 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Qualification")
+ .HasColumnType("int");
+
+ b.Property("WorkExperience")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
{
b.Property("Id")
@@ -133,6 +160,9 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("datetime2");
+ b.Property("ImplementerId")
+ .HasColumnType("int");
+
b.Property("ManufactureId")
.HasColumnType("int");
@@ -146,6 +176,8 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.HasIndex("ManufactureId");
b.ToTable("Orders");
@@ -178,6 +210,10 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null)
.WithMany("Orders")
.HasForeignKey("ManufactureId")
@@ -185,6 +221,8 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations
.IsRequired();
b.Navigation("Client");
+
+ b.Navigation("Implementer");
});
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b =>
@@ -197,6 +235,11 @@ namespace BlacksmithWorkshopDatebaseImplement.Migrations
b.Navigation("ManufactureComponents");
});
+ modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b =>
{
b.Navigation("Components");
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs
new file mode 100644
index 0000000..ea3eaba
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Implementer.cs
@@ -0,0 +1,58 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace BlacksmithWorkshopDatabaseImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public int Id { get; private set; }
+ [Required]
+ public string ImplementerFIO { get; private set; } = string.Empty;
+ [Required]
+ public string Password { get; private set; } = string.Empty;
+ [Required]
+ public int WorkExperience { get; private set; }
+ [Required]
+ public int Qualification { get; private set; }
+ //Привязываем исполнителя к заказам один ко многим
+ [ForeignKey("ImplementerId")]
+ public virtual List Orders { get; private set; } = new();
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Password = model.Password,
+ Qualification = model.Qualification,
+ ImplementerFIO = model.ImplementerFIO,
+ WorkExperience = model.WorkExperience,
+ };
+ }
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Password = model.Password;
+ Qualification = model.Qualification;
+ ImplementerFIO = model.ImplementerFIO;
+ WorkExperience = model.WorkExperience;
+ }
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Password = Password,
+ Qualification = Qualification,
+ ImplementerFIO = ImplementerFIO,
+ WorkExperience = WorkExperience,
+ };
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs
index ae4020f..c217dda 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopDatebaseImplement/Models/Order.cs
@@ -24,6 +24,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
public int ClientId { get; private set; }
[Required]
public virtual Client? Client { get; private set; }
+ public int? ImplementerId { get; private set; }
+ public virtual Implementer? Implementer { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
@@ -39,7 +41,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
- ClientId = model.ClientId
+ ClientId = model.ClientId,
+ ImplementerId = model.ImplementerId
};
}
public static Order Create(OrderViewModel model)
@@ -62,6 +65,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
return;
}
Status = model.Status;
+ if (model.ImplementerId != null)
+ {
+ ImplementerId = model.ImplementerId;
+ }
if (model.DateImplement != null)
{
DateImplement = model.DateImplement;
@@ -77,7 +84,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
DateCreate = DateCreate,
DateImplement = DateImplement,
ClientId = ClientId,
- ClientFIO = Client?.ClientFIO ?? string.Empty
- };
+ ClientFIO = Client?.ClientFIO ?? string.Empty,
+ ImplementerId = ImplementerId,
+ ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
+ };
}
}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs
index 4c631a2..ec51aa2 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs
@@ -9,10 +9,12 @@ namespace BlacksmithWorkshopFileImplement
private readonly string OrderFileName = "Order.xml";
private readonly string ManufactureFileName = "Manufacture.xml";
private readonly string ClientFileName = "Client.xml";
- public List Components { get; private set; }
+ private readonly string ImplementerFileName = "Implementer.xml";
+ public List Components { get; private set; }
public List Orders { get; private set; }
public List Manufactures { get; private set; }
public List Clients { get; private set; }
+ public List Implementers { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@@ -25,13 +27,15 @@ namespace BlacksmithWorkshopFileImplement
public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName, "Manufactures", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
- private DataFileSingleton()
+ public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementer", x => x.GetXElement);
+ private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Manufactures = LoadData(ManufactureFileName, "Manufacture", x => Manufacture.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)
{
if (File.Exists(filename))
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..47c1eba
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,88 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopFileImplement.Models;
+
+namespace BlacksmithWorkshopFileImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataFileSingleton _source;
+ public ImplementerStorage()
+ {
+ _source = DataFileSingleton.GetInstance();
+ }
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ _source.Implementers.Remove(res);
+ _source.SaveImplementers();
+ }
+ return res?.GetViewModel;
+ }
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ if (!model.Id.HasValue && (string.IsNullOrEmpty(model.ImplementerFIO) || string.IsNullOrEmpty(model.Password)))
+ {
+ return new();
+ }
+ if (model.Id.HasValue)//Сначала ищем по Id
+ {
+ return _source.Implementers
+ .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ }
+ return _source.Implementers//Затем по логину и паролю
+ .FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ return new();
+ }
+ if (model.Id.HasValue)
+ {
+ return _source.Implementers
+ .Where(x => x.Id == model.Id)
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ return _source.Implementers
+ .Where(x => x.ImplementerFIO == 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 res = Implementer.Create(model);
+ if (res != null)
+ {
+ _source.Implementers.Add(res);
+ _source.SaveImplementers();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ res.Update(model);
+ _source.SaveImplementers();
+ }
+ return res?.GetViewModel;
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs
index 3ab0d7b..c7755b6 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs
@@ -14,16 +14,17 @@ namespace BlacksmithWorkshopFileImplement.Implements
{
source = DataFileSingleton.GetInstance();
}
- private OrderViewModel AddManufactureAndClientName (OrderViewModel model)
+ private OrderViewModel AddManufactureAndClientAndImplementerName (OrderViewModel model)
{
model.ManufactureName = source.Manufactures.SingleOrDefault(x => x.Id == model.ManufactureId)?.ManufactureName ?? string.Empty;
model.ClientFIO = source.Clients.SingleOrDefault(x => x.Id == model.ClientId)?.ClientFIO ?? string.Empty;
+ model.ImplementerFIO = source.Implementers.SingleOrDefault(x => x.Id == model.ImplementerId)?.ImplementerFIO ?? string.Empty;
return model;
}
public List GetFullList()
{
return source.Orders
- .Select(x => AddManufactureAndClientName(x.GetViewModel))
+ .Select(x => AddManufactureAndClientAndImplementerName(x.GetViewModel))
.ToList();
}
public List GetFilteredList(OrderSearchModel model)
@@ -36,21 +37,21 @@ namespace BlacksmithWorkshopFileImplement.Implements
{
return source.Orders
.Where(x => x.Id == model.Id)
- .Select(x => AddManufactureAndClientName(x.GetViewModel))
+ .Select(x => AddManufactureAndClientAndImplementerName(x.GetViewModel))
.ToList();
}
else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если Id в модели нет, ищем по датам
{
return source.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
- .Select(x => AddManufactureAndClientName(x.GetViewModel))
+ .Select(x => AddManufactureAndClientAndImplementerName(x.GetViewModel))
.ToList();
}
else if (model.ClientId.HasValue)//далее ищем по Id клиента
{
return source.Orders
.Where(x => x.ClientId == model.ClientId)
- .Select(x => AddManufactureAndClientName(x.GetViewModel))
+ .Select(x => AddManufactureAndClientAndImplementerName(x.GetViewModel))
.ToList();
}
return new();//если нет ни того, ни другого, ни третьего, возвращаем пустой список
@@ -66,7 +67,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
{
return null;
}
- return AddManufactureAndClientName(order);
+ return AddManufactureAndClientAndImplementerName(order);
}
public OrderViewModel? Insert(OrderBindingModel model)
{
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs
new file mode 100644
index 0000000..49b3d73
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs
@@ -0,0 +1,71 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+using System.Xml.Linq;
+
+namespace BlacksmithWorkshopFileImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public int Id { get; private set; }
+ public string ImplementerFIO { get; private set; } = string.Empty;
+ public string Password { get; private set; } = string.Empty;
+ public int WorkExperience { get; private set; }
+ public int Qualification { get; private set; }
+ public static Implementer? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ ImplementerFIO = element.Element("FIO")!.Value,
+ Password = element.Element("Password")!.Value,
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
+ WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
+ };
+ }
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Password = model.Password,
+ Qualification = model.Qualification,
+ ImplementerFIO = model.ImplementerFIO,
+ WorkExperience = model.WorkExperience,
+ };
+ }
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Password = model.Password;
+ Qualification = model.Qualification;
+ ImplementerFIO = model.ImplementerFIO;
+ WorkExperience = model.WorkExperience;
+ }
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Password = Password,
+ Qualification = Qualification,
+ ImplementerFIO = ImplementerFIO,
+ };
+ public XElement GetXElement => new("Client",
+ new XAttribute("Id", Id),
+ new XElement("Password", Password),
+ new XElement("FIO", ImplementerFIO),
+ new XElement("Qualification", Qualification),
+ new XElement("WorkExperience", WorkExperience)
+ );
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
index e2e542c..55d50b4 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs
@@ -2,6 +2,7 @@
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Enums;
using BlacksmithWorkshopDataModels.Models;
+using System.Reflection;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
@@ -16,6 +17,7 @@ namespace BlacksmithWorkshopFileImplement.Models
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public int ClientId { get; private set; }
+ public int? ImplementerId { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@@ -31,8 +33,9 @@ namespace BlacksmithWorkshopFileImplement.Models
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
- ClientId = model.ClientId
- };
+ ClientId = model.ClientId,
+ ImplementerId = model.ImplementerId,
+ };
}
public static Order? Create(XElement element)
{
@@ -55,7 +58,8 @@ namespace BlacksmithWorkshopFileImplement.Models
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = dateImplement,
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
- };
+ ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
+ };
}
public void Update(OrderBindingModel? model)
{
@@ -64,6 +68,10 @@ namespace BlacksmithWorkshopFileImplement.Models
return;
}
Status = model.Status;
+ if (model.ImplementerId != null)
+ {
+ ImplementerId = model.ImplementerId;
+ }
if (model.DateImplement != null)
{
DateImplement = model.DateImplement;
@@ -89,7 +97,8 @@ namespace BlacksmithWorkshopFileImplement.Models
new XElement("Status", (int)Status),
new XElement("DateCreate", DateCreate),
new XElement("DateImplement", DateImplement),
- new XElement("ClientId", ClientId)
+ new XElement("ClientId", ClientId),
+ new XElement("ImplementerId", ImplementerId)
);
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
index 062f7e3..6625a94 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs
@@ -9,13 +9,15 @@ namespace BlacksmithWorkshopListImplement
public List Orders { get; set; }
public List Manufactures { get; set; }
public List Clients { get; set; }
- private DataListSingleton()
+ public List Implementers { get; set; }
+ private DataListSingleton()
{
Components = new List();
Orders = new List();
Manufactures = new List();
Clients = new List();
- }
+ Implementers = new List();
+ }
public static DataListSingleton GetInstance()
{
if (_instance == null)
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..261100d
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,119 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.StoragesContracts;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopListImplement.Models;
+
+namespace BlacksmithWorkshopListImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataListSingleton _source;
+ public ImplementerStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ for (int i = 0; i < _source.Implementers.Count; ++i)
+ {
+ if (_source.Implementers[i].Id == model.Id)
+ {
+ var element = _source.Implementers[i];
+ _source.Implementers.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (model.Id.HasValue && implementer.Id == model.Id)
+ {
+ return implementer.GetViewModel;
+ }
+ if (model.ImplementerFIO != null && model.Password != null && implementer.ImplementerFIO.Equals(model.ImplementerFIO) && implementer.Password.Equals(model.Password))
+ {
+ return implementer.GetViewModel;
+ }
+ if (model.ImplementerFIO != null && implementer.ImplementerFIO.Equals(model.ImplementerFIO))
+ {
+ return implementer.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ var result = new List();
+ if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ return result;
+ }
+ if (model.Id.HasValue)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.Id == model.Id)
+ {
+ result.Add(implementer.GetViewModel);
+ }
+ }
+ return result;
+ }
+ else
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.ImplementerFIO == model.ImplementerFIO)
+ {
+ result.Add(implementer.GetViewModel);
+ }
+ }
+ return result;
+ }
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var implementer in _source.Implementers)
+ {
+ result.Add(implementer.GetViewModel);
+ }
+ return result;
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var implementer in _source.Implementers)
+ {
+ if (model.Id <= implementer.Id)
+ {
+ model.Id = implementer.Id + 1;
+ }
+ }
+ var res = Implementer.Create(model);
+ if (res != null)
+ {
+ _source.Implementers.Add(res);
+ }
+ return res?.GetViewModel;
+ }
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.Id == model.Id)
+ {
+ implementer.Update(model);
+ return implementer.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs
index a84095f..fc24ebd 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs
@@ -23,6 +23,8 @@ namespace BlacksmithWorkshopListImplement.Implements
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
var client = _source.Clients.Find(x => x.Id == order.ClientId);
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
result.Add(vm);
}
return result;
@@ -45,6 +47,8 @@ namespace BlacksmithWorkshopListImplement.Implements
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
var client = _source.Clients.Find(x => x.Id == order.ClientId);
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
result.Add(vm);
}
}
@@ -60,6 +64,8 @@ namespace BlacksmithWorkshopListImplement.Implements
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
var client = _source.Clients.Find(x => x.Id == order.ClientId);
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
result.Add(vm);
}
}
@@ -75,11 +81,30 @@ namespace BlacksmithWorkshopListImplement.Implements
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
var client = _source.Clients.Find(x => x.Id == order.ClientId);
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
result.Add(vm);
}
}
}
- return result;
+ else if (model.Status.HasValue)//далее ищем по статусу
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Status == model.Status)
+ {
+ OrderViewModel vm = order.GetViewModel;
+ var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
+ vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
+ var client = _source.Clients.Find(x => x.Id == order.ClientId);
+ vm.ClientFIO = client?.ClientFIO ?? string.Empty;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
+ result.Add(vm);
+ }
+ }
+ }
+ return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
@@ -96,9 +121,44 @@ namespace BlacksmithWorkshopListImplement.Implements
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
var client = _source.Clients.Find(x => x.Id == order.ClientId);
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
- return vm;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
+ return vm;
}
- }
+ else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId)
+ {
+ OrderViewModel vm = order.GetViewModel;
+ var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
+ vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
+ var client = _source.Clients.Find(x => x.Id == order.ClientId);
+ vm.ClientFIO = client?.ClientFIO ?? string.Empty;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
+ return vm;
+ }
+ else if (model.ImplementerId.HasValue && !model.Status.HasValue)
+ {
+ OrderViewModel vm = order.GetViewModel;
+ var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
+ vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
+ var client = _source.Clients.Find(x => x.Id == order.ClientId);
+ vm.ClientFIO = client?.ClientFIO ?? string.Empty;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
+ return vm;
+ }
+ else if (model.ImplementerId.HasValue && model.Status.HasValue)
+ {
+ OrderViewModel vm = order.GetViewModel;
+ var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
+ vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
+ var client = _source.Clients.Find(x => x.Id == order.ClientId);
+ vm.ClientFIO = client?.ClientFIO ?? string.Empty;
+ var implementer = _source.Implementers.Find(x => x.Id == order.ImplementerId);
+ vm.ImplementerFIO = implementer?.ImplementerFIO ?? string.Empty;
+ return vm;
+ }
+ }
return null;
}
public OrderViewModel? Insert(OrderBindingModel model)
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs
new file mode 100644
index 0000000..15a429a
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs
@@ -0,0 +1,48 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Models;
+
+namespace BlacksmithWorkshopListImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public int Id { get; private set; }
+ public string ImplementerFIO { get; private set; } = string.Empty;
+ public string Password { get; private set; } = string.Empty;
+ public int WorkExperience { get; private set; }
+ public int Qualification { get; private set; }
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Password = model.Password,
+ Qualification = model.Qualification,
+ ImplementerFIO = model.ImplementerFIO,
+ WorkExperience = model.WorkExperience,
+ };
+ }
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Password = model.Password;
+ Qualification = model.Qualification;
+ ImplementerFIO = model.ImplementerFIO;
+ WorkExperience = model.WorkExperience;
+ }
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Password = Password,
+ Qualification = Qualification,
+ ImplementerFIO = ImplementerFIO,
+ };
+ }
+}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
index 2550c97..0817af2 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs
@@ -16,7 +16,8 @@ namespace BlacksmithWorkshopListImplement.Models
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public int ClientId { get; private set; }
- public static Order? Create(OrderBindingModel? model)
+ public int? ImplementerId { get; private set; }
+ public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
@@ -31,7 +32,8 @@ namespace BlacksmithWorkshopListImplement.Models
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
- ClientId = model.ClientId
+ ClientId = model.ClientId,
+ ImplementerId = model.ImplementerId
};
}
public void Update(OrderBindingModel? model)
@@ -41,6 +43,10 @@ namespace BlacksmithWorkshopListImplement.Models
return;
}
Status = model.Status;
+ if (model.ImplementerId != null)
+ {
+ ImplementerId = model.ImplementerId;
+ }
if (model.DateImplement != null)
{
DateImplement = model.DateImplement;
@@ -54,7 +60,7 @@ namespace BlacksmithWorkshopListImplement.Models
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
- DateImplement = DateImplement,
- };
+ DateImplement = DateImplement
+ };
}
}
\ No newline at end of file
diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ImplementerController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ImplementerController.cs
new file mode 100644
index 0000000..f0c8a86
--- /dev/null
+++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Controllers/ImplementerController.cs
@@ -0,0 +1,101 @@
+using BlacksmithWorkshopContracts.BindingModels;
+using BlacksmithWorkshopContracts.BusinessLogicContracts;
+using BlacksmithWorkshopContracts.BusinessLogicsContracts;
+using BlacksmithWorkshopContracts.SearchModels;
+using BlacksmithWorkshopContracts.ViewModels;
+using BlacksmithWorkshopDataModels.Enums;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using Microsoft.AspNetCore.Mvc;
+
+namespace BlacksmithWorkshopRestAPI.Controllers
+{
+ 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/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs
index 9f3d78b..663ba2b 100644
--- a/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs
+++ b/BlacksmithWorkshop/BlacksmithWorkshopRestAPI/Program.cs
@@ -16,10 +16,12 @@ 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();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle