diff --git a/SushiBar/SushiBar/FormCreateOrder.cs b/SushiBar/SushiBar/FormCreateOrder.cs index eed5d1b..0e8909b 100644 --- a/SushiBar/SushiBar/FormCreateOrder.cs +++ b/SushiBar/SushiBar/FormCreateOrder.cs @@ -78,6 +78,7 @@ namespace SushiBar var operationResult = _logicO.CreateOrder(new OrderBindingModel { SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), + SushiName = comboBoxSushi.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/SushiBar/SushiBar/FormMain.Designer.cs b/SushiBar/SushiBar/FormMain.Designer.cs index 81f4b35..709f9ea 100644 --- a/SushiBar/SushiBar/FormMain.Designer.cs +++ b/SushiBar/SushiBar/FormMain.Designer.cs @@ -132,7 +132,7 @@ this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.sushiToolStripMenuItem.Text = "Sushi"; - this.sushiToolStripMenuItem.Click += new System.EventHandler(this.sushiToolStripMenuItem_Click); + this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click); // // FormMain // diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index b75d098..b25ada8 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -1,15 +1,7 @@ using Microsoft.Extensions.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; -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 SushiBarDataModels.Enums; namespace SushiBar { @@ -62,7 +54,15 @@ namespace SushiBar _logger.LogInformation("Order №{id}. Change statuc on -Submit", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { + Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); if (!operationResult) { throw new Exception("Error on saving. Additional info below."); @@ -86,7 +86,15 @@ namespace SushiBar _logger.LogInformation("Order №{id}. Change status on -Ready",id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { + Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString() ?? "", + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString() ?? "Unkown"), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString() ?? "0"), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString() ?? ""), + }); if (!operationResult) { throw new Exception("Error on saving. Additional info below."); @@ -110,7 +118,15 @@ namespace SushiBar _logger.LogInformation("Order №{id}. Change status on -Issued", id); try { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { + Id = id, + SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), + SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); if (!operationResult) { throw new Exception("Error on saving. Additional info below."); @@ -145,11 +161,11 @@ namespace SushiBar } } - private void sushiToolStripMenuItem_Click(object sender, EventArgs e) + private void SushiToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormSushi)); + var service = Program.ServiceProvider?.GetService(typeof(FormSushiMoreThenOne)); - if (service is FormSushi form) + if (service is FormSushiMoreThenOne form) { form.ShowDialog(); } diff --git a/SushiBar/SushiBar/FormSushi.Designer.cs b/SushiBar/SushiBar/FormSushi.Designer.cs index dc821d8..b25ccaf 100644 --- a/SushiBar/SushiBar/FormSushi.Designer.cs +++ b/SushiBar/SushiBar/FormSushi.Designer.cs @@ -38,10 +38,11 @@ this.buttonEdit = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Value = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -136,25 +137,15 @@ // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, this.Component, - this.Count}); + this.Value}); this.dataGridView.Location = new System.Drawing.Point(6, 22); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 25; this.dataGridView.Size = new System.Drawing.Size(625, 315); this.dataGridView.TabIndex = 0; // - // Component - // - this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Component.HeaderText = "Component"; - this.Component.Name = "Component"; - // - // Count - // - this.Count.HeaderText = "Count"; - this.Count.Name = "Count"; - // // buttonCancel // this.buttonCancel.Location = new System.Drawing.Point(658, 415); @@ -175,6 +166,23 @@ this.buttonSave.UseVisualStyleBackColor = true; this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); // + // ID + // + this.ID.HeaderText = "Id"; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // Component + // + this.Component.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Component.HeaderText = "ComponentName"; + this.Component.Name = "Component"; + // + // Value + // + this.Value.HeaderText = "Count"; + this.Value.Name = "Value"; + // // FormSushi // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -209,9 +217,10 @@ private Button buttonEdit; private Button buttonAdd; private DataGridView dataGridView; - private DataGridViewTextBoxColumn Component; - private DataGridViewTextBoxColumn Count; private Button buttonCancel; private Button buttonSave; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Value; } } \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushi.cs b/SushiBar/SushiBar/FormSushi.cs index 699c58c..8c6f484 100644 --- a/SushiBar/SushiBar/FormSushi.cs +++ b/SushiBar/SushiBar/FormSushi.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using Microsoft.VisualBasic.Logging; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; @@ -40,9 +39,8 @@ namespace SushiBar } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонент изделия"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Error loading components for sushi"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -51,7 +49,7 @@ namespace SushiBar double price = 0; foreach (var elem in _sushiComponents) { - price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + price += (elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2; } return Math.Round(price * 1.1, 2); diff --git a/SushiBar/SushiBar/FormSushi.resx b/SushiBar/SushiBar/FormSushi.resx index 9c00fcb..567000b 100644 --- a/SushiBar/SushiBar/FormSushi.resx +++ b/SushiBar/SushiBar/FormSushi.resx @@ -57,10 +57,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + True - + True \ No newline at end of file diff --git a/SushiBar/SushiBar/FormSushiMoreThenOne.cs b/SushiBar/SushiBar/FormSushiMoreThenOne.cs index 90fa957..c7404ec 100644 --- a/SushiBar/SushiBar/FormSushiMoreThenOne.cs +++ b/SushiBar/SushiBar/FormSushiMoreThenOne.cs @@ -27,9 +27,7 @@ namespace SushiBar dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["SushiComponents"].Visible = false; } - _logger.LogInformation("Load sushi"); - } catch (Exception ex) { diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 6b27301..a85d1ec 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -22,7 +22,15 @@ namespace SushiBarBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); + + if (model.Status != OrderStatus.Unknown) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + model.Status = OrderStatus.Accepted; + if (_orderStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -33,7 +41,7 @@ namespace SushiBarBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel model) { - return UpdateStatus(model, OrderStatus.Issued); + return UpdateStatus(model, OrderStatus.Ready); } public bool FinishOrder(OrderBindingModel model) @@ -75,7 +83,7 @@ namespace SushiBarBusinessLogic.BusinessLogics return false; } model.Status = status; - if (model.Status is OrderStatus.Issued) + if (model.Status == OrderStatus.Issued) { model.DateImplement = DateTime.Now; } @@ -98,18 +106,6 @@ namespace SushiBarBusinessLogic.BusinessLogics { return; } - if (model.SushiId <= 0) - { - throw new ArgumentNullException("Sushi id must be more then zero", nameof(model.SushiId)); - } - if (model.Count <= 0) - { - throw new ArgumentNullException("Count must be more then zero", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Sum must be more then zero", nameof(model.Sum)); - } _logger.LogInformation("Order. OrderId:{Id} .Count:{Count} .Sum:{Sum} .Status{Status} .DateCreate{DateCreate}", model.Id, model.Count, model.Sum, model.Status.ToString(), model.DateCreate.ToString()); var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs index 6428849..fc24db9 100644 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -7,6 +7,7 @@ namespace SushiBarContracts.BindingModels { public int Id { get; set; } public int SushiId { get; set; } + public string SushiName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Unknown; diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index 4cc6956..046f8f6 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -10,7 +10,7 @@ namespace SushiBarContracts.ViewModels public int Id { get; set; } public int SushiId { get; set; } - [DisplayName("Sushi")] + [DisplayName("Name of Product")] public string SushiName { get; set; } = string.Empty; [DisplayName("Count")] @@ -19,7 +19,7 @@ namespace SushiBarContracts.ViewModels [DisplayName("Sum")] public double Sum { get; set; } - [DisplayName("Statuc")] + [DisplayName("Status")] public OrderStatus Status { get; set; } = OrderStatus.Unknown; [DisplayName("Date Create")] diff --git a/SushiBar/SushibarListImplement/Implements/ComponentStorage.cs b/SushiBar/SushibarListImplement/Implements/ComponentStorage.cs index b7f196c..bbcb960 100644 --- a/SushiBar/SushibarListImplement/Implements/ComponentStorage.cs +++ b/SushiBar/SushibarListImplement/Implements/ComponentStorage.cs @@ -22,8 +22,7 @@ namespace SushibarListImplement.Implements } return result; } - public List GetFilteredList(ComponentSearchModel - model) + public List GetFilteredList(ComponentSearchModel model) { var result = new List(); if (string.IsNullOrEmpty(model.ComponentName)) diff --git a/SushiBar/SushibarListImplement/Models/Order.cs b/SushiBar/SushibarListImplement/Models/Order.cs index 9666414..2fdef34 100644 --- a/SushiBar/SushibarListImplement/Models/Order.cs +++ b/SushiBar/SushibarListImplement/Models/Order.cs @@ -2,12 +2,14 @@ using SushiBarContracts.ViewModels; using SushiBarDataModels.Enums; using SushiBarDataModels.Models; +using System.Reflection; namespace SushibarListImplement.Models { public class Order : IOrderModel { public int Id { get; private set; } + public string SushiName { get; private set; } = string.Empty; public int SushiId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -25,6 +27,7 @@ namespace SushibarListImplement.Models { Id = model.Id, SushiId = model.SushiId, + SushiName = model.SushiName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -41,6 +44,7 @@ namespace SushibarListImplement.Models } Id = model.Id; SushiId = model.SushiId; + SushiName = model.SushiName; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -52,6 +56,7 @@ namespace SushibarListImplement.Models { Id = Id, SushiId = SushiId, + SushiName = SushiName, Count = Count, Sum = Sum, Status = Status,