Compare commits

...

32 Commits

Author SHA1 Message Date
3b5ed82b3f complete lab 2023-04-21 18:44:15 +04:00
e3c8540c6f Complete lab 2023-04-11 11:12:55 +04:00
6dca3efbb7 Add new order + fix 2023-04-11 08:33:53 +04:00
8e73008033 Merge branch 'LabWork_4' into LabWork_4_hard
# Conflicts:
#	SushiBar/SushiBar/FormMain.Designer.cs
#	SushiBar/SushiBar/FormMain.cs
#	SushiBar/SushiBar/Program.cs
2023-04-10 22:16:15 +04:00
31b569c848 delete .idea 2023-03-28 10:11:45 +04:00
d8422b1ef1 Complete hard lab 3 2023-03-28 10:06:56 +04:00
c46aebdc08 Complete hard lab 3 2023-03-27 19:12:26 +04:00
e19bbc11d1 Merge branch 'LabWork_3' into LabWork_3_hard
# Conflicts:
#	SushiBar/SushiBar/FormMain.Designer.cs
2023-03-27 18:20:02 +04:00
48e89f3b9f Delete .idea 2023-03-15 21:43:56 +04:00
a44b0f052d complete lab 2 hard 2023-03-14 10:46:34 +04:00
55c5aedfd2 ready lab work 2023-03-14 10:12:32 +04:00
56ad2da264 Report Logic 2023-03-12 20:56:37 +04:00
b9747e4e18 b_logic + contracts 2023-03-12 20:49:40 +04:00
40a93a182a 2 hard lab 2023-03-11 21:23:26 +04:00
a46c723d58 Merge branch 'LabWork_2' into LabWork_2_hard 2023-02-28 08:58:17 +04:00
9b712685ba Edit main form
Complete lab 3
2023-02-27 17:15:26 +04:00
45235c7a82 add database 2023-02-27 17:07:02 +04:00
153d212184 last fix 2023-02-14 22:45:26 +04:00
6c5c4607cf last fix 2023-02-14 22:44:19 +04:00
4b9f66ba35 fix 2023-02-14 10:17:42 +04:00
0851de65f5 fix 2023-02-14 10:05:38 +04:00
16d53bc9ec Complete 2023-02-13 19:08:26 +04:00
8edde4a4fc add project SushiBarFileImplements 2023-02-13 18:45:25 +04:00
b7ccba8acc Complete lab 1 hard 2023-02-13 16:48:36 +04:00
665aaab1a6 additional class for store 2023-02-13 15:35:09 +04:00
ae4eef9254 add new models for store 2023-02-13 15:18:58 +04:00
9399daba9e Bug fix 2023-01-31 20:14:33 +04:00
d7f9f16b23 complete 2023-01-31 01:11:18 +04:00
10a579904a add listImplenets 2023-01-30 23:13:26 +04:00
a6bcc01785 add Business logic part 2023-01-30 19:25:38 +04:00
3e25205bf6 Switch product to sushi 2023-01-30 18:27:32 +04:00
a87d95c92b Add Models and Contracts 2023-01-30 18:15:58 +04:00
146 changed files with 10809 additions and 56 deletions

View File

