лаба 6

This commit is contained in:
leonteva.v 2024-05-25 04:12:03 +04:00
parent a6b4f7dc3d
commit 361c146bc1
44 changed files with 1740 additions and 110 deletions

View File

@ -0,0 +1,163 @@
namespace Typography
{
partial class FormImplementer
{
/// <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()
{
labelFIO = new Label();
labelPassword = new Label();
labelWorkExperience = new Label();
labelQualification = new Label();
textBoxPassword = new TextBox();
textBoxFIO = new TextBox();
textBoxWorkExperience = new TextBox();
textBoxQualification = new TextBox();
buttonSave = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// labelFIO
//
labelFIO.AutoSize = true;
labelFIO.Location = new Point(12, 15);
labelFIO.Name = "labelFIO";
labelFIO.Size = new Size(42, 20);
labelFIO.TabIndex = 0;
labelFIO.Text = "ФИО";
//
// labelPassword
//
labelPassword.AutoSize = true;
labelPassword.Location = new Point(12, 48);
labelPassword.Name = "labelPassword";
labelPassword.Size = new Size(62, 20);
labelPassword.TabIndex = 1;
labelPassword.Text = "Пароль";
//
// labelWorkExperience
//
labelWorkExperience.AutoSize = true;
labelWorkExperience.Location = new Point(12, 81);
labelWorkExperience.Name = "labelWorkExperience";
labelWorkExperience.Size = new Size(99, 20);
labelWorkExperience.TabIndex = 2;
labelWorkExperience.Text = "Стаж работы";
//
// labelQualification
//
labelQualification.AutoSize = true;
labelQualification.Location = new Point(12, 114);
labelQualification.Name = "labelQualification";
labelQualification.Size = new Size(111, 20);
labelQualification.TabIndex = 3;
labelQualification.Text = "Квалификация";
//
// textBoxPassword
//
textBoxPassword.Location = new Point(129, 45);
textBoxPassword.Name = "textBoxPassword";
textBoxPassword.Size = new Size(241, 27);
textBoxPassword.TabIndex = 4;
//
// textBoxFIO
//
textBoxFIO.Location = new Point(129, 12);
textBoxFIO.Name = "textBoxFIO";
textBoxFIO.Size = new Size(241, 27);
textBoxFIO.TabIndex = 5;
//
// textBoxWorkExperience
//
textBoxWorkExperience.Location = new Point(129, 78);
textBoxWorkExperience.Name = "textBoxWorkExperience";
textBoxWorkExperience.Size = new Size(134, 27);
textBoxWorkExperience.TabIndex = 6;
//
// textBoxQualification
//
textBoxQualification.Location = new Point(129, 111);
textBoxQualification.Name = "textBoxQualification";
textBoxQualification.Size = new Size(134, 27);
textBoxQualification.TabIndex = 7;
//
// buttonSave
//
buttonSave.Location = new Point(168, 146);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(102, 29);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(276, 146);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormImplementer
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(382, 187);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxQualification);
Controls.Add(textBoxWorkExperience);
Controls.Add(textBoxFIO);
Controls.Add(textBoxPassword);
Controls.Add(labelQualification);
Controls.Add(labelWorkExperience);
Controls.Add(labelPassword);
Controls.Add(labelFIO);
Name = "FormImplementer";
StartPosition = FormStartPosition.CenterParent;
Text = "Исполнитель";
Load += FormImplementer_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelFIO;
private Label labelPassword;
private Label labelWorkExperience;
private Label labelQualification;
private TextBox textBoxPassword;
private TextBox textBoxFIO;
private TextBox textBoxWorkExperience;
private TextBox textBoxQualification;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,92 @@
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace Typography
{
public partial class FormImplementer : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormImplementer(ILogger<FormImplementer> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormImplementer_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение исполнителя");
var view = _logic.ReadElement(new ImplementerSearchModel { Id = _id.Value });
if (view != null)
{
textBoxFIO.Text = view.ImplementerFIO;
textBoxPassword.Text = view.Password;
textBoxWorkExperience.Text = view.WorkExperience.ToString();
textBoxQualification.Text = view.Qualification.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(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(textBoxWorkExperience.Text),
Qualification = Convert.ToInt32(textBoxQualification.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View 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>

View File

@ -0,0 +1,118 @@
namespace Typography
{
partial class FormImplementers
{
/// <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()
{
dataGridViewImplementers = new DataGridView();
buttonRef = new Button();
buttonDel = new Button();
buttonUpd = new Button();
buttonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridViewImplementers).BeginInit();
SuspendLayout();
//
// dataGridViewImplementers
//
dataGridViewImplementers.BackgroundColor = SystemColors.ControlLightLight;
dataGridViewImplementers.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewImplementers.Location = new Point(1, 1);
dataGridViewImplementers.Name = "dataGridViewImplementers";
dataGridViewImplementers.RowHeadersVisible = false;
dataGridViewImplementers.RowHeadersWidth = 51;
dataGridViewImplementers.RowTemplate.Height = 29;
dataGridViewImplementers.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewImplementers.Size = new Size(650, 402);
dataGridViewImplementers.TabIndex = 0;
//
// buttonRef
//
buttonRef.Location = new Point(668, 117);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(102, 29);
buttonRef.TabIndex = 1;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// buttonDel
//
buttonDel.Location = new Point(668, 82);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(102, 29);
buttonDel.TabIndex = 2;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonUpd
//
buttonUpd.Location = new Point(668, 47);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(102, 29);
buttonUpd.TabIndex = 3;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(668, 12);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(102, 29);
buttonAdd.TabIndex = 4;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// FormImplementers
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(782, 403);
Controls.Add(buttonAdd);
Controls.Add(buttonUpd);
Controls.Add(buttonDel);
Controls.Add(buttonRef);
Controls.Add(dataGridViewImplementers);
Name = "FormImplementers";
StartPosition = FormStartPosition.CenterParent;
Text = "Исполнители";
Load += FormImplementers_Load;
((System.ComponentModel.ISupportInitialize)dataGridViewImplementers).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridViewImplementers;
private Button buttonRef;
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,104 @@
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using TypographyView;
namespace Typography
{
public partial class FormImplementers : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
public FormImplementers(ILogger<FormImplementers> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormImplementers_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridViewImplementers.DataSource = list;
dataGridViewImplementers.Columns["Id"].Visible = false;
dataGridViewImplementers.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка исполнителей");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки исполнителей");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridViewImplementers.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
form.Id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridViewImplementers.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridViewImplementers.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();
}
}
}

View 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>

View File

@ -33,16 +33,16 @@
directoriesToolStripMenuItem = new ToolStripMenuItem();
componentsToolStripMenuItem = new ToolStripMenuItem();
printedsToolStripMenuItem = new ToolStripMenuItem();
clientsToolStripMenuItem = new ToolStripMenuItem();
implementersToolStripMenuItem = new ToolStripMenuItem();
ReportsToolStripMenuItem = new ToolStripMenuItem();
PrintedListToolStripMenuItem = new ToolStripMenuItem();
PrintedComponentsToolStripMenuItem = new ToolStripMenuItem();
ListOfOrdersToolStripMenuItem = new ToolStripMenuItem();
workLaunchToolStripMenuItem = new ToolStripMenuItem();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
clientsToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridViewOrders).BeginInit();
menuStrip.SuspendLayout();
SuspendLayout();
@ -63,7 +63,7 @@
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, ReportsToolStripMenuItem });
menuStrip.Items.AddRange(new ToolStripItem[] { directoriesToolStripMenuItem, ReportsToolStripMenuItem, workLaunchToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1331, 28);
@ -72,7 +72,7 @@
//
// directoriesToolStripMenuItem
//
directoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, printedsToolStripMenuItem, clientsToolStripMenuItem });
directoriesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, printedsToolStripMenuItem, clientsToolStripMenuItem, implementersToolStripMenuItem });
directoriesToolStripMenuItem.Name = "directoriesToolStripMenuItem";
directoriesToolStripMenuItem.Size = new Size(117, 24);
directoriesToolStripMenuItem.Text = "Справочники";
@ -91,6 +91,20 @@
printedsToolStripMenuItem.Text = "Печатная продукция";
printedsToolStripMenuItem.Click += printedsToolStripMenuItem_Click;
//
// clientsToolStripMenuItem
//
clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
clientsToolStripMenuItem.Size = new Size(237, 26);
clientsToolStripMenuItem.Text = "Клиенты";
clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click;
//
// implementersToolStripMenuItem
//
implementersToolStripMenuItem.Name = "implementersToolStripMenuItem";
implementersToolStripMenuItem.Size = new Size(237, 26);
implementersToolStripMenuItem.Text = "Исполнители";
implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click;
//
// ReportsToolStripMenuItem
//
ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { PrintedListToolStripMenuItem, PrintedComponentsToolStripMenuItem, ListOfOrdersToolStripMenuItem });
@ -119,6 +133,13 @@
ListOfOrdersToolStripMenuItem.Text = "Список заказов";
ListOfOrdersToolStripMenuItem.Click += ListOfOrdersToolStripMenuItem_Click;
//
// workLaunchToolStripMenuItem
//
workLaunchToolStripMenuItem.Name = "workLaunchToolStripMenuItem";
workLaunchToolStripMenuItem.Size = new Size(114, 24);
workLaunchToolStripMenuItem.Text = "Запуск работ";
workLaunchToolStripMenuItem.Click += workLaunchToolStripMenuItem_Click;
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(1109, 42);
@ -129,29 +150,9 @@
buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += buttonCreateOrder_Click;
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(1109, 96);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(195, 29);
buttonTakeOrderInWork.TabIndex = 6;
buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click;
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(1109, 149);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(195, 29);
buttonOrderReady.TabIndex = 7;
buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += buttonOrderReady_Click;
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(1109, 202);
buttonIssuedOrder.Location = new Point(1109, 108);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(195, 29);
buttonIssuedOrder.TabIndex = 8;
@ -161,7 +162,7 @@
//
// buttonRef
//
buttonRef.Location = new Point(1109, 255);
buttonRef.Location = new Point(1109, 174);
buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(195, 29);
buttonRef.TabIndex = 9;
@ -169,13 +170,6 @@
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += buttonRef_Click;
//
// clientsToolStripMenuItem
//
clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
clientsToolStripMenuItem.Size = new Size(237, 26);
clientsToolStripMenuItem.Text = "Клиенты";
clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -183,8 +177,6 @@
ClientSize = new Size(1331, 453);
Controls.Add(buttonRef);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);
Controls.Add(buttonTakeOrderInWork);
Controls.Add(buttonCreateOrder);
Controls.Add(dataGridViewOrders);
Controls.Add(menuStrip);
@ -207,8 +199,6 @@
private ToolStripMenuItem componentsToolStripMenuItem;
private ToolStripMenuItem printedsToolStripMenuItem;
private Button buttonCreateOrder;
private Button buttonTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem ReportsToolStripMenuItem;
@ -216,5 +206,7 @@
private ToolStripMenuItem PrintedComponentsToolStripMenuItem;
private ToolStripMenuItem ListOfOrdersToolStripMenuItem;
private ToolStripMenuItem clientsToolStripMenuItem;
private ToolStripMenuItem implementersToolStripMenuItem;
private ToolStripMenuItem workLaunchToolStripMenuItem;
}
}

