complete lab work

This commit is contained in:
Viltskaa 2023-04-10 15:36:30 +04:00
parent 055e45b191
commit bbf06c417e
23 changed files with 1251 additions and 75 deletions

View File

@ -95,7 +95,8 @@ namespace SushiBar
ClientId = Convert.ToInt32(comboBoxClients.SelectedValue), ClientId = Convert.ToInt32(comboBoxClients.SelectedValue),
SushiName = comboBoxSushi.Text, SushiName = comboBoxSushi.Text,
Count = Convert.ToInt32(textBoxCount.Text), Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text) Sum = Convert.ToDouble(textBoxSum.Text),
ImplementerId = null
}) ; }) ;
if (!operationResult) if (!operationResult)
{ {

View File

@ -0,0 +1,167 @@
namespace SushiBar
{
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()
{
this.label1 = new System.Windows.Forms.Label();
this.textBoxFio = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBoxPassword = new System.Windows.Forms.TextBox();
this.numericUpDownExp = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.numericUpDownQul = new System.Windows.Forms.NumericUpDown();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownExp)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQul)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(25, 15);
this.label1.TabIndex = 0;
this.label1.Text = "FIO";
//
// textBoxFio
//
this.textBoxFio.Location = new System.Drawing.Point(43, 6);
this.textBoxFio.Name = "textBoxFio";
this.textBoxFio.Size = new System.Drawing.Size(196, 23);
this.textBoxFio.TabIndex = 1;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 41);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(57, 15);
this.label2.TabIndex = 2;
this.label2.Text = "Password";
//
// textBoxPassword
//
this.textBoxPassword.Location = new System.Drawing.Point(75, 38);
this.textBoxPassword.Name = "textBoxPassword";
this.textBoxPassword.Size = new System.Drawing.Size(164, 23);
this.textBoxPassword.TabIndex = 3;
//
// numericUpDownExp
//
this.numericUpDownExp.Location = new System.Drawing.Point(113, 67);
this.numericUpDownExp.Name = "numericUpDownExp";
this.numericUpDownExp.Size = new System.Drawing.Size(126, 23);
this.numericUpDownExp.TabIndex = 4;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 69);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(95, 15);
this.label3.TabIndex = 5;
this.label3.Text = "Work Experience";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(12, 98);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(75, 15);
this.label4.TabIndex = 6;
this.label4.Text = "Qualification";
//
// numericUpDownQul
//
this.numericUpDownQul.Location = new System.Drawing.Point(93, 96);
this.numericUpDownQul.Name = "numericUpDownQul";
this.numericUpDownQul.Size = new System.Drawing.Size(146, 23);
this.numericUpDownQul.TabIndex = 7;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 126);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(114, 23);
this.buttonSave.TabIndex = 8;
this.buttonSave.Text = "Save";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(132, 126);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(107, 23);
this.buttonCancel.TabIndex = 9;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormImplementer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(245, 157);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.numericUpDownQul);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.numericUpDownExp);
this.Controls.Add(this.textBoxPassword);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBoxFio);
this.Controls.Add(this.label1);
this.Name = "FormImplementer";
this.Text = "FormImplementer";
this.Load += new System.EventHandler(this.FormImplementer_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownExp)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQul)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label label1;
private TextBox textBoxFio;
private Label label2;
private TextBox textBoxPassword;
private NumericUpDown numericUpDownExp;
private Label label3;
private Label label4;
private NumericUpDown numericUpDownQul;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,108 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBar
{
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 ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
MessageBox.Show("Fill password", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxFio.Text))
{
MessageBox.Show("Fill fio", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Saving");
try
{
var model = new ImplementerBindingModel
{
Id = _id ?? 0,
ImplementerFio = textBoxFio.Text,
Password = textBoxPassword.Text,
Qualification = (int)numericUpDownQul.Value,
WorkExperience = (int)numericUpDownExp.Value,
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Error on saving. Additional info below");
}
MessageBox.Show("Good", "Info",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on save");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormImplementer_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Getting implementer");
var view = _logic.ReadElement(new ImplementerSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxFio.Text = view.ImplementerFio;
textBoxPassword.Text = view.Password;
numericUpDownQul.Value = view.Qualification;
numericUpDownExp.Value = view.WorkExperience;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on getting implementer");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
}

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,114 @@
namespace SushiBar
{
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()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonEdit = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonReload = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(648, 426);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(666, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(122, 23);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Add";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonEdit
//
this.buttonEdit.Location = new System.Drawing.Point(666, 41);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(122, 23);
this.buttonEdit.TabIndex = 2;
this.buttonEdit.Text = "Edit";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(666, 70);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(122, 23);
this.buttonDelete.TabIndex = 3;
this.buttonDelete.Text = "Delete";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// buttonReload
//
this.buttonReload.Location = new System.Drawing.Point(666, 99);
this.buttonReload.Name = "buttonReload";
this.buttonReload.Size = new System.Drawing.Size(122, 23);
this.buttonReload.TabIndex = 4;
this.buttonReload.Text = "Reload";
this.buttonReload.UseVisualStyleBackColor = true;
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
//
// FormImplementers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonReload);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormImplementers";
this.Text = "FormImplementers";
this.Load += new System.EventHandler(this.FormImplementers_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonEdit;
private Button buttonDelete;
private Button buttonReload;
}
}

View File

@ -0,0 +1,108 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar
{
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 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 ButtonEdit_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Delete record?", "Question",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Deleting");
try
{
if (!_logic.Delete(new ImplementerBindingModel
{
Id = id
}))
{
throw new Exception("Error on delete. Addtional info below");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on delete");
MessageBox.Show(ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonReload_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormImplementers_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ImplementerFio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Load implementers");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on load");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}

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,18 @@
this.directoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.directoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.implementersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.listComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsOnSushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentsOnSushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.listOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listOrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.startWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonSubmit = new System.Windows.Forms.Button(); this.buttonSubmit = new System.Windows.Forms.Button();
this.buttonReady = new System.Windows.Forms.Button(); this.buttonReady = new System.Windows.Forms.Button();
this.buttonIssue = new System.Windows.Forms.Button(); this.buttonIssue = new System.Windows.Forms.Button();
this.buttonReload = new System.Windows.Forms.Button(); this.buttonReload = new System.Windows.Forms.Button();
this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -53,17 +55,18 @@
this.dataGridView.Location = new System.Drawing.Point(12, 27); this.dataGridView.Location = new System.Drawing.Point(12, 27);
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25; this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(796, 411); this.dataGridView.Size = new System.Drawing.Size(1277, 411);
this.dataGridView.TabIndex = 0; this.dataGridView.TabIndex = 0;
// //
// menuStrip1 // menuStrip1
// //
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.directoryToolStripMenuItem, this.directoryToolStripMenuItem,
this.reportsToolStripMenuItem}); this.reportsToolStripMenuItem,
this.startWorkToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(940, 24); this.menuStrip1.Size = new System.Drawing.Size(1421, 24);
this.menuStrip1.TabIndex = 1; this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1"; this.menuStrip1.Text = "menuStrip1";
// //
@ -72,7 +75,8 @@
this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.componentsToolStripMenuItem, this.componentsToolStripMenuItem,
this.sushiToolStripMenuItem, this.sushiToolStripMenuItem,
this.clientsToolStripMenuItem}); this.clientsToolStripMenuItem,
this.implementersToolStripMenuItem});
this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem"; this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem";
this.directoryToolStripMenuItem.Size = new System.Drawing.Size(67, 20); this.directoryToolStripMenuItem.Size = new System.Drawing.Size(67, 20);
this.directoryToolStripMenuItem.Text = "Directory"; this.directoryToolStripMenuItem.Text = "Directory";
@ -80,17 +84,31 @@
// componentsToolStripMenuItem // componentsToolStripMenuItem
// //
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.componentsToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
this.componentsToolStripMenuItem.Text = "Components"; this.componentsToolStripMenuItem.Text = "Components";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
// //
// sushiToolStripMenuItem // sushiToolStripMenuItem
// //
this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.sushiToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
this.sushiToolStripMenuItem.Text = "Sushi"; this.sushiToolStripMenuItem.Text = "Sushi";
this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
// //
// clientsToolStripMenuItem
//
this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
this.clientsToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
this.clientsToolStripMenuItem.Text = "Clients";
this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
//
// implementersToolStripMenuItem
//
this.implementersToolStripMenuItem.Name = "implementersToolStripMenuItem";
this.implementersToolStripMenuItem.Size = new System.Drawing.Size(147, 22);
this.implementersToolStripMenuItem.Text = "Implementers";
this.implementersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
//
// reportsToolStripMenuItem // reportsToolStripMenuItem
// //
this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -122,9 +140,16 @@
this.listOrdersToolStripMenuItem.Text = "List Orders"; this.listOrdersToolStripMenuItem.Text = "List Orders";
this.listOrdersToolStripMenuItem.Click += new System.EventHandler(this.ListOrdersToolStripMenuItem_Click); this.listOrdersToolStripMenuItem.Click += new System.EventHandler(this.ListOrdersToolStripMenuItem_Click);
// //
// startWorkToolStripMenuItem
//
this.startWorkToolStripMenuItem.Name = "startWorkToolStripMenuItem";
this.startWorkToolStripMenuItem.Size = new System.Drawing.Size(72, 20);
this.startWorkToolStripMenuItem.Text = "Start work";
this.startWorkToolStripMenuItem.Click += new System.EventHandler(this.StartWorkToolStripMenuItem_Click);
//
// buttonCreateOrder // buttonCreateOrder
// //
this.buttonCreateOrder.Location = new System.Drawing.Point(814, 27); this.buttonCreateOrder.Location = new System.Drawing.Point(1295, 27);
this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(114, 23); this.buttonCreateOrder.Size = new System.Drawing.Size(114, 23);
this.buttonCreateOrder.TabIndex = 2; this.buttonCreateOrder.TabIndex = 2;
@ -134,7 +159,7 @@
// //
// buttonSubmit // buttonSubmit
// //
this.buttonSubmit.Location = new System.Drawing.Point(814, 56); this.buttonSubmit.Location = new System.Drawing.Point(1295, 56);
this.buttonSubmit.Name = "buttonSubmit"; this.buttonSubmit.Name = "buttonSubmit";
this.buttonSubmit.Size = new System.Drawing.Size(114, 23); this.buttonSubmit.Size = new System.Drawing.Size(114, 23);
this.buttonSubmit.TabIndex = 3; this.buttonSubmit.TabIndex = 3;
@ -144,7 +169,7 @@
// //
// buttonReady // buttonReady
// //
this.buttonReady.Location = new System.Drawing.Point(814, 85); this.buttonReady.Location = new System.Drawing.Point(1295, 85);
this.buttonReady.Name = "buttonReady"; this.buttonReady.Name = "buttonReady";
this.buttonReady.Size = new System.Drawing.Size(114, 23); this.buttonReady.Size = new System.Drawing.Size(114, 23);
this.buttonReady.TabIndex = 4; this.buttonReady.TabIndex = 4;
@ -154,7 +179,7 @@
// //
// buttonIssue // buttonIssue
// //
this.buttonIssue.Location = new System.Drawing.Point(814, 114); this.buttonIssue.Location = new System.Drawing.Point(1295, 114);
this.buttonIssue.Name = "buttonIssue"; this.buttonIssue.Name = "buttonIssue";
this.buttonIssue.Size = new System.Drawing.Size(114, 23); this.buttonIssue.Size = new System.Drawing.Size(114, 23);
this.buttonIssue.TabIndex = 5; this.buttonIssue.TabIndex = 5;
@ -164,7 +189,7 @@
// //
// buttonReload // buttonReload
// //
this.buttonReload.Location = new System.Drawing.Point(814, 143); this.buttonReload.Location = new System.Drawing.Point(1295, 143);
this.buttonReload.Name = "buttonReload"; this.buttonReload.Name = "buttonReload";
this.buttonReload.Size = new System.Drawing.Size(114, 23); this.buttonReload.Size = new System.Drawing.Size(114, 23);
this.buttonReload.TabIndex = 6; this.buttonReload.TabIndex = 6;
@ -172,18 +197,11 @@
this.buttonReload.UseVisualStyleBackColor = true; this.buttonReload.UseVisualStyleBackColor = true;
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click); this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
// //
// clientsToolStripMenuItem
//
this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.clientsToolStripMenuItem.Text = "Clients";
this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
//
// FormMain // FormMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(940, 450); this.ClientSize = new System.Drawing.Size(1421, 450);
this.Controls.Add(this.buttonReload); this.Controls.Add(this.buttonReload);
this.Controls.Add(this.buttonIssue); this.Controls.Add(this.buttonIssue);
this.Controls.Add(this.buttonReady); this.Controls.Add(this.buttonReady);
@ -220,5 +238,7 @@
private ToolStripMenuItem componentsOnSushiToolStripMenuItem; private ToolStripMenuItem componentsOnSushiToolStripMenuItem;
private ToolStripMenuItem listOrdersToolStripMenuItem; private ToolStripMenuItem listOrdersToolStripMenuItem;
private ToolStripMenuItem clientsToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem;
private ToolStripMenuItem startWorkToolStripMenuItem;
private ToolStripMenuItem implementersToolStripMenuItem;
} }
} }

