This commit is contained in:
Viltskaa 2023-01-31 20:14:33 +04:00
parent d7f9f16b23
commit 9399daba9e
12 changed files with 84 additions and 58 deletions

View File

@ -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)
});

View File

@ -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
//

View File

@ -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<OrderStatus>(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<OrderStatus>(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<OrderStatus>(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();
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -57,10 +57,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Component.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="Value.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -27,9 +27,7 @@ namespace SushiBar
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["SushiComponents"].Visible = false;
}
_logger.LogInformation("Load sushi");
}
catch (Exception ex)
{

View File

@ -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

View File

@ -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;

View File

@ -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")]

View File

@ -22,8 +22,7 @@ namespace SushibarListImplement.Implements
}
return result;
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
model)
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
var result = new List<ComponentViewModel>();
if (string.IsNullOrEmpty(model.ComponentName))

View File

@ -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,