ПИбд-22 Боровков М В 1 лабораторная работа #1

Closed
bekodeg wants to merge 22 commits from labWork1 into main
7 changed files with 95 additions and 52 deletions
Showing only changes of commit 6d93b02536 - Show all commits

View File

@ -91,6 +91,7 @@
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(272, 27);
textBoxCount.TabIndex = 5;
textBoxCount.TextChanged += textBoxCount_TextChanged;
//
// textBoxSum
//
@ -107,6 +108,7 @@
comboBoxSushi.Name = "comboBoxSushi";
comboBoxSushi.Size = new Size(272, 28);
comboBoxSushi.TabIndex = 7;
comboBoxSushi.SelectedIndexChanged += comboBoxSushi_SelectedIndexChanged;
//
// FormCreateOrder
//
@ -123,7 +125,7 @@
Controls.Add(buttonSave);
Name = "FormCreateOrder";
Text = "Заказ";
Load += this.FormCreateOrder_Load;
Load += FormCreateOrder_Load;
ResumeLayout(false);
PerformLayout();
}

View File

@ -21,5 +21,15 @@ namespace SushiBar.Forms
{
ButtonCancel_Click(sender, e);
}
private void textBoxCount_TextChanged(object sender, EventArgs e)
{
TextBoxCount_TextChanged(sender, e);
}
private void comboBoxSushi_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBoxSushi_SelectedIndexChanged(sender, e);
}
}
}

View File

@ -1,7 +1,10 @@
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Logging;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using System.Windows.Forms;
namespace SushiBar.Forms
{
@ -21,12 +24,15 @@ namespace SushiBar.Forms
{
try
{
var list = _logicS.ReadList(null);
if (list != null)
{
comboBoxSushi.Items.AddRange(list.ToArray());
}
_logger.LogInformation("Загрузка суши для заказа");
List<SushiViewModel>? _list = _logicS.ReadList(null);
if (_list != null)
{
comboBoxSushi.DisplayMember = "SushiName";
comboBoxSushi.ValueMember = "Id";
comboBoxSushi.DataSource = _list;
comboBoxSushi.SelectedItem = null;
}
}
catch (Exception ex)
{

View File

@ -2,6 +2,7 @@
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarDataModels.Enums;
using System.Windows.Forms;
namespace SushiBar.Forms
@ -40,8 +41,7 @@ namespace SushiBar.Forms
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs
e)
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
@ -74,7 +74,7 @@ namespace SushiBar.Forms
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id });
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");

View File

@ -27,6 +27,7 @@ namespace SushiBar.Forms
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["SushiComponents"].Visible = false;
dataGridView.Columns["SushiName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка суши");

View File

@ -49,57 +49,58 @@ namespace SushiBarBusinessLogic.BusinessLogics
}
public bool TakeOrderInWork(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Принят)
{
_logger.LogWarning("Wrong Order Status");
_logger.LogWarning("Insert operation failed");
return false;
}
model.Status = OrderStatus.Выполняется;
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
return ToNextStatus(model, OrderStatus.Выполняется);
}
public bool DeliveryOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Выполняется)
return ToNextStatus(model, OrderStatus.Выдан);
}
public bool FinishOrder(OrderBindingModel model)
{
return ToNextStatus(model, OrderStatus.Готов);
}
public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus)
{
CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel()
{
_logger.LogWarning("Wrong Order Status");
_logger.LogWarning("Insert operation failed");
Id = model.Id
});
if (element == null)
{
throw new ArgumentNullException(nameof(element));
}
model.SushiId = element.SushiId;
model.DateCreate = element.DateCreate;
model.DateImplement = element.DateImplement;
model.Status = element.Status;
model.Count = element.Count;
model.Sum = element.Sum;
if (model.Status != orderStatus - 1)
{
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
return false;
}
model.Status = OrderStatus.Готов;
model.Status = orderStatus;
if (model.Status == OrderStatus.Выдан)
{
model.DateImplement = DateTime.Now;
}
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Insert operation failed");
model.Status--;
_logger.LogWarning("Changing status operation faled");
return false;
}
return true;
}
public bool FinishOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Готов)
{
_logger.LogWarning("Wrong Order Status");
_logger.LogWarning("Insert operation failed");
return false;
}
model.Status = OrderStatus.Выдан;
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)

View File

@ -18,13 +18,24 @@ namespace SushiBarListImplement.Implements
var result = new List<OrderViewModel>();
foreach (var order in _source.Orders)
{
result.Add(order.GetViewModel);
result.Add(AttachSushiName(order.GetViewModel));
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (model == null || !model.Id.HasValue)
{
return result;
}
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
result.Add(AttachSushiName(order.GetViewModel));
}
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model)
@ -37,7 +48,7 @@ namespace SushiBarListImplement.Implements
{
if (model.Id.HasValue && order.Id == model.Id)
{
return order.GetViewModel;
return AttachSushiName(order.GetViewModel);
}
}
return null;
@ -58,7 +69,7 @@ namespace SushiBarListImplement.Implements
return null;
}
_source.Orders.Add(newOrder);
return newOrder.GetViewModel;
return AttachSushiName(newOrder.GetViewModel);
}
public OrderViewModel? Update(OrderBindingModel model)
{
@ -67,7 +78,7 @@ namespace SushiBarListImplement.Implements
if (order.Id == model.Id)
{
order.Update(model);
return order.GetViewModel;
return AttachSushiName(order.GetViewModel);
}
}
return null;
@ -80,10 +91,22 @@ namespace SushiBarListImplement.Implements
{
var element = _source.Orders[i];
_source.Orders.RemoveAt(i);
return element.GetViewModel;
return AttachSushiName(element.GetViewModel);
}
}
return null;
}
private OrderViewModel AttachSushiName(OrderViewModel model)
{
foreach (var sushi in _source.Sushis)
{
if (sushi.Id == model.SushiId)
{
model.SushiName = sushi.SushiName;
return model;
}
}
return model;
}
}
}