View File

@ -3,6 +3,7 @@ using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using Typography;
using TypographyContracts.BindingModels;
using TypographyBusinessLogic.BusinessLogics;
namespace TypographyView
@ -12,12 +13,14 @@ namespace TypographyView
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
_workProcess = workProcess;
}
private void LoadData()
{
@ -28,6 +31,7 @@ namespace TypographyView
{
dataGridViewOrders.DataSource = list;
dataGridViewOrders.Columns["ClientId"].Visible = false;
dataGridViewOrders.Columns["ImplementerId"].Visible = false;
dataGridViewOrders.Columns["PrintedId"].Visible = false;
dataGridViewOrders.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
@ -64,50 +68,6 @@ namespace TypographyView
LoadData();
}
}
private void buttonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridViewOrders.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridViewOrders.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridViewOrders.SelectedRows.Count == 1)
@ -172,5 +132,18 @@ namespace TypographyView
form.ShowDialog();
}
}
private void implementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
}
private void workLaunchToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}

View File

@ -42,12 +42,15 @@ namespace TypographyView
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IPrintedStorage, PrintedStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IPrintedLogic, PrintedLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
@ -63,6 +66,8 @@ namespace TypographyView
services.AddTransient<FormReportPrintedComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormClients>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormImplementers>();
}
}
}