View File

@ -12,12 +12,18 @@ namespace SushiBar
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic; 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(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_workProcess = workProcess;
} }
private void LoadData() private void LoadData()
@ -31,6 +37,7 @@ namespace SushiBar
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["SushiId"].Visible = false; dataGridView.Columns["SushiId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
dataGridView.Columns["ClientFio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientFio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
} }
} }
@ -218,5 +225,20 @@ namespace SushiBar
form.ShowDialog(); form.ShowDialog();
} }
} }
private void StartWorkToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
MessageBox.Show("Process work is started", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
}
} }
} }

View File

@ -35,12 +35,15 @@ namespace SushiBar
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ISushiStorage, SushiStorage>(); services.AddTransient<ISushiStorage, SushiStorage>();
services.AddTransient<IClientStorage, ClientStorage>(); services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISushiLogic, SushiLogic>(); services.AddTransient<ISushiLogic, SushiLogic>();
services.AddTransient<IReportLogic, ReportLogic>(); services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>(); services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>(); services.AddTransient<AbstractSaveToWord, SaveToWord>();
@ -55,6 +58,8 @@ namespace SushiBar
services.AddTransient<FormReportOrders>(); services.AddTransient<FormReportOrders>();
services.AddTransient<FormSushiOnComponents>(); services.AddTransient<FormSushiOnComponents>();
services.AddTransient<FormClients>(); services.AddTransient<FormClients>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormImplementer>();
} }
} }
} }

