Фиксы

This commit is contained in:
dasha 2023-02-07 12:55:45 +04:00
parent 4a72fab709
commit f550a6900b
7 changed files with 67 additions and 79 deletions

View File

@ -45,12 +45,12 @@ namespace SushiBarView
try try
{ {
int id = Convert.ToInt32(comboBoxSushi.SelectedValue); int id = Convert.ToInt32(comboBoxSushi.SelectedValue);
var product = _logicS.ReadElement(new SushiSearchModel var sushi = _logicS.ReadElement(new SushiSearchModel
{ {
Id = id Id = id
}); });
int count = Convert.ToInt32(textBoxCount.Text); int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа"); _logger.LogInformation("Расчет суммы заказа");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -50,7 +50,7 @@ namespace SushiBarView
} }
private void LoadData() private void LoadData()
{ {
_logger.LogInformation("Загрузка ингредиент суши"); _logger.LogInformation("Загрузка ингредиентов суши");
try try
{ {
if (_sushiIngredients != null) if (_sushiIngredients != null)
@ -65,7 +65,7 @@ namespace SushiBarView
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки ингредиент суши"); _logger.LogError(ex, "Ошибка загрузки ингредиентов суши");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
@ -83,13 +83,11 @@ namespace SushiBarView
_logger.LogInformation("Добавление нового ингредиента: { IngredientName} - { Count}", form.IngredientModel.IngredientName, form.Count); _logger.LogInformation("Добавление нового ингредиента: { IngredientName} - { Count}", form.IngredientModel.IngredientName, form.Count);
if (_sushiIngredients.ContainsKey(form.Id)) if (_sushiIngredients.ContainsKey(form.Id))
{ {
_sushiIngredients[form.Id] = (form.IngredientModel, _sushiIngredients[form.Id] = (form.IngredientModel, form.Count);
form.Count);
} }
else else
{ {
_sushiIngredients.Add(form.Id, (form.IngredientModel, _sushiIngredients.Add(form.Id, (form.IngredientModel, form.Count));
form.Count));
} }
LoadData(); LoadData();
} }
@ -102,8 +100,7 @@ namespace SushiBarView
var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients)); var service = Program.ServiceProvider?.GetService(typeof(FormSushiIngredients));
if (service is FormSushiIngredients form) if (service is FormSushiIngredients form)
{ {
int id = int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
form.Id = id; form.Id = id;
form.Count = _sushiIngredients[id].Item2; form.Count = _sushiIngredients[id].Item2;
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
@ -123,8 +120,7 @@ namespace SushiBarView
{ {
if (dataGridView.SelectedRows.Count == 1) if (dataGridView.SelectedRows.Count == 1)
{ {
if (MessageBox.Show("Удалить запись?", "Вопрос", if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
try try
{ {
@ -133,8 +129,7 @@ namespace SushiBarView
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message, "Ошибка", MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
LoadData(); LoadData();
} }
@ -148,20 +143,17 @@ namespace SushiBarView
{ {
if (string.IsNullOrEmpty(textBoxName.Text)) if (string.IsNullOrEmpty(textBoxName.Text))
{ {
MessageBox.Show("Заполните название", "Ошибка", MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (string.IsNullOrEmpty(textBoxPrice.Text)) if (string.IsNullOrEmpty(textBoxPrice.Text))
{ {
MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
return; return;
} }
if (_sushiIngredients == null || _sushiIngredients.Count == 0) if (_sushiIngredients == null || _sushiIngredients.Count == 0)
{ {
MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Сохранение суши"); _logger.LogInformation("Сохранение суши");

View File

@ -105,7 +105,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
}); });
if (element != null && element.Id != model.Id) if (element != null && element.Id != model.Id)
{ {
throw new InvalidOperationException("Компонент с таким названием уже есть"); throw new InvalidOperationException("Ингридиент с таким названием уже есть");
} }
} }
} }

View File

@ -18,6 +18,18 @@ namespace SushiBarBusinessLogic.BusinessLogics
_logger = logger; _logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
} }
public List<OrderViewModel>? 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;
}
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
{ {
@ -36,6 +48,30 @@ namespace SushiBarBusinessLogic.BusinessLogics
} }
return true; return true;
} }
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.SushiId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор у суши", nameof(model.SushiId));
}
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}. SushiId: { SushiId}", model.Id, model.Sum, model.SushiId);
}
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{ {
@ -70,43 +106,5 @@ namespace SushiBarBusinessLogic.BusinessLogics
{ {
return StatusUpdate(model, OrderStatus.Готов); return StatusUpdate(model, OrderStatus.Готов);
} }
public List<OrderViewModel>? 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.SushiId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор у суши", nameof(model.SushiId));
}
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}. SushiId: { SushiId}", model.Id, model.Sum, model.SushiId);
}
} }
} }

