Все работает как надо

This commit is contained in:
Kirill 2024-03-13 20:35:00 +04:00
parent 9f4a25aee9
commit 697f5a5bfc
7 changed files with 122 additions and 118 deletions

View File

@ -26,9 +26,8 @@ namespace ClothShopBusinessLogic.BusinessLogics
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() :
_orderStorage.GetFilteredList(model);
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
@ -38,10 +37,30 @@ namespace ClothShopBusinessLogic.BusinessLogics
return list;
}
private void CheckModel(OrderBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество заказов должно быть больше нуля");
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Цена заказа должна быть больше нуля");
}
_logger.LogInformation("Order. OrderId:{Id}. Sum:{Sum}", model.Id, model.Sum);
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false;
if (model.Status != OrderStatus.Неизвестен)
{
return false;
}
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
@ -49,21 +68,21 @@ namespace ClothShopBusinessLogic.BusinessLogics
return false;
}
return true;
}
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
private bool ChangeStatus(OrderBindingModel model, OrderStatus status)
{
CheckModel(model);
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (element == null)
{
_logger.LogWarning("Read operation failed");
_logger.LogWarning("Find order failed");
return false;
}
if (element.Status != status - 1)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
_logger.LogWarning("Status change failed");
throw new InvalidOperationException("Невозможно перевести состояние заказа");
}
model.Status = status;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
@ -85,26 +104,5 @@ namespace ClothShopBusinessLogic.BusinessLogics
{
return ChangeStatus(model, OrderStatus.Выдан);
}
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count));
}
_logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id);
}
}
}

View File

@ -23,23 +23,19 @@ namespace ClothShopListImplement.Implements
var result = new List<OrderViewModel>();
foreach (var order in _source.Orders)
{
result.Add(order.GetViewModel);
result.Add(AcessDressesStorage(order.GetViewModel));
}
return result;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel
model)
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
var result = new List<OrderViewModel>();
if (string.IsNullOrEmpty(model.Id.ToString()))
{
return result;
}
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
{
result.Add(order.GetViewModel);
result.Add(AcessDressesStorage(order.GetViewModel));
}
}
return result;
@ -91,7 +87,7 @@ namespace ClothShopListImplement.Implements
}
public OrderViewModel? Delete(OrderBindingModel model)
{
for (int i = 0; i < _source.Orders.Count; ++i)
for (int i = 0; i < _source.Orders.Count; i++)
{
if (_source.Orders[i].Id == model.Id)
{
@ -102,5 +98,17 @@ namespace ClothShopListImplement.Implements
}
return null;
}
public OrderViewModel AcessDressesStorage(OrderViewModel model)
{
foreach (var dress in _source.Textiles)
{
if (dress.Id == model.TextileId)
{
model.TextileName = dress.TextileName;
break;
}
}
return model;
}
}
}

View File