View File

@ -0,0 +1,123 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
namespace SushiBarBusinessLogic.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. FIO:{FIO}.Id:{ Id}",
model.ImplementerFio, model.Id);
var element = _implementerStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
{
_logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFio, model?.Id);
var list = (model == null) ? _implementerStorage.GetFullList() :
_implementerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.WorkExperience < 0)
{
throw new ArgumentException(nameof(model.WorkExperience));
}
if (model.Qualification < 0)
{
throw new ArgumentException(nameof(model.Qualification));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException(nameof(model.ImplementerFio));
}
if (string.IsNullOrEmpty(model.ImplementerFio))
{
throw new ArgumentNullException(nameof(model.ImplementerFio));
}
_logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFio);
var element = _implementerStorage.GetElement(new ImplementerSearchModel
{
ImplementerFio = model.ImplementerFio,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Исполнитель с таким фио уже есть");
}
}
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging; using DocumentFormat.OpenXml.EMMA;
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels; using SushiBarContracts.SearchModels;
@ -83,24 +84,34 @@ namespace SushiBarBusinessLogic.BusinessLogics
private bool UpdateStatus(OrderBindingModel model, OrderStatus status) private bool UpdateStatus(OrderBindingModel model, OrderStatus status)
{ {
CheckModel(model);
var order = _orderStorage.GetElement(new OrderSearchModel() { Id = model.Id }); var order = _orderStorage.GetElement(new OrderSearchModel() { Id = model.Id });
if (model.Status + 1 != status) if (order == null)
{
throw new ArgumentNullException(nameof(order));
}
if (order.Status + 1 != status)
{ {
_logger.LogWarning("Status update operation failed"); _logger.LogWarning("Status update operation failed");
return false; return false;
} }
model.Status = status; model.Status = status;
model.DateImplement = order?.DateImplement; model.DateCreate = order.DateCreate;
if (model.Status == OrderStatus.Ready) if (model.DateImplement == null)
model.DateImplement = order.DateImplement;
if (order.ImplementerId.HasValue)
model.ImplementerId = order.ImplementerId;
if (model.Status == OrderStatus.Issued)
{ {
model.DateImplement = DateTime.Now; model.DateImplement = DateTime.Now;
} }
model.ClientId = order.ClientId;
model.SushiId = order.SushiId;
model.Sum = order.Sum;
model.Count = order.Count;
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
model.Status--;
_logger.LogWarning("Update operation failed"); _logger.LogWarning("Update operation failed");
return false; return false;
} }

