This commit is contained in:
revengel66 2024-06-21 15:05:38 +04:00
parent c84c2beeeb
commit 278dc1ea67
3 changed files with 114 additions and 38 deletions

View File

@ -36,42 +36,42 @@
labelSum = new Label(); labelSum = new Label();
textBoxSum = new TextBox(); textBoxSum = new TextBox();
comboBoxPizza = new ComboBox(); comboBoxPizza = new ComboBox();
comboBoxClient = new ComboBox();
labelClient = new Label();
SuspendLayout(); SuspendLayout();
// //
// textBoxCount // textBoxCount
// //
textBoxCount.Location = new Point(113, 55); textBoxCount.Location = new Point(99, 73);
textBoxCount.Margin = new Padding(3, 4, 3, 4);
textBoxCount.Name = "textBoxCount"; textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(266, 27); textBoxCount.Size = new Size(233, 23);
textBoxCount.TabIndex = 13; textBoxCount.TabIndex = 13;
textBoxCount.TextChanged += textBoxCount_TextChanged; textBoxCount.TextChanged += textBoxCount_TextChanged;
// //
// labelCount // labelCount
// //
labelCount.AutoSize = true; labelCount.AutoSize = true;
labelCount.Location = new Point(13, 59); labelCount.Location = new Point(11, 76);
labelCount.Name = "labelCount"; labelCount.Name = "labelCount";
labelCount.Size = new Size(93, 20); labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 12; labelCount.TabIndex = 12;
labelCount.Text = "Количество:"; labelCount.Text = "Количество:";
// //
// labelPizza // labelPizza
// //
labelPizza.AutoSize = true; labelPizza.AutoSize = true;
labelPizza.Location = new Point(13, 20); labelPizza.Location = new Point(11, 15);
labelPizza.Name = "labelPizza"; labelPizza.Name = "labelPizza";
labelPizza.Size = new Size(55, 20); labelPizza.Size = new Size(43, 15);
labelPizza.TabIndex = 11; labelPizza.TabIndex = 11;
labelPizza.Text = "Пицца"; labelPizza.Text = "Пицца";
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(294, 145); buttonCancel.Location = new Point(257, 170);
buttonCancel.Margin = new Padding(3, 4, 3, 4);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(86, 31); buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 15; buttonCancel.TabIndex = 15;
buttonCancel.Text = "Отмена"; buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
@ -80,10 +80,9 @@
// buttonSave // buttonSave
// //
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSave.Location = new Point(193, 145); buttonSave.Location = new Point(169, 170);
buttonSave.Margin = new Padding(3, 4, 3, 4);
buttonSave.Name = "buttonSave"; buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 31); buttonSave.Size = new Size(82, 23);
buttonSave.TabIndex = 16; buttonSave.TabIndex = 16;
buttonSave.Text = "Сохранить"; buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true; buttonSave.UseVisualStyleBackColor = true;
@ -92,36 +91,53 @@
// labelSum // labelSum
// //
labelSum.AutoSize = true; labelSum.AutoSize = true;
labelSum.Location = new Point(13, 97); labelSum.Location = new Point(11, 105);
labelSum.Name = "labelSum"; labelSum.Name = "labelSum";
labelSum.Size = new Size(58, 20); labelSum.Size = new Size(48, 15);
labelSum.TabIndex = 12; labelSum.TabIndex = 12;
labelSum.Text = "Сумма:"; labelSum.Text = "Сумма:";
// //
// textBoxSum // textBoxSum
// //
textBoxSum.Location = new Point(113, 93); textBoxSum.Location = new Point(99, 102);
textBoxSum.Margin = new Padding(3, 4, 3, 4);
textBoxSum.Name = "textBoxSum"; textBoxSum.Name = "textBoxSum";
textBoxSum.ReadOnly = true; textBoxSum.ReadOnly = true;
textBoxSum.Size = new Size(266, 27); textBoxSum.Size = new Size(233, 23);
textBoxSum.TabIndex = 13; textBoxSum.TabIndex = 13;
// //
// comboBoxPizza // comboBoxPizza
// //
comboBoxPizza.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxPizza.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxPizza.FormattingEnabled = true; comboBoxPizza.FormattingEnabled = true;
comboBoxPizza.Location = new Point(113, 16); comboBoxPizza.Location = new Point(99, 12);
comboBoxPizza.Margin = new Padding(3, 4, 3, 4);
comboBoxPizza.Name = "comboBoxPizza"; comboBoxPizza.Name = "comboBoxPizza";
comboBoxPizza.Size = new Size(266, 28); comboBoxPizza.Size = new Size(233, 23);
comboBoxPizza.TabIndex = 17; comboBoxPizza.TabIndex = 17;
// //
// comboBoxClient
//
comboBoxClient.FormattingEnabled = true;
comboBoxClient.Location = new Point(99, 43);
comboBoxClient.Name = "comboBoxClient";
comboBoxClient.Size = new Size(233, 23);
comboBoxClient.TabIndex = 18;
//
// labelClient
//
labelClient.AutoSize = true;
labelClient.Location = new Point(12, 46);
labelClient.Name = "labelClient";
labelClient.Size = new Size(46, 15);
labelClient.TabIndex = 19;
labelClient.Text = "Клиент";
//
// FormCreateOrder // FormCreateOrder
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(401, 200); ClientSize = new Size(351, 211);
Controls.Add(labelClient);
Controls.Add(comboBoxClient);
Controls.Add(comboBoxPizza); Controls.Add(comboBoxPizza);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
@ -130,7 +146,6 @@
Controls.Add(textBoxCount); Controls.Add(textBoxCount);
Controls.Add(labelCount); Controls.Add(labelCount);
Controls.Add(labelPizza); Controls.Add(labelPizza);
Margin = new Padding(3, 4, 3, 4);
Name = "FormCreateOrder"; Name = "FormCreateOrder";
Text = "Заказ"; Text = "Заказ";
Load += FormCreateOrder_Load; Load += FormCreateOrder_Load;
@ -147,5 +162,7 @@
private Label labelSum; private Label labelSum;
private TextBox textBoxSum; private TextBox textBoxSum;
private ComboBox comboBoxPizza; private ComboBox comboBoxPizza;
private ComboBox comboBoxClient;
private Label labelClient;
} }
} }

