ПИбд-22 Боровков М В 5 лабораторная работа #6

Closed
bekodeg wants to merge 44 commits from labWork5 into labWork4
31 changed files with 1432 additions and 1668 deletions
Showing only changes of commit 93931fb296 - Show all commits

View File

@ -28,55 +28,75 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormComponent));
label1 = new Label(); label1 = new Label();
textBoxName = new TextBox(); textBoxName = new TextBox();
textBoxCost = new TextBox(); textBoxCost = new TextBox();
label2 = new Label(); label2 = new Label();
buttonSave = new Button(); ButtonSave = new Button();
buttonCancel = new Button(); ButtonCancel = new Button();
SuspendLayout(); SuspendLayout();
// //
// label1 // label1
// //
resources.ApplyResources(label1, "label1"); label1.AutoSize = true;
label1.Location = new Point(12, 9);
label1.Name = "label1"; label1.Name = "label1";
label1.Size = new Size(77, 20);
label1.TabIndex = 0;
label1.Text = "Название";
// //
// textBoxName // textBoxName
// //
resources.ApplyResources(textBoxName, "textBoxName"); textBoxName.Location = new Point(95, 6);
textBoxName.Name = "textBoxName"; textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(246, 27);
textBoxName.TabIndex = 1;
// //
// textBoxCost // textBoxCost
// //
resources.ApplyResources(textBoxCost, "textBoxCost"); textBoxCost.Location = new Point(95, 39);
textBoxCost.Name = "textBoxCost"; textBoxCost.Name = "textBoxCost";
textBoxCost.Size = new Size(246, 27);
textBoxCost.TabIndex = 3;
// //
// label2 // label2
// //
resources.ApplyResources(label2, "label2"); label2.AutoSize = true;
label2.ImeMode = ImeMode.NoControl;
label2.Location = new Point(12, 42);
label2.Name = "label2"; label2.Name = "label2";
label2.Size = new Size(45, 20);
label2.TabIndex = 2;
label2.Text = "Цена";
// //
// buttonSave // ButtonSave
// //
resources.ApplyResources(buttonSave, "buttonSave"); ButtonSave.Location = new Point(95, 85);
buttonSave.Name = "buttonSave"; ButtonSave.Name = "ButtonSave";
buttonSave.UseVisualStyleBackColor = true; ButtonSave.Size = new Size(121, 29);
buttonSave.Click += buttonSave_Click; ButtonSave.TabIndex = 4;
ButtonSave.Text = "Сохранить";
ButtonSave.UseVisualStyleBackColor = true;
ButtonSave.Click += ButtonSave_Click;
// //
// buttonCancel // ButtonCancel
// //
resources.ApplyResources(buttonCancel, "buttonCancel"); ButtonCancel.ImeMode = ImeMode.NoControl;
buttonCancel.Name = "buttonCancel"; ButtonCancel.Location = new Point(222, 85);
buttonCancel.UseVisualStyleBackColor = true; ButtonCancel.Name = "ButtonCancel";
buttonCancel.Click += buttonCancel_Click; ButtonCancel.Size = new Size(119, 29);
ButtonCancel.TabIndex = 5;
ButtonCancel.Text = "Отмена";
ButtonCancel.UseVisualStyleBackColor = true;
ButtonCancel.Click += ButtonCancel_Click;
// //
// FormComponent // FormComponent
// //
resources.ApplyResources(this, "$this"); AllowDrop = true;
AutoScaleMode = AutoScaleMode.None; AutoScaleMode = AutoScaleMode.None;
Controls.Add(buttonCancel); ClientSize = new Size(353, 126);
Controls.Add(buttonSave); Controls.Add(ButtonCancel);
Controls.Add(ButtonSave);
Controls.Add(textBoxCost); Controls.Add(textBoxCost);
Controls.Add(label2); Controls.Add(label2);
Controls.Add(textBoxName); Controls.Add(textBoxName);
@ -84,6 +104,7 @@
MaximizeBox = false; MaximizeBox = false;
Name = "FormComponent"; Name = "FormComponent";
ShowInTaskbar = false; ShowInTaskbar = false;
Text = "Компонент";
TopMost = true; TopMost = true;
Load += FormComponent_Load; Load += FormComponent_Load;
ResumeLayout(false); ResumeLayout(false);
@ -96,7 +117,7 @@
private TextBox textBoxName; private TextBox textBoxName;
private TextBox textBoxCost; private TextBox textBoxCost;
private Label label2; private Label label2;
private Button buttonSave; private Button ButtonSave;
private Button buttonCancel; private Button ButtonCancel;
} }
} }

View File

@ -1,17 +1,81 @@
using System; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace SushiBar.Forms namespace SushiBar.Forms
{ {
public partial class FormComponent public partial class FormComponent : Form
{ {
private void buttonSave_Click(object sender, EventArgs e) private readonly ILogger _logger;
private readonly IComponentLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormComponent(ILogger<FormComponent> logger, IComponentLogic logic)
{ {
ButtonSave_Click(sender, e); InitializeComponent();
_logger = logger;
_logic = logic;
} }
private void FormComponent_Load(object sender, EventArgs e)
private void buttonCancel_Click(object sender, EventArgs e)
{ {
ButtonCancel_Click(sender, e); if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение компонента");
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, "Ошибка получения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение компонента");
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("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
} }
} }
} }

View File

