diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln
index aca11be..6d15e9a 100644
--- a/Confectionery/Confectionery.sln
+++ b/Confectionery/Confectionery.sln
@@ -3,7 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Confectionery", "Confectionery\Confectionery.csproj", "{E19664A2-BC0D-451E-B9E1-2A5546873A14}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryView", "Confectionery\ConfectioneryView.csproj", "{E19664A2-BC0D-451E-B9E1-2A5546873A14}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{92EBD50D-79CE-46FC-B261-43098E98B78F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{181AF2FE-AE82-4767-B58B-36C0F22B56CD}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{B72CA521-8F72-4F11-9B1F-FC8CA295C6BB}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{5915CA47-6266-42F1-9AC9-A6B3882CE245}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +23,22 @@ Global
{E19664A2-BC0D-451E-B9E1-2A5546873A14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E19664A2-BC0D-451E-B9E1-2A5546873A14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E19664A2-BC0D-451E-B9E1-2A5546873A14}.Release|Any CPU.Build.0 = Release|Any CPU
+ {92EBD50D-79CE-46FC-B261-43098E98B78F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {92EBD50D-79CE-46FC-B261-43098E98B78F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {92EBD50D-79CE-46FC-B261-43098E98B78F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {92EBD50D-79CE-46FC-B261-43098E98B78F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {181AF2FE-AE82-4767-B58B-36C0F22B56CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {181AF2FE-AE82-4767-B58B-36C0F22B56CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {181AF2FE-AE82-4767-B58B-36C0F22B56CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {181AF2FE-AE82-4767-B58B-36C0F22B56CD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B72CA521-8F72-4F11-9B1F-FC8CA295C6BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B72CA521-8F72-4F11-9B1F-FC8CA295C6BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B72CA521-8F72-4F11-9B1F-FC8CA295C6BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B72CA521-8F72-4F11-9B1F-FC8CA295C6BB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {5915CA47-6266-42F1-9AC9-A6B3882CE245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5915CA47-6266-42F1-9AC9-A6B3882CE245}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5915CA47-6266-42F1-9AC9-A6B3882CE245}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5915CA47-6266-42F1-9AC9-A6B3882CE245}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Confectionery/Confectionery/ConfectioneryView.csproj b/Confectionery/Confectionery/ConfectioneryView.csproj
new file mode 100644
index 0000000..96b207b
--- /dev/null
+++ b/Confectionery/Confectionery/ConfectioneryView.csproj
@@ -0,0 +1,21 @@
+
+
+
+ WinExe
+ net8.0-windows
+ enable
+ true
+ enable
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Confectionery/Confectionery/Form1.Designer.cs b/Confectionery/Confectionery/Form1.Designer.cs
deleted file mode 100644
index 8566574..0000000
--- a/Confectionery/Confectionery/Form1.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace Confectionery
-{
- 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/Confectionery/Form1.cs b/Confectionery/Confectionery/Form1.cs
deleted file mode 100644
index aec9b02..0000000
--- a/Confectionery/Confectionery/Form1.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Confectionery
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
diff --git a/Confectionery/Confectionery/FormComponent.Designer.cs b/Confectionery/Confectionery/FormComponent.Designer.cs
new file mode 100644
index 0000000..9694a57
--- /dev/null
+++ b/Confectionery/Confectionery/FormComponent.Designer.cs
@@ -0,0 +1,122 @@
+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();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ textBoxName = new TextBox();
+ textBoxCost = new TextBox();
+ SuspendLayout();
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(16, 21);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(94, 25);
+ labelName.TabIndex = 0;
+ labelName.Text = "Название:";
+ //
+ // labelCost
+ //
+ labelCost.AutoSize = true;
+ labelCost.Location = new Point(16, 66);
+ labelCost.Name = "labelCost";
+ labelCost.Size = new Size(57, 25);
+ labelCost.TabIndex = 1;
+ labelCost.Text = "Цена:";
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Location = new Point(336, 148);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(112, 34);
+ buttonSave.TabIndex = 2;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Location = new Point(454, 148);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(112, 34);
+ buttonCancel.TabIndex = 3;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // textBoxName
+ //
+ textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ textBoxName.Location = new Point(170, 21);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(396, 31);
+ textBoxName.TabIndex = 4;
+ //
+ // textBoxCost
+ //
+ textBoxCost.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ textBoxCost.Location = new Point(170, 66);
+ textBoxCost.Name = "textBoxCost";
+ textBoxCost.Size = new Size(160, 31);
+ textBoxCost.TabIndex = 5;
+ //
+ // FormComponent
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(578, 194);
+ Controls.Add(textBoxCost);
+ Controls.Add(textBoxName);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(labelCost);
+ Controls.Add(labelName);
+ Name = "FormComponent";
+ Text = "Компонент";
+ Load += FormComponent_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelCost;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private TextBox textBoxName;
+ private TextBox textBoxCost;
+ }
+}
diff --git a/Confectionery/Confectionery/FormComponent.cs b/Confectionery/Confectionery/FormComponent.cs
new file mode 100644
index 0000000..52e30c6
--- /dev/null
+++ b/Confectionery/Confectionery/FormComponent.cs
@@ -0,0 +1,87 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+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/Confectionery/Form1.resx b/Confectionery/Confectionery/FormComponent.resx
similarity index 93%
rename from Confectionery/Confectionery/Form1.resx
rename to Confectionery/Confectionery/FormComponent.resx
index 1af7de1..af32865 100644
--- a/Confectionery/Confectionery/Form1.resx
+++ b/Confectionery/Confectionery/FormComponent.resx
@@ -1,17 +1,17 @@
-
diff --git a/Confectionery/Confectionery/FormComponents.Designer.cs b/Confectionery/Confectionery/FormComponents.Designer.cs
new file mode 100644
index 0000000..52508c7
--- /dev/null
+++ b/Confectionery/Confectionery/FormComponents.Designer.cs
@@ -0,0 +1,119 @@
+namespace ConfectioneryView
+{
+ partial class FormComponents
+ {
+ ///
+ /// 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()
+ {
+ buttonAdd = new Button();
+ buttonUpd = new Button();
+ buttonDel = new Button();
+ buttonRef = new Button();
+ dataGridView = new DataGridView();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // buttonAdd
+ //
+ buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonAdd.Location = new Point(754, 12);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(112, 56);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += ButtonAdd_Click;
+ //
+ // buttonUpd
+ //
+ buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonUpd.Location = new Point(754, 74);
+ buttonUpd.Name = "buttonUpd";
+ buttonUpd.Size = new Size(112, 56);
+ buttonUpd.TabIndex = 1;
+ buttonUpd.Text = "Изменить";
+ buttonUpd.UseVisualStyleBackColor = true;
+ buttonUpd.Click += ButtonUpd_Click;
+ //
+ // buttonDel
+ //
+ buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonDel.Location = new Point(754, 198);
+ buttonDel.Name = "buttonDel";
+ buttonDel.Size = new Size(112, 56);
+ buttonDel.TabIndex = 2;
+ buttonDel.Text = "Удалить";
+ buttonDel.UseVisualStyleBackColor = true;
+ buttonDel.Click += ButtonDel_Click;
+ //
+ // buttonRef
+ //
+ buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonRef.Location = new Point(754, 136);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new Size(112, 56);
+ buttonRef.TabIndex = 3;
+ buttonRef.Text = "Обновить";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += ButtonRef_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ dataGridView.BackgroundColor = SystemColors.Window;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(0, 0);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 62;
+ dataGridView.Size = new Size(742, 444);
+ dataGridView.TabIndex = 4;
+ //
+ // FormComponents
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(878, 444);
+ Controls.Add(buttonRef);
+ Controls.Add(buttonDel);
+ Controls.Add(buttonUpd);
+ Controls.Add(buttonAdd);
+ Controls.Add(dataGridView);
+ Name = "FormComponents";
+ Text = "Компоненты";
+ Load += FormComponents_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Button buttonAdd;
+ private Button buttonUpd;
+ private Button buttonDel;
+ private Button buttonRef;
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormComponents.cs b/Confectionery/Confectionery/FormComponents.cs
new file mode 100644
index 0000000..3a363f3
--- /dev/null
+++ b/Confectionery/Confectionery/FormComponents.cs
@@ -0,0 +1,108 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+namespace ConfectioneryView
+{
+ public partial class FormComponents : Form
+ {
+ 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 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();
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormComponents.resx b/Confectionery/Confectionery/FormComponents.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/Confectionery/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/Confectionery/FormCreateOrder.Designer.cs b/Confectionery/Confectionery/FormCreateOrder.Designer.cs
new file mode 100644
index 0000000..377b38d
--- /dev/null
+++ b/Confectionery/Confectionery/FormCreateOrder.Designer.cs
@@ -0,0 +1,150 @@
+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();
+ labelCount = new Label();
+ labelSum = new Label();
+ comboBoxPastry = new ComboBox();
+ textBoxCount = new TextBox();
+ textBoxSum = new TextBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ SuspendLayout();
+ //
+ // labelPastry
+ //
+ labelPastry.AutoSize = true;
+ labelPastry.Location = new Point(16, 21);
+ labelPastry.Name = "labelPastry";
+ labelPastry.Size = new Size(84, 25);
+ labelPastry.TabIndex = 0;
+ labelPastry.Text = "Изделие:";
+ //
+ // labelCount
+ //
+ labelCount.AutoSize = true;
+ labelCount.Location = new Point(16, 66);
+ labelCount.Name = "labelCount";
+ labelCount.Size = new Size(111, 25);
+ labelCount.TabIndex = 1;
+ labelCount.Text = "Количество:";
+ //
+ // labelSum
+ //
+ labelSum.AutoSize = true;
+ labelSum.Location = new Point(16, 112);
+ labelSum.Name = "labelSum";
+ labelSum.Size = new Size(71, 25);
+ labelSum.TabIndex = 2;
+ labelSum.Text = "Сумма:";
+ //
+ // comboBoxPastry
+ //
+ comboBoxPastry.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxPastry.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxPastry.FormattingEnabled = true;
+ comboBoxPastry.Location = new Point(170, 21);
+ comboBoxPastry.Name = "comboBoxPastry";
+ comboBoxPastry.Size = new Size(396, 33);
+ comboBoxPastry.TabIndex = 3;
+ comboBoxPastry.SelectedIndexChanged += ComboBoxPastry_SelectedIndexChanged;
+ //
+ // textBoxCount
+ //
+ textBoxCount.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ textBoxCount.Location = new Point(170, 66);
+ textBoxCount.Name = "textBoxCount";
+ textBoxCount.Size = new Size(396, 31);
+ textBoxCount.TabIndex = 4;
+ textBoxCount.TextChanged += TextBoxCount_TextChanged;
+ //
+ // textBoxSum
+ //
+ textBoxSum.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ textBoxSum.Location = new Point(170, 112);
+ textBoxSum.Name = "textBoxSum";
+ textBoxSum.ReadOnly = true;
+ textBoxSum.Size = new Size(396, 31);
+ textBoxSum.TabIndex = 5;
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Location = new Point(336, 148);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(112, 34);
+ buttonSave.TabIndex = 6;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Location = new Point(454, 148);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(112, 34);
+ buttonCancel.TabIndex = 7;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // FormCreateOrder
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(578, 194);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxSum);
+ Controls.Add(textBoxCount);
+ Controls.Add(comboBoxPastry);
+ Controls.Add(labelSum);
+ Controls.Add(labelCount);
+ Controls.Add(labelPastry);
+ Name = "FormCreateOrder";
+ Text = "Создание заказа";
+ Load += FormCreateOrder_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelPastry;
+ private Label labelCount;
+ private Label labelSum;
+ private ComboBox comboBoxPastry;
+ private TextBox textBoxCount;
+ private TextBox textBoxSum;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormCreateOrder.cs b/Confectionery/Confectionery/FormCreateOrder.cs
new file mode 100644
index 0000000..8170330
--- /dev/null
+++ b/Confectionery/Confectionery/FormCreateOrder.cs
@@ -0,0 +1,122 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using Microsoft.Extensions.Logging;
+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 list = _logicP.ReadList(null);
+ if (list != null)
+ {
+ comboBoxPastry.DisplayMember = "PastryName";
+ comboBoxPastry.ValueMember = "Id";
+ comboBoxPastry.DataSource = list;
+ comboBoxPastry.SelectedItem = null;
+ }
+ _logger.LogInformation("Кондитерское изделие загружено");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки кондитерского изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ private void CalcSum()
+ {
+ if (comboBoxPastry.SelectedValue != null &&
+ !string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ try
+ {
+ int id = Convert.ToInt32(comboBoxPastry.SelectedValue);
+ var pastry = _logicP.ReadElement(new PastrySearchModel
+ {
+ Id = id
+ });
+ int count = Convert.ToInt32(textBoxCount.Text);
+ textBoxSum.Text = Math.Round(count * (pastry?.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(textBoxCount.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(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();
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormCreateOrder.resx b/Confectionery/Confectionery/FormCreateOrder.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/Confectionery/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/Confectionery/FormMain.Designer.cs b/Confectionery/Confectionery/FormMain.Designer.cs
new file mode 100644
index 0000000..f9b4147
--- /dev/null
+++ b/Confectionery/Confectionery/FormMain.Designer.cs
@@ -0,0 +1,179 @@
+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()
+ {
+ dataGridView = new DataGridView();
+ buttonCreateOrder = new Button();
+ buttonTakeOrderInWork = new Button();
+ buttonOrderReady = new Button();
+ buttonIssuedOrder = new Button();
+ buttonRef = new Button();
+ menuStrip = new MenuStrip();
+ referencesToolStripMenuItem = new ToolStripMenuItem();
+ componentsToolStripMenuItem = new ToolStripMenuItem();
+ pastriesToolStripMenuItem = new ToolStripMenuItem();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ menuStrip.SuspendLayout();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ dataGridView.BackgroundColor = SystemColors.Window;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(0, 36);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 62;
+ dataGridView.Size = new Size(1001, 406);
+ dataGridView.TabIndex = 1;
+ //
+ // buttonCreateOrder
+ //
+ buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonCreateOrder.Location = new Point(1016, 36);
+ buttonCreateOrder.Name = "buttonCreateOrder";
+ buttonCreateOrder.Size = new Size(126, 74);
+ buttonCreateOrder.TabIndex = 3;
+ buttonCreateOrder.Text = "Создать заказ";
+ buttonCreateOrder.UseVisualStyleBackColor = true;
+ buttonCreateOrder.Click += ButtonCreateOrder_Click;
+ //
+ // buttonTakeOrderInWork
+ //
+ buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonTakeOrderInWork.Location = new Point(1016, 116);
+ buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
+ buttonTakeOrderInWork.Size = new Size(126, 74);
+ buttonTakeOrderInWork.TabIndex = 4;
+ buttonTakeOrderInWork.Text = "Отдать на выполнение";
+ buttonTakeOrderInWork.UseVisualStyleBackColor = true;
+ buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click;
+ //
+ // buttonOrderReady
+ //
+ buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonOrderReady.Location = new Point(1016, 196);
+ buttonOrderReady.Name = "buttonOrderReady";
+ buttonOrderReady.Size = new Size(126, 74);
+ buttonOrderReady.TabIndex = 5;
+ buttonOrderReady.Text = "Заказ готов";
+ buttonOrderReady.UseVisualStyleBackColor = true;
+ buttonOrderReady.Click += ButtonOrderReady_Click;
+ //
+ // buttonIssuedOrder
+ //
+ buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonIssuedOrder.Location = new Point(1016, 276);
+ buttonIssuedOrder.Name = "buttonIssuedOrder";
+ buttonIssuedOrder.Size = new Size(126, 74);
+ buttonIssuedOrder.TabIndex = 6;
+ buttonIssuedOrder.Text = "Заказ выдан";
+ buttonIssuedOrder.UseVisualStyleBackColor = true;
+ buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
+ //
+ // buttonRef
+ //
+ buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonRef.Location = new Point(1016, 356);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new Size(126, 74);
+ buttonRef.TabIndex = 7;
+ buttonRef.Text = "Обновить список";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += ButtonRef_Click;
+ //
+ // menuStrip
+ //
+ menuStrip.Dock = DockStyle.None;
+ menuStrip.ImageScalingSize = new Size(24, 24);
+ menuStrip.Items.AddRange(new ToolStripItem[] { referencesToolStripMenuItem });
+ menuStrip.Location = new Point(0, 0);
+ menuStrip.Name = "menuStrip";
+ menuStrip.Size = new Size(147, 33);
+ menuStrip.TabIndex = 8;
+ menuStrip.Text = "menuStrip1";
+ //
+ // referencesToolStripMenuItem
+ //
+ referencesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, pastriesToolStripMenuItem });
+ referencesToolStripMenuItem.Name = "referencesToolStripMenuItem";
+ referencesToolStripMenuItem.Size = new Size(139, 29);
+ referencesToolStripMenuItem.Text = "Справочники";
+ //
+ // componentsToolStripMenuItem
+ //
+ componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
+ componentsToolStripMenuItem.Size = new Size(298, 34);
+ componentsToolStripMenuItem.Text = "Компоненты";
+ componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
+ //
+ // pastriesToolStripMenuItem
+ //
+ pastriesToolStripMenuItem.Name = "pastriesToolStripMenuItem";
+ pastriesToolStripMenuItem.Size = new Size(298, 34);
+ pastriesToolStripMenuItem.Text = "Кондитерские изделия";
+ pastriesToolStripMenuItem.Click += PastriesToolStripMenuItem_Click;
+ //
+ // FormMain
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1154, 442);
+ Controls.Add(menuStrip);
+ Controls.Add(buttonRef);
+ Controls.Add(buttonIssuedOrder);
+ Controls.Add(buttonOrderReady);
+ Controls.Add(buttonTakeOrderInWork);
+ Controls.Add(buttonCreateOrder);
+ Controls.Add(dataGridView);
+ MainMenuStrip = menuStrip;
+ Name = "FormMain";
+ Text = "Кондитерская";
+ Load += FormMain_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ menuStrip.ResumeLayout(false);
+ menuStrip.PerformLayout();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonCreateOrder;
+ private Button buttonTakeOrderInWork;
+ private Button buttonOrderReady;
+ private Button buttonIssuedOrder;
+ private Button buttonRef;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem referencesToolStripMenuItem;
+ private ToolStripMenuItem pastriesToolStripMenuItem;
+ private ToolStripMenuItem componentsToolStripMenuItem;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormMain.cs b/Confectionery/Confectionery/FormMain.cs
new file mode 100644
index 0000000..31ae8de
--- /dev/null
+++ b/Confectionery/Confectionery/FormMain.cs
@@ -0,0 +1,179 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryDataModels.Enums;
+using Microsoft.Extensions.Logging;
+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.None;
+ }
+ _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 PastriesToolStripMenuItem_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(
+ CreateBindingModel(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(
+ CreateBindingModel(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(
+ CreateBindingModel(id));
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. " +
+ "Дополнительная информация в логах.");
+ }
+ _logger.LogInformation("Заказ №{id} выдан", id);
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void ButtonRef_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ private OrderBindingModel CreateBindingModel(int id,
+ bool isDone = false)
+ {
+ return new OrderBindingModel
+ {
+ Id = id,
+ PastryId = Convert.ToInt32(dataGridView.SelectedRows[
+ 0].Cells["PastryId"].Value),
+ Status = Enum.Parse(dataGridView.SelectedRows[
+ 0].Cells["Status"].Value.ToString()),
+ Count = Convert.ToInt32(dataGridView.SelectedRows[
+ 0].Cells["Count"].Value),
+ Sum = double.Parse(dataGridView.SelectedRows[
+ 0].Cells["Sum"].Value.ToString()),
+ DateCreate = DateTime.Parse(dataGridView.SelectedRows[
+ 0].Cells["DateCreate"].Value.ToString()),
+ };
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormMain.resx b/Confectionery/Confectionery/FormMain.resx
new file mode 100644
index 0000000..faf28b9
--- /dev/null
+++ b/Confectionery/Confectionery/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
+
+
+ 233, 17
+
+
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormPastries.Designer.cs b/Confectionery/Confectionery/FormPastries.Designer.cs
new file mode 100644
index 0000000..bffc820
--- /dev/null
+++ b/Confectionery/Confectionery/FormPastries.Designer.cs
@@ -0,0 +1,126 @@
+namespace ConfectioneryView
+{
+ partial class FormPastries
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer Pastries = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (Pastries != null))
+ {
+ Pastries.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();
+ 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.BackgroundColor = SystemColors.Window;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(0, 0);
+ dataGridView.Margin = new Padding(4);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(742, 444);
+ dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonAdd.Location = new Point(754, 12);
+ buttonAdd.Margin = new Padding(4);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(112, 56);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += ButtonAdd_Click;
+ //
+ // buttonUpd
+ //
+ buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonUpd.Location = new Point(754, 74);
+ buttonUpd.Margin = new Padding(4);
+ buttonUpd.Name = "buttonUpd";
+ buttonUpd.Size = new Size(112, 56);
+ buttonUpd.TabIndex = 2;
+ buttonUpd.Text = "Изменить";
+ buttonUpd.UseVisualStyleBackColor = true;
+ buttonUpd.Click += ButtonUpd_Click;
+ //
+ // buttonDel
+ //
+ buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonDel.Location = new Point(754, 198);
+ buttonDel.Margin = new Padding(4);
+ buttonDel.Name = "buttonDel";
+ buttonDel.Size = new Size(112, 56);
+ buttonDel.TabIndex = 3;
+ buttonDel.Text = "Удалить";
+ buttonDel.UseVisualStyleBackColor = true;
+ buttonDel.Click += ButtonDel_Click;
+ //
+ // buttonRef
+ //
+ buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonRef.Location = new Point(754, 136);
+ buttonRef.Margin = new Padding(4);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new Size(112, 56);
+ buttonRef.TabIndex = 4;
+ buttonRef.Text = "Обновить";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += ButtonRef_Click;
+ //
+ // FormPastries
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(878, 444);
+ Controls.Add(buttonRef);
+ Controls.Add(buttonDel);
+ Controls.Add(buttonUpd);
+ Controls.Add(buttonAdd);
+ Controls.Add(dataGridView);
+ Margin = new Padding(4);
+ Name = "FormPastries";
+ Text = "Кондитерские изделия";
+ Load += FormPastries_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonUpd;
+ private Button buttonDel;
+ private Button buttonRef;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormPastries.cs b/Confectionery/Confectionery/FormPastries.cs
new file mode 100644
index 0000000..2b4b445
--- /dev/null
+++ b/Confectionery/Confectionery/FormPastries.cs
@@ -0,0 +1,112 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+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 ButtonUpd_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(
+ typeof(FormPastry));
+ if (service is FormPastry form)
+ {
+ var tmp = Convert.ToInt32(
+ dataGridView.SelectedRows[0].Cells["Id"].Value);
+ 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 PastryBindingModel
+ {
+ 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();
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormPastries.resx b/Confectionery/Confectionery/FormPastries.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/Confectionery/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/Confectionery/FormPastry.Designer.cs b/Confectionery/Confectionery/FormPastry.Designer.cs
new file mode 100644
index 0000000..b6b2990
--- /dev/null
+++ b/Confectionery/Confectionery/FormPastry.Designer.cs
@@ -0,0 +1,239 @@
+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();
+ labelPrice = new Label();
+ textBoxName = new TextBox();
+ textBoxPrice = new TextBox();
+ groupBox = new GroupBox();
+ buttonRef = new Button();
+ buttonDel = new Button();
+ buttonUpd = new Button();
+ buttonAdd = new Button();
+ dataGridView = new DataGridView();
+ id = new DataGridViewTextBoxColumn();
+ Component = new DataGridViewTextBoxColumn();
+ Count = new DataGridViewTextBoxColumn();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ groupBox.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(16, 21);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(94, 25);
+ labelName.TabIndex = 0;
+ labelName.Text = "Название:";
+ //
+ // labelPrice
+ //
+ labelPrice.AutoSize = true;
+ labelPrice.Location = new Point(16, 66);
+ labelPrice.Name = "labelPrice";
+ labelPrice.Size = new Size(103, 25);
+ labelPrice.TabIndex = 1;
+ labelPrice.Text = "Стоимость:";
+ //
+ // textBoxName
+ //
+ textBoxName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ textBoxName.Location = new Point(170, 21);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(396, 31);
+ textBoxName.TabIndex = 2;
+ //
+ // textBoxPrice
+ //
+ textBoxPrice.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ textBoxPrice.Location = new Point(170, 66);
+ textBoxPrice.Name = "textBoxPrice";
+ textBoxPrice.Size = new Size(160, 31);
+ textBoxPrice.TabIndex = 3;
+ //
+ // groupBox
+ //
+ groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ groupBox.Controls.Add(buttonRef);
+ groupBox.Controls.Add(buttonDel);
+ groupBox.Controls.Add(buttonUpd);
+ groupBox.Controls.Add(buttonAdd);
+ groupBox.Controls.Add(dataGridView);
+ groupBox.Location = new Point(16, 112);
+ groupBox.Name = "groupBox";
+ groupBox.Size = new Size(850, 286);
+ groupBox.TabIndex = 4;
+ groupBox.TabStop = false;
+ groupBox.Text = "Компоненты";
+ //
+ // buttonRef
+ //
+ buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonRef.Location = new Point(732, 215);
+ buttonRef.Name = "buttonRef";
+ buttonRef.Size = new Size(112, 56);
+ buttonRef.TabIndex = 4;
+ buttonRef.Text = "Обновить";
+ buttonRef.UseVisualStyleBackColor = true;
+ buttonRef.Click += ButtonRef_Click;
+ //
+ // buttonDel
+ //
+ buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonDel.Location = new Point(732, 153);
+ buttonDel.Name = "buttonDel";
+ buttonDel.Size = new Size(112, 56);
+ buttonDel.TabIndex = 3;
+ buttonDel.Text = "Удалить";
+ buttonDel.UseVisualStyleBackColor = true;
+ buttonDel.Click += ButtonDel_Click;
+ //
+ // buttonUpd
+ //
+ buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonUpd.Location = new Point(732, 91);
+ buttonUpd.Name = "buttonUpd";
+ buttonUpd.Size = new Size(112, 56);
+ buttonUpd.TabIndex = 2;
+ buttonUpd.Text = "Изменить";
+ buttonUpd.UseVisualStyleBackColor = true;
+ buttonUpd.Click += ButtonUpd_Click;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonAdd.Location = new Point(732, 29);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(112, 56);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += ButtonAdd_Click;
+ //
+ // dataGridView
+ //
+ dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+ dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+ dataGridView.BackgroundColor = SystemColors.Window;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, Component, Count });
+ dataGridView.Location = new Point(6, 29);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowHeadersWidth = 51;
+ dataGridView.RowTemplate.Height = 29;
+ dataGridView.Size = new Size(720, 251);
+ dataGridView.TabIndex = 0;
+ //
+ // id
+ //
+ id.HeaderText = "id";
+ id.MinimumWidth = 6;
+ id.Name = "id";
+ id.Visible = false;
+ //
+ // Component
+ //
+ Component.FillWeight = 200F;
+ Component.HeaderText = "Компонент";
+ Component.MinimumWidth = 6;
+ Component.Name = "Component";
+ //
+ // Count
+ //
+ Count.HeaderText = "Количество";
+ Count.MinimumWidth = 6;
+ Count.Name = "Count";
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Location = new Point(754, 404);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(112, 34);
+ buttonCancel.TabIndex = 5;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Location = new Point(636, 404);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(112, 34);
+ buttonSave.TabIndex = 6;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // FormPastry
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(878, 444);
+ Controls.Add(buttonSave);
+ Controls.Add(buttonCancel);
+ Controls.Add(groupBox);
+ Controls.Add(textBoxPrice);
+ Controls.Add(textBoxName);
+ Controls.Add(labelPrice);
+ Controls.Add(labelName);
+ Name = "FormPastry";
+ Text = "Кондитерское изделие";
+ Load += FormPastry_Load;
+ Click += FormPastry_Load;
+ groupBox.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelPrice;
+ private TextBox textBoxName;
+ private TextBox textBoxPrice;
+ private GroupBox groupBox;
+ private Button buttonRef;
+ private Button buttonDel;
+ private Button buttonUpd;
+ private Button buttonAdd;
+ private DataGridView dataGridView;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private DataGridViewTextBoxColumn id;
+ private DataGridViewTextBoxColumn Component;
+ private DataGridViewTextBoxColumn Count;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormPastry.cs b/Confectionery/Confectionery/FormPastry.cs
new file mode 100644
index 0000000..7e0750b
--- /dev/null
+++ b/Confectionery/Confectionery/FormPastry.cs
@@ -0,0 +1,226 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryDataModels.Models;
+using Microsoft.Extensions.Logging;
+namespace ConfectioneryView
+{
+ public partial class FormPastry : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IPastryLogic _logic;
+ private int? _id;
+ private Dictionary _pastryComponents;
+ public int Id { set { _id = value; } }
+ public FormPastry(ILogger logger, IPastryLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _pastryComponents = new Dictionary();
+ }
+ private void FormPastry_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;
+ textBoxPrice.Text = view.Price.ToString();
+ _pastryComponents = 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 (_pastryComponents != null)
+ {
+ dataGridView.Rows.Clear();
+ foreach (var pc in _pastryComponents)
+ {
+ dataGridView.Rows.Add(new object[] { pc.Key,
+ pc.Value.Item1.ComponentName, pc.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(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 (_pastryComponents.ContainsKey(form.Id))
+ {
+ _pastryComponents[form.Id] = (form.ComponentModel,
+ form.Count);
+ }
+ else
+ {
+ _pastryComponents.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(FormPastryComponent));
+ if (service is FormPastryComponent form)
+ {
+ int id = Convert.ToInt32(
+ dataGridView.SelectedRows[0].Cells[0].Value);
+ form.Id = id;
+ form.Count = _pastryComponents[id].Item2;
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (form.ComponentModel == null)
+ {
+ return;
+ }
+ _logger.LogInformation("Изменение компонента: " +
+ "{ ComponentName} - { Count}",
+ form.ComponentModel.ComponentName, form.Count);
+ _pastryComponents[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);
+ _pastryComponents?.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 (_pastryComponents == null || _pastryComponents.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(textBoxPrice.Text),
+ PastryComponents = _pastryComponents
+ };
+ 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 _pastryComponents)
+ {
+ price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2);
+ }
+ return Math.Round(price * 1.1, 2);
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormPastry.resx b/Confectionery/Confectionery/FormPastry.resx
new file mode 100644
index 0000000..2b71d7f
--- /dev/null
+++ b/Confectionery/Confectionery/FormPastry.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
+
+
+ True
+
+
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormPastryComponent.Designer.cs b/Confectionery/Confectionery/FormPastryComponent.Designer.cs
new file mode 100644
index 0000000..03b23ed
--- /dev/null
+++ b/Confectionery/Confectionery/FormPastryComponent.Designer.cs
@@ -0,0 +1,123 @@
+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();
+ labelCount = new Label();
+ comboBoxComponent = new ComboBox();
+ textBoxCount = new TextBox();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ SuspendLayout();
+ //
+ // labelComponent
+ //
+ labelComponent.AutoSize = true;
+ labelComponent.Location = new Point(16, 21);
+ labelComponent.Name = "labelComponent";
+ labelComponent.Size = new Size(107, 25);
+ labelComponent.TabIndex = 0;
+ labelComponent.Text = "Компонент:";
+ //
+ // labelCount
+ //
+ labelCount.AutoSize = true;
+ labelCount.Location = new Point(16, 66);
+ labelCount.Name = "labelCount";
+ labelCount.Size = new Size(111, 25);
+ labelCount.TabIndex = 1;
+ labelCount.Text = "Количество:";
+ //
+ // comboBoxComponent
+ //
+ comboBoxComponent.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxComponent.FormattingEnabled = true;
+ comboBoxComponent.Location = new Point(170, 21);
+ comboBoxComponent.Name = "comboBoxComponent";
+ comboBoxComponent.Size = new Size(396, 33);
+ comboBoxComponent.TabIndex = 2;
+ //
+ // textBoxCount
+ //
+ textBoxCount.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ textBoxCount.Location = new Point(170, 66);
+ textBoxCount.Name = "textBoxCount";
+ textBoxCount.Size = new Size(396, 31);
+ textBoxCount.TabIndex = 3;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonCancel.Location = new Point(454, 148);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(112, 34);
+ buttonCancel.TabIndex = 4;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonSave.Location = new Point(336, 148);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(112, 34);
+ buttonSave.TabIndex = 5;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // FormPastryComponent
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(578, 194);
+ Controls.Add(buttonSave);
+ Controls.Add(buttonCancel);
+ Controls.Add(textBoxCount);
+ Controls.Add(comboBoxComponent);
+ Controls.Add(labelCount);
+ Controls.Add(labelComponent);
+ Name = "FormPastryComponent";
+ Text = "Компонент кондитерского изделия";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelComponent;
+ private Label labelCount;
+ private ComboBox comboBoxComponent;
+ private TextBox textBoxCount;
+ private Button buttonCancel;
+ private Button buttonSave;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/Confectionery/FormPastryComponent.cs b/Confectionery/Confectionery/FormPastryComponent.cs
new file mode 100644
index 0000000..8b114ed
--- /dev/null
+++ b/Confectionery/Confectionery/FormPastryComponent.cs
@@ -0,0 +1,78 @@
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Models;
+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(textBoxCount.Text); }
+ set { textBoxCount.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(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();
+ }
+ }
+}
diff --git a/Confectionery/Confectionery/FormPastryComponent.resx b/Confectionery/Confectionery/FormPastryComponent.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Confectionery/Confectionery/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/Confectionery/Program.cs b/Confectionery/Confectionery/Program.cs
index 716fec3..ca20fc5 100644
--- a/Confectionery/Confectionery/Program.cs
+++ b/Confectionery/Confectionery/Program.cs
@@ -1,17 +1,51 @@
-namespace Confectionery
+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.
+ /// The main entry point for the application.
///
[STAThread]
static void Main()
{
- // To customize application configuration such as set high DPI settings or default font,
- // see https://aka.ms/applicationconfiguration.
+ // 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();
+ services.AddTransient();
}
}
-}
\ No newline at end of file
+}
diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ComponentLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ComponentLogic.cs
new file mode 100644
index 0000000..8debb4a
--- /dev/null
+++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/ComponentLogic.cs
@@ -0,0 +1,119 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+namespace ConfectioneryBusinessLogic.BusinessLogics
+{
+ public class ComponentLogic : IComponentLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IComponentStorage _componentStorage;
+ public ComponentLogic(ILogger logger, IComponentStorage
+ componentStorage)
+ {
+ _logger = logger;
+ _componentStorage = componentStorage;
+ }
+ public List? ReadList(ComponentSearchModel? model)
+ {
+ _logger.LogInformation(
+ "ReadList. ComponentName:{ComponentName}.Id:{ Id}",
+ model?.ComponentName, model?.Id);
+ var list = model == null ? _componentStorage.GetFullList() :
+ _componentStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public ComponentViewModel? ReadElement(ComponentSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation(
+ "ReadElement. ComponentName:{ComponentName}.Id:{ Id}",
+ model.ComponentName, model.Id);
+ var element = _componentStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+ public bool Create(ComponentBindingModel model)
+ {
+ CheckModel(model);
+ if (_componentStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(ComponentBindingModel model)
+ {
+ CheckModel(model);
+ if (_componentStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(ComponentBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_componentStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(ComponentBindingModel model,
+ bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ throw new ArgumentNullException("Нет названия компонента",
+ nameof(model.ComponentName));
+ }
+ if (model.Cost <= 0)
+ {
+ throw new ArgumentNullException(
+ "Цена компонента должна быть больше 0",
+ nameof(model.Cost));
+ }
+ _logger.LogInformation(
+ "Component. ComponentName:{ComponentName}.Cost:{ Cost}." +
+ " Id: { Id}", model.ComponentName, model.Cost, model.Id);
+ var element = _componentStorage.GetElement(new ComponentSearchModel
+ {
+ ComponentName = model.ComponentName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException(
+ "Компонент с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs
new file mode 100644
index 0000000..15852c6
--- /dev/null
+++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -0,0 +1,105 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Enums;
+using Microsoft.Extensions.Logging;
+namespace ConfectioneryBusinessLogic.BusinessLogics
+{
+ public class OrderLogic : IOrderLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IOrderStorage _orderStorage;
+ public OrderLogic(ILogger logger,
+ IOrderStorage orderStorage)
+ {
+ _logger = logger;
+ _orderStorage = orderStorage;
+ }
+ public List? ReadList(OrderSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
+ var list = model == null ? _orderStorage.GetFullList() :
+ _orderStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public bool CreateOrder(OrderBindingModel model)
+ {
+ CheckModel(model);
+ if (model.Status != OrderStatus.Неизвестен) return false;
+ model.Status = OrderStatus.Принят;
+ if (_orderStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
+ {
+ CheckModel(model);
+ var element = _orderStorage.GetElement(
+ new OrderSearchModel { Id = model.Id });
+ if (element == null)
+ {
+ _logger.LogWarning("Read operation failed");
+ return false;
+ }
+ if (element.Status != status - 1)
+ {
+ _logger.LogWarning("Status change operation failed");
+ throw new InvalidOperationException("Текущий статус заказа" +
+ " не может быть переведен в выбранный");
+ }
+ model.Status = status;
+ if (model.Status == OrderStatus.Выдан)
+ model.DateImplement = DateTime.Now;
+ _orderStorage.Update(model);
+ return true;
+ }
+ public bool TakeOrderInWork(OrderBindingModel model)
+ {
+ return ChangeStatus(model, OrderStatus.Выполняется);
+ }
+ public bool FinishOrder(OrderBindingModel model)
+ {
+ return ChangeStatus(model, OrderStatus.Готов);
+ }
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ return ChangeStatus(model, OrderStatus.Выдан);
+ }
+ private void CheckModel(OrderBindingModel model,
+ bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.Sum <= 0)
+ {
+ throw new ArgumentNullException(
+ "Цена заказа должна быть больше 0", nameof(model.Sum));
+ }
+ if (model.Count <= 0)
+ {
+ throw new ArgumentNullException(
+ "Количество элементов в заказе должно быть больше 0",
+ nameof(model.Count));
+ }
+ _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}",
+ model.Sum, model.Id);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs
new file mode 100644
index 0000000..48f1c41
--- /dev/null
+++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs
@@ -0,0 +1,119 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using Microsoft.Extensions.Logging;
+namespace ConfectioneryBusinessLogic.BusinessLogics
+{
+ public class PastryLogic : IPastryLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IPastryStorage _PastryStorage;
+ public PastryLogic(ILogger logger,
+ IPastryStorage PastryStorage)
+ {
+ _logger = logger;
+ _PastryStorage = PastryStorage;
+ }
+ public List? ReadList(PastrySearchModel? model)
+ {
+ _logger.LogInformation(
+ "ReadList. PastryName:{PastryName}. Id:{ Id}",
+ model?.PastryName, model?.Id);
+ var list = model == null ? _PastryStorage.GetFullList()
+ : _PastryStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+ public PastryViewModel? ReadElement(PastrySearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation(
+ "ReadElement. PastryName:{PastryName}.Id:{ Id}",
+ model.PastryName, model.Id);
+ var element = _PastryStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+ public bool Create(PastryBindingModel model)
+ {
+ CheckModel(model);
+ if (_PastryStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Update(PastryBindingModel model)
+ {
+ CheckModel(model);
+ if (_PastryStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+ public bool Delete(PastryBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+ if (_PastryStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+ private void CheckModel(PastryBindingModel model,
+ bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.PastryName))
+ {
+ throw new ArgumentNullException("Нет названия кондитерского " +
+ "изделия", nameof(model.PastryName));
+ }
+ if (model.Price <= 0)
+ {
+ throw new ArgumentNullException(
+ "Цена кондитерского изделия должна быть больше 0",
+ nameof(model.Price));
+ }
+ _logger.LogInformation(
+ "Pastry. Pastry:{Pastry}. Price:{ Price }. Id: { Id}",
+ model.PastryName, model.Price, model.Id);
+ var element = _PastryStorage.GetElement(new PastrySearchModel
+ {
+ PastryName = model.PastryName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException(
+ "Кондитерское изделие с таким названием уже есть");
+ }
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj
new file mode 100644
index 0000000..fa96f14
--- /dev/null
+++ b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj
@@ -0,0 +1,17 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Confectionery/ConfectioneryContracts/BindingModels/ComponentBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/ComponentBindingModel.cs
new file mode 100644
index 0000000..0acfcce
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/BindingModels/ComponentBindingModel.cs
@@ -0,0 +1,10 @@
+using ConfectioneryDataModels.Models;
+namespace ConfectioneryContracts.BindingModels
+{
+ public class ComponentBindingModel : IComponentModel
+ {
+ public int Id { get; set; }
+ public string ComponentName { get; set; } = string.Empty;
+ public double Cost { get; set; }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs
new file mode 100644
index 0000000..d7c1485
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs
@@ -0,0 +1,15 @@
+using ConfectioneryDataModels.Enums;
+using ConfectioneryDataModels.Models;
+namespace ConfectioneryContracts.BindingModels
+{
+ public class OrderBindingModel : IOrderModel
+ {
+ public int Id { get; set; }
+ public int PastryId { get; set; }
+ public int Count { get; set; }
+ public double Sum { get; set; }
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ public DateTime? DateImplement { get; set; }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs
new file mode 100644
index 0000000..433d003
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs
@@ -0,0 +1,15 @@
+using ConfectioneryDataModels.Models;
+namespace ConfectioneryContracts.BindingModels
+{
+ public class PastryBindingModel : IPastryModel
+ {
+ public int Id { get; set; }
+ public string PastryName { get; set; } = string.Empty;
+ public double Price { get; set; }
+ public Dictionary PastryComponents
+ {
+ get;
+ set;
+ } = new();
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IComponentLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IComponentLogic.cs
new file mode 100644
index 0000000..da9a5af
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IComponentLogic.cs
@@ -0,0 +1,14 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.ViewModels;
+namespace ConfectioneryContracts.BusinessLogicsContracts
+{
+ public interface IComponentLogic
+ {
+ List? ReadList(ComponentSearchModel? model);
+ ComponentViewModel? ReadElement(ComponentSearchModel model);
+ bool Create(ComponentBindingModel model);
+ bool Update(ComponentBindingModel model);
+ bool Delete(ComponentBindingModel model);
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs
new file mode 100644
index 0000000..7493eb8
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -0,0 +1,15 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.ViewModels;
+namespace ConfectioneryContracts.BusinessLogicsContracts
+{
+ public interface IOrderLogic
+ {
+ List? ReadList(OrderSearchModel? model);
+ bool CreateOrder(OrderBindingModel model);
+ bool TakeOrderInWork(OrderBindingModel model);
+ bool FinishOrder(OrderBindingModel model);
+ bool DeliveryOrder(OrderBindingModel model);
+ }
+}
+
diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs
new file mode 100644
index 0000000..390ec5c
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs
@@ -0,0 +1,14 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.ViewModels;
+namespace ConfectioneryContracts.BusinessLogicsContracts
+{
+ public interface IPastryLogic
+ {
+ List? ReadList(PastrySearchModel? model);
+ PastryViewModel? ReadElement(PastrySearchModel model);
+ bool Create(PastryBindingModel model);
+ bool Update(PastryBindingModel model);
+ bool Delete(PastryBindingModel model);
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj
new file mode 100644
index 0000000..6f0f586
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/Confectionery/ConfectioneryContracts/SearchModels/ComponentSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/ComponentSearchModel.cs
new file mode 100644
index 0000000..2325c7f
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/SearchModels/ComponentSearchModel.cs
@@ -0,0 +1,8 @@
+namespace ConfectioneryContracts.SearchModels
+{
+ public class ComponentSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ComponentName { get; set; }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs
new file mode 100644
index 0000000..6df7699
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs
@@ -0,0 +1,7 @@
+namespace ConfectioneryContracts.SearchModels
+{
+ public class OrderSearchModel
+ {
+ public int? Id { get; set; }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs
new file mode 100644
index 0000000..542cf03
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs
@@ -0,0 +1,8 @@
+namespace ConfectioneryContracts.SearchModels
+{
+ public class PastrySearchModel
+ {
+ public int? Id { get; set; }
+ public string? PastryName { get; set; }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IComponentStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IComponentStorage.cs
new file mode 100644
index 0000000..b9b5c90
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IComponentStorage.cs
@@ -0,0 +1,16 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.ViewModels;
+namespace ConfectioneryContracts.StoragesContracts
+{
+ public interface IComponentStorage
+ {
+ List GetFullList();
+ List GetFilteredList(ComponentSearchModel model);
+ ComponentViewModel? GetElement(ComponentSearchModel model);
+ ComponentViewModel? Insert(ComponentBindingModel model);
+ ComponentViewModel? Update(ComponentBindingModel model);
+ ComponentViewModel? Delete(ComponentBindingModel model);
+ }
+}
+
diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs
new file mode 100644
index 0000000..5a4a6d6
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs
@@ -0,0 +1,15 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.ViewModels;
+namespace ConfectioneryContracts.StoragesContracts
+{
+ public interface IOrderStorage
+ {
+ List GetFullList();
+ List GetFilteredList(OrderSearchModel model);
+ OrderViewModel? GetElement(OrderSearchModel model);
+ OrderViewModel? Insert(OrderBindingModel model);
+ OrderViewModel? Update(OrderBindingModel model);
+ OrderViewModel? Delete(OrderBindingModel model);
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs
new file mode 100644
index 0000000..ff2a043
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs
@@ -0,0 +1,15 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.ViewModels;
+namespace ConfectioneryContracts.StoragesContracts
+{
+ public interface IPastryStorage
+ {
+ List GetFullList();
+ List GetFilteredList(PastrySearchModel model);
+ PastryViewModel? GetElement(PastrySearchModel model);
+ PastryViewModel? Insert(PastryBindingModel model);
+ PastryViewModel? Update(PastryBindingModel model);
+ PastryViewModel? Delete(PastryBindingModel model);
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs
new file mode 100644
index 0000000..8947ea1
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/ViewModels/ComponentViewModel.cs
@@ -0,0 +1,13 @@
+using ConfectioneryDataModels.Models;
+using System.ComponentModel;
+namespace ConfectioneryContracts.ViewModels
+{
+ public class ComponentViewModel : IComponentModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название компонента")]
+ public string ComponentName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Cost { get; set; }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs
new file mode 100644
index 0000000..5aaf95e
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,24 @@
+using ConfectioneryDataModels.Enums;
+using ConfectioneryDataModels.Models;
+using System.ComponentModel;
+namespace ConfectioneryContracts.ViewModels
+{
+ public class OrderViewModel : IOrderModel
+ {
+ [DisplayName("Номер")]
+ public int Id { get; set; }
+ public int PastryId { get; set; }
+ [DisplayName("Изделие")]
+ public string PastryName { get; set; } = string.Empty;
+ [DisplayName("Количество")]
+ public int Count { get; set; }
+ [DisplayName("Сумма")]
+ public double Sum { get; set; }
+ [DisplayName("Статус")]
+ public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
+ [DisplayName("Дата создания")]
+ public DateTime DateCreate { get; set; } = DateTime.Now;
+ [DisplayName("Дата выполнения")]
+ public DateTime? DateImplement { get; set; }
+ }
+}
diff --git a/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs
new file mode 100644
index 0000000..1f2a88f
--- /dev/null
+++ b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs
@@ -0,0 +1,15 @@
+using ConfectioneryDataModels.Models;
+using System.ComponentModel;
+namespace ConfectioneryContracts.ViewModels
+{
+ public class PastryViewModel : IPastryModel
+ {
+ public int Id { get; set; }
+ [DisplayName("Название кондитерского изделия")]
+ public string PastryName { get; set; } = string.Empty;
+ [DisplayName("Цена")]
+ public double Price { get; set; }
+ public Dictionary
+ PastryComponents { get; set; } = new();
+ }
+}
diff --git a/Confectionery/Confectionery/Confectionery.csproj b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj
similarity index 51%
rename from Confectionery/Confectionery/Confectionery.csproj
rename to Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj
index 663fdb8..fa71b7a 100644
--- a/Confectionery/Confectionery/Confectionery.csproj
+++ b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj
@@ -1,11 +1,9 @@
- WinExe
- net8.0-windows
- enable
- true
+ net8.0
enable
+ enable
-
\ No newline at end of file
+
diff --git a/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs
new file mode 100644
index 0000000..d8ece29
--- /dev/null
+++ b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs
@@ -0,0 +1,11 @@
+namespace ConfectioneryDataModels.Enums
+{
+ public enum OrderStatus
+ {
+ Неизвестен = -1,
+ Принят = 0,
+ Выполняется = 1,
+ Готов = 2,
+ Выдан = 3
+ }
+}
diff --git a/Confectionery/ConfectioneryDataModels/IId.cs b/Confectionery/ConfectioneryDataModels/IId.cs
new file mode 100644
index 0000000..3f58c8a
--- /dev/null
+++ b/Confectionery/ConfectioneryDataModels/IId.cs
@@ -0,0 +1,7 @@
+namespace ConfectioneryDataModels
+{
+ public interface IId
+ {
+ int Id { get; }
+ }
+}
diff --git a/Confectionery/ConfectioneryDataModels/Models/IComponentModel.cs b/Confectionery/ConfectioneryDataModels/Models/IComponentModel.cs
new file mode 100644
index 0000000..1981909
--- /dev/null
+++ b/Confectionery/ConfectioneryDataModels/Models/IComponentModel.cs
@@ -0,0 +1,8 @@
+namespace ConfectioneryDataModels.Models
+{
+ public interface IComponentModel : IId
+ {
+ string ComponentName { get; }
+ double Cost { get; }
+ }
+}
diff --git a/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs
new file mode 100644
index 0000000..fc46939
--- /dev/null
+++ b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs
@@ -0,0 +1,13 @@
+using ConfectioneryDataModels.Enums;
+namespace ConfectioneryDataModels.Models
+{
+ public interface IOrderModel : IId
+ {
+ int PastryId { get; }
+ int Count { get; }
+ double Sum { get; }
+ OrderStatus Status { get; }
+ DateTime DateCreate { get; }
+ DateTime? DateImplement { get; }
+ }
+}
diff --git a/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs b/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs
new file mode 100644
index 0000000..b13c2c5
--- /dev/null
+++ b/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs
@@ -0,0 +1,9 @@
+namespace ConfectioneryDataModels.Models
+{
+ public interface IPastryModel : IId
+ {
+ string PastryName { get; }
+ double Price { get; }
+ Dictionary PastryComponents { get; }
+ }
+}
diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj
new file mode 100644
index 0000000..3bc7a6c
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs
new file mode 100644
index 0000000..88e7f95
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs
@@ -0,0 +1,25 @@
+using ConfectioneryListImplement.Models;
+namespace ConfectioneryListImplement
+{
+ public class DataListSingleton
+ {
+ private static DataListSingleton? _instance;
+ public List Components { get; set; }
+ public List Orders { get; set; }
+ public List Pastries { get; set; }
+ private DataListSingleton()
+ {
+ Components = new List();
+ Orders = new List();
+ Pastries = new List();
+ }
+ public static DataListSingleton GetInstance()
+ {
+ if (_instance == null)
+ {
+ _instance = new DataListSingleton();
+ }
+ return _instance;
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryListImplement/Implements/ComponentStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/ComponentStorage.cs
new file mode 100644
index 0000000..e72b1dc
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/Implements/ComponentStorage.cs
@@ -0,0 +1,103 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryListImplement.Models;
+namespace ConfectioneryListImplement.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ private readonly DataListSingleton _source;
+ public ComponentStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var component in _source.Components)
+ {
+ result.Add(component.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(
+ ComponentSearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return result;
+ }
+ foreach (var component in _source.Components)
+ {
+ if (component.ComponentName.Contains(model.ComponentName))
+ {
+ result.Add(component.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) &&
+ !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var component in _source.Components)
+ {
+ if ((!string.IsNullOrEmpty(model.ComponentName) &&
+ component.ComponentName == model.ComponentName) ||
+ (model.Id.HasValue && component.Id == model.Id))
+ {
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var component in _source.Components)
+ {
+ if (model.Id <= component.Id)
+ {
+ model.Id = component.Id + 1;
+ }
+ }
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ _source.Components.Add(newComponent);
+ return newComponent.GetViewModel;
+ }
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ foreach (var component in _source.Components)
+ {
+ if (component.Id == model.Id)
+ {
+ component.Update(model);
+ return component.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ for (int i = 0; i < _source.Components.Count; ++i)
+ {
+ if (_source.Components[i].Id == model.Id)
+ {
+ var element = _source.Components[i];
+ _source.Components.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..fead955
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs
@@ -0,0 +1,111 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryListImplement.Models;
+namespace ConfectioneryListImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataListSingleton _source;
+ public OrderStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var order in _source.Orders)
+ {
+ result.Add(AccessPastryStorage(order.GetViewModel));
+ }
+ return result;
+ }
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ var result = new List();
+ if (!model.Id.HasValue)
+ {
+ return result;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ result.Add(AccessPastryStorage(order.GetViewModel));
+ }
+ }
+ return result;
+ }
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id.HasValue && order.Id == model.Id)
+ {
+ return order.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id <= order.Id)
+ {
+ model.Id = order.Id + 1;
+ }
+ }
+ var newOrder = Order.Create(model);
+ if (newOrder == null)
+ {
+ return null;
+ }
+ _source.Orders.Add(newOrder);
+ return newOrder.GetViewModel;
+ }
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ order.Update(model);
+ return order.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ for (int i = 0; i < _source.Orders.Count; ++i)
+ {
+ if (_source.Orders[i].Id == model.Id)
+ {
+ var element = _source.Orders[i];
+ _source.Orders.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public OrderViewModel AccessPastryStorage(OrderViewModel model)
+ {
+ foreach (var Pastry in _source.Pastries)
+ {
+ if (Pastry.Id == model.PastryId)
+ {
+ model.PastryName = Pastry.PastryName;
+ break;
+ }
+ }
+ return model;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs
new file mode 100644
index 0000000..ad83c5b
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs
@@ -0,0 +1,101 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryListImplement.Models;
+namespace ConfectioneryListImplement.Implements
+{
+ public class PastryStorage : IPastryStorage
+ {
+ private readonly DataListSingleton _source;
+ public PastryStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var Pastry in _source.Pastries)
+ {
+ result.Add(Pastry.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(PastrySearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.PastryName))
+ {
+ return result;
+ }
+ foreach (var Pastry in _source.Pastries)
+ {
+ if (Pastry.PastryName.Contains(model.PastryName))
+ {
+ result.Add(Pastry.GetViewModel);
+ }
+ }
+ return result;
+ }
+ public PastryViewModel? GetElement(PastrySearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var Pastry in _source.Pastries)
+ {
+ if ((!string.IsNullOrEmpty(model.PastryName) &&
+ Pastry.PastryName == model.PastryName) ||
+ (model.Id.HasValue && Pastry.Id == model.Id))
+ {
+ return Pastry.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public PastryViewModel? Insert(PastryBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var Pastry in _source.Pastries)
+ {
+ if (model.Id <= Pastry.Id)
+ {
+ model.Id = Pastry.Id + 1;
+ }
+ }
+ var newPastry = Pastry.Create(model);
+ if (newPastry == null)
+ {
+ return null;
+ }
+ _source.Pastries.Add(newPastry);
+ return newPastry.GetViewModel;
+ }
+ public PastryViewModel? Update(PastryBindingModel model)
+ {
+ foreach (var Pastry in _source.Pastries)
+ {
+ if (Pastry.Id == model.Id)
+ {
+ Pastry.Update(model);
+ return Pastry.GetViewModel;
+ }
+ }
+ return null;
+ }
+ public PastryViewModel? Delete(PastryBindingModel model)
+ {
+ for (int i = 0; i < _source.Pastries.Count; ++i)
+ {
+ if (_source.Pastries[i].Id == model.Id)
+ {
+ var element = _source.Pastries[i];
+ _source.Pastries.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryListImplement/Models/Component.cs b/Confectionery/ConfectioneryListImplement/Models/Component.cs
new file mode 100644
index 0000000..5a8e9a0
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/Models/Component.cs
@@ -0,0 +1,40 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Models;
+namespace ConfectioneryListImplement.Models
+{
+ public class Component : IComponentModel
+ {
+ public int Id { get; private set; }
+ public string ComponentName { get; private set; } = string.Empty;
+ public double Cost { get; set; }
+ public static Component? Create(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+ public void Update(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+ }
+}
diff --git a/Confectionery/ConfectioneryListImplement/Models/Order.cs b/Confectionery/ConfectioneryListImplement/Models/Order.cs
new file mode 100644
index 0000000..08f2f6a
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/Models/Order.cs
@@ -0,0 +1,53 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Enums;
+using ConfectioneryDataModels.Models;
+namespace ConfectioneryListImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int Id { get; private set; }
+ public int PastryId { get; private set; }
+ public int Count { get; private set; }
+ public double Sum { get; private set; }
+ public OrderStatus Status { get; private set; }
+ public DateTime DateCreate { get; private set; }
+ public DateTime? DateImplement { get; private set; }
+ public static Order? Create(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order()
+ {
+ Id = model.Id,
+ PastryId = model.PastryId,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement,
+ };
+ }
+ public void Update(OrderBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Status = model.Status;
+ DateImplement = model.DateImplement;
+ }
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ PastryId = PastryId,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement,
+ };
+ }
+}
diff --git a/Confectionery/ConfectioneryListImplement/Models/Pastry.cs b/Confectionery/ConfectioneryListImplement/Models/Pastry.cs
new file mode 100644
index 0000000..627e63e
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/Models/Pastry.cs
@@ -0,0 +1,48 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryDataModels.Models;
+namespace ConfectioneryListImplement.Models
+{
+ public class Pastry : IPastryModel
+ {
+ public int Id { get; private set; }
+ public string PastryName { get; private set; } = string.Empty;
+ public double Price { get; private set; }
+ public Dictionary PastryComponents
+ {
+ get;
+ private set;
+ } = new Dictionary();
+ public static Pastry? Create(PastryBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Pastry()
+ {
+ Id = model.Id,
+ PastryName = model.PastryName,
+ Price = model.Price,
+ PastryComponents = model.PastryComponents
+ };
+ }
+ public void Update(PastryBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ PastryName = model.PastryName;
+ Price = model.Price;
+ PastryComponents = model.PastryComponents;
+ }
+ public PastryViewModel GetViewModel => new()
+ {
+ Id = Id,
+ PastryName = PastryName,
+ Price = Price,
+ PastryComponents = PastryComponents
+ };
+ }
+}