View File

@ -11,12 +11,14 @@ namespace Pizzeria
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IPizzaLogic _logicP; private readonly IPizzaLogic _logicP;
private readonly IOrderLogic _logicO; private readonly IOrderLogic _logicO;
private readonly IClientLogic _logicC;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IPizzaLogic logicP, IOrderLogic logicO) public FormCreateOrder(ILogger<FormCreateOrder> logger, IPizzaLogic logicP, IOrderLogic logicO, IClientLogic logicC)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logicP = logicP; _logicP = logicP;
_logicC = logicC;
_logicO = logicO; _logicO = logicO;
} }
private void FormCreateOrder_Load(object sender, EventArgs e) private void FormCreateOrder_Load(object sender, EventArgs e)
@ -32,12 +34,29 @@ namespace Pizzeria
comboBoxPizza.DataSource = _list; comboBoxPizza.DataSource = _list;
comboBoxPizza.SelectedItem = null; comboBoxPizza.SelectedItem = null;
} }
} }
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);
} }
_logger.LogInformation("Loading clients for order");
try
{
var clientList = _logicC.ReadList(null);
if (clientList != null)
{
comboBoxClient.DisplayMember = "ClientFIO";
comboBoxClient.ValueMember = "Id";
comboBoxClient.DataSource = clientList;
comboBoxClient.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading clients for order");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void CalcSum() private void CalcSum()
@ -52,7 +71,7 @@ namespace Pizzeria
Id = id Id = id
}); });
int count = Convert.ToInt32(textBoxCount.Text); int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (Pizza?.Price ?? 0),2).ToString(); textBoxSum.Text = Math.Round(count * (Pizza?.Price ?? 0), 2).ToString();
_logger.LogInformation("Расчет суммы заказа"); _logger.LogInformation("Расчет суммы заказа");
} }
catch (Exception ex) catch (Exception ex)
@ -89,7 +108,12 @@ namespace Pizzeria
} }
if (comboBoxPizza.SelectedValue == null) if (comboBoxPizza.SelectedValue == null)
{ {
MessageBox.Show("Выберите пицца", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxClient.SelectedValue == null)
{
MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Создание заказа"); _logger.LogInformation("Создание заказа");
@ -98,6 +122,7 @@ namespace Pizzeria
var operationResult = _logicO.CreateOrder(new OrderBindingModel var operationResult = _logicO.CreateOrder(new OrderBindingModel
{ {
PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue), PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue),
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text), Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text) Sum = Convert.ToDouble(textBoxSum.Text)
}); });