View File

@ -0,0 +1,116 @@
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace TypographyBusinessLogic.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 List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}. ImplementerFIO: {ImplementerFIO}.",
model?.Id, model?.ImplementerFIO);
var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id: {Id}. ImplementerFIO: {ImplementerFIO}.",
model?.Id, model?.ImplementerFIO);
var element = _implementerStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public bool Create(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ImplementerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_implementerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password));
}
if (model.WorkExperience < 0)
{
throw new ArgumentNullException("Стаж работы должен быть неотрицательным", nameof(model.WorkExperience));
}
if (model.Qualification < 0)
{
throw new ArgumentNullException("Квалификация должна быть неотрицательной", nameof(model.Qualification));
}
_logger.LogInformation("Implementer. Id: {Id}. ImplementerFIO: {ImplementerFIO}. WorkExperience: {WorkExperience}. Qualification: {Qualification}.",
model?.Id, model?.ImplementerFIO, model?.WorkExperience, model?.Qualification);
var element = _implementerStorage.GetElement(new ImplementerSearchModel { ImplementerFIO = model.ImplementerFIO });
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
}
}
}
}

View File

@ -5,6 +5,7 @@ using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using Microsoft.Extensions.Logging;
using TypographyDataModels.Enums;
using System.Xml.Linq;
namespace TypographyBusinessLogic.BusinessLogics
{
@ -12,11 +13,29 @@ namespace TypographyBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
static readonly object _locker = new object();
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{
_logger = logger;
_orderStorage = orderStorage;
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ClientId: {ClientId}. ImplementerId: {ImplementerId}. Status: {Status}. DateFrom: {DateFrom}. DateTo: {DateTo}. Id: {Id}",
model.ClientId, model.ImplementerId, model.Status, model.DateFrom, model.DateTo, model.Id);
var element = _orderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
@ -48,7 +67,10 @@ namespace TypographyBusinessLogic.BusinessLogics
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return ChangeOrderStatus(model, OrderStatus.Выполняется);
lock (_locker)
{
return ChangeOrderStatus(model, OrderStatus.Выполняется);
}
}
public bool FinishOrder(OrderBindingModel model)
{
@ -89,11 +111,13 @@ namespace TypographyBusinessLogic.BusinessLogics
return false;
}
model.Status = newStatus;
if (newStatus == OrderStatus.Выдан)
if (!model.ImplementerId.HasValue)
model.ImplementerId = orderView.ImplementerId;
model.DateImplement = orderView.DateImplement;
if (newStatus == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
}
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Order status change failed");