@ -3,7 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32819.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBar", "SushiBar\SushiBar.csproj", "{DB81A759-B157-477C-9281-EE358968519D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBar", "SushiBar\SushiBar.csproj", "{DB81A759-B157-477C-9281-EE358968519D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "SushiBarModels\SushiBarDataModels.csproj", "{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1185D549-D227-4BE3-8EAD-D294029BCA5D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{A273021E-72E7-4C23-927C-A3E4851BD8D1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushibarListImplement", "SushibarListImplement\SushibarListImplement.csproj", "{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarFileImplement", "SushiBarFileImplement\SushiBarFileImplement.csproj", "{E55FF400-876B-4E35-8536-E099241195B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +27,30 @@ Global
{DB81A759-B157-477C-9281-EE358968519D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB81A759-B157-477C-9281-EE358968519D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB81A759-B157-477C-9281-EE358968519D}.Release|Any CPU.Build.0 = Release|Any CPU
{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFB2D9F9-EA44-4E61-B6BE-5A2AA3C6AF07}.Release|Any CPU.Build.0 = Release|Any CPU
{1185D549-D227-4BE3-8EAD-D294029BCA5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1185D549-D227-4BE3-8EAD-D294029BCA5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1185D549-D227-4BE3-8EAD-D294029BCA5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1185D549-D227-4BE3-8EAD-D294029BCA5D}.Release|Any CPU.Build.0 = Release|Any CPU
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A273021E-72E7-4C23-927C-A3E4851BD8D1}.Release|Any CPU.Build.0 = Release|Any CPU
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BA388CC-72A1-47FE-A1DC-56C6A95D2F09}.Release|Any CPU.Build.0 = Release|Any CPU
{E55FF400-876B-4E35-8536-E099241195B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E55FF400-876B-4E35-8536-E099241195B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E55FF400-876B-4E35-8536-E099241195B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E55FF400-876B-4E35-8536-E099241195B8}.Release|Any CPU.Build.0 = Release|Any CPU
{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E59EEFE-0146-4AFB-BA8C-18F2D8F8D22D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,39 +0,0 @@
namespace SushiBar
{
partial class Form1
{
/// <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.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace SushiBar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,121 @@
namespace SushiBar
{
partial class FormComponent
{
/// <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.textBoxName = new System.Windows.Forms.TextBox();
this.labelName = new System.Windows.Forms.Label();
this.labelCost = new System.Windows.Forms.Label();
this.textBoxCost = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(57, 6);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(270, 23);
this.textBoxName.TabIndex = 0;
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(12, 9);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(39, 15);
this.labelName.TabIndex = 1;
this.labelName.Text = "Name";
//
// labelCost
//
this.labelCost.AutoSize = true;
this.labelCost.Location = new System.Drawing.Point(12, 36);
this.labelCost.Name = "labelCost";
this.labelCost.Size = new System.Drawing.Size(31, 15);
this.labelCost.TabIndex = 2;
this.labelCost.Text = "Cost";
//
// textBoxCost
//
this.textBoxCost.Location = new System.Drawing.Point(57, 33);
this.textBoxCost.Name = "textBoxCost";
this.textBoxCost.Size = new System.Drawing.Size(270, 23);
this.textBoxCost.TabIndex = 3;
//
// buttonSave
//
this.buttonSave.BackColor = System.Drawing.SystemColors.Control;
this.buttonSave.Location = new System.Drawing.Point(12, 62);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(153, 23);
this.buttonSave.TabIndex = 4;
this.buttonSave.Text = "Save";
this.buttonSave.UseVisualStyleBackColor = false;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.BackColor = System.Drawing.SystemColors.Control;
this.buttonCancel.Location = new System.Drawing.Point(171, 62);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(156, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = false;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormComponent
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(339, 93);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCost);
this.Controls.Add(this.labelCost);
this.Controls.Add(this.labelName);
this.Controls.Add(this.textBoxName);
this.Name = "FormComponent";
this.Text = "FormComponent";
this.Load += new System.EventHandler(this.FormComponent_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxName;
private Label labelName;
private Label labelCost;
private TextBox textBoxCost;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,84 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
namespace SushiBar
{
public partial class FormComponent : Form
{
private readonly ILogger _logger;
private readonly IComponentLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Fill name text box", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Saving Component");
try
{
var model = new ComponentBindingModel
{
Id = _id ?? 0,
ComponentName = textBoxName.Text,
Cost = Convert.ToDouble(textBoxCost.Text)
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
throw new Exception("Error on saving. Additional info below.");
}
MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on saving");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void FormComponent_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Get component");
var view = _logic.ReadElement(new ComponentSearchModel{ Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.ComponentName;
textBoxCost.Text = view.Cost.ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in getting cpmponent");
MessageBox.Show(ex.Message, "Error", 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,114 @@
namespace SushiBar
{
partial class FormComponents
{
/// <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.buttonRemove = 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(612, 426);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(630, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(158, 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(630, 41);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(158, 23);
this.buttonEdit.TabIndex = 2;
this.buttonEdit.Text = "Edit";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
//
// buttonRemove
//
this.buttonRemove.Location = new System.Drawing.Point(630, 70);
this.buttonRemove.Name = "buttonRemove";
this.buttonRemove.Size = new System.Drawing.Size(158, 23);
this.buttonRemove.TabIndex = 3;
this.buttonRemove.Text = "Remove";
this.buttonRemove.UseVisualStyleBackColor = true;
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
//
// buttonReload
//
this.buttonReload.Location = new System.Drawing.Point(630, 99);
this.buttonReload.Name = "buttonReload";
this.buttonReload.Size = new System.Drawing.Size(158, 23);
this.buttonReload.TabIndex = 4;
this.buttonReload.Text = "Reload";
this.buttonReload.UseVisualStyleBackColor = true;
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
//
// FormComponents
//
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.buttonRemove);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormComponents";
this.Text = "Form1";
this.Load += new System.EventHandler(this.FormComponents_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonEdit;
private Button buttonRemove;
private Button buttonReload;
}
}

View File

@ -0,0 +1,105 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar
{
public partial class FormComponents : Form
{
private readonly ILogger _logger;
private readonly IComponentLogic _logic;
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent 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(FormComponent));
if (service is FormComponent form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonRemove_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("Delete component");
try
{
if (!_logic.Delete(new ComponentBindingModel
{
Id = id
}))
{
throw new Exception("Error on deleting. Additional info below.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error delete component");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonReload_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormComponents_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["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Load components");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error load components");
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,144 @@
namespace SushiBar
{
partial class FormCreateOrder
{
/// <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.labelSushi = new System.Windows.Forms.Label();
this.comboBoxSushi = new System.Windows.Forms.ComboBox();
this.labelCount = new System.Windows.Forms.Label();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.labelSum = new System.Windows.Forms.Label();
this.textBoxSum = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelSushi
//
this.labelSushi.AutoSize = true;
this.labelSushi.Location = new System.Drawing.Point(12, 9);
this.labelSushi.Name = "labelSushi";
this.labelSushi.Size = new System.Drawing.Size(35, 15);
this.labelSushi.TabIndex = 0;
this.labelSushi.Text = "Sushi";
//
// comboBoxSushi
//
this.comboBoxSushi.FormattingEnabled = true;
this.comboBoxSushi.Location = new System.Drawing.Point(53, 6);
this.comboBoxSushi.Name = "comboBoxSushi";
this.comboBoxSushi.Size = new System.Drawing.Size(197, 23);
this.comboBoxSushi.TabIndex = 1;
this.comboBoxSushi.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSushi_SelectedIndexChanged);
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(12, 41);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(40, 15);
this.labelCount.TabIndex = 2;
this.labelCount.Text = "Count";
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(53, 38);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(197, 23);
this.textBoxCount.TabIndex = 3;
this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged);
//
// labelSum
//
this.labelSum.AutoSize = true;
this.labelSum.Location = new System.Drawing.Point(12, 74);
this.labelSum.Name = "labelSum";
this.labelSum.Size = new System.Drawing.Size(31, 15);
this.labelSum.TabIndex = 4;
this.labelSum.Text = "Sum";
//
// textBoxSum
//
this.textBoxSum.Location = new System.Drawing.Point(53, 71);
this.textBoxSum.Name = "textBoxSum";
this.textBoxSum.Size = new System.Drawing.Size(197, 23);
this.textBoxSum.TabIndex = 5;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 100);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(105, 23);
this.buttonSave.TabIndex = 6;
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(123, 100);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(127, 23);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormCreateOrder
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(262, 130);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxSum);
this.Controls.Add(this.labelSum);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.comboBoxSushi);
this.Controls.Add(this.labelSushi);
this.Name = "FormCreateOrder";
this.Text = "FormCreateOrder";
this.Load += new System.EventHandler(this.FormCreateOrder_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelSushi;
private ComboBox comboBoxSushi;
private Label labelCount;
private TextBox textBoxCount;
private Label labelSum;
private TextBox textBoxSum;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,122 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
namespace SushiBar
{
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly ISushiLogic _logicP;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISushiLogic logicP, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicO = logicO;
}
private void CalcSum()
{
if (comboBoxSushi.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxSushi.SelectedValue);
var sushi = _logicP.ReadElement(new SushiSearchModel { Id = id });
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), 2).ToString();
_logger.LogInformation("Calculating sum of order");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on calculating sum of order");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
try
{
var list = _logicP.ReadList(null);
if (list != null)
{
comboBoxSushi.DisplayMember = "SushiName";
comboBoxSushi.ValueMember = "Id";
comboBoxSushi.DataSource = list;
comboBoxSushi.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on loading sushi");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Fill in text box count", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSushi.SelectedValue == null)
{
MessageBox.Show("Select sushi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Create order");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue),
SushiName = comboBoxSushi.Text,
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});
if (!operationResult)
{
throw new Exception("Error on creating order. Additional info below.");
}
MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on saving");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Load sushi for order");
LoadData();
}
private void TextBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ComboBoxSushi_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
}
}

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>

280
SushiBar/SushiBar/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,280 @@
namespace SushiBar
{
partial class FormMain
{
/// <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.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.directoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.storesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.listComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsOnSushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.orderListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonSubmit = new System.Windows.Forms.Button();
this.buttonReady = new System.Windows.Forms.Button();
this.buttonIssue = new System.Windows.Forms.Button();
this.buttonReload = new System.Windows.Forms.Button();
this.buttonSell = new System.Windows.Forms.Button();
this.buttonSupply = new System.Windows.Forms.Button();
this.storeListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.storeWorkloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.orderListWithGroupByToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(796, 411);
this.dataGridView.TabIndex = 0;
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.directoryToolStripMenuItem,
this.reportsToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(937, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
//
// directoryToolStripMenuItem
//
this.directoryToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.componentsToolStripMenuItem,
this.sushiToolStripMenuItem,
this.storesToolStripMenuItem});
this.directoryToolStripMenuItem.Name = "directoryToolStripMenuItem";
this.directoryToolStripMenuItem.Size = new System.Drawing.Size(67, 20);
this.directoryToolStripMenuItem.Text = "Directory";
//
// componentsToolStripMenuItem
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
this.componentsToolStripMenuItem.Text = "Components";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// sushiToolStripMenuItem
//
this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
this.sushiToolStripMenuItem.Text = "Sushi";
this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
//
// storesToolStripMenuItem
//
this.storesToolStripMenuItem.Name = "storesToolStripMenuItem";
this.storesToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
this.storesToolStripMenuItem.Text = "Stores";
this.storesToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click);
//
// reportsToolStripMenuItem
//
this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.listComponentsToolStripMenuItem,
this.componentsOnSushiToolStripMenuItem,
this.orderListToolStripMenuItem,
this.storeListToolStripMenuItem,
this.storeWorkloadToolStripMenuItem,
this.orderListWithGroupByToolStripMenuItem});
this.reportsToolStripMenuItem.Name = "reportsToolStripMenuItem";
this.reportsToolStripMenuItem.Size = new System.Drawing.Size(59, 20);
this.reportsToolStripMenuItem.Text = "Reports";
//
// listComponentsToolStripMenuItem
//
this.listComponentsToolStripMenuItem.Name = "listComponentsToolStripMenuItem";
this.listComponentsToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.listComponentsToolStripMenuItem.Text = "List components";
this.listComponentsToolStripMenuItem.Click += new System.EventHandler(this.ListComponentsToolStripMenuItem_Click);
//
// componentsOnSushiToolStripMenuItem
//
this.componentsOnSushiToolStripMenuItem.Name = "componentsOnSushiToolStripMenuItem";
this.componentsOnSushiToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.componentsOnSushiToolStripMenuItem.Text = "Components on sushi";
this.componentsOnSushiToolStripMenuItem.Click += new System.EventHandler(this.ComponentsOnSushiToolStripMenuItem_Click);
//
// orderListToolStripMenuItem
//
this.orderListToolStripMenuItem.Name = "orderListToolStripMenuItem";
this.orderListToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.orderListToolStripMenuItem.Text = "Order list";
this.orderListToolStripMenuItem.Click += new System.EventHandler(this.ListOrdersToolStripMenuItem_Click);
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(814, 27);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(114, 23);
this.buttonCreateOrder.TabIndex = 2;
this.buttonCreateOrder.Text = "Create Order";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// buttonSubmit
//
this.buttonSubmit.Location = new System.Drawing.Point(814, 56);
this.buttonSubmit.Name = "buttonSubmit";
this.buttonSubmit.Size = new System.Drawing.Size(114, 23);
this.buttonSubmit.TabIndex = 3;
this.buttonSubmit.Text = "Submit";
this.buttonSubmit.UseVisualStyleBackColor = true;
this.buttonSubmit.Click += new System.EventHandler(this.ButtonSubmit_Click);
//
// buttonReady
//
this.buttonReady.Location = new System.Drawing.Point(814, 85);
this.buttonReady.Name = "buttonReady";
this.buttonReady.Size = new System.Drawing.Size(114, 23);
this.buttonReady.TabIndex = 4;
this.buttonReady.Text = "Order Ready";
this.buttonReady.UseVisualStyleBackColor = true;
this.buttonReady.Click += new System.EventHandler(this.ButtonReady_Click);
//
// buttonIssue
//
this.buttonIssue.Location = new System.Drawing.Point(814, 114);
this.buttonIssue.Name = "buttonIssue";
this.buttonIssue.Size = new System.Drawing.Size(114, 23);
this.buttonIssue.TabIndex = 5;
this.buttonIssue.Text = "Order Issue";
this.buttonIssue.UseVisualStyleBackColor = true;
this.buttonIssue.Click += new System.EventHandler(this.ButtonIssue_Click);
//
// buttonReload
//
this.buttonReload.Location = new System.Drawing.Point(814, 143);
this.buttonReload.Name = "buttonReload";
this.buttonReload.Size = new System.Drawing.Size(114, 23);
this.buttonReload.TabIndex = 6;
this.buttonReload.Text = "Reload";
this.buttonReload.UseVisualStyleBackColor = true;
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
//
// buttonSell
//
this.buttonSell.Location = new System.Drawing.Point(814, 415);
this.buttonSell.Name = "buttonSell";
this.buttonSell.Size = new System.Drawing.Size(111, 23);
this.buttonSell.TabIndex = 7;
this.buttonSell.Text = "Sell";
this.buttonSell.UseVisualStyleBackColor = true;
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
//
// buttonSupply
//
this.buttonSupply.Location = new System.Drawing.Point(814, 386);
this.buttonSupply.Name = "buttonSupply";
this.buttonSupply.Size = new System.Drawing.Size(111, 23);
this.buttonSupply.TabIndex = 8;
this.buttonSupply.Text = "Supply";
this.buttonSupply.UseVisualStyleBackColor = true;
this.buttonSupply.Click += new System.EventHandler(this.ButtonReplenishment_Click);
//
// storeListToolStripMenuItem
//
this.storeListToolStripMenuItem.Name = "storeListToolStripMenuItem";
this.storeListToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.storeListToolStripMenuItem.Text = "Store list";
this.storeListToolStripMenuItem.Click += new System.EventHandler(this.StoreListToolStripMenuItem_Click);
//
// storeWorkloadToolStripMenuItem
//
this.storeWorkloadToolStripMenuItem.Name = "storeWorkloadToolStripMenuItem";
this.storeWorkloadToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.storeWorkloadToolStripMenuItem.Text = "Store workload";
this.storeWorkloadToolStripMenuItem.Click += new System.EventHandler(this.StoreWorkloadToolStripMenuItem_Click);
//
// orderListWithGroupByToolStripMenuItem
//
this.orderListWithGroupByToolStripMenuItem.Name = "orderListWithGroupByToolStripMenuItem";
this.orderListWithGroupByToolStripMenuItem.Size = new System.Drawing.Size(199, 22);
this.orderListWithGroupByToolStripMenuItem.Text = "Order list with group by";
this.orderListWithGroupByToolStripMenuItem.Click += new System.EventHandler(this.OrderListWithGroupByToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(937, 450);
this.Controls.Add(this.buttonSupply);
this.Controls.Add(this.buttonSell);
this.Controls.Add(this.buttonReload);
this.Controls.Add(this.buttonIssue);
this.Controls.Add(this.buttonReady);
this.Controls.Add(this.buttonSubmit);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
this.Text = "FormMain";
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private DataGridView dataGridView;
private MenuStrip menuStrip1;
private ToolStripMenuItem directoryToolStripMenuItem;
private Button buttonCreateOrder;
private Button buttonSubmit;
private Button buttonReady;
private Button buttonIssue;
private Button buttonReload;
private ToolStripMenuItem componentsToolStripMenuItem;
private ToolStripMenuItem sushiToolStripMenuItem;
private ToolStripMenuItem storesToolStripMenuItem;
private ToolStripMenuItem reportsToolStripMenuItem;
private ToolStripMenuItem listComponentsToolStripMenuItem;
private ToolStripMenuItem componentsOnSushiToolStripMenuItem;
private ToolStripMenuItem orderListToolStripMenuItem;
private Button buttonSell;
private Button buttonSupply;
private ToolStripMenuItem storeListToolStripMenuItem;
private ToolStripMenuItem storeWorkloadToolStripMenuItem;
private ToolStripMenuItem orderListWithGroupByToolStripMenuItem;
}
}

View File

@ -0,0 +1,269 @@
using Microsoft.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarDataModels.Enums;
namespace SushiBar
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
}
private void LoadData()
{
_logger.LogInformation("Load components");
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["SushiId"].Visible = false;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on load orders");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonSubmit_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Change statuc on -Submit", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel {
Id = id,
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Error on saving. Additional info below.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error submit order");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Change status on -Ready",id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel {
Id = id,
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString() ?? "",
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? "Unkown"),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString() ?? "0"),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString() ?? ""),
});
if (!operationResult)
{
throw new Exception("Error on saving. Additional info below.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on change status");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonIssue_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Change status on -Issued", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel {
Id = id,
SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value),
SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Error on saving. Additional info below.");
}
_logger.LogInformation("Order №{id} issued", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on change status");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonReload_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
private void SushiToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushiMoreThenOne));
if (service is FormSushiMoreThenOne form)
{
form.ShowDialog();
}
}
private void ListComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() != DialogResult.OK) return;
_reportLogic.SaveSushiToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Complete", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void ComponentsOnSushiToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushiOnComponents));
if (service is FormSushiOnComponents form)
{
form.ShowDialog();
}
}
private void ListOrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
if (service is FormReportOrders form)
{
form.ShowDialog();
}
}
private void StoreToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStores));
if (service is FormStores form)
{
form.ShowDialog();
}
}
private void ButtonReplenishment_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment));
if (service is FormStoreReplenishment form)
{
form.ShowDialog();
}
}
private void ButtonSell_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStoreSell));
if (service is FormStoreSell form)
{
form.ShowDialog();
}
}
private void StoreListToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() != DialogResult.OK) return;
_reportLogic.SaveStoresToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Complete", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void StoreWorkloadToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStoreWorkload));
if (service is FormStoreWorkload form)
{
form.ShowDialog();
}
}
private void OrderListWithGroupByToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrdersGroupByDate));
if (service is FormReportOrdersGroupByDate form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,63 @@
<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>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,131 @@
namespace SushiBar
{
partial class FormReportOrders
{
/// <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.panel = new System.Windows.Forms.Panel();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.labelTo = new System.Windows.Forms.Label();
this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker();
this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker();
this.labelFrom = new System.Windows.Forms.Label();
this.panel.SuspendLayout();
this.SuspendLayout();
//
// panel
//
this.panel.Controls.Add(this.buttonCreate);
this.panel.Controls.Add(this.buttonSave);
this.panel.Controls.Add(this.labelTo);
this.panel.Controls.Add(this.dateTimePickerTo);
this.panel.Controls.Add(this.dateTimePickerFrom);
this.panel.Controls.Add(this.labelFrom);
this.panel.Dock = System.Windows.Forms.DockStyle.Top;
this.panel.Location = new System.Drawing.Point(0, 0);
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size(800, 37);
this.panel.TabIndex = 0;
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(617, 7);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 5;
this.buttonCreate.Text = "Create";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(698, 7);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 4;
this.buttonSave.Text = "Save PDF";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// labelTo
//
this.labelTo.AutoSize = true;
this.labelTo.Location = new System.Drawing.Point(250, 11);
this.labelTo.Name = "labelTo";
this.labelTo.Size = new System.Drawing.Size(19, 15);
this.labelTo.TabIndex = 3;
this.labelTo.Text = "To";
//
// dateTimePickerTo
//
this.dateTimePickerTo.Location = new System.Drawing.Point(275, 5);
this.dateTimePickerTo.Name = "dateTimePickerTo";
this.dateTimePickerTo.Size = new System.Drawing.Size(200, 23);
this.dateTimePickerTo.TabIndex = 2;
//
// dateTimePickerFrom
//
this.dateTimePickerFrom.Location = new System.Drawing.Point(44, 5);
this.dateTimePickerFrom.Name = "dateTimePickerFrom";
this.dateTimePickerFrom.Size = new System.Drawing.Size(200, 23);
this.dateTimePickerFrom.TabIndex = 1;
//
// labelFrom
//
this.labelFrom.AutoSize = true;
this.labelFrom.Location = new System.Drawing.Point(3, 11);
this.labelFrom.Name = "labelFrom";
this.labelFrom.Size = new System.Drawing.Size(35, 15);
this.labelFrom.TabIndex = 0;
this.labelFrom.Text = "From";
//
// FormReportOrders
//
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.panel);
this.Name = "FormReportOrders";
this.Text = "FormReportsOrders";
this.panel.ResumeLayout(false);
this.panel.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonCreate;
private Button buttonSave;
private Label labelTo;
private DateTimePicker dateTimePickerTo;
private DateTimePicker dateTimePickerFrom;
private Label labelFrom;
}
}

View File