@ -65,7 +65,7 @@
this.textBoxSum.ReadOnly = true;
this.textBoxSum.Size = new System.Drawing.Size(260, 27);
this.textBoxSum.TabIndex = 13;
this.textBoxSum.Click += new System.EventHandler(this.TextBoxSum_TextChanged);
this.textBoxSum.TextChanged += new System.EventHandler(this.textBoxPrice_TextChanged);
//
// textBoxCount
//
@ -73,7 +73,7 @@
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(260, 27);
this.textBoxCount.TabIndex = 12;
this.textBoxCount.Click += new System.EventHandler(this.TextBoxCount_TextChanged);
this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxPrice_TextChanged);
//
// labelSum
//
@ -110,7 +110,7 @@
this.comboBoxTextile.Name = "comboBoxTextile";
this.comboBoxTextile.Size = new System.Drawing.Size(260, 28);
this.comboBoxTextile.TabIndex = 8;
this.comboBoxTextile.Click += new System.EventHandler(this.ComboBoxTextile_SelectedIndexChanged);
this.comboBoxTextile.SelectedIndexChanged += new System.EventHandler(this.comboBoxTextile_SelectedIndexChanged);
//
// FormCreateOrder
//

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using ClothShopContracts.BindingModels;
using ClothShopContracts.BusinessLogicContracts;
using ClothShopContracts.ViewModels;
using ClothShopContracts.SearchModels;
using Microsoft.Extensions.Logging;
@ -17,75 +18,34 @@ namespace ClothShopView
public partial class FormCreateOrder : Form
{
private readonly ILogger _logger;
private readonly ITextileLogic _logicR;
private readonly ITextileLogic _logicP;
private readonly IOrderLogic _logicO;
public FormCreateOrder(ILogger<FormCreateOrder> logger, ITextileLogic logicR, IOrderLogic logicO)
private List<TextileViewModel>? _list;
public FormCreateOrder()
{
InitializeComponent();
}
public FormCreateOrder(ILogger<FormCreateOrder> logger, ITextileLogic logicP, IOrderLogic logicO)
{
InitializeComponent();
_logger = logger;
_logicR = logicR;
_logicP = logicP;
_logicO = logicO;
}
private void FormCreateOrder_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка ремонта для заказа");
try
_logger.LogInformation("Загрузка изделий для заказа");
_list = _logicP.ReadList(null);
if (_list != null)
{
var list = _logicR.ReadList(null);
if (list != null)
{
comboBoxTextile.DisplayMember = "TextileName";
comboBoxTextile.ValueMember = "Id";
comboBoxTextile.DataSource = list;
comboBoxTextile.SelectedItem = null;
}
_logger.LogInformation("Ремонт загружено");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки ремонта");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
comboBoxTextile.DisplayMember = "TextileName";
comboBoxTextile.ValueMember = "Id";
comboBoxTextile.DataSource = _list;
comboBoxTextile.SelectedItem = null;
_logger.LogInformation("Загрузка суши для заказа");
}
}
private void CalcSum()
{
if (comboBoxTextile.SelectedValue != null &&
!string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxTextile.SelectedValue);
var textile = _logicR.ReadElement(new TextileSearchModel
{
Id
= id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (textile?.Price ?? 0),
2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void TextBoxCount_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void TextBoxSum_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ComboBoxTextile_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
@ -96,7 +56,7 @@ namespace ClothShopView
}
if (comboBoxTextile.SelectedValue == null)
{
MessageBox.Show("Выберите ремонт", "Ошибка",
MessageBox.Show("Выберите изделие", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
@ -125,6 +85,42 @@ namespace ClothShopView
MessageBoxIcon.Error);
}
}
private void CalcSum()
{
if (comboBoxTextile.SelectedValue != null &&
!string.IsNullOrEmpty(textBoxCount.Text))
{
try
{
int id = Convert.ToInt32(comboBoxTextile.SelectedValue);
var textile = _logicP.ReadElement(new TextileSearchModel
{
Id = id
});
int count = Convert.ToInt32(textBoxCount.Text);
textBoxSum.Text = Math.Round(count * (textile?.Price ?? 0),
2).ToString();
_logger.LogInformation("Расчет суммы заказа");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка расчета суммы заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void comboBoxTextile_SelectedIndexChanged(object sender, EventArgs e)
{
CalcSum();
}
private void textBoxPrice_TextChanged(object sender, EventArgs e)
{
CalcSum();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;

View File

@ -45,13 +45,14 @@
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.dataGridView.BackgroundColor = System.Drawing.Color.White;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 31);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(839, 377);
this.dataGridView.Size = new System.Drawing.Size(914, 377);
this.dataGridView.TabIndex = 8;
//
// menuStrip
@ -61,7 +62,7 @@
this.справочникиToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1090, 28);
this.menuStrip.Size = new System.Drawing.Size(1156, 28);
this.menuStrip.TabIndex = 7;
this.menuStrip.Text = "Меню справочников";
//
@ -77,20 +78,20 @@
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.компонентыToolStripMenuItem.Text = "Компоненты";
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// изделиеToolStripMenuItem
//
this.изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem";
this.изделиеToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.изделиеToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
this.изделиеToolStripMenuItem.Text = "Изделие";
this.изделиеToolStripMenuItem.Click += new System.EventHandler(this.TextileToolStripMenuItem_Click);
//
// buttonRefresh
//
this.buttonRefresh.Location = new System.Drawing.Point(870, 331);
this.buttonRefresh.Location = new System.Drawing.Point(932, 324);
this.buttonRefresh.Name = "buttonRefresh";
this.buttonRefresh.Size = new System.Drawing.Size(212, 38);
this.buttonRefresh.TabIndex = 13;
@ -100,7 +101,7 @@
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(870, 263);
this.buttonIssuedOrder.Location = new System.Drawing.Point(932, 256);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(212, 38);
this.buttonIssuedOrder.TabIndex = 12;
@ -110,7 +111,7 @@
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(870, 197);
this.buttonOrderReady.Location = new System.Drawing.Point(932, 190);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(212, 38);
this.buttonOrderReady.TabIndex = 11;
@ -120,7 +121,7 @@
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(870, 131);
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(932, 124);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(212, 38);
this.buttonTakeOrderInWork.TabIndex = 10;
@ -130,7 +131,7 @@
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(870, 63);
this.buttonCreateOrder.Location = new System.Drawing.Point(932, 56);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(212, 38);
this.buttonCreateOrder.TabIndex = 9;
@ -142,7 +143,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1090, 417);
this.ClientSize = new System.Drawing.Size(1156, 417);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip);
this.Controls.Add(this.buttonRefresh);

View File

@ -38,7 +38,8 @@ namespace ClothShopView
{
dataGridView.DataSource = list;
dataGridView.Columns["TextileId"].Visible = false;
dataGridView.Columns["TextileName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["TextileName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка заказов");
}

View File

@ -33,7 +33,7 @@ namespace ClothShopView
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка ремонта");
_logger.LogInformation("Загрузка изделиеа");
try
{
var view = _logic.ReadElement(new TextileSearchModel
@ -50,7 +50,7 @@ namespace ClothShopView
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки ремонта");
_logger.LogError(ex, "Ошибка загрузки изделиеа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
@ -58,7 +58,7 @@ namespace ClothShopView
}
private void LoadData()
{
_logger.LogInformation("Загрузка компонент ремонта");
_logger.LogInformation("Загрузка компонент изделиеа");
try
{
if (_textileComponents != null)
@ -73,7 +73,7 @@ namespace ClothShopView
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки компонент ремонта");
_logger.LogError(ex, "Ошибка загрузки компонент изделиеа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
@ -177,7 +177,7 @@ namespace ClothShopView
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение ремонта");
_logger.LogInformation("Сохранение изделиеа");
try
{
var model = new TextileBindingModel
@ -200,7 +200,7 @@ namespace ClothShopView
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения ремонта");
_logger.LogError(ex, "Ошибка сохранения изделиеа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}