View File

@ -0,0 +1,118 @@
using TypographyDataModels.Enums;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace TypographyBusinessLogic.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));
}
}
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(100, 1000) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = order.Id
});
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
});
}
private async Task RunOrderInWork(ImplementerViewModel implementer)
{
if (_orderLogic == null || implementer == null)
{
return;
}
try
{
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
{
ImplementerId = implementer.Id,
Status = OrderStatus.Выполняется
}));
if (runOrder == null)
{
return;
}
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = runOrder.Id
});
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
}
}

View File

@ -0,0 +1,13 @@
using TypographyDataModels.Models;
namespace TypographyContracts.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; }
}
}

View File

@ -6,8 +6,9 @@ namespace TypographyContracts.BindingModels
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int PrintedId { get; set; }
public int ClientId { get; set; }
public int? ImplementerId { get; set; }
public int PrintedId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -0,0 +1,15 @@
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
namespace TypographyContracts.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);
}
}

View File

@ -7,6 +7,7 @@ namespace TypographyContracts.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);

View File

@ -0,0 +1,7 @@
namespace TypographyContracts.BusinessLogicsContracts
{
public interface IWorkProcess
{
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
}
}

View File

@ -0,0 +1,9 @@
namespace TypographyContracts.SearchModels
{
public class ImplementerSearchModel
{
public int? Id { get; set; }
public string? ImplementerFIO { get; set; }
public string? Password { get; set; }
}
}

View File

@ -1,9 +1,13 @@
namespace TypographyContracts.SearchModels
using TypographyDataModels.Enums;
namespace TypographyContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
public int? ClientId { get; set; }
public int? ImplementerId { get; set; }
public OrderStatus? Status { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}

View File

@ -0,0 +1,16 @@
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
namespace TypographyContracts.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);
}
}

View File

@ -0,0 +1,18 @@
using TypographyDataModels.Models;
using System.ComponentModel;
namespace TypographyContracts.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; }
}
}

View File

@ -11,6 +11,9 @@ namespace TypographyContracts.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;
public int PrintedId { get; set; }
[DisplayName("Изделие")]
public string PrintedName { get; set; } = string.Empty;

View File

@ -0,0 +1,10 @@
namespace TypographyDataModels.Models
{
public interface IImplementerModel : IId
{
string ImplementerFIO { get; }
string Password { get; }
int WorkExperience { get; }
int Qualification { get; }
}
}

View File