View File

@ -4,8 +4,6 @@ using PizzeriaContracts.ViewModels;
using PizzeriaDatabaseImplement.Models; using PizzeriaDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using PizzeriaContracts.StorageContracts; using PizzeriaContracts.StorageContracts;
using System.Collections.Generic;
using System.Linq;
namespace PizzeriaDatabaseImplement.Implements namespace PizzeriaDatabaseImplement.Implements
{ {
@ -14,7 +12,11 @@ namespace PizzeriaDatabaseImplement.Implements
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
using var context = new PizzeriaDatabase(); using var context = new PizzeriaDatabase();
return context.Orders.Include(x => x.Pizza).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); return context.Orders
.Include(x => x.Pizza)
.Include(x => x.Client)
.Select(x => x.GetViewModel)
.ToList();
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -22,13 +24,28 @@ namespace PizzeriaDatabaseImplement.Implements
using var context = new PizzeriaDatabase(); using var context = new PizzeriaDatabase();
if (model.DateFrom.HasValue) if (model.DateFrom.HasValue)
{ {
return context.Orders.Include(x => x.Pizza).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); return context.Orders
.Include(x => x.Pizza)
.Include(x => x.Client)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
} }
if (model.ClientId.HasValue) if (model.ClientId.HasValue)
{ {
return context.Orders.Include(x => x.Pizza).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); return context.Orders
.Include(x => x.Pizza)
.Include(x => x.Client)
.Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
} }
return context.Orders.Include(x => x.Pizza).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); return context.Orders
.Include(x => x.Pizza)
.Include(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
} }
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
@ -38,7 +55,11 @@ namespace PizzeriaDatabaseImplement.Implements
return new(); return new();
} }
using var context = new PizzeriaDatabase(); using var context = new PizzeriaDatabase();
return context.Orders.Include(x => x.Pizza).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; return context.Orders
.Include(x => x.Pizza)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
@ -53,7 +74,11 @@ namespace PizzeriaDatabaseImplement.Implements
} }
context.Orders.Add(newOrder); context.Orders.Add(newOrder);
context.SaveChanges(); context.SaveChanges();
return newOrder.GetViewModel; return context.Orders
.Include(x => x.Pizza)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel;
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
@ -66,7 +91,11 @@ namespace PizzeriaDatabaseImplement.Implements
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return order.GetViewModel; return context.Orders
.Include(x => x.Pizza)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
} }
public OrderViewModel? Delete(OrderBindingModel model) public OrderViewModel? Delete(OrderBindingModel model)
@ -75,9 +104,14 @@ namespace PizzeriaDatabaseImplement.Implements
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
if (order != null) if (order != null)
{ {
var deletedElement = context.Orders
.Include(x => x.Pizza)
.Include(x => x.Client)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Orders.Remove(order); context.Orders.Remove(order);
context.SaveChanges(); context.SaveChanges();
return order.GetViewModel; return deletedElement;
} }
return null; return null;
} }