@ -117,178 +117,172 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="&gt;&gt;buttonSave.Name" xml:space="preserve">
<value>buttonSave</value>
</data>
<data name="&gt;&gt;textBox1.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;buttonCancel.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;buttonSave.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;label2.Type" xml:space="preserve"> <data name="&gt;&gt;label2.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="&gt;&gt;button2.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;buttonSave.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;textBoxCost.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;button2.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="button2.Location" type="System.Drawing.Point, System.Drawing">
<value>222, 85</value>
</data>
<data name="textBoxCost.Location" type="System.Drawing.Point, System.Drawing">
<value>95, 39</value>
</data>
<data name="&gt;&gt;buttonCancel.Name" xml:space="preserve">
<value>buttonCancel</value>
</data>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>8, 20</value>
</data>
<data name="&gt;&gt;label1.Name" xml:space="preserve">
<value>label1</value>
</data>
<data name="&gt;&gt;label1.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;textBoxName.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>FormComponent</value>
</data>
<data name="&gt;&gt;button2.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="label2.TabIndex" type="System.Int32, mscorlib"> <data name="Button1.TabIndex" type="System.Int32, mscorlib">
<value>2</value> <value>4</value>
</data> </data>
<data name="&gt;&gt;button1.Type" xml:space="preserve"> <data name="&gt;&gt;ButtonSave.Name" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>ButtonSave</value>
</data> </data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing"> <data name="&gt;&gt;Button2.Parent" xml:space="preserve">
<value>800, 450</value> <value>$this</value>
</data>
<data name="&gt;&gt;label1.ZOrder" xml:space="preserve">
<value>5</value>
</data> </data>
<data name="&gt;&gt;textBoxCost.ZOrder" xml:space="preserve"> <data name="&gt;&gt;textBoxCost.ZOrder" xml:space="preserve">
<value>2</value> <value>2</value>
</data> </data>
<data name="buttonCancel.Location" type="System.Drawing.Point, System.Drawing"> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<value>222, 85</value> <data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 9</value>
</data>
<data name="ButtonCancel.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data> </data>
<data name="&gt;&gt;textBox1.Parent" xml:space="preserve"> <data name="&gt;&gt;textBox1.Parent" xml:space="preserve">
<value>$this</value> <value>$this</value>
</data> </data>
<data name="&gt;&gt;buttonCancel.ZOrder" xml:space="preserve"> <data name="label2.TabIndex" type="System.Int32, mscorlib">
<value>0</value> <value>2</value>
</data> </data>
<data name="textBox1.Location" type="System.Drawing.Point, System.Drawing"> <data name="&gt;&gt;textBoxCost.Parent" xml:space="preserve">
<value>68, 6</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>FormComponent</value>
</data>
<data name="&gt;&gt;textBoxName.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="&gt;&gt;buttonSave.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="buttonCancel.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="&gt;&gt;buttonCancel.Parent" xml:space="preserve">
<value>$this</value> <value>$this</value>
</data> </data>
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 9</value>
</data>
<data name="&gt;&gt;label2.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="&gt;&gt;button1.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="button2.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="&gt;&gt;textBox1.Name" xml:space="preserve">
<value>textBox1</value>
</data>
<data name="textBox1.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="&gt;&gt;button1.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="button1.Location" type="System.Drawing.Point, System.Drawing">
<value>95, 85</value>
</data>
<data name="&gt;&gt;textBoxName.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;textBoxCost.Name" xml:space="preserve">
<value>textBoxCost</value>
</data>
<data name="textBoxCost.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
</data>
<data name="textBoxName.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="buttonSave.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
</data>
<data name="&gt;&gt;label2.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;button1.Name" xml:space="preserve">
<value>button1</value>
</data>
<data name="&gt;&gt;button2.Name" xml:space="preserve">
<value>button2</value>
</data>
<data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="buttonSave.Location" type="System.Drawing.Point, System.Drawing">
<value>95, 85</value>
</data>
<data name="&gt;&gt;label1.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>System.Windows.Forms.Form, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 42</value>
</data>
<data name="&gt;&gt;textBoxCost.Type" xml:space="preserve"> <data name="&gt;&gt;textBoxCost.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="textBox1.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="&gt;&gt;textBoxName.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="Button2.Location" type="System.Drawing.Point, System.Drawing">
<value>222, 85</value>
</data>
<data name="&gt;&gt;textBoxCost.Name" xml:space="preserve">
<value>textBoxCost</value>
</data>
<data name="&gt;&gt;label1.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;Button1.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;label2.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="Button2.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="&gt;&gt;ButtonSave.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="&gt;&gt;textBox1.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>800, 450</value>
</data>
<data name="ButtonCancel.Location" type="System.Drawing.Point, System.Drawing">
<value>222, 85</value>
</data>
<data name="ButtonSave.Location" type="System.Drawing.Point, System.Drawing">
<value>95, 85</value>
</data>
<data name="&gt;&gt;label1.ZOrder" xml:space="preserve">
<value>5</value>
</data>
<data name="textBoxName.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="&gt;&gt;ButtonCancel.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>FormComponent</value>
</data>
<data name="&gt;&gt;Button2.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 42</value>
</data>
<data name="ButtonSave.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
</data>
<data name="textBoxCost.Location" type="System.Drawing.Point, System.Drawing">
<value>95, 39</value>
</data>
<data name="&gt;&gt;Button1.Name" xml:space="preserve">
<value>Button1</value>
</data>
<data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="&gt;&gt;label1.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;ButtonSave.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;ButtonCancel.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;label1.Name" xml:space="preserve">
<value>label1</value>
</data>
<data name="&gt;&gt;textBoxName.Name" xml:space="preserve"> <data name="&gt;&gt;textBoxName.Name" xml:space="preserve">
<value>textBoxName</value> <value>textBoxName</value>
</data> </data>
<data name="&gt;&gt;Button1.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="&gt;&gt;textBoxName.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="textBoxCost.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
</data>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>8, 20</value>
</data>
<data name="&gt;&gt;textBoxName.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="&gt;&gt;textBox1.Name" xml:space="preserve">
<value>textBox1</value>
</data>
<data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>System.Windows.Forms.Form, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;Button2.Name" xml:space="preserve">
<value>Button2</value>
</data>
<data name="&gt;&gt;label2.Name" xml:space="preserve"> <data name="&gt;&gt;label2.Name" xml:space="preserve">
<value>label2</value> <value>label2</value>
</data> </data>
<data name="button1.TabIndex" type="System.Int32, mscorlib"> <data name="&gt;&gt;ButtonSave.Type" xml:space="preserve">
<value>4</value> <value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="textBox1.Location" type="System.Drawing.Point, System.Drawing">
<value>68, 6</value>
</data>
<data name="&gt;&gt;label2.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="&gt;&gt;Button1.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>FormComponent</value>
</data>
<data name="&gt;&gt;Button2.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="Button1.Location" type="System.Drawing.Point, System.Drawing">
<value>95, 85</value>
</data> </data>
<data name="textBoxName.Location" type="System.Drawing.Point, System.Drawing"> <data name="textBoxName.Location" type="System.Drawing.Point, System.Drawing">
<value>95, 6</value> <value>95, 6</value>
@ -296,10 +290,10 @@
<data name="&gt;&gt;textBox1.ZOrder" xml:space="preserve"> <data name="&gt;&gt;textBox1.ZOrder" xml:space="preserve">
<value>0</value> <value>0</value>
</data> </data>
<metadata name="$this.Language" type="System.Globalization.CultureInfo, System.Private.CoreLib, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"> <data name="&gt;&gt;ButtonCancel.Name" xml:space="preserve">
<value>ru</value> <value>ButtonCancel</value>
</metadata> </data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <data name="&gt;&gt;ButtonCancel.Type" xml:space="preserve">
<value>True</value> <value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</metadata> </data>
</root> </root>

View File

@ -147,19 +147,19 @@
<data name="label2.Text" xml:space="preserve"> <data name="label2.Text" xml:space="preserve">
<value>Цена</value> <value>Цена</value>
</data> </data>
<data name="buttonSave.Size" type="System.Drawing.Size, System.Drawing"> <data name="ButtonSave.Size" type="System.Drawing.Size, System.Drawing">
<value>121, 29</value> <value>121, 29</value>
</data> </data>
<data name="buttonSave.Text" xml:space="preserve"> <data name="ButtonSave.Text" xml:space="preserve">
<value>Сохранить</value> <value>Сохранить</value>
</data> </data>
<data name="buttonCancel.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms"> <data name="ButtonCancel.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value> <value>NoControl</value>
</data> </data>
<data name="buttonCancel.Size" type="System.Drawing.Size, System.Drawing"> <data name="ButtonCancel.Size" type="System.Drawing.Size, System.Drawing">
<value>119, 29</value> <value>119, 29</value>
</data> </data>
<data name="buttonCancel.Text" xml:space="preserve"> <data name="ButtonCancel.Text" xml:space="preserve">
<value>Отмена</value> <value>Отмена</value>
</data> </data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing"> <data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">

View File

@ -1,81 +0,0 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace SushiBar.Forms
{
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 FormComponent_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение компонента");
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, "Ошибка получения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение компонента");
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("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -29,10 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonAdd = new Button(); ButtonAdd = new Button();
buttonUpd = new Button(); ButtonUpd = new Button();
buttonDel = new Button(); ButtonDel = new Button();
buttonRef = new Button(); ButtonRef = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -48,58 +48,64 @@
dataGridView.Size = new Size(694, 408); dataGridView.Size = new Size(694, 408);
dataGridView.TabIndex = 0; dataGridView.TabIndex = 0;
// //
// buttonAdd // ButtonAdd
// //
buttonAdd.Location = new Point(700, 12); ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonAdd.Name = "buttonAdd"; ButtonAdd.Location = new Point(700, 12);
buttonAdd.Size = new Size(180, 29); ButtonAdd.Name = "ButtonAdd";
buttonAdd.TabIndex = 1; ButtonAdd.Size = new Size(180, 29);
buttonAdd.Text = "Добавить"; ButtonAdd.TabIndex = 1;
buttonAdd.UseVisualStyleBackColor = true; ButtonAdd.Text = "Добавить";
buttonAdd.Click += buttonAdd_Click; ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
// //
// buttonUpd // ButtonUpd
// //
buttonUpd.Location = new Point(700, 47); ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonUpd.Name = "buttonUpd"; ButtonUpd.Location = new Point(700, 47);
buttonUpd.Size = new Size(180, 29); ButtonUpd.Name = "ButtonUpd";
buttonUpd.TabIndex = 2; ButtonUpd.Size = new Size(180, 29);
buttonUpd.Text = "Изменить"; ButtonUpd.TabIndex = 2;
buttonUpd.UseVisualStyleBackColor = true; ButtonUpd.Text = "Изменить";
buttonUpd.Click += buttonUpd_Click; ButtonUpd.UseVisualStyleBackColor = true;
ButtonUpd.Click += ButtonUpd_Click;
// //
// buttonDel // ButtonDel
// //
buttonDel.Location = new Point(700, 82); ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonDel.Name = "buttonDel"; ButtonDel.Location = new Point(700, 82);
buttonDel.Size = new Size(180, 29); ButtonDel.Name = "ButtonDel";
buttonDel.TabIndex = 3; ButtonDel.Size = new Size(180, 29);
buttonDel.Text = "Удалить"; ButtonDel.TabIndex = 3;
buttonDel.UseVisualStyleBackColor = true; ButtonDel.Text = "Удалить";
buttonDel.Click += buttonDel_Click; ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
// //
// buttonRef // buttonRef
// //
buttonRef.Location = new Point(700, 117); ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Name = "buttonRef"; ButtonRef.Location = new Point(700, 117);
buttonRef.Size = new Size(180, 29); ButtonRef.Name = "ButtonRef";
buttonRef.TabIndex = 4; ButtonRef.Size = new Size(180, 29);
buttonRef.Text = "Обновить"; ButtonRef.TabIndex = 4;
buttonRef.UseVisualStyleBackColor = true; ButtonRef.Text = "Обновить";
buttonRef.Click += buttonRef_Click; ButtonRef.UseVisualStyleBackColor = true;
ButtonRef.Click += ButtonRef_Click;
// //
// FormComponents // FormComponents
// //
AllowDrop = true;
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(892, 408); ClientSize = new Size(892, 408);
Controls.Add(buttonRef); Controls.Add(ButtonRef);
Controls.Add(buttonDel); Controls.Add(ButtonDel);
Controls.Add(buttonUpd); Controls.Add(ButtonUpd);
Controls.Add(buttonAdd); Controls.Add(ButtonAdd);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Name = "FormComponents"; Name = "FormComponents";
Text = "Компоненты"; Text = "Компоненты";
WindowState = FormWindowState.Maximized;
Load += FormComponents_Load; Load += FormComponents_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
@ -108,9 +114,9 @@
#endregion #endregion
private DataGridView dataGridView; private DataGridView dataGridView;
private Button buttonAdd; private Button ButtonAdd;
private Button buttonUpd; private Button ButtonUpd;
private Button buttonDel; private Button ButtonDel;
private Button buttonRef; private Button ButtonRef;
} }
} }

