all done
This commit is contained in:
parent
4f3e16d4f5
commit
aa0971caf0
177
FurnitureAssembly/FurnitureAssembly/ImplementerForm.Designer.cs
generated
Normal file
177
FurnitureAssembly/FurnitureAssembly/ImplementerForm.Designer.cs
generated
Normal file
@ -0,0 +1,177 @@
|
||||
namespace FurnitureAssemblyView
|
||||
{
|
||||
partial class ImplementerForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.numericUpDownQual = new System.Windows.Forms.NumericUpDown();
|
||||
this.numericUpDownWE = new System.Windows.Forms.NumericUpDown();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.textBoxPassword = new System.Windows.Forms.TextBox();
|
||||
this.textBoxFIO = new System.Windows.Forms.TextBox();
|
||||
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||
this.ButtonSave = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQual)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWE)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// numericUpDownQual
|
||||
//
|
||||
this.numericUpDownQual.Location = new System.Drawing.Point(269, 258);
|
||||
this.numericUpDownQual.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.numericUpDownQual.Name = "numericUpDownQual";
|
||||
this.numericUpDownQual.Size = new System.Drawing.Size(171, 31);
|
||||
this.numericUpDownQual.TabIndex = 27;
|
||||
//
|
||||
// numericUpDownWE
|
||||
//
|
||||
this.numericUpDownWE.Location = new System.Drawing.Point(269, 187);
|
||||
this.numericUpDownWE.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.numericUpDownWE.Name = "numericUpDownWE";
|
||||
this.numericUpDownWE.Size = new System.Drawing.Size(171, 31);
|
||||
this.numericUpDownWE.TabIndex = 26;
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(129, 262);
|
||||
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(130, 25);
|
||||
this.label3.TabIndex = 25;
|
||||
this.label3.Text = "Квалификация";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(129, 190);
|
||||
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(118, 25);
|
||||
this.label2.TabIndex = 24;
|
||||
this.label2.Text = "Стаж работы";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(129, 123);
|
||||
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(74, 25);
|
||||
this.label1.TabIndex = 23;
|
||||
this.label1.Text = "Пароль";
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(129, 55);
|
||||
this.labelName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(52, 25);
|
||||
this.labelName.TabIndex = 22;
|
||||
this.labelName.Text = "ФИО";
|
||||
//
|
||||
// textBoxPassword
|
||||
//
|
||||
this.textBoxPassword.Location = new System.Drawing.Point(269, 118);
|
||||
this.textBoxPassword.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.textBoxPassword.Name = "textBoxPassword";
|
||||
this.textBoxPassword.Size = new System.Drawing.Size(400, 31);
|
||||
this.textBoxPassword.TabIndex = 21;
|
||||
//
|
||||
// textBoxFIO
|
||||
//
|
||||
this.textBoxFIO.Location = new System.Drawing.Point(269, 50);
|
||||
this.textBoxFIO.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.textBoxFIO.Name = "textBoxFIO";
|
||||
this.textBoxFIO.Size = new System.Drawing.Size(400, 31);
|
||||
this.textBoxFIO.TabIndex = 20;
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
this.ButtonCancel.Location = new System.Drawing.Point(564, 363);
|
||||
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.ButtonCancel.Name = "ButtonCancel";
|
||||
this.ButtonCancel.Size = new System.Drawing.Size(107, 38);
|
||||
this.ButtonCancel.TabIndex = 19;
|
||||
this.ButtonCancel.Text = "Отмена";
|
||||
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// ButtonSave
|
||||
//
|
||||
this.ButtonSave.Location = new System.Drawing.Point(415, 363);
|
||||
this.ButtonSave.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.ButtonSave.Name = "ButtonSave";
|
||||
this.ButtonSave.Size = new System.Drawing.Size(107, 38);
|
||||
this.ButtonSave.TabIndex = 18;
|
||||
this.ButtonSave.Text = "Сохранить";
|
||||
this.ButtonSave.UseVisualStyleBackColor = true;
|
||||
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// ImplementerForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.numericUpDownQual);
|
||||
this.Controls.Add(this.numericUpDownWE);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Controls.Add(this.textBoxPassword);
|
||||
this.Controls.Add(this.textBoxFIO);
|
||||
this.Controls.Add(this.ButtonCancel);
|
||||
this.Controls.Add(this.ButtonSave);
|
||||
this.Name = "ImplementerForm";
|
||||
this.Text = "Исполнитель";
|
||||
this.Load += new System.EventHandler(this.ImplementerForm_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQual)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWE)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private NumericUpDown numericUpDownQual;
|
||||
private NumericUpDown numericUpDownWE;
|
||||
private Label label3;
|
||||
private Label label2;
|
||||
private Label label1;
|
||||
private Label labelName;
|
||||
private TextBox textBoxPassword;
|
||||
private TextBox textBoxFIO;
|
||||
private Button ButtonCancel;
|
||||
private Button ButtonSave;
|
||||
}
|
||||
}
|
109
FurnitureAssembly/FurnitureAssembly/ImplementerForm.cs
Normal file
109
FurnitureAssembly/FurnitureAssembly/ImplementerForm.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FurnitureAssemblyView
|
||||
{
|
||||
public partial class ImplementerForm : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerLogic _logic;
|
||||
private int? _id;
|
||||
public int Id { set { _id = value; } }
|
||||
public ImplementerForm(ILogger<ImplementerForm> logger, IImplementerLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void ImplementerForm_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;
|
||||
numericUpDownWE.Value = view.WorkExperience;
|
||||
numericUpDownQual.Value = view.Qualification;
|
||||
}
|
||||
}
|
||||
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(textBoxFIO.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните ФИО", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxPassword.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните пароль", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение исполнителя");
|
||||
try
|
||||
{
|
||||
var model = new ImplementerBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ImplementerFIO = textBoxFIO.Text,
|
||||
Password = textBoxPassword.Text,
|
||||
WorkExperience = Convert.ToInt32(numericUpDownWE.Value),
|
||||
Qualification = Convert.ToInt32(numericUpDownQual.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();
|
||||
}
|
||||
}
|
||||
}
|
60
FurnitureAssembly/FurnitureAssembly/ImplementerForm.resx
Normal file
60
FurnitureAssembly/FurnitureAssembly/ImplementerForm.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
120
FurnitureAssembly/FurnitureAssembly/ImplementersForm.Designer.cs
generated
Normal file
120
FurnitureAssembly/FurnitureAssembly/ImplementersForm.Designer.cs
generated
Normal file
@ -0,0 +1,120 @@
|
||||
namespace FurnitureAssemblyView
|
||||
{
|
||||
partial class ImplementersForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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.Location = new System.Drawing.Point(749, 309);
|
||||
this.ButtonRef.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.ButtonRef.Name = "ButtonRef";
|
||||
this.ButtonRef.Size = new System.Drawing.Size(150, 48);
|
||||
this.ButtonRef.TabIndex = 16;
|
||||
this.ButtonRef.Text = "Обновить";
|
||||
this.ButtonRef.UseVisualStyleBackColor = true;
|
||||
this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||
//
|
||||
// ButtonDel
|
||||
//
|
||||
this.ButtonDel.Location = new System.Drawing.Point(749, 212);
|
||||
this.ButtonDel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.ButtonDel.Name = "ButtonDel";
|
||||
this.ButtonDel.Size = new System.Drawing.Size(150, 48);
|
||||
this.ButtonDel.TabIndex = 15;
|
||||
this.ButtonDel.Text = "Удалить";
|
||||
this.ButtonDel.UseVisualStyleBackColor = true;
|
||||
this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||
//
|
||||
// ButtonUpd
|
||||
//
|
||||
this.ButtonUpd.Location = new System.Drawing.Point(749, 117);
|
||||
this.ButtonUpd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.ButtonUpd.Name = "ButtonUpd";
|
||||
this.ButtonUpd.Size = new System.Drawing.Size(150, 48);
|
||||
this.ButtonUpd.TabIndex = 14;
|
||||
this.ButtonUpd.Text = "Изменить";
|
||||
this.ButtonUpd.UseVisualStyleBackColor = true;
|
||||
this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||
//
|
||||
// ButtonAdd
|
||||
//
|
||||
this.ButtonAdd.Location = new System.Drawing.Point(749, 24);
|
||||
this.ButtonAdd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.ButtonAdd.Name = "ButtonAdd";
|
||||
this.ButtonAdd.Size = new System.Drawing.Size(150, 48);
|
||||
this.ButtonAdd.TabIndex = 13;
|
||||
this.ButtonAdd.Text = "Добавить";
|
||||
this.ButtonAdd.UseVisualStyleBackColor = true;
|
||||
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(13, 14);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(707, 540);
|
||||
this.dataGridView.TabIndex = 12;
|
||||
//
|
||||
// ImplementersForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(992, 568);
|
||||
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 = "ImplementersForm";
|
||||
this.Text = "Исполнители";
|
||||
this.Load += new System.EventHandler(this.ImplementersForm_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;
|
||||
}
|
||||
}
|
120
FurnitureAssembly/FurnitureAssembly/ImplementersForm.cs
Normal file
120
FurnitureAssembly/FurnitureAssembly/ImplementersForm.cs
Normal file
@ -0,0 +1,120 @@
|
||||
using FurnitureAssembly;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FurnitureAssemblyView
|
||||
{
|
||||
public partial class ImplementersForm : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerLogic _logic;
|
||||
public ImplementersForm(ILogger<ImplementersForm> logger, IImplementerLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void ImplementersForm_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(ImplementerForm));
|
||||
if (service is ImplementerForm 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(ImplementerForm));
|
||||
if (service is ImplementerForm 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();
|
||||
}
|
||||
}
|
||||
}
|
60
FurnitureAssembly/FurnitureAssembly/ImplementersForm.resx
Normal file
60
FurnitureAssembly/FurnitureAssembly/ImplementersForm.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -38,11 +38,13 @@
|
||||
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.FurnituresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.FurnituresComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
buttonReady = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
@ -50,9 +52,10 @@
|
||||
//
|
||||
// buttonReady
|
||||
//
|
||||
buttonReady.Location = new System.Drawing.Point(1273, 225);
|
||||
buttonReady.Location = new System.Drawing.Point(1011, 135);
|
||||
buttonReady.Margin = new System.Windows.Forms.Padding(2);
|
||||
buttonReady.Name = "buttonReady";
|
||||
buttonReady.Size = new System.Drawing.Size(215, 34);
|
||||
buttonReady.Size = new System.Drawing.Size(150, 20);
|
||||
buttonReady.TabIndex = 3;
|
||||
buttonReady.Text = "Заказ готов";
|
||||
buttonReady.UseVisualStyleBackColor = true;
|
||||
@ -61,18 +64,20 @@
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Location = new System.Drawing.Point(9, 52);
|
||||
this.dataGridView.Location = new System.Drawing.Point(6, 31);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 62;
|
||||
this.dataGridView.RowTemplate.Height = 33;
|
||||
this.dataGridView.Size = new System.Drawing.Size(1227, 386);
|
||||
this.dataGridView.Size = new System.Drawing.Size(973, 449);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Location = new System.Drawing.Point(1273, 52);
|
||||
this.buttonCreate.Location = new System.Drawing.Point(1011, 31);
|
||||
this.buttonCreate.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(215, 34);
|
||||
this.buttonCreate.Size = new System.Drawing.Size(150, 20);
|
||||
this.buttonCreate.TabIndex = 1;
|
||||
this.buttonCreate.Text = "Создать заказ";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
@ -80,9 +85,10 @@
|
||||
//
|
||||
// buttonToWork
|
||||
//
|
||||
this.buttonToWork.Location = new System.Drawing.Point(1273, 137);
|
||||
this.buttonToWork.Location = new System.Drawing.Point(1011, 82);
|
||||
this.buttonToWork.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonToWork.Name = "buttonToWork";
|
||||
this.buttonToWork.Size = new System.Drawing.Size(215, 34);
|
||||
this.buttonToWork.Size = new System.Drawing.Size(150, 20);
|
||||
this.buttonToWork.TabIndex = 2;
|
||||
this.buttonToWork.Text = "Отдать на выполнение";
|
||||
this.buttonToWork.UseVisualStyleBackColor = true;
|
||||
@ -90,9 +96,10 @@
|
||||
//
|
||||
// buttonPut
|
||||
//
|
||||
this.buttonPut.Location = new System.Drawing.Point(1273, 308);
|
||||
this.buttonPut.Location = new System.Drawing.Point(1011, 185);
|
||||
this.buttonPut.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonPut.Name = "buttonPut";
|
||||
this.buttonPut.Size = new System.Drawing.Size(215, 34);
|
||||
this.buttonPut.Size = new System.Drawing.Size(150, 20);
|
||||
this.buttonPut.TabIndex = 4;
|
||||
this.buttonPut.Text = "Заказ выдан";
|
||||
this.buttonPut.UseVisualStyleBackColor = true;
|
||||
@ -100,9 +107,10 @@
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
this.buttonRefresh.Location = new System.Drawing.Point(1273, 389);
|
||||
this.buttonRefresh.Location = new System.Drawing.Point(1011, 233);
|
||||
this.buttonRefresh.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.buttonRefresh.Name = "buttonRefresh";
|
||||
this.buttonRefresh.Size = new System.Drawing.Size(215, 34);
|
||||
this.buttonRefresh.Size = new System.Drawing.Size(150, 20);
|
||||
this.buttonRefresh.TabIndex = 5;
|
||||
this.buttonRefresh.Text = "Обновить список";
|
||||
this.buttonRefresh.UseVisualStyleBackColor = true;
|
||||
@ -113,10 +121,12 @@
|
||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.справочникиToolStripMenuItem,
|
||||
this.отчетыToolStripMenuItem});
|
||||
this.отчетыToolStripMenuItem,
|
||||
this.запускРаботToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(1530, 33);
|
||||
this.menuStrip.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1);
|
||||
this.menuStrip.Size = new System.Drawing.Size(1193, 24);
|
||||
this.menuStrip.TabIndex = 6;
|
||||
this.menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@ -125,25 +135,40 @@
|
||||
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.компонентыToolStripMenuItem,
|
||||
this.изделияToolStripMenuItem,
|
||||
this.клиентыToolStripMenuItem});
|
||||
this.клиентыToolStripMenuItem,
|
||||
this.исполнителиToolStripMenuItem});
|
||||
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
|
||||
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 22);
|
||||
this.справочникиToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// компонентыToolStripMenuItem
|
||||
//
|
||||
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
|
||||
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
|
||||
this.компонентыToolStripMenuItem.Text = "Компоненты";
|
||||
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click);
|
||||
//
|
||||
// изделияToolStripMenuItem
|
||||
//
|
||||
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
|
||||
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
|
||||
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
|
||||
this.изделияToolStripMenuItem.Text = "Изделия";
|
||||
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.изделияToolStripMenuItem_Click);
|
||||
//
|
||||
// клиентыToolStripMenuItem
|
||||
//
|
||||
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
|
||||
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
|
||||
this.клиентыToolStripMenuItem.Text = "Клиенты";
|
||||
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
|
||||
//
|
||||
// исполнителиToolStripMenuItem
|
||||
//
|
||||
this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem";
|
||||
this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
|
||||
this.исполнителиToolStripMenuItem.Text = "Исполнители";
|
||||
this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
|
||||
//
|
||||
// отчетыToolStripMenuItem
|
||||
//
|
||||
this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
@ -151,42 +176,42 @@
|
||||
this.FurnituresComponentsToolStripMenuItem,
|
||||
this.списокЗаказовToolStripMenuItem});
|
||||
this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem";
|
||||
this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29);
|
||||
this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(60, 22);
|
||||
this.отчетыToolStripMenuItem.Text = "Отчеты";
|
||||
//
|
||||
// FurnituresToolStripMenuItem
|
||||
//
|
||||
this.FurnituresToolStripMenuItem.Name = "FurnituresToolStripMenuItem";
|
||||
this.FurnituresToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
|
||||
this.FurnituresToolStripMenuItem.Size = new System.Drawing.Size(216, 22);
|
||||
this.FurnituresToolStripMenuItem.Text = "Список изделий";
|
||||
this.FurnituresToolStripMenuItem.Click += new System.EventHandler(this.FurnituresToolStripMenuItem_Click);
|
||||
//
|
||||
// FurnituresComponentsToolStripMenuItem
|
||||
//
|
||||
this.FurnituresComponentsToolStripMenuItem.Name = "FurnituresComponentsToolStripMenuItem";
|
||||
this.FurnituresComponentsToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
|
||||
this.FurnituresComponentsToolStripMenuItem.Size = new System.Drawing.Size(216, 22);
|
||||
this.FurnituresComponentsToolStripMenuItem.Text = "Изделия по компонентам";
|
||||
this.FurnituresComponentsToolStripMenuItem.Click += new System.EventHandler(this.FurnituresComponentsToolStripMenuItem_Click);
|
||||
//
|
||||
// списокЗаказовToolStripMenuItem
|
||||
//
|
||||
this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
|
||||
this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(325, 34);
|
||||
this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(216, 22);
|
||||
this.списокЗаказовToolStripMenuItem.Text = "Список заказов";
|
||||
this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
|
||||
//
|
||||
// клиентыToolStripMenuItem
|
||||
// запускРаботToolStripMenuItem
|
||||
//
|
||||
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
|
||||
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
|
||||
this.клиентыToolStripMenuItem.Text = "Клиенты";
|
||||
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
|
||||
this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
|
||||
this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(95, 22);
|
||||
this.запускРаботToolStripMenuItem.Text = " Запуск работ";
|
||||
this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.doWorkToolStripMenuItem_Click);
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1530, 450);
|
||||
this.ClientSize = new System.Drawing.Size(1193, 491);
|
||||
this.Controls.Add(this.buttonRefresh);
|
||||
this.Controls.Add(this.buttonPut);
|
||||
this.Controls.Add(buttonReady);
|
||||
@ -195,6 +220,7 @@
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "MainForm";
|
||||
this.Text = "Сборка мебели";
|
||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
||||
@ -222,5 +248,7 @@
|
||||
private ToolStripMenuItem FurnituresComponentsToolStripMenuItem;
|
||||
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
|
||||
private ToolStripMenuItem клиентыToolStripMenuItem;
|
||||
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
||||
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -20,12 +20,15 @@ namespace FurnitureAssemblyView
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
private readonly IReportLogic _reportLogic;
|
||||
public MainForm(ILogger<MainForm> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
|
||||
private readonly IWorkProcess _workModeling;
|
||||
|
||||
public MainForm(ILogger<MainForm> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workModeling)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_reportLogic = reportLogic;
|
||||
_workModeling = workModeling;
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
@ -44,6 +47,7 @@ namespace FurnitureAssemblyView
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["FurnitureId"].Visible = false;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["ImplementerId"].Visible = false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка заказов");
|
||||
@ -238,5 +242,21 @@ namespace FurnitureAssemblyView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(ImplementersForm));
|
||||
if (service is ImplementersForm form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void doWorkToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
_workModeling.DoWork((
|
||||
Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!,
|
||||
_orderLogic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,106 +28,137 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.comboBoxFurniture = new System.Windows.Forms.ComboBox();
|
||||
this.labelFurniture = new System.Windows.Forms.Label();
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.labelSum = new System.Windows.Forms.Label();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.textBoxSum = new System.Windows.Forms.TextBox();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
comboBoxFurniture = new ComboBox();
|
||||
labelFurniture = new Label();
|
||||
labelCount = new Label();
|
||||
labelSum = new Label();
|
||||
textBoxCount = new TextBox();
|
||||
textBoxSum = new TextBox();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
clientLabel = new Label();
|
||||
clientBox = new ComboBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxFurniture
|
||||
//
|
||||
this.comboBoxFurniture.FormattingEnabled = true;
|
||||
this.comboBoxFurniture.Location = new System.Drawing.Point(115, 14);
|
||||
this.comboBoxFurniture.Name = "comboBoxFurniture";
|
||||
this.comboBoxFurniture.Size = new System.Drawing.Size(250, 33);
|
||||
this.comboBoxFurniture.TabIndex = 0;
|
||||
comboBoxFurniture.FormattingEnabled = true;
|
||||
comboBoxFurniture.Location = new Point(92, 11);
|
||||
comboBoxFurniture.Margin = new Padding(2);
|
||||
comboBoxFurniture.Name = "comboBoxFurniture";
|
||||
comboBoxFurniture.Size = new Size(201, 28);
|
||||
comboBoxFurniture.TabIndex = 0;
|
||||
//
|
||||
// labelFurniture
|
||||
//
|
||||
this.labelFurniture.AutoSize = true;
|
||||
this.labelFurniture.Location = new System.Drawing.Point(12, 22);
|
||||
this.labelFurniture.Name = "labelFurniture";
|
||||
this.labelFurniture.Size = new System.Drawing.Size(80, 25);
|
||||
this.labelFurniture.TabIndex = 1;
|
||||
this.labelFurniture.Text = "Изделие";
|
||||
labelFurniture.AutoSize = true;
|
||||
labelFurniture.Location = new Point(10, 18);
|
||||
labelFurniture.Margin = new Padding(2, 0, 2, 0);
|
||||
labelFurniture.Name = "labelFurniture";
|
||||
labelFurniture.Size = new Size(68, 20);
|
||||
labelFurniture.TabIndex = 1;
|
||||
labelFurniture.Text = "Изделие";
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(12, 67);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(107, 25);
|
||||
this.labelCount.TabIndex = 2;
|
||||
this.labelCount.Text = "Количество";
|
||||
labelCount.AutoSize = true;
|
||||
labelCount.Location = new Point(10, 54);
|
||||
labelCount.Margin = new Padding(2, 0, 2, 0);
|
||||
labelCount.Name = "labelCount";
|
||||
labelCount.Size = new Size(90, 20);
|
||||
labelCount.TabIndex = 2;
|
||||
labelCount.Text = "Количество";
|
||||
//
|
||||
// labelSum
|
||||
//
|
||||
this.labelSum.AutoSize = true;
|
||||
this.labelSum.Location = new System.Drawing.Point(12, 118);
|
||||
this.labelSum.Name = "labelSum";
|
||||
this.labelSum.Size = new System.Drawing.Size(67, 25);
|
||||
this.labelSum.TabIndex = 3;
|
||||
this.labelSum.Text = "Сумма";
|
||||
labelSum.AutoSize = true;
|
||||
labelSum.Location = new Point(10, 94);
|
||||
labelSum.Margin = new Padding(2, 0, 2, 0);
|
||||
labelSum.Name = "labelSum";
|
||||
labelSum.Size = new Size(55, 20);
|
||||
labelSum.TabIndex = 3;
|
||||
labelSum.Text = "Сумма";
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(115, 64);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(250, 31);
|
||||
this.textBoxCount.TabIndex = 4;
|
||||
this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged);
|
||||
textBoxCount.Location = new Point(92, 51);
|
||||
textBoxCount.Margin = new Padding(2);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(201, 27);
|
||||
textBoxCount.TabIndex = 4;
|
||||
textBoxCount.TextChanged += textBoxCount_TextChanged;
|
||||
//
|
||||
// textBoxSum
|
||||
//
|
||||
this.textBoxSum.Location = new System.Drawing.Point(115, 115);
|
||||
this.textBoxSum.Name = "textBoxSum";
|
||||
this.textBoxSum.ReadOnly = true;
|
||||
this.textBoxSum.Size = new System.Drawing.Size(250, 31);
|
||||
this.textBoxSum.TabIndex = 5;
|
||||
textBoxSum.Location = new Point(92, 92);
|
||||
textBoxSum.Margin = new Padding(2);
|
||||
textBoxSum.Name = "textBoxSum";
|
||||
textBoxSum.ReadOnly = true;
|
||||
textBoxSum.Size = new Size(201, 27);
|
||||
textBoxSum.TabIndex = 5;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(31, 161);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonSave.TabIndex = 6;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
buttonSave.Location = new Point(26, 163);
|
||||
buttonSave.Margin = new Padding(2);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(90, 27);
|
||||
buttonSave.TabIndex = 6;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(253, 161);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(112, 34);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
buttonCancel.Location = new Point(203, 163);
|
||||
buttonCancel.Margin = new Padding(2);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(90, 27);
|
||||
buttonCancel.TabIndex = 7;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
// clientLabel
|
||||
//
|
||||
clientLabel.AutoSize = true;
|
||||
clientLabel.Location = new Point(17, 131);
|
||||
clientLabel.Name = "clientLabel";
|
||||
clientLabel.RightToLeft = RightToLeft.No;
|
||||
clientLabel.Size = new Size(58, 20);
|
||||
clientLabel.TabIndex = 9;
|
||||
clientLabel.Text = "Клиент";
|
||||
//
|
||||
// clientBox
|
||||
//
|
||||
clientBox.FormattingEnabled = true;
|
||||
clientBox.Location = new Point(92, 128);
|
||||
clientBox.Margin = new Padding(2);
|
||||
clientBox.Name = "clientBox";
|
||||
clientBox.Size = new Size(201, 28);
|
||||
clientBox.TabIndex = 10;
|
||||
//
|
||||
// OrderForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(401, 207);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.textBoxSum);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.labelSum);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Controls.Add(this.labelFurniture);
|
||||
this.Controls.Add(this.comboBoxFurniture);
|
||||
this.Name = "OrderForm";
|
||||
this.Text = "Заказ";
|
||||
this.Load += new System.EventHandler(this.OrderForm_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(304, 201);
|
||||
Controls.Add(clientBox);
|
||||
Controls.Add(clientLabel);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(textBoxSum);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(labelSum);
|
||||
Controls.Add(labelCount);
|
||||
Controls.Add(labelFurniture);
|
||||
Controls.Add(comboBoxFurniture);
|
||||
Margin = new Padding(2);
|
||||
Name = "OrderForm";
|
||||
Text = "Заказ";
|
||||
Load += OrderForm_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -140,5 +171,7 @@
|
||||
private TextBox textBoxSum;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Label clientLabel;
|
||||
private ComboBox clientBox;
|
||||
}
|
||||
}
|
@ -19,12 +19,14 @@ namespace FurnitureAssemblyView
|
||||
private readonly ILogger _logger;
|
||||
private readonly IfurnitureLogic _logicP;
|
||||
private readonly IOrderLogic _logicO;
|
||||
public OrderForm(ILogger<OrderForm> logger, IfurnitureLogic logicP, IOrderLogic logicO)
|
||||
private readonly IClientLogic _logicC;
|
||||
public OrderForm(ILogger<OrderForm> logger, IfurnitureLogic logicP, IOrderLogic logicO, IClientLogic logicC)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicP = logicP;
|
||||
_logicO = logicO;
|
||||
_logicC = logicC;
|
||||
}
|
||||
|
||||
private void OrderForm_Load(object sender, EventArgs e)
|
||||
@ -47,6 +49,23 @@ namespace FurnitureAssemblyView
|
||||
_logger.LogError(ex, "Ошибка загрузки списка изделий");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
_logger.LogInformation("Загрузка клиентов для заказа");
|
||||
try
|
||||
{
|
||||
var clientList = _logicC.ReadList(null);
|
||||
if (clientList != null)
|
||||
{
|
||||
clientBox.DisplayMember = "Client";
|
||||
clientBox.ValueMember = "Id";
|
||||
clientBox.DataSource = clientList.Select(c => c.ClientFIO).ToList();
|
||||
clientBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка клиентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void CalcSum()
|
||||
{
|
||||
@ -54,10 +73,14 @@ namespace FurnitureAssemblyView
|
||||
{
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(comboBoxFurniture.SelectedIndex)+1;
|
||||
var list = _logicP.ReadList(null);
|
||||
int id = list.Where(l => l.FurnitureName == comboBoxFurniture.SelectedValue.ToString())
|
||||
.Select(l => l.Id).First();
|
||||
//int id = Convert.ToInt32(comboBoxFurniture.SelectedIndex)+1;
|
||||
var furniture = _logicP.ReadElement(new FurnitureSearchModel
|
||||
{
|
||||
Id = id
|
||||
Id = id,
|
||||
FurnitureName = comboBoxFurniture.Text
|
||||
});
|
||||
int count = Convert.ToInt32(textBoxCount.Text);
|
||||
textBoxSum.Text = Math.Round(count * (furniture?.Price ?? 0), 2).ToString();
|
||||
@ -96,9 +119,10 @@ namespace FurnitureAssemblyView
|
||||
{
|
||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||
{
|
||||
FurnitureId = Convert.ToInt32(comboBoxFurniture.SelectedIndex)+1,
|
||||
FurnitureId = Convert.ToInt32(comboBoxFurniture.SelectedIndex) + 1,
|
||||
Count = Convert.ToInt32(textBoxCount.Text),
|
||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||
Sum = Convert.ToDouble(textBoxSum.Text),
|
||||
ClientId = Convert.ToInt32(clientBox.SelectedIndex) + 1
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
|
@ -1,4 +1,64 @@
|
||||
<root>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using FurnitureAssemblyDatabaseImplement.Implements;
|
||||
using FurnitureAssemblyBusinessLogic.BusinessLogics;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyBusinessLogic.BusinessLogics;
|
||||
using NLog.Extensions.Logging;
|
||||
using FurnitureAssemblyView;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -43,6 +44,9 @@ namespace FurnitureAssembly
|
||||
services.AddTransient<IfurnitureLogic, FurnitureLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||
services.AddTransient<MainForm>();
|
||||
services.AddTransient<ComponentForm>();
|
||||
services.AddTransient<ComponentsForm>();
|
||||
@ -58,6 +62,9 @@ namespace FurnitureAssembly
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
services.AddTransient<ImplementersForm>();
|
||||
services.AddTransient<ImplementerForm>();
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,131 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ImplementerLogic : IImplementerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IImplementerStorage _implementerStorage;
|
||||
|
||||
public ImplementerLogic(ILogger<ImplementerLogic> 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. ImplementerFIO: {ImplementerFIO} Id:{ Id}", model.ImplementerFIO, model.Id);
|
||||
var element = _implementerStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ImplementerFIO: {ImplementerFIO}. Id:{ Id}", model?.ImplementerFIO, model?.Id);
|
||||
var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public 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 (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет ФИО исполнителя",
|
||||
nameof(model.ImplementerFIO));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля пользователя",
|
||||
nameof(model.Password));
|
||||
}
|
||||
|
||||
if (model.WorkExperience < 0)
|
||||
{
|
||||
throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience));
|
||||
}
|
||||
if (model.Qualification < 0)
|
||||
{
|
||||
throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Id: { Id}", model.ImplementerFIO, model.Id);
|
||||
var element = _implementerStorage.GetElement(new ImplementerSearchModel { ImplementerFIO = model.ImplementerFIO });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Исполнитель с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -41,7 +41,17 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||
return ChangeStatus(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus)
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (viewModel == null)
|
||||
@ -51,13 +61,9 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||
if (viewModel.Status + 1 != newStatus)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
return false;
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
model.Status = newStatus;
|
||||
model.FurnitureId = viewModel.FurnitureId;
|
||||
model.Count = viewModel.Count;
|
||||
model.Sum = viewModel.Sum;
|
||||
model.DateCreate = viewModel.DateCreate;
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
@ -66,7 +72,11 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||
{
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
}
|
||||
CheckModel(model);
|
||||
if (viewModel.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = viewModel.ImplementerId.Value;
|
||||
}
|
||||
CheckModel(model, false);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
@ -75,11 +85,6 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
||||
@ -93,11 +98,6 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
@ -127,6 +127,21 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||
|
||||
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. PackageId: { PackageId}", model.Id, model.Sum, model.FurnitureId);
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Status: {Status}. ImplementerId: {ImplementerId} Id:{ Id}", model.Status, model.ImplementerId, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,156 @@
|
||||
using FurnitureAssemblyDataModels.Enums;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class WorkModeling : IWorkProcess
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly Random _rnd;
|
||||
private IOrderLogic? _orderLogic;
|
||||
public WorkModeling(ILogger<WorkModeling> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_rnd = new Random(1000);
|
||||
}
|
||||
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic
|
||||
orderLogic)
|
||||
{
|
||||
_orderLogic = orderLogic;
|
||||
var implementers = implementerLogic.ReadList(null);
|
||||
if (implementers == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
return;
|
||||
}
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel
|
||||
{
|
||||
Status = OrderStatus.Принят
|
||||
});
|
||||
if (orders == null || orders.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||
return;
|
||||
}
|
||||
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
|
||||
|
||||
foreach (var implementer in implementers)
|
||||
{
|
||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Иммитация работы исполнителя
|
||||
/// </summary>
|
||||
/// <param name="implementer"></param>
|
||||
/// <param name="orders"></param>
|
||||
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
|
||||
{
|
||||
if (_orderLogic == null || implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await RunOrderInWork(implementer);
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var order in orders)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("DoWork. Worker {Id} try get order { Order}", implementer.Id, order.Id);
|
||||
// пытаемся назначить заказ на исполнителя
|
||||
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
ImplementerId = implementer.Id
|
||||
});
|
||||
// делаем работу
|
||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(50,
|
||||
1000) * order.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order{ Order} ", implementer.Id, order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
ImplementerId = implementer.Id
|
||||
});
|
||||
// отдыхаем
|
||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||
|
||||
}
|
||||
// кто-то мог уже перехватить заказ, игнорируем ошибку
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
// заканчиваем выполнение имитации в случае иной ошибки
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
|
||||
/// </summary>
|
||||
/// <param name="implementer"></param>
|
||||
/// <returns></returns>
|
||||
private async Task RunOrderInWork(ImplementerViewModel implementer)
|
||||
{
|
||||
if (_orderLogic == null || implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = implementer.Id,
|
||||
Status = OrderStatus.Выполняется
|
||||
}));
|
||||
if (runOrder == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}",
|
||||
implementer.Id, runOrder.Id);
|
||||
// доделываем работу
|
||||
Thread.Sleep(implementer.WorkExperience * _rnd.Next(50, 300) *
|
||||
runOrder.Count);
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}",
|
||||
implementer.Id, runOrder.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = runOrder.Id,
|
||||
ImplementerId = implementer.Id
|
||||
});
|
||||
// отдыхаем
|
||||
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
|
||||
}
|
||||
// заказа может не быть, просто игнорируем ошибку
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.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; }
|
||||
}
|
||||
}
|
@ -18,5 +18,6 @@ namespace FurnitureAssemblyContracts.BindingModels
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; } = null;
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IImplementerLogic
|
||||
{
|
||||
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
|
||||
ImplementerViewModel? ReadElement(ImplementerSearchModel model);
|
||||
bool Create(ImplementerBindingModel model);
|
||||
bool Update(ImplementerBindingModel model);
|
||||
bool Delete(ImplementerBindingModel model);
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
||||
public interface IOrderLogic
|
||||
{
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
OrderViewModel? ReadElement(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
bool FinishOrder(OrderBindingModel model);
|
||||
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IWorkProcess
|
||||
{
|
||||
/// <summary>
|
||||
/// Запуск работ
|
||||
/// </summary>
|
||||
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.SearchModels
|
||||
{
|
||||
public class ImplementerSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ImplementerFIO { get; set; }
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using FurnitureAssemblyDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -12,5 +13,7 @@ namespace FurnitureAssemblyContracts.SearchModels
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public OrderStatus? Status { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.StoragesContracts
|
||||
{
|
||||
public interface IImplementerStorage
|
||||
{
|
||||
List<ImplementerViewModel> GetFullList();
|
||||
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model);
|
||||
ImplementerViewModel? GetElement(ImplementerSearchModel model);
|
||||
ImplementerViewModel? Insert(ImplementerBindingModel model);
|
||||
ImplementerViewModel? Update(ImplementerBindingModel model);
|
||||
ImplementerViewModel? Delete(ImplementerBindingModel model);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.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; }
|
||||
}
|
||||
}
|
@ -30,5 +30,8 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public int? ImplementerId { get; set; }
|
||||
[DisplayName("Исполнитель")]
|
||||
public string? ImplementerFIO { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using FurnitureAssemblyDataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDataModels.Models
|
||||
{
|
||||
public interface IImplementerModel : IId
|
||||
{
|
||||
string ImplementerFIO { get; }
|
||||
string Password { get; }
|
||||
int WorkExperience { get; }
|
||||
int Qualification { get; }
|
||||
}
|
||||
}
|
@ -16,5 +16,6 @@ namespace FurnitureAssemblyDataModels.Models
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
int ClientId { get; }
|
||||
int? ImplementerId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,6 @@ namespace FurnitureAssemblyDatabaseImplement
|
||||
public virtual DbSet<FurnitureComponent> FurnitureComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Clients.FirstOrDefault(x =>
|
||||
return context.Clients
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
|
@ -0,0 +1,101 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => model.Id.HasValue && 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;
|
||||
}
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x =>
|
||||
x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Implementers
|
||||
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Implementers
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
var newImplementer = Implementer.Create(model);
|
||||
if (newImplementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
context.Implementers.Add(newImplementer);
|
||||
context.SaveChanges();
|
||||
return newImplementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var client = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
client.Update(model);
|
||||
context.SaveChanges();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Implementers.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -22,14 +22,14 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
context.Orders.Remove(order);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -37,19 +37,45 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x =>
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x =>
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.ImplementerId.Equals(model.ImplementerId) && x.Status.Equals(model.Status))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
|
||||
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || model.ClientId == x.ClientId)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => !(
|
||||
(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
|
||||
|| (model.ClientId.HasValue && !x.ClientId.Equals(model.ClientId))
|
||||
|| (model.Status.HasValue && !x.Status.Equals(model.Status))))
|
||||
)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -60,6 +86,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -74,8 +101,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
}
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
@ -88,7 +114,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
252
FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240429145846_lab6.Designer.cs
generated
Normal file
252
FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Migrations/20240429145846_lab6.Designer.cs
generated
Normal file
@ -0,0 +1,252 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FurnitureAssemblyDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FurnitureAssemblyDatabase))]
|
||||
[Migration("20240429145846_lab6")]
|
||||
partial class lab6
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.0-preview.3.23174.2")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("FurnitureName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Furnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("FurnitureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.ToTable("FurnitureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("FurnitureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.FurnitureComponent", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("FurnitureComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("FurnitureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Furniture");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany()
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("FurnitureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Furniture");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("FurnitureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Furniture", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class lab6 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ImplementerId",
|
||||
table: "Orders",
|
||||
type: "int",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Implementers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
WorkExperience = table.Column<int>(type: "int", nullable: false),
|
||||
Qualification = table.Column<int>(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");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
@ -113,6 +113,33 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.ToTable("FurnitureComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ImplementerFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Qualification")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WorkExperience")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Implementers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -136,6 +163,9 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.Property<int>("FurnitureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
@ -148,6 +178,8 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.HasIndex("ImplementerId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
@ -184,9 +216,15 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Furniture");
|
||||
|
||||
b.Navigation("Implementer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Component", b =>
|
||||
@ -200,6 +238,11 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public int WorkExperience { get; private set; }
|
||||
[Required]
|
||||
public int Qualification { get; private set; }
|
||||
[ForeignKey("ImplementerId")]
|
||||
public virtual List<Order> Orders { get; private set; } = new();
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implementer()
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Password = model.Password,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Qualification = model.Qualification
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Password = model.Password;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
}
|
||||
}
|
@ -36,6 +36,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
public virtual Furniture Furniture { get; set; }
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
public virtual Implementer? Implementer { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
@ -48,7 +51,8 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
ClientId = model.ClientId,
|
||||
ImplementerId = model.ImplementerId
|
||||
};
|
||||
}
|
||||
|
||||
@ -58,10 +62,11 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
return;
|
||||
}
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
//Count = model.Count;
|
||||
//Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
@ -75,7 +80,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId,
|
||||
ClientFIO = Client.ClientFIO
|
||||
ClientFIO = Client.ClientFIO,
|
||||
ImplementerId = ImplementerId,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using FurnitureAssemblyFileImplement_.Models;
|
||||
using FurnitureAssemFileImplement.Models;
|
||||
using FurnitureAssemblyFileImplement_.Models;
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -8,7 +7,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemFileImplement
|
||||
namespace FurnitureAssemblyFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
@ -17,10 +16,13 @@ namespace FurnitureAssemFileImplement
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string FurnitureFileName = "Furniture.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
private readonly string ImplementerFileName = "Implementer.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Furniture> Furnitures { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public List<Implementer> Implementers { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -33,12 +35,14 @@ namespace FurnitureAssemFileImplement
|
||||
public void SaveFurnitures() => SaveData(Furnitures, FurnitureFileName, "Furnitures", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Furnitures = LoadData(FurnitureFileName, "Furniture", x => Furniture.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<T>? LoadData<T>(string filename, string xmlNodeName,
|
||||
Func<XElement, T> selectFunction)
|
||||
|
@ -3,7 +3,7 @@ using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyFileImplement_.Models;
|
||||
using FurnitureAssemFileImplement;
|
||||
using FurnitureAssemblyFileImplement;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -3,7 +3,6 @@ using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using FurnitureAssemFileImplement;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -3,7 +3,6 @@ using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using FurnitureAssemFileImplement;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -0,0 +1,105 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyFileImplement_.Models;
|
||||
using FurnitureAssemblyFileImplement;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement_.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ImplementerStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return source.Implementers
|
||||
.FirstOrDefault(x => model.Id.HasValue && 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;
|
||||
}
|
||||
return source.Implementers
|
||||
.FirstOrDefault(x =>
|
||||
x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Implementers
|
||||
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> 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 newImpl = Implementer.Create(model);
|
||||
if (newImpl == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Implementers.Add(newImpl);
|
||||
source.SaveComponents();
|
||||
return newImpl.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (implementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
implementer.Update(model);
|
||||
source.SaveComponents();
|
||||
return implementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Implementers.Remove(element);
|
||||
source.SaveComponents();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,14 +2,14 @@
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemFileImplement.Models;
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemFileImplement.Implements
|
||||
namespace FurnitureAssemblyFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
@ -26,19 +26,22 @@ namespace FurnitureAssemFileImplement.Implements
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && !model.Status.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders
|
||||
.Where(x => x.Id.Equals(model.Id) || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || model.ClientId == x.ClientId)
|
||||
.Where(x => !(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
|
||||
|| ((model.ClientId.HasValue) && !(x.ClientId.Equals(model.ClientId)))
|
||||
|| ((model.Status.HasValue) && !(x.Status.Equals(model.Status)))
|
||||
))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -47,6 +50,11 @@ namespace FurnitureAssemFileImplement.Implements
|
||||
.FirstOrDefault(x =>
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
|
||||
var order = source.Orders
|
||||
.FirstOrDefault(x =>
|
||||
(model.Id.HasValue && x.Id == model.Id) || (x.ImplementerId.Equals(model.ImplementerId) && x.Status.Equals(model.Status)));
|
||||
return order?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
|
@ -1,11 +1,6 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement_.Models
|
||||
|
@ -1,7 +1,6 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemFileImplement;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
|
@ -0,0 +1,84 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement_.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int WorkExperience { get; private set; }
|
||||
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implementer()
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Password = model.Password,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Qualification = model.Qualification
|
||||
};
|
||||
}
|
||||
|
||||
public static Implementer? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implementer()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ImplementerFIO = element.Element("ImplementerFIO")!.Value,
|
||||
Password = element.Element("Password")!.Value,
|
||||
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
|
||||
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Password = model.Password;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Implementer",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ImplementerFIO", ImplementerFIO),
|
||||
new XElement("Password", Password),
|
||||
new XElement("WorkExperience", WorkExperience.ToString()),
|
||||
new XElement("Qualification", Qualification.ToString())
|
||||
);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemFileImplement.Models
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
@ -31,6 +31,7 @@ namespace FurnitureAssemFileImplement.Models
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
public int? ImplementerId { get; private set; } = null;
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
@ -47,7 +48,8 @@ namespace FurnitureAssemFileImplement.Models
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
ClientId = model.ClientId,
|
||||
ImplementerId = model.ImplementerId
|
||||
};
|
||||
}
|
||||
|
||||
@ -65,7 +67,8 @@ namespace FurnitureAssemFileImplement.Models
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value)
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")?.Value)
|
||||
};
|
||||
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
|
||||
|
||||
@ -87,6 +90,7 @@ namespace FurnitureAssemFileImplement.Models
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
@ -99,7 +103,8 @@ namespace FurnitureAssemFileImplement.Models
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Order",
|
||||
@ -111,6 +116,7 @@ namespace FurnitureAssemFileImplement.Models
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
new XElement("DateImplement", DateImplement.ToString()));
|
||||
new XElement("DateImplement", DateImplement.ToString()),
|
||||
new XElement("ImplemwenterId", ImplementerId.ToString()));
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,14 @@ namespace FurnitureAssemblyListImplement
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Furniture> Furnitures { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Furnitures = new List<Furniture>();
|
||||
Clients = new List<Client>();
|
||||
Implementers = new List<Implementer>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -0,0 +1,122 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyListImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var impl in _source.Implementers)
|
||||
{
|
||||
if (model.Id.HasValue && impl.Id == model.Id)
|
||||
{
|
||||
return impl.GetViewModel;
|
||||
}
|
||||
|
||||
if (model.ImplementerFIO != null && model.Password != null
|
||||
&& impl.ImplementerFIO.Equals(model.ImplementerFIO) && impl.Password.Equals(model.Password))
|
||||
{
|
||||
return impl.GetViewModel;
|
||||
}
|
||||
|
||||
if (model.ImplementerFIO != null && impl.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
{
|
||||
return impl.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
var result = new List<ImplementerViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var impl in _source.Implementers)
|
||||
{
|
||||
if (impl.ImplementerFIO.Contains(model.ImplementerFIO))
|
||||
{
|
||||
result.Add(impl.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ImplementerViewModel>();
|
||||
foreach (var component in _source.Implementers)
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var impl in _source.Implementers)
|
||||
{
|
||||
if (model.Id <= impl.Id)
|
||||
{
|
||||
model.Id = impl.Id + 1;
|
||||
}
|
||||
}
|
||||
var newImpl = Implementer.Create(model);
|
||||
if (newImpl == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Implementers.Add(newImpl);
|
||||
return newImpl.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
foreach (var impl in _source.Implementers)
|
||||
{
|
||||
if (impl.Id == model.Id)
|
||||
{
|
||||
impl.Update(model);
|
||||
return impl.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ namespace FurnitureAssemblyListImplement.Implements
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -44,6 +44,10 @@ namespace FurnitureAssemblyListImplement.Implements
|
||||
{
|
||||
return order.GetViewModel;
|
||||
}
|
||||
else if (order.ImplementerId.Equals(model.ImplementerId) && order.Status.Equals(model.Status))
|
||||
{
|
||||
return order.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -51,15 +55,15 @@ namespace FurnitureAssemblyListImplement.Implements
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
if (model == null)
|
||||
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id.Equals(model.Id) ||
|
||||
model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo ||
|
||||
order.ClientId.Equals(model.ClientId))
|
||||
if (!(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo)
|
||||
|| ((model.ClientId.HasValue) && !(order.ClientId.Equals(model.ClientId)))
|
||||
|| ((model.Status.HasValue) && !(order.Status.Equals(model.Status)))))
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
}
|
||||
|
@ -1,11 +1,6 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
|
||||
namespace FurnitureAssemblyListImplement.Models
|
||||
{
|
||||
|
@ -0,0 +1,59 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyListImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int WorkExperience { get; private set; }
|
||||
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Implementer()
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Password = model.Password,
|
||||
WorkExperience = model.WorkExperience,
|
||||
Qualification = model.Qualification
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Password = model.Password;
|
||||
WorkExperience = model.WorkExperience;
|
||||
Qualification = model.Qualification;
|
||||
}
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ namespace FurnitureAssemblyListImplement.Models
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
public int? ImplementerId { get; private set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -42,7 +43,8 @@ namespace FurnitureAssemblyListImplement.Models
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
ClientId = model.ClientId,
|
||||
ImplementerId = model.ImplementerId
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
@ -53,6 +55,7 @@ namespace FurnitureAssemblyListImplement.Models
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
@ -64,7 +67,8 @@ namespace FurnitureAssemblyListImplement.Models
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,102 @@
|
||||
using FurnitureAssemblyDataModels.Enums;
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace FurnitureAssemblyRestApi.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<ImplementerController> 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<OrderViewModel>? GetNewOrders()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadList(new OrderSearchModel
|
||||
{
|
||||
Status = OrderStatus.Принят
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения новых заказов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public OrderViewModel? GetImplementerOrder(int implementerId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = implementerId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.TakeOrderInWork(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу",
|
||||
model.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.FinishOrder(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{ Id}", model.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user