View File

@ -16,9 +16,9 @@ namespace SushiBarListImplement.Implements
public List<IngredientViewModel> GetFullList() public List<IngredientViewModel> GetFullList()
{ {
var result = new List<IngredientViewModel>(); var result = new List<IngredientViewModel>();
foreach (var component in _source.Ingredients) foreach (var ingredient in _source.Ingredients)
{ {
result.Add(component.GetViewModel); result.Add(ingredient.GetViewModel);
} }
return result; return result;
} }
@ -29,11 +29,11 @@ namespace SushiBarListImplement.Implements
{ {
return result; return result;
} }
foreach (var component in _source.Ingredients) foreach (var ingredient in _source.Ingredients)
{ {
if (component.IngredientName.Contains(model.IngredientName)) if (ingredient.IngredientName.Contains(model.IngredientName))
{ {
result.Add(component.GetViewModel); result.Add(ingredient.GetViewModel);
} }
} }
return result; return result;
@ -44,13 +44,12 @@ namespace SushiBarListImplement.Implements
{ {
return null; return null;
} }
foreach (var component in _source.Ingredients) foreach (var ingredient in _source.Ingredients)
{ {
if ((!string.IsNullOrEmpty(model.IngredientName) && if ((!string.IsNullOrEmpty(model.IngredientName) && ingredient.IngredientName == model.IngredientName) ||
component.IngredientName == model.IngredientName) || (model.Id.HasValue && ingredient.Id == model.Id))
(model.Id.HasValue && component.Id == model.Id))
{ {
return component.GetViewModel; return ingredient.GetViewModel;
} }
} }
return null; return null;
@ -58,11 +57,11 @@ namespace SushiBarListImplement.Implements
public IngredientViewModel? Insert(IngredientBindingModel model) public IngredientViewModel? Insert(IngredientBindingModel model)
{ {
model.Id = 1; model.Id = 1;
foreach (var component in _source.Ingredients) foreach (var ingredient in _source.Ingredients)
{ {
if (model.Id <= component.Id) if (model.Id <= ingredient.Id)
{ {
model.Id = component.Id + 1; model.Id = ingredient.Id + 1;
} }
} }
var newIngredient = Ingredient.Create(model); var newIngredient = Ingredient.Create(model);
@ -75,12 +74,12 @@ namespace SushiBarListImplement.Implements
} }
public IngredientViewModel? Update(IngredientBindingModel model) public IngredientViewModel? Update(IngredientBindingModel model)
{ {
foreach (var component in _source.Ingredients) foreach (var ingredient in _source.Ingredients)
{ {
if (component.Id == model.Id) if (ingredient.Id == model.Id)
{ {
component.Update(model); ingredient.Update(model);
return component.GetViewModel; return ingredient.GetViewModel;
} }
} }
return null; return null;

View File

@ -47,8 +47,7 @@ namespace SushiBarListImplement.Implements
} }
foreach (var sushi in _source.ListSushi) foreach (var sushi in _source.ListSushi)
{ {
if ((!string.IsNullOrEmpty(model.SushiName) && if ((!string.IsNullOrEmpty(model.SushiName) && sushi.SushiName == model.SushiName) ||
sushi.SushiName == model.SushiName) ||
(model.Id.HasValue && sushi.Id == model.Id)) (model.Id.HasValue && sushi.Id == model.Id))
{ {
return sushi.GetViewModel; return sushi.GetViewModel;

View File

@ -7,6 +7,7 @@ namespace SushiBarListImplement.Models
{ {
public class Order : IOrderModel public class Order : IOrderModel
{ {
public int Id { get; private set; }
public int SushiId { get; private set; } public int SushiId { get; private set; }
public string SushiName { get; private set; } = string.Empty; public string SushiName { get; private set; } = string.Empty;
public int Count { get; private set; } public int Count { get; private set; }
@ -14,7 +15,6 @@ namespace SushiBarListImplement.Models
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public int Id { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
if (model == null) if (model == null)