View File

@ -1,35 +1,98 @@
using System; using SushiBarContracts.BindingModels;
using System.Collections.Generic; using SushiBarContracts.BusinessLogicsContracts;
using System.ComponentModel; using Microsoft.Extensions.Logging;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBar.Forms namespace SushiBar.Forms
{ {
public partial class FormComponents public partial class FormComponents : Form
{ {
private void buttonAdd_Click(object sender, EventArgs e) private readonly ILogger _logger;
private readonly IComponentLogic _logic;
public FormComponents(ILogger<FormComponents> logger, IComponentLogic logic)
{ {
ButtonAdd_Click(sender, e); InitializeComponent();
_logger = logger;
_logic = logic;
} }
private void FormComponents_Load(object sender, EventArgs e)
private void buttonUpd_Click(object sender, EventArgs e)
{ {
ButtonUpd_Click(sender, e); LoadData();
} }
private void LoadData()
private void buttonDel_Click(object sender, EventArgs e)
{ {
ButtonDel_Click(sender, e); 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("Загрузка компонентов");
private void buttonRef_Click(object sender, EventArgs e) }
catch (Exception ex)
{ {
ButtonRef_Click(sender, e); _logger.LogError(ex, "Ошибка загрузки компонентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента");
try
{
if (!_logic.Delete(new ComponentBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
} }
} }
} }

View File

@ -1,98 +0,0 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace SushiBar.Forms
{
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 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("Загрузка компонентов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонентов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента");
try
{
if (!_logic.Delete(new ComponentBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -28,35 +28,35 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
buttonSave = new Button(); ButtonSave = new Button();
buttonCancel = new Button(); ButtonCancel = new Button();
label1 = new Label(); label1 = new Label();
label2 = new Label(); label2 = new Label();
label3 = new Label(); label3 = new Label();
textBoxCount = new TextBox(); TextBoxCount = new TextBox();
textBoxSum = new TextBox(); TextBoxSum = new TextBox();
comboBoxSushi = new ComboBox(); ComboBoxSushi = new ComboBox();
SuspendLayout(); SuspendLayout();
// //
// buttonSave // ButtonSave
// //
buttonSave.Location = new Point(185, 112); ButtonSave.Location = new Point(185, 112);
buttonSave.Name = "buttonSave"; ButtonSave.Name = "ButtonSave";
buttonSave.Size = new Size(100, 30); ButtonSave.Size = new Size(100, 30);
buttonSave.TabIndex = 0; ButtonSave.TabIndex = 0;
buttonSave.Text = "Сохранить"; ButtonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; ButtonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click; ButtonSave.Click += ButtonSave_Click;
// //
// buttonCancel // ButtonCancel
// //
buttonCancel.Location = new Point(291, 112); ButtonCancel.Location = new Point(291, 112);
buttonCancel.Name = "buttonCancel"; ButtonCancel.Name = "ButtonCancel";
buttonCancel.Size = new Size(100, 30); ButtonCancel.Size = new Size(100, 30);
buttonCancel.TabIndex = 1; ButtonCancel.TabIndex = 1;
buttonCancel.Text = "Отмена"; ButtonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; ButtonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click; ButtonCancel.Click += ButtonCancel_Click;
// //
// label1 // label1
// //
@ -85,48 +85,50 @@
label3.TabIndex = 4; label3.TabIndex = 4;
label3.Text = "Сумма:"; label3.Text = "Сумма:";
// //
// textBoxCount // TextBoxCount
// //
textBoxCount.Location = new Point(119, 46); TextBoxCount.Location = new Point(119, 46);
textBoxCount.Name = "textBoxCount"; TextBoxCount.Name = "TextBoxCount";
textBoxCount.Size = new Size(272, 27); TextBoxCount.Size = new Size(272, 27);
textBoxCount.TabIndex = 5; TextBoxCount.TabIndex = 5;
textBoxCount.TextChanged += textBoxCount_TextChanged; TextBoxCount.TextChanged += TextBoxCount_TextChanged;
// //
// textBoxSum // TextBoxSum
// //
textBoxSum.Location = new Point(119, 79); TextBoxSum.Location = new Point(119, 79);
textBoxSum.Name = "textBoxSum"; TextBoxSum.Name = "TextBoxSum";
textBoxSum.ReadOnly = true; TextBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(272, 27); TextBoxSum.Size = new Size(272, 27);
textBoxSum.TabIndex = 6; TextBoxSum.TabIndex = 6;
// //
// comboBoxSushi // ComboBoxSushi
// //
comboBoxSushi.FormattingEnabled = true; ComboBoxSushi.FormattingEnabled = true;
comboBoxSushi.Location = new Point(119, 12); ComboBoxSushi.Location = new Point(119, 12);
comboBoxSushi.Name = "comboBoxSushi"; ComboBoxSushi.Name = "ComboBoxSushi";
comboBoxSushi.Size = new Size(272, 28); ComboBoxSushi.Size = new Size(272, 28);
comboBoxSushi.TabIndex = 7; ComboBoxSushi.TabIndex = 7;
comboBoxSushi.SelectedIndexChanged += comboBoxSushi_SelectedIndexChanged; ComboBoxSushi.SelectedIndexChanged += ComboBoxSushi_SelectedIndexChanged;
// //
// FormCreateOrder // FormCreateOrder
// //
AllowDrop = true;
AutoScaleMode = AutoScaleMode.None; AutoScaleMode = AutoScaleMode.None;
ClientSize = new Size(403, 152); ClientSize = new Size(403, 152);
Controls.Add(comboBoxSushi); Controls.Add(ComboBoxSushi);
Controls.Add(textBoxSum); Controls.Add(TextBoxSum);
Controls.Add(textBoxCount); Controls.Add(TextBoxCount);
Controls.Add(label3); Controls.Add(label3);
Controls.Add(label2); Controls.Add(label2);
Controls.Add(label1); Controls.Add(label1);
Controls.Add(buttonCancel); Controls.Add(ButtonCancel);
Controls.Add(buttonSave); Controls.Add(ButtonSave);
MaximizeBox = false; MaximizeBox = false;
MinimizeBox = false; MinimizeBox = false;
Name = "FormCreateOrder"; Name = "FormCreateOrder";
ShowInTaskbar = false; ShowInTaskbar = false;
Text = "Заказ"; Text = "Заказ";
TopMost = true;
Load += FormCreateOrder_Load; Load += FormCreateOrder_Load;
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
@ -134,13 +136,13 @@
#endregion #endregion
private Button buttonSave; private Button ButtonSave;
private Button buttonCancel; private Button ButtonCancel;
private Label label1; private Label label1;
private Label label2; private Label label2;
private Label label3; private Label label3;
private TextBox textBoxCount; private TextBox TextBoxCount;
private TextBox textBoxSum; private TextBox TextBoxSum;
private ComboBox comboBoxSushi; private ComboBox ComboBoxSushi;
} }
} }

View File

@ -1,35 +1,113 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic; using SushiBarContracts.BindingModels;
using System.ComponentModel; using SushiBarContracts.BusinessLogicsContracts;
using System.Data; using SushiBarContracts.SearchModels;
using System.Drawing; using SushiBarContracts.ViewModels;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBar.Forms namespace SushiBar.Forms
{ {
public partial class FormCreateOrder public partial class FormCreateOrder : Form
{ {
private void buttonSave_Click(object sender, EventArgs e) private readonly ILogger _logger;
private readonly ISushiLogic _logicS;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISushiLogic logicS, IOrderLogic logicO)
{ {
ButtonSave_Click(sender, e); InitializeComponent();
_logger = logger;
_logicS = logicS;
_logicO = logicO;
} }
private void FormCreateOrder_Load(object sender, EventArgs e)
private void buttonCancel_Click(object sender, EventArgs e)
{ {
ButtonCancel_Click(sender, e); try
{
_logger.LogInformation("Загрузка суши для заказа");
List<SushiViewModel>? _list = _logicS.ReadList(null);
if (_list != null)
{
ComboBoxSushi.DisplayMember = "SushiName";
ComboBoxSushi.ValueMember = "Id";
ComboBoxSushi.DataSource = _list;
ComboBoxSushi.SelectedItem = null;
} }
private void textBoxCount_TextChanged(object sender, EventArgs e)
{
TextBoxCount_TextChanged(sender, e);
} }
catch (Exception ex)
private void comboBoxSushi_SelectedIndexChanged(object sender, EventArgs e)
{ {
ComboBoxSushi_SelectedIndexChanged(sender, e); _logger.LogError(ex, "Ошибка загрузки суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (ComboBoxSushi.SelectedValue != null && !string.IsNullOrEmpty(TextBoxCount.Text))
{
try
{
int id = Convert.ToInt32(ComboBoxSushi.SelectedValue);
var sushi = _logicS.ReadElement(new SushiSearchModel
{
Id = id
});
int count = Convert.ToInt32(TextBoxCount.Text);
TextBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void TextBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ComboBoxSushi_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(TextBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (ComboBoxSushi.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
SushiId = Convert.ToInt32(ComboBoxSushi.SelectedValue),
Count = Convert.ToInt32(TextBoxCount.Text),
Sum = Convert.ToDouble(TextBoxSum.Text)
});
if (!operationResult)
{
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
} }
} }
} }

View File

@ -1,115 +0,0 @@
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using System.Windows.Forms;
namespace SushiBar.Forms
{
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly ISushiLogic _logicS;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ISushiLogic logicS, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicS = logicS;
_logicO = logicO;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
try
{
_logger.LogInformation("Загрузка суши для заказа");
List<SushiViewModel>? _list = _logicS.ReadList(null);
if (_list != null)
{
comboBoxSushi.DisplayMember = "SushiName";
comboBoxSushi.ValueMember = "Id";
comboBoxSushi.DataSource = _list;
comboBoxSushi.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (comboBoxSushi.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxSushi.SelectedValue);
var sushi = _logicS.ReadElement(new SushiSearchModel
{
Id = id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void TextBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ComboBoxSushi_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSushi.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание заказа");
try
{
var operationResult = _logicO.CreateOrder(new OrderBindingModel
{
SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text)
});
if (!operationResult)
{
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -30,10 +30,13 @@
{ {
dataGridView = new DataGridView(); dataGridView = new DataGridView();
menuStrip1 = new MenuStrip(); menuStrip1 = new MenuStrip();
ToolStripMenuItem = new ToolStripMenuItem(); toolStripMenuItem = new ToolStripMenuItem();
sushiToolStripMenuItem = new ToolStripMenuItem(); sushiToolStripMenuItem = new ToolStripMenuItem();
componentsToolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem();
clientsToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem1 = new ToolStripMenuItem();
sushisReportToolStripMenuItem = new ToolStripMenuItem();
componentsReportПоСушиToolStripMenuItem = new ToolStripMenuItem();
orderReportToolStripMenuItem = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem();
sushisToolStripMenuItem = new ToolStripMenuItem(); sushisToolStripMenuItem = new ToolStripMenuItem();
componentSushisToolStripMenuItem = new ToolStripMenuItem(); componentSushisToolStripMenuItem = new ToolStripMenuItem();
@ -49,46 +52,74 @@
// //
// dataGridView // dataGridView
// //
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 28); dataGridView.Location = new Point(0, 28);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29; dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(1303, 696); dataGridView.Size = new Size(992, 422);
dataGridView.TabIndex = 0; dataGridView.TabIndex = 0;
// //
// menuStrip1 // menuStrip1
// //
menuStrip1.ImageScalingSize = new Size(20, 20); menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenuItem, отчётыToolStripMenuItem }); menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, отчётыToolStripMenuItem1 });
menuStrip1.Location = new Point(0, 0); menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1"; menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(1501, 28); menuStrip1.Size = new Size(1501, 28);
menuStrip1.TabIndex = 1; menuStrip1.TabIndex = 1;
menuStrip1.Text = "menuStrip1"; menuStrip1.Text = "menuStrip1";
// //
// ToolStripMenuItem // toolStripMenuItem
// //
ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { sushiToolStripMenuItem, componentsToolStripMenuItem, clientsToolStripMenuItem }); toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { sushiToolStripMenuItem, componentsToolStripMenuItem });
ToolStripMenuItem.Name = "ToolStripMenuItem"; toolStripMenuItem.Name = "toolStripMenuItem";
ToolStripMenuItem.Size = new Size(117, 24); toolStripMenuItem.Size = new Size(117, 24);
ToolStripMenuItem.Text = "Справочники"; toolStripMenuItem.Text = "Справочники";
// //
// sushiToolStripMenuItem // sushiToolStripMenuItem
// //
sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
sushiToolStripMenuItem.Size = new Size(224, 26); sushiToolStripMenuItem.Size = new Size(224, 26);
sushiToolStripMenuItem.Text = "Суши"; sushiToolStripMenuItem.Text = "Суши";
sushiToolStripMenuItem.Click += sushiToolStripMenuItem_Click; sushiToolStripMenuItem.Click += SushiToolStripMenuItem_Click;
// //
// componentsToolStripMenuItem // componentsToolStripMenuItem
// //
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
componentsToolStripMenuItem.Size = new Size(224, 26); componentsToolStripMenuItem.Size = new Size(224, 26);
componentsToolStripMenuItem.Text = "Компоненты"; componentsToolStripMenuItem.Text = "Компоненты";
componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click; componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
//
// отчётыToolStripMenuItem1
//
отчётыToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { sushisReportToolStripMenuItem, componentsReportПоСушиToolStripMenuItem, orderReportToolStripMenuItem });
отчётыToolStripMenuItem1.Name = "отчётыToolStripMenuItem1";
отчётыToolStripMenuItem1.Size = new Size(73, 24);
отчётыToolStripMenuItem1.Text = "Отчёты";
//
// sushisReportToolStripMenuItem
//
sushisReportToolStripMenuItem.Name = "sushisReportToolStripMenuItem";
sushisReportToolStripMenuItem.Size = new Size(243, 26);
sushisReportToolStripMenuItem.Text = "Список суши";
sushisReportToolStripMenuItem.Click += sushisReportToolStripMenuItem_Click;
//
// componentsReportПоСушиToolStripMenuItem
//
componentsReportПоСушиToolStripMenuItem.Name = "componentsReportПоСушиToolStripMenuItem";
componentsReportПоСушиToolStripMenuItem.Size = new Size(243, 26);
componentsReportПоСушиToolStripMenuItem.Text = "Компоненты по суши";
componentsReportПоСушиToolStripMenuItem.Click += componentsReportПоСушиToolStripMenuItem_Click;
//
// orderReportToolStripMenuItem
//
orderReportToolStripMenuItem.Name = "orderReportToolStripMenuItem";
orderReportToolStripMenuItem.Size = new Size(243, 26);
orderReportToolStripMenuItem.Text = "Список заказов";
orderReportToolStripMenuItem.Click += orderReportToolStripMenuItem_Click;
// //
// clientsToolStripMenuItem // clientsToolStripMenuItem
// //
@ -99,89 +130,82 @@
// //
// отчётыToolStripMenuItem // отчётыToolStripMenuItem
// //
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { sushisToolStripMenuItem, componentSushisToolStripMenuItem, ordersToolStripMenuItem });
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
отчётыToolStripMenuItem.Size = new Size(73, 24); отчётыToolStripMenuItem.Size = new Size(32, 19);
отчётыToolStripMenuItem.Text = "Отчёты";
// //
// sushisToolStripMenuItem // sushisToolStripMenuItem
// //
sushisToolStripMenuItem.Name = "sushisToolStripMenuItem"; sushisToolStripMenuItem.Name = "sushisToolStripMenuItem";
sushisToolStripMenuItem.Size = new Size(276, 26); sushisToolStripMenuItem.Size = new Size(32, 19);
sushisToolStripMenuItem.Text = "Список суши";
sushisToolStripMenuItem.Click += sushisToolStripMenuItem_Click;
// //
// componentSushisToolStripMenuItem // componentSushisToolStripMenuItem
// //
componentSushisToolStripMenuItem.Name = "componentSushisToolStripMenuItem"; componentSushisToolStripMenuItem.Name = "componentSushisToolStripMenuItem";
componentSushisToolStripMenuItem.Size = new Size(276, 26); componentSushisToolStripMenuItem.Size = new Size(32, 19);
componentSushisToolStripMenuItem.Text = "Компоненты по изделиям";
componentSushisToolStripMenuItem.Click += componentSushisToolStripMenuItem_Click;
// //
// ordersToolStripMenuItem // ordersToolStripMenuItem
// //
ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; ordersToolStripMenuItem.Name = "ordersToolStripMenuItem";
ordersToolStripMenuItem.Size = new Size(276, 26); ordersToolStripMenuItem.Size = new Size(32, 19);
ordersToolStripMenuItem.Text = "Список заказов";
ordersToolStripMenuItem.Click += ordersToolStripMenuItem_Click;
// //
// buttonCreateOrder // buttonCreateOrder
// //
buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonCreateOrder.Location = new Point(1309, 57); buttonCreateOrder.Location = new Point(998, 31);
buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(180, 30); buttonCreateOrder.Size = new Size(180, 30);
buttonCreateOrder.TabIndex = 8; buttonCreateOrder.TabIndex = 8;
buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.Text = "Создать заказ";
buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.UseVisualStyleBackColor = true;
buttonCreateOrder.Click += buttonCreateOrder_Click; buttonCreateOrder.Click += ButtonCreateOrder_Click;
// //
// buttonTakeOrderInWork // buttonTakeOrderInWork
// //
buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonTakeOrderInWork.Location = new Point(1309, 93); buttonTakeOrderInWork.Location = new Point(998, 67);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(180, 30); buttonTakeOrderInWork.Size = new Size(180, 30);
buttonTakeOrderInWork.TabIndex = 9; buttonTakeOrderInWork.TabIndex = 9;
buttonTakeOrderInWork.Text = "Отдать на выполнение"; buttonTakeOrderInWork.Text = "Отдать на выполнение";
buttonTakeOrderInWork.UseVisualStyleBackColor = true; buttonTakeOrderInWork.UseVisualStyleBackColor = true;
buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
// //
// buttonOrderReady // buttonOrderReady
// //
buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonOrderReady.Location = new Point(1309, 129); buttonOrderReady.Location = new Point(998, 103);
buttonOrderReady.Name = "buttonOrderReady"; buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(180, 30); buttonOrderReady.Size = new Size(180, 30);
buttonOrderReady.TabIndex = 10; buttonOrderReady.TabIndex = 10;
buttonOrderReady.Text = "Заказ готов"; buttonOrderReady.Text = "Заказ готов";
buttonOrderReady.UseVisualStyleBackColor = true; buttonOrderReady.UseVisualStyleBackColor = true;
buttonOrderReady.Click += buttonOrderReady_Click; buttonOrderReady.Click += ButtonOrderReady_Click;
// //
// buttonIssuedOrder // buttonIssuedOrder
// //
buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonIssuedOrder.Location = new Point(1309, 165); buttonIssuedOrder.Location = new Point(998, 139);
buttonIssuedOrder.Name = "buttonIssuedOrder"; buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(180, 30); buttonIssuedOrder.Size = new Size(180, 30);
buttonIssuedOrder.TabIndex = 11; buttonIssuedOrder.TabIndex = 11;
buttonIssuedOrder.Text = "Заказ Выдан"; buttonIssuedOrder.Text = "Заказ Выдан";
buttonIssuedOrder.UseVisualStyleBackColor = true; buttonIssuedOrder.UseVisualStyleBackColor = true;
buttonIssuedOrder.Click += buttonIssuedOrder_Click; buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
// //
// buttonRef // buttonRef
// //
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Location = new Point(1309, 201); buttonRef.Location = new Point(998, 175);
buttonRef.Name = "buttonRef"; buttonRef.Name = "buttonRef";
buttonRef.Size = new Size(180, 30); buttonRef.Size = new Size(180, 30);
buttonRef.TabIndex = 12; buttonRef.TabIndex = 12;
buttonRef.Text = "Обновить список"; buttonRef.Text = "Обновить список";
buttonRef.UseVisualStyleBackColor = true; buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += buttonRef_Click; buttonRef.Click += ButtonRef_Click;
// //
// FormMain // FormMain
// //
AllowDrop = true;
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1501, 724); ClientSize = new Size(1501, 724);
@ -195,6 +219,7 @@
MainMenuStrip = menuStrip1; MainMenuStrip = menuStrip1;
Name = "FormMain"; Name = "FormMain";
Text = "Сушибар"; Text = "Сушибар";
WindowState = FormWindowState.Maximized;
Load += FormMain_Load; Load += FormMain_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
menuStrip1.ResumeLayout(false); menuStrip1.ResumeLayout(false);
@ -207,18 +232,21 @@
private DataGridView dataGridView; private DataGridView dataGridView;
private MenuStrip menuStrip1; private MenuStrip menuStrip1;
private ToolStripMenuItem ToolStripMenuItem; private Button buttonCreateOrder;
private Button buttonTakeOrderInWork;
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem toolStripMenuItem;
private ToolStripMenuItem sushiToolStripMenuItem; private ToolStripMenuItem sushiToolStripMenuItem;
private ToolStripMenuItem componentsToolStripMenuItem; private ToolStripMenuItem componentsToolStripMenuItem;
private ToolStripMenuItem отчётыToolStripMenuItem; private ToolStripMenuItem отчётыToolStripMenuItem;
private ToolStripMenuItem sushisToolStripMenuItem; private ToolStripMenuItem sushisToolStripMenuItem;
private ToolStripMenuItem componentSushisToolStripMenuItem; private ToolStripMenuItem componentSushisToolStripMenuItem;
private ToolStripMenuItem ordersToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem;
private Button buttonCreateOrder; private ToolStripMenuItem отчётыToolStripMenuItem1;
private Button buttonTakeOrderInWork; private ToolStripMenuItem sushisReportToolStripMenuItem;
private Button buttonOrderReady; private ToolStripMenuItem componentsReportПоСушиToolStripMenuItem;
private Button buttonIssuedOrder; private ToolStripMenuItem orderReportToolStripMenuItem;
private Button buttonRef;
private ToolStripMenuItem clientsToolStripMenuItem;
} }
} }

View File

@ -1,55 +1,171 @@
namespace SushiBar.Forms using Microsoft.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar.Forms
{ {
public partial class FormMain public partial class FormMain : Form
{ {
private void buttonCreateOrder_Click(object sender, EventArgs e) private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{ {
ButtonCreateOrder_Click(sender, e); InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["SushiId"].Visible = false;
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
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(FormSushis));
if (service is FormSushis form)
{
form.ShowDialog();
}
}
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 ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
} }
private void buttonTakeOrderInWork_Click(object sender, EventArgs e) private void sushisReportToolStripMenuItem_Click(object sender, EventArgs e)
{ {
ButtonTakeOrderInWork_Click(sender, e); using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveSushisToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} }
private void buttonOrderReady_Click(object sender, EventArgs e) private void componentsReportПоСушиToolStripMenuItem_Click(object sender, EventArgs e)
{ {
ButtonOrderReady_Click(sender, e); var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiComponents));
if (service is FormReportSushiComponents form)
{
form.ShowDialog();
}
} }
private void buttonIssuedOrder_Click(object sender, EventArgs e) private void orderReportToolStripMenuItem_Click(object sender, EventArgs e)
{ {
ButtonIssuedOrder_Click(sender, e); var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
if (service is FormReportOrders form)
{
form.ShowDialog();
} }
private void buttonRef_Click(object sender, EventArgs e)
{
ButtonRef_Click(sender, e);
}
private void sushiToolStripMenuItem_Click(object sender, EventArgs e)
{
SushiToolStripMenuItem_Click(sender, e);
}
private void componentsToolStripMenuItem_Click(object sender, EventArgs e)
{
ComponentsToolStripMenuItem_Click(sender, e);
}
private void componentSushisToolStripMenuItem_Click(object sender, EventArgs e)
{
ComponentSushisToolStripMenuItem_Click(sender, e);
}
private void ordersToolStripMenuItem_Click(object sender, EventArgs e)
{
OrdersToolStripMenuItem_Click(sender, e);
}
private void sushisToolStripMenuItem_Click(object sender, EventArgs e)
{
SushisToolStripMenuItem_Click(sender, e);
} }
private void clientsToolStripMenuItem_Click(object sender, EventArgs e) private void clientsToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -1,179 +0,0 @@
using Microsoft.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarDataModels.Enums;
using System.Windows.Forms;
namespace SushiBar.Forms
{
public partial class FormMain : Form
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_reportLogic = reportLogic;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["SushiId"].Visible = false;
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
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(FormSushis));
if (service is FormSushis form)
{
form.ShowDialog();
}
}
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 ButtonTakeOrderInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonOrderReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonIssuedOrder_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void SushisToolStripMenuItem_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog { Filter = "docx|*.docx" };
if (dialog.ShowDialog() == DialogResult.OK)
{
_reportLogic.SaveSushisToWordFile(new ReportBindingModel
{
FileName = dialog.FileName
});
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void ComponentSushisToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportSushiComponents));
if (service is FormReportSushiComponents form)
{
form.ShowDialog();
}
}
private void OrdersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders));
if (service is FormReportOrders form)
{
form.ShowDialog();
}
}
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
}
}