@ -0,0 +1,98 @@
using Microsoft.Extensions.Logging;
using Microsoft.Reporting.WinForms;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using System.Windows.Forms;
namespace SushiBar
{
public partial class FormReportOrders : Form
{
private readonly ReportViewer reportViewer;
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportOrders(ILogger<FormReportOrders> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
reportViewer = new ReportViewer
{
Dock = DockStyle.Fill
};
reportViewer.LocalReport.LoadReportDefinition(new FileStream("Report.rdlc", FileMode.Open));
Controls.Clear();
Controls.Add(reportViewer);
Controls.Add(panel);
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
{
MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var dataSource = _logic.GetOrders(new ReportBindingModel
{
DateFrom = dateTimePickerFrom.Value,
DateTo = dateTimePickerTo.Value
});
var source = new ReportDataSource("DataSetOrders", dataSource);
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(source);
var parameters = new[] {
new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}")
};
reportViewer.LocalReport.SetParameters(parameters);
reportViewer.RefreshReport();
_logger.LogInformation(
"Загрузка списка заказов на период {From}-{To}",
dateTimePickerFrom.Value.ToShortDateString(),
dateTimePickerTo.Value.ToShortDateString()
);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка заказов на период");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date)
{
MessageBox.Show("Дата начала должна быть меньше даты окончания",
"Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
using var dialog = new SaveFileDialog
{
Filter = "pdf|*.pdf"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveOrdersToPdfFile(new ReportBindingModel
{
FileName = dialog.FileName,
DateFrom = dateTimePickerFrom.Value,
DateTo = dateTimePickerTo.Value
});
_logger.LogInformation("Сохранение списка заказов на период{ From}-{ To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString());
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения списка заказов на период");
MessageBox.Show(ex.Message, "Ошибка", 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,87 @@
namespace SushiBar
{
partial class FormReportOrdersGroupByDate
{
/// <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.panel = new System.Windows.Forms.Panel();
this.buttonCreate = new System.Windows.Forms.Button();
this.Save = new System.Windows.Forms.Button();
this.panel.SuspendLayout();
this.SuspendLayout();
//
// panel
//
this.panel.Controls.Add(this.buttonCreate);
this.panel.Controls.Add(this.Save);
this.panel.Dock = System.Windows.Forms.DockStyle.Top;
this.panel.Location = new System.Drawing.Point(0, 0);
this.panel.Name = "panel";
this.panel.Size = new System.Drawing.Size(800, 30);
this.panel.TabIndex = 0;
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(617, 3);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 5;
this.buttonCreate.Text = "Create";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// Save
//
this.Save.Location = new System.Drawing.Point(698, 3);
this.Save.Name = "Save";
this.Save.Size = new System.Drawing.Size(75, 23);
this.Save.TabIndex = 4;
this.Save.Text = "Save";
this.Save.UseVisualStyleBackColor = true;
this.Save.Click += new System.EventHandler(this.Save_Click);
//
// FormReportOrdersGroupByDate
//
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.panel);
this.Name = "FormReportOrdersGroupByDate";
this.Text = "FormReportOrdersGroupByDate";
this.Load += new System.EventHandler(this.FormReportOrdersGroupByDate_Load);
this.panel.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private Panel panel;
private Button buttonCreate;
private Button Save;
}
}

View File

@ -0,0 +1,74 @@
using Microsoft.Extensions.Logging;
using Microsoft.Reporting.WinForms;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar
{
public partial class FormReportOrdersGroupByDate : Form
{
private readonly ReportViewer reportViewer;
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportOrdersGroupByDate(ILogger<FormReportOrdersGroupByDate> logger, IReportLogic logic)
{
_logger = logger;
_logic = logic;
InitializeComponent();
reportViewer = new ReportViewer
{
Dock = DockStyle.Fill
};
reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportHard.rdlc", FileMode.Open));
Controls.Clear();
Controls.Add(reportViewer);
Controls.Add(panel);
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
try
{
var dataSource = _logic.GetGroupOrders();
var source = new ReportDataSource("DataSetOrdersGroup", dataSource);
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(source);
reportViewer.RefreshReport();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка заказов на период");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void Save_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "pdf|*.pdf"
};
if (dialog.ShowDialog() != DialogResult.OK) return;
try
{
_logic.SaveOrdersGroupedToPdf(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения списка заказов на период");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormReportOrdersGroupByDate_Load(object sender, EventArgs e)
{
}
}
}

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>

195
SushiBar/SushiBar/FormStore.Designer.cs generated Normal file
View File

@ -0,0 +1,195 @@
namespace SushiBar
{
partial class FormStore
{
/// <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.SushiName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Cost = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.comboBoxName = new System.Windows.Forms.ComboBox();
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.labelMaxSushi = new System.Windows.Forms.Label();
this.maxSushi = new System.Windows.Forms.NumericUpDown();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.maxSushi)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.SushiName,
this.Cost,
this.Count});
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(598, 426);
this.dataGridView.TabIndex = 0;
//
// SushiName
//
this.SushiName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.SushiName.HeaderText = "Sushi";
this.SushiName.Name = "SushiName";
//
// Cost
//
this.Cost.HeaderText = "Cost";
this.Cost.Name = "Cost";
//
// Count
//
this.Count.HeaderText = "Count";
this.Count.Name = "Count";
//
// comboBoxName
//
this.comboBoxName.FormattingEnabled = true;
this.comboBoxName.Location = new System.Drawing.Point(616, 12);
this.comboBoxName.Name = "comboBoxName";
this.comboBoxName.Size = new System.Drawing.Size(172, 23);
this.comboBoxName.TabIndex = 1;
this.comboBoxName.SelectedIndexChanged += new System.EventHandler(this.ComboBoxName_SelectedIndexChanged);
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(616, 56);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(172, 23);
this.textBoxAddress.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(616, 38);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(49, 15);
this.label1.TabIndex = 3;
this.label1.Text = "Address";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(616, 82);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 15);
this.label2.TabIndex = 5;
this.label2.Text = "Date Opening";
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(621, 415);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 6;
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(702, 415);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(86, 23);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// dateTimePicker
//
this.dateTimePicker.Location = new System.Drawing.Point(616, 100);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(172, 23);
this.dateTimePicker.TabIndex = 8;
//
// labelMaxSushi
//
this.labelMaxSushi.AutoSize = true;
this.labelMaxSushi.Location = new System.Drawing.Point(616, 126);
this.labelMaxSushi.Name = "labelMaxSushi";
this.labelMaxSushi.Size = new System.Drawing.Size(61, 15);
this.labelMaxSushi.TabIndex = 9;
this.labelMaxSushi.Text = "Max Suhsi";
//
// maxSushi
//
this.maxSushi.Location = new System.Drawing.Point(616, 144);
this.maxSushi.Name = "maxSushi";
this.maxSushi.Size = new System.Drawing.Size(172, 23);
this.maxSushi.TabIndex = 10;
//
// FormStore
//
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.maxSushi);
this.Controls.Add(this.labelMaxSushi);
this.Controls.Add(this.dateTimePicker);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.comboBoxName);
this.Controls.Add(this.dataGridView);
this.Name = "FormStore";
this.Text = "FormStore";
this.Load += new System.EventHandler(this.FormStore_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.maxSushi)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private DataGridView dataGridView;
private ComboBox comboBoxName;
private TextBox textBoxAddress;
private Label label1;
private Label label2;
private Button buttonSave;
private Button buttonCancel;
private DateTimePicker dateTimePicker;
private DataGridViewTextBoxColumn SushiName;
private DataGridViewTextBoxColumn Cost;
private DataGridViewTextBoxColumn Count;
private Label labelMaxSushi;
private NumericUpDown maxSushi;
}
}

View File

@ -0,0 +1,143 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBar
{
public partial class FormStore : Form
{
private readonly List<StoreViewModel>? _listStores;
private readonly IStoreLogic _logic;
private readonly ILogger _logger;
public int id { get; set; }
public FormStore(ILogger<FormStore> logger, IStoreLogic logic)
{
InitializeComponent();
_logger = logger;
_listStores = logic.ReadList(null);
_logic = logic;
if (_listStores != null)
{
comboBoxName.DisplayMember = "StoreName";
comboBoxName.ValueMember = "Id";
comboBoxName.DataSource = _listStores;
comboBoxName.SelectedItem = null;
}
}
private void LoadData(bool extendDate = true)
{
try
{
var model = GetStore(extendDate ? id : Convert.ToInt32(comboBoxName.SelectedValue));
if (model != null)
{
comboBoxName.Text = model.StoreName;
textBoxAddress.Text = model.StoreAddress;
dateTimePicker.Text = Convert.ToString(model.OpeningDate);
maxSushi.Value = model.maxSushi;
dataGridView.Rows.Clear();
foreach (var el in model.Sushis.Values)
{
dataGridView.Rows.Add(el.Item1.SushiName, el.Item1.Price, el.Item2);
}
}
_logger.LogInformation("Load stores");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on load");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private IStoreModel? GetStore(int Id)
{
if (_listStores == null)
{
return null;
}
foreach (var elem in _listStores)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(comboBoxName.Text))
{
MessageBox.Show("Select store name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxAddress.Text))
{
MessageBox.Show("Fill in address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Saving store");
try
{
DateTime.TryParse(dateTimePicker.Text, out var dateTime);
StoreBindingModel model = new()
{
StoreName = comboBoxName.Text,
StoreAddress = textBoxAddress.Text,
OpeningDate = dateTime,
maxSushi = (int)maxSushi.Value
};
var searchModel = GetStore(id);
bool operationResult;
if (searchModel != null)
{
model.Id = searchModel.Id;
operationResult = _logic.Update(model);
}
else
{
operationResult = _logic.Create(model);
}
if (!operationResult)
{
throw new Exception("Error on saving. Additional info below");
}
MessageBox.Show("Save is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on saving");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void ComboBoxName_SelectedIndexChanged(object sender, EventArgs e)
{
LoadData(false);
}
private void FormStore_Load(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,78 @@
<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>
<metadata name="SushiName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Cost.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="SushiName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Cost.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -0,0 +1,142 @@
namespace SushiBar
{
partial class FormStoreReplenishment
{
/// <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.comboBoxStore = new System.Windows.Forms.ComboBox();
this.comboBoxSushi = new System.Windows.Forms.ComboBox();
this.labelSushi = new System.Windows.Forms.Label();
this.labelStore = new System.Windows.Forms.Label();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelCount = new System.Windows.Forms.Label();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// comboBoxStore
//
this.comboBoxStore.FormattingEnabled = true;
this.comboBoxStore.Location = new System.Drawing.Point(73, 12);
this.comboBoxStore.Name = "comboBoxStore";
this.comboBoxStore.Size = new System.Drawing.Size(172, 23);
this.comboBoxStore.TabIndex = 0;
//
// comboBoxSushi
//
this.comboBoxSushi.FormattingEnabled = true;
this.comboBoxSushi.Location = new System.Drawing.Point(73, 41);
this.comboBoxSushi.Name = "comboBoxSushi";
this.comboBoxSushi.Size = new System.Drawing.Size(172, 23);
this.comboBoxSushi.TabIndex = 1;
//
// labelSushi
//
this.labelSushi.AutoSize = true;
this.labelSushi.Location = new System.Drawing.Point(12, 44);
this.labelSushi.Name = "labelSushi";
this.labelSushi.Size = new System.Drawing.Size(35, 15);
this.labelSushi.TabIndex = 2;
this.labelSushi.Text = "Sushi";
//
// labelStore
//
this.labelStore.AutoSize = true;
this.labelStore.Location = new System.Drawing.Point(12, 15);
this.labelStore.Name = "labelStore";
this.labelStore.Size = new System.Drawing.Size(34, 15);
this.labelStore.TabIndex = 3;
this.labelStore.Text = "Store";
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 101);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(113, 23);
this.buttonSave.TabIndex = 4;
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(131, 101);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(114, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(12, 75);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(40, 15);
this.labelCount.TabIndex = 6;
this.labelCount.Text = "Count";
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(73, 72);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(172, 23);
this.textBoxCount.TabIndex = 7;
//
// FormStoreReplenishment
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(257, 136);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.labelStore);
this.Controls.Add(this.labelSushi);
this.Controls.Add(this.comboBoxSushi);
this.Controls.Add(this.comboBoxStore);
this.Name = "FormStoreReplenishment";
this.Text = "FormStoreReplenishment";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private ComboBox comboBoxStore;
private ComboBox comboBoxSushi;
private Label labelSushi;
private Label labelStore;
private Button buttonSave;
private Button buttonCancel;
private Label labelCount;
private TextBox textBoxCount;
}
}

View File

@ -0,0 +1,95 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.ViewModels;
namespace SushiBar
{
public partial class FormStoreReplenishment : Form
{
private readonly ILogger _logger;
private readonly IStoreLogic _storeLogic;
private readonly ISushiLogic _sushiLogic;
private readonly List<StoreViewModel>? _listStores;
private readonly List<SushiViewModel>? _listSushi;
public FormStoreReplenishment(ILogger<FormStoreReplenishment> logger, IStoreLogic storeLogic, ISushiLogic sushiLogic)
{
InitializeComponent();
_storeLogic = storeLogic;
_sushiLogic = sushiLogic;
_logger = logger;
_listStores = storeLogic.ReadList(null);
if (_listStores != null)
{
comboBoxStore.DisplayMember = "StoreName";
comboBoxStore.ValueMember = "Id";
comboBoxStore.DataSource = _listStores;
comboBoxStore.SelectedItem = null;
}
_listSushi = sushiLogic.ReadList(null);
if (_listSushi != null)
{
comboBoxSushi.DisplayMember = "SushiName";
comboBoxSushi.ValueMember = "Id";
comboBoxSushi.DataSource = _listSushi;
comboBoxSushi.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxStore.SelectedValue == null)
{
MessageBox.Show("Select store", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSushi.SelectedValue == null)
{
MessageBox.Show("Select sushi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Add sushi to store");
try
{
var sushi = _sushiLogic.ReadElement(new()
{
Id = (int)comboBoxSushi.SelectedValue
});
if (sushi == null)
{
throw new Exception("Sushi is not found. Additional info below.");
}
var resultOperation = _storeLogic.SupplySushi(
model: new() { Id = (int)comboBoxStore.SelectedValue },
sushi: sushi,
quantity: Convert.ToInt32(textBoxCount.Text)
);
if (!resultOperation)
{
throw new Exception("Error on saving. Additional info below.");
}
MessageBox.Show("Save is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on saving");
MessageBox.Show(ex.Message, "Error", 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,110 @@
namespace SushiBar
{
partial class FormStoreSell
{
/// <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.SushiNames = new System.Windows.Forms.ComboBox();
this.labelSushi = new System.Windows.Forms.Label();
this.Count = new System.Windows.Forms.NumericUpDown();
this.buttonSell = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.Count)).BeginInit();
this.SuspendLayout();
//
// SushiNames
//
this.SushiNames.FormattingEnabled = true;
this.SushiNames.Location = new System.Drawing.Point(12, 27);
this.SushiNames.Name = "SushiNames";
this.SushiNames.Size = new System.Drawing.Size(172, 23);
this.SushiNames.TabIndex = 0;
//
// labelSushi
//
this.labelSushi.AutoSize = true;
this.labelSushi.Location = new System.Drawing.Point(12, 9);
this.labelSushi.Name = "labelSushi";
this.labelSushi.Size = new System.Drawing.Size(35, 15);
this.labelSushi.TabIndex = 1;
this.labelSushi.Text = "Sushi";
//
// Count
//
this.Count.Location = new System.Drawing.Point(12, 56);
this.Count.Name = "Count";
this.Count.Size = new System.Drawing.Size(172, 23);
this.Count.TabIndex = 2;
//
// buttonSell
//
this.buttonSell.Location = new System.Drawing.Point(12, 85);
this.buttonSell.Name = "buttonSell";
this.buttonSell.Size = new System.Drawing.Size(82, 23);
this.buttonSell.TabIndex = 3;
this.buttonSell.Text = "Sell";
this.buttonSell.UseVisualStyleBackColor = true;
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(100, 85);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(84, 23);
this.buttonCancel.TabIndex = 4;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormStoreSell
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(198, 118);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSell);
this.Controls.Add(this.Count);
this.Controls.Add(this.labelSushi);
this.Controls.Add(this.SushiNames);
this.Name = "FormStoreSell";
this.Text = "FormStoreSell";
this.Load += new System.EventHandler(this.FormStoreSell_Load);
((System.ComponentModel.ISupportInitialize)(this.Count)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private ComboBox SushiNames;
private Label labelSushi;
private NumericUpDown Count;
private Button buttonSell;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,84 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar
{
public partial class FormStoreSell : Form
{
private readonly ILogger _logger;
private readonly ISushiLogic _logicSushi;
private readonly IStoreLogic _logicStore;
public FormStoreSell(ILogger<FormStoreSell> logger, ISushiLogic sushiLogic, IStoreLogic storeLogic)
{
InitializeComponent();
_logger = logger;
_logicSushi = sushiLogic;
_logicStore = storeLogic;
}
private void ButtonSell_Click(object sender, EventArgs e)
{
if (Count.Value == 0)
{
MessageBox.Show("Count must be more then zero!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (SushiNames.SelectedValue == null)
{
MessageBox.Show("Select sushi", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Create sell");
try
{
var operationResult = _logicStore.SellSushi(
new SushiBindingModel()
{
Id = Convert.ToInt32(SushiNames.SelectedValue)
},
(int)Count.Value
);
if (!operationResult)
{
throw new Exception("Error on create sell. Additional info below");
}
MessageBox.Show("Complete create", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on create");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormStoreSell_Load(object sender, EventArgs e)
{
_logger.LogInformation("Load sushi to sell");
try
{
var list = _logicSushi.ReadList(null);
if (list == null) return;
SushiNames.DisplayMember = "SushiName";
SushiNames.ValueMember = "Id";
SushiNames.DataSource = list;
SushiNames.SelectedItem = null;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on loading");
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,101 @@
namespace SushiBar
{
partial class FormStoreWorkload
{
/// <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.buttonSave = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.StoreName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Sushi = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 12);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(116, 23);
this.buttonSave.TabIndex = 0;
this.buttonSave.Text = "Save excel file";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.StoreName,
this.Sushi,
this.Count});
this.dataGridView.Location = new System.Drawing.Point(12, 41);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(776, 397);
this.dataGridView.TabIndex = 1;
//
// StoreName
//
this.StoreName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.StoreName.HeaderText = "Store name";
this.StoreName.Name = "StoreName";
//
// Sushi
//
this.Sushi.HeaderText = "Sushi";
this.Sushi.Name = "Sushi";
//
// Count
//
this.Count.HeaderText = "Count";
this.Count.Name = "Count";
//
// FormStoreWorkload
//
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.dataGridView);
this.Controls.Add(this.buttonSave);
this.Name = "FormStoreWorkload";
this.Text = "FormStoreWorkload";
this.Load += new System.EventHandler(this.FormStoreWorkload_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button buttonSave;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn StoreName;
private DataGridViewTextBoxColumn Sushi;
private DataGridViewTextBoxColumn Count;
}
}

View File

@ -0,0 +1,84 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
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 FormStoreWorkload : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormStoreWorkload(ILogger<FormSushiOnComponents> logger, IReportLogic logic)
{
_logger = logger;
_logic = logic;
InitializeComponent();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveWorkloadStoresToExcel(new ReportBindingModel
{
FileName = dialog.FileName
});
_logger.LogInformation("Saving list sushi on components");
MessageBox.Show("Success", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error save excel");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void FormStoreWorkload_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetStores();
if (dict != null)
{
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.StoreName, "", "" });
foreach (var listElem in elem.Sushis)
{
dataGridView.Rows.Add(new object[] { "", listElem.Value.Item1.SushiName, listElem.Value.Item2 });
}
dataGridView.Rows.Add(new object[] { "", "Count", elem.Sushis.Values.Select(x => x.Item2).Sum().ToString() });
dataGridView.Rows.Add(Array.Empty<object>());
}
}
_logger.LogInformation("Load list stores");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on load");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,78 @@
<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>
<metadata name="StoreName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Sushi.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="StoreName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Sushi.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

114
SushiBar/SushiBar/FormStores.Designer.cs generated Normal file
View File

@ -0,0 +1,114 @@
namespace SushiBar
{
partial class FormStores
{
/// <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.buttonRemove = new System.Windows.Forms.Button();
this.buttonChange = new System.Windows.Forms.Button();
this.buttonUpdate = 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(605, 426);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(623, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(165, 23);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Add";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonRemove
//
this.buttonRemove.Location = new System.Drawing.Point(623, 41);
this.buttonRemove.Name = "buttonRemove";
this.buttonRemove.Size = new System.Drawing.Size(165, 23);
this.buttonRemove.TabIndex = 2;
this.buttonRemove.Text = "Remove";
this.buttonRemove.UseVisualStyleBackColor = true;
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
//
// buttonChange
//
this.buttonChange.Location = new System.Drawing.Point(623, 70);
this.buttonChange.Name = "buttonChange";
this.buttonChange.Size = new System.Drawing.Size(165, 23);
this.buttonChange.TabIndex = 3;
this.buttonChange.Text = "Change";
this.buttonChange.UseVisualStyleBackColor = true;
this.buttonChange.Click += new System.EventHandler(this.ButtonChange_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(623, 99);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(165, 23);
this.buttonUpdate.TabIndex = 4;
this.buttonUpdate.Text = "Update";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpdate_Click);
//
// FormStores
//
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.buttonUpdate);
this.Controls.Add(this.buttonChange);
this.Controls.Add(this.buttonRemove);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormStores";
this.Text = "FormStores";
this.Load += new System.EventHandler(this.FormStores_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonRemove;
private Button buttonChange;
private Button buttonUpdate;
}
}

View File

@ -0,0 +1,113 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar
{
public partial class FormStores : Form
{
private readonly ILogger _logger;
private readonly IStoreLogic _logic;
public FormStores(ILogger<FormStores> logger, IStoreLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Sushis"].Visible = false;
}
_logger.LogInformation("Load stores");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on loading");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStore));
if (service is FormStore form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonRemove_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 store");
try
{
if (!_logic.Delete(new StoreBindingModel
{
Id = id
}))
{
throw new Exception("Error on deleting. Additional info below.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error delete store");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStore));
if (service is FormStore form)
{
form.id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormStores_Load(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>

226
SushiBar/SushiBar/FormSushi.Designer.cs generated Normal file
View File

@ -0,0 +1,226 @@
namespace SushiBar
{
partial class FormSushi
{
/// <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.labelName = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.labelCost = new System.Windows.Forms.Label();
this.textBoxPrice = new System.Windows.Forms.TextBox();
this.groupBox = new System.Windows.Forms.GroupBox();
this.buttonReload = new System.Windows.Forms.Button();
this.buttonRemove = new System.Windows.Forms.Button();
this.buttonEdit = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Value = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.groupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(12, 9);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(39, 15);
this.labelName.TabIndex = 0;
this.labelName.Text = "Name";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(57, 6);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(589, 23);
this.textBoxName.TabIndex = 1;
//
// labelCost
//
this.labelCost.AutoSize = true;
this.labelCost.Location = new System.Drawing.Point(12, 41);
this.labelCost.Name = "labelCost";
this.labelCost.Size = new System.Drawing.Size(33, 15);
this.labelCost.TabIndex = 2;
this.labelCost.Text = "Price";
//
// textBoxPrice
//
this.textBoxPrice.Location = new System.Drawing.Point(57, 38);
this.textBoxPrice.Name = "textBoxPrice";
this.textBoxPrice.Size = new System.Drawing.Size(589, 23);
this.textBoxPrice.TabIndex = 3;
//
// groupBox
//
this.groupBox.Controls.Add(this.buttonReload);
this.groupBox.Controls.Add(this.buttonRemove);
this.groupBox.Controls.Add(this.buttonEdit);
this.groupBox.Controls.Add(this.buttonAdd);
this.groupBox.Controls.Add(this.dataGridView);
this.groupBox.Location = new System.Drawing.Point(15, 67);
this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(773, 343);
this.groupBox.TabIndex = 4;
this.groupBox.TabStop = false;
this.groupBox.Text = "Components";
//
// buttonReload
//
this.buttonReload.Location = new System.Drawing.Point(637, 109);
this.buttonReload.Name = "buttonReload";
this.buttonReload.Size = new System.Drawing.Size(130, 23);
this.buttonReload.TabIndex = 4;
this.buttonReload.Text = "Reload";
this.buttonReload.UseVisualStyleBackColor = true;
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
//
// buttonRemove
//
this.buttonRemove.Location = new System.Drawing.Point(637, 80);
this.buttonRemove.Name = "buttonRemove";
this.buttonRemove.Size = new System.Drawing.Size(130, 23);
this.buttonRemove.TabIndex = 3;
this.buttonRemove.Text = "Remove";
this.buttonRemove.UseVisualStyleBackColor = true;
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
//
// buttonEdit
//
this.buttonEdit.Location = new System.Drawing.Point(637, 51);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(130, 23);
this.buttonEdit.TabIndex = 2;
this.buttonEdit.Text = "Edit";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(637, 22);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(130, 23);
this.buttonAdd.TabIndex = 1;
this.buttonAdd.Text = "Add";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.Component,
this.Value});
this.dataGridView.Location = new System.Drawing.Point(6, 22);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(625, 315);
this.dataGridView.TabIndex = 0;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(658, 415);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(130, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(522, 415);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(130, 23);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Save";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// ID
//
this.ID.HeaderText = "ID";
this.ID.Name = "ID";
this.ID.Visible = false;
//
// Component
//
this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Component.HeaderText = "ComponentName";
this.Component.Name = "Component";
//
// Value
//
this.Value.HeaderText = "Count";
this.Value.Name = "Value";
//
// FormSushi
//
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.buttonSave);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.groupBox);
this.Controls.Add(this.textBoxPrice);
this.Controls.Add(this.labelCost);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelName);
this.Name = "FormSushi";
this.Text = "FormSushi";
this.Load += new System.EventHandler(this.FormSushi_Load);
this.groupBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelName;
private TextBox textBoxName;
private Label labelCost;
private TextBox textBoxPrice;
private GroupBox groupBox;
private Button buttonReload;
private Button buttonRemove;
private Button buttonEdit;
private Button buttonAdd;
private DataGridView dataGridView;
private Button buttonCancel;
private Button buttonSave;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn Component;
private DataGridViewTextBoxColumn Value;
}
}

View File

@ -0,0 +1,209 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarDataModels.Models;
namespace SushiBar
{
public partial class FormSushi : Form
{
private readonly ILogger _logger;
private readonly ISushiLogic _logic;
private int? _id;
private Dictionary<int, (IComponentModel, int)> _sushiComponents;
public int Id { set { _id = value; } }
public FormSushi(ILogger<FormSushi> logger, ISushiLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_sushiComponents = new Dictionary<int, (IComponentModel, int)>();
}
private void LoadData()
{
_logger.LogInformation("Load components");
try
{
if (_sushiComponents != null)
{
dataGridView.Rows.Clear();
foreach (var pc in _sushiComponents)
{
dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
}
textBoxPrice.Text = CalcPrice().ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading components for sushi");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private double CalcPrice()
{
double price = 0;
foreach (var elem in _sushiComponents)
{
price += (elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2;
}
return Math.Round(price * 1.1, 2);
}
private void FormSushi_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Load records");
try
{
var view = _logic.ReadElement(new SushiSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.SushiName;
textBoxPrice.Text = view.Price.ToString();
_sushiComponents = view.SushiComponents ?? new Dictionary<int, (IComponentModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on loading");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
if (service is FormSushiComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Add new component:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
if (_sushiComponents.ContainsKey(form.Id))
{
_sushiComponents[form.Id] = (form.ComponentModel, form.Count);
}
else
{
_sushiComponents.Add(form.Id, (form.ComponentModel, form.Count));
}
LoadData();
}
}
}
private void ButtonEdit_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
if (service is FormSushiComponent form)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id;
form.Count = _sushiComponents[id].Item2;
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Edit component:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_sushiComponents[form.Id] = (form.ComponentModel,form.Count);
LoadData();
}
}
}
}
private void ButtonRemove_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Delte record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Deleting component: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_sushiComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonReload_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Fill in name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxPrice.Text))
{
MessageBox.Show("Fill in cost", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_sushiComponents == null || _sushiComponents.Count == 0)
{
MessageBox.Show("Fill in components", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Saving component");
try
{
var model = new SushiBindingModel
{
Id = _id ?? 0,
SushiName = textBoxName.Text,
Price = Convert.ToDouble(textBoxPrice.Text),
SushiComponents = _sushiComponents
};
var operationResult = _id.HasValue ? _logic.Update(model) :
_logic.Create(model);
if (!operationResult)
{
throw new Exception("Error on saving. Additional info below.");
}
MessageBox.Show("Saving is successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on saving");
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,69 @@
<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>
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Value.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -0,0 +1,119 @@
namespace SushiBar
{
partial class FormSushiComponent
{
/// <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.labelComp = new System.Windows.Forms.Label();
this.comboBoxComponent = new System.Windows.Forms.ComboBox();
this.labelCount = new System.Windows.Forms.Label();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelComp
//
this.labelComp.AutoSize = true;
this.labelComp.Location = new System.Drawing.Point(12, 9);
this.labelComp.Name = "labelComp";
this.labelComp.Size = new System.Drawing.Size(71, 15);
this.labelComp.TabIndex = 0;
this.labelComp.Text = "Component";
//
// comboBoxComponent
//
this.comboBoxComponent.FormattingEnabled = true;
this.comboBoxComponent.Location = new System.Drawing.Point(89, 6);
this.comboBoxComponent.Name = "comboBoxComponent";
this.comboBoxComponent.Size = new System.Drawing.Size(224, 23);
this.comboBoxComponent.TabIndex = 1;
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(12, 41);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(40, 15);
this.labelCount.TabIndex = 2;
this.labelCount.Text = "Count";
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(89, 38);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(224, 23);
this.textBoxCount.TabIndex = 3;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 67);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(143, 23);
this.buttonSave.TabIndex = 4;
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(161, 67);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(152, 23);
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// FormSushiComponent
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(325, 99);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.comboBoxComponent);
this.Controls.Add(this.labelComp);
this.Name = "FormSushiComponent";
this.Text = "FormSushiComponent";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelComp;
private ComboBox comboBoxComponent;
private Label labelCount;
private TextBox textBoxCount;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,81 @@
using Microsoft.VisualBasic.Logging;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBar
{
public partial class FormSushiComponent: Form
{
private readonly List<ComponentViewModel>? _list;
public int Id
{
get
{
return Convert.ToInt32(comboBoxComponent.SelectedValue);
}
set
{
comboBoxComponent.SelectedValue = value;
}
}
public IComponentModel? ComponentModel
{
get
{
if (_list == null)
{
return null;
}
foreach (var elem in _list)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public int Count
{
get { return Convert.ToInt32(textBoxCount.Text); }
set { textBoxCount.Text = value.ToString(); }
}
public FormSushiComponent(IComponentLogic logic)
{
InitializeComponent();
_list = logic.ReadList(null);
if (_list != null)
{
comboBoxComponent.DisplayMember = "ComponentName";
comboBoxComponent.ValueMember = "Id";
comboBoxComponent.DataSource = _list;
comboBoxComponent.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Fill in text box count", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxComponent.SelectedValue == null)
{
MessageBox.Show("Select component", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
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,114 @@
namespace SushiBar
{
partial class FormSushiMoreThenOne
{
/// <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.buttonRemove = 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(422, 426);
this.dataGridView.TabIndex = 0;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(440, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(168, 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(440, 41);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(168, 23);
this.buttonEdit.TabIndex = 2;
this.buttonEdit.Text = "Edit";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.ButtonEdit_Click);
//
// buttonRemove
//
this.buttonRemove.Location = new System.Drawing.Point(440, 70);
this.buttonRemove.Name = "buttonRemove";
this.buttonRemove.Size = new System.Drawing.Size(168, 23);
this.buttonRemove.TabIndex = 3;
this.buttonRemove.Text = "Remove";
this.buttonRemove.UseVisualStyleBackColor = true;
this.buttonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
//
// buttonReload
//
this.buttonReload.Location = new System.Drawing.Point(440, 99);
this.buttonReload.Name = "buttonReload";
this.buttonReload.Size = new System.Drawing.Size(168, 23);
this.buttonReload.TabIndex = 4;
this.buttonReload.Text = "Reload";
this.buttonReload.UseVisualStyleBackColor = true;
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
//
// FormSushiMoreThenOne
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(620, 450);
this.Controls.Add(this.buttonReload);
this.Controls.Add(this.buttonRemove);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormSushiMoreThenOne";
this.Text = "FormSushiMoreThenOne";
this.Load += new System.EventHandler(this.FormSushiMoreThenOne_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonEdit;
private Button buttonRemove;
private Button buttonReload;
}
}

View File

@ -0,0 +1,102 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar
{
public partial class FormSushiMoreThenOne : Form
{
private readonly ILogger _logger;
private readonly ISushiLogic _logic;
public FormSushiMoreThenOne(ILogger<FormSushiMoreThenOne> logger, ISushiLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["SushiComponents"].Visible = false;
}
_logger.LogInformation("Load sushi");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on load sushi");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
if (service is FormSushi 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(FormSushi));
if (service is FormSushi form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonRemove_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("Delete sushi");
try
{
if (!_logic.Delete(new SushiBindingModel { Id = id }))
{
throw new Exception("Error on deleting. Additional info below.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error delete sushi");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonReload_Click(object sender, EventArgs e)
{
LoadData();
}
private void FormSushiMoreThenOne_Load(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

@ -0,0 +1,101 @@
namespace SushiBar
{
partial class FormSushiOnComponents
{
/// <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.ButtonSave = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.component = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.sushi = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.count = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// ButtonSave
//
this.ButtonSave.Location = new System.Drawing.Point(12, 12);
this.ButtonSave.Name = "ButtonSave";
this.ButtonSave.Size = new System.Drawing.Size(155, 23);
this.ButtonSave.TabIndex = 0;
this.ButtonSave.Text = "Save excel file";
this.ButtonSave.UseVisualStyleBackColor = true;
this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.component,
this.sushi,
this.count});
this.dataGridView.Location = new System.Drawing.Point(12, 41);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(776, 397);
this.dataGridView.TabIndex = 1;
//
// component
//
this.component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.component.HeaderText = "Components";
this.component.Name = "component";
//
// sushi
//
this.sushi.HeaderText = "Sushis";
this.sushi.Name = "sushi";
//
// count
//
this.count.HeaderText = "Count";
this.count.Name = "count";
//
// FormComponentsOnSushi
//
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.dataGridView);
this.Controls.Add(this.ButtonSave);
this.Name = "FormComponentsOnSushi";
this.Text = "FormComponentsOnSushi";
this.Load += new System.EventHandler(this.FormComponentsOnSushi_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button ButtonSave;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn component;
private DataGridViewTextBoxColumn sushi;
private DataGridViewTextBoxColumn count;
}
}

View File

@ -0,0 +1,76 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar
{
public partial class FormSushiOnComponents : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormSushiOnComponents(ILogger<FormSushiOnComponents> logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void ButtonSave_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveProductComponentToExcelFile(new
ReportBindingModel
{
FileName = dialog.FileName
});
_logger.LogInformation("Saving list sushi on components");
MessageBox.Show("Success", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void FormComponentsOnSushi_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetSushi();
if (dict != null)
{
dataGridView.Rows.Clear();
foreach (var elem in dict)
{
dataGridView.Rows.Add(new object[] { elem.SushiName, "", "" });
foreach (var listElem in elem.Components)
{
dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 });
}
dataGridView.Rows.Add(new object[] { "Count", "", elem.TotalCount });
dataGridView.Rows.Add(Array.Empty<object>());
}
}
_logger.LogInformation("Load list sushi on components");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error on load list sushi on components");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,69 @@
<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>
<metadata name="sushi.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -1,17 +1,63 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarBusinessLogic.OfficePackage;
using SushiBarBusinessLogic.OfficePackage.Implements;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.StoragesContracts;
using SushiBarDatabaseImplement.Implements;
namespace SushiBar
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ISushiStorage, SushiStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISushiLogic, SushiLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<IStoreStorage, StoreStorage>();
services.AddTransient<IStoreLogic, StoreLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormSushi>();
services.AddTransient<FormSushiComponent>();
services.AddTransient<FormSushiMoreThenOne>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormSushiOnComponents>();
services.AddTransient<FormStores>();
services.AddTransient<FormStore>();
services.AddTransient<FormStoreReplenishment>();
services.AddTransient<FormStoreSell>();
services.AddTransient<FormStoreWorkload>();
services.AddTransient<FormReportOrdersGroupByDate>();
}
}
}

View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace SushiBar.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SushiBar.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,451 @@
<?xml version="1.0" encoding="utf-8"?>
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<AutoRefresh>0</AutoRefresh>
<DataSources>
<DataSource Name="SushiBarContractsViewModel">
<ConnectionProperties>
<DataProvider>System.Data.DataSet</DataProvider>
<ConnectString>/* Local Connection */</ConnectString>
</ConnectionProperties>
<rd:DataSourceID>bf577a27-98a7-43b2-8beb-1a37d37ce5cd</rd:DataSourceID>
</DataSource>
</DataSources>
<DataSets>
<DataSet Name="DataSetOrdersGroup">
<Query>
<DataSourceName>SushiBarContractsViewModel</DataSourceName>
<CommandText>/* Local Query */</CommandText>
</Query>
<Fields>
<Field Name="OrderDate">
<DataField>OrderDate</DataField>
<rd:TypeName>System.DateTime</rd:TypeName>
</Field>
<Field Name="Count">
<DataField>Count</DataField>
<rd:TypeName>System.Integer</rd:TypeName>
</Field>
<Field Name="Sum">
<DataField>Sum</DataField>
<rd:TypeName>System.Decimal</rd:TypeName>
</Field>
</Fields>
<rd:DataSetInfo>
<rd:DataSetName>SushiBarContracts.ViewModels</rd:DataSetName>
<rd:TableName>ReportOrderGroupViewModel</rd:TableName>
<rd:ObjectDataSourceType>SushiBarContracts.ViewModels.ReportOrderGroupViewModel, SushiBarContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>
</rd:DataSetInfo>
</DataSet>
</DataSets>
<ReportSections>
<ReportSection>
<Body>
<ReportItems>
<Textbox Name="Textbox1">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Orders</Value>
<Style>
<FontSize>20pt</FontSize>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Center</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox1</rd:DefaultName>
<Height>0.99688cm</Height>
<Width>21.51cm</Width>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<Tablix Name="Tablix1">
<TablixBody>
<TablixColumns>
<TablixColumn>
<Width>9.33979cm</Width>
</TablixColumn>
<TablixColumn>
<Width>5.00063cm</Width>
</TablixColumn>
<TablixColumn>
<Width>5.97895cm</Width>
</TablixColumn>
</TablixColumns>
<TablixRows>
<TablixRow>
<Height>2.22236cm</Height>
<TablixCells>
<TablixCell>
<CellContents>
<Textbox Name="Textbox2">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Date</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox2</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Textbox4">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Count</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox4</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Textbox6">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Sum</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox6</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
</TablixCells>
</TablixRow>
<TablixRow>
<Height>2.22236cm</Height>
<TablixCells>
<TablixCell>
<CellContents>
<Textbox Name="OrderDate">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!OrderDate.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>OrderDate</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Count">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!Count.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Count</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
<TablixCell>
<CellContents>
<Textbox Name="Sum">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!Sum.Value</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Sum</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</CellContents>
</TablixCell>
</TablixCells>
</TablixRow>
</TablixRows>
</TablixBody>
<TablixColumnHierarchy>
<TablixMembers>
<TablixMember />
<TablixMember />
<TablixMember />
</TablixMembers>
</TablixColumnHierarchy>
<TablixRowHierarchy>
<TablixMembers>
<TablixMember>
<KeepWithGroup>After</KeepWithGroup>
</TablixMember>
<TablixMember>
<Group Name="Подробности" />
</TablixMember>
</TablixMembers>
</TablixRowHierarchy>
<DataSetName>DataSetOrdersGroup</DataSetName>
<Top>2.4609cm</Top>
<Left>0.60854cm</Left>
<Height>4.44472cm</Height>
<Width>20.31937cm</Width>
<ZIndex>1</ZIndex>
<Style>
<Border>
<Style>Solid</Style>
</Border>
</Style>
</Tablix>
<Textbox Name="Textbox12">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Parameters!ReportParameterPeriod.Value</Value>
<Style>
<FontSize>12pt</FontSize>
</Style>
</TextRun>
</TextRuns>
<Style>
<TextAlign>Center</TextAlign>
</Style>
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox12</rd:DefaultName>
<Top>1.42557cm</Top>
<Height>0.6cm</Height>
<Width>21.51cm</Width>
<ZIndex>2</ZIndex>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<Textbox Name="Textbox13">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>Total</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
<Paragraph>
<TextRuns>
<TextRun>
<Value />
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox13</rd:DefaultName>
<Top>7.43162cm</Top>
<Left>16.16604cm</Left>
<Height>0.6cm</Height>
<Width>2.5cm</Width>
<ZIndex>3</ZIndex>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
<Textbox Name="Textbox14">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Sum(Fields!Sum.Value, "DataSetOrders")</Value>
<Style />
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Textbox14</rd:DefaultName>
<Top>7.43162cm</Top>
<Left>18.66604cm</Left>
<Height>0.6cm</Height>
<Width>2.26187cm</Width>
<ZIndex>4</ZIndex>
<Style>
<Border>
<Style>None</Style>
</Border>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
</Textbox>
</ReportItems>
<Height>3.22917in</Height>
<Style />
</Body>
<Width>8.50383in</Width>
<Page>
<PageHeight>29.7cm</PageHeight>
<PageWidth>21cm</PageWidth>
<LeftMargin>2cm</LeftMargin>
<RightMargin>2cm</RightMargin>
<TopMargin>2cm</TopMargin>
<BottomMargin>2cm</BottomMargin>
<ColumnSpacing>0.13cm</ColumnSpacing>
<Style />
</Page>
</ReportSection>
</ReportSections>
<ReportParameters>
<ReportParameter Name="ReportParameterPeriod">
<DataType>String</DataType>
<Nullable>true</Nullable>
<Prompt>ReportParameter1</Prompt>
</ReportParameter>
</ReportParameters>
<ReportParametersLayout>
<GridLayoutDefinition>
<NumberOfColumns>4</NumberOfColumns>
<NumberOfRows>2</NumberOfRows>
<CellDefinitions>
<CellDefinition>
<ColumnIndex>0</ColumnIndex>
<RowIndex>0</RowIndex>
<ParameterName>ReportParameterPeriod</ParameterName>
</CellDefinition>
</CellDefinitions>
</GridLayoutDefinition>
</ReportParametersLayout>
<rd:ReportUnitType>Cm</rd:ReportUnitType>
<rd:ReportID>10f2c1a3-5a29-4515-be40-6fe4bab54720</rd:ReportID>
</Report>

View File

@ -8,4 +8,37 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.17" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
<ProjectReference Include="..\SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj" />
<ProjectReference Include="..\SushiBarFileImplement\SushiBarFileImplement.csproj" />
<ProjectReference Include="..\SushibarListImplement\SushibarListImplement.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -0,0 +1,109 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace SushiBarBusinessLogic.BusinessLogics
{
public class ComponentLogic : IComponentLogic
{
private readonly ILogger _logger;
private readonly IComponentStorage _componentStorage;
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
{
_logger = logger;
_componentStorage = componentStorage;
}
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
{
_logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{Id}", model?.ComponentName, model?.Id);
var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ComponentViewModel? ReadElement(ComponentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id);
var element = _componentStorage.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(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ComponentBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_componentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ComponentBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ComponentName))
{
throw new ArgumentNullException("Name of component is empty", nameof(model.ComponentName));
}
if (model.Cost <= 0)
{
throw new ArgumentNullException("Cost must be more then zero", nameof(model.Cost));
}
_logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
var element = _componentStorage.GetElement(new ComponentSearchModel
{
ComponentName = model.ComponentName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("This name is already exists");
}
}
}
}

View File

@ -0,0 +1,138 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Enums;
namespace SushiBarBusinessLogic.BusinessLogics
{
public class OrderLogic : IOrderLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IStoreLogic _storeLogic;
private readonly ISushiStorage _sushiStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IStoreLogic storeLogic, ISushiStorage sushiStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_storeLogic = storeLogic;
_sushiStorage = sushiStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Unknown)
{
_logger.LogWarning("Insert operation failed. Order status incorrect.");
return false;
}
model.Status = OrderStatus.Accepted;
if (_orderStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
return UpdateStatus(model, OrderStatus.Ready);
}
public bool FinishOrder(OrderBindingModel model)
{
return UpdateStatus(model, OrderStatus.Issued);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList .Id:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return UpdateStatus(model, OrderStatus.Performed);
}
private bool UpdateStatus(OrderBindingModel model, OrderStatus status)
{
CheckModel(model);
var order = _orderStorage.GetElement(new OrderSearchModel() { Id = model.Id });
if (model.Status + 1 != status)
{
_logger.LogWarning("Status update operation failed");
return false;
}
if (status == OrderStatus.Ready)
{
var sushi = _sushiStorage.GetElement(new() { Id = model.SushiId });
if (sushi == null)
{
_logger.LogWarning("Status update to " + status + " operation failed. Document not found.");
return false;
}
if (!_storeLogic.CheckToSupply(sushi, model.Count))
{
_logger.LogWarning("Status update to " + status + " operation failed. Shop supply error.");
return false;
}
}
model.Status = status;
model.DateImplement = order?.DateImplement;
if (model.Status == OrderStatus.Issued)
{
model.DateImplement = DateTime.Now;
}
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
_logger.LogInformation("Order. OrderId:{Id} .Count:{Count} .Sum:{Sum} .Status{Status} .DateCreate{DateCreate}", model.Id, model.Count, model.Sum, model.Status.ToString(), model.DateCreate.ToString());
var element = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("This name is already exists");
}
}
}
}

View File

@ -0,0 +1,163 @@
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
using SushiBarBusinessLogic.OfficePackage;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
namespace SushiBarBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly IComponentStorage _componentStorage;
private readonly ISushiStorage _sushiStorage;
private readonly IOrderStorage _orderStorage;
private readonly IStoreStorage _storeStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(
ISushiStorage sushiStorage,
IComponentStorage componentStorage,
IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel,
AbstractSaveToWord saveToWord,
AbstractSaveToPdf saveToPdf, IStoreStorage storeStorage)
{
_sushiStorage = sushiStorage;
_componentStorage = componentStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
_storeStorage = storeStorage;
}
public List<ReportSushiComponentViewModel> GetSushi()
{
var sushi = _sushiStorage.GetFullList();
var list = new List<ReportSushiComponentViewModel>();
foreach (var suh in sushi)
{
var record = new ReportSushiComponentViewModel
{
SushiName = suh.SushiName,
Components = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach (var component in suh.SushiComponents)
{
record.Components.Add(new Tuple<string, int>(component.Value.Item1.ComponentName, component.Value.Item2));
record.TotalCount += component.Value.Item2;
}
list.Add(record);
}
return list;
}
public List<StoreViewModel> GetStores()
{
return _storeStorage.GetFullList();
}
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
{
return _orderStorage.GetFilteredList(new OrderSearchModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo
})
.Select(x => new ReportOrdersViewModel
{
Id = x.Id,
DateCreate = x.DateCreate,
SushiName = x.SushiName,
Sum = x.Sum,
Status = x.Status.ToString()
})
.ToList();
}
public List<ReportOrderGroupViewModel> GetGroupOrders()
{
return _orderStorage.GetFullList()
.Select(x => new ReportOrdersViewModel
{
Id = x.Id,
DateCreate = x.DateCreate,
SushiName = x.SushiName,
Sum = x.Sum,
Status = x.Status.ToString()
})
.GroupBy(x => x.DateCreate.ToShortDateString())
.Select(x => new ReportOrderGroupViewModel
{
OrderDate = DateTime.Parse(x.Key),
Count = x.Count(),
Sum = x.Sum(y => y.Sum),
}).ToList();
}
public void SaveStoresToWordFile(ReportBindingModel model)
{
_saveToWord.CreateTableDoc(new WordInfo
{
FileName = model.FileName,
Title = "Stores list",
Stores = _storeStorage.GetFullList()
});
}
public void SaveWorkloadStoresToExcel(ReportBindingModel model)
{
_saveToExcel.CreateReportStores(new ExcelInfo
{
FileName = model.FileName,
Title = "Workload stores",
Stores = _storeStorage.GetFullList()
});
}
public void SaveSushiToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Sushi list",
Sushi = _sushiStorage.GetFullList()
});
}
public void SaveProductComponentToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Sushi",
Sushi = GetSushi()
});
}
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Orders list",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Orders = GetOrders(model)
});
}
public void SaveOrdersGroupedToPdf(ReportBindingModel model)
{
_saveToPdf.CreateDocGroupedByDate(new PdfInfo
{
FileName = model.FileName,
Title = "Order list grouped by date",
GroupOrders = GetGroupOrders()
});
}
}
}

View File

@ -0,0 +1,289 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBarBusinessLogic.BusinessLogics
{
public class StoreLogic : IStoreLogic
{
private readonly ILogger _logger;
private readonly IStoreStorage _storeStorage;
public StoreLogic(ILogger<StoreLogic> logger, IStoreStorage storeStorage)
{
_logger = logger;
_storeStorage = storeStorage;
}
public bool AddPackage(StoreSearchModel model, ISushiModel sushi, int quantity)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (quantity <= 0)
{
throw new ArgumentException("Quantity must be more then zero", nameof(quantity));
}
_logger.LogInformation("AddPackageInStore. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id);
var element = _storeStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("AddPackageInStore element not found");
return false;
}
_logger.LogInformation("AddPackageInStore find. Id:{Id}", element.Id);
if (element.Sushis.TryGetValue(sushi.Id, out var pair))
{
element.Sushis[sushi.Id] = (sushi, quantity + pair.Item2);
_logger.LogInformation("AddPackageInStore. Has been added {quantity} {package} in {StoreName}", quantity, sushi.SushiName, element.StoreName);
}
else
{
element.Sushis[sushi.Id] = (sushi, quantity);
_logger.LogInformation("AddPastryInShop. Has been added {quantity} new Package {package} in {StoreName}", quantity, sushi.SushiName, element.StoreName);
}
_storeStorage.Update(new()
{
Id = element.Id,
StoreAddress = element.StoreAddress,
StoreName = element.StoreName,
OpeningDate = element.OpeningDate,
Sushis = element.Sushis,
maxSushi = element.maxSushi
});
return true;
}
public bool Create(StoreBindingModel model)
{
CheckModel(model);
model.Sushis = new();
if (_storeStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(StoreBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_storeStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool SupplySushi(StoreSearchModel model, ISushiModel sushi, int quantity)
{
if (model == null || sushi == null || quantity <= 0)
{
throw new ArgumentNullException();
}
var store = _storeStorage.GetElement(model);
if (store == null)
{
_logger.LogWarning("Required store element not found in storage");
return false;
}
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", store.Id, store.StoreName);
int countSushi = store.Sushis.Sum(s => s.Value.Item2);
if (store.maxSushi - countSushi >= quantity)
{
if (store.Sushis.TryGetValue(sushi.Id, out var pair))
{
store.Sushis[sushi.Id] = (sushi, quantity + pair.Item2);
_logger.LogInformation("AddPackageInStore. Has been added {quantity} {package} in {StoreName}", quantity, sushi.SushiName, store.StoreName);
}
else
{
store.Sushis[sushi.Id] = (sushi, quantity);
_logger.LogInformation("AddPastryInShop. Has been added {quantity} new Package {package} in {StoreName}", quantity, sushi.SushiName, store.StoreName);
}
_storeStorage.Update(new()
{
Id = store.Id,
StoreAddress = store.StoreAddress,
StoreName = store.StoreName,
OpeningDate = store.OpeningDate,
Sushis = store.Sushis,
maxSushi = store.maxSushi
});
}
else
{
_logger.LogWarning("Required shop is overflowed");
return false;
}
return true;
}
public bool CheckToSupply(ISushiModel sushi, int quantity)
{
if (quantity <= 0)
{
_logger.LogWarning("Check then supply operation error. Document count < 0.");
return false;
}
int countSushi = 0;
foreach (var store in _storeStorage.GetFullList())
{
countSushi += store.maxSushi;
countSushi = store.Sushis.Values.Aggregate(countSushi, (current, valueTuple) => current - valueTuple.Item2);
}
if (countSushi - quantity < 0)
{
_logger.LogWarning("Check then supply operation error. There's no place for new docs in stores.");
return false;
}
foreach (var store in _storeStorage.GetFullList())
{
countSushi = store.Sushis.Values.Aggregate(store.maxSushi, (current, valueTuple) => current - valueTuple.Item2);
if (countSushi == 0)
{
continue;
}
if (countSushi - quantity >= 0)
{
if (SupplySushi(new() { Id = store.Id }, sushi, countSushi))
countSushi = 0;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (countSushi - quantity < 0)
{
if (SupplySushi(new StoreSearchModel { Id = store.Id }, sushi, countSushi))
quantity -= countSushi;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (countSushi <= 0)
{
return true;
}
}
return false;
}
public bool SellSushi(ISushiModel model, int quantity)
{
return _storeStorage.SellSushi(model, quantity);
}
public StoreViewModel? ReadElement(StoreSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id);
var element = _storeStorage.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<StoreViewModel>? ReadList(StoreSearchModel? model)
{
_logger.LogInformation("ReadList. StoreName:{StoreName}.Id:{ Id} ", model?.StoreName, model?.Id);
var list = model == null ? _storeStorage.GetFullList() : _storeStorage.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(StoreBindingModel model)
{
CheckModel(model, false);
if (string.IsNullOrEmpty(model.StoreName))
{
throw new ArgumentNullException("Store name is empty!", nameof(model.StoreName));
}
if (_storeStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(StoreBindingModel model, bool withParams=true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.StoreName))
{
throw new ArgumentNullException("Store name is empty!", nameof(model.StoreName));
}
_logger.LogInformation("Store. StoreName:{0}.StoreAdress:{1}. Id: {2}", model.StoreName, model.StoreAddress, model.Id);
var element = _storeStorage.GetElement(new StoreSearchModel
{
StoreName = model.StoreName
});
if (element != null && element.Id != model.Id && element.StoreName == model.StoreName)
{
throw new InvalidOperationException("This name of store is already exists!");
}
}
}
}

View File

@ -0,0 +1,113 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
namespace SushiBarBusinessLogic.BusinessLogics
{
public class SushiLogic : ISushiLogic
{
private readonly ILogger _logger;
private readonly ISushiStorage _sushiStorage;
public SushiLogic(ILogger<ComponentLogic> logger, ISushiStorage sushiStorage)
{
_logger = logger;
_sushiStorage = sushiStorage;
}
public bool Create(SushiBindingModel model)
{
CheckModel(model);
if (_sushiStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(SushiBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_sushiStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public SushiViewModel? ReadElement(SushiSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. SushiName:{SushiName}.Id:{Id}", model.SushiName, model.Id);
var element = _sushiStorage.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<SushiViewModel>? ReadList(SushiSearchModel? model)
{
_logger.LogInformation("ReadList. SushiName:{SushiName}.Id:{Id}", model?.SushiName, model?.Id);
var list = model == null ? _sushiStorage.GetFullList() : _sushiStorage.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(SushiBindingModel model)
{
CheckModel(model);
if (_sushiStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(SushiBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.SushiName))
{
throw new ArgumentNullException("Name of sushi is empty", nameof(model.SushiName));
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Price must be more then zero", nameof(model.Price));
}
_logger.LogInformation("Sushi. SushiName:{SushiName} .Price:{Price}. Id:{Id}", model.SushiName, model.Price, model.Id);
var element = _sushiStorage.GetElement(new SushiSearchModel {
SushiName = model.SushiName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("This name is already exists");
}
}
}
}

View File

@ -0,0 +1,162 @@
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
namespace SushiBarBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcel
{
public void CreateReport(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var sushi in info.Sushi)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = sushi.SushiName,
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var com in sushi.Components)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = com.Item1,
StyleInfo =
ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = com.Item2.ToString(),
StyleInfo =
ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Total",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = sushi.TotalCount.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
public void CreateReportStores(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var storeViewModel in info.Stores)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = storeViewModel.StoreName,
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = "Sushi",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = "Count",
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var com in storeViewModel.Sushis)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = com.Value.Item2.ToString(),
StyleInfo =
ExcelStyleInfoType.TextWithBroder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = com.Value.Item1.SushiName,
StyleInfo =
ExcelStyleInfoType.TextWithBroder
});
rowIndex++;
}
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = "Total",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = storeViewModel.Sushis
.Values
.Select(x => x.Item2)
.Sum()
.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
}
SaveExcel(info);
}
protected abstract void CreateExcel(ExcelInfo info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
protected abstract void MergeCells(ExcelMergeParameters excelParams);
protected abstract void SaveExcel(ExcelInfo info);
}
}

View File

@ -0,0 +1,96 @@
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
namespace SushiBarBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = $"с{ info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style= "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "2cm", "3cm", "6cm", "2cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Id", "Date", "Sushi", "Status", "Cost" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.Orders)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> {
order.Id.ToString(),
order.DateCreate.ToShortDateString(),
order.SushiName,
order.Status.ToString(),
order.Sum.ToString()
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Total: {info.Orders.Sum(x=> x.Sum)}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Rigth
});
SavePdf(info);
}
public void CreateDocGroupedByDate(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "4cm", "4cm", "4cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Date", "Count", "Sum" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var order in info.GroupOrders)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> {
order.OrderDate.ToShortDateString(),
order.Count.ToString(),
order.Sum.ToString()
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Total: {info.GroupOrders.Sum(x=> x.Sum)}\t",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Rigth
});
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreateParagraph(PdfParagraph paragraph);
protected abstract void CreateTable(List<string> columns);
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -0,0 +1,80 @@
using DocumentFormat.OpenXml.Wordprocessing;
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
namespace SushiBarBusinessLogic.OfficePackage;
public abstract class AbstractSaveToWord
{
public void CreateTableDoc(WordInfo info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
var rows = info.Stores
.Select(store => CreateRow(
new()
{
CreateCell(new WordCell { Text = store.StoreName }),
CreateCell(new WordCell { Text = store.StoreAddress }),
CreateCell(new WordCell { Text = store.OpeningDate.ToShortDateString()})
})).ToList();
rows.Insert(0, CreateRow(new ()
{
CreateCell(new WordCell{ Text = "Store name", Width = 3000 }),
CreateCell(new WordCell{ Text = "Store Address", Width = 2000 }),
CreateCell(new WordCell{ Text = "Opening Date", Width = 3000 }),
}));
CreateTable(rows);
SaveWord(info);
}
public void CreateDoc(WordInfo info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(info.Title, new WordTextProperties { Bold = true, Size = "24", })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
foreach (var sushi in info.Sushi)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(sushi.SushiName, new WordTextProperties { Bold = true, Size = "24" }),
($" {sushi.Price}", new WordTextProperties { Size = "24", JustificationType = WordJustificationType.Right }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);
}
protected abstract void CreateWord(WordInfo info);
protected abstract void CreateParagraph(WordParagraph? paragraph);
protected abstract void SaveWord(WordInfo info);
protected abstract void CreateTable(List<TableRow> rows);
protected abstract TableRow CreateRow(List<TableCell> cells);
protected abstract TableCell CreateCell(WordCell cell);
}

View File

@ -0,0 +1,7 @@
namespace SushiBarBusinessLogic.OfficePackage.HelpersEnum
{
public enum ExcelStyleInfoType
{
Title, Text, TextWithBroder
}
}

View File

@ -0,0 +1,9 @@
namespace SushiBarBusinessLogic.OfficePackage.HelpersEnum
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Rigth
}
}

View File

@ -0,0 +1,7 @@
namespace SushiBarBusinessLogic.OfficePackage.HelpersEnum
{
public enum WordJustificationType
{
Center,Both,Right
}
}

View File

@ -0,0 +1,13 @@
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class ExcelCellParameters
{
public string ColumnName { get; set; } = string.Empty;
public uint RowIndex { get; set; }
public string Text { get; set; } = string.Empty;
public string CellReference => $"{ColumnName}{RowIndex}";
public ExcelStyleInfoType StyleInfo { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using SushiBarContracts.ViewModels;
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class ExcelInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportSushiComponentViewModel> Sushi{ get; set; } = new();
public List<StoreViewModel> Stores { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class ExcelMergeParameters
{
public string CellFromName { get; set; } = string.Empty;
public string CellToName { get; set; } = string.Empty;
public string Merge => $"{CellFromName}:{CellToName}";
}
}

View File

@ -0,0 +1,14 @@
using SushiBarContracts.ViewModels;
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class PdfInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportOrdersViewModel> Orders { get; set; } = new();
public List<ReportOrderGroupViewModel> GroupOrders { get; set; } = new();
}
}

View File

@ -0,0 +1,11 @@
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class PdfParagraph
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class PdfRowParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels;
public class WordCell
{
public int Width { get; set; }
public string Text { get; set; } = string.Empty;
}

View File

@ -0,0 +1,12 @@
using SushiBarContracts.ViewModels;
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class WordInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<SushiViewModel> Sushi { get; set; } = new();
public List<StoreViewModel> Stores { get; set; } = new();
}
}

View File

@ -0,0 +1,8 @@
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class WordParagraph
{
public List<(string, WordTextProperties)> Texts { get; set; } = new();
public WordTextProperties? TextProperties { get; set; }
}
}

View File

@ -0,0 +1,11 @@
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
namespace SushiBarBusinessLogic.OfficePackage.HelpersModels
{
public class WordTextProperties
{
public string Size { get; set; } = string.Empty;
public bool Bold { get; set; }
public WordJustificationType JustificationType { get; set; }
}
}

View File

@ -0,0 +1,298 @@
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Office2016.Excel;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
namespace SushiBarBusinessLogic.OfficePackage.Implements
{
public class SaveToExcel : AbstractSaveToExcel
{
private SpreadsheetDocument? _spreadsheetDocument;
private SharedStringTablePart? _shareStringPart;
private Worksheet? _worksheet;
private static void CreateStyles(WorkbookPart workbookpart)
{
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
sp.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
var fontUsual = new Font();
fontUsual.Append(new FontSize() { Val = 12D });
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Theme = 1U });
fontUsual.Append(new FontName() { Val = "Times New Roman" });
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
var fontTitle = new Font();
fontTitle.Append(new Bold());
fontTitle.Append(new FontSize() { Val = 14D });
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Theme = 1U });
fontTitle.Append(new FontName() { Val = "Times New Roman" });
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
fonts.Append(fontUsual);
fonts.Append(fontTitle);
var fills = new Fills() { Count = 2U };
var fill1 = new Fill();
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
var fill2 = new Fill();
fill2.Append(new PatternFill()
{
PatternType = PatternValues.Gray125
});
fills.Append(fill1);
fills.Append(fill2);
var borders = new Borders() { Count = 2U };
var borderNoBorder = new Border();
borderNoBorder.Append(new LeftBorder());
borderNoBorder.Append(new RightBorder());
borderNoBorder.Append(new TopBorder());
borderNoBorder.Append(new BottomBorder());
borderNoBorder.Append(new DiagonalBorder());
var borderThin = new Border();
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color()
{ Indexed = 64U });
var rightBorder = new RightBorder()
{
Style = BorderStyleValues.Thin
};
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var bottomBorder = new BottomBorder()
{
Style = BorderStyleValues.Thin
};
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
borderThin.Append(leftBorder);
borderThin.Append(rightBorder);
borderThin.Append(topBorder);
borderThin.Append(bottomBorder);
borderThin.Append(new DiagonalBorder());
borders.Append(borderNoBorder);
borders.Append(borderThin);
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
var cellFormatStyle = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 0U
};
cellStyleFormats.Append(cellFormatStyle);
var cellFormats = new CellFormats() { Count = 3U };
var cellFormatFont = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 0U,
FormatId = 0U,
ApplyFont = true
};
var cellFormatFontAndBorder = new CellFormat()
{
NumberFormatId = 0U,
FontId = 0U,
FillId = 0U,
BorderId = 1U,
FormatId = 0U,
ApplyFont = true,
ApplyBorder = true
};
var cellFormatTitle = new CellFormat()
{
NumberFormatId = 0U,
FontId = 1U,
FillId = 0U,
BorderId = 0U,
FormatId = 0U,
Alignment = new Alignment()
{
Vertical = VerticalAlignmentValues.Center,
WrapText = true,
Horizontal = HorizontalAlignmentValues.Center
},
ApplyFont = true
};
cellFormats.Append(cellFormatFont);
cellFormats.Append(cellFormatFontAndBorder);
cellFormats.Append(cellFormatTitle);
var cellStyles = new CellStyles() { Count = 1U };
cellStyles.Append(new CellStyle()
{
Name = "Normal",
FormatId = 0U,
BuiltinId = 0U
});
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U };
var tableStyles = new TableStyles()
{
Count = 0U,
DefaultTableStyle = "TableStyleMedium2",
DefaultPivotStyle = "PivotStyleLight16"
};
var stylesheetExtensionList = new StylesheetExtensionList();
var stylesheetExtension1 = new StylesheetExtension()
{
Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"
};
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
stylesheetExtension1.Append(new SlicerStyles()
{
DefaultSlicerStyle = "SlicerStyleLight1"
});
var stylesheetExtension2 = new StylesheetExtension()
{
Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}"
};
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
stylesheetExtension2.Append(new TimelineStyles()
{
DefaultTimelineStyle = "TimeSlicerStyleLight1"
});
stylesheetExtensionList.Append(stylesheetExtension1);
stylesheetExtensionList.Append(stylesheetExtension2);
sp.Stylesheet.Append(fonts);
sp.Stylesheet.Append(fills);
sp.Stylesheet.Append(borders);
sp.Stylesheet.Append(cellStyleFormats);
sp.Stylesheet.Append(cellFormats);
sp.Stylesheet.Append(cellStyles);
sp.Stylesheet.Append(differentialFormats);
sp.Stylesheet.Append(tableStyles);
sp.Stylesheet.Append(stylesheetExtensionList);
}
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
{
return styleInfo switch
{
ExcelStyleInfoType.Title => 2U,
ExcelStyleInfoType.TextWithBroder => 1U,
ExcelStyleInfoType.Text => 0U,
_ => 0U,
};
}
protected override void CreateExcel(ExcelInfo info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
CreateStyles(workbookpart);
_shareStringPart =_spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
: _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
_shareStringPart.SharedStringTable ??= new SharedStringTable();
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id =_spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Лист"
};
sheets.Append(sheet);
_worksheet = worksheetPart.Worksheet;
}
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
{
if (_worksheet == null || _shareStringPart == null)
{
return;
}
var sheetData = _worksheet.GetFirstChild<SheetData>();
if (sheetData == null)
{
return;
}
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
}
else
{
row = new Row() { RowIndex = excelParams.RowIndex };
sheetData.Append(row);
}
Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
{
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
}
else
{
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
{
refCell = rowCell;
break;
}
}
var newCell = new Cell()
{
CellReference = excelParams.CellReference
};
row.InsertBefore(newCell, refCell);
cell = newCell;
}
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
_shareStringPart.SharedStringTable.Save();
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
}
protected override void MergeCells(ExcelMergeParameters excelParams)
{
if (_worksheet == null)
{
return;
}
MergeCells mergeCells;
if (_worksheet.Elements<MergeCells>().Any())
{
mergeCells = _worksheet.Elements<MergeCells>().First();
}
else
{
mergeCells = new MergeCells();
if (_worksheet.Elements<CustomSheetView>().Any())
{
_worksheet.InsertAfter(mergeCells,
_worksheet.Elements<CustomSheetView>().First());
}
else
{
_worksheet.InsertAfter(mergeCells,
_worksheet.Elements<SheetData>().First());
}
}
var mergeCell = new MergeCell()
{
Reference = new StringValue(excelParams.Merge)
};
mergeCells.Append(mergeCell);
}
protected override void SaveExcel(ExcelInfo info)
{
if (_spreadsheetDocument == null)
{
return;
}
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
_spreadsheetDocument.Close();
}
}
}

View File

@ -0,0 +1,95 @@
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
namespace SushiBarBusinessLogic.OfficePackage.Implements
{
public class SaveToPdf : AbstractSaveToPdf
{
private Document? _document;
private Section? _section;
private Table? _table;
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_section == null)
{
return;
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
protected override void CreateTable(List<string> columns)
{
if (_document == null)
{
return;
}
_table = _document.LastSection.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
{
return;
}
var row = _table.AddRow();
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
if (!string.IsNullOrEmpty(rowParameters.Style))
{
row.Cells[i].Style = rowParameters.Style;
}
Unit borderWidth = 0.5;
row.Cells[i].Borders.Left.Width = borderWidth;
row.Cells[i].Borders.Right.Width = borderWidth;
row.Cells[i].Borders.Top.Width = borderWidth;
row.Cells[i].Borders.Bottom.Width = borderWidth;
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
}
}
protected override void SavePdf(PdfInfo info)
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
}
}

View File

@ -0,0 +1,148 @@
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
namespace SushiBarBusinessLogic.OfficePackage.Implements
{
public class SaveToWord : AbstractSaveToWord
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
{
WordJustificationType.Both => JustificationValues.Both,
WordJustificationType.Center => JustificationValues.Center,
WordJustificationType.Right => JustificationValues.Right,
_ => JustificationValues.Left,
};
}
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
var pageSize = new PageSize
{
Orient = PageOrientationValues.Portrait
};
properties.AppendChild(pageSize);
return properties;
}
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
{
if (paragraphProperties == null)
{
return null;
}
var properties = new ParagraphProperties();
properties.AppendChild(new Justification()
{
Val =
GetJustificationValues(paragraphProperties.JustificationType)
});
properties.AppendChild(new SpacingBetweenLines
{
LineRule = LineSpacingRuleValues.Auto
});
properties.AppendChild(new Indentation());
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
if (!string.IsNullOrEmpty(paragraphProperties.Size))
{
paragraphMarkRunProperties.AppendChild(new FontSize
{
Val =
paragraphProperties.Size
});
}
properties.AppendChild(paragraphMarkRunProperties);
return properties;
}
protected override void CreateWord(WordInfo info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
}
protected override void CreateParagraph(WordParagraph? paragraph)
{
if (_docBody == null || paragraph == null)
{
return;
}
var docParagraph = new Paragraph();
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
foreach (var run in paragraph.Texts)
{
var docRun = new Run();
var properties = new RunProperties();
properties.AppendChild(new FontSize { Val = run.Item2.Size });
if (run.Item2.Bold)
{
properties.AppendChild(new Bold());
}
docRun.AppendChild(properties);
docRun.AppendChild(new Text
{
Text = run.Item1,
Space = SpaceProcessingModeValues.Preserve
});
docParagraph.AppendChild(docRun);
}
_docBody.AppendChild(docParagraph);
}
protected override void SaveWord(WordInfo info)
{
if (_docBody == null || _wordDocument == null)
{
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Close();
}
protected override void CreateTable(List<TableRow> rows)
{
if (_docBody == null)
{
return;
}
var table = new Table();
var tblProp = new TableProperties(
new TableBorders(
new TopBorder { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new BottomBorder { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new LeftBorder { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new RightBorder { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new InsideHorizontalBorder { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 },
new InsideVerticalBorder { Val = new EnumValue<BorderValues>(BorderValues.BasicBlackDashes), Size = 3 }
)
);
table.AppendChild(tblProp);
table.Append(rows);
_docBody.Append(table);
}
protected override TableRow CreateRow(List<TableCell> cells)
{
return new TableRow(cells);
}
protected override TableCell CreateCell(WordCell cell)
{
var createCell = new TableCell(new Paragraph(
new Run(
new Text(cell.Text))));
createCell.Append(
new TableCellProperties(
new TableCellWidth { Width = cell.Width.ToString() }));
return createCell;
}
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="PDFsharp-MigraDoc" Version="1.50.5147" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,11 @@
using SushiBarDataModels.Models;
namespace SushiBarContracts.BindingModels
{
public class ComponentBindingModel : IComponentModel
{
public int Id { get; set; }
public string ComponentName { get; set; } = string.Empty;
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using SushiBarDataModels.Enums;
using SushiBarDataModels.Models;
namespace SushiBarContracts.BindingModels
{
public class OrderBindingModel : IOrderModel
{
public int Id { get; set; }
public int SushiId { get; set; }
public string SushiName { get; set; } = string.Empty;
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace SushiBarContracts.BindingModels
{
public class ReportBindingModel
{
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using SushiBarDataModels.Models;
namespace SushiBarContracts.BindingModels
{
public class StoreBindingModel : IStoreModel
{
public string StoreName { get; set; } = string.Empty;
public string StoreAddress { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Now;
public Dictionary<int, (ISushiModel, int)> Sushis { get; set; } = new();
public int maxSushi { get; set; }
public int Id { get; set; }
}
}

View File

@ -0,0 +1,12 @@
using SushiBarDataModels.Models;
namespace SushiBarContracts.BindingModels
{
public class SushiBindingModel : ISushiModel
{
public int Id { get; set; }
public string SushiName { get; set; } = string.Empty;
public double Price { get; set; }
public Dictionary<int, (IComponentModel, int)> SushiComponents { get; set; } = new();
}
}

View File

@ -0,0 +1,15 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.BusinessLogicsContracts
{
public interface IComponentLogic
{
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
ComponentViewModel? ReadElement(ComponentSearchModel model);
bool Create(ComponentBindingModel model);
bool Update(ComponentBindingModel model);
bool Delete(ComponentBindingModel model);
}
}

View File

@ -0,0 +1,15 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.BusinessLogicsContracts
{
public interface IOrderLogic
{
List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model);
bool DeliveryOrder(OrderBindingModel model);
}
}

View File

@ -0,0 +1,19 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.BusinessLogicsContracts
{
public interface IReportLogic
{
List<ReportSushiComponentViewModel> GetSushi();
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
public List<StoreViewModel> GetStores();
void SaveSushiToWordFile(ReportBindingModel model);
void SaveProductComponentToExcelFile(ReportBindingModel model);
void SaveOrdersToPdfFile(ReportBindingModel model);
public void SaveStoresToWordFile(ReportBindingModel model);
public void SaveWorkloadStoresToExcel(ReportBindingModel model);
public void SaveOrdersGroupedToPdf(ReportBindingModel model);
public List<ReportOrderGroupViewModel> GetGroupOrders();
}
}

View File

@ -0,0 +1,19 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBarContracts.BusinessLogicsContracts
{
public interface IStoreLogic
{
List<StoreViewModel>? ReadList(StoreSearchModel? model);
StoreViewModel? ReadElement(StoreSearchModel model);
bool Create(StoreBindingModel model);
bool Update(StoreBindingModel model);
bool Delete(StoreBindingModel model);
bool SupplySushi(StoreSearchModel model, ISushiModel sushi, int quantity);
bool CheckToSupply(ISushiModel sushi, int quantity);
bool SellSushi(ISushiModel model, int quantity);
}
}

View File

@ -0,0 +1,15 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.BusinessLogicsContracts
{
public interface ISushiLogic
{
List<SushiViewModel>? ReadList(SushiSearchModel? model);
SushiViewModel? ReadElement(SushiSearchModel model);
bool Create(SushiBindingModel model);
bool Update(SushiBindingModel model);
bool Delete(SushiBindingModel model);
}
}

View File

@ -0,0 +1,8 @@
namespace SushiBarContracts.SearchModels
{
public class ComponentSearchModel
{
public int? Id { get; set; }
public string? ComponentName { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace SushiBarContracts.SearchModels
{
public class OrderSearchModel
{
public int? Id { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace SushiBarContracts.SearchModels
{
public class StoreSearchModel
{
public int? Id { get; set; }
public string? StoreName { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace SushiBarContracts.SearchModels
{
public class SushiSearchModel
{
public int? Id { get; set; }
public string? SushiName { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.StoragesContracts
{
public interface IComponentStorage
{
List<ComponentViewModel> GetFullList();
List<ComponentViewModel> GetFilteredList(ComponentSearchModel model);
ComponentViewModel? GetElement(ComponentSearchModel model);
ComponentViewModel? Insert(ComponentBindingModel model);
ComponentViewModel? Update(ComponentBindingModel model);
ComponentViewModel? Delete(ComponentBindingModel model);
}
}

View File

@ -0,0 +1,16 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.StoragesContracts
{
public interface IOrderStorage
{
List<OrderViewModel> GetFullList();
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
OrderViewModel? GetElement(OrderSearchModel model);
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
}
}

View File

@ -0,0 +1,18 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBarContracts.StoragesContracts
{
public interface IStoreStorage
{
List<StoreViewModel> GetFullList();
List<StoreViewModel> GetFilteredList(StoreSearchModel model);
StoreViewModel? GetElement(StoreSearchModel model);
StoreViewModel? Insert(StoreBindingModel model);
StoreViewModel? Update(StoreBindingModel model);
StoreViewModel? Delete(StoreBindingModel model);
bool SellSushi(ISushiModel model, int quantity);
}
}

View File

@ -0,0 +1,16 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.StoragesContracts
{
public interface ISushiStorage
{
List<SushiViewModel> GetFullList();
List<SushiViewModel> GetFilteredList(SushiSearchModel model);
SushiViewModel? GetElement(SushiSearchModel model);
SushiViewModel? Insert(SushiBindingModel model);
SushiViewModel? Update(SushiBindingModel model);
SushiViewModel? Delete(SushiBindingModel model);
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SushiBarModels\SushiBarDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,17 @@
using SushiBarDataModels.Models;
using System.ComponentModel;
namespace SushiBarContracts.ViewModels
{
public class ComponentViewModel : IComponentModel
{
public int Id { get; set; }
[DisplayName("Name of Component")]
public string ComponentName { get; set; } = string.Empty;
[DisplayName("Cost")]
public double Cost { get; set; }
}
}

View File

@ -0,0 +1,32 @@
using SushiBarDataModels.Enums;
using SushiBarDataModels.Models;
using System.ComponentModel;
namespace SushiBarContracts.ViewModels
{
public class OrderViewModel : IOrderModel
{
[DisplayName("Number")]
public int Id { get; set; }
public int SushiId { get; set; }
[DisplayName("Name of Product")]
public string SushiName { get; set; } = string.Empty;
[DisplayName("Count")]
public int Count { get; set; }
[DisplayName("Sum")]
public double Sum { get; set; }
[DisplayName("Status")]
public OrderStatus Status { get; set; } = OrderStatus.Unknown;
[DisplayName("Date Create")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Date Implement")]
public DateTime? DateImplement { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace SushiBarContracts.ViewModels;
public class ReportOrderGroupViewModel
{
public DateTime OrderDate { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
}

Some files were not shown because too many files have changed in this diff Show More