diff --git a/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs b/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs
new file mode 100644
index 0000000..4d1d77a
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponent - Копировать.Designer.cs
@@ -0,0 +1,118 @@
+namespace Pizzeria
+{
+ partial class FormComponent
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ labelName = new Label();
+ labelPrice = new Label();
+ textBoxName = new TextBox();
+ textBoxCost = new TextBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ SuspendLayout();
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(12, 21);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(62, 15);
+ labelName.TabIndex = 0;
+ labelName.Text = "Название:";
+ //
+ // labelPrice
+ //
+ labelPrice.AutoSize = true;
+ labelPrice.Location = new Point(12, 50);
+ labelPrice.Name = "labelPrice";
+ labelPrice.Size = new Size(38, 15);
+ labelPrice.TabIndex = 1;
+ labelPrice.Text = "Цена:";
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(100, 18);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(233, 23);
+ textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ textBoxCost.Location = new Point(100, 47);
+ textBoxCost.Name = "textBoxCost";
+ textBoxCost.Size = new Size(233, 23);
+ textBoxCost.TabIndex = 2;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(177, 93);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 3;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(258, 93);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 3;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // FormComponent
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(345, 136);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxCost);
+ Controls.Add(textBoxName);
+ Controls.Add(labelPrice);
+ Controls.Add(labelName);
+ Name = "FormComponent";
+ Text = "Компонент";
+ Load += FormComponent_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelPrice;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormComponent - Копировать.resx b/Pizzeria/Pizzeria/FormComponent - Копировать.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponent - Копировать.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormComponent.Designer.cs b/Pizzeria/Pizzeria/FormComponent.Designer.cs
new file mode 100644
index 0000000..4d1d77a
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponent.Designer.cs
@@ -0,0 +1,118 @@
+namespace Pizzeria
+{
+ partial class FormComponent
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ labelName = new Label();
+ labelPrice = new Label();
+ textBoxName = new TextBox();
+ textBoxCost = new TextBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ SuspendLayout();
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(12, 21);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(62, 15);
+ labelName.TabIndex = 0;
+ labelName.Text = "Название:";
+ //
+ // labelPrice
+ //
+ labelPrice.AutoSize = true;
+ labelPrice.Location = new Point(12, 50);
+ labelPrice.Name = "labelPrice";
+ labelPrice.Size = new Size(38, 15);
+ labelPrice.TabIndex = 1;
+ labelPrice.Text = "Цена:";
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(100, 18);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(233, 23);
+ textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ textBoxCost.Location = new Point(100, 47);
+ textBoxCost.Name = "textBoxCost";
+ textBoxCost.Size = new Size(233, 23);
+ textBoxCost.TabIndex = 2;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(177, 93);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 3;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(258, 93);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 3;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // FormComponent
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(345, 136);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxCost);
+ Controls.Add(textBoxName);
+ Controls.Add(labelPrice);
+ Controls.Add(labelName);
+ Name = "FormComponent";
+ Text = "Компонент";
+ Load += FormComponent_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelPrice;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormComponent.cs b/Pizzeria/Pizzeria/FormComponent.cs
new file mode 100644
index 0000000..1f694de
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponent.cs
@@ -0,0 +1,95 @@
+using Microsoft.Extensions.Logging;
+using PizzeriaContracts.BindingModels;
+using PizzeriaContracts.BusinessLogicsContracts;
+using PizzeriaContracts.SearchModels;
+
+
+namespace Pizzeria
+{
+ 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 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();
+ }
+
+ }
+}
diff --git a/Pizzeria/Pizzeria/FormComponent.resx b/Pizzeria/Pizzeria/FormComponent.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Pizzeria/Pizzeria/FormComponent.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs
index 0117f39..dcc698e 100644
--- a/Pizzeria/Pizzeria/FormComponents.Designer.cs
+++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs
@@ -50,7 +50,6 @@
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(628, 450);
dataGridView.TabIndex = 0;
- dataGridView.CellContentClick += dataGridView_CellContentClick;
//
// ButtonAdd
//
diff --git a/Pizzeria/Pizzeria/FormComponents.cs b/Pizzeria/Pizzeria/FormComponents.cs
index 07c29bc..6684db0 100644
--- a/Pizzeria/Pizzeria/FormComponents.cs
+++ b/Pizzeria/Pizzeria/FormComponents.cs
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Logging;
+using PizzeriaContracts.BindingModels;
using PizzeriaContracts.BusinessLogicsContracts;
namespace Pizzeria
@@ -39,10 +40,6 @@ namespace Pizzeria
}
}
- private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
-
- }
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
@@ -54,20 +51,61 @@ namespace Pizzeria
}
}
+
}
private void ButtonRef_Click(object sender, EventArgs e)
{
-
+ 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 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();
+ }
+ }
+ }
}
}
}
diff --git a/Pizzeria/Pizzeria/Pizzeria.csproj b/Pizzeria/Pizzeria/Pizzeria.csproj
index b57c89e..2da550f 100644
--- a/Pizzeria/Pizzeria/Pizzeria.csproj
+++ b/Pizzeria/Pizzeria/Pizzeria.csproj
@@ -8,4 +8,27 @@
enable
+
+
+
+
+
+
+ Always
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs
index 88a8498..7ca1d01 100644
--- a/Pizzeria/Pizzeria/Program.cs
+++ b/Pizzeria/Pizzeria/Program.cs
@@ -3,6 +3,10 @@ using PizzeriaContracts.BusinessLogicsContracts;
using PizzeriaContracts.StorageContracts;
using System.Drawing;
using System;
+using PizzeriaListImplement.Implements;
+using PizzeriaBusinessLogic.BusinessLogic;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
namespace Pizzeria
{
diff --git a/Pizzeria/Pizzeria/nlog.config b/Pizzeria/Pizzeria/nlog.config
new file mode 100644
index 0000000..85797a7
--- /dev/null
+++ b/Pizzeria/Pizzeria/nlog.config
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file