View File

@ -29,7 +29,8 @@ public class WorkModeling : IWorkProcess
_logger.LogWarning("DoWork. Implementers is null"); _logger.LogWarning("DoWork. Implementers is null");
return; return;
} }
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Accepted });
var orders = _orderLogic.ReadList(new OrderSearchModel { Status = new() { OrderStatus.Accepted, OrderStatus.Performed } });
if (orders == null || orders.Count == 0) if (orders == null || orders.Count == 0)
{ {
_logger.LogWarning("DoWork. Orders is null or empty"); _logger.LogWarning("DoWork. Orders is null or empty");
@ -49,7 +50,7 @@ public class WorkModeling : IWorkProcess
{ {
return; return;
} }
await RunOrderInWork(implementer); await RunOrderInWork(implementer, orders);
await Task.Run(() => await Task.Run(() =>
{ {
foreach (var order in orders) foreach (var order in orders)
@ -62,8 +63,7 @@ public class WorkModeling : IWorkProcess
Id = order.Id, Id = order.Id,
ImplementerId = implementer.Id ImplementerId = implementer.Id
}); });
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
1000) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.FinishOrder(new OrderBindingModel _orderLogic.FinishOrder(new OrderBindingModel
{ {
@ -84,40 +84,37 @@ public class WorkModeling : IWorkProcess
}); });
} }
private async Task RunOrderInWork(ImplementerViewModel implementer) private async Task RunOrderInWork(ImplementerViewModel implementer, List<OrderViewModel> allOrders)
{ {
if (_orderLogic == null) if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0)
{ {
return; return;
} }
try try
{ {
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Performed));
OrderSearchModel
{
ImplementerId = implementer.Id,
Status = OrderStatus.Performed
}));
if (runOrder == null) if (runOrder == null)
{ {
return; return;
} }
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}",
implementer.Id, runOrder.Id); _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) *
runOrder.Count); Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
implementer.Id, runOrder.Id); _orderLogic.DeliveryOrder(new OrderBindingModel
_orderLogic.FinishOrder(new OrderBindingModel
{ {
Id = runOrder.Id Id = runOrder.Id
}); });
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
} }
catch (InvalidOperationException ex) catch (InvalidOperationException ex)
{ {
_logger.LogWarning(ex, "Error try get work"); _logger.LogWarning(ex, "Error try get work");
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Error while do work"); _logger.LogError(ex, "Error while do work");

View File

@ -8,7 +8,7 @@ namespace SushiBarContracts.BindingModels
public int Id { get; set; } public int Id { get; set; }
public int SushiId { get; set; } public int SushiId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int ImplementerId { get; set; } public int? ImplementerId { get; set; }
public string ClientFio { get; set; } = string.Empty; public string ClientFio { get; set; } = string.Empty;
public string SushiName { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty;
public int Count { get; set; } public int Count { get; set; }

View File

@ -1,4 +1,5 @@
using SushiBarContracts.SearchModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
namespace SushiBarContracts.BusinessLogicsContracts; namespace SushiBarContracts.BusinessLogicsContracts;
@ -7,7 +8,7 @@ public interface IImplementerLogic
{ {
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model); List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
ImplementerViewModel? ReadElement(ImplementerSearchModel model); ImplementerViewModel? ReadElement(ImplementerSearchModel model);
bool Create(ImplementerSearchModel model); bool Create(ImplementerBindingModel model);
bool Update(ImplementerSearchModel model); bool Update(ImplementerBindingModel model);
bool Delete(ImplementerSearchModel model); bool Delete(ImplementerBindingModel model);
} }

View File

@ -9,6 +9,6 @@ namespace SushiBarContracts.SearchModels
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public int? ClientId { get; set; } public int? ClientId { get; set; }
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
public OrderStatus Status { get; set; } public List<OrderStatus> Status { get; set; }
} }
} }

