diff --git a/AbstractFoodOrders/AbstractFoodOrders.sln b/AbstractFoodOrders/AbstractFoodOrders.sln deleted file mode 100644 index e961f8c..0000000 --- a/AbstractFoodOrders/AbstractFoodOrders.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32929.385 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersView", "AbstractFoodOrdersView\AbstractFoodOrdersView.csproj", "{831CD419-7329-4082-9B2F-9EA0EE2EA4AC}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractFoodOrdersDataModel", "AbstractFoodOrdersDataModel\AbstractFoodOrdersDataModel.csproj", "{FC864A68-E5FF-4015-A4B3-85B7CDD584FE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {831CD419-7329-4082-9B2F-9EA0EE2EA4AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {831CD419-7329-4082-9B2F-9EA0EE2EA4AC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {831CD419-7329-4082-9B2F-9EA0EE2EA4AC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {831CD419-7329-4082-9B2F-9EA0EE2EA4AC}.Release|Any CPU.Build.0 = Release|Any CPU - {FC864A68-E5FF-4015-A4B3-85B7CDD584FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FC864A68-E5FF-4015-A4B3-85B7CDD584FE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FC864A68-E5FF-4015-A4B3-85B7CDD584FE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FC864A68-E5FF-4015-A4B3-85B7CDD584FE}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B6811B4E-9459-44E1-80D8-752C2718AB6A} - EndGlobalSection -EndGlobal diff --git a/AbstractFoodOrders/AbstractFoodOrdersDataModel/Enums/OrderStatus.cs b/AbstractFoodOrders/AbstractFoodOrdersDataModel/Enums/OrderStatus.cs index 8e429e3..a4f0aac 100644 --- a/AbstractFoodOrders/AbstractFoodOrdersDataModel/Enums/OrderStatus.cs +++ b/AbstractFoodOrders/AbstractFoodOrdersDataModel/Enums/OrderStatus.cs @@ -10,8 +10,8 @@ namespace AbstractFoodOrdersDataModel.Enums { Неизвестен = -1, Принят = 0, - Выполняется = 2, - Готов = 3, + Выполняется = 1, + Готов = 2, Выдан = 3 } } diff --git a/AbstractFoodOrders/AbstractFoodOrdersDataModel/AbstractFoodOrdersDataModel.csproj b/AbstractFoodOrders/AbstractFoodOrdersDataModel/FoodOrdersDataModel.csproj similarity index 100% rename from AbstractFoodOrders/AbstractFoodOrdersDataModel/AbstractFoodOrdersDataModel.csproj rename to AbstractFoodOrders/AbstractFoodOrdersDataModel/FoodOrdersDataModel.csproj diff --git a/AbstractFoodOrders/AbstractFoodOrdersDataModel/Models/IOrderModel.cs b/AbstractFoodOrders/AbstractFoodOrdersDataModel/Models/IOrderModel.cs index 3c80a08..49199b9 100644 --- a/AbstractFoodOrders/AbstractFoodOrdersDataModel/Models/IOrderModel.cs +++ b/AbstractFoodOrders/AbstractFoodOrdersDataModel/Models/IOrderModel.cs @@ -9,7 +9,7 @@ namespace AbstractFoodOrdersDataModel.Models { public interface IOrderModel : IId { - int ProductId { get; } + int FoodId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/AbstractFoodOrdersView.csproj b/AbstractFoodOrders/AbstractFoodOrdersView/AbstractFoodOrdersView.csproj deleted file mode 100644 index b57c89e..0000000 --- a/AbstractFoodOrders/AbstractFoodOrdersView/AbstractFoodOrdersView.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FoodOrdersView.csproj b/AbstractFoodOrders/AbstractFoodOrdersView/FoodOrdersView.csproj new file mode 100644 index 0000000..7cd53c5 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FoodOrdersView.csproj @@ -0,0 +1,39 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/Form1.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/Form1.Designer.cs deleted file mode 100644 index 5eadd67..0000000 --- a/AbstractFoodOrders/AbstractFoodOrdersView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AbstractFoodOrdersView -{ - 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/AbstractFoodOrders/AbstractFoodOrdersView/Form1.cs b/AbstractFoodOrders/AbstractFoodOrdersView/Form1.cs deleted file mode 100644 index 90277c4..0000000 --- a/AbstractFoodOrders/AbstractFoodOrdersView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AbstractFoodOrdersView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.Designer.cs new file mode 100644 index 0000000..d4bed64 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace FoodOrdersView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ComponentNameTextBox = new System.Windows.Forms.TextBox(); + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.CostTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ComponentNameTextBox + // + this.ComponentNameTextBox.Location = new System.Drawing.Point(83, 12); + this.ComponentNameTextBox.Name = "ComponentNameTextBox"; + this.ComponentNameTextBox.Size = new System.Drawing.Size(236, 23); + this.ComponentNameTextBox.TabIndex = 0; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(13, 15); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 1; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(37, 64); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.TabIndex = 3; + this.labelCost.Text = "Цена:"; + // + // CostTextBox + // + this.CostTextBox.Location = new System.Drawing.Point(83, 61); + this.CostTextBox.Name = "CostTextBox"; + this.CostTextBox.Size = new System.Drawing.Size(234, 23); + this.CostTextBox.TabIndex = 2; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(83, 99); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(84, 23); + this.SaveButton.TabIndex = 4; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(233, 99); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(84, 23); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(332, 144); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.CostTextBox); + this.Controls.Add(this.labelName); + this.Controls.Add(this.ComponentNameTextBox); + this.Name = "FormComponent"; + this.Text = "FormComponent"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox ComponentNameTextBox; + private Label labelName; + private Label labelCost; + private TextBox CostTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.cs new file mode 100644 index 0000000..2d600cd --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.cs @@ -0,0 +1,102 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FoodOrdersView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + + if (view != null) + { + ComponentNameTextBox.Text = view.ComponentName; + CostTextBox.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(ComponentNameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение компонента"); + + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = ComponentNameTextBox.Text, + Cost = Convert.ToDouble(CostTextBox.Text) + }; + + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.resx b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponent.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/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.Designer.cs new file mode 100644 index 0000000..c845d13 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.Designer.cs @@ -0,0 +1,119 @@ +namespace AbstractShopView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonChange = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.AllowUserToAddRows = false; + this.dataGridView1.AllowUserToDeleteRows = false; + this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView1.Location = new System.Drawing.Point(0, 0); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersVisible = false; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView1.Size = new System.Drawing.Size(392, 383); + this.dataGridView1.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(398, 12); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(139, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonChange + // + this.buttonChange.Location = new System.Drawing.Point(398, 47); + this.buttonChange.Name = "buttonChange"; + this.buttonChange.Size = new System.Drawing.Size(139, 29); + this.buttonChange.TabIndex = 2; + this.buttonChange.Text = "Изменить"; + this.buttonChange.UseVisualStyleBackColor = true; + this.buttonChange.Click += new System.EventHandler(this.ChangeButton_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(398, 82); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(139, 29); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(398, 117); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(139, 29); + this.buttonUpdate.TabIndex = 4; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(540, 383); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonChange); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView1); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView1; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.cs new file mode 100644 index 0000000..e54ea42 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using AbstractFoodOrdersView; +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.BusinessLogicsContracts; +using FoodOrdersView; +using Microsoft.Extensions.Logging; + +namespace AbstractShopView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic +logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["Id"].Visible = false; + dataGridView1.Columns["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.resx b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormComponents.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/AbstractFoodOrders/AbstractFoodOrdersView/FormCreateOrder.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..44ee9a7 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormCreateOrder.Designer.cs @@ -0,0 +1,143 @@ +namespace FoodOrdersView +{ + 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.WorkNameLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.SumLabel = new System.Windows.Forms.Label(); + this.FoodComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SumTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // WorkNameLabel + // + this.WorkNameLabel.AutoSize = true; + this.WorkNameLabel.Location = new System.Drawing.Point(25, 15); + this.WorkNameLabel.Name = "WorkNameLabel"; + this.WorkNameLabel.Size = new System.Drawing.Size(59, 15); + this.WorkNameLabel.TabIndex = 0; + this.WorkNameLabel.Text = "Изделие: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(25, 44); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(78, 15); + this.CountLabel.TabIndex = 1; + this.CountLabel.Text = "Количество: "; + // + // SumLabel + // + this.SumLabel.AutoSize = true; + this.SumLabel.Location = new System.Drawing.Point(25, 76); + this.SumLabel.Name = "SumLabel"; + this.SumLabel.Size = new System.Drawing.Size(51, 15); + this.SumLabel.TabIndex = 2; + this.SumLabel.Text = "Сумма: "; + // + // FoodComboBox + // + this.FoodComboBox.FormattingEnabled = true; + this.FoodComboBox.Location = new System.Drawing.Point(111, 15); + this.FoodComboBox.Name = "FoodComboBox"; + this.FoodComboBox.Size = new System.Drawing.Size(214, 23); + this.FoodComboBox.TabIndex = 4; + this.FoodComboBox.SelectedIndexChanged += new System.EventHandler(this.FoodComboBox_SelectedIndexChanged); + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(111, 44); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(214, 23); + this.CountTextBox.TabIndex = 5; + this.CountTextBox.TextChanged += new System.EventHandler(this.CountTextBox_TextChanged); + // + // SumTextBox + // + this.SumTextBox.Location = new System.Drawing.Point(111, 73); + this.SumTextBox.Name = "SumTextBox"; + this.SumTextBox.Size = new System.Drawing.Size(214, 23); + this.SumTextBox.TabIndex = 6; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(111, 115); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(95, 23); + this.SaveButton.TabIndex = 7; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(230, 115); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(95, 23); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отменить"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ButtonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(350, 146); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.SumTextBox); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.FoodComboBox); + this.Controls.Add(this.SumLabel); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.WorkNameLabel); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label WorkNameLabel; + private Label CountLabel; + private Label SumLabel; + private ComboBox FoodComboBox; + private TextBox CountTextBox; + private TextBox SumTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormCreateOrder.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormCreateOrder.cs new file mode 100644 index 0000000..d7ec2d2 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormCreateOrder.cs @@ -0,0 +1,144 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FoodOrdersView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IFoodLogic _logicW; + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IFoodLogic logicF, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicW = logicF; + _logicO = logicO; + LoadData(); + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий для заказа"); + + try + { + var list = _logicW.ReadList(null); + if (list != null) + { + FoodComboBox.DisplayMember = "FoodName"; + FoodComboBox.ValueMember = "Id"; + FoodComboBox.DataSource = list; + FoodComboBox.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CalcSum() + { + if (FoodComboBox.SelectedValue != null && !string.IsNullOrEmpty(CountTextBox.Text)) + { + try + { + int id = Convert.ToInt32(FoodComboBox.SelectedValue); + + var product = _logicW.ReadElement(new FoodSearchModel + { + Id = id + }); + + int count = Convert.ToInt32(CountTextBox.Text); + SumTextBox.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 CountTextBox_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void FoodComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (FoodComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Создание заказа"); + + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + FoodId = Convert.ToInt32(FoodComboBox.SelectedValue), + FoodName = FoodComboBox.Text, + Count = Convert.ToInt32(CountTextBox.Text), + Sum = Convert.ToDouble(SumTextBox.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/AbstractFoodOrders/AbstractFoodOrdersView/FormCreateOrder.resx b/AbstractFoodOrders/AbstractFoodOrdersView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/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/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.Designer.cs new file mode 100644 index 0000000..f76c710 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.Designer.cs @@ -0,0 +1,225 @@ +namespace FoodOrdersView +{ + partial class FormFood + { + /// + /// 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.FoodNameLabel = new System.Windows.Forms.Label(); + this.PriceLabel = new System.Windows.Forms.Label(); + this.FoodNameTextBox = new System.Windows.Forms.TextBox(); + this.PriceTextBox = new System.Windows.Forms.TextBox(); + this.ComponentsGroupBox = new System.Windows.Forms.GroupBox(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.AddButton = new System.Windows.Forms.Button(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ComponentNameField = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.CountField = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ComponentsGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // FoodNameLabel + // + this.FoodNameLabel.AutoSize = true; + this.FoodNameLabel.Location = new System.Drawing.Point(12, 9); + this.FoodNameLabel.Name = "FoodNameLabel"; + this.FoodNameLabel.Size = new System.Drawing.Size(65, 15); + this.FoodNameLabel.TabIndex = 0; + this.FoodNameLabel.Text = "Название: "; + // + // PriceLabel + // + this.PriceLabel.AutoSize = true; + this.PriceLabel.Location = new System.Drawing.Point(12, 47); + this.PriceLabel.Name = "PriceLabel"; + this.PriceLabel.Size = new System.Drawing.Size(73, 15); + this.PriceLabel.TabIndex = 1; + this.PriceLabel.Text = "Стоимость: "; + // + // FoodNameTextBox + // + this.FoodNameTextBox.Location = new System.Drawing.Point(83, 6); + this.FoodNameTextBox.Name = "FoodNameTextBox"; + this.FoodNameTextBox.Size = new System.Drawing.Size(250, 23); + this.FoodNameTextBox.TabIndex = 2; + // + // PriceTextBox + // + this.PriceTextBox.Location = new System.Drawing.Point(83, 44); + this.PriceTextBox.Name = "PriceTextBox"; + this.PriceTextBox.Size = new System.Drawing.Size(250, 23); + this.PriceTextBox.TabIndex = 3; + // + // ComponentsGroupBox + // + this.ComponentsGroupBox.Controls.Add(this.ButtonCancel); + this.ComponentsGroupBox.Controls.Add(this.SaveButton); + this.ComponentsGroupBox.Controls.Add(this.DeleteButton); + this.ComponentsGroupBox.Controls.Add(this.UpdateButton); + this.ComponentsGroupBox.Controls.Add(this.ChangeButton); + this.ComponentsGroupBox.Controls.Add(this.AddButton); + this.ComponentsGroupBox.Controls.Add(this.dataGridView1); + this.ComponentsGroupBox.Location = new System.Drawing.Point(12, 73); + this.ComponentsGroupBox.Name = "ComponentsGroupBox"; + this.ComponentsGroupBox.Size = new System.Drawing.Size(677, 352); + this.ComponentsGroupBox.TabIndex = 4; + this.ComponentsGroupBox.TabStop = false; + this.ComponentsGroupBox.Text = "Компоненты"; + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(521, 137); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(150, 38); + this.DeleteButton.TabIndex = 4; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(521, 192); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(150, 38); + this.UpdateButton.TabIndex = 3; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(521, 79); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(150, 38); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(521, 22); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(150, 38); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.ComponentNameField, + this.CountField}); + this.dataGridView1.Location = new System.Drawing.Point(6, 22); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(509, 285); + this.dataGridView1.TabIndex = 0; + // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // ComponentNameField + // + this.ComponentNameField.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ComponentNameField.HeaderText = "Компонент"; + this.ComponentNameField.Name = "ComponentNameField"; + // + // CountField + // + this.CountField.HeaderText = "Количество"; + this.CountField.Name = "CountField"; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(469, 321); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(98, 23); + this.SaveButton.TabIndex = 5; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(573, 321); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(98, 23); + this.ButtonCancel.TabIndex = 6; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormFood + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(701, 429); + this.Controls.Add(this.ComponentsGroupBox); + this.Controls.Add(this.PriceTextBox); + this.Controls.Add(this.FoodNameTextBox); + this.Controls.Add(this.PriceLabel); + this.Controls.Add(this.FoodNameLabel); + this.Name = "FormFood"; + this.Text = "Изделие"; + this.ComponentsGroupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label FoodNameLabel; + private Label PriceLabel; + private TextBox FoodNameTextBox; + private TextBox PriceTextBox; + private GroupBox ComponentsGroupBox; + private Button ChangeButton; + private Button AddButton; + private DataGridView dataGridView1; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ComponentNameField; + private DataGridViewTextBoxColumn CountField; + private Button DeleteButton; + private Button UpdateButton; + private Button ButtonCancel; + private Button SaveButton; + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.cs new file mode 100644 index 0000000..6b28b90 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.cs @@ -0,0 +1,238 @@ +using AbstractFoodOrdersDataModel.Models; +using AbstractFoodOrdersView; +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FoodOrdersView +{ + public partial class FormFood : Form + { + private readonly ILogger _logger; + + private readonly IFoodLogic _logic; + + private int? _id; + + private Dictionary _workComponents; + + public int Id { set { _id = value; } } + public FormFood(ILogger logger, IFoodLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _workComponents = new Dictionary(); + } + private void FormFood_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + + try + { + var view = _logic.ReadElement(new FoodSearchModel + { + Id = _id.Value + }); + + if (view != null) + { + FoodNameTextBox.Text = view.FoodName; + PriceTextBox.Text = view.Price.ToString(); + _workComponents = view.FoodComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + + try + { + if (_workComponents != null) + { + dataGridView1.Rows.Clear(); + foreach (var pc in _workComponents) + { + dataGridView1.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + PriceTextBox.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFoodComponent)); + + if (service is FormFoodComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + + if (_workComponents.ContainsKey(form.Id)) + { + _workComponents[form.Id] = (form.ComponentModel, form.Count); + } + + else + { + _workComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + + LoadData(); + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFoodComponent)); + + if (service is FormFoodComponent form) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _workComponents[id].Item2; + + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _workComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView1.SelectedRows[0].Cells[1].Value); + _workComponents?.Remove(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FoodNameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(PriceTextBox.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (_workComponents == null || _workComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение изделия"); + + try + { + var model = new FoodBindingModel + { + Id = _id ?? 0, + FoodName = FoodNameTextBox.Text, + Price = Convert.ToDouble(PriceTextBox.Text), + FoodComponents = _workComponents + }; + + 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 _workComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.resx b/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.resx new file mode 100644 index 0000000..7c56f52 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFood.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.Designer.cs new file mode 100644 index 0000000..206d772 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace FoodOrdersView +{ + partial class FormFoodComponent + { + /// + /// 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.ComponentComboBox = new System.Windows.Forms.ComboBox(); + this.ComponentSelectLabel = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // ComponentComboBox + // + this.ComponentComboBox.FormattingEnabled = true; + this.ComponentComboBox.Location = new System.Drawing.Point(108, 12); + this.ComponentComboBox.Name = "ComponentComboBox"; + this.ComponentComboBox.Size = new System.Drawing.Size(234, 23); + this.ComponentComboBox.TabIndex = 0; + // + // ComponentSelectLabel + // + this.ComponentSelectLabel.AutoSize = true; + this.ComponentSelectLabel.Location = new System.Drawing.Point(27, 15); + this.ComponentSelectLabel.Name = "ComponentSelectLabel"; + this.ComponentSelectLabel.Size = new System.Drawing.Size(75, 15); + this.ComponentSelectLabel.TabIndex = 1; + this.ComponentSelectLabel.Text = "Компонент: "; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(27, 53); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(75, 15); + this.label1.TabIndex = 2; + this.label1.Text = "Количество:"; + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(108, 50); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(234, 23); + this.CountTextBox.TabIndex = 3; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(108, 87); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(89, 23); + this.SaveButton.TabIndex = 4; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(253, 87); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(89, 23); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormFoodComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(354, 122); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.label1); + this.Controls.Add(this.ComponentSelectLabel); + this.Controls.Add(this.ComponentComboBox); + this.Name = "FormFoodComponent"; + this.Text = "Компоненты изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox ComponentComboBox; + private Label ComponentSelectLabel; + private Label label1; + private TextBox CountTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.cs new file mode 100644 index 0000000..7adcb9c --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.cs @@ -0,0 +1,90 @@ +using AbstractFoodOrdersDataModel.Models; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopContracts.ViewModels; +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 FoodOrdersView +{ + public partial class FormFoodComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(ComponentComboBox.SelectedValue); + } + set + { + ComponentComboBox.SelectedValue = value; + } + } + + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + public FormFoodComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + ComponentComboBox.DisplayMember = "ComponentName"; + ComponentComboBox.ValueMember = "Id"; + ComponentComboBox.DataSource = _list; + ComponentComboBox.SelectedItem = null; + } + } + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (ComponentComboBox.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/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.resx b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoodComponent.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/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.Designer.cs new file mode 100644 index 0000000..9be2393 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.Designer.cs @@ -0,0 +1,120 @@ +namespace FoodOrdersView +{ + partial class Изделия + { + /// + /// 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.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButtoan = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(12, 12); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(572, 426); + this.dataGridView1.TabIndex = 0; + // + // AddButton + // + this.AddButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.AddButton.Location = new System.Drawing.Point(590, 13); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(109, 35); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.ChangeButton.Location = new System.Drawing.Point(590, 63); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(109, 35); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.DeleteButton.Location = new System.Drawing.Point(590, 113); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(109, 35); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButtoan + // + this.UpdateButtoan.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.UpdateButtoan.Location = new System.Drawing.Point(590, 163); + this.UpdateButtoan.Name = "UpdateButtoan"; + this.UpdateButtoan.Size = new System.Drawing.Size(109, 35); + this.UpdateButtoan.TabIndex = 4; + this.UpdateButtoan.Text = "Обновить"; + this.UpdateButtoan.UseVisualStyleBackColor = true; + this.UpdateButtoan.Click += new System.EventHandler(this.UpdateButton_Click); + // + // Изделия + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(711, 450); + this.Controls.Add(this.UpdateButtoan); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.dataGridView1); + this.Name = "Изделия"; + this.Text = "Изделия"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView1; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButtoan; + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.cs new file mode 100644 index 0000000..46e8598 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.cs @@ -0,0 +1,121 @@ +using AbstractFoodOrdersView; +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.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 FoodOrdersView +{ + public partial class Изделия : Form + { + private readonly ILogger _logger; + private readonly IFoodLogic _logic; + + public Изделия(ILogger<Изделия> logger, IFoodLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["Id"].Visible = false; + dataGridView1.Columns["FoodName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["FoodComponents"].Visible = false; + } + + _logger.LogInformation("Загрузка изделий"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFood)); + + if (service is FormFood form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormFood)); + + if (service is FormFood form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление изделия"); + + try + { + if (!_logic.Delete(new FoodBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.resx b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormFoods.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/AbstractFoodOrders/AbstractFoodOrdersView/FormMain.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormMain.Designer.cs new file mode 100644 index 0000000..b2a5b4f --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormMain.Designer.cs @@ -0,0 +1,181 @@ +namespace FoodOrdersView +{ + 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.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.CreateOrderButton = new System.Windows.Forms.Button(); + this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); + this.OrderReadyButton = new System.Windows.Forms.Button(); + this.IssuedOrderButton = new System.Windows.Forms.Button(); + this.UpdateListButton = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + 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(700, 24); + 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(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // dataGridView1 + // + this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(0, 27); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(568, 341); + this.dataGridView1.TabIndex = 1; + // + // CreateOrderButton + // + this.CreateOrderButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.CreateOrderButton.Location = new System.Drawing.Point(574, 27); + this.CreateOrderButton.Name = "CreateOrderButton"; + this.CreateOrderButton.Size = new System.Drawing.Size(122, 41); + this.CreateOrderButton.TabIndex = 2; + this.CreateOrderButton.Text = "Создать заказ"; + this.CreateOrderButton.UseVisualStyleBackColor = true; + this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click); + // + // TakeOrderInWorkButton + // + this.TakeOrderInWorkButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.TakeOrderInWorkButton.Location = new System.Drawing.Point(574, 74); + this.TakeOrderInWorkButton.Name = "TakeOrderInWorkButton"; + this.TakeOrderInWorkButton.Size = new System.Drawing.Size(122, 41); + this.TakeOrderInWorkButton.TabIndex = 3; + this.TakeOrderInWorkButton.Text = "Отдать на выполнение"; + this.TakeOrderInWorkButton.UseVisualStyleBackColor = true; + this.TakeOrderInWorkButton.Click += new System.EventHandler(this.TakeOrderInWorkButton_Click); + // + // OrderReadyButton + // + this.OrderReadyButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.OrderReadyButton.Location = new System.Drawing.Point(574, 121); + this.OrderReadyButton.Name = "OrderReadyButton"; + this.OrderReadyButton.Size = new System.Drawing.Size(122, 41); + this.OrderReadyButton.TabIndex = 4; + this.OrderReadyButton.Text = "Заказ готов"; + this.OrderReadyButton.UseVisualStyleBackColor = true; + this.OrderReadyButton.Click += new System.EventHandler(this.OrderReadyButton_Click); + // + // IssuedOrderButton + // + this.IssuedOrderButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.IssuedOrderButton.Location = new System.Drawing.Point(574, 168); + this.IssuedOrderButton.Name = "IssuedOrderButton"; + this.IssuedOrderButton.Size = new System.Drawing.Size(122, 41); + this.IssuedOrderButton.TabIndex = 5; + this.IssuedOrderButton.Text = "Заказ выдан"; + this.IssuedOrderButton.UseVisualStyleBackColor = true; + this.IssuedOrderButton.Click += new System.EventHandler(this.IssuedOrderButton_Click); + // + // UpdateListButton + // + this.UpdateListButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.UpdateListButton.Location = new System.Drawing.Point(574, 215); + this.UpdateListButton.Name = "UpdateListButton"; + this.UpdateListButton.Size = new System.Drawing.Size(122, 41); + this.UpdateListButton.TabIndex = 6; + this.UpdateListButton.Text = "Обновить список"; + this.UpdateListButton.UseVisualStyleBackColor = true; + this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 380); + this.Controls.Add(this.UpdateListButton); + this.Controls.Add(this.IssuedOrderButton); + this.Controls.Add(this.OrderReadyButton); + this.Controls.Add(this.TakeOrderInWorkButton); + this.Controls.Add(this.CreateOrderButton); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Заказ еды"; + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private DataGridView dataGridView1; + private Button CreateOrderButton; + private Button TakeOrderInWorkButton; + private Button OrderReadyButton; + private Button IssuedOrderButton; + private Button UpdateListButton; + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormMain.cs b/AbstractFoodOrders/AbstractFoodOrdersView/FormMain.cs new file mode 100644 index 0000000..2cd58b0 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/FormMain.cs @@ -0,0 +1,201 @@ +using AbstractFoodOrdersDataModel.Enums; +using AbstractFoodOrdersView; +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopView; +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 FoodOrdersView +{ + 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) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["FoodId"].Visible = false; + } + + _logger.LogInformation("Загрузка заказов"); + } + 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(FormComponents)); + + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(Изделия)); + + if (service is Изделия form) + { + form.ShowDialog(); + } + } + + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void TakeOrderInWorkButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Принят'", id); + + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + FoodId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["FoodId"].Value), + FoodName = dataGridView1.SelectedRows[0].Cells["FoodName"].Value.ToString(), + Status = Enum.Parse(dataGridView1.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView1.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView1.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void IssuedOrderButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + FoodId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["FoodId"].Value), + FoodName = dataGridView1.SelectedRows[0].Cells["FoodName"].Value.ToString(), + Status = Enum.Parse(dataGridView1.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView1.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView1.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void OrderReadyButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + FoodId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["FoodId"].Value), + FoodName = dataGridView1.SelectedRows[0].Cells["FoodName"].Value.ToString(), + Status = Enum.Parse(dataGridView1.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView1.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView1.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + + 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 UpdateListButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/FormMain.resx b/AbstractFoodOrders/AbstractFoodOrdersView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/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/AbstractFoodOrders/AbstractFoodOrdersView/Program.cs b/AbstractFoodOrders/AbstractFoodOrdersView/Program.cs index fd46dc9..bebd53b 100644 --- a/AbstractFoodOrders/AbstractFoodOrdersView/Program.cs +++ b/AbstractFoodOrders/AbstractFoodOrdersView/Program.cs @@ -1,17 +1,53 @@ +using AbstractShopBusinessLogic.BusinessLogic; +using AbstractShopBusinessLogic.BusinessLogics; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopContracts.StoragesContracts; +using AbstractShopListImplement.Implements; +using AbstractShopView; +using FoodOrdersView; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using PlumbingRepairBusinessLogic.BusinessLogic; + namespace AbstractFoodOrdersView { internal static class Program { + private static IServiceProvider? _serviceProvider; + public static IServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. 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 + } \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/Properties/Resources.Designer.cs b/AbstractFoodOrders/AbstractFoodOrdersView/Properties/Resources.Designer.cs new file mode 100644 index 0000000..458df60 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace FoodOrdersView.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("FoodOrdersView.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/AbstractFoodOrders/AbstractFoodOrdersView/Form1.resx b/AbstractFoodOrders/AbstractFoodOrdersView/Properties/Resources.resx similarity index 100% rename from AbstractFoodOrders/AbstractFoodOrdersView/Form1.resx rename to AbstractFoodOrders/AbstractFoodOrdersView/Properties/Resources.resx diff --git a/AbstractFoodOrders/AbstractFoodOrdersView/nlog.config b/AbstractFoodOrders/AbstractFoodOrdersView/nlog.config new file mode 100644 index 0000000..dcd37c8 --- /dev/null +++ b/AbstractFoodOrders/AbstractFoodOrdersView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/ComponentLogic.cs b/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..9c7fe33 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -0,0 +1,109 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.StoragesContracts; +using AbstractShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +namespace AbstractShopBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : + _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{ Id} ", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента",nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/FoodLogic.cs b/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/FoodLogic.cs new file mode 100644 index 0000000..648d591 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/FoodLogic.cs @@ -0,0 +1,142 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.StoragesContracts; +using AbstractShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopBusinessLogic.BusinessLogic +{ + public class FoodLogic : IFoodLogic + { + private readonly ILogger _logger; + + private readonly IFoodStorage _foodStorage; + + public FoodLogic(ILogger logger, IFoodStorage foodStorage) + { + _logger = logger; + _foodStorage = foodStorage; + } + + public bool Create(FoodBindingModel model) + { + CheckModel(model); + + if (_foodStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Delete(FoodBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_foodStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + public FoodViewModel? ReadElement(FoodSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. FoodName:{FoodName}.Id:{ Id}", model.FoodName, model.Id); + + var element = _foodStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } + + public List? ReadList(FoodSearchModel? model) + { + _logger.LogInformation("ReadList. FoodName:{FoodName}.Id:{ Id}", model?.FoodName, model?.Id); + + var list = model == null ? _foodStorage.GetFullList() : _foodStorage.GetFilteredList(model); + + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + + return list; + } + + public bool Update(FoodBindingModel model) + { + CheckModel(model); + + if (_foodStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + private void CheckModel(FoodBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.FoodName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.FoodName)); + } + + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + + _logger.LogInformation("Work. FoodName:{FoodName}.Price:{ Cost}. Id: { Id}", model.FoodName, model.Price, model.Id); + + var element = _foodStorage.GetElement(new FoodSearchModel + { + FoodName = model.FoodName + }); + + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/OrderLogic.cs b/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..292d5c2 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,135 @@ +using AbstractFoodOrdersDataModel.Enums; +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.BusinessLogicsContracts; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.StoragesContracts; +using AbstractShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairBusinessLogic.BusinessLogic +{ + 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.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model); + + if (model.Status + 1 != newStatus) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("Order. OrderId:{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; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (model.FoodId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.FoodId)); + } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + + _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.FoodId); + } + } +} diff --git a/AbstractFoodOrders/AbstractShopBusinessLogic/FoodOrderBusinessLogic.csproj b/AbstractFoodOrders/AbstractShopBusinessLogic/FoodOrderBusinessLogic.csproj new file mode 100644 index 0000000..48c442d --- /dev/null +++ b/AbstractFoodOrders/AbstractShopBusinessLogic/FoodOrderBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/AbstractFoodOrders/AbstractShopContracts/BindingModels/ComponentBindingModel.cs b/AbstractFoodOrders/AbstractShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..178f273 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,19 @@ +using AbstractFoodOrdersDataModel.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + + public double Cost { get; set; } + + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/BindingModels/FoodBindingModel.cs b/AbstractFoodOrders/AbstractShopContracts/BindingModels/FoodBindingModel.cs new file mode 100644 index 0000000..e61cd65 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/BindingModels/FoodBindingModel.cs @@ -0,0 +1,20 @@ +using AbstractFoodOrdersDataModel.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.BindingModels +{ + public class FoodBindingModel : IFoodModel + { + public int Id { get; set; } + public string FoodName { get; set; } = string.Empty; + + public double Price { get; set; } + + public Dictionary FoodComponents { get; set; } = new(); + + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/BindingModels/OrderBindingModel.cs b/AbstractFoodOrders/AbstractShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..af98182 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,28 @@ +using AbstractFoodOrdersDataModel.Enums; +using AbstractFoodOrdersDataModel.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int FoodId { get; set; } + public string FoodName { get; set; } = string.Empty; + + 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/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IComponentLogic.cs b/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..1f67bd0 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel? model); + bool Create(ComponentBindingModel? model); + bool Update(ComponentBindingModel? model); + bool Delete(ComponentBindingModel? model); + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IFoodLogic.cs b/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IFoodLogic.cs new file mode 100644 index 0000000..871b885 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IFoodLogic.cs @@ -0,0 +1,15 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.ViewModels; + +namespace AbstractShopContracts.BusinessLogicsContracts +{ + public interface IFoodLogic + { + List? ReadList(FoodSearchModel? model); + FoodViewModel? ReadElement(FoodSearchModel? model); + bool Create(FoodBindingModel? model); + bool Update(FoodBindingModel? model); + bool Delete(FoodBindingModel? model); + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..ad9d9e6 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,15 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.ViewModels; + +namespace AbstractShopContracts.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/AbstractFoodOrders/AbstractShopContracts/FoodOrdersContracts.csproj b/AbstractFoodOrders/AbstractShopContracts/FoodOrdersContracts.csproj new file mode 100644 index 0000000..544f156 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/FoodOrdersContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/AbstractFoodOrders/AbstractShopContracts/SearchModels/ComponentSearchModel.cs b/AbstractFoodOrders/AbstractShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..928f1ff --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/SearchModels/FoodSearchModel.cs b/AbstractFoodOrders/AbstractShopContracts/SearchModels/FoodSearchModel.cs new file mode 100644 index 0000000..30c3f51 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/SearchModels/FoodSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.SearchModels +{ + public class FoodSearchModel + { + public int? Id { get; set; } + public string? FoodName { get; set; } + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/SearchModels/OrderSearchModel.cs b/AbstractFoodOrders/AbstractShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..2a95ab3 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IComponentStorage.cs b/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..7c4c9c2 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,17 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.ViewModels; + +namespace AbstractShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert (ComponentBindingModel model); + ComponentViewModel? Update (ComponentBindingModel model); + ComponentViewModel? Delete (ComponentBindingModel model); + + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IFoodStorage.cs b/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IFoodStorage.cs new file mode 100644 index 0000000..b893503 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IFoodStorage.cs @@ -0,0 +1,21 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.StoragesContracts +{ + public interface IFoodStorage + { + List GetFullList(); + List GetFilteredList(FoodSearchModel model); + FoodViewModel? GetElement(FoodSearchModel model); + FoodViewModel? Insert(FoodBindingModel model); + FoodViewModel? Update(FoodBindingModel model); + FoodViewModel? Delete(FoodBindingModel model); + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IOrderStorage.cs b/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..7cf0126 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.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/AbstractFoodOrders/AbstractShopContracts/ViewModels/ComponentViewModel.cs b/AbstractFoodOrders/AbstractShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..a21679b --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,20 @@ +using AbstractFoodOrdersDataModel.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id {get; set;} + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/ViewModels/FoodViewModel.cs b/AbstractFoodOrders/AbstractShopContracts/ViewModels/FoodViewModel.cs new file mode 100644 index 0000000..a9e3d4d --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/ViewModels/FoodViewModel.cs @@ -0,0 +1,24 @@ +using AbstractFoodOrdersDataModel.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.ViewModels +{ + public class FoodViewModel : IFoodModel + { + public int Id {get; set; } + + [DisplayName("Название продукта")] + public string FoodName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary FoodComponents { get; set; } = new(); + + } +} diff --git a/AbstractFoodOrders/AbstractShopContracts/ViewModels/OrderViewModel.cs b/AbstractFoodOrders/AbstractShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..a528a9c --- /dev/null +++ b/AbstractFoodOrders/AbstractShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,36 @@ +using AbstractFoodOrdersDataModel.Enums; +using AbstractFoodOrdersDataModel.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName(" Номер ")] + public int Id { get; set; } + public int FoodId { get; set; } + [DisplayName(" Изделие ")] + public string FoodName { 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/AbstractFoodOrders/AbstractShopListImplement/DataListSingleton.cs b/AbstractFoodOrders/AbstractShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..846c8b5 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using AbstractShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Foods { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Foods = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/AbstractFoodOrders/AbstractShopListImplement/FoodOrdersListImplement.csproj b/AbstractFoodOrders/AbstractShopListImplement/FoodOrdersListImplement.csproj new file mode 100644 index 0000000..89b36c7 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopListImplement/FoodOrdersListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/AbstractFoodOrders/AbstractShopListImplement/Implements/ComponentStorage.cs b/AbstractFoodOrders/AbstractShopListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..326455b --- /dev/null +++ b/AbstractFoodOrders/AbstractShopListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,108 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.StoragesContracts; +using AbstractShopContracts.ViewModels; +using AbstractShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractShopListImplement/Implements/FoodStorage.cs b/AbstractFoodOrders/AbstractShopListImplement/Implements/FoodStorage.cs new file mode 100644 index 0000000..30363e6 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopListImplement/Implements/FoodStorage.cs @@ -0,0 +1,125 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.StoragesContracts; +using AbstractShopContracts.ViewModels; +using AbstractShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopListImplement.Implements +{ + public class FoodStorage : IFoodStorage + { + private readonly DataListSingleton _source; + public FoodStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + + foreach (var work in _source.Foods) + { + result.Add(work.GetViewModel); + } + + return result; + } + + public List GetFilteredList(FoodSearchModel model) + { + var result = new List(); + + if (string.IsNullOrEmpty(model.FoodName)) + { + return result; + } + + foreach (var work in _source.Foods) + { + if (work.FoodName.Contains(model.FoodName)) + { + result.Add(work.GetViewModel); + } + } + + return result; + } + + public FoodViewModel? GetElement(FoodSearchModel model) + { + if (string.IsNullOrEmpty(model.FoodName) && !model.Id.HasValue) + { + return null; + } + + foreach (var work in _source.Foods) + { + if ((!string.IsNullOrEmpty(model.FoodName) && work.FoodName == model.FoodName) || (model.Id.HasValue && work.Id == model.Id)) + { + return work.GetViewModel; + } + } + + return null; + } + + public FoodViewModel? Insert(FoodBindingModel model) + { + model.Id = 1; + + foreach (var work in _source.Foods) + { + if (model.Id <= work.Id) + { + model.Id = work.Id + 1; + } + } + + var newWork = Food.Create(model); + + if (newWork == null) + { + return null; + } + + _source.Foods.Add(newWork); + + return newWork.GetViewModel; + } + + public FoodViewModel? Update(FoodBindingModel model) + { + foreach (var work in _source.Foods) + { + if (work.Id == model.Id) + { + work.Update(model); + return work.GetViewModel; + } + } + + return null; + } + + public FoodViewModel? Delete(FoodBindingModel model) + { + for (int i = 0; i < _source.Foods.Count; ++i) + { + if (_source.Foods[i].Id == model.Id) + { + var element = _source.Foods[i]; + _source.Foods.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} + diff --git a/AbstractFoodOrders/AbstractShopListImplement/Implements/OrderStorage.cs b/AbstractFoodOrders/AbstractShopListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..f813c71 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopListImplement/Implements/OrderStorage.cs @@ -0,0 +1,124 @@ +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.SearchModels; +using AbstractShopContracts.StoragesContracts; +using AbstractShopContracts.ViewModels; +using AbstractShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopListImplement.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(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 (model.Id.HasValue && order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + + return null; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + _source.Orders.Add(newOrder); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + + return null; + } + } +} diff --git a/AbstractFoodOrders/AbstractShopListImplement/Models/Component.cs b/AbstractFoodOrders/AbstractShopListImplement/Models/Component.cs new file mode 100644 index 0000000..5d91693 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using AbstractFoodOrdersDataModel.Models; +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopListImplement.Models +{ + internal class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} \ No newline at end of file diff --git a/AbstractFoodOrders/AbstractShopListImplement/Models/Food.cs b/AbstractFoodOrders/AbstractShopListImplement/Models/Food.cs new file mode 100644 index 0000000..8b529f5 --- /dev/null +++ b/AbstractFoodOrders/AbstractShopListImplement/Models/Food.cs @@ -0,0 +1,54 @@ +using AbstractFoodOrdersDataModel.Models; +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopListImplement.Models +{ + public class Food : IFoodModel + { + public int Id { get; private set; } + public string FoodName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary FoodComponents + { + get; + private set; + } = new Dictionary(); + public static Food? Create(FoodBindingModel? model) + { + if (model == null) + { + return null; + } + return new Food() + { + Id = model.Id, + FoodName = model.FoodName, + Price = model.Price, + FoodComponents = model.FoodComponents + }; + } + public void Update(FoodBindingModel? model) + { + if (model == null) + { + return; + } + FoodName = model.FoodName; + Price = model.Price; + FoodComponents = model.FoodComponents; + } + public FoodViewModel GetViewModel => new() + { + Id = Id, + FoodName = FoodName, + Price = Price, + FoodComponents = FoodComponents + }; + } +} diff --git a/AbstractFoodOrders/AbstractShopListImplement/Models/Order.cs b/AbstractFoodOrders/AbstractShopListImplement/Models/Order.cs new file mode 100644 index 0000000..8d4d1bb --- /dev/null +++ b/AbstractFoodOrders/AbstractShopListImplement/Models/Order.cs @@ -0,0 +1,71 @@ +using AbstractFoodOrdersDataModel.Enums; +using AbstractFoodOrdersDataModel.Models; +using AbstractShopContracts.BindingModels; +using AbstractShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractShopListImplement.Models +{ + internal class Order : IOrderModel + { + public int Id { get; private set; } + public int FoodId { get; private set; } + public string FoodName { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + FoodId = model.FoodId, + FoodName = model.FoodName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + FoodId = model.FoodId; + FoodName = model.FoodName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + FoodId = FoodId, + FoodName = FoodName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} + diff --git a/AbstractFoodOrders/FoodOrders.sln b/AbstractFoodOrders/FoodOrders.sln new file mode 100644 index 0000000..105ea8c --- /dev/null +++ b/AbstractFoodOrders/FoodOrders.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersView", "AbstractFoodOrdersView\FoodOrdersView.csproj", "{831CD419-7329-4082-9B2F-9EA0EE2EA4AC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersDataModel", "AbstractFoodOrdersDataModel\FoodOrdersDataModel.csproj", "{FC864A68-E5FF-4015-A4B3-85B7CDD584FE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersContracts", "AbstractShopContracts\FoodOrdersContracts.csproj", "{D189A77F-A5BF-4C88-A412-97D160F73062}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersListImplement", "AbstractShopListImplement\FoodOrdersListImplement.csproj", "{9F3DC091-FE2A-461A-92CE-8289205E6AAC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrderBusinessLogic", "AbstractShopBusinessLogic\FoodOrderBusinessLogic.csproj", "{B3E18E56-A55D-47DC-8BFD-51689EE95375}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {831CD419-7329-4082-9B2F-9EA0EE2EA4AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {831CD419-7329-4082-9B2F-9EA0EE2EA4AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {831CD419-7329-4082-9B2F-9EA0EE2EA4AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {831CD419-7329-4082-9B2F-9EA0EE2EA4AC}.Release|Any CPU.Build.0 = Release|Any CPU + {FC864A68-E5FF-4015-A4B3-85B7CDD584FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC864A68-E5FF-4015-A4B3-85B7CDD584FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC864A68-E5FF-4015-A4B3-85B7CDD584FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC864A68-E5FF-4015-A4B3-85B7CDD584FE}.Release|Any CPU.Build.0 = Release|Any CPU + {D189A77F-A5BF-4C88-A412-97D160F73062}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D189A77F-A5BF-4C88-A412-97D160F73062}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D189A77F-A5BF-4C88-A412-97D160F73062}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D189A77F-A5BF-4C88-A412-97D160F73062}.Release|Any CPU.Build.0 = Release|Any CPU + {9F3DC091-FE2A-461A-92CE-8289205E6AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F3DC091-FE2A-461A-92CE-8289205E6AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F3DC091-FE2A-461A-92CE-8289205E6AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F3DC091-FE2A-461A-92CE-8289205E6AAC}.Release|Any CPU.Build.0 = Release|Any CPU + {B3E18E56-A55D-47DC-8BFD-51689EE95375}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B3E18E56-A55D-47DC-8BFD-51689EE95375}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B3E18E56-A55D-47DC-8BFD-51689EE95375}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B3E18E56-A55D-47DC-8BFD-51689EE95375}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B6811B4E-9459-44E1-80D8-752C2718AB6A} + EndGlobalSection +EndGlobal