@ -5,6 +5,7 @@ namespace TypographyDataModels.Models
public interface IOrderModel : IId
{
int ClientId { get; }
int? ImplementerId { get; }
int PrintedId { get; }
int Count { get; }
double Sum { get; }

View File

@ -0,0 +1,80 @@
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using TypographyDatabaseImplement.Models;
namespace TypographyDatabaseImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
public List<ImplementerViewModel> GetFullList()
{
using var context = new TypographyDatabase();
return context.Implementers
.Select(x => x.GetViewModel)
.ToList();
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
return new();
}
using var context = new TypographyDatabase();
return context.Implementers
.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password))
{
return null;
}
using var context = new TypographyDatabase();
return context.Implementers
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
(!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO &&
!string.IsNullOrEmpty(model.Password) && x.Password == model.Password))
?.GetViewModel;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
var newImplementer = Implementer.Create(model);
if (newImplementer == null)
{
return null;
}
using var context = new TypographyDatabase();
context.Implementers.Add(newImplementer);
context.SaveChanges();
return newImplementer.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
using var context = new TypographyDatabase();
var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (implementer == null)
{
return null;
}
implementer.Update(model);
context.SaveChanges();
return implementer.GetViewModel;
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
using var context = new TypographyDatabase();
var element = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Implementers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -11,7 +11,7 @@ namespace TypographyDatabaseImplement.Implements
{
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
{
return null;
}
@ -19,11 +19,14 @@ namespace TypographyDatabaseImplement.Implements
return context.Orders
.Include(x => x.Printed)
.Include(x => x.Client)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.ClientId.HasValue && x.ClientId == model.ClientId))?.GetViewModel;
.Include(x => x.Implementer)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
(model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status))?
.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue)
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue)
{
return new();
}
@ -31,8 +34,10 @@ namespace TypographyDatabaseImplement.Implements
return context.Orders
.Include(x => x.Printed)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Where(x => (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) ||
(model.ClientId.HasValue && x.ClientId == model.ClientId))
(model.ClientId.HasValue && x.ClientId == model.ClientId) ||
(model.Status.HasValue && x.Status == model.Status))
.Select(x => x.GetViewModel)
.ToList();
}
@ -42,6 +47,7 @@ namespace TypographyDatabaseImplement.Implements
return context.Orders
.Include(x => x.Printed)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
}
@ -65,7 +71,7 @@ namespace TypographyDatabaseImplement.Implements
{
return null;
}
order.Update(model);
order.Update(model, context);
context.SaveChanges();
return order.GetViewModel;
}

View File