View File

@ -11,7 +11,7 @@ namespace SushiBarContracts.ViewModels
public int SushiId { get; init; } public int SushiId { get; init; }
public int ClientId { get; init; } public int ClientId { get; init; }
public int ImplementerId { get; set; } public int? ImplementerId { get; set; }
[DisplayName("Client FIO")] [DisplayName("Client FIO")]
public string ClientFio { get; init; } = string.Empty; public string ClientFio { get; init; } = string.Empty;

View File

@ -4,6 +4,7 @@ using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts; using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
using SushiBarDatabaseImplement.Models; using SushiBarDatabaseImplement.Models;
using SushiBarDataModels.Enums;
namespace SushiBarDatabaseImplement.Implements namespace SushiBarDatabaseImplement.Implements
{ {
@ -33,30 +34,52 @@ namespace SushiBarDatabaseImplement.Implements
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();
return context.Orders return context.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) .Include(x => x.Client)
?.GetViewModel; .Include(x => x.Implementer)
.FirstOrDefault(x =>
(model.Status == null || model.Status != null && model.Status.Contains(x.Status)) &&
model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId ||
model.Id.HasValue && x.Id == model.Id
)
?.GetViewModel;
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel? model) public List<OrderViewModel> GetFilteredList(OrderSearchModel? model)
{ {
if (model is null) if (model.Id.HasValue)
return new List<OrderViewModel>();
using var context = new SushiBarDatabase();
if (model.ClientId.HasValue)
{ {
return context.Orders var result = GetElement(model);
.Include(x => x.Client) return result != null ? new() { result } : new();
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
} }
return context.Orders using var context = new SushiBarDatabase();
.Include(x => x.Sushi) IQueryable<Order>? queryWhere = null;
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel) if (model.DateFrom.HasValue && model.DateTo.HasValue)
.ToList(); {
queryWhere = context.Orders
.Where(x => model.DateFrom <= x.DateCreate.Date &&
x.DateCreate.Date <= model.DateTo);
}
else if (model.Status != null)
{
queryWhere = context.Orders
.Where(x => model.Status.Contains(x.Status));
}
else if (model.ClientId.HasValue)
{
queryWhere = context.Orders
.Where(x => x.ClientId == model.ClientId);
}
else
{
return new();
}
return queryWhere
.Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel)
.ToList();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()

