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

View File

@ -21,5 +21,15 @@ namespace SushiBar.Forms
{ {
ButtonCancel_Click(sender, e); 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.Extensions.Logging;
using Microsoft.VisualBasic.Logging;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels; using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using System.Windows.Forms;
namespace SushiBar.Forms namespace SushiBar.Forms
{ {
@ -21,12 +24,15 @@ namespace SushiBar.Forms
{ {
try try
{ {
var list = _logicS.ReadList(null);
if (list != null)
{
comboBoxSushi.Items.AddRange(list.ToArray());
}
_logger.LogInformation("Загрузка суши для заказа"); _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) catch (Exception ex)
{ {

View File

@ -2,6 +2,7 @@
using SushiBarBusinessLogic.BusinessLogics; using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarDataModels.Enums;
using System.Windows.Forms; using System.Windows.Forms;
namespace SushiBar.Forms namespace SushiBar.Forms
@ -40,8 +41,7 @@ namespace SushiBar.Forms
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void ComponentsToolStripMenuItem_Click(object sender, EventArgs private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e)
e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form) if (service is FormComponents form)

View File

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

View File

@ -49,52 +49,53 @@ namespace SushiBarBusinessLogic.BusinessLogics
} }
public bool TakeOrderInWork(OrderBindingModel model) public bool TakeOrderInWork(OrderBindingModel model)
{ {
CheckModel(model); return ToNextStatus(model, OrderStatus.Выполняется);
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;
} }
public bool DeliveryOrder(OrderBindingModel model) public bool DeliveryOrder(OrderBindingModel model)
{ {
CheckModel(model); return ToNextStatus(model, OrderStatus.Выдан);
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;
} }
public bool FinishOrder(OrderBindingModel model) public bool FinishOrder(OrderBindingModel model)
{ {
CheckModel(model); return ToNextStatus(model, OrderStatus.Готов);
if (model.Status != OrderStatus.Готов) }
public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus)
{ {
_logger.LogWarning("Wrong Order Status"); CheckModel(model, false);
_logger.LogWarning("Insert operation failed"); var element = _orderStorage.GetElement(new OrderSearchModel()
{
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; return false;
} }
model.Status = OrderStatus.Выдан; model.Status = orderStatus;
if (model.Status == OrderStatus.Выдан)
{
model.DateImplement = DateTime.Now;
}
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); model.Status--;
_logger.LogWarning("Changing status operation faled");
return false; return false;
} }
return true; return true;

View File

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