@ -12,7 +12,7 @@ using TypographyDatabaseImplement;
namespace TypographyDatabaseImplement.Migrations
{
[DbContext(typeof(TypographyDatabase))]
[Migration("20240524210919_r")]
[Migration("20240525000632_r")]
partial class r
{
/// <inheritdoc />
@ -70,6 +70,33 @@ namespace TypographyDatabaseImplement.Migrations
b.ToTable("Components");
});
modelBuilder.Entity("TypographyDatabaseImplement.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("TypographyDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
@ -90,6 +117,9 @@ namespace TypographyDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("PrintedId")
.HasColumnType("int");
@ -103,6 +133,8 @@ namespace TypographyDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("PrintedId");
b.ToTable("Orders");
@ -162,6 +194,10 @@ namespace TypographyDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TypographyDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("ImplementerOrders")
.HasForeignKey("ImplementerId");
b.HasOne("TypographyDatabaseImplement.Models.Printed", "Printed")
.WithMany("Orders")
.HasForeignKey("PrintedId")
@ -170,6 +206,8 @@ namespace TypographyDatabaseImplement.Migrations
b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Printed");
});
@ -202,6 +240,11 @@ namespace TypographyDatabaseImplement.Migrations
b.Navigation("PrintedComponents");
});
modelBuilder.Entity("TypographyDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("ImplementerOrders");
});
modelBuilder.Entity("TypographyDatabaseImplement.Models.Printed", b =>
{
b.Navigation("Components");

View File

@ -40,6 +40,22 @@ namespace TypographyDatabaseImplement.Migrations
table.PrimaryKey("PK_Components", x => x.Id);
});
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.CreateTable(
name: "Printeds",
columns: table => new
@ -61,6 +77,7 @@ namespace TypographyDatabaseImplement.Migrations
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientId = table.Column<int>(type: "int", nullable: false),
ImplementerId = table.Column<int>(type: "int", nullable: true),
PrintedId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
@ -77,6 +94,11 @@ namespace TypographyDatabaseImplement.Migrations
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Implementers_ImplementerId",
column: x => x.ImplementerId,
principalTable: "Implementers",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Orders_Printeds_PrintedId",
column: x => x.PrintedId,
@ -117,6 +139,11 @@ namespace TypographyDatabaseImplement.Migrations
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ImplementerId",
table: "Orders",
column: "ImplementerId");
migrationBuilder.CreateIndex(
name: "IX_Orders_PrintedId",
table: "Orders",
@ -145,6 +172,9 @@ namespace TypographyDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Implementers");
migrationBuilder.DropTable(
name: "Components");

View File

@ -67,6 +67,33 @@ namespace TypographyDatabaseImplement.Migrations
b.ToTable("Components");
});
modelBuilder.Entity("TypographyDatabaseImplement.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("TypographyDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
@ -87,6 +114,9 @@ namespace TypographyDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("PrintedId")
.HasColumnType("int");
@ -100,6 +130,8 @@ namespace TypographyDatabaseImplement.Migrations
b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("PrintedId");
b.ToTable("Orders");
@ -159,6 +191,10 @@ namespace TypographyDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TypographyDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("ImplementerOrders")
.HasForeignKey("ImplementerId");
b.HasOne("TypographyDatabaseImplement.Models.Printed", "Printed")
.WithMany("Orders")
.HasForeignKey("PrintedId")
@ -167,6 +203,8 @@ namespace TypographyDatabaseImplement.Migrations
b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Printed");
});
@ -199,6 +237,11 @@ namespace TypographyDatabaseImplement.Migrations
b.Navigation("PrintedComponents");
});
modelBuilder.Entity("TypographyDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("ImplementerOrders");
});
modelBuilder.Entity("TypographyDatabaseImplement.Models.Printed", b =>
{
b.Navigation("Components");

View File

@ -0,0 +1,57 @@
using TypographyContracts.BindingModels;
using TypographyContracts.ViewModels;
using TypographyDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace TypographyDatabaseImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; set; }
[Required]
public string ImplementerFIO { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public int WorkExperience { get; set; }
[Required]
public int Qualification { get; set; }
[ForeignKey("ImplementerId")]
public virtual List<Order> ImplementerOrders { get; set; } = new();
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new Implementer()
{
Id = model.Id,
ImplementerFIO = model.ImplementerFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
ImplementerFIO = model.ImplementerFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFIO = ImplementerFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
}
}

View File

@ -15,6 +15,8 @@ namespace TypographyDatabaseImplement.Models
[Required]
public int ClientId { get; private set; }
public virtual Client Client { get; set; } = new();
public int? ImplementerId { get; private set; }
public virtual Implementer? Implementer { get; set; } = new();
[Required]
public int PrintedId { get; private set; }
public virtual Printed Printed { get; set; } = new();
@ -38,6 +40,8 @@ namespace TypographyDatabaseImplement.Models
Id = model.Id,
ClientId = model.ClientId,
Client = context.Clients.First(x => model.ClientId == x.Id),
ImplementerId = model.ImplementerId,
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null,
PrintedId = model.PrintedId,
Printed = context.Printeds.First(x => model.PrintedId == x.Id),
Count = model.Count,
@ -47,12 +51,14 @@ namespace TypographyDatabaseImplement.Models
DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel? model)
public void Update(OrderBindingModel? model, TypographyDatabase context)
{
if (model == null)
{
return;
}
ImplementerId = model.ImplementerId;
Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => model.ImplementerId == x.Id) : null;
Status = model.Status;
DateImplement = model.DateImplement;
}
@ -61,6 +67,8 @@ namespace TypographyDatabaseImplement.Models
Id = Id,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
ImplementerId = ImplementerId,
ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null,
PrintedId = PrintedId,
PrintedName = Printed.PrintedName,
Count = Count,

View File

@ -10,7 +10,7 @@ namespace TypographyDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=TypographyDatabase_5;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=Typograph6;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
@ -19,5 +19,6 @@ namespace TypographyDatabaseImplement
public virtual DbSet<PrintedComponent> PrintedComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<Implementer> Implementers { set; get; }
}
}

View File