View File

@ -0,0 +1,251 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SushiBarDatabaseImplement;
#nullable disable
namespace SushiBarDatabaseImplement.Migrations
{
[DbContext(typeof(SushiBarDatabase))]
[Migration("20230410100751_lab6")]
partial class lab6
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("SushiBarDatabaseImplement.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("SushiBarDatabaseImplement.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("SushiBarDatabaseImplement.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("SushiBarDatabaseImplement.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?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("Sum")
.HasColumnType("float");
b.Property<int>("SushiId")
.HasColumnType("int");
b.Property<string>("SushiName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("SushiId");
b.ToTable("Orders");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("SushiName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", 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>("SushiId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("SushiId");
b.ToTable("SushiComponents");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer")
.WithMany()
.HasForeignKey("ImplementerId");
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
.WithMany("Orders")
.HasForeignKey("SushiId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component")
.WithMany("SushiComponent")
.HasForeignKey("ComponentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
.WithMany("Components")
.HasForeignKey("SushiId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b =>
{
b.Navigation("SushiComponent");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
{
b.Navigation("Components");
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,67 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SushiBarDatabaseImplement.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");
}
}
}

View File

@ -67,6 +67,33 @@ namespace SushiBarDatabaseImplement.Migrations
b.ToTable("Components"); b.ToTable("Components");
}); });
modelBuilder.Entity("SushiBarDatabaseImplement.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("SushiBarDatabaseImplement.Models.Order", b => modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -87,6 +114,9 @@ namespace SushiBarDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
@ -104,6 +134,8 @@ namespace SushiBarDatabaseImplement.Migrations
b.HasIndex("ClientId"); b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.HasIndex("SushiId"); b.HasIndex("SushiId");
b.ToTable("Orders"); b.ToTable("Orders");
@ -163,6 +195,10 @@ namespace SushiBarDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Implementer", "Implementer")
.WithMany()
.HasForeignKey("ImplementerId");
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("SushiId") .HasForeignKey("SushiId")
@ -171,6 +207,8 @@ namespace SushiBarDatabaseImplement.Migrations
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Implementer");
b.Navigation("Sushi"); b.Navigation("Sushi");
}); });

View File

@ -15,7 +15,7 @@ namespace SushiBarDatabaseImplement.Models
[Required] [Required]
public int ClientId { get; private set; } public int ClientId { get; private set; }
public int ImplementerId { get; private set; } public int? ImplementerId { get; private set; } = null;
public string SushiName { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty;
@ -95,7 +95,7 @@ namespace SushiBarDatabaseImplement.Models
Status = Status, Status = Status,
ClientFio = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFio ?? string.Empty, ClientFio = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFio ?? string.Empty,
SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty, SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty,
ImplementerFio = Implementer?.ImplementerFio ?? string.Empty ImplementerFio = context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFio ?? string.Empty,
}; };
} } } }
} }

View File

@ -12,7 +12,7 @@ namespace SushiBarFileImplement.Models
public string SushiName { get; private set; } = string.Empty; public string SushiName { get; private set; } = string.Empty;
public int SushiId { get; private set; } public int SushiId { get; private set; }
public int ClientId { get; } public int ClientId { get; }
public int ImplementerId { get; set; } public int? ImplementerId { get; set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Unknown; public OrderStatus Status { get; private set; } = OrderStatus.Unknown;