diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.Designer.cs
new file mode 100644
index 0000000..ff1dbf1
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.Designer.cs
@@ -0,0 +1,178 @@
+namespace PrecastConcretePlantView
+{
+ partial class FormImplementer
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonSave = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown();
+ this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown();
+ this.textBoxPassword = new System.Windows.Forms.TextBox();
+ this.textBoxFio = new System.Windows.Forms.TextBox();
+ this.label4 = new System.Windows.Forms.Label();
+ this.label3 = new System.Windows.Forms.Label();
+ this.label2 = new System.Windows.Forms.Label();
+ this.label1 = new System.Windows.Forms.Label();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonSave
+ //
+ this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonSave.Location = new System.Drawing.Point(108, 151);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(89, 33);
+ this.buttonSave.TabIndex = 19;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonCancel.Location = new System.Drawing.Point(219, 151);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(89, 33);
+ this.buttonCancel.TabIndex = 18;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // numericUpDownQualification
+ //
+ this.numericUpDownQualification.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.numericUpDownQualification.Location = new System.Drawing.Point(116, 97);
+ this.numericUpDownQualification.Name = "numericUpDownQualification";
+ this.numericUpDownQualification.Size = new System.Drawing.Size(264, 23);
+ this.numericUpDownQualification.TabIndex = 17;
+ //
+ // numericUpDownWorkExperience
+ //
+ this.numericUpDownWorkExperience.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.numericUpDownWorkExperience.Location = new System.Drawing.Point(116, 68);
+ this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience";
+ this.numericUpDownWorkExperience.Size = new System.Drawing.Size(264, 23);
+ this.numericUpDownWorkExperience.TabIndex = 16;
+ //
+ // textBoxPassword
+ //
+ this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.textBoxPassword.Location = new System.Drawing.Point(116, 40);
+ this.textBoxPassword.Name = "textBoxPassword";
+ this.textBoxPassword.PasswordChar = '*';
+ this.textBoxPassword.Size = new System.Drawing.Size(264, 23);
+ this.textBoxPassword.TabIndex = 15;
+ //
+ // textBoxFio
+ //
+ this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.textBoxFio.Location = new System.Drawing.Point(116, 11);
+ this.textBoxFio.Name = "textBoxFio";
+ this.textBoxFio.Size = new System.Drawing.Size(264, 23);
+ this.textBoxFio.TabIndex = 14;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(14, 99);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(91, 15);
+ this.label4.TabIndex = 13;
+ this.label4.Text = "Квалификация:";
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(67, 70);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(38, 15);
+ this.label3.TabIndex = 12;
+ this.label3.Text = "Стаж:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(58, 43);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(52, 15);
+ this.label2.TabIndex = 11;
+ this.label2.Text = "Пароль:";
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(68, 14);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(37, 15);
+ this.label1.TabIndex = 10;
+ this.label1.Text = "ФИО:";
+ //
+ // FormImplementer
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(402, 196);
+ this.Controls.Add(this.buttonSave);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.numericUpDownQualification);
+ this.Controls.Add(this.numericUpDownWorkExperience);
+ this.Controls.Add(this.textBoxPassword);
+ this.Controls.Add(this.textBoxFio);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.label3);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.label1);
+ this.Name = "FormImplementer";
+ this.Text = "FormImplementer";
+ this.Load += new System.EventHandler(this.FormImplementer_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Button buttonSave;
+ private Button buttonCancel;
+ private NumericUpDown numericUpDownQualification;
+ private NumericUpDown numericUpDownWorkExperience;
+ private TextBox textBoxPassword;
+ private TextBox textBoxFio;
+ private Label label4;
+ private Label label3;
+ private Label label2;
+ private Label label1;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.cs
new file mode 100644
index 0000000..2aa54fd
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.cs
@@ -0,0 +1,100 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+using PrecastConcretePlantContracts.SearchModels;
+
+namespace PrecastConcretePlantView
+{
+ public partial class FormImplementer : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IImplementerLogic _logic;
+ private int? _id;
+ public int Id { set { _id = value; } }
+
+ public FormImplementer(ILogger logger, IImplementerLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormImplementer_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ try
+ {
+ _logger.LogInformation("Получение исполнителя");
+ var view = _logic.ReadElement(new ImplementerSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ textBoxFio.Text = view.ImplementerFIO;
+ textBoxPassword.Text = view.Password;
+ numericUpDownQualification.Value = view.Qualification;
+ numericUpDownWorkExperience.Value = view.WorkExperience;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения исполнителя");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxPassword.Text))
+ {
+ MessageBox.Show("Заполните пароль", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxFio.Text))
+ {
+ MessageBox.Show("Заполните фио", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение исполнителя");
+ try
+ {
+ var model = new ImplementerBindingModel
+ {
+ Id = _id ?? 0,
+ ImplementerFIO = textBoxFio.Text,
+ Password = textBoxPassword.Text,
+ Qualification = (int)numericUpDownQualification.Value,
+ WorkExperience = (int)numericUpDownWorkExperience.Value,
+ };
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения исполнителя");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.resx b/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormImplementer.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
index 8ce8f67..ec5c71a 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs
@@ -30,19 +30,19 @@
{
this.buttonRef = new System.Windows.Forms.Button();
this.buttonFinish = new System.Windows.Forms.Button();
- this.buttonReady = new System.Windows.Forms.Button();
- this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reinforcedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pastriesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.pastryComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.ReinforcedComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@@ -50,7 +50,7 @@
// buttonRef
//
this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonRef.Location = new System.Drawing.Point(823, 294);
+ this.buttonRef.Location = new System.Drawing.Point(1128, 219);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(147, 32);
this.buttonRef.TabIndex = 12;
@@ -61,7 +61,7 @@
// buttonFinish
//
this.buttonFinish.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonFinish.Location = new System.Drawing.Point(823, 235);
+ this.buttonFinish.Location = new System.Drawing.Point(1128, 142);
this.buttonFinish.Name = "buttonFinish";
this.buttonFinish.Size = new System.Drawing.Size(147, 32);
this.buttonFinish.TabIndex = 11;
@@ -69,32 +69,10 @@
this.buttonFinish.UseVisualStyleBackColor = true;
this.buttonFinish.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
- // buttonReady
- //
- this.buttonReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonReady.Location = new System.Drawing.Point(823, 177);
- this.buttonReady.Name = "buttonReady";
- this.buttonReady.Size = new System.Drawing.Size(147, 32);
- this.buttonReady.TabIndex = 10;
- this.buttonReady.Text = "Заказ готов";
- this.buttonReady.UseVisualStyleBackColor = true;
- this.buttonReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
- //
- // buttonTakeOrderInWork
- //
- this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonTakeOrderInWork.Location = new System.Drawing.Point(823, 118);
- this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
- this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 32);
- this.buttonTakeOrderInWork.TabIndex = 9;
- this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
- this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
- this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
- //
// buttonCreateOrder
//
this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonCreateOrder.Location = new System.Drawing.Point(823, 59);
+ this.buttonCreateOrder.Location = new System.Drawing.Point(1128, 59);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(147, 32);
this.buttonCreateOrder.TabIndex = 8;
@@ -111,17 +89,18 @@
this.dataGridView.Location = new System.Drawing.Point(12, 29);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
- this.dataGridView.Size = new System.Drawing.Size(805, 348);
+ this.dataGridView.Size = new System.Drawing.Size(1110, 348);
this.dataGridView.TabIndex = 7;
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem,
- this.reportsToolStripMenuItem});
+ this.reportsToolStripMenuItem,
+ this.запускРаботToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
- this.menuStrip1.Size = new System.Drawing.Size(999, 24);
+ this.menuStrip1.Size = new System.Drawing.Size(1304, 24);
this.menuStrip1.TabIndex = 13;
this.menuStrip1.Text = "menuStrip1";
//
@@ -130,7 +109,8 @@
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.reinforcedToolStripMenuItem,
this.componentToolStripMenuItem,
- this.clientsToolStripMenuItem});
+ this.clientsToolStripMenuItem,
+ this.исполнителиToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники";
@@ -149,11 +129,25 @@
this.componentToolStripMenuItem.Text = "Компоненты";
this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
+ // clientsToolStripMenuItem
+ //
+ this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
+ this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.clientsToolStripMenuItem.Text = "Клиенты";
+ this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
+ //
+ // исполнителиToolStripMenuItem
+ //
+ this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem";
+ this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.исполнителиToolStripMenuItem.Text = "Исполнители";
+ this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
+ //
// reportsToolStripMenuItem
//
this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.pastriesToolStripMenuItem,
- this.pastryComponentsToolStripMenuItem,
+ this.ReinforcedComponentsToolStripMenuItem,
this.ordersToolStripMenuItem});
this.reportsToolStripMenuItem.Name = "reportsToolStripMenuItem";
this.reportsToolStripMenuItem.Size = new System.Drawing.Size(60, 20);
@@ -166,12 +160,12 @@
this.pastriesToolStripMenuItem.Text = "Список изделий";
this.pastriesToolStripMenuItem.Click += new System.EventHandler(this.ReinforcedsToolStripMenuItem_Click_1);
//
- // pastryComponentsToolStripMenuItem
+ // ReinforcedComponentsToolStripMenuItem
//
- this.pastryComponentsToolStripMenuItem.Name = "pastryComponentsToolStripMenuItem";
- this.pastryComponentsToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
- this.pastryComponentsToolStripMenuItem.Text = "Изделия с компонентами";
- this.pastryComponentsToolStripMenuItem.Click += new System.EventHandler(this.ReinforcedComponentsToolStripMenuItem_Click);
+ this.ReinforcedComponentsToolStripMenuItem.Name = "ReinforcedComponentsToolStripMenuItem";
+ this.ReinforcedComponentsToolStripMenuItem.Size = new System.Drawing.Size(215, 22);
+ this.ReinforcedComponentsToolStripMenuItem.Text = "Изделия с компонентами";
+ this.ReinforcedComponentsToolStripMenuItem.Click += new System.EventHandler(this.ReinforcedComponentsToolStripMenuItem_Click);
//
// ordersToolStripMenuItem
//
@@ -180,23 +174,21 @@
this.ordersToolStripMenuItem.Text = "Список заказов";
this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
//
- // clientsToolStripMenuItem
+ // запускРаботToolStripMenuItem
//
- this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
- this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
- this.clientsToolStripMenuItem.Text = "Клиенты";
- this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
+ this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
+ this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20);
+ this.запускРаботToolStripMenuItem.Text = "Запуск работ";
+ this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(999, 389);
+ this.ClientSize = new System.Drawing.Size(1304, 389);
this.Controls.Add(this.menuStrip1);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonFinish);
- this.Controls.Add(this.buttonReady);
- this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Name = "FormMain";
@@ -214,8 +206,6 @@
private Button buttonRef;
private Button buttonFinish;
- private Button buttonReady;
- private Button buttonTakeOrderInWork;
private Button buttonCreateOrder;
private DataGridView dataGridView;
private MenuStrip menuStrip1;
@@ -224,8 +214,10 @@
private ToolStripMenuItem componentToolStripMenuItem;
private ToolStripMenuItem reportsToolStripMenuItem;
private ToolStripMenuItem pastriesToolStripMenuItem;
- private ToolStripMenuItem pastryComponentsToolStripMenuItem;
+ private ToolStripMenuItem ReinforcedComponentsToolStripMenuItem;
private ToolStripMenuItem ordersToolStripMenuItem;
private ToolStripMenuItem clientsToolStripMenuItem;
+ private ToolStripMenuItem исполнителиToolStripMenuItem;
+ private ToolStripMenuItem запускРаботToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
index f709908..60162f6 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs
@@ -13,13 +13,14 @@ namespace PrecastConcretePlantView
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
- public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic)
+ private readonly IWorkProcess _workProcess;
+ public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
- _reportLogic = reportLogic;
+ _workProcess = workProcess;
}
private void FormMain_Load(object sender, EventArgs e)
{
@@ -36,8 +37,10 @@ namespace PrecastConcretePlantView
dataGridView.Columns["Id"].HeaderText = "Номер заказа";
dataGridView.Columns["ReinforcedId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
+ dataGridView.Columns["ImplementerId"].Visible = false;
dataGridView.Columns["ReinforcedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}
@@ -194,5 +197,23 @@ namespace PrecastConcretePlantView
form.ShowDialog();
}
}
+
+ private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormViewImplementers));
+ if (service is FormViewImplementers form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ _workProcess.DoWork((
+ Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!,
+ _orderLogic);
+ MessageBox.Show("Процесс обработки запущен", "Сообщение",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormReportReinforcedComponents.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormReportReinforcedComponents.Designer.cs
index 60aee93..7f9e747 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/FormReportReinforcedComponents.Designer.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormReportReinforcedComponents.Designer.cs
@@ -30,7 +30,7 @@
{
this.buttonSaveToExcel = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
- this.ColumnPastry = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.ColumnReinforced = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
@@ -57,7 +57,7 @@
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
- this.ColumnPastry,
+ this.ColumnReinforced,
this.ColumnComponent,
this.ColumnCount});
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom;
@@ -70,12 +70,12 @@
this.dataGridView.Size = new System.Drawing.Size(666, 510);
this.dataGridView.TabIndex = 3;
//
- // ColumnPastry
+ // ColumnReinforced
//
- this.ColumnPastry.HeaderText = "Изделие";
- this.ColumnPastry.Name = "ColumnPastry";
- this.ColumnPastry.ReadOnly = true;
- this.ColumnPastry.Width = 200;
+ this.ColumnReinforced.HeaderText = "Изделие";
+ this.ColumnReinforced.Name = "ColumnReinforced";
+ this.ColumnReinforced.ReadOnly = true;
+ this.ColumnReinforced.Width = 200;
//
// ColumnComponent
//
@@ -109,7 +109,7 @@
private Button buttonSaveToExcel;
private DataGridView dataGridView;
- private DataGridViewTextBoxColumn ColumnPastry;
+ private DataGridViewTextBoxColumn ColumnReinforced;
private DataGridViewTextBoxColumn ColumnComponent;
private DataGridViewTextBoxColumn ColumnCount;
}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.Designer.cs
new file mode 100644
index 0000000..d2bc9c3
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.Designer.cs
@@ -0,0 +1,121 @@
+namespace PrecastConcretePlantView
+{
+ partial class FormViewImplementers
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.buttonRef = new System.Windows.Forms.Button();
+ this.buttonDel = new System.Windows.Forms.Button();
+ this.buttonUpd = new System.Windows.Forms.Button();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // buttonRef
+ //
+ this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRef.Location = new System.Drawing.Point(532, 149);
+ this.buttonRef.Name = "buttonRef";
+ this.buttonRef.Size = new System.Drawing.Size(90, 37);
+ this.buttonRef.TabIndex = 14;
+ this.buttonRef.Text = "Обновить";
+ this.buttonRef.UseVisualStyleBackColor = true;
+ this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
+ //
+ // buttonDel
+ //
+ this.buttonDel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDel.Location = new System.Drawing.Point(532, 110);
+ this.buttonDel.Name = "buttonDel";
+ this.buttonDel.Size = new System.Drawing.Size(90, 33);
+ this.buttonDel.TabIndex = 13;
+ this.buttonDel.Text = "Удалить";
+ this.buttonDel.UseVisualStyleBackColor = true;
+ this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
+ //
+ // buttonUpd
+ //
+ this.buttonUpd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUpd.Location = new System.Drawing.Point(532, 70);
+ this.buttonUpd.Name = "buttonUpd";
+ this.buttonUpd.Size = new System.Drawing.Size(90, 34);
+ this.buttonUpd.TabIndex = 12;
+ this.buttonUpd.Text = "Изменить";
+ this.buttonUpd.UseVisualStyleBackColor = true;
+ this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonAdd.Location = new System.Drawing.Point(532, 34);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(90, 30);
+ this.buttonAdd.TabIndex = 11;
+ this.buttonAdd.Text = "Добавить";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
+ //
+ // dataGridView
+ //
+ this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowTemplate.Height = 25;
+ this.dataGridView.Size = new System.Drawing.Size(469, 290);
+ this.dataGridView.TabIndex = 10;
+ //
+ // FormViewImplementers
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(634, 314);
+ this.Controls.Add(this.buttonRef);
+ this.Controls.Add(this.buttonDel);
+ this.Controls.Add(this.buttonUpd);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormViewImplementers";
+ this.Text = "FormViewImplementers";
+ this.Load += new System.EventHandler(this.FormViewImplementers_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.cs b/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.cs
new file mode 100644
index 0000000..b38f18e
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.cs
@@ -0,0 +1,103 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlant;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+
+namespace PrecastConcretePlantView
+{
+ public partial class FormViewImplementers : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IImplementerLogic _logic;
+ public FormViewImplementers(ILogger logger, IImplementerLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+ private void FormViewImplementers_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Загрузка исполнителей");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки исполнителей");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
+ if (service is FormImplementer form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
+ if (service is FormImplementer form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id =
+ Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление исполнителя");
+ try
+ {
+ if (!_logic.Delete(new ImplementerBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления исполнителя");
+ MessageBox.Show(ex.Message, "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.resx b/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlant/FormViewImplementers.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs
index a914093..bd6e9fd 100644
--- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs
+++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs
@@ -42,12 +42,16 @@ namespace PrecastConcretePlant
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();
@@ -63,6 +67,8 @@ namespace PrecastConcretePlant
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs
new file mode 100644
index 0000000..65115e5
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/ImplementerLogic.cs
@@ -0,0 +1,123 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantBusinessLogic.BusinessLogic
+{
+ public class ImplementerLogic : IImplementerLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IImplementerStorage _implementerStorage;
+ public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage)
+ {
+ _logger = logger;
+ _implementerStorage = implementerStorage;
+ }
+
+ public bool Create(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(ImplementerBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_implementerStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}",
+ model.ImplementerFIO, model.Id);
+ var element = _implementerStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public List? ReadList(ImplementerSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id);
+ var list = (model == null) ? _implementerStorage.GetFullList() :
+ _implementerStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public bool Update(ImplementerBindingModel model)
+ {
+ CheckModel(model);
+ if (_implementerStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(ImplementerBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.WorkExperience < 0)
+ {
+ throw new ArgumentException("Опыт работы не может быть отрицательным", nameof(model.WorkExperience));
+ }
+ if (model.Qualification < 0)
+ {
+ throw new ArgumentException("Квалификация не может быть отрицательной", nameof(model.Qualification));
+ }
+ if (string.IsNullOrEmpty(model.Password))
+ {
+ throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO));
+ }
+ if (string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ throw new ArgumentNullException("Нет фио исполнителя", nameof(model.ImplementerFIO));
+ }
+ _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO);
+ var element = _implementerStorage.GetElement(new ImplementerSearchModel
+ {
+ ImplementerFIO = model.ImplementerFIO,
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Исполнитель с таким фио уже есть");
+ }
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs
index b40d4ad..47dbedf 100644
--- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/OrderLogic.cs
@@ -88,13 +88,17 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
}
if ((int)vmodel.Status + 1 != (int)orderStatus)
{
- throw new ArgumentException($"Попытка перевести заказ не в следующий статус: " +
+ throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " +
$"Текущий статус: {vmodel.Status} \n" +
$"Планируемый статус: {orderStatus} \n" +
- $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}",
- nameof(vmodel));
+ $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}");
}
model.Status = orderStatus;
+ model.DateCreate = vmodel.DateCreate;
+ if (model.DateImplement == null)
+ model.DateImplement = vmodel.DateImplement;
+ if (vmodel.ImplementerId.HasValue)
+ model.ImplementerId = vmodel.ImplementerId;
model.ReinforcedId = vmodel.ReinforcedId;
model.Sum = vmodel.Sum;
model.Count = vmodel.Count;
@@ -105,5 +109,22 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic
}
return true;
}
+
+ public OrderViewModel? ReadElement(OrderSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
+ var element = _orderStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs
new file mode 100644
index 0000000..712941a
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogic/WorkModeling.cs
@@ -0,0 +1,143 @@
+using Microsoft.Extensions.Logging;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Enums;
+
+namespace PrecastConcretePlantBusinessLogic.BusinessLogic
+{
+ public class WorkModeling : IWorkProcess
+ {
+ private readonly ILogger _logger;
+
+ private readonly Random _rnd;
+
+ private IOrderLogic? _orderLogic;
+
+ public WorkModeling(ILogger logger)
+ {
+ _logger = logger;
+ _rnd = new Random(1000);
+ }
+
+ public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
+ {
+ _orderLogic = orderLogic;
+ var implementers = implementerLogic.ReadList(null);
+ if (implementers == null)
+ {
+ _logger.LogWarning("DoWork. Implementers is null");
+ return;
+ }
+ // Поскольку у нас могут быть заказы в работе мы не дожны заканчивать работы, если нет Принятых заказов
+ // Поэтому находим заказы в работе и продолжаем работу, если они есть
+ var orders = _orderLogic.ReadList(new OrderSearchModel { Statusses = new() { OrderStatus.Принят, OrderStatus.Выполняется } });
+ if (orders == null || orders.Count == 0)
+ {
+ _logger.LogWarning("DoWork. Orders is null or empty");
+ return;
+ }
+ _logger.LogDebug("DoWork for {Count} orders", orders.Count);
+ foreach (var implementer in implementers)
+ {
+ Task.Run(() => WorkerWorkAsync(implementer, orders));
+ }
+ }
+
+ ///
+ /// Иммитация работы исполнителя
+ ///
+ ///
+ ///
+ private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders)
+ {
+ if (_orderLogic == null || implementer == null)
+ {
+ return;
+ }
+ await RunOrderInWork(implementer, orders);
+
+ await Task.Run(() =>
+ {
+ foreach (var order in orders)
+ {
+ try
+ {
+ _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
+ // пытаемся назначить заказ на исполнителя
+ _orderLogic.TakeOrderInWork(new OrderBindingModel
+ {
+ Id = order.Id,
+ ImplementerId = implementer.Id
+ });
+ // делаем работу
+ Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
+ _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
+ _orderLogic.FinishOrder(new OrderBindingModel
+ {
+ Id = order.Id
+ });
+ // отдыхаем
+ Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
+ }
+ // кто-то мог уже перехватить заказ, игнорируем ошибку
+ catch (InvalidOperationException ex)
+ {
+ _logger.LogWarning(ex, "Error try get work");
+ }
+ // заканчиваем выполнение имитации в случае иной ошибки
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error while do work");
+ throw;
+ }
+ }
+ });
+ }
+
+ ///
+ /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
+ ///
+ ///
+ ///
+ private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders)
+ {
+ if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0)
+ {
+ return;
+ }
+ try
+ {
+ // Выбираем из всех заказов тот, который выполняется данным исполнителем
+ var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется));
+ if (runOrder == null)
+ {
+ return;
+ }
+
+ _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
+ // доделываем работу
+ Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
+ _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
+ _orderLogic.FinishOrder(new OrderBindingModel
+ {
+ Id = runOrder.Id
+ });
+ // отдыхаем
+ Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
+ }
+ // заказа может не быть, просто игнорируем ошибку
+ catch (InvalidOperationException ex)
+ {
+ _logger.LogWarning(ex, "Error try get work");
+ }
+ // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Error while do work");
+ throw;
+ }
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs
new file mode 100644
index 0000000..d882af8
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs
@@ -0,0 +1,17 @@
+using PrecastConcretePlantDataModels;
+
+namespace PrecastConcretePlantContracts.BindingModels
+{
+ public class ImplementerBindingModel : IImplementerModel
+ {
+ public int Id { get; set; }
+
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ public string Password { get; set; } = string.Empty;
+
+ public int WorkExperience { get; set; }
+
+ public int Qualification { get; set; }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs
index ed2ee53..b0e89b6 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs
@@ -8,6 +8,7 @@ namespace PrecastConcretePlantContracts.BindingModels
public int Id { get; set; }
public int ReinforcedId { get; set; }
public int ClientId { get; set; }
+ public int? ImplementerId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs
new file mode 100644
index 0000000..ca5cca0
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs
@@ -0,0 +1,19 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantContracts.BusinessLogicsContracts
+{
+ public interface IImplementerLogic
+ {
+ List? ReadList(ImplementerSearchModel? model);
+
+ ImplementerViewModel? ReadElement(ImplementerSearchModel model);
+
+ bool Create(ImplementerBindingModel model);
+
+ bool Update(ImplementerBindingModel model);
+
+ bool Delete(ImplementerBindingModel model);
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs
index 93ca57c..4e54a5e 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -7,6 +7,7 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts
public interface IOrderLogic
{
List? ReadList(OrderSearchModel? model);
+ OrderViewModel? ReadElement(OrderSearchModel model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs
new file mode 100644
index 0000000..57c9eef
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs
@@ -0,0 +1,10 @@
+namespace PrecastConcretePlantContracts.BusinessLogicsContracts
+{
+ public interface IWorkProcess
+ {
+ ///
+ /// Запуск работ
+ ///
+ void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs
new file mode 100644
index 0000000..a6f1cb9
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs
@@ -0,0 +1,11 @@
+namespace PrecastConcretePlantContracts.SearchModels
+{
+ public class ImplementerSearchModel
+ {
+ public int? Id { get; set; }
+
+ public string? ImplementerFIO { get; set; }
+
+ public string? Password { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs
index f0a18e3..c939776 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs
@@ -1,4 +1,6 @@
-namespace PrecastConcretePlantContracts.SearchModels
+using PrecastConcretePlantDataModels.Enums;
+
+namespace PrecastConcretePlantContracts.SearchModels
{
public class OrderSearchModel
{
@@ -6,5 +8,7 @@
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int? ClientId { get; set; }
+ public int? ImplementerId { get; set; }
+ public List? Statusses { get; set; }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IImplementerStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IImplementerStorage.cs
new file mode 100644
index 0000000..3606708
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IImplementerStorage.cs
@@ -0,0 +1,21 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantContracts.StoragesContract
+{
+ 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/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs
new file mode 100644
index 0000000..31e3dcd
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs
@@ -0,0 +1,22 @@
+using PrecastConcretePlantDataModels;
+using System.ComponentModel;
+
+namespace PrecastConcretePlantContracts.ViewModels
+{
+ public class ImplementerViewModel : IImplementerModel
+ {
+ public int Id { get; set; }
+
+ [DisplayName("ФИО исполнителя")]
+ public string ImplementerFIO { get; set; } = string.Empty;
+
+ [DisplayName("Пароль")]
+ public string Password { get; set; } = string.Empty;
+
+ [DisplayName("Стаж работы")]
+ public int WorkExperience { get; set; }
+
+ [DisplayName("Квалификация")]
+ public int Qualification { get; set; }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs
index 0aca3a4..665ffb4 100644
--- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs
@@ -10,6 +10,9 @@ namespace PrecastConcretePlantContracts.ViewModels
public int Id { get; set; }
public int ReinforcedId { get; set; }
public int ClientId { get; set; }
+ public int? ImplementerId { get; set; }
+ [DisplayName("Фамилия исполнителя")]
+ public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Фамилия клиента")]
public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Изделие")]
diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IImplementerModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IImplementerModel.cs
new file mode 100644
index 0000000..d17b6ae
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/IImplementerModel.cs
@@ -0,0 +1,10 @@
+namespace PrecastConcretePlantDataModels
+{
+ public interface IImplementerModel : IId
+ {
+ string ImplementerFIO { get; }
+ string Password { get; }
+ int WorkExperience { get; }
+ int Qualification { get; }
+ }
+}
\ No newline at end of file
diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IOrderModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IOrderModel.cs
index 09861bc..a330a3b 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDataModels/IOrderModel.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/IOrderModel.cs
@@ -5,6 +5,8 @@ namespace PrecastConcretePlantDataModels.Models
public interface IOrderModel : IId
{
int ReinforcedId { get; }
+ int ClientId { get; }
+ int? ImplementerId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implementer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implementer.cs
new file mode 100644
index 0000000..400b244
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implementer.cs
@@ -0,0 +1,62 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDatabaseImplement.Models;
+using PrecastConcretePlantDataModels;
+using System.ComponentModel.DataAnnotations.Schema;
+
+
+namespace PrecastConcretePlantDatabaseImplement
+{
+ 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; }
+
+ [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/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/ImplementerStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/ImplementerStorage.cs
new file mode 100644
index 0000000..cb0fdd1
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/ImplementerStorage.cs
@@ -0,0 +1,81 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantDatabaseImplement
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ context.Implementers.Remove(res);
+ context.SaveChanges();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ if (model.Id.HasValue)
+ return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ if (model.ImplementerFIO != null && model.Password != null)
+ return context.Implementers
+ .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
+ && x.Password.Equals(model.Password))
+ ?.GetViewModel;
+ if (model.ImplementerFIO != null)
+ return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
+ return null;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+ return res != null ? new() { res } : new();
+ }
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ return context.Implementers.Select(x => x.GetViewModel).ToList();
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ var res = Implementer.Create(model);
+ if (res != null)
+ {
+ context.Implementers.Add(res);
+ context.SaveChanges();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ using var context = new PrecastConcretePlantDatabase();
+ var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ res.Update(model);
+ context.SaveChanges();
+ }
+ return res?.GetViewModel;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230410162237_add_implementer.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230410162237_add_implementer.Designer.cs
new file mode 100644
index 0000000..b991c82
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230410162237_add_implementer.Designer.cs
@@ -0,0 +1,257 @@
+//
+using System;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using PrecastConcretePlantDatabaseImplement;
+
+#nullable disable
+
+namespace PrecastConcretePlantDatabaseImplement.Migrations
+{
+ [DbContext(typeof(PrecastConcretePlantDatabase))]
+ [Migration("20230410162237_add_implementer")]
+ partial class add_implementer
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.3")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Email")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Qualification")
+ .HasColumnType("int");
+
+ b.Property("WorkExperience")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.ToTable("Components");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("DateCreate")
+ .HasColumnType("datetime2");
+
+ b.Property("DateImplement")
+ .HasColumnType("datetime2");
+
+ b.Property("ImplementerId")
+ .HasColumnType("int");
+
+ b.Property("ReinforcedId")
+ .HasColumnType("int");
+
+ b.Property("Status")
+ .HasColumnType("int");
+
+ b.Property("Sum")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("ImplementerId");
+
+ b.HasIndex("ReinforcedId");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Price")
+ .HasColumnType("float");
+
+ b.Property("ReinforcedName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Reinforceds");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComponentId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("ReinforcedId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComponentId");
+
+ b.HasIndex("ReinforcedId");
+
+ b.ToTable("ReinforcedComponents");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
+ {
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Client", "Client")
+ .WithMany("Orders")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
+ .WithMany("Orders")
+ .HasForeignKey("ReinforcedId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Client");
+
+ b.Navigation("Implementer");
+
+ b.Navigation("Reinforced");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
+ {
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component")
+ .WithMany("ReinforcedComponents")
+ .HasForeignKey("ComponentId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinfordced")
+ .WithMany("Components")
+ .HasForeignKey("ReinforcedId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Component");
+
+ b.Navigation("Reinfordced");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Client", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
+ {
+ b.Navigation("ReinforcedComponents");
+ });
+
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
+ {
+ b.Navigation("Components");
+
+ b.Navigation("Orders");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230410162237_add_implementer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230410162237_add_implementer.cs
new file mode 100644
index 0000000..a2be1fb
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20230410162237_add_implementer.cs
@@ -0,0 +1,67 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace PrecastConcretePlantDatabaseImplement.Migrations
+{
+ ///
+ public partial class add_implementer : 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/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs
index 812d817..ad1f97a 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDatabaseModelSnapshot.cs
@@ -47,6 +47,33 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.ToTable("Clients");
});
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Qualification")
+ .HasColumnType("int");
+
+ b.Property("WorkExperience")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Property("Id")
@@ -87,6 +114,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("datetime2");
+ b.Property("ImplementerId")
+ .HasColumnType("int");
+
b.Property("ReinforcedId")
.HasColumnType("int");
@@ -100,6 +130,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.HasIndex("ReinforcedId");
b.ToTable("Orders");
@@ -159,6 +191,10 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("PrecastConcretePlantDatabaseImplement.Implementer", "Implementer")
+ .WithMany("Orders")
+ .HasForeignKey("ImplementerId");
+
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
.WithMany("Orders")
.HasForeignKey("ReinforcedId")
@@ -167,6 +203,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Navigation("Client");
+ b.Navigation("Implementer");
+
b.Navigation("Reinforced");
});
@@ -194,6 +232,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
b.Navigation("Orders");
});
+ modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Implementer", b =>
+ {
+ b.Navigation("Orders");
+ });
+
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
{
b.Navigation("ReinforcedComponents");
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs
index fe55eb6..6f7d406 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Order.cs
@@ -1,10 +1,8 @@
-using Microsoft.EntityFrameworkCore;
-using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BindingModels;
using PrecastConcretePlantContracts.ViewModels;
using PrecastConcretePlantDataModels.Enums;
using PrecastConcretePlantDataModels.Models;
using System.ComponentModel.DataAnnotations;
-using System.Reflection;
namespace PrecastConcretePlantDatabaseImplement.Models
@@ -20,6 +18,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models
public int ClientId { get; private set; }
+ public int? ImplementerId { get; private set; }
+
[Required]
public int Count { get; private set; }
@@ -38,6 +38,8 @@ namespace PrecastConcretePlantDatabaseImplement.Models
public Client Client { get; private set; }
+ public Implementer? Implementer { get; private set; }
+
public static Order? Create(OrderBindingModel? model)
{
@@ -53,6 +55,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
+ ImplementerId = model.ImplementerId,
DateImplement = model.DateImplement,
Id = model.Id,
};
@@ -70,6 +73,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
+ ImplementerId = model.ImplementerId;
Id = model.Id;
}
public OrderViewModel GetViewModel
@@ -88,6 +92,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
+ ImplementerId = ImplementerId,
Id = Id,
};
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/OrderStorage.cs
index 3bb23ab..4e0e666 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/OrderStorage.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/OrderStorage.cs
@@ -13,36 +13,50 @@ namespace PrecastConcretePlantDatabaseImplement
public OrderViewModel? GetElement(OrderSearchModel model)
{
using var context = new PrecastConcretePlantDatabase();
- if (!model.Id.HasValue)
- {
- return null;
- }
- return context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
+ return context.Orders
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x =>
+ (model.Statusses == null || model.Statusses != null && model.Statusses.Contains(x.Status)) &&
+ model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId ||
+ model.Id.HasValue && x.Id == model.Id
+ )
+ ?.GetViewModel;
}
public List GetFilteredList(OrderSearchModel model)
{
+ if (model.Id.HasValue)
+ {
+ var result = GetElement(model);
+ return result != null ? new() { result } : new();
+ }
using var context = new PrecastConcretePlantDatabase();
- if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
+ IQueryable? queryWhere = null;
+
+ if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
- return context.Orders
- .Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
+ queryWhere = context.Orders
+ .Where(x => model.DateFrom <= x.DateCreate.Date &&
+ x.DateCreate.Date <= model.DateTo);
+ }
+ else if (model.Statusses != null)
+ {
+ queryWhere = context.Orders.Where(x => model.Statusses.Contains(x.Status));
+ }
+ else if (model.ClientId.HasValue)
+ {
+ queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId);
+ }
+ else
+ {
+ return new();
+ }
+ return queryWhere
.Include(x => x.Client)
- .Include(x => x.Reinforced)
+ .Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
- }
- if (model.ClientId.HasValue)
- {
- return context.Orders
- .Where(x => x.Client.Id == model.ClientId)
- .Include(x => x.Client)
- .Include(x => x.Reinforced)
- .Select(x => x.GetViewModel)
- .ToList();
- }
- var result = GetElement(model);
- return result != null ? new() { result } : new();
}
public List GetFullList()
@@ -51,6 +65,7 @@ namespace PrecastConcretePlantDatabaseImplement
return context.Orders
.Include(x => x.Reinforced)
.Include(x => x.Client)
+ .Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
}
@@ -71,7 +86,11 @@ namespace PrecastConcretePlantDatabaseImplement
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
- var order = context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => x.Id == model.Id);
+ var order = context.Orders
+ .Include(x => x.Reinforced)
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
@@ -84,7 +103,10 @@ namespace PrecastConcretePlantDatabaseImplement
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new PrecastConcretePlantDatabase();
- var element = context.Orders.Include(x => x.Reinforced).FirstOrDefault(x => x.Id == model.Id);
+ var element = context.Orders
+ .Include(x => x.Client)
+ .Include(x => x.Implementer)
+ .FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs
index f3e9bea..87edd3d 100644
--- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabase.cs
@@ -24,5 +24,6 @@ namespace PrecastConcretePlantDatabaseImplement
public virtual DbSet ReinforcedComponents { set; get; }
public virtual DbSet Orders { set; get; }
public virtual DbSet Clients { set; get; }
+ public virtual DbSet Implementers { set; get; }
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs
index d539b03..4b5dab1 100644
--- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs
@@ -10,10 +10,13 @@ namespace PrecastConcretePlantFileImplement
private readonly string OrderFileName = "Order.xml";
private readonly string ReinforcedFileName = "Reinforced.xml";
private readonly string ClientFileName = "Client.xml";
+ private readonly string ImplementerFileName = "Implementer.xml";
+
public List Components { get; set; }
public List Orders { get; set; }
public List Reinforceds { get; set; }
public List Clients { get; private set; }
+ public List Implementers { get; private set; }
public static DataFileSingleton GetInstance()
{
@@ -27,6 +30,7 @@ namespace PrecastConcretePlantFileImplement
public void SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
+ public void SaveImplementers() => SaveData(Orders, ImplementerFileName, "Implementers", x => x.GetXElement);
private DataFileSingleton()
{
@@ -34,6 +38,7 @@ namespace PrecastConcretePlantFileImplement
Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
+ Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
}
private static List? LoadData(string filename, string xmlNodeName, Func selectFunction)
{
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implementer.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implementer.cs
new file mode 100644
index 0000000..f3a906f
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implementer.cs
@@ -0,0 +1,82 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels;
+using System.Xml.Linq;
+
+namespace PrecastConcretePlantFileImplement
+{
+ 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/PrecastConcretePlant/PrecastConcretePlantFileImplement/ImplementerStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ImplementerStorage.cs
new file mode 100644
index 0000000..7790281
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ImplementerStorage.cs
@@ -0,0 +1,83 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantFileImplement
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataFileSingleton _source;
+ public ImplementerStorage()
+ {
+ _source = DataFileSingleton.GetInstance();
+ }
+
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ _source.Implementers.Remove(res);
+ _source.SaveImplementers();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ if (model.Id.HasValue)
+ return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
+ if (model.ImplementerFIO != null && model.Password != null)
+ return _source.Implementers
+ .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
+ && x.Password.Equals(model.Password))
+ ?.GetViewModel;
+ if (model.ImplementerFIO != null)
+ return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
+ return null;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+ return res != null ? new() { res } : new();
+ }
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ return _source.Implementers.Select(x => x.GetViewModel).ToList();
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
+ var res = Implementer.Create(model);
+ if (res != null)
+ {
+ _source.Implementers.Add(res);
+ _source.SaveImplementers();
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (res != null)
+ {
+ res.Update(model);
+ _source.SaveImplementers();
+ }
+ return res?.GetViewModel;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs
index d49b807..022ed61 100644
--- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs
@@ -15,6 +15,8 @@ namespace PrecastConcretePlantFileImplement.Models
public int ClientId { get; set; }
+ public int? ImplementerId { get; set; }
+
public int Count { get; private set; }
public double Sum { get; private set; }
@@ -40,6 +42,7 @@ namespace PrecastConcretePlantFileImplement.Models
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
+ ImplementerId = model.ImplementerId,
Id = model.Id,
};
}
@@ -59,6 +62,7 @@ namespace PrecastConcretePlantFileImplement.Models
ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
+ ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement),
};
}
@@ -74,12 +78,14 @@ namespace PrecastConcretePlantFileImplement.Models
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
+ ImplementerId = model.ImplementerId;
Id = model.Id;
}
public OrderViewModel GetViewModel => new()
{
ReinforcedId = ReinforcedId,
- ReinforcedName= DataFileSingleton.GetInstance().Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
+ ImplementerFIO = DataFileSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty,
+ ReinforcedName = DataFileSingleton.GetInstance().Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty,
ClientFIO = DataFileSingleton.GetInstance().Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
ClientId = ClientId,
Count = Count,
@@ -97,7 +103,8 @@ namespace PrecastConcretePlantFileImplement.Models
new XElement("Sum", Sum.ToString()),
new XElement("Status", (int)Status),
new XElement("DateCreate", DateCreate),
- new XElement("DateImplement", DateImplement)
+ new XElement("DateImplement", DateImplement),
+ new XElement("ImplementerId", ImplementerId)
);
}
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/ClientStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/ClientStorage.cs
index 5cf0c4c..247c157 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/ClientStorage.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/ClientStorage.cs
@@ -2,11 +2,6 @@
using PrecastConcretePlantContracts.SearchModels;
using PrecastConcretePlantContracts.StoragesContract;
using PrecastConcretePlantContracts.ViewModels;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace PrecastConcretePlantListImplement
{
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
index d97f79f..e3b91b3 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs
@@ -9,12 +9,14 @@ namespace PrecastConcretePlantListImplement
public List Orders { get; set; }
public List Reinforced { get; set; }
public List Clients { get; set; }
+ public List Implementers { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Reinforced = new List();
Clients = new List();
+ Implementers = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implementer.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implementer.cs
new file mode 100644
index 0000000..15e16a7
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implementer.cs
@@ -0,0 +1,55 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels;
+
+namespace PrecastConcretePlantListImplement
+{
+ public class Implementer : IImplementerModel
+ {
+ public int Id { get; private set; }
+
+ public string ImplementerFIO { get; private set; } = string.Empty;
+
+ public string Password { get; private set; } = string.Empty;
+
+ public int WorkExperience { get; private set; }
+
+ public int Qualification { get; private set; }
+
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Password = model.Password,
+ Qualification = model.Qualification,
+ ImplementerFIO = model.ImplementerFIO,
+ WorkExperience = model.WorkExperience,
+ };
+ }
+
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Password = model.Password;
+ Qualification = model.Qualification;
+ ImplementerFIO = model.ImplementerFIO;
+ WorkExperience = model.WorkExperience;
+ }
+
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Password = Password,
+ Qualification = Qualification,
+ ImplementerFIO = ImplementerFIO,
+ };
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/ImplementerStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/ImplementerStorage.cs
new file mode 100644
index 0000000..51446c1
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/ImplementerStorage.cs
@@ -0,0 +1,111 @@
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.StoragesContract;
+using PrecastConcretePlantContracts.ViewModels;
+
+namespace PrecastConcretePlantListImplement
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataListSingleton _source;
+ public ImplementerStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ for (int i = 0; i < _source.Implementers.Count; ++i)
+ {
+ if (_source.Implementers[i].Id == model.Id)
+ {
+ var element = _source.Implementers[i];
+ _source.Implementers.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ foreach (var x in _source.Implementers)
+ {
+ if (model.Id.HasValue && x.Id == model.Id)
+ return x.GetViewModel;
+ if (model.ImplementerFIO != null && model.Password != null &&
+ x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))
+ return x.GetViewModel;
+ if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
+ return x.GetViewModel;
+ }
+ return null;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+ return res != null ? new() { res } : new();
+ }
+ List result = new();
+ if (model.ImplementerFIO != null)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
+ {
+ result.Add(implementer.GetViewModel);
+ }
+ }
+ }
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var implementer in _source.Implementers)
+ {
+ result.Add(implementer.GetViewModel);
+ }
+ return result;
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var implementer in _source.Implementers)
+ {
+ if (model.Id <= implementer.Id)
+ {
+ model.Id = implementer.Id + 1;
+ }
+ }
+ var res = Implementer.Create(model);
+ if (res != null)
+ {
+ _source.Implementers.Add(res);
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.Id == model.Id)
+ {
+ implementer.Update(model);
+ return implementer.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Order.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Order.cs
index ced16ad..517a6bf 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Order.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Order.cs
@@ -14,6 +14,8 @@ namespace PrecastConcretePlantListImplement.Models
public int ClientId { get; private set; }
+ public int? ImplementerId { get; private set; }
+
public int Count { get; private set; }
public double Sum { get; private set; }
@@ -39,6 +41,7 @@ namespace PrecastConcretePlantListImplement.Models
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
+ ImplementerId = model.ImplementerId,
Id = model.Id,
};
}
@@ -54,12 +57,14 @@ namespace PrecastConcretePlantListImplement.Models
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
+ ImplementerId = model.ImplementerId;
Id = model.Id;
}
public OrderViewModel GetViewModel => new()
{
ReinforcedId = ReinforcedId,
ClientId = ClientId,
+ ImplementerId = ImplementerId,
Count = Count,
Sum = Sum,
Status = Status,
diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
index 57c4ed2..281e926 100644
--- a/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/OrderStorage.cs
@@ -38,6 +38,15 @@ namespace PrecastConcretePlantListImplement
{
return GetViewModel(order);
}
+ else if (model.ImplementerId.HasValue && model.Statusses != null &&
+ order.ImplementerId == model.ImplementerId && model.Statusses.Contains(order.Status))
+ {
+ return GetViewModel(order);
+ }
+ else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId)
+ {
+ return GetViewModel(order);
+ }
}
return null;
}
@@ -60,6 +69,14 @@ namespace PrecastConcretePlantListImplement
{
result.Add(GetViewModel(order));
}
+ else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId)
+ {
+ result.Add(GetViewModel(order));
+ }
+ else if (model.Statusses != null && model.Statusses.Contains(order.Status))
+ {
+ result.Add(GetViewModel(order));
+ }
}
return result;
}
diff --git a/PrecastConcretePlant/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs b/PrecastConcretePlant/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs
new file mode 100644
index 0000000..a49aa8c
--- /dev/null
+++ b/PrecastConcretePlant/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs
@@ -0,0 +1,107 @@
+using Microsoft.AspNetCore.Mvc;
+using PrecastConcretePlantContracts.BindingModels;
+using PrecastConcretePlantContracts.BusinessLogicsContracts;
+using PrecastConcretePlantContracts.SearchModels;
+using PrecastConcretePlantContracts.ViewModels;
+using PrecastConcretePlantDataModels.Enums;
+
+namespace PrecastConcretePlantRestApi.Controllers
+{
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class ImplementerController : Controller
+ {
+ private readonly ILogger _logger;
+
+ private readonly IOrderLogic _order;
+
+ private readonly IImplementerLogic _logic;
+
+ public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger)
+ {
+ _logger = logger;
+ _order = order;
+ _logic = logic;
+ }
+
+ [HttpGet]
+ public ImplementerViewModel? Login(string login, string password)
+ {
+ try
+ {
+ return _logic.ReadElement(new ImplementerSearchModel
+ {
+ ImplementerFIO = login,
+ Password = password
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка авторизации сотрудника");
+ throw;
+ }
+ }
+
+ [HttpGet]
+ public List? GetNewOrders()
+ {
+ try
+ {
+ return _order.ReadList(new OrderSearchModel
+ {
+ Statusses = new() { OrderStatus.Принят }
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения новых заказов");
+ throw;
+ }
+ }
+
+ [HttpGet]
+ public OrderViewModel? GetImplementerOrder(int implementerId)
+ {
+ try
+ {
+ return _order.ReadElement(new OrderSearchModel
+ {
+ ImplementerId = implementerId
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
+ throw;
+ }
+ }
+
+ [HttpPost]
+ public void TakeOrderInWork(OrderBindingModel model)
+ {
+ try
+ {
+ _order.TakeOrderInWork(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id);
+ throw;
+ }
+ }
+
+ [HttpPost]
+ public void FinishOrder(OrderBindingModel model)
+ {
+ try
+ {
+ _order.FinishOrder(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id);
+ throw;
+ }
+ }
+ }
+}
diff --git a/PrecastConcretePlant/PrecastConcretePlantRestApi/Program.cs b/PrecastConcretePlant/PrecastConcretePlantRestApi/Program.cs
index 06c3613..02d5d5c 100644
--- a/PrecastConcretePlant/PrecastConcretePlantRestApi/Program.cs
+++ b/PrecastConcretePlant/PrecastConcretePlantRestApi/Program.cs
@@ -12,9 +12,11 @@ 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.AddTransient();
builder.Services.AddControllers();