View File

@ -41,13 +41,13 @@
// //
// panel // panel
// //
panel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
panel.Controls.Add(label2); panel.Controls.Add(label2);
panel.Controls.Add(label1); panel.Controls.Add(label1);
panel.Controls.Add(dateTimePickerTo); panel.Controls.Add(dateTimePickerTo);
panel.Controls.Add(dateTimePickerFrom); panel.Controls.Add(dateTimePickerFrom);
panel.Controls.Add(buttonToPdf); panel.Controls.Add(buttonToPdf);
panel.Controls.Add(buttonMake); panel.Controls.Add(buttonMake);
panel.Dock = DockStyle.Top;
panel.Location = new Point(0, 0); panel.Location = new Point(0, 0);
panel.Name = "panel"; panel.Name = "panel";
panel.Size = new Size(1242, 51); panel.Size = new Size(1242, 51);
@ -107,9 +107,11 @@
// //
// panelBody // panelBody
// //
panelBody.Location = new Point(0, 57); panelBody.AllowDrop = true;
panelBody.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
panelBody.Location = new Point(12, 57);
panelBody.Name = "panelBody"; panelBody.Name = "panelBody";
panelBody.Size = new Size(1242, 515); panelBody.Size = new Size(1218, 506);
panelBody.TabIndex = 1; panelBody.TabIndex = 1;
// //
// FormReportOrders // FormReportOrders

