diff --git a/Confectionery/Confectionery.sln b/Confectionery/Confectionery.sln index 30fc608..2c453a2 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.3.32825.248 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Confectionery", "Confectionery\Confectionery.csproj", "{7B75620D-9ECD-4175-8E35-D31CEC904A4B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Confectionery", "Confectionery\Confectionery.csproj", "{7B75620D-9ECD-4175-8E35-D31CEC904A4B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConfectioneryDataModels", "ConfectioneryDataModels\ConfectioneryDataModels.csproj", "{22A053DC-3DC2-4375-9563-BF647A1092A4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryContracts", "ConfectioneryContracts\ConfectioneryContracts.csproj", "{6C4950D1-D788-4D5A-8C15-0A376274F2DD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryBusinessLogic", "ConfectioneryBusinessLogic\ConfectioneryBusinessLogic.csproj", "{30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfectioneryListImplement", "ConfectioneryListImplement\ConfectioneryListImplement.csproj", "{85992074-656D-4F79-AB23-60DE4F9ABF30}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +23,22 @@ Global {7B75620D-9ECD-4175-8E35-D31CEC904A4B}.Debug|Any CPU.Build.0 = Debug|Any CPU {7B75620D-9ECD-4175-8E35-D31CEC904A4B}.Release|Any CPU.ActiveCfg = Release|Any CPU {7B75620D-9ECD-4175-8E35-D31CEC904A4B}.Release|Any CPU.Build.0 = Release|Any CPU + {22A053DC-3DC2-4375-9563-BF647A1092A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {22A053DC-3DC2-4375-9563-BF647A1092A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {22A053DC-3DC2-4375-9563-BF647A1092A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {22A053DC-3DC2-4375-9563-BF647A1092A4}.Release|Any CPU.Build.0 = Release|Any CPU + {6C4950D1-D788-4D5A-8C15-0A376274F2DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C4950D1-D788-4D5A-8C15-0A376274F2DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C4950D1-D788-4D5A-8C15-0A376274F2DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C4950D1-D788-4D5A-8C15-0A376274F2DD}.Release|Any CPU.Build.0 = Release|Any CPU + {30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30F4AE5A-2C90-4C7F-BBE9-2FA56BE26C63}.Release|Any CPU.Build.0 = Release|Any CPU + {85992074-656D-4F79-AB23-60DE4F9ABF30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85992074-656D-4F79-AB23-60DE4F9ABF30}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85992074-656D-4F79-AB23-60DE4F9ABF30}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85992074-656D-4F79-AB23-60DE4F9ABF30}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Confectionery/Confectionery/Confectionery.csproj b/Confectionery/Confectionery/Confectionery.csproj index b57c89e..0e7fb26 100644 --- a/Confectionery/Confectionery/Confectionery.csproj +++ b/Confectionery/Confectionery/Confectionery.csproj @@ -8,4 +8,45 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ 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 ac3f400..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 - } -} \ No newline at end of file diff --git a/Confectionery/Confectionery/Form1.cs b/Confectionery/Confectionery/Form1.cs deleted file mode 100644 index 922703b..0000000 --- a/Confectionery/Confectionery/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Confectionery -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ 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..383a5bb --- /dev/null +++ b/Confectionery/Confectionery/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace Confectionery +{ + 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() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.comboBoxPastry = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(71, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Изделие:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 47); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(93, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Количество:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(12, 87); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(58, 20); + this.label3.TabIndex = 2; + this.label3.Text = "Сумма:"; + // + // comboBoxPastry + // + this.comboBoxPastry.FormattingEnabled = true; + this.comboBoxPastry.Location = new System.Drawing.Point(129, 6); + this.comboBoxPastry.Name = "comboBoxPastry"; + this.comboBoxPastry.Size = new System.Drawing.Size(219, 28); + this.comboBoxPastry.TabIndex = 3; + this.comboBoxPastry.SelectedIndexChanged += new System.EventHandler(this.comboBoxPastry_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(129, 44); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(219, 27); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(129, 84); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.ReadOnly = true; + this.textBoxSum.Size = new System.Drawing.Size(219, 27); + this.textBoxSum.TabIndex = 5; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(142, 130); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(254, 130); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(377, 171); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxPastry); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + 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..b196daa --- /dev/null +++ b/Confectionery/Confectionery/FormCreateOrder.cs @@ -0,0 +1,142 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Confectionery +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IPastryLogic _logicP; + private readonly IOrderLogic _logicO; + + private List? _list; + public int Id { get { return Convert.ToInt32(comboBoxPastry.SelectedValue); } set { comboBoxPastry.SelectedValue = value; } } + public IPastryModel? PastryModel + { + 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 FormCreateOrder(ILogger logger, IPastryLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxPastry.DisplayMember = "PastryName"; + comboBoxPastry.ValueMember = "Id"; + comboBoxPastry.DataSource = _list; + comboBoxPastry.SelectedItem = null; + } + } + + private void CalcSum() + { + if (comboBoxPastry.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPastry.SelectedValue); + var product = _logicP.ReadElement(new PastrySearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void comboBoxPastry_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(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..f298a7b --- /dev/null +++ b/Confectionery/Confectionery/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/FormIngredient.Designer.cs b/Confectionery/Confectionery/FormIngredient.Designer.cs new file mode 100644 index 0000000..34abc65 --- /dev/null +++ b/Confectionery/Confectionery/FormIngredient.Designer.cs @@ -0,0 +1,119 @@ +namespace Confectionery +{ + partial class FormIngredient + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelName = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(254, 140); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(354, 140); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 23); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(44, 59); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(48, 20); + this.label1.TabIndex = 3; + this.label1.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(98, 20); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(350, 27); + this.textBoxName.TabIndex = 4; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(98, 56); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(125, 27); + this.textBoxCost.TabIndex = 5; + // + // FormIngredient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(455, 176); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label1); + this.Controls.Add(this.labelName); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormIngredient"; + this.Text = "Ингредиент"; + this.Load += new System.EventHandler(this.FormIngredient_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelName; + private Label label1; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormIngredient.cs b/Confectionery/Confectionery/FormIngredient.cs new file mode 100644 index 0000000..e7be51b --- /dev/null +++ b/Confectionery/Confectionery/FormIngredient.cs @@ -0,0 +1,81 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using Microsoft.Extensions.Logging; +namespace Confectionery +{ + public partial class FormIngredient : Form + { + private readonly ILogger _logger; + private readonly IIngredientLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormIngredient(ILogger logger, IIngredientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + 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 IngredientBindingModel + { + Id = _id ?? 0, + IngredientName = 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 FormIngredient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation(" "); + var view = _logic.ReadElement(new IngredientSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.IngredientName; + textBoxCost.Text = view.Cost.ToString(); + } + } + 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(); + } + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormIngredient.resx b/Confectionery/Confectionery/FormIngredient.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/Confectionery/FormIngredient.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/FormIngredients.Designer.cs b/Confectionery/Confectionery/FormIngredients.Designer.cs new file mode 100644 index 0000000..2cefcea --- /dev/null +++ b/Confectionery/Confectionery/FormIngredients.Designer.cs @@ -0,0 +1,119 @@ +namespace Confectionery +{ + partial class FormIngredients + { + /// + /// 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.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(489, 449); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(522, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(522, 69); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(522, 126); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(522, 184); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // FormIngredients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(628, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormIngredients"; + this.Text = "Ингредиенты"; + this.Load += new System.EventHandler(this.FormIngredients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.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/FormIngredients.cs b/Confectionery/Confectionery/FormIngredients.cs new file mode 100644 index 0000000..42d7e50 --- /dev/null +++ b/Confectionery/Confectionery/FormIngredients.cs @@ -0,0 +1,111 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Confectionery +{ + public partial class FormIngredients : Form + { + private readonly ILogger _logger; + private readonly IIngredientLogic _logic; + + public FormIngredients(ILogger logger, IIngredientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormIngredients_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["IngredientName"].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(FormIngredient)); + if (service is FormIngredient 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(FormIngredient)); + if (service is FormIngredient 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 IngredientBindingModel { 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/FormIngredients.resx b/Confectionery/Confectionery/FormIngredients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/Confectionery/FormIngredients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..1b586a0 --- /dev/null +++ b/Confectionery/Confectionery/FormMain.Designer.cs @@ -0,0 +1,179 @@ +namespace Confectionery +{ + 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() + { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ингредиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1238, 28); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ингредиентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // ингредиентыToolStripMenuItem + // + this.ингредиентыToolStripMenuItem.Name = "ингредиентыToolStripMenuItem"; + this.ингредиентыToolStripMenuItem.Size = new System.Drawing.Size(251, 26); + this.ингредиентыToolStripMenuItem.Text = "Ингредиенты"; + this.ингредиентыToolStripMenuItem.Click += new System.EventHandler(this.ингредиентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(251, 26); + this.изделияToolStripMenuItem.Text = "Кондитерские изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.изделияToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 31); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(991, 417); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(1016, 54); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(197, 29); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1016, 137); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(197, 29); + this.buttonTakeOrderInWork.TabIndex = 3; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.buttonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(1016, 223); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(197, 29); + this.buttonOrderReady.TabIndex = 4; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.buttonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(1016, 308); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(197, 29); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.buttonIssuedOrder_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(1016, 381); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(197, 29); + this.buttonRef.TabIndex = 6; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1238, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Кондитерская"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem ингредиентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormMain.cs b/Confectionery/Confectionery/FormMain.cs new file mode 100644 index 0000000..5a41079 --- /dev/null +++ b/Confectionery/Confectionery/FormMain.cs @@ -0,0 +1,156 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Confectionery +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["PastryId"].Visible = false; + dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ингредиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormIngredients)); + if (service is FormIngredients form) + { + form.ShowDialog(); + } + } + + private void изделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPastries)); + if (service is FormPastries form) + { + form.ShowDialog(); + } + } + + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/Confectionery/FormMain.resx b/Confectionery/Confectionery/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/Confectionery/Confectionery/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Confectionery/Confectionery/FormPastries.Designer.cs b/Confectionery/Confectionery/FormPastries.Designer.cs new file mode 100644 index 0000000..2c20659 --- /dev/null +++ b/Confectionery/Confectionery/FormPastries.Designer.cs @@ -0,0 +1,119 @@ +namespace Confectionery +{ + partial class FormPastries + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(523, 186); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 9; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(523, 128); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 8; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(523, 71); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 7; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(523, 14); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 6; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(1, 2); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(489, 449); + this.dataGridView.TabIndex = 5; + // + // FormPastries + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(642, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormPastries"; + this.Text = "Кондитерские изделия"; + this.Load += new System.EventHandler(this.FormPastries_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormPastries.cs b/Confectionery/Confectionery/FormPastries.cs new file mode 100644 index 0000000..46471e4 --- /dev/null +++ b/Confectionery/Confectionery/FormPastries.cs @@ -0,0 +1,112 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Confectionery +{ + 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["PastryIngredients"].Visible = false; + dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка изделий"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void 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) + { + 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..f298a7b --- /dev/null +++ b/Confectionery/Confectionery/FormPastries.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..276e7e4 --- /dev/null +++ b/Confectionery/Confectionery/FormPastry.Designer.cs @@ -0,0 +1,241 @@ +namespace Confectionery +{ + 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() + { + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBoxIngredients = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.PastryId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.IngredientName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBoxIngredients.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(80, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 39); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(86, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(98, 6); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(248, 27); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Location = new System.Drawing.Point(98, 36); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.ReadOnly = true; + this.textBoxPrice.Size = new System.Drawing.Size(125, 27); + this.textBoxPrice.TabIndex = 3; + // + // groupBoxIngredients + // + this.groupBoxIngredients.Controls.Add(this.buttonRef); + this.groupBoxIngredients.Controls.Add(this.buttonDel); + this.groupBoxIngredients.Controls.Add(this.buttonUpd); + this.groupBoxIngredients.Controls.Add(this.buttonAdd); + this.groupBoxIngredients.Controls.Add(this.dataGridView); + this.groupBoxIngredients.Location = new System.Drawing.Point(12, 69); + this.groupBoxIngredients.Name = "groupBoxIngredients"; + this.groupBoxIngredients.Size = new System.Drawing.Size(776, 334); + this.groupBoxIngredients.TabIndex = 4; + this.groupBoxIngredients.TabStop = false; + this.groupBoxIngredients.Text = "Ингрединеты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(635, 171); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(126, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(635, 124); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(126, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(635, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(126, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(635, 26); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(126, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.PastryId, + this.IngredientName, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 26); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(496, 308); + this.dataGridView.TabIndex = 0; + // + // PastryId + // + this.PastryId.HeaderText = "Id"; + this.PastryId.MinimumWidth = 6; + this.PastryId.Name = "PastryId"; + this.PastryId.ReadOnly = true; + this.PastryId.Visible = false; + this.PastryId.Width = 125; + // + // IngredientName + // + this.IngredientName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.IngredientName.HeaderText = "Название игредиента"; + this.IngredientName.MinimumWidth = 6; + this.IngredientName.Name = "IngredientName"; + this.IngredientName.ReadOnly = true; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + this.Count.ReadOnly = true; + this.Count.Width = 125; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(520, 409); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 29); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(662, 409); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 29); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormPastry + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBoxIngredients); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormPastry"; + this.Text = "Кондитерское изделие"; + this.Load += new System.EventHandler(this.FormPastry_Load); + this.groupBoxIngredients.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxIngredients; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn PastryId; + private DataGridViewTextBoxColumn IngredientName; + 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..3006995 --- /dev/null +++ b/Confectionery/Confectionery/FormPastry.cs @@ -0,0 +1,212 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Confectionery +{ + public partial class FormPastry : Form + { + private readonly ILogger _logger; + private readonly IPastryLogic _logic; + private int? _id; + private Dictionary _pastryIngredients; + public int Id { set { _id = value; } } + + public FormPastry(ILogger logger, IPastryLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _pastryIngredients = 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(); + _pastryIngredients = view.PastryIngredients ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка ингредиентов изделия"); + try + { + if (_pastryIngredients != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _pastryIngredients) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.IngredientName, 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(FormPastryIngredient)); + if (service is FormPastryIngredient form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.IngredientModel == null) + { + return; + } + _logger.LogInformation("Добавление нового ингредиента: {IngredientName} - {Count}", form.IngredientModel.IngredientName, form.Count); + if (_pastryIngredients.ContainsKey(form.Id)) + { + _pastryIngredients[form.Id] = (form.IngredientModel, form.Count); + } + else + { + _pastryIngredients.Add(form.Id, (form.IngredientModel, form.Count)); + } + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPastryIngredient)); + if (service is FormPastryIngredient form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _pastryIngredients[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.IngredientModel == null) + { + return; + } + _logger.LogInformation("Изменение ингредиента: {IngredientName} - {Count}", form.IngredientModel.IngredientName, form.Count); + _pastryIngredients[form.Id] = (form.IngredientModel, 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("Удаление ингредиента: {IngredientName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _pastryIngredients?.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 (_pastryIngredients == null || _pastryIngredients.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), + PastryIngredients = _pastryIngredients + }; + 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 _pastryIngredients) + { + 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..8bf7ff5 --- /dev/null +++ b/Confectionery/Confectionery/FormPastry.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + \ No newline at end of file diff --git a/Confectionery/Confectionery/FormPastryIngredient.Designer.cs b/Confectionery/Confectionery/FormPastryIngredient.Designer.cs new file mode 100644 index 0000000..040da22 --- /dev/null +++ b/Confectionery/Confectionery/FormPastryIngredient.Designer.cs @@ -0,0 +1,119 @@ +namespace Confectionery +{ + partial class FormPastryIngredient + { + /// + /// 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.comboBoxIngredient = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(95, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Ингредиент:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 53); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(93, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Количество:"; + // + // comboBoxIngredient + // + this.comboBoxIngredient.FormattingEnabled = true; + this.comboBoxIngredient.Location = new System.Drawing.Point(113, 6); + this.comboBoxIngredient.Name = "comboBoxIngredient"; + this.comboBoxIngredient.Size = new System.Drawing.Size(294, 28); + this.comboBoxIngredient.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(111, 50); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(296, 27); + this.textBoxCount.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(199, 92); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(313, 92); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormPastryIngredient + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(419, 133); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxIngredient); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormPastryIngredient"; + this.Text = "Ингредиент кондитерского изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private ComboBox comboBoxIngredient; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/Confectionery/Confectionery/FormPastryIngredient.cs b/Confectionery/Confectionery/FormPastryIngredient.cs new file mode 100644 index 0000000..ccf5294 --- /dev/null +++ b/Confectionery/Confectionery/FormPastryIngredient.cs @@ -0,0 +1,77 @@ +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Confectionery +{ + public partial class FormPastryIngredient : Form + { + private readonly List? _list; + public int Id { get { return Convert.ToInt32(comboBoxIngredient.SelectedValue); } set { comboBoxIngredient.SelectedValue = value; } } + public IIngredientModel? IngredientModel + { + 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 FormPastryIngredient(IIngredientLogic logic) + { + InitializeComponent(); + + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxIngredient.DisplayMember = "IngredientName"; + comboBoxIngredient.ValueMember = "Id"; + comboBoxIngredient.DataSource = _list; + comboBoxIngredient.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxIngredient.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/FormPastryIngredient.resx b/Confectionery/Confectionery/FormPastryIngredient.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Confectionery/Confectionery/FormPastryIngredient.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..c98764e 100644 --- a/Confectionery/Confectionery/Program.cs +++ b/Confectionery/Confectionery/Program.cs @@ -1,7 +1,18 @@ +using ConfectioneryBusinessLogic.BusinessLogics; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + namespace Confectionery { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +22,32 @@ namespace Confectionery // 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/Confectionery/Properties/Resources.Designer.cs b/Confectionery/Confectionery/Properties/Resources.Designer.cs new file mode 100644 index 0000000..0332000 --- /dev/null +++ b/Confectionery/Confectionery/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Confectionery.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Confectionery.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Confectionery/Confectionery/Form1.resx b/Confectionery/Confectionery/Properties/Resources.resx similarity index 100% rename from Confectionery/Confectionery/Form1.resx rename to Confectionery/Confectionery/Properties/Resources.resx diff --git a/Confectionery/Confectionery/nlog.config b/Confectionery/Confectionery/nlog.config new file mode 100644 index 0000000..b94cde0 --- /dev/null +++ b/Confectionery/Confectionery/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs new file mode 100644 index 0000000..8dd820f --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/IngredientLogic.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace ConfectioneryBusinessLogic.BusinessLogics +{ + public class IngredientLogic : IIngredientLogic + { + private readonly ILogger _logger; + private readonly IIngredientStorage _ingredientStorage; + + public IngredientLogic(ILogger logger, IIngredientStorage ingredientStorage) + { + _logger = logger; + _ingredientStorage = ingredientStorage; + } + + public List? ReadList(IngredientSearchModel? model) + { + _logger.LogInformation("ReadList. IngredientName:{IngredientName}. Id:{Id}", model?.IngredientName, model?.Id); + var list = model == null ? _ingredientStorage.GetFullList() : _ingredientStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public IngredientViewModel? ReadElement(IngredientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. IngredientName:{IngredientName}. Id:{Id}", model.IngredientName, model.Id); + var element = _ingredientStorage.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 (IngredientBindingModel model) + { + CheckModel(model); + if (_ingredientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(IngredientBindingModel model) + { + CheckModel(model); + if (_ingredientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(IngredientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_ingredientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(IngredientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.IngredientName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.IngredientName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена ингредиента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Ingredient. IngredietnName:{IngredientName}. Cost:{Cost}. Id:{Id}", model.IngredientName, model.Cost, model.Id); + var element = _ingredientStorage.GetElement(new IngredientSearchModel + { + IngredientName = model.IngredientName + }); + 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..f35b2ce --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,149 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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 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 DeliveryOrder(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Готов) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); + } + model.Status = OrderStatus.Выдан; + model.DateImplement = DateTime.Now; + _orderStorage.Update(model); + return true; + } + + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус выполнения перед готовностью!"); + } + model.Status = OrderStatus.Готов; + _orderStorage.Update(model); + return true; + } + + 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 TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != OrderStatus.Принят) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Заказ должен быть переведен в статус принятого перед его выполнением!"); + } + model.Status = OrderStatus.Выполняется; + _orderStorage.Update(model); + return true; + } + + 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:{Sum}. Id:{Id}", model.Sum, model.Id); + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Заказ с таким ID уже существует"); + } + } + } +} diff --git a/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs new file mode 100644 index 0000000..a7d1138 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/BusinessLogics/PastryLogic.cs @@ -0,0 +1,122 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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)); + } + if (model.PastryIngredients == null || model.PastryIngredients.Count == 0) + { + throw new ArgumentNullException("Нет ингредиентов изделия", nameof(model.PastryIngredients)); + } + _logger.LogInformation("Pastry. PastryName:{PastryName}. Cost:{Cost}. 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..0eae306 --- /dev/null +++ b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs new file mode 100644 index 0000000..d3a6e12 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/IngredientBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConfectioneryDataModels.Models; + +namespace ConfectioneryContracts.BindingModels +{ + public class IngredientBindingModel : IIngredientModel + { + public int Id { get; set; } + public string IngredientName { 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..8262c80 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..845f1c6 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BindingModels/PastryBindingModel.cs @@ -0,0 +1,21 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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 PastryIngredients + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs new file mode 100644 index 0000000..2701f63 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IIngredientLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.BusinessLogicsContracts +{ + public interface IIngredientLogic + { + List? ReadList(IngredientSearchModel? model); + IngredientViewModel? ReadElement(IngredientSearchModel model); + bool Create(IngredientBindingModel model); + bool Update(IngredientBindingModel model); + bool Delete(IngredientBindingModel model); + } +} diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..7a91377 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..961f022 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IPastryLogic.cs @@ -0,0 +1,20 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..b0b970c --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ConfectioneryContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs new file mode 100644 index 0000000..e44cfca --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/IngredientSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class IngredientSearchModel + { + public int? Id { get; set; } + public string? IngredientName { get; set; } + + } +} diff --git a/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..99f81bc --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..33c17c1 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/SearchModels/PastrySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.SearchModels +{ + public class PastrySearchModel + { + public int? Id { get; set; } + public string? PastryName { get; set; } + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs new file mode 100644 index 0000000..574c861 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IIngredientStorage.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.StoragesContracts +{ + public interface IIngredientStorage + { + List GetFullList(); + List GetFilteredList(IngredientSearchModel model); + IngredientViewModel? GetElement(IngredientSearchModel model); + IngredientViewModel? Insert(IngredientBindingModel model); + IngredientViewModel? Update(IngredientBindingModel model); + IngredientViewModel? Delete(IngredientBindingModel model); + + } +} diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..cbdd94f --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..78fc0c9 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IPastryStorage.cs @@ -0,0 +1,22 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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/IngredientViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs new file mode 100644 index 0000000..81a9302 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/IngredientViewModel.cs @@ -0,0 +1,20 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryContracts.ViewModels +{ + public class IngredientViewModel : IIngredientModel + { + public int Id { get; set; } + [DisplayName("Название ингредиента")] + public string IngredientName { 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..dadab69 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..b96bfb9 --- /dev/null +++ b/Confectionery/ConfectioneryContracts/ViewModels/PastryViewModel.cs @@ -0,0 +1,24 @@ +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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 PastryIngredients + { + get; + set; + } = new(); + } +} diff --git a/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj new file mode 100644 index 0000000..27ac386 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/ConfectioneryDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..bb0ce5a --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace ConfectioneryDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryDataModels/IId.cs b/Confectionery/ConfectioneryDataModels/IId.cs new file mode 100644 index 0000000..fc8cada --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs b/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs new file mode 100644 index 0000000..de483fd --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IIngredientModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IIngredientModel : IId + { + string IngredientName { get; } + double Cost { get; } + } +} diff --git a/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..2ca229e --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IOrderModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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..b6ebab9 --- /dev/null +++ b/Confectionery/ConfectioneryDataModels/Models/IPastryModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryDataModels.Models +{ + public interface IPastryModel : IId + { + string PastryName { get; } + double Price { get; } + Dictionary PastryIngredients { get; } + } +} diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj new file mode 100644 index 0000000..41b6c3e --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs new file mode 100644 index 0000000..2cce9b4 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -0,0 +1,32 @@ +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Ingredients { get; set; } + public List Orders { get; set; } + public List Pastries { get; set; } + private DataListSingleton() + { + Ingredients = 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/IngredientStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/IngredientStorage.cs new file mode 100644 index 0000000..0c3bdcc --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/IngredientStorage.cs @@ -0,0 +1,112 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Implements +{ + public class IngredientStorage : IIngredientStorage + { + private readonly DataListSingleton _source; + public IngredientStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var ingredient in _source.Ingredients) + { + result.Add(ingredient.GetViewModel); + } + return result; + } + + public List GetFilteredList(IngredientSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.IngredientName)) + { + return result; + } + foreach (var ingredient in _source.Ingredients) + { + if (ingredient.IngredientName.Contains(model.IngredientName)) + { + result.Add(ingredient.GetViewModel); + } + } + return result; + } + + public IngredientViewModel? GetElement(IngredientSearchModel model) + { + if (string.IsNullOrEmpty(model.IngredientName) && !model.Id.HasValue) + { + return null; + } + foreach (var ingredient in _source.Ingredients) + { + if ((!string.IsNullOrEmpty(model.IngredientName) && ingredient.IngredientName == model.IngredientName) || + (model.Id.HasValue && ingredient.Id == model.Id)) + { + return ingredient.GetViewModel; + } + } + return null; + } + + public IngredientViewModel? Insert(IngredientBindingModel model) + { + model.Id = 1; + foreach (var ingredient in _source.Ingredients) + { + if (model.Id <= ingredient.Id) + { + model.Id = ingredient.Id + 1; + } + } + var newIngredient = Ingredient.Create(model); + if (newIngredient == null) + { + return null; + } + _source.Ingredients.Add(newIngredient); + return newIngredient.GetViewModel; + } + + public IngredientViewModel? Update(IngredientBindingModel model) + { + foreach (var ingredient in _source.Ingredients) + { + if (ingredient.Id == model.Id) + { + ingredient.Update(model); + return ingredient.GetViewModel; + } + } + return null; + } + + public IngredientViewModel? Delete(IngredientBindingModel model) + { + for (int i = 0; i < _source.Ingredients.Count; ++i) + { + if (_source.Ingredients[i].Id == model.Id) + { + var element = _source.Ingredients[i]; + _source.Ingredients.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..b4a058f --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/OrderStorage.cs @@ -0,0 +1,124 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +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 AccessPastryStorage(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 AccessPastryStorage(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AccessPastryStorage(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 AccessPastryStorage(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; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs b/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs new file mode 100644 index 0000000..5ffbcb2 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Implements/PastryStorage.cs @@ -0,0 +1,111 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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; + } + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs b/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs new file mode 100644 index 0000000..9d185c0 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Ingredient.cs @@ -0,0 +1,47 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement.Models +{ + public class Ingredient : IIngredientModel + { + public int Id { get; private set; } + public string IngredientName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Ingredient? Create(IngredientBindingModel? model) + { + if (model == null) + { + return null; + } + return new Ingredient() + { + Id = model.Id, + IngredientName = model.IngredientName, + Cost = model.Cost + }; + } + public void Update(IngredientBindingModel? model) + { + if (model == null) + { + return; + } + IngredientName = model.IngredientName; + Cost = model.Cost; + } + public IngredientViewModel GetViewModel => new() + { + Id = Id, + IngredientName = IngredientName, + Cost = Cost + }; + } +} diff --git a/Confectionery/ConfectioneryListImplement/Models/Order.cs b/Confectionery/ConfectioneryListImplement/Models/Order.cs new file mode 100644 index 0000000..42c0102 --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Order.cs @@ -0,0 +1,66 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Enums; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +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; + if (model.DateImplement.HasValue) 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..b4f45ed --- /dev/null +++ b/Confectionery/ConfectioneryListImplement/Models/Pastry.cs @@ -0,0 +1,50 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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 PastryIngredients { 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, + PastryIngredients = model.PastryIngredients + }; + } + public void Update(PastryBindingModel? model) + { + if (model == null) + { + return; + } + PastryName = model.PastryName; + Price = model.Price; + PastryIngredients = model.PastryIngredients; + } + public PastryViewModel GetViewModel => new() + { + Id = Id, + PastryName = PastryName, + Price = Price, + PastryIngredients = PastryIngredients + }; + } +}