Compare commits
10 Commits
2a48f8feaa
...
5018b8f100
Author | SHA1 | Date | |
---|---|---|---|
|
5018b8f100 | ||
|
99848f8c3a | ||
|
d6125832ab | ||
|
9b1c9186f5 | ||
|
da472583a8 | ||
|
79fcf1755d | ||
|
95c13d3b6e | ||
|
49791fd7ff | ||
|
e09c8d19c2 | ||
|
9e34022abf |
2
.gitignore
vendored
2
.gitignore
vendored
@ -397,5 +397,3 @@ FodyWeavers.xsd
|
||||
|
||||
# JetBrains Rider
|
||||
*.sln.iml
|
||||
|
||||
*.csproj
|
||||
|
72
SushiBar/SushiBar/Forms/FormComponent.Designer.cs
generated
72
SushiBar/SushiBar/Forms/FormComponent.Designer.cs
generated
@ -28,61 +28,85 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormComponent));
|
||||
label1 = new Label();
|
||||
textBoxName = new TextBox();
|
||||
textBoxCost = new TextBox();
|
||||
label2 = new Label();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
ButtonSave = new Button();
|
||||
ButtonCancel = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
//
|
||||
resources.ApplyResources(label1, "label1");
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(12, 9);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(77, 20);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Название";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
resources.ApplyResources(textBoxName, "textBoxName");
|
||||
textBoxName.Location = new Point(95, 6);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(246, 27);
|
||||
textBoxName.TabIndex = 1;
|
||||
//
|
||||
// textBoxCost
|
||||
//
|
||||
resources.ApplyResources(textBoxCost, "textBoxCost");
|
||||
textBoxCost.Location = new Point(95, 39);
|
||||
textBoxCost.Name = "textBoxCost";
|
||||
textBoxCost.Size = new Size(246, 27);
|
||||
textBoxCost.TabIndex = 3;
|
||||
//
|
||||
// label2
|
||||
//
|
||||
resources.ApplyResources(label2, "label2");
|
||||
label2.AutoSize = true;
|
||||
label2.ImeMode = ImeMode.NoControl;
|
||||
label2.Location = new Point(12, 42);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(45, 20);
|
||||
label2.TabIndex = 2;
|
||||
label2.Text = "Цена";
|
||||
//
|
||||
// buttonSave
|
||||
// ButtonSave
|
||||
//
|
||||
resources.ApplyResources(buttonSave, "buttonSave");
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
ButtonSave.Location = new Point(95, 85);
|
||||
ButtonSave.Name = "ButtonSave";
|
||||
ButtonSave.Size = new Size(121, 29);
|
||||
ButtonSave.TabIndex = 4;
|
||||
ButtonSave.Text = "Сохранить";
|
||||
ButtonSave.UseVisualStyleBackColor = true;
|
||||
ButtonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
// ButtonCancel
|
||||
//
|
||||
resources.ApplyResources(buttonCancel, "buttonCancel");
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
ButtonCancel.ImeMode = ImeMode.NoControl;
|
||||
ButtonCancel.Location = new Point(222, 85);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(119, 29);
|
||||
ButtonCancel.TabIndex = 5;
|
||||
ButtonCancel.Text = "Отмена";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
ButtonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// FormComponent
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
AllowDrop = true;
|
||||
AutoScaleMode = AutoScaleMode.None;
|
||||
ClientSize = new Size(353, 126);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(ButtonSave);
|
||||
Controls.Add(textBoxCost);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(label1);
|
||||
MaximizeBox = false;
|
||||
Name = "FormComponent";
|
||||
Load += this.FormComponent_Load;
|
||||
ShowInTaskbar = false;
|
||||
Text = "Компонент";
|
||||
TopMost = true;
|
||||
Load += FormComponent_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -93,7 +117,7 @@
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxCost;
|
||||
private Label label2;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Button ButtonSave;
|
||||
private Button ButtonCancel;
|
||||
}
|
||||
}
|
@ -1,17 +1,81 @@
|
||||
using System;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
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 buttonCancel_Click(object sender, EventArgs e)
|
||||
private void FormComponent_Load(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,189 +117,183 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="textBox1.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>68, 6</value>
|
||||
</data>
|
||||
<data name=">>textBoxName.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>buttonCancel.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name=">>textBoxCost.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<data name=">>label2.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="textBox1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>textBox1.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name="label1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name=">>buttonSave.Name" xml:space="preserve">
|
||||
<value>buttonSave</value>
|
||||
</data>
|
||||
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>12, 9</value>
|
||||
</data>
|
||||
<data name=">>textBoxName.ZOrder" xml:space="preserve">
|
||||
<data name="Button1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>4</value>
|
||||
</data>
|
||||
<data name=">>button2.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<data name=">>ButtonSave.Name" xml:space="preserve">
|
||||
<value>ButtonSave</value>
|
||||
</data>
|
||||
<data name=">>textBoxCost.Parent" xml:space="preserve">
|
||||
<data name=">>Button2.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name="$this.Text" xml:space="preserve">
|
||||
<value>FormComponent</value>
|
||||
</data>
|
||||
<data name="textBoxName.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
|
||||
<value>800, 450</value>
|
||||
</data>
|
||||
<data name=">>textBoxCost.ZOrder" xml:space="preserve">
|
||||
<value>2</value>
|
||||
</data>
|
||||
<data name=">>button2.Name" xml:space="preserve">
|
||||
<value>button2</value>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>12, 9</value>
|
||||
</data>
|
||||
<data name=">>label2.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>button1.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 name=">>label1.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name="textBoxCost.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>3</value>
|
||||
</data>
|
||||
<data name="textBoxCost.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>95, 39</value>
|
||||
</data>
|
||||
<data name="textBoxName.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>95, 6</value>
|
||||
</data>
|
||||
<data name=">>button1.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name="buttonSave.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>95, 85</value>
|
||||
</data>
|
||||
<data name=">>$this.Name" xml:space="preserve">
|
||||
<value>FormComponent</value>
|
||||
</data>
|
||||
<data name=">>textBox1.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="button2.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>222, 85</value>
|
||||
</data>
|
||||
<data name=">>$this.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Form, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>label1.ZOrder" xml:space="preserve">
|
||||
<data name="ButtonCancel.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name=">>buttonSave.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>buttonSave.Parent" xml:space="preserve">
|
||||
<data name=">>textBox1.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>button2.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name="buttonCancel.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name=">>button1.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>buttonCancel.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>label1.Name" xml:space="preserve">
|
||||
<value>label1</value>
|
||||
</data>
|
||||
<data name=">>buttonSave.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>label1.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>label2.Name" xml:space="preserve">
|
||||
<value>label2</value>
|
||||
</data>
|
||||
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
|
||||
<value>8, 20</value>
|
||||
</data>
|
||||
<data name=">>textBox1.Name" xml:space="preserve">
|
||||
<value>textBox1</value>
|
||||
</data>
|
||||
<data name="label2.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>2</value>
|
||||
</data>
|
||||
<data name="button2.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>5</value>
|
||||
<data name=">>textBoxCost.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>textBoxCost.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="textBox1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>textBoxName.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>button1.Name" xml:space="preserve">
|
||||
<value>button1</value>
|
||||
</data>
|
||||
<data name=">>buttonCancel.Name" xml:space="preserve">
|
||||
<value>buttonCancel</value>
|
||||
</data>
|
||||
<data name=">>textBoxName.Name" xml:space="preserve">
|
||||
<value>textBoxName</value>
|
||||
</data>
|
||||
<data name=">>buttonCancel.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="buttonCancel.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<data name="Button2.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>222, 85</value>
|
||||
</data>
|
||||
<data name=">>textBoxCost.Name" xml:space="preserve">
|
||||
<value>textBoxCost</value>
|
||||
</data>
|
||||
<data name=">>label2.ZOrder" xml:space="preserve">
|
||||
<value>3</value>
|
||||
<data name=">>label1.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="buttonSave.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>4</value>
|
||||
<data name=">>Button1.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>label2.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name="Button2.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name=">>ButtonSave.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>textBox1.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>button2.ZOrder" xml:space="preserve">
|
||||
<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=">>label1.ZOrder" xml:space="preserve">
|
||||
<value>5</value>
|
||||
</data>
|
||||
<data name="textBoxName.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>ButtonCancel.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="button1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>4</value>
|
||||
<data name="$this.Text" xml:space="preserve">
|
||||
<value>FormComponent</value>
|
||||
</data>
|
||||
<data name=">>label2.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<data name=">>Button2.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>12, 42</value>
|
||||
</data>
|
||||
<metadata name="$this.Language" type="System.Globalization.CultureInfo, System.Private.CoreLib, Culture=neutral, PublicKeyToken=7cec85d7bea7798e">
|
||||
<value>ru</value>
|
||||
</metadata>
|
||||
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<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=">>Button1.Name" xml:space="preserve">
|
||||
<value>Button1</value>
|
||||
</data>
|
||||
<data name="label1.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name=">>label1.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>ButtonSave.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>ButtonCancel.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>label1.Name" xml:space="preserve">
|
||||
<value>label1</value>
|
||||
</data>
|
||||
<data name=">>textBoxName.Name" xml:space="preserve">
|
||||
<value>textBoxName</value>
|
||||
</data>
|
||||
<data name=">>Button1.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>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=">>textBoxName.ZOrder" xml:space="preserve">
|
||||
<value>4</value>
|
||||
</data>
|
||||
<data name=">>textBox1.Name" xml:space="preserve">
|
||||
<value>textBox1</value>
|
||||
</data>
|
||||
<data name=">>$this.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Form, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>Button2.Name" xml:space="preserve">
|
||||
<value>Button2</value>
|
||||
</data>
|
||||
<data name=">>label2.Name" xml:space="preserve">
|
||||
<value>label2</value>
|
||||
</data>
|
||||
<data name=">>ButtonSave.Type" xml:space="preserve">
|
||||
<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=">>label2.ZOrder" xml:space="preserve">
|
||||
<value>3</value>
|
||||
</data>
|
||||
<data name=">>Button1.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>$this.Name" xml:space="preserve">
|
||||
<value>FormComponent</value>
|
||||
</data>
|
||||
<data name=">>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 name="textBoxName.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>95, 6</value>
|
||||
</data>
|
||||
<data name=">>textBox1.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name=">>ButtonCancel.Name" xml:space="preserve">
|
||||
<value>ButtonCancel</value>
|
||||
</data>
|
||||
<data name=">>ButtonCancel.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
@ -147,19 +147,19 @@
|
||||
<data name="label2.Text" xml:space="preserve">
|
||||
<value>Цена</value>
|
||||
</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>
|
||||
</data>
|
||||
<data name="buttonSave.Text" xml:space="preserve">
|
||||
<data name="ButtonSave.Text" xml:space="preserve">
|
||||
<value>Сохранить</value>
|
||||
</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>
|
||||
</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>
|
||||
</data>
|
||||
<data name="buttonCancel.Text" xml:space="preserve">
|
||||
<data name="ButtonCancel.Text" xml:space="preserve">
|
||||
<value>Отмена</value>
|
||||
</data>
|
||||
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
100
SushiBar/SushiBar/Forms/FormComponents.Designer.cs
generated
100
SushiBar/SushiBar/Forms/FormComponents.Designer.cs
generated
@ -29,77 +29,83 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
buttonAdd = new Button();
|
||||
buttonUpd = new Button();
|
||||
buttonDel = new Button();
|
||||
buttonRef = new Button();
|
||||
ButtonAdd = new Button();
|
||||
ButtonUpd = new Button();
|
||||
ButtonDel = new Button();
|
||||
ButtonRef = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Left;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(668, 408);
|
||||
dataGridView.Size = new Size(694, 408);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
// ButtonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(674, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(114, 29);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonAdd.Location = new Point(700, 12);
|
||||
ButtonAdd.Name = "ButtonAdd";
|
||||
ButtonAdd.Size = new Size(180, 29);
|
||||
ButtonAdd.TabIndex = 1;
|
||||
ButtonAdd.Text = "Добавить";
|
||||
ButtonAdd.UseVisualStyleBackColor = true;
|
||||
ButtonAdd.Click += ButtonAdd_Click;
|
||||
//
|
||||
// buttonUpd
|
||||
// ButtonUpd
|
||||
//
|
||||
buttonUpd.Location = new Point(674, 47);
|
||||
buttonUpd.Name = "buttonUpd";
|
||||
buttonUpd.Size = new Size(114, 29);
|
||||
buttonUpd.TabIndex = 2;
|
||||
buttonUpd.Text = "Изменить";
|
||||
buttonUpd.UseVisualStyleBackColor = true;
|
||||
buttonUpd.Click += buttonUpd_Click;
|
||||
ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonUpd.Location = new Point(700, 47);
|
||||
ButtonUpd.Name = "ButtonUpd";
|
||||
ButtonUpd.Size = new Size(180, 29);
|
||||
ButtonUpd.TabIndex = 2;
|
||||
ButtonUpd.Text = "Изменить";
|
||||
ButtonUpd.UseVisualStyleBackColor = true;
|
||||
ButtonUpd.Click += ButtonUpd_Click;
|
||||
//
|
||||
// buttonDel
|
||||
// ButtonDel
|
||||
//
|
||||
buttonDel.Location = new Point(674, 82);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(114, 29);
|
||||
buttonDel.TabIndex = 3;
|
||||
buttonDel.Text = "Удалить";
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += buttonDel_Click;
|
||||
ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonDel.Location = new Point(700, 82);
|
||||
ButtonDel.Name = "ButtonDel";
|
||||
ButtonDel.Size = new Size(180, 29);
|
||||
ButtonDel.TabIndex = 3;
|
||||
ButtonDel.Text = "Удалить";
|
||||
ButtonDel.UseVisualStyleBackColor = true;
|
||||
ButtonDel.Click += ButtonDel_Click;
|
||||
//
|
||||
// buttonRef
|
||||
// ButtonRef
|
||||
//
|
||||
buttonRef.Location = new Point(674, 117);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(114, 29);
|
||||
buttonRef.TabIndex = 4;
|
||||
buttonRef.Text = "Обновить";
|
||||
buttonRef.UseVisualStyleBackColor = true;
|
||||
buttonRef.Click += buttonRef_Click;
|
||||
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonRef.Location = new Point(700, 117);
|
||||
ButtonRef.Name = "ButtonRef";
|
||||
ButtonRef.Size = new Size(180, 29);
|
||||
ButtonRef.TabIndex = 4;
|
||||
ButtonRef.Text = "Обновить";
|
||||
ButtonRef.UseVisualStyleBackColor = true;
|
||||
ButtonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// FormComponents
|
||||
//
|
||||
AllowDrop = true;
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 408);
|
||||
Controls.Add(buttonRef);
|
||||
Controls.Add(buttonDel);
|
||||
Controls.Add(buttonUpd);
|
||||
Controls.Add(buttonAdd);
|
||||
ClientSize = new Size(892, 408);
|
||||
Controls.Add(ButtonRef);
|
||||
Controls.Add(ButtonDel);
|
||||
Controls.Add(ButtonUpd);
|
||||
Controls.Add(ButtonAdd);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormComponents";
|
||||
Text = "Компоненты";
|
||||
WindowState = FormWindowState.Maximized;
|
||||
Load += FormComponents_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
@ -108,9 +114,9 @@
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonUpd;
|
||||
private Button buttonDel;
|
||||
private Button buttonRef;
|
||||
private Button ButtonAdd;
|
||||
private Button ButtonUpd;
|
||||
private Button ButtonDel;
|
||||
private Button ButtonRef;
|
||||
}
|
||||
}
|
@ -1,35 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
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 buttonUpd_Click(object sender, EventArgs e)
|
||||
private void FormComponents_Load(object sender, EventArgs e)
|
||||
{
|
||||
ButtonUpd_Click(sender, e);
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void buttonDel_Click(object sender, EventArgs e)
|
||||
private void LoadData()
|
||||
{
|
||||
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("Загрузка компонентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonRef_Click(object sender, EventArgs e)
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonRef_Click(sender, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
108
SushiBar/SushiBar/Forms/FormCreateOrder.Designer.cs
generated
108
SushiBar/SushiBar/Forms/FormCreateOrder.Designer.cs
generated
@ -28,35 +28,35 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
ButtonSave = new Button();
|
||||
ButtonCancel = new Button();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
label3 = new Label();
|
||||
textBoxCount = new TextBox();
|
||||
textBoxSum = new TextBox();
|
||||
comboBoxSushi = new ComboBox();
|
||||
TextBoxCount = new TextBox();
|
||||
TextBoxSum = new TextBox();
|
||||
ComboBoxSushi = new ComboBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonSave
|
||||
// ButtonSave
|
||||
//
|
||||
buttonSave.Location = new Point(185, 112);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(100, 30);
|
||||
buttonSave.TabIndex = 0;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
ButtonSave.Location = new Point(185, 112);
|
||||
ButtonSave.Name = "ButtonSave";
|
||||
ButtonSave.Size = new Size(100, 30);
|
||||
ButtonSave.TabIndex = 0;
|
||||
ButtonSave.Text = "Сохранить";
|
||||
ButtonSave.UseVisualStyleBackColor = true;
|
||||
ButtonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
// ButtonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(291, 112);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(100, 30);
|
||||
buttonCancel.TabIndex = 1;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
ButtonCancel.Location = new Point(291, 112);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(100, 30);
|
||||
ButtonCancel.TabIndex = 1;
|
||||
ButtonCancel.Text = "Отмена";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
ButtonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
@ -85,46 +85,50 @@
|
||||
label3.TabIndex = 4;
|
||||
label3.Text = "Сумма:";
|
||||
//
|
||||
// textBoxCount
|
||||
// TextBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(119, 46);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(272, 27);
|
||||
textBoxCount.TabIndex = 5;
|
||||
textBoxCount.TextChanged += textBoxCount_TextChanged;
|
||||
TextBoxCount.Location = new Point(119, 46);
|
||||
TextBoxCount.Name = "TextBoxCount";
|
||||
TextBoxCount.Size = new Size(272, 27);
|
||||
TextBoxCount.TabIndex = 5;
|
||||
TextBoxCount.TextChanged += TextBoxCount_TextChanged;
|
||||
//
|
||||
// textBoxSum
|
||||
// TextBoxSum
|
||||
//
|
||||
textBoxSum.Location = new Point(119, 79);
|
||||
textBoxSum.Name = "textBoxSum";
|
||||
textBoxSum.ReadOnly = true;
|
||||
textBoxSum.Size = new Size(272, 27);
|
||||
textBoxSum.TabIndex = 6;
|
||||
TextBoxSum.Location = new Point(119, 79);
|
||||
TextBoxSum.Name = "TextBoxSum";
|
||||
TextBoxSum.ReadOnly = true;
|
||||
TextBoxSum.Size = new Size(272, 27);
|
||||
TextBoxSum.TabIndex = 6;
|
||||
//
|
||||
// comboBoxSushi
|
||||
// ComboBoxSushi
|
||||
//
|
||||
comboBoxSushi.FormattingEnabled = true;
|
||||
comboBoxSushi.Location = new Point(119, 12);
|
||||
comboBoxSushi.Name = "comboBoxSushi";
|
||||
comboBoxSushi.Size = new Size(272, 28);
|
||||
comboBoxSushi.TabIndex = 7;
|
||||
comboBoxSushi.SelectedIndexChanged += comboBoxSushi_SelectedIndexChanged;
|
||||
ComboBoxSushi.FormattingEnabled = true;
|
||||
ComboBoxSushi.Location = new Point(119, 12);
|
||||
ComboBoxSushi.Name = "ComboBoxSushi";
|
||||
ComboBoxSushi.Size = new Size(272, 28);
|
||||
ComboBoxSushi.TabIndex = 7;
|
||||
ComboBoxSushi.SelectedIndexChanged += ComboBoxSushi_SelectedIndexChanged;
|
||||
//
|
||||
// FormCreateOrder
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
AllowDrop = true;
|
||||
AutoScaleMode = AutoScaleMode.None;
|
||||
ClientSize = new Size(403, 152);
|
||||
Controls.Add(comboBoxSushi);
|
||||
Controls.Add(textBoxSum);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(ComboBoxSushi);
|
||||
Controls.Add(TextBoxSum);
|
||||
Controls.Add(TextBoxCount);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(ButtonSave);
|
||||
MaximizeBox = false;
|
||||
MinimizeBox = false;
|
||||
Name = "FormCreateOrder";
|
||||
ShowInTaskbar = false;
|
||||
Text = "Заказ";
|
||||
TopMost = true;
|
||||
Load += FormCreateOrder_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
@ -132,13 +136,13 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Button ButtonSave;
|
||||
private Button ButtonCancel;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private TextBox textBoxCount;
|
||||
private TextBox textBoxSum;
|
||||
private ComboBox comboBoxSushi;
|
||||
private TextBox TextBoxCount;
|
||||
private TextBox TextBoxSum;
|
||||
private ComboBox ComboBoxSushi;
|
||||
}
|
||||
}
|
@ -1,35 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
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 buttonCancel_Click(object sender, EventArgs e)
|
||||
private void FormCreateOrder_Load(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;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки суши");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void textBoxCount_TextChanged(object sender, EventArgs e)
|
||||
private void CalcSum()
|
||||
{
|
||||
TextBoxCount_TextChanged(sender, e);
|
||||
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 comboBoxSushi_SelectedIndexChanged(object sender, EventArgs e)
|
||||
private void TextBoxCount_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
ComboBoxSushi_SelectedIndexChanged(sender, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
152
SushiBar/SushiBar/Forms/FormMain.Designer.cs
generated
152
SushiBar/SushiBar/Forms/FormMain.Designer.cs
generated
@ -31,26 +31,27 @@
|
||||
dataGridView = new DataGridView();
|
||||
menuStrip1 = new MenuStrip();
|
||||
ToolStripMenuItem = new ToolStripMenuItem();
|
||||
sushiToolStripMenuItem = new ToolStripMenuItem();
|
||||
componentsToolStripMenuItem = new ToolStripMenuItem();
|
||||
buttonCreateOrder = new Button();
|
||||
buttonTakeOrderInWork = new Button();
|
||||
buttonOrderReady = new Button();
|
||||
buttonIssuedOrder = new Button();
|
||||
buttonRef = new Button();
|
||||
SushiToolStripMenuItem = new ToolStripMenuItem();
|
||||
ComponentsToolStripMenuItem = new ToolStripMenuItem();
|
||||
ButtonCreateOrder = new Button();
|
||||
ButtonTakeOrderInWork = new Button();
|
||||
ButtonOrderReady = new Button();
|
||||
ButtonIssuedOrder = new Button();
|
||||
ButtonRef = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(12, 31);
|
||||
dataGridView.Location = new Point(0, 28);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(980, 407);
|
||||
dataGridView.Size = new Size(992, 422);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// menuStrip1
|
||||
@ -65,90 +66,97 @@
|
||||
//
|
||||
// ToolStripMenuItem
|
||||
//
|
||||
ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { sushiToolStripMenuItem, componentsToolStripMenuItem });
|
||||
ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SushiToolStripMenuItem, ComponentsToolStripMenuItem });
|
||||
ToolStripMenuItem.Name = "ToolStripMenuItem";
|
||||
ToolStripMenuItem.Size = new Size(117, 24);
|
||||
ToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// sushiToolStripMenuItem
|
||||
// SushiToolStripMenuItem
|
||||
//
|
||||
sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
|
||||
sushiToolStripMenuItem.Size = new Size(182, 26);
|
||||
sushiToolStripMenuItem.Text = "Суши";
|
||||
sushiToolStripMenuItem.Click += sushiToolStripMenuItem_Click;
|
||||
SushiToolStripMenuItem.Name = "SushiToolStripMenuItem";
|
||||
SushiToolStripMenuItem.Size = new Size(182, 26);
|
||||
SushiToolStripMenuItem.Text = "Суши";
|
||||
SushiToolStripMenuItem.Click += SushiToolStripMenuItem_Click;
|
||||
//
|
||||
// componentsToolStripMenuItem
|
||||
// ComponentsToolStripMenuItem
|
||||
//
|
||||
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
|
||||
componentsToolStripMenuItem.Size = new Size(182, 26);
|
||||
componentsToolStripMenuItem.Text = "Компоненты";
|
||||
componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click;
|
||||
ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem";
|
||||
ComponentsToolStripMenuItem.Size = new Size(182, 26);
|
||||
ComponentsToolStripMenuItem.Text = "Компоненты";
|
||||
ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
||||
//
|
||||
// buttonCreateOrder
|
||||
// ButtonCreateOrder
|
||||
//
|
||||
buttonCreateOrder.Location = new Point(998, 50);
|
||||
buttonCreateOrder.Name = "buttonCreateOrder";
|
||||
buttonCreateOrder.Size = new Size(180, 30);
|
||||
buttonCreateOrder.TabIndex = 2;
|
||||
buttonCreateOrder.Text = "Создать заказ";
|
||||
buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||
buttonCreateOrder.Click += buttonCreateOrder_Click;
|
||||
ButtonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonCreateOrder.Location = new Point(998, 31);
|
||||
ButtonCreateOrder.Name = "ButtonCreateOrder";
|
||||
ButtonCreateOrder.Size = new Size(180, 30);
|
||||
ButtonCreateOrder.TabIndex = 2;
|
||||
ButtonCreateOrder.Text = "Создать заказ";
|
||||
ButtonCreateOrder.UseVisualStyleBackColor = true;
|
||||
ButtonCreateOrder.Click += ButtonCreateOrder_Click;
|
||||
//
|
||||
// buttonTakeOrderInWork
|
||||
// ButtonTakeOrderInWork
|
||||
//
|
||||
buttonTakeOrderInWork.Location = new Point(998, 86);
|
||||
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
|
||||
buttonTakeOrderInWork.Size = new Size(180, 30);
|
||||
buttonTakeOrderInWork.TabIndex = 3;
|
||||
buttonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||
buttonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||
buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click;
|
||||
ButtonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonTakeOrderInWork.Location = new Point(998, 67);
|
||||
ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork";
|
||||
ButtonTakeOrderInWork.Size = new Size(180, 30);
|
||||
ButtonTakeOrderInWork.TabIndex = 3;
|
||||
ButtonTakeOrderInWork.Text = "Отдать на выполнение";
|
||||
ButtonTakeOrderInWork.UseVisualStyleBackColor = true;
|
||||
ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
|
||||
//
|
||||
// buttonOrderReady
|
||||
// ButtonOrderReady
|
||||
//
|
||||
buttonOrderReady.Location = new Point(998, 122);
|
||||
buttonOrderReady.Name = "buttonOrderReady";
|
||||
buttonOrderReady.Size = new Size(180, 30);
|
||||
buttonOrderReady.TabIndex = 4;
|
||||
buttonOrderReady.Text = "Заказ готов";
|
||||
buttonOrderReady.UseVisualStyleBackColor = true;
|
||||
buttonOrderReady.Click += buttonOrderReady_Click;
|
||||
ButtonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonOrderReady.Location = new Point(998, 103);
|
||||
ButtonOrderReady.Name = "ButtonOrderReady";
|
||||
ButtonOrderReady.Size = new Size(180, 30);
|
||||
ButtonOrderReady.TabIndex = 4;
|
||||
ButtonOrderReady.Text = "Заказ готов";
|
||||
ButtonOrderReady.UseVisualStyleBackColor = true;
|
||||
ButtonOrderReady.Click += ButtonOrderReady_Click;
|
||||
//
|
||||
// buttonIssuedOrder
|
||||
// ButtonIssuedOrder
|
||||
//
|
||||
buttonIssuedOrder.Location = new Point(998, 158);
|
||||
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||
buttonIssuedOrder.Size = new Size(180, 30);
|
||||
buttonIssuedOrder.TabIndex = 5;
|
||||
buttonIssuedOrder.Text = "Заказ Выдан";
|
||||
buttonIssuedOrder.UseVisualStyleBackColor = true;
|
||||
buttonIssuedOrder.Click += buttonIssuedOrder_Click;
|
||||
ButtonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonIssuedOrder.Location = new Point(998, 139);
|
||||
ButtonIssuedOrder.Name = "ButtonIssuedOrder";
|
||||
ButtonIssuedOrder.Size = new Size(180, 30);
|
||||
ButtonIssuedOrder.TabIndex = 5;
|
||||
ButtonIssuedOrder.Text = "Заказ Выдан";
|
||||
ButtonIssuedOrder.UseVisualStyleBackColor = true;
|
||||
ButtonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
||||
//
|
||||
// buttonRef
|
||||
// ButtonRef
|
||||
//
|
||||
buttonRef.Location = new Point(998, 194);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(180, 30);
|
||||
buttonRef.TabIndex = 6;
|
||||
buttonRef.Text = "Обновить список";
|
||||
buttonRef.UseVisualStyleBackColor = true;
|
||||
buttonRef.Click += buttonRef_Click;
|
||||
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonRef.Location = new Point(998, 175);
|
||||
ButtonRef.Name = "ButtonRef";
|
||||
ButtonRef.Size = new Size(180, 30);
|
||||
ButtonRef.TabIndex = 6;
|
||||
ButtonRef.Text = "Обновить список";
|
||||
ButtonRef.UseVisualStyleBackColor = true;
|
||||
ButtonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AllowDrop = true;
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1190, 450);
|
||||
Controls.Add(buttonRef);
|
||||
Controls.Add(buttonIssuedOrder);
|
||||
Controls.Add(buttonOrderReady);
|
||||
Controls.Add(buttonTakeOrderInWork);
|
||||
Controls.Add(buttonCreateOrder);
|
||||
Controls.Add(ButtonRef);
|
||||
Controls.Add(ButtonIssuedOrder);
|
||||
Controls.Add(ButtonOrderReady);
|
||||
Controls.Add(ButtonTakeOrderInWork);
|
||||
Controls.Add(ButtonCreateOrder);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Name = "FormMain";
|
||||
Text = "Сушибар";
|
||||
WindowState = FormWindowState.Maximized;
|
||||
Load += FormMain_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
menuStrip1.ResumeLayout(false);
|
||||
@ -161,13 +169,13 @@
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private MenuStrip menuStrip1;
|
||||
private Button buttonCreateOrder;
|
||||
private Button buttonTakeOrderInWork;
|
||||
private Button buttonOrderReady;
|
||||
private Button buttonIssuedOrder;
|
||||
private Button buttonRef;
|
||||
private Button ButtonCreateOrder;
|
||||
private Button ButtonTakeOrderInWork;
|
||||
private Button ButtonOrderReady;
|
||||
private Button ButtonIssuedOrder;
|
||||
private Button ButtonRef;
|
||||
private ToolStripMenuItem ToolStripMenuItem;
|
||||
private ToolStripMenuItem sushiToolStripMenuItem;
|
||||
private ToolStripMenuItem componentsToolStripMenuItem;
|
||||
private ToolStripMenuItem SushiToolStripMenuItem;
|
||||
private ToolStripMenuItem ComponentsToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -1,40 +1,137 @@
|
||||
namespace SushiBar.Forms
|
||||
using Microsoft.Extensions.Logging;
|
||||
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;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||
{
|
||||
ButtonCreateOrder_Click(sender, e);
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
}
|
||||
|
||||
private void buttonTakeOrderInWork_Click(object sender, EventArgs e)
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
ButtonTakeOrderInWork_Click(sender, e);
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void buttonOrderReady_Click(object sender, EventArgs e)
|
||||
private void LoadData()
|
||||
{
|
||||
ButtonOrderReady_Click(sender, e);
|
||||
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 buttonIssuedOrder_Click(object sender, EventArgs e)
|
||||
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonIssuedOrder_Click(sender, e);
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||
if (service is FormComponents form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonRef_Click(object sender, EventArgs e)
|
||||
private void SushiToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonRef_Click(sender, e);
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSushis));
|
||||
if (service is FormSushis form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void sushiToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void ButtonCreateOrder_Click(object sender, EventArgs e)
|
||||
{
|
||||
SushiToolStripMenuItem_Click(sender, e);
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
if (service is FormCreateOrder form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void componentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
||||
{
|
||||
ComponentsToolStripMenuItem_Click(sender, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,140 +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;
|
||||
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
178
SushiBar/SushiBar/Forms/FormShop.Designer.cs
generated
Normal file
178
SushiBar/SushiBar/Forms/FormShop.Designer.cs
generated
Normal file
@ -0,0 +1,178 @@
|
||||
namespace SushiBar.Forms
|
||||
{
|
||||
partial class FormShop
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
ButtonSave = new Button();
|
||||
ButtonCancel = new Button();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
textBoxName = new TextBox();
|
||||
textBoxAddress = new TextBox();
|
||||
dataGridView = new DataGridView();
|
||||
Id = new DataGridViewTextBoxColumn();
|
||||
SushiName = new DataGridViewTextBoxColumn();
|
||||
Sum = new DataGridViewTextBoxColumn();
|
||||
Count = new DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// ButtonSave
|
||||
//
|
||||
ButtonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonSave.Location = new Point(536, 418);
|
||||
ButtonSave.Name = "ButtonSave";
|
||||
ButtonSave.Size = new Size(123, 29);
|
||||
ButtonSave.TabIndex = 0;
|
||||
ButtonSave.Text = "Сохранить";
|
||||
ButtonSave.UseVisualStyleBackColor = true;
|
||||
ButtonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
ButtonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonCancel.Location = new Point(665, 418);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(123, 29);
|
||||
ButtonCancel.TabIndex = 1;
|
||||
ButtonCancel.Text = "Отмена";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(22, 28);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(77, 20);
|
||||
label1.TabIndex = 2;
|
||||
label1.Text = "Название\r\n";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(22, 71);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(51, 20);
|
||||
label2.TabIndex = 3;
|
||||
label2.Text = "Адрес";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBoxName.Location = new Point(150, 25);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(631, 27);
|
||||
textBoxName.TabIndex = 5;
|
||||
//
|
||||
// textBoxAddress
|
||||
//
|
||||
textBoxAddress.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBoxAddress.Location = new Point(150, 68);
|
||||
textBoxAddress.Name = "textBoxAddress";
|
||||
textBoxAddress.Size = new Size(631, 27);
|
||||
textBoxAddress.TabIndex = 6;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Id, SushiName, Sum, Count });
|
||||
dataGridView.Location = new Point(23, 111);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(759, 302);
|
||||
dataGridView.TabIndex = 7;
|
||||
//
|
||||
// Id
|
||||
//
|
||||
Id.HeaderText = "Id";
|
||||
Id.MinimumWidth = 6;
|
||||
Id.Name = "Id";
|
||||
Id.Visible = false;
|
||||
Id.Width = 125;
|
||||
//
|
||||
// SushiName
|
||||
//
|
||||
SushiName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
SushiName.HeaderText = "Суши";
|
||||
SushiName.MinimumWidth = 6;
|
||||
SushiName.Name = "SushiName";
|
||||
SushiName.ReadOnly = true;
|
||||
//
|
||||
// Sum
|
||||
//
|
||||
Sum.HeaderText = "Стоимость";
|
||||
Sum.MinimumWidth = 6;
|
||||
Sum.Name = "Sum";
|
||||
Sum.ReadOnly = true;
|
||||
Sum.Width = 125;
|
||||
//
|
||||
// Count
|
||||
//
|
||||
Count.HeaderText = "Количество";
|
||||
Count.MinimumWidth = 6;
|
||||
Count.Name = "Count";
|
||||
Count.ReadOnly = true;
|
||||
Count.Width = 125;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AllowDrop = true;
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(793, 453);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(textBoxAddress);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(ButtonSave);
|
||||
Name = "FormShop";
|
||||
Text = "Форма магазина";
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button ButtonSave;
|
||||
private Button ButtonCancel;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private TextBox textBoxName;
|
||||
private TextBox textBoxAddress;
|
||||
private DataGridView dataGridView;
|
||||
private DataGridViewTextBoxColumn Id;
|
||||
private DataGridViewTextBoxColumn SushiName;
|
||||
private DataGridViewTextBoxColumn Sum;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
}
|
||||
}
|
60
SushiBar/SushiBar/Forms/FormShop.cs
Normal file
60
SushiBar/SushiBar/Forms/FormShop.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
namespace SushiBar.Forms
|
||||
{
|
||||
public partial class FormShop : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _logic;
|
||||
public int? _id;
|
||||
private Dictionary<int, (ISushiModel, int)> _sushis;
|
||||
public FormShop(ILogger logger, IShopLogic logic)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxAddress.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
var model = new ShopBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
ShopName = textBoxName.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
DateCreate = DateTime.Now,
|
||||
ShopSushi = _sushis
|
||||
};
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
144
SushiBar/SushiBar/Forms/FormShop.resx
Normal file
144
SushiBar/SushiBar/Forms/FormShop.resx
Normal file
@ -0,0 +1,144 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="SushiName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Sum.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="SushiName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Sum.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>
|
116
SushiBar/SushiBar/Forms/FormShops.Designer.cs
generated
Normal file
116
SushiBar/SushiBar/Forms/FormShops.Designer.cs
generated
Normal file
@ -0,0 +1,116 @@
|
||||
namespace SushiBar.Forms
|
||||
{
|
||||
partial class FormShops
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
buttonCreate = new Button();
|
||||
buttonUpdate = new Button();
|
||||
buttonRemove = new Button();
|
||||
buttonRef = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(12, 12);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(606, 426);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonCreate.Location = new Point(635, 12);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(153, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Добавить";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonUpdate.Location = new Point(635, 56);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(153, 29);
|
||||
buttonUpdate.TabIndex = 2;
|
||||
buttonUpdate.Text = "Изменить";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonRemove
|
||||
//
|
||||
buttonRemove.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonRemove.Location = new Point(635, 102);
|
||||
buttonRemove.Name = "buttonRemove";
|
||||
buttonRemove.Size = new Size(153, 29);
|
||||
buttonRemove.TabIndex = 3;
|
||||
buttonRemove.Text = "Удалить";
|
||||
buttonRemove.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonRef
|
||||
//
|
||||
buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonRef.Location = new Point(635, 146);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(153, 29);
|
||||
buttonRef.TabIndex = 4;
|
||||
buttonRef.Text = "Обновить";
|
||||
buttonRef.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormShops
|
||||
//
|
||||
AllowDrop = true;
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonRef);
|
||||
Controls.Add(buttonRemove);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormShops";
|
||||
Text = "FormShops";
|
||||
Load += FormShops_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonCreate;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonRemove;
|
||||
private Button buttonRef;
|
||||
}
|
||||
}
|
54
SushiBar/SushiBar/Forms/FormShops.cs
Normal file
54
SushiBar/SushiBar/Forms/FormShops.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SushiBar.Forms
|
||||
{
|
||||
public partial class FormShops : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IShopLogic _logic;
|
||||
public FormShops(ILogger logger, IShopLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["ShopIceCreams"].Visible = false;
|
||||
}
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FormShops_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
120
SushiBar/SushiBar/Forms/FormShops.resx
Normal file
120
SushiBar/SushiBar/Forms/FormShops.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
160
SushiBar/SushiBar/Forms/FormSushi.Designer.cs
generated
160
SushiBar/SushiBar/Forms/FormSushi.Designer.cs
generated
@ -28,17 +28,17 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonAdd = new Button();
|
||||
ButtonAdd = new Button();
|
||||
dataGridView = new DataGridView();
|
||||
ID = new DataGridViewTextBoxColumn();
|
||||
ComponentName = new DataGridViewTextBoxColumn();
|
||||
ComponentCount = new DataGridViewTextBoxColumn();
|
||||
groupBox1 = new GroupBox();
|
||||
buttonRef = new Button();
|
||||
buttonDel = new Button();
|
||||
buttonUpd = new Button();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
ButtonRef = new Button();
|
||||
ButtonDel = new Button();
|
||||
ButtonUpd = new Button();
|
||||
ButtonSave = new Button();
|
||||
ButtonCancel = new Button();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
textBoxPrice = new TextBox();
|
||||
@ -47,24 +47,25 @@
|
||||
groupBox1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonAdd
|
||||
// ButtonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(640, 29);
|
||||
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(126, 39);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonAdd.Location = new Point(614, 28);
|
||||
ButtonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonAdd.Name = "ButtonAdd";
|
||||
ButtonAdd.Size = new Size(151, 39);
|
||||
ButtonAdd.TabIndex = 0;
|
||||
ButtonAdd.Text = "Добавить";
|
||||
ButtonAdd.UseVisualStyleBackColor = true;
|
||||
ButtonAdd.Click += ButtonAdd_Click;
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.AllowUserToDeleteRows = false;
|
||||
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ComponentName, ComponentCount });
|
||||
dataGridView.Dock = DockStyle.Left;
|
||||
dataGridView.Location = new Point(3, 24);
|
||||
dataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||
dataGridView.Name = "dataGridView";
|
||||
@ -72,7 +73,7 @@
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 25;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(630, 267);
|
||||
dataGridView.Size = new Size(605, 243);
|
||||
dataGridView.TabIndex = 1;
|
||||
//
|
||||
// ID
|
||||
@ -102,76 +103,80 @@
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(buttonRef);
|
||||
groupBox1.Controls.Add(buttonDel);
|
||||
groupBox1.Controls.Add(buttonUpd);
|
||||
groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
groupBox1.Controls.Add(ButtonRef);
|
||||
groupBox1.Controls.Add(ButtonDel);
|
||||
groupBox1.Controls.Add(ButtonUpd);
|
||||
groupBox1.Controls.Add(dataGridView);
|
||||
groupBox1.Controls.Add(buttonAdd);
|
||||
groupBox1.Controls.Add(ButtonAdd);
|
||||
groupBox1.Location = new Point(14, 101);
|
||||
groupBox1.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBox1.Size = new Size(773, 295);
|
||||
groupBox1.Size = new Size(774, 295);
|
||||
groupBox1.TabIndex = 2;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Компоненты";
|
||||
//
|
||||
// buttonRef
|
||||
// ButtonRef
|
||||
//
|
||||
buttonRef.Location = new Point(640, 169);
|
||||
buttonRef.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(126, 39);
|
||||
buttonRef.TabIndex = 4;
|
||||
buttonRef.Text = "Обновить";
|
||||
buttonRef.UseVisualStyleBackColor = true;
|
||||
buttonRef.Click += buttonRef_Click;
|
||||
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonRef.Location = new Point(614, 168);
|
||||
ButtonRef.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonRef.Name = "ButtonRef";
|
||||
ButtonRef.Size = new Size(151, 39);
|
||||
ButtonRef.TabIndex = 4;
|
||||
ButtonRef.Text = "Обновить";
|
||||
ButtonRef.UseVisualStyleBackColor = true;
|
||||
ButtonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// buttonDel
|
||||
// ButtonDel
|
||||
//
|
||||
buttonDel.Location = new Point(640, 123);
|
||||
buttonDel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(126, 39);
|
||||
buttonDel.TabIndex = 3;
|
||||
buttonDel.Text = "Удалить";
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += buttonDel_Click;
|
||||
ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonDel.Location = new Point(614, 122);
|
||||
ButtonDel.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonDel.Name = "ButtonDel";
|
||||
ButtonDel.Size = new Size(151, 39);
|
||||
ButtonDel.TabIndex = 3;
|
||||
ButtonDel.Text = "Удалить";
|
||||
ButtonDel.UseVisualStyleBackColor = true;
|
||||
ButtonDel.Click += ButtonDel_Click;
|
||||
//
|
||||
// buttonUpd
|
||||
// ButtonUpd
|
||||
//
|
||||
buttonUpd.Location = new Point(640, 76);
|
||||
buttonUpd.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonUpd.Name = "buttonUpd";
|
||||
buttonUpd.Size = new Size(126, 39);
|
||||
buttonUpd.TabIndex = 2;
|
||||
buttonUpd.Text = "Изменить";
|
||||
buttonUpd.UseVisualStyleBackColor = true;
|
||||
buttonUpd.Click += buttonUpd_Click;
|
||||
ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonUpd.Location = new Point(614, 75);
|
||||
ButtonUpd.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonUpd.Name = "ButtonUpd";
|
||||
ButtonUpd.Size = new Size(151, 39);
|
||||
ButtonUpd.TabIndex = 2;
|
||||
ButtonUpd.Text = "Изменить";
|
||||
ButtonUpd.UseVisualStyleBackColor = true;
|
||||
ButtonUpd.Click += ButtonUpd_Click;
|
||||
//
|
||||
// buttonSave
|
||||
// ButtonSave
|
||||
//
|
||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonSave.Location = new Point(573, 404);
|
||||
buttonSave.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(100, 31);
|
||||
buttonSave.TabIndex = 3;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
ButtonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonSave.Location = new Point(573, 404);
|
||||
ButtonSave.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonSave.Name = "ButtonSave";
|
||||
ButtonSave.Size = new Size(100, 31);
|
||||
ButtonSave.TabIndex = 3;
|
||||
ButtonSave.Text = "Сохранить";
|
||||
ButtonSave.UseVisualStyleBackColor = true;
|
||||
ButtonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
// ButtonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(679, 404);
|
||||
buttonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(100, 31);
|
||||
buttonCancel.TabIndex = 4;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
ButtonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
ButtonCancel.Location = new Point(679, 404);
|
||||
ButtonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(100, 31);
|
||||
ButtonCancel.TabIndex = 4;
|
||||
ButtonCancel.Text = "Отмена";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
ButtonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
@ -209,6 +214,7 @@
|
||||
//
|
||||
// FormSushi
|
||||
//
|
||||
AllowDrop = true;
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 451);
|
||||
@ -216,8 +222,8 @@
|
||||
Controls.Add(textBoxPrice);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(ButtonSave);
|
||||
Controls.Add(groupBox1);
|
||||
Name = "FormSushi";
|
||||
Text = "Суши";
|
||||
@ -230,14 +236,14 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonAdd;
|
||||
private Button ButtonAdd;
|
||||
private DataGridView dataGridView;
|
||||
private GroupBox groupBox1;
|
||||
private Button buttonRef;
|
||||
private Button buttonDel;
|
||||
private Button buttonUpd;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Button ButtonRef;
|
||||
private Button ButtonDel;
|
||||
private Button ButtonUpd;
|
||||
private Button ButtonSave;
|
||||
private Button ButtonCancel;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private TextBox textBoxPrice;
|
||||
|
@ -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 void buttonDel_Click(object sender, EventArgs e)
|
||||
private double CalcPrice()
|
||||
{
|
||||
ButtonDel_Click(sender, e);
|
||||
}
|
||||
|
||||
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);
|
||||
double price = 0;
|
||||
foreach (var elem in _sushiComponents)
|
||||
{
|
||||
price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
|
||||
}
|
||||
return Math.Round(price * 1.1, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@
|
||||
label2 = new Label();
|
||||
comboBoxComponent = new ComboBox();
|
||||
textBoxCount = new TextBox();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
ButtonSave = new Button();
|
||||
ButtonCancel = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
@ -69,39 +69,44 @@
|
||||
textBoxCount.Size = new Size(227, 27);
|
||||
textBoxCount.TabIndex = 3;
|
||||
//
|
||||
// buttonSave
|
||||
// ButtonSave
|
||||
//
|
||||
buttonSave.Location = new Point(158, 95);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(94, 29);
|
||||
buttonSave.TabIndex = 4;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
ButtonSave.Location = new Point(158, 95);
|
||||
ButtonSave.Name = "ButtonSave";
|
||||
ButtonSave.Size = new Size(94, 29);
|
||||
ButtonSave.TabIndex = 4;
|
||||
ButtonSave.Text = "Сохранить";
|
||||
ButtonSave.UseVisualStyleBackColor = true;
|
||||
ButtonSave.Click += ButtonSave_Click;
|
||||
//
|
||||
// buttonCancel
|
||||
// ButtonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(258, 95);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 5;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
ButtonCancel.Location = new Point(258, 95);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(94, 29);
|
||||
ButtonCancel.TabIndex = 5;
|
||||
ButtonCancel.Text = "Отмена";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
ButtonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// FormSushiComponent
|
||||
//
|
||||
AllowDrop = true;
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(364, 132);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(ButtonSave);
|
||||
Controls.Add(textBoxCount);
|
||||
Controls.Add(comboBoxComponent);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
MaximizeBox = false;
|
||||
MinimizeBox = false;
|
||||
Name = "FormSushiComponent";
|
||||
ShowInTaskbar = false;
|
||||
Text = "Компонент Изделия";
|
||||
TopMost = true;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
@ -112,7 +117,7 @@
|
||||
private Label label2;
|
||||
private ComboBox comboBoxComponent;
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Button ButtonSave;
|
||||
private Button ButtonCancel;
|
||||
}
|
||||
}
|
@ -1,25 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarDataModels.Models;
|
||||
|
||||
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
|
||||
{
|
||||
comboBoxComponent.SelectedValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
public IComponentModel? ComponentModel
|
||||
{
|
||||
ButtonCancel_Click(sender, e);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
98
SushiBar/SushiBar/Forms/FormSushis.Designer.cs
generated
98
SushiBar/SushiBar/Forms/FormSushis.Designer.cs
generated
@ -29,10 +29,10 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
buttonRef = new Button();
|
||||
buttonDel = new Button();
|
||||
buttonUpd = new Button();
|
||||
buttonAdd = new Button();
|
||||
ButtonRef = new Button();
|
||||
ButtonDel = new Button();
|
||||
ButtonUpd = new Button();
|
||||
ButtonAdd = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -46,61 +46,67 @@
|
||||
dataGridView.RowHeadersWidth = 70;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(762, 450);
|
||||
dataGridView.Size = new Size(777, 450);
|
||||
dataGridView.TabIndex = 1;
|
||||
//
|
||||
// buttonRef
|
||||
// ButtonRef
|
||||
//
|
||||
buttonRef.Location = new Point(768, 117);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(114, 29);
|
||||
buttonRef.TabIndex = 8;
|
||||
buttonRef.Text = "Обновить";
|
||||
buttonRef.UseVisualStyleBackColor = true;
|
||||
buttonRef.Click += buttonRef_Click;
|
||||
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonRef.Location = new Point(783, 117);
|
||||
ButtonRef.Name = "ButtonRef";
|
||||
ButtonRef.Size = new Size(150, 29);
|
||||
ButtonRef.TabIndex = 8;
|
||||
ButtonRef.Text = "Обновить";
|
||||
ButtonRef.UseVisualStyleBackColor = true;
|
||||
ButtonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// buttonDel
|
||||
// ButtonDel
|
||||
//
|
||||
buttonDel.Location = new Point(768, 82);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(114, 29);
|
||||
buttonDel.TabIndex = 7;
|
||||
buttonDel.Text = "Удалить";
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += buttonDel_Click;
|
||||
ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonDel.Location = new Point(783, 82);
|
||||
ButtonDel.Name = "ButtonDel";
|
||||
ButtonDel.Size = new Size(150, 29);
|
||||
ButtonDel.TabIndex = 7;
|
||||
ButtonDel.Text = "Удалить";
|
||||
ButtonDel.UseVisualStyleBackColor = true;
|
||||
ButtonDel.Click += ButtonDel_Click;
|
||||
//
|
||||
// buttonUpd
|
||||
// ButtonUpd
|
||||
//
|
||||
buttonUpd.Location = new Point(768, 47);
|
||||
buttonUpd.Name = "buttonUpd";
|
||||
buttonUpd.Size = new Size(114, 29);
|
||||
buttonUpd.TabIndex = 6;
|
||||
buttonUpd.Text = "Изменить";
|
||||
buttonUpd.UseVisualStyleBackColor = true;
|
||||
buttonUpd.Click += buttonUpd_Click;
|
||||
ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonUpd.Location = new Point(783, 47);
|
||||
ButtonUpd.Name = "ButtonUpd";
|
||||
ButtonUpd.Size = new Size(150, 29);
|
||||
ButtonUpd.TabIndex = 6;
|
||||
ButtonUpd.Text = "Изменить";
|
||||
ButtonUpd.UseVisualStyleBackColor = true;
|
||||
ButtonUpd.Click += ButtonUpd_Click;
|
||||
//
|
||||
// buttonAdd
|
||||
// ButtonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(768, 12);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(114, 29);
|
||||
buttonAdd.TabIndex = 5;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonAdd.Location = new Point(783, 12);
|
||||
ButtonAdd.Name = "ButtonAdd";
|
||||
ButtonAdd.Size = new Size(150, 29);
|
||||
ButtonAdd.TabIndex = 5;
|
||||
ButtonAdd.Text = "Добавить";
|
||||
ButtonAdd.UseVisualStyleBackColor = true;
|
||||
ButtonAdd.Click += ButtonAdd_Click;
|
||||
//
|
||||
// FormSushis
|
||||
//
|
||||
AllowDrop = true;
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(893, 450);
|
||||
Controls.Add(buttonRef);
|
||||
Controls.Add(buttonDel);
|
||||
Controls.Add(buttonUpd);
|
||||
Controls.Add(buttonAdd);
|
||||
ClientSize = new Size(945, 450);
|
||||
Controls.Add(ButtonRef);
|
||||
Controls.Add(ButtonDel);
|
||||
Controls.Add(ButtonUpd);
|
||||
Controls.Add(ButtonAdd);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormSushis";
|
||||
Text = "Суши";
|
||||
WindowState = FormWindowState.Maximized;
|
||||
Load += FormSushis_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
@ -109,9 +115,9 @@
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonRef;
|
||||
private Button buttonDel;
|
||||
private Button buttonUpd;
|
||||
private Button buttonAdd;
|
||||
private Button ButtonRef;
|
||||
private Button ButtonDel;
|
||||
private Button ButtonUpd;
|
||||
private Button ButtonAdd;
|
||||
}
|
||||
}
|
@ -1,35 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.BusinessLogicsContracts;
|
||||
|
||||
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 buttonUpd_Click(object sender, EventArgs e)
|
||||
private void FormSushis_Load(object sender, EventArgs e)
|
||||
{
|
||||
ButtonUpd_Click(sender, e);
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void buttonDel_Click(object sender, EventArgs e)
|
||||
private void LoadData()
|
||||
{
|
||||
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("Загрузка суши");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки суши");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonRef_Click(object sender, EventArgs e)
|
||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
ButtonRef_Click(sender, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
40
SushiBar/SushiBar/SushiBar.csproj
Normal file
40
SushiBar/SushiBar/SushiBar.csproj
Normal file
@ -0,0 +1,40 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="NLog" Version="5.2.8" />
|
||||
<PackageReference Include="NLog.Config" Version="4.7.15" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
<PackageReference Include="ReportViewerCore.WinForms" Version="15.1.19" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\SushiBarFileImplement\SushiBarFileImplement.csproj" />
|
||||
<ProjectReference Include="..\SushiBarListImplement\SushiBarListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="nlog.config">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Report\ReportOrders.rdlc">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -90,6 +90,11 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentException("Нет названия магазина", nameof(model.ShopName));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Address))
|
||||
{
|
||||
throw new ArgumentNullException("Нет адресса магазина", nameof(model.ShopName));
|
||||
}
|
||||
_logger.LogTrace("Shop. ShopName:{ShopName}.Address:{Address}. DateCreate:{DateCreate}. Id: { Id}", model.ShopName, model.Address, model.DateCreate, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
ShopName = model.ShopName
|
||||
@ -99,5 +104,37 @@ namespace SushiBarBusinessLogic.BusinessLogics
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
public bool MakeSupply(ShopSearchModel model, SushiBindingModel sushi, int count)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (sushi == null){
|
||||
throw new ArgumentNullException(nameof(sushi));
|
||||
}
|
||||
ShopViewModel? shop = _shopStorage.GetElement(new ShopSearchModel { Id = model.Id });
|
||||
if (shop == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(shop));
|
||||
}
|
||||
if (shop.ShopSushi.TryGetValue(sushi.Id, out var pair))
|
||||
{
|
||||
shop.ShopSushi[sushi.Id] = (pair.Item1, pair.Item2 + count);
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.ShopSushi.Add(sushi.Id, (sushi, count));
|
||||
}
|
||||
Update(new()
|
||||
{
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
DateCreate = shop.DateCreate,
|
||||
Address = shop.Address,
|
||||
ShopSushi = shop.ShopSushi
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj
Normal file
20
SushiBar/SushiBarBusinessLogic/SushiBarBusinessLogic.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml.Framework" Version="3.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -8,5 +8,10 @@ namespace SushiBarContracts.BindingModels
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
public string Address { get; set; } = string.Empty;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public Dictionary<int, (ISushiModel, int)> ShopSushi
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,6 @@ namespace SushiBarContracts.BusinessLogicsContracts
|
||||
bool Create(ShopBindingModel model);
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool MakeSupply(ShopSearchModel model, SushiBindingModel sushi, int count);
|
||||
}
|
||||
}
|
||||
|
13
SushiBar/SushiBarContracts/SushiBarContracts.csproj
Normal file
13
SushiBar/SushiBarContracts/SushiBarContracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
using SushiBarDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
@ -12,5 +13,6 @@ namespace SushiBarContracts.ViewModels
|
||||
public string Address { get; set; } = string.Empty;
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public Dictionary<int, (ISushiModel, int)> ShopSushi { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -5,5 +5,6 @@
|
||||
string ShopName { get; }
|
||||
string Address { get; }
|
||||
DateTime DateCreate { get; }
|
||||
Dictionary<int, (ISushiModel, int)> ShopSushi {get;}
|
||||
}
|
||||
}
|
||||
|
9
SushiBar/SushiBarDataModels/SushiBarDataModels.csproj
Normal file
9
SushiBar/SushiBarDataModels/SushiBarDataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -4,7 +4,7 @@ namespace SushiBarListImplement
|
||||
{
|
||||
public class DataListSingleton
|
||||
{
|
||||
private static DataListSingleton _instance;
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Sushi> Sushis { get; set; }
|
||||
|
@ -98,6 +98,5 @@ namespace SushiBarListImplement.Implements
|
||||
}
|
||||
return null;
|
||||
}
|
||||
з
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace SushiBarListImplement.Models
|
||||
public string ShopName { get; private set; } = string.Empty;
|
||||
public string Address { get; private set; } = string.Empty;
|
||||
public DateTime DateCreate { get; private set; }
|
||||
public Dictionary<int, (ISushiModel, int)> ShopShoshi
|
||||
public Dictionary<int, (ISushiModel, int)> ShopSushi
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
@ -26,7 +26,8 @@ namespace SushiBarListImplement.Models
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateCreate = model.DateCreate
|
||||
DateCreate = model.DateCreate,
|
||||
ShopSushi = model.ShopSushi
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel? model)
|
||||
@ -38,13 +39,15 @@ namespace SushiBarListImplement.Models
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateCreate = model.DateCreate;
|
||||
ShopSushi = model.ShopSushi;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
DateCreate = DateCreate
|
||||
DateCreate = DateCreate,
|
||||
ShopSushi = ShopSushi
|
||||
};
|
||||
}
|
||||
}
|
||||
|
14
SushiBar/SushiBarListImplement/SushiBarListImplement.csproj
Normal file
14
SushiBar/SushiBarListImplement/SushiBarListImplement.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user