@ -11,10 +11,12 @@ namespace TypographyFileImplement
private readonly string OrderFileName = "Order.xml";
private readonly string PrintedFileName = "Printed.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<Printed> Printeds { get; private set; }
public List<Client> Clients { get; private set; }
public List<Implementer> Implementers { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -27,12 +29,14 @@ namespace TypographyFileImplement
public void SavePrinteds() => SaveData(Printeds, PrintedFileName, "Printeds", 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)!)!;
Printeds = LoadData(PrintedFileName, "Product", x => Printed.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)
{

View File

@ -0,0 +1,80 @@
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using TypographyFileImplement.Models;
namespace TypographyFileImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
private readonly DataFileSingleton source;
public ImplementerStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ImplementerViewModel> GetFullList()
{
return source.Implementers
.Select(x => x.GetViewModel)
.ToList();
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
return new();
}
return source.Implementers
.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password))
{
return null;
}
return source.Implementers
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
(!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO &&
!string.IsNullOrEmpty(model.Password) && x.Password == model.Password))
?.GetViewModel;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
var newImplementer = Implementer.Create(model);
if (newImplementer == null)
{
return null;
}
source.Implementers.Add(newImplementer);
source.SaveImplementers();
return newImplementer.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (implementer == null)
{
return null;
}
implementer.Update(model);
source.SaveImplementers();
return implementer.GetViewModel;
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Implementers.Remove(element);
source.SaveImplementers();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -22,11 +22,16 @@ namespace TypographyFileImplement.Implements
private OrderViewModel DefineOthersNames(OrderViewModel model)
{
string? clientFIO = source.Clients.FirstOrDefault(x => model.ClientId == x.Id)?.ClientFIO;
string? implementerFIO = source.Implementers.FirstOrDefault(x => model.ImplementerId == x.Id)?.ImplementerFIO;
string? printedName = source.Printeds.FirstOrDefault(x => model.PrintedId == x.Id)?.PrintedName;
if (clientFIO != null)
{
model.ClientFIO = clientFIO;
}
if (implementerFIO != null)
{
model.ImplementerFIO = implementerFIO;
}
if (printedName != null)
{
model.PrintedName = printedName;
@ -35,24 +40,28 @@ namespace TypographyFileImplement.Implements
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue)
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue)
{
return new();
}
return source.Orders
.Where(x => (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) ||
(model.ClientId.HasValue && x.ClientId == model.ClientId))
(model.ClientId.HasValue && x.ClientId == model.ClientId) ||
(model.Status.HasValue && x.Status == model.Status))
.Select(x => DefineOthersNames(x.GetViewModel))
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue && !model.ClientId.HasValue)
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
{
return null;
}
return DefineOthersNames(source.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.ClientId.HasValue && x.Id == model.ClientId))?.GetViewModel);
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
(model.ClientId.HasValue && x.Id == model.ClientId) ||
(model.ImplementerId.HasValue && x.Id == model.ImplementerId && x.Status == model.Status))?
.GetViewModel);
}
public OrderViewModel? Insert(OrderBindingModel model)
{

View File

@ -0,0 +1,72 @@
using TypographyContracts.BindingModels;
using TypographyContracts.ViewModels;
using TypographyDataModels.Models;
using System.Xml.Linq;
using System.Reflection;
namespace TypographyFileImplement.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("Cost")!.Value),
Qualification = Convert.ToInt32(element.Element("Cost")!.Value)
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
ImplementerFIO = model.ImplementerFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFIO = ImplementerFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
public XElement GetXElement => new("Implementer",
new XAttribute("Id", Id),
new XElement("ImplementerFIO", ImplementerFIO),
new XElement("Password", Password),
new XElement("WorkExperience", WorkExperience),
new XElement("Qualification", Qualification));
}
}

View File

@ -15,6 +15,7 @@ namespace TypographyFileImplement.Models
{
public int Id { get; private set; }
public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
public int PrintedId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
@ -31,6 +32,7 @@ namespace TypographyFileImplement.Models
{
Id = model.Id,
ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
PrintedId = model.PrintedId,
Count = model.Count,
Sum = model.Sum,
@ -49,6 +51,7 @@ namespace TypographyFileImplement.Models
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
PrintedId = Convert.ToInt32(element.Element("PrintedId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
@ -65,12 +68,14 @@ namespace TypographyFileImplement.Models
return;
}
Status = model.Status;
ImplementerId = model.ImplementerId;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ImplementerId = ImplementerId,
PrintedId = PrintedId,
Count = Count,
Sum = Sum,
@ -81,6 +86,7 @@ namespace TypographyFileImplement.Models
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("ClientId", ClientId),
new XElement("ImplementerId", ImplementerId),
new XElement("PrintedId", PrintedId),
new XElement("Count", Count),
new XElement("Sum", Sum.ToString()),

View File

@ -9,12 +9,14 @@ namespace TypographyListImplement
public List<Order> Orders { get; set; }
public List<Printed> Printeds { get; set; }
public List<Client> Clients { get; set; }
public List<Implementer> Implementers { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Printeds = new List<Printed>();
Clients = new List<Client>();
Implementers = new List<Implementer>();
}
public static DataListSingleton GetInstance()
{

View File

@ -0,0 +1,102 @@
using TypographyContracts.BindingModels;
using TypographyContracts.SearchModels;
using TypographyContracts.StoragesContracts;
using TypographyContracts.ViewModels;
using TypographyListImplement.Models;
namespace TypographyListImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
private readonly DataListSingleton _source;
public ImplementerStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ImplementerViewModel> GetFullList()
{
var result = new List<ImplementerViewModel>();
foreach (var implementer in _source.Implementers)
{
result.Add(implementer.GetViewModel);
}
return result;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
var result = new List<ImplementerViewModel>();
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
return result;
}
foreach (var implementer in _source.Implementers)
{
if (implementer.ImplementerFIO.Contains(model.ImplementerFIO))
{
result.Add(implementer.GetViewModel);
}
}
return result;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password))
{
return null;
}
foreach (var implementer in _source.Implementers)
{
if ((model.Id.HasValue && implementer.Id == model.Id) ||
(!string.IsNullOrEmpty(model.ImplementerFIO) && implementer.ImplementerFIO == model.ImplementerFIO &&
!string.IsNullOrEmpty(model.Password) && implementer.Password == model.Password))
{
return implementer.GetViewModel;
}
}
return null;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = 1;
foreach (var implementer in _source.Implementers)
{
if (model.Id <= implementer.Id)
{
model.Id = implementer.Id + 1;
}
}
var newImplementer = Implementer.Create(model);
if (newImplementer == null)
{
return null;
}
_source.Implementers.Add(newImplementer);
return newImplementer.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == model.Id)
{
implementer.Update(model);
return implementer.GetViewModel;
}
}
return null;
}
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;
}
}
}

