diff --git a/Confectionery/ConfectioneryView/ConfectioneryView.csproj b/Confectionery/ConfectioneryView/ConfectioneryView.csproj
index b57c89e..b773ed7 100644
--- a/Confectionery/ConfectioneryView/ConfectioneryView.csproj
+++ b/Confectionery/ConfectioneryView/ConfectioneryView.csproj
@@ -8,4 +8,27 @@
enable
+
+
+
+
+
+
+ Always
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/Form1.Designer.cs b/Confectionery/ConfectioneryView/Form1.Designer.cs
deleted file mode 100644
index dc04dbe..0000000
--- a/Confectionery/ConfectioneryView/Form1.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace ConfectioneryView
-{
- partial class Form1
- {
- ///
- /// 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()
- {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
- }
-
- #endregion
- }
-}
diff --git a/Confectionery/ConfectioneryView/Form1.cs b/Confectionery/ConfectioneryView/Form1.cs
deleted file mode 100644
index c9838ec..0000000
--- a/Confectionery/ConfectioneryView/Form1.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace ConfectioneryView
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
diff --git a/Confectionery/ConfectioneryView/FormComponent.Designer.cs b/Confectionery/ConfectioneryView/FormComponent.Designer.cs
new file mode 100644
index 0000000..360eb91
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormComponent.Designer.cs
@@ -0,0 +1,117 @@
+namespace ConfectioneryView
+{
+ 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();
+ labelCost = new Label();
+ textBoxName = new TextBox();
+ textBoxCost = new TextBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ SuspendLayout();
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(23, 29);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(84, 20);
+ labelName.TabIndex = 0;
+ labelName.Text = "Название: ";
+ //
+ // labelCost
+ //
+ labelCost.AutoSize = true;
+ labelCost.Location = new Point(23, 94);
+ labelCost.Name = "labelCost";
+ labelCost.Size = new Size(52, 20);
+ labelCost.TabIndex = 1;
+ labelCost.Text = "Цена: ";
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(125, 26);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(256, 27);
+ textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ textBoxCost.Location = new Point(125, 91);
+ textBoxCost.Name = "textBoxCost";
+ textBoxCost.Size = new Size(256, 27);
+ textBoxCost.TabIndex = 3;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(170, 143);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(94, 29);
+ buttonSave.TabIndex = 4;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(287, 143);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(94, 29);
+ buttonCancel.TabIndex = 5;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // FormComponent
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(407, 186);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxCost);
+ Controls.Add(textBoxName);
+ Controls.Add(labelCost);
+ Controls.Add(labelName);
+ Name = "FormComponent";
+ Text = "Компонент";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelCost;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormComponent.cs b/Confectionery/ConfectioneryView/FormComponent.cs
new file mode 100644
index 0000000..42d52d3
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormComponent.cs
@@ -0,0 +1,98 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+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 ConfectioneryView
+{
+ 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/Confectionery/ConfectioneryView/FormComponent.resx b/Confectionery/ConfectioneryView/FormComponent.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/ConfectioneryView/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/Confectionery/ConfectioneryView/FormComponents.Designer.cs b/Confectionery/ConfectioneryView/FormComponents.Designer.cs
index 0f504bf..aacb97d 100644
--- a/Confectionery/ConfectioneryView/FormComponents.Designer.cs
+++ b/Confectionery/ConfectioneryView/FormComponents.Designer.cs
@@ -1,4 +1,5 @@
-namespace ConfectioneryView
+
+namespace ConfectioneryView
{
partial class FormComponents
{
@@ -28,12 +29,104 @@
///
private void InitializeComponent()
{
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "FormComponents";
+ buttonAdd = new Button();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonRefresh = new Button();
+ dataGridView = new DataGridView();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // buttonAdd
+ //
+ buttonAdd.BackColor = SystemColors.Menu;
+ buttonAdd.Location = new Point(622, 49);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(157, 29);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = false;
+ buttonAdd.Click += buttonAdd_Click;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.BackColor = SystemColors.Menu;
+ buttonUpdate.Location = new Point(622, 135);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(157, 29);
+ buttonUpdate.TabIndex = 1;
+ buttonUpdate.Text = "Изменить";
+ buttonUpdate.UseVisualStyleBackColor = false;
+ buttonUpdate.Click += buttonUpdate_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.BackColor = SystemColors.Menu;
+ buttonDelete.Location = new Point(622, 219);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(157, 29);
+ buttonDelete.TabIndex = 2;
+ buttonDelete.Text = "Удалить";
+ buttonDelete.UseVisualStyleBackColor = false;
+ buttonDelete.Click += buttonDelete_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.BackColor = SystemColors.Menu;
+ buttonRefresh.Location = new Point(622, 303);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(157, 29);
+ buttonRefresh.TabIndex = 3;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = false;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.BackgroundColor = SystemColors.ButtonHighlight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Dock = DockStyle.Left;
+ dataGridView.Location = new Point(0, 0);
+ dataGridView.MultiSelect = false;
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(585, 450);
+ dataGridView.TabIndex = 4;
+ //
+ // FormComponents
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ BackColor = SystemColors.Control;
+ ClientSize = new Size(800, 450);
+ Controls.Add(dataGridView);
+ Controls.Add(buttonRefresh);
+ Controls.Add(buttonDelete);
+ Controls.Add(buttonUpdate);
+ Controls.Add(buttonAdd);
+ Name = "FormComponents";
+ Text = "Компоненты";
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
+ {
+ throw new NotImplementedException();
}
#endregion
+
+ private Button buttonAdd;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonRefresh;
+ private DataGridView dataGridView;
}
}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormComponents.cs b/Confectionery/ConfectioneryView/FormComponents.cs
index a605ae5..7850141 100644
--- a/Confectionery/ConfectioneryView/FormComponents.cs
+++ b/Confectionery/ConfectioneryView/FormComponents.cs
@@ -1,4 +1,7 @@
-using System;
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -12,9 +15,106 @@ namespace ConfectioneryView
{
public partial class FormComponents : Form
{
- public FormComponents()
+ private readonly ILogger _logger;
+ private readonly IComponentLogic _logic;
+ public FormComponents(ILogger 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 buttonUpdate_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 buttonDelete_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 buttonRefresh_Click(object sender, EventArgs e)
+ {
+ LoadData();
}
}
}
diff --git a/Confectionery/ConfectioneryView/FormComponents.resx b/Confectionery/ConfectioneryView/FormComponents.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormComponents.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/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..c0bb1b5
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormCreateOrder.Designer.cs
@@ -0,0 +1,146 @@
+namespace ConfectioneryView
+{
+ partial class FormCreateOrder
+ {
+ ///
+ /// 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()
+ {
+ labelPastry = new Label();
+ labelAmount = new Label();
+ labelSum = new Label();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ comboBoxPastry = new ComboBox();
+ textBoxAmount = new TextBox();
+ textBoxSum = new TextBox();
+ SuspendLayout();
+ //
+ // labelPastry
+ //
+ labelPastry.AutoSize = true;
+ labelPastry.Location = new Point(23, 31);
+ labelPastry.Name = "labelPastry";
+ labelPastry.Size = new Size(64, 20);
+ labelPastry.TabIndex = 0;
+ labelPastry.Text = "Десерт: ";
+ //
+ // labelAmount
+ //
+ labelAmount.AutoSize = true;
+ labelAmount.Location = new Point(23, 72);
+ labelAmount.Name = "labelAmount";
+ labelAmount.Size = new Size(93, 20);
+ labelAmount.TabIndex = 1;
+ labelAmount.Text = "Количество:";
+ //
+ // labelSum
+ //
+ labelSum.AutoSize = true;
+ labelSum.Location = new Point(23, 110);
+ labelSum.Name = "labelSum";
+ labelSum.Size = new Size(58, 20);
+ labelSum.TabIndex = 2;
+ labelSum.Text = "Сумма:";
+ //
+ // buttonSave
+ //
+ buttonSave.BackColor = SystemColors.ControlLightLight;
+ buttonSave.Location = new Point(223, 156);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(94, 29);
+ buttonSave.TabIndex = 3;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = false;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.BackColor = SystemColors.ControlLightLight;
+ buttonCancel.Location = new Point(335, 156);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(94, 29);
+ buttonCancel.TabIndex = 4;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = false;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // comboBoxPastry
+ //
+ comboBoxPastry.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxPastry.FormattingEnabled = true;
+ comboBoxPastry.Location = new Point(137, 28);
+ comboBoxPastry.Name = "comboBoxPastry";
+ comboBoxPastry.Size = new Size(292, 28);
+ comboBoxPastry.TabIndex = 1;
+ comboBoxPastry.SelectedIndexChanged += comboBoxPastry_SelectedIndexChanged;
+ //
+ // textBoxAmount
+ //
+ textBoxAmount.Location = new Point(137, 69);
+ textBoxAmount.Name = "textBoxAmount";
+ textBoxAmount.Size = new Size(292, 27);
+ textBoxAmount.TabIndex = 6;
+ textBoxAmount.TextChanged += textBoxCount_TextChanged;
+ //
+ // textBoxSum
+ //
+ textBoxSum.Location = new Point(137, 107);
+ textBoxSum.Name = "textBoxSum";
+ textBoxSum.ReadOnly = true;
+ textBoxSum.Size = new Size(292, 27);
+ textBoxSum.TabIndex = 5;
+ //
+ // FormCreateOrder
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(457, 195);
+ Controls.Add(textBoxSum);
+ Controls.Add(textBoxAmount);
+ Controls.Add(comboBoxPastry);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(labelSum);
+ Controls.Add(labelAmount);
+ Controls.Add(labelPastry);
+ Name = "FormCreateOrder";
+ Text = "Создание заказа";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelPastry;
+ private Label labelAmount;
+ private Label labelSum;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private ComboBox comboBoxPastry;
+ private TextBox textBoxAmount;
+ private TextBox textBoxSum;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.cs b/Confectionery/ConfectioneryView/FormCreateOrder.cs
new file mode 100644
index 0000000..c4d9078
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormCreateOrder.cs
@@ -0,0 +1,129 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryDataModels.Models;
+using Microsoft.Extensions.Logging;
+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 ConfectioneryView
+{
+ public partial class FormCreateOrder : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IPastryLogic _logicP;
+
+ private readonly IOrderLogic _logicO;
+
+ public FormCreateOrder(ILogger logger, IPastryLogic logicP, IOrderLogic logicO)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicP = logicP;
+ _logicO = logicO;
+ }
+
+ private void FormCreateOrder_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка изделий для заказа");
+ try
+ {
+ var pastryList = _logicP.ReadList(null);
+ if (pastryList != null)
+ {
+ comboBoxPastry.DisplayMember = "PastryName";
+ comboBoxPastry.ValueMember = "Id";
+ comboBoxPastry.DataSource = pastryList;
+ comboBoxPastry.SelectedItem = null;
+
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки десерта");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ }
+
+ private void CalcSum()
+ {
+ if (comboBoxPastry.SelectedValue != null && !string.IsNullOrEmpty(textBoxAmount.Text))
+ {
+ try
+ {
+ int id = Convert.ToInt32(comboBoxPastry.SelectedValue);
+ var product = _logicP.ReadElement(new PastrySearchModel { Id = id });
+ int count = Convert.ToInt32(textBoxAmount.Text);
+ textBoxSum.Text = Math.Round(count * (product?.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 comboBoxPastry_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ CalcSum();
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxAmount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxPastry.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Создание заказа");
+ try
+ {
+ var operationResult = _logicO.CreateOrder(new OrderBindingModel
+ {
+ PastryId = Convert.ToInt32(comboBoxPastry.SelectedValue),
+ Count = Convert.ToInt32(textBoxAmount.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();
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryView/FormCreateOrder.resx b/Confectionery/ConfectioneryView/FormCreateOrder.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormCreateOrder.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/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs
new file mode 100644
index 0000000..2e0c0e7
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs
@@ -0,0 +1,173 @@
+namespace ConfectioneryView
+{
+ partial class FormMain
+ {
+ ///
+ /// 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()
+ {
+ menuStrip1 = new MenuStrip();
+ GuideToolStripMenuItem = new ToolStripMenuItem();
+ ComponentToolStripMenuItem = new ToolStripMenuItem();
+ PastryToolStripMenuItem = new ToolStripMenuItem();
+ dataGridView = new DataGridView();
+ buttonCreateOrder = new Button();
+ buttonTakeOrderInWork = new Button();
+ buttonOrderReady = new Button();
+ buttonOrderIssued = new Button();
+ buttonRefresh = new Button();
+ menuStrip1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // menuStrip1
+ //
+ menuStrip1.ImageScalingSize = new Size(20, 20);
+ menuStrip1.Items.AddRange(new ToolStripItem[] { GuideToolStripMenuItem });
+ menuStrip1.Location = new Point(0, 0);
+ menuStrip1.Name = "menuStrip1";
+ menuStrip1.Size = new Size(1177, 28);
+ menuStrip1.TabIndex = 0;
+ menuStrip1.Text = "menuStrip1";
+ //
+ // GuideToolStripMenuItem
+ //
+ GuideToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentToolStripMenuItem, PastryToolStripMenuItem });
+ GuideToolStripMenuItem.Name = "GuideToolStripMenuItem";
+ GuideToolStripMenuItem.Size = new Size(117, 24);
+ GuideToolStripMenuItem.Text = "Справочники";
+ //
+ // ComponentToolStripMenuItem
+ //
+ ComponentToolStripMenuItem.Name = "ComponentToolStripMenuItem";
+ ComponentToolStripMenuItem.Size = new Size(224, 26);
+ ComponentToolStripMenuItem.Text = "Компоненты";
+ ComponentToolStripMenuItem.Click += ComponentToolStripMenuItem_Click;
+ //
+ // PastryToolStripMenuItem
+ //
+ PastryToolStripMenuItem.Name = "PastryToolStripMenuItem";
+ PastryToolStripMenuItem.Size = new Size(224, 26);
+ PastryToolStripMenuItem.Text = "Изделия";
+ PastryToolStripMenuItem.Click += PastryToolStripMenuItem_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.BackgroundColor = SystemColors.ControlLightLight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(0, 31);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(920, 422);
+ dataGridView.TabIndex = 1;
+ //
+ // buttonCreateOrder
+ //
+ buttonCreateOrder.Location = new Point(954, 62);
+ buttonCreateOrder.Name = "buttonCreateOrder";
+ buttonCreateOrder.Size = new Size(196, 29);
+ buttonCreateOrder.TabIndex = 2;
+ buttonCreateOrder.Text = "Создать заказ";
+ buttonCreateOrder.UseVisualStyleBackColor = true;
+ buttonCreateOrder.Click += buttonCreateOrder_Click;
+ //
+ // buttonTakeOrderInWork
+ //
+ buttonTakeOrderInWork.Location = new Point(954, 143);
+ buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
+ buttonTakeOrderInWork.Size = new Size(196, 29);
+ buttonTakeOrderInWork.TabIndex = 3;
+ buttonTakeOrderInWork.Text = "Отдать на выполнение";
+ buttonTakeOrderInWork.UseVisualStyleBackColor = true;
+ buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click;
+ //
+ // buttonOrderReady
+ //
+ buttonOrderReady.Location = new Point(954, 220);
+ buttonOrderReady.Name = "buttonOrderReady";
+ buttonOrderReady.Size = new Size(196, 29);
+ buttonOrderReady.TabIndex = 4;
+ buttonOrderReady.Text = "Заказ готов";
+ buttonOrderReady.UseVisualStyleBackColor = true;
+ buttonOrderReady.Click += buttonOrderReady_Click;
+ //
+ // buttonOrderIssued
+ //
+ buttonOrderIssued.Location = new Point(954, 298);
+ buttonOrderIssued.Name = "buttonOrderIssued";
+ buttonOrderIssued.Size = new Size(196, 29);
+ buttonOrderIssued.TabIndex = 5;
+ buttonOrderIssued.Text = "Заказ выдан";
+ buttonOrderIssued.UseVisualStyleBackColor = true;
+ buttonOrderIssued.Click += buttonOrderIssued_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(954, 373);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(196, 29);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить список";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // FormMain
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1177, 450);
+ Controls.Add(buttonRefresh);
+ Controls.Add(buttonOrderIssued);
+ Controls.Add(buttonOrderReady);
+ Controls.Add(buttonTakeOrderInWork);
+ Controls.Add(buttonCreateOrder);
+ Controls.Add(dataGridView);
+ Controls.Add(menuStrip1);
+ MainMenuStrip = menuStrip1;
+ Name = "FormMain";
+ Text = "Кондитерский магазин";
+ menuStrip1.ResumeLayout(false);
+ menuStrip1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private MenuStrip menuStrip1;
+ private ToolStripMenuItem GuideToolStripMenuItem;
+ private ToolStripMenuItem ComponentToolStripMenuItem;
+ private ToolStripMenuItem PastryToolStripMenuItem;
+ private DataGridView dataGridView;
+ private Button buttonCreateOrder;
+ private Button buttonTakeOrderInWork;
+ private Button buttonOrderReady;
+ private Button buttonOrderIssued;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs
new file mode 100644
index 0000000..e5810a0
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormMain.cs
@@ -0,0 +1,159 @@
+using ConfectioneryBusinessLogic.BusinessLogics;
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+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 ConfectioneryView
+{
+ public partial class FormMain : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IOrderLogic _orderLogic;
+
+ public FormMain(ILogger logger, IOrderLogic orderLogic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _orderLogic = orderLogic;
+ }
+
+ private void FormMain_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка заказов");
+ try
+ {
+ var list = _orderLogic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["PastryID"].Visible = false;
+ dataGridView.Columns["PastryName"].AutoSizeMode=DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Заказы загружаются");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ComponentToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
+ if (service is FormComponents form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void PastryToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPastries));
+ if (service is FormPastries 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 buttonOrderIssued_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 buttonRefresh_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryView/FormMain.resx b/Confectionery/ConfectioneryView/FormMain.resx
new file mode 100644
index 0000000..a0623c8
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormMain.resx
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ 17, 17
+
+
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormPastries.Designer.cs b/Confectionery/ConfectioneryView/FormPastries.Designer.cs
new file mode 100644
index 0000000..139208b
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastries.Designer.cs
@@ -0,0 +1,114 @@
+namespace ConfectioneryView
+{
+ partial class FormPastries
+ {
+ ///
+ /// 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()
+ {
+ dataGridView = new DataGridView();
+ buttonAdd = new Button();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonRefresh = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.BackgroundColor = SystemColors.ControlLightLight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(-1, 0);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(440, 399);
+ dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Location = new Point(462, 62);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(172, 29);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += buttonAdd_Click;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.Location = new Point(462, 148);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(172, 29);
+ buttonUpdate.TabIndex = 2;
+ buttonUpdate.Text = "Изменить";
+ buttonUpdate.UseVisualStyleBackColor = true;
+ buttonUpdate.Click += buttonUpdate_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.Location = new Point(462, 230);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(172, 29);
+ buttonDelete.TabIndex = 3;
+ buttonDelete.Text = "Удалить";
+ buttonDelete.UseVisualStyleBackColor = true;
+ buttonDelete.Click += buttonDelete_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(462, 314);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(172, 29);
+ buttonRefresh.TabIndex = 4;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // FormPastries
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(663, 397);
+ Controls.Add(buttonRefresh);
+ Controls.Add(buttonDelete);
+ Controls.Add(buttonUpdate);
+ Controls.Add(buttonAdd);
+ Controls.Add(dataGridView);
+ Name = "FormPastries";
+ Text = "Кондитерские изделия";
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormPastries.cs b/Confectionery/ConfectioneryView/FormPastries.cs
new file mode 100644
index 0000000..0ad0e24
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastries.cs
@@ -0,0 +1,112 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+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 ConfectioneryView
+{
+ public partial class FormPastries : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IPastryLogic _logic;
+ public FormPastries(ILogger logger, IPastryLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormPastries_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["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["PastryComponents"].Visible = false;
+ }
+ _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(FormPastry));
+ if (service is FormPastry form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonUpdate_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
+ if (service is FormPastry form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void buttonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление изделия");
+ try
+ {
+ if (!_logic.Delete(new PastryBindingModel { Id = id }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void buttonRefresh_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryView/FormPastries.resx b/Confectionery/ConfectioneryView/FormPastries.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastries.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/Confectionery/ConfectioneryView/FormPastry.Designer.cs b/Confectionery/ConfectioneryView/FormPastry.Designer.cs
new file mode 100644
index 0000000..d392dcf
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastry.Designer.cs
@@ -0,0 +1,246 @@
+namespace ConfectioneryView
+{
+ partial class FormPastry
+ {
+ ///
+ /// 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();
+ labelCost = new Label();
+ textBoxName = new TextBox();
+ textBoxCost = new TextBox();
+ groupBoxComponents = new GroupBox();
+ buttonRefresh = new Button();
+ buttonDelete = new Button();
+ buttonUpload = new Button();
+ buttonAdd = new Button();
+ dataGridView = new DataGridView();
+ ColumnId = new DataGridViewTextBoxColumn();
+ ColumnComponent = new DataGridViewTextBoxColumn();
+ ColumnCount = new DataGridViewTextBoxColumn();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ groupBoxComponents.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(17, 22);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(84, 20);
+ labelName.TabIndex = 0;
+ labelName.Text = "Название: ";
+ //
+ // labelCost
+ //
+ labelCost.AutoSize = true;
+ labelCost.Location = new Point(17, 67);
+ labelCost.Name = "labelCost";
+ labelCost.Size = new Size(86, 20);
+ labelCost.TabIndex = 1;
+ labelCost.Text = "Стоимость:";
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(129, 19);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(350, 27);
+ textBoxName.TabIndex = 2;
+ //
+ // textBoxCost
+ //
+ textBoxCost.Enabled = false;
+ textBoxCost.Location = new Point(129, 64);
+ textBoxCost.Name = "textBoxCost";
+ textBoxCost.Size = new Size(179, 27);
+ textBoxCost.TabIndex = 3;
+ //
+ // groupBoxComponents
+ //
+ groupBoxComponents.Controls.Add(buttonRefresh);
+ groupBoxComponents.Controls.Add(buttonDelete);
+ groupBoxComponents.Controls.Add(buttonUpload);
+ groupBoxComponents.Controls.Add(buttonAdd);
+ groupBoxComponents.Controls.Add(dataGridView);
+ groupBoxComponents.Location = new Point(19, 104);
+ groupBoxComponents.Name = "groupBoxComponents";
+ groupBoxComponents.Size = new Size(760, 364);
+ groupBoxComponents.TabIndex = 4;
+ groupBoxComponents.TabStop = false;
+ groupBoxComponents.Text = "Компоненты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.BackColor = SystemColors.ControlLightLight;
+ buttonRefresh.Location = new Point(608, 257);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(135, 29);
+ buttonRefresh.TabIndex = 4;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = false;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.BackColor = SystemColors.ControlLightLight;
+ buttonDelete.Location = new Point(608, 185);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(135, 29);
+ buttonDelete.TabIndex = 3;
+ buttonDelete.Text = "Удалить";
+ buttonDelete.UseVisualStyleBackColor = false;
+ buttonDelete.Click += buttonDelete_Click;
+ //
+ // buttonUpload
+ //
+ buttonUpload.BackColor = SystemColors.ControlLightLight;
+ buttonUpload.Location = new Point(608, 113);
+ buttonUpload.Name = "buttonUpload";
+ buttonUpload.Size = new Size(135, 29);
+ buttonUpload.TabIndex = 2;
+ buttonUpload.Text = "Изменить";
+ buttonUpload.UseVisualStyleBackColor = false;
+ buttonUpload.Click += buttonUpload_Click;
+ //
+ // buttonAdd
+ //
+ buttonAdd.BackColor = SystemColors.ControlLightLight;
+ buttonAdd.Location = new Point(608, 48);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(135, 29);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = false;
+ buttonAdd.Click += buttonAdd_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.AllowUserToDeleteRows = false;
+ dataGridView.BackgroundColor = SystemColors.ControlLightLight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnComponent, ColumnCount });
+ dataGridView.Dock = DockStyle.Left;
+ dataGridView.Location = new Point(3, 23);
+ dataGridView.Margin = new Padding(5, 4, 5, 4);
+ dataGridView.MultiSelect = false;
+ dataGridView.Name = "dataGridView";
+ dataGridView.ReadOnly = true;
+ dataGridView.RowHeadersVisible = false;
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridView.Size = new Size(579, 338);
+ dataGridView.TabIndex = 0;
+ //
+ // ColumnId
+ //
+ ColumnId.HeaderText = "Id";
+ ColumnId.MinimumWidth = 6;
+ ColumnId.Name = "ColumnId";
+ ColumnId.ReadOnly = true;
+ ColumnId.Visible = false;
+ ColumnId.Width = 125;
+ //
+ // ColumnComponent
+ //
+ ColumnComponent.HeaderText = "Компонент";
+ ColumnComponent.MinimumWidth = 6;
+ ColumnComponent.Name = "ColumnComponent";
+ ColumnComponent.ReadOnly = true;
+ ColumnComponent.Width = 400;
+ //
+ // ColumnCount
+ //
+ ColumnCount.HeaderText = "Количество";
+ ColumnCount.MinimumWidth = 6;
+ ColumnCount.Name = "ColumnCount";
+ ColumnCount.ReadOnly = true;
+ ColumnCount.Width = 175;
+ //
+ // buttonSave
+ //
+ buttonSave.BackColor = SystemColors.ControlLightLight;
+ buttonSave.Location = new Point(554, 480);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(94, 29);
+ buttonSave.TabIndex = 5;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = false;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.BackColor = SystemColors.ControlLightLight;
+ buttonCancel.Location = new Point(685, 480);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(94, 29);
+ buttonCancel.TabIndex = 6;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = false;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // FormPastry
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 521);
+ Controls.Add(buttonSave);
+ Controls.Add(buttonCancel);
+ Controls.Add(groupBoxComponents);
+ Controls.Add(textBoxCost);
+ Controls.Add(textBoxName);
+ Controls.Add(labelCost);
+ Controls.Add(labelName);
+ Name = "FormPastry";
+ Text = "Кондитерское изделие";
+ groupBoxComponents.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelCost;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ private GroupBox groupBoxComponents;
+ private DataGridView dataGridView;
+ private Button buttonRefresh;
+ private Button buttonDelete;
+ private Button buttonUpload;
+ private Button buttonAdd;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private DataGridViewTextBoxColumn ColumnId;
+ private DataGridViewTextBoxColumn ColumnComponent;
+ private DataGridViewTextBoxColumn ColumnCount;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormPastry.cs b/Confectionery/ConfectioneryView/FormPastry.cs
new file mode 100644
index 0000000..6b457b3
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastry.cs
@@ -0,0 +1,217 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryDataModels.Models;
+using Microsoft.Extensions.Logging;
+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 ConfectioneryView
+{
+ public partial class FormPastry : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IPastryLogic _logic;
+
+ private int? _id;
+
+ private Dictionary _productComponents;
+
+ public int Id { set { _id = value; } }
+
+ public FormPastry(ILogger logger, IPastryLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _productComponents = new Dictionary();
+ }
+
+ private void FormProduct_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка изделия");
+ try
+ {
+ var view = _logic.ReadElement(new PastrySearchModel { Id = _id.Value });
+ if (view != null)
+ {
+ textBoxName.Text = view.PastryName;
+ textBoxCost.Text = view.Price.ToString();
+ _productComponents = view.PastryComponents ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка компонент изделия");
+ try
+ {
+ if (_productComponents != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _productComponents)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 });
+ }
+ textBoxCost.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(FormPastryComponent));
+ if (service is FormPastryComponent form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
+ if (_productComponents.ContainsKey(form.Id))
+ {
+ _productComponents[form.Id] = (form.ComponentModel, form.Count);
+ }
+ else
+ {
+ _productComponents.Add(form.Id, (form.ComponentModel, form.Count));
+ }
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonUpload_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPastryComponent));
+ if (service is FormPastryComponent form)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _productComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count);
+ _productComponents[form.Id] = (form.ComponentModel, form.Count);
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void buttonDelete_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);
+ _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonRefresh_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(textBoxCost.Text))
+ {
+ MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (_productComponents == null || _productComponents.Count == 0)
+ {
+ MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение изделия");
+ try
+ {
+ var model = new PastryBindingModel
+ {
+ Id = _id ?? 0,
+ PastryName = textBoxName.Text,
+ Price = Convert.ToDouble(textBoxCost.Text),
+ PastryComponents = _productComponents
+ };
+ 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 _productComponents)
+ {
+ price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
+ }
+ return Math.Round(price * 1.1, 2);
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryView/FormPastry.resx b/Confectionery/ConfectioneryView/FormPastry.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastry.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/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs b/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs
new file mode 100644
index 0000000..4e26d73
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastryComponent.Designer.cs
@@ -0,0 +1,119 @@
+namespace ConfectioneryView
+{
+ partial class FormPastryComponent
+ {
+ ///
+ /// 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()
+ {
+ labelComponent = new Label();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ labelAnount = new Label();
+ comboBoxComponent = new ComboBox();
+ textBoxAmount = new TextBox();
+ SuspendLayout();
+ //
+ // labelComponent
+ //
+ labelComponent.AutoSize = true;
+ labelComponent.Location = new Point(28, 30);
+ labelComponent.Name = "labelComponent";
+ labelComponent.Size = new Size(95, 20);
+ labelComponent.TabIndex = 0;
+ labelComponent.Text = "Компонент: ";
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(231, 128);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(94, 29);
+ buttonSave.TabIndex = 1;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(346, 128);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(94, 29);
+ buttonCancel.TabIndex = 2;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // labelAnount
+ //
+ labelAnount.AutoSize = true;
+ labelAnount.Location = new Point(28, 81);
+ labelAnount.Name = "labelAnount";
+ labelAnount.Size = new Size(97, 20);
+ labelAnount.TabIndex = 3;
+ labelAnount.Text = "Количество: ";
+ //
+ // comboBoxComponent
+ //
+ comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxComponent.FormattingEnabled = true;
+ comboBoxComponent.Location = new Point(130, 27);
+ comboBoxComponent.Name = "comboBoxComponent";
+ comboBoxComponent.Size = new Size(310, 28);
+ comboBoxComponent.TabIndex = 4;
+ //
+ // textBoxAmount
+ //
+ textBoxAmount.Location = new Point(130, 78);
+ textBoxAmount.Name = "textBoxAmount";
+ textBoxAmount.Size = new Size(310, 27);
+ textBoxAmount.TabIndex = 5;
+ //
+ // FormPastryComponent
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(469, 179);
+ Controls.Add(textBoxAmount);
+ Controls.Add(comboBoxComponent);
+ Controls.Add(labelAnount);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(labelComponent);
+ Name = "FormPastryComponent";
+ Text = "Компонент кондитерского изделия";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelComponent;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private Label labelAnount;
+ private ComboBox comboBoxComponent;
+ private TextBox textBoxAmount;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormPastryComponent.cs b/Confectionery/ConfectioneryView/FormPastryComponent.cs
new file mode 100644
index 0000000..8d3cc48
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastryComponent.cs
@@ -0,0 +1,81 @@
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Models;
+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 ConfectioneryView
+{
+ public partial class FormPastryComponent : Form
+ {
+ private readonly List? _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(textBoxAmount.Text); } set { textBoxAmount.Text = value.ToString(); } }
+
+ public FormPastryComponent(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(textBoxAmount.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();
+ }
+
+ }
+}
diff --git a/Confectionery/ConfectioneryView/FormPastryComponent.resx b/Confectionery/ConfectioneryView/FormPastryComponent.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastryComponent.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/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs
index 8b4cd92..a9c2a83 100644
--- a/Confectionery/ConfectioneryView/Program.cs
+++ b/Confectionery/ConfectioneryView/Program.cs
@@ -1,7 +1,18 @@
+using ConfectioneryBusinessLogic.BusinessLogics;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryListImplement.Implements;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+
namespace ConfectioneryView
{
internal static class Program
{
+ private static ServiceProvider? _serviceProvider;
+ public static ServiceProvider? ServiceProvider => _serviceProvider;
+
///
/// The main entry point for the application.
///
@@ -11,7 +22,33 @@ namespace ConfectioneryView
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new Form1());
+ var services = new ServiceCollection();
+ ConfigureServices(services);
+ _serviceProvider = services.BuildServiceProvider();
+ Application.Run(_serviceProvider.GetRequiredService());
+ }
+
+ private static void ConfigureServices(ServiceCollection services)
+ {
+ services.AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddNLog("nlog.config");
+ });
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/nlog.config b/Confectionery/ConfectioneryView/nlog.config
new file mode 100644
index 0000000..85797a7
--- /dev/null
+++ b/Confectionery/ConfectioneryView/nlog.config
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file