View File

@ -1,25 +1,93 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic; using Microsoft.Reporting.WinForms;
using System.ComponentModel; using SushiBarContracts.BindingModels;
using System.Data; using SushiBarContracts.BusinessLogicsContracts;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBar.Forms namespace SushiBar.Forms
{ {
public partial class FormReportOrders 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/ReportOrders.rdlc", FileMode.Open));
panelBody.Controls.Add(reportViewer);
}
private void buttonMake_Click(object sender, EventArgs e) private void buttonMake_Click(object sender, EventArgs e)
{ {
ButtonMake_Click(sender, 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 buttonToPdf_Click(object sender, EventArgs e) private void buttonToPdf_Click(object sender, EventArgs e)
{ {
ButtonToPdf_Click(sender, 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
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
_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

@ -1,93 +0,0 @@
using Microsoft.Extensions.Logging;
using Microsoft.Reporting.WinForms;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar.Forms
{
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/ReportOrders.rdlc", FileMode.Open));
panelBody.Controls.Add(reportViewer);
}
private void ButtonMake_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 ButtonToPdf_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
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
_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

@ -48,6 +48,7 @@
// //
// dataGridView // dataGridView
// //
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dataGridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Component, Sushi, Count }); dataGridView.Columns.AddRange(new DataGridViewColumn[] { Component, Sushi, Count });
@ -83,6 +84,7 @@
// //
// FormReportSushiComponents // FormReportSushiComponents
// //
AllowDrop = true;
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(909, 457); ClientSize = new Size(909, 457);

View File

@ -1,10 +1,79 @@
namespace SushiBar.Forms using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using System.Windows.Forms;
namespace SushiBar.Forms
{ {
public partial class FormReportSushiComponents public partial class FormReportSushiComponents : Form
{ {
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportSushiComponents(ILogger<FormReportSushiComponents>
logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormReportSushiComponents_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetSushiComponent();
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[] {
"Итого", "", elem.TotalCount
});
dataGridView.Rows.Add(Array.Empty<object>());
}
}
_logger.LogInformation("Загрузка списка суши по компонентам");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка изделий по компонентам");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonSaveToExcel_Click(object sender, EventArgs e) private void buttonSaveToExcel_Click(object sender, EventArgs e)
{ {
ButtonSaveToExcel_Click(sender, e); using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveSushiComponentToExcelFile(new ReportBindingModel
{
FileName = dialog.FileName
});
_logger.LogInformation("Сохранение списка изделий по компонентам");
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
} }
} }

View File

@ -126,13 +126,4 @@
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="Component.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> </root>

View File

@ -1,79 +0,0 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using System.Windows.Forms;
namespace SushiBar.Forms
{
public partial class FormReportSushiComponents : Form
{
private readonly ILogger _logger;
private readonly IReportLogic _logic;
public FormReportSushiComponents(ILogger<FormReportSushiComponents>
logger, IReportLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormReportSushiComponents_Load(object sender, EventArgs e)
{
try
{
var dict = _logic.GetSushiComponent();
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[] {
"Итого", "", elem.TotalCount
});
dataGridView.Rows.Add(Array.Empty<object>());
}
}
_logger.LogInformation("Загрузка списка суши по компонентам");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка изделий по компонентам");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSaveToExcel_Click(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
_logic.SaveSushiComponentToExcelFile(new ReportBindingModel
{
FileName = dialog.FileName
});
_logger.LogInformation("Сохранение списка изделий по компонентам");
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View File

@ -28,17 +28,17 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
buttonAdd = new Button(); ButtonAdd = new Button();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
ID = new DataGridViewTextBoxColumn(); ID = new DataGridViewTextBoxColumn();
ComponentName = new DataGridViewTextBoxColumn(); ComponentName = new DataGridViewTextBoxColumn();
ComponentCount = new DataGridViewTextBoxColumn(); ComponentCount = new DataGridViewTextBoxColumn();
groupBox1 = new GroupBox(); groupBox1 = new GroupBox();
buttonRef = new Button(); ButtonRef = new Button();
buttonDel = new Button(); ButtonDel = new Button();
buttonUpd = new Button(); ButtonUpd = new Button();
buttonSave = new Button(); ButtonSave = new Button();
buttonCancel = new Button(); ButtonCancel = new Button();
label1 = new Label(); label1 = new Label();
label2 = new Label(); label2 = new Label();
textBoxPrice = new TextBox(); textBoxPrice = new TextBox();
@ -47,16 +47,17 @@
groupBox1.SuspendLayout(); groupBox1.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// buttonAdd // ButtonAdd
// //
buttonAdd.Location = new Point(640, 29); ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonAdd.Margin = new Padding(3, 4, 3, 4); ButtonAdd.Location = new Point(614, 28);
buttonAdd.Name = "buttonAdd"; ButtonAdd.Margin = new Padding(3, 4, 3, 4);
buttonAdd.Size = new Size(126, 39); ButtonAdd.Name = "ButtonAdd";
buttonAdd.TabIndex = 0; ButtonAdd.Size = new Size(151, 39);
buttonAdd.Text = "Добавить"; ButtonAdd.TabIndex = 0;
buttonAdd.UseVisualStyleBackColor = true; ButtonAdd.Text = "Добавить";
buttonAdd.Click += buttonAdd_Click; ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
// //
// dataGridView // dataGridView
// //
@ -72,7 +73,7 @@
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 25; dataGridView.RowTemplate.Height = 25;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(630, 263); dataGridView.Size = new Size(605, 243);
dataGridView.TabIndex = 1; dataGridView.TabIndex = 1;
// //
// ID // ID
@ -102,76 +103,80 @@
// //
// groupBox1 // groupBox1
// //
groupBox1.Controls.Add(buttonRef); groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBox1.Controls.Add(buttonDel); groupBox1.Controls.Add(ButtonRef);
groupBox1.Controls.Add(buttonUpd); groupBox1.Controls.Add(ButtonDel);
groupBox1.Controls.Add(ButtonUpd);
groupBox1.Controls.Add(dataGridView); groupBox1.Controls.Add(dataGridView);
groupBox1.Controls.Add(buttonAdd); groupBox1.Controls.Add(ButtonAdd);
groupBox1.Location = new Point(14, 101); groupBox1.Location = new Point(14, 101);
groupBox1.Margin = new Padding(3, 4, 3, 4); groupBox1.Margin = new Padding(3, 4, 3, 4);
groupBox1.Name = "groupBox1"; groupBox1.Name = "groupBox1";
groupBox1.Padding = new Padding(3, 4, 3, 4); groupBox1.Padding = new Padding(3, 4, 3, 4);
groupBox1.Size = new Size(773, 295); groupBox1.Size = new Size(774, 295);
groupBox1.TabIndex = 2; groupBox1.TabIndex = 2;
groupBox1.TabStop = false; groupBox1.TabStop = false;
groupBox1.Text = "Компоненты"; groupBox1.Text = "Компоненты";
// //
// buttonRef // buttonRef
// //
buttonRef.Location = new Point(640, 169); ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Margin = new Padding(3, 4, 3, 4); ButtonRef.Location = new Point(614, 168);
buttonRef.Name = "buttonRef"; ButtonRef.Margin = new Padding(3, 4, 3, 4);
buttonRef.Size = new Size(126, 39); ButtonRef.Name = "ButtonRef";
buttonRef.TabIndex = 4; ButtonRef.Size = new Size(151, 39);
buttonRef.Text = "Обновить"; ButtonRef.TabIndex = 4;
buttonRef.UseVisualStyleBackColor = true; ButtonRef.Text = "Обновить";
buttonRef.Click += buttonRef_Click; ButtonRef.UseVisualStyleBackColor = true;
ButtonRef.Click += ButtonRef_Click;
// //
// buttonDel // ButtonDel
// //
buttonDel.Location = new Point(640, 123); ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonDel.Margin = new Padding(3, 4, 3, 4); ButtonDel.Location = new Point(614, 122);
buttonDel.Name = "buttonDel"; ButtonDel.Margin = new Padding(3, 4, 3, 4);
buttonDel.Size = new Size(126, 39); ButtonDel.Name = "ButtonDel";
buttonDel.TabIndex = 3; ButtonDel.Size = new Size(151, 39);
buttonDel.Text = "Удалить"; ButtonDel.TabIndex = 3;
buttonDel.UseVisualStyleBackColor = true; ButtonDel.Text = "Удалить";
buttonDel.Click += buttonDel_Click; ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
// //
// buttonUpd // ButtonUpd
// //
buttonUpd.Location = new Point(640, 76); ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonUpd.Margin = new Padding(3, 4, 3, 4); ButtonUpd.Location = new Point(614, 75);
buttonUpd.Name = "buttonUpd"; ButtonUpd.Margin = new Padding(3, 4, 3, 4);
buttonUpd.Size = new Size(126, 39); ButtonUpd.Name = "ButtonUpd";
buttonUpd.TabIndex = 2; ButtonUpd.Size = new Size(151, 39);
buttonUpd.Text = "Изменить"; ButtonUpd.TabIndex = 2;
buttonUpd.UseVisualStyleBackColor = true; ButtonUpd.Text = "Изменить";
buttonUpd.Click += buttonUpd_Click; ButtonUpd.UseVisualStyleBackColor = true;
ButtonUpd.Click += ButtonUpd_Click;
// //
// buttonSave // ButtonSave
// //
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(573, 404); ButtonSave.Location = new Point(573, 404);
buttonSave.Margin = new Padding(3, 4, 3, 4); ButtonSave.Margin = new Padding(3, 4, 3, 4);
buttonSave.Name = "buttonSave"; ButtonSave.Name = "ButtonSave";
buttonSave.Size = new Size(100, 31); ButtonSave.Size = new Size(100, 31);
buttonSave.TabIndex = 3; ButtonSave.TabIndex = 3;
buttonSave.Text = "Сохранить"; ButtonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; ButtonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click; ButtonSave.Click += ButtonSave_Click;
// //
// buttonCancel // ButtonCancel
// //
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(679, 404); ButtonCancel.Location = new Point(679, 404);
buttonCancel.Margin = new Padding(3, 4, 3, 4); ButtonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Name = "buttonCancel"; ButtonCancel.Name = "ButtonCancel";
buttonCancel.Size = new Size(100, 31); ButtonCancel.Size = new Size(100, 31);
buttonCancel.TabIndex = 4; ButtonCancel.TabIndex = 4;
buttonCancel.Text = "Отмена"; ButtonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; ButtonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click; ButtonCancel.Click += ButtonCancel_Click;
// //
// label1 // label1
// //
@ -209,6 +214,7 @@
// //
// FormSushi // FormSushi
// //
AllowDrop = true;
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 451); ClientSize = new Size(800, 451);
@ -216,15 +222,11 @@
Controls.Add(textBoxPrice); Controls.Add(textBoxPrice);
Controls.Add(label2); Controls.Add(label2);
Controls.Add(label1); Controls.Add(label1);
Controls.Add(buttonCancel); Controls.Add(ButtonCancel);
Controls.Add(buttonSave); Controls.Add(ButtonSave);
Controls.Add(groupBox1); Controls.Add(groupBox1);
MaximizeBox = false;
MinimizeBox = false;
Name = "FormSushi"; Name = "FormSushi";
ShowInTaskbar = false;
Text = "Суши"; Text = "Суши";
TopMost = true;
Load += FormSushi_Load; Load += FormSushi_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
groupBox1.ResumeLayout(false); groupBox1.ResumeLayout(false);
@ -234,14 +236,14 @@
#endregion #endregion
private Button buttonAdd; private Button ButtonAdd;
private DataGridView dataGridView; private DataGridView dataGridView;
private GroupBox groupBox1; private GroupBox groupBox1;
private Button buttonRef; private Button ButtonRef;
private Button buttonDel; private Button ButtonDel;
private Button buttonUpd; private Button ButtonUpd;
private Button buttonSave; private Button ButtonSave;
private Button buttonCancel; private Button ButtonCancel;
private Label label1; private Label label1;
private Label label2; private Label label2;
private TextBox textBoxPrice; private TextBox textBoxPrice;

View File

@ -1,35 +1,199 @@
namespace SushiBar.Forms using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarDataModels.Models;
namespace SushiBar.Forms
{ {
public partial class FormSushi public partial class FormSushi : Form
{ {
private void buttonAdd_Click(object sender, EventArgs e) 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)
{ {
ButtonAdd_Click(sender, e); InitializeComponent();
_logger = logger;
_logic = logic;
_sushiComponents = new Dictionary<int, (IComponentModel, int)>();
}
private void FormSushi_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка изделия");
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, "Ошибка загрузки изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка компонент изделия");
try
{
if (_sushiComponents != null)
{
dataGridView.Rows.Clear();
foreach (var sc in _sushiComponents)
{
dataGridView.Rows.Add(new object[] { sc.Key, sc.Value.Item1.ComponentName, sc.Value.Item2 });
}
textBoxPrice.Text = CalcPrice().ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
if (service is FormSushiComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Добавление нового компонента: { 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 ButtonUpd_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("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_sushiComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Удаление компонента: { 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, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxPrice.Text))
{
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_sushiComponents == null || _sushiComponents.Count == 0)
{
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение изделия");
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("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void buttonUpd_Click(object sender, EventArgs e) private void ButtonCancel_Click(object sender, EventArgs e)
{ {
ButtonUpd_Click(sender, e); DialogResult = DialogResult.Cancel;
Close();
} }
private double CalcPrice()
private void buttonDel_Click(object sender, EventArgs e)
{ {
ButtonDel_Click(sender, e); 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 buttonRef_Click(object sender, EventArgs e)
{
ButtonRef_Click(sender, e);
}
private void buttonSave_Click(object sender, EventArgs e)
{
ButtonSave_Click(sender, e);
}
private void buttonCancel_Click(object sender, EventArgs e)
{
ButtonCancel_Click(sender, e);
} }
} }
} }

View File

@ -126,13 +126,4 @@
<metadata name="ComponentCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="ComponentCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ComponentName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ComponentCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>

View File

@ -32,8 +32,8 @@
label2 = new Label(); label2 = new Label();
comboBoxComponent = new ComboBox(); comboBoxComponent = new ComboBox();
textBoxCount = new TextBox(); textBoxCount = new TextBox();
buttonSave = new Button(); ButtonSave = new Button();
buttonCancel = new Button(); ButtonCancel = new Button();
SuspendLayout(); SuspendLayout();
// //
// label1 // label1
@ -69,33 +69,34 @@
textBoxCount.Size = new Size(227, 27); textBoxCount.Size = new Size(227, 27);
textBoxCount.TabIndex = 3; textBoxCount.TabIndex = 3;
// //
// buttonSave // ButtonSave
// //
buttonSave.Location = new Point(158, 95); ButtonSave.Location = new Point(158, 95);
buttonSave.Name = "buttonSave"; ButtonSave.Name = "ButtonSave";
buttonSave.Size = new Size(94, 29); ButtonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 4; ButtonSave.TabIndex = 4;
buttonSave.Text = "Сохранить"; ButtonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; ButtonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click; ButtonSave.Click += ButtonSave_Click;
// //
// buttonCancel // ButtonCancel
// //
buttonCancel.Location = new Point(258, 95); ButtonCancel.Location = new Point(258, 95);
buttonCancel.Name = "buttonCancel"; ButtonCancel.Name = "ButtonCancel";
buttonCancel.Size = new Size(94, 29); ButtonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 5; ButtonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена"; ButtonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; ButtonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click; ButtonCancel.Click += ButtonCancel_Click;
// //
// FormSushiComponent // FormSushiComponent
// //
AllowDrop = true;
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(364, 132); ClientSize = new Size(364, 132);
Controls.Add(buttonCancel); Controls.Add(ButtonCancel);
Controls.Add(buttonSave); Controls.Add(ButtonSave);
Controls.Add(textBoxCount); Controls.Add(textBoxCount);
Controls.Add(comboBoxComponent); Controls.Add(comboBoxComponent);
Controls.Add(label2); Controls.Add(label2);
@ -116,7 +117,7 @@
private Label label2; private Label label2;
private ComboBox comboBoxComponent; private ComboBox comboBoxComponent;
private TextBox textBoxCount; private TextBox textBoxCount;
private Button buttonSave; private Button ButtonSave;
private Button buttonCancel; private Button ButtonCancel;
} }
} }

View File

@ -1,25 +1,78 @@
using System; using SushiBarContracts.BusinessLogicsContracts;
using System.Collections.Generic; using SushiBarContracts.ViewModels;
using System.ComponentModel; using SushiBarDataModels.Models;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBar.Forms namespace SushiBar.Forms
{ {
public partial class FormSushiComponent partial class FormSushiComponent : Form
{ {
private void buttonSave_Click(object sender, EventArgs e) private readonly List<ComponentViewModel>? _list;
public int Id
{ {
ButtonSave_Click(sender, e); get
{
return Convert.ToInt32(comboBoxComponent.SelectedValue);
} }
set
private void buttonCancel_Click(object sender, EventArgs e)
{ {
ButtonCancel_Click(sender, e); 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("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxComponent.SelectedValue == null)
{
MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
} }
} }
} }

View File

@ -1,78 +0,0 @@
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBar.Forms
{
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("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxComponent.SelectedValue == null)
{
MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -1,199 +0,0 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarDataModels.Models;
namespace SushiBar.Forms
{
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 FormSushi_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка изделия");
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, "Ошибка загрузки изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка компонент изделия");
try
{
if (_sushiComponents != null)
{
dataGridView.Rows.Clear();
foreach (var sc in _sushiComponents)
{
dataGridView.Rows.Add(new object[] { sc.Key, sc.Value.Item1.ComponentName, sc.Value.Item2 });
}
textBoxPrice.Text = CalcPrice().ToString();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонент изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushiComponent));
if (service is FormSushiComponent form)
{
if (form.ShowDialog() == DialogResult.OK)
{
if (form.ComponentModel == null)
{
return;
}
_logger.LogInformation("Добавление нового компонента: { 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 ButtonUpd_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("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
_sushiComponents[form.Id] = (form.ComponentModel, form.Count);
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Удаление компонента: { 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, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxPrice.Text))
{
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_sushiComponents == null || _sushiComponents.Count == 0)
{
MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение изделия");
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("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
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);
}
}
}

View File

@ -29,10 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
dataGridView = new DataGridView(); dataGridView = new DataGridView();
buttonRef = new Button(); ButtonRef = new Button();
buttonDel = new Button(); ButtonDel = new Button();
buttonUpd = new Button(); ButtonUpd = new Button();
buttonAdd = new Button(); ButtonAdd = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -46,61 +46,67 @@
dataGridView.RowHeadersWidth = 70; dataGridView.RowHeadersWidth = 70;
dataGridView.RowTemplate.Height = 29; dataGridView.RowTemplate.Height = 29;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(762, 450); dataGridView.Size = new Size(777, 450);
dataGridView.TabIndex = 1; dataGridView.TabIndex = 1;
// //
// buttonRef // ButtonRef
// //
buttonRef.Location = new Point(768, 117); ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonRef.Name = "buttonRef"; ButtonRef.Location = new Point(783, 117);
buttonRef.Size = new Size(114, 29); ButtonRef.Name = "ButtonRef";
buttonRef.TabIndex = 8; ButtonRef.Size = new Size(150, 29);
buttonRef.Text = "Обновить"; ButtonRef.TabIndex = 8;
buttonRef.UseVisualStyleBackColor = true; ButtonRef.Text = "Обновить";
buttonRef.Click += buttonRef_Click; ButtonRef.UseVisualStyleBackColor = true;
ButtonRef.Click += ButtonRef_Click;
// //
// buttonDel // ButtonDel
// //
buttonDel.Location = new Point(768, 82); ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonDel.Name = "buttonDel"; ButtonDel.Location = new Point(783, 82);
buttonDel.Size = new Size(114, 29); ButtonDel.Name = "ButtonDel";
buttonDel.TabIndex = 7; ButtonDel.Size = new Size(150, 29);
buttonDel.Text = "Удалить"; ButtonDel.TabIndex = 7;
buttonDel.UseVisualStyleBackColor = true; ButtonDel.Text = "Удалить";
buttonDel.Click += buttonDel_Click; ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
// //
// buttonUpd // ButtonUpd
// //
buttonUpd.Location = new Point(768, 47); ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonUpd.Name = "buttonUpd"; ButtonUpd.Location = new Point(783, 47);
buttonUpd.Size = new Size(114, 29); ButtonUpd.Name = "ButtonUpd";
buttonUpd.TabIndex = 6; ButtonUpd.Size = new Size(150, 29);
buttonUpd.Text = "Изменить"; ButtonUpd.TabIndex = 6;
buttonUpd.UseVisualStyleBackColor = true; ButtonUpd.Text = "Изменить";
buttonUpd.Click += buttonUpd_Click; ButtonUpd.UseVisualStyleBackColor = true;
ButtonUpd.Click += ButtonUpd_Click;
// //
// buttonAdd // ButtonAdd
// //
buttonAdd.Location = new Point(768, 12); ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonAdd.Name = "buttonAdd"; ButtonAdd.Location = new Point(783, 12);
buttonAdd.Size = new Size(114, 29); ButtonAdd.Name = "ButtonAdd";
buttonAdd.TabIndex = 5; ButtonAdd.Size = new Size(150, 29);
buttonAdd.Text = "Добавить"; ButtonAdd.TabIndex = 5;
buttonAdd.UseVisualStyleBackColor = true; ButtonAdd.Text = "Добавить";
buttonAdd.Click += buttonAdd_Click; ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
// //
// FormSushis // FormSushis
// //
AllowDrop = true;
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(893, 450); ClientSize = new Size(945, 450);
Controls.Add(buttonRef); Controls.Add(ButtonRef);
Controls.Add(buttonDel); Controls.Add(ButtonDel);
Controls.Add(buttonUpd); Controls.Add(ButtonUpd);
Controls.Add(buttonAdd); Controls.Add(ButtonAdd);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Name = "FormSushis"; Name = "FormSushis";
Text = "Суши"; Text = "Суши";
WindowState = FormWindowState.Maximized;
Load += FormSushis_Load; Load += FormSushis_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
@ -109,9 +115,9 @@
#endregion #endregion
private DataGridView dataGridView; private DataGridView dataGridView;
private Button buttonRef; private Button ButtonRef;
private Button buttonDel; private Button ButtonDel;
private Button buttonUpd; private Button ButtonUpd;
private Button buttonAdd; private Button ButtonAdd;
} }
} }

View File

@ -1,35 +1,99 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic; using SushiBarContracts.BindingModels;
using System.ComponentModel; using SushiBarContracts.BusinessLogicsContracts;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SushiBar.Forms namespace SushiBar.Forms
{ {
public partial class FormSushis public partial class FormSushis : Form
{ {
private void buttonAdd_Click(object sender, EventArgs e) private readonly ILogger _logger;
private readonly ISushiLogic _logic;
public FormSushis(ILogger<FormSushis> logger, ISushiLogic logic)
{ {
ButtonAdd_Click(sender, e); InitializeComponent();
_logger = logger;
_logic = logic;
} }
private void FormSushis_Load(object sender, EventArgs e)
private void buttonUpd_Click(object sender, EventArgs e)
{ {
ButtonUpd_Click(sender, e); LoadData();
} }
private void LoadData()
private void buttonDel_Click(object sender, EventArgs e)
{ {
ButtonDel_Click(sender, e); try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SushiComponents"].Visible = false;
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка суши");
private void buttonRef_Click(object sender, EventArgs e) }
catch (Exception ex)
{ {
ButtonRef_Click(sender, e); _logger.LogError(ex, "Ошибка загрузки суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
if (service is FormSushi form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
if (service is FormSushi form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента");
try
{
if (!_logic.Delete(new SushiBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
} }
} }
} }

View File

@ -1,99 +0,0 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
namespace SushiBar.Forms
{
public partial class FormSushis : Form
{
private readonly ILogger _logger;
private readonly ISushiLogic _logic;
public FormSushis(ILogger<FormSushis> logger, ISushiLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormSushis_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["SushiComponents"].Visible = false;
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка суши");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
if (service is FormSushi form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSushi));
if (service is FormSushi form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление компонента");
try
{
if (!_logic.Delete(new SushiBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}