View File

@ -25,19 +25,27 @@ namespace TypographyListImplement.Implements
private OrderViewModel DefineOthersNames(Order model)
{
OrderViewModel result = model.GetViewModel;
foreach (var order in _source.Clients)
foreach (var client in _source.Clients)
{
if (result.ClientId == order.Id)
if (result.ClientId == client.Id)
{
result.ClientFIO = order.ClientFIO;
result.ClientFIO = client.ClientFIO;
break;
}
}
foreach (var order in _source.Printeds)
foreach (var implementer in _source.Implementers)
{
if (result.PrintedId == order.Id)
if (result.ImplementerId == implementer.Id)
{
result.PrintedName = order.PrintedName;
result.ImplementerFIO = implementer.ImplementerFIO;
break;
}
}
foreach (var printed in _source.Printeds)
{
if (result.PrintedId == printed.Id)
{
result.PrintedName = printed.PrintedName;
break;
}
}
@ -46,14 +54,15 @@ namespace TypographyListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue)
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue)
{
return result;
}
foreach (var order in _source.Orders)
{
if ((model.DateFrom.HasValue && model.DateTo.HasValue && order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) ||
(model.ClientId.HasValue && order.ClientId == model.ClientId))
(model.ClientId.HasValue && order.ClientId == model.ClientId) ||
(model.Status.HasValue && order.Status == model.Status))
{
result.Add(DefineOthersNames(order));
}
@ -62,13 +71,14 @@ namespace TypographyListImplement.Implements
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue))
{
return null;
}
foreach (var order in _source.Orders)
{
if ((model.Id.HasValue && order.Id == model.Id) || (model.ClientId.HasValue && order.ClientId == model.ClientId))
if ((model.Id.HasValue && order.Id == model.Id) ||
(model.ImplementerId.HasValue && order.Id == model.ImplementerId && order.Status == model.Status))
{
return DefineOthersNames(order);
}

View File

@ -0,0 +1,49 @@
using TypographyDataModels.Models;
using TypographyContracts.BindingModels;
using TypographyContracts.ViewModels;
namespace TypographyListImplement.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
};
}
}

View File

@ -9,6 +9,7 @@ namespace TypographyListImplement.Models
{
public int Id { get; private set; }
public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
public int PrintedId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
@ -25,6 +26,7 @@ namespace TypographyListImplement.Models
{
Id = model.Id,
ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
PrintedId = model.PrintedId,
Count = model.Count,
Sum = model.Sum,
@ -40,12 +42,14 @@ namespace TypographyListImplement.Models
return;
}
Status = model.Status;
ImplementerId = model.ImplementerId;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ImplementerId = ImplementerId,
PrintedId = PrintedId,
Count = Count,
Sum = Sum,

View File

@ -0,0 +1,99 @@
using TypographyDataModels.Enums;
using TypographyContracts.BindingModels;
using TypographyContracts.BusinessLogicsContracts;
using TypographyContracts.SearchModels;
using TypographyContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace TypographyRestApi.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;
}
}
}
}

View File

@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<IPrintedStorage, PrintedStorage>();
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<IPrintedLogic, PrintedLogic>();
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle