чем был сильней контроль, тем хаос безграничней

This commit is contained in:
dex_moth 2024-03-05 21:14:06 +04:00
parent 676d37152f
commit c65f7168a8
14 changed files with 484 additions and 79 deletions

View File

@ -33,12 +33,14 @@
toolStripDropDownButton1 = new ToolStripDropDownButton(); toolStripDropDownButton1 = new ToolStripDropDownButton();
компонентыToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem();
консервыToolStripMenuItem = new ToolStripMenuItem(); консервыToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
buttonCreateOrder = new Button(); buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button(); buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button(); buttonOrderReady = new Button();
buttonIssuedOrder = new Button(); buttonIssuedOrder = new Button();
buttonRef = new Button(); buttonRef = new Button();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
toolStripLabelReplenish = new ToolStripLabel();
toolStrip1.SuspendLayout(); toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
@ -46,7 +48,7 @@
// toolStrip1 // toolStrip1
// //
toolStrip1.ImageScalingSize = new Size(20, 20); toolStrip1.ImageScalingSize = new Size(20, 20);
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 }); toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripLabelReplenish });
toolStrip1.Location = new Point(0, 0); toolStrip1.Location = new Point(0, 0);
toolStrip1.Name = "toolStrip1"; toolStrip1.Name = "toolStrip1";
toolStrip1.Size = new Size(1107, 27); toolStrip1.Size = new Size(1107, 27);
@ -56,7 +58,7 @@
// toolStripDropDownButton1 // toolStripDropDownButton1
// //
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem }); toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, магазиныToolStripMenuItem });
toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image");
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
toolStripDropDownButton1.Name = "toolStripDropDownButton1"; toolStripDropDownButton1.Name = "toolStripDropDownButton1";
@ -66,17 +68,24 @@
// компонентыToolStripMenuItem // компонентыToolStripMenuItem
// //
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem"; компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(182, 26); компонентыToolStripMenuItem.Size = new Size(224, 26);
компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click;
// //
// консервыToolStripMenuItem // консервыToolStripMenuItem
// //
консервыToolStripMenuItem.Name = онсервыToolStripMenuItem"; консервыToolStripMenuItem.Name = онсервыToolStripMenuItem";
консервыToolStripMenuItem.Size = new Size(182, 26); консервыToolStripMenuItem.Size = new Size(224, 26);
консервыToolStripMenuItem.Text = "Консервы"; консервыToolStripMenuItem.Text = "Консервы";
консервыToolStripMenuItem.Click += консервыToolStripMenuItem_Click; консервыToolStripMenuItem.Click += консервыToolStripMenuItem_Click;
// //
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(224, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
//
// buttonCreateOrder // buttonCreateOrder
// //
buttonCreateOrder.Location = new Point(914, 75); buttonCreateOrder.Location = new Point(914, 75);
@ -145,6 +154,13 @@
dataGridView.Size = new Size(872, 580); dataGridView.Size = new Size(872, 580);
dataGridView.TabIndex = 6; dataGridView.TabIndex = 6;
// //
// toolStripLabelReplenish
//
toolStripLabelReplenish.Name = "toolStripLabelReplenish";
toolStripLabelReplenish.Size = new Size(168, 24);
toolStripLabelReplenish.Text = "Пополнение магазина";
toolStripLabelReplenish.Click += toolStripLabelReplenish_Click;
//
// FormMain // FormMain
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
@ -180,5 +196,7 @@
private ToolStripDropDownButton toolStripDropDownButton1; private ToolStripDropDownButton toolStripDropDownButton1;
private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem консервыToolStripMenuItem; private ToolStripMenuItem консервыToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripLabel toolStripLabelReplenish;
} }
} }

View File

@ -65,6 +65,27 @@ namespace FishFactory.Forms
form.ShowDialog(); form.ShowDialog();
} }
} }
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void toolStripLabelReplenish_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShopReplenish));
if (service is FormShopReplenish form)
{
form.ShowDialog();
LoadData();
}
}
private void buttonCreateOrder_Click(object sender, EventArgs e) private void buttonCreateOrder_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));

View File

@ -38,7 +38,7 @@
CannedName = new DataGridViewTextBoxColumn(); CannedName = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn(); Count = new DataGridViewTextBoxColumn();
label3 = new Label(); label3 = new Label();
dateTimePicker = new DateTimePicker(); openingDatePicker = new DateTimePicker();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -133,19 +133,19 @@
label3.TabIndex = 7; label3.TabIndex = 7;
label3.Text = "Дата открытия:"; label3.Text = "Дата открытия:";
// //
// dateTimePicker // openingDatePicker
// //
dateTimePicker.Location = new Point(557, 20); openingDatePicker.Location = new Point(557, 20);
dateTimePicker.Name = "dateTimePicker"; openingDatePicker.Name = "openingDatePicker";
dateTimePicker.Size = new Size(294, 27); openingDatePicker.Size = new Size(294, 27);
dateTimePicker.TabIndex = 8; openingDatePicker.TabIndex = 8;
// //
// FormShop // FormShop
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(863, 568); ClientSize = new Size(863, 568);
Controls.Add(dateTimePicker); Controls.Add(openingDatePicker);
Controls.Add(label3); Controls.Add(label3);
Controls.Add(dataGridView); Controls.Add(dataGridView);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
@ -173,6 +173,6 @@
private DataGridViewTextBoxColumn CannedName; private DataGridViewTextBoxColumn CannedName;
private DataGridViewTextBoxColumn Count; private DataGridViewTextBoxColumn Count;
private Label label3; private Label label3;
private DateTimePicker dateTimePicker; private DateTimePicker openingDatePicker;
} }
} }

View File

@ -1,30 +1,120 @@
using System; using FishFactoryContracts.BindingModels;
using System.Collections.Generic; using FishFactoryContracts.BusinessLogicsContracts;
using System.ComponentModel; using FishFactoryContracts.SearchModels;
using System.Data; using FishFactoryDataModel.Models;
using System.Drawing; using Microsoft.Extensions.Logging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace FishFactory namespace FishFactory
{ {
public partial class FormShop : Form public partial class FormShop : Form
{ {
public FormShop() private readonly ILogger _logger;
private readonly IShopLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
private Dictionary<int, (ICannedModel, int)> _shopCanneds;
private DateTime? _openingDate = null;
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger;
_logic = logic;
_shopCanneds = new Dictionary<int, (ICannedModel, int)>();
}
private void FormShop_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка магазина");
try
{
var view = _logic.ReadElement(new ShopSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxShopName.Text = view.ShopName;
textBoxAdress.Text = view.Adress;
openingDatePicker.Value = view.OpeningDate;
_shopCanneds = view.ShopCanneds ?? new Dictionary<int, (ICannedModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка изделий в магазине");
try
{
if (_shopCanneds != null)
{
dataGridView.Rows.Clear();
foreach (var sr in _shopCanneds)
{
dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.CannedName, sr.Value.Item2 });
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void buttonSave_Click(object sender, EventArgs e) private void buttonSave_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(textBoxShopName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxAdress.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxShopName.Text,
Adress = textBoxAdress.Text,
OpeningDate = openingDatePicker.Value
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void buttonCancel_Click(object sender, EventArgs e) private void buttonCancel_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel;
Close();
} }
} }
} }

View File

@ -1,30 +1,89 @@
using System; 
using System.Collections.Generic; using FishFactoryContracts.BindingModels;
using System.ComponentModel; using FishFactoryContracts.BusinessLogicsContracts;
using System.Data; using FishFactoryContracts.ViewModels;
using System.Drawing; using Microsoft.Extensions.Logging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FishFactory namespace FishFactory
{ {
public partial class FormShopReplenish : Form public partial class FormShopReplenish : Form
{ {
public FormShopReplenish() private readonly ILogger _logger;
private readonly ICannedLogic _logicP;
private readonly IShopLogic _logicS;
private List<ShopViewModel> _shopList = new List<ShopViewModel>();
private List<CannedViewModel> _cannedList = new List<CannedViewModel>();
public FormShopReplenish(ILogger<FormShopReplenish> logger, ICannedLogic logicP, IShopLogic logicS)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicS = logicS;
}
private void FormCreateReplenish_Load(object sender, EventArgs e)
{
_shopList = _logicS.ReadList(null);
_cannedList = _logicP.ReadList(null);
if (_shopList != null)
{
comboBoxShopCanneds.DisplayMember = "ShopName";
comboBoxShopCanneds.ValueMember = "Id";
comboBoxShopCanneds.DataSource = _shopList;
comboBoxShopCanneds.SelectedItem = null;
_logger.LogInformation("Загрузка магазинов для поставок");
}
if (_cannedList != null)
{
comboBoxCanned.DisplayMember = "CannedName";
comboBoxCanned.ValueMember = "Id";
comboBoxCanned.DataSource = _cannedList;
comboBoxCanned.SelectedItem = null;
_logger.LogInformation("Загрузка консерв для поставок");
}
} }
private void buttonSave_Click(object sender, EventArgs e) private void buttonSave_Click(object sender, EventArgs e)
{ {
if (comboBoxShopCanneds.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxCanned.SelectedValue == null)
{
MessageBox.Show("Выберите консерву", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание поставки");
try
{
var operationResult = _logicS.Replenish(new ReplenishBindingModel
{
ShopId = Convert.ToInt32(comboBoxShopCanneds.SelectedValue),
CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text)
});
if (!operationResult)
{
throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания поставки");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void buttonCancel_Click(object sender, EventArgs e) private void buttonCancel_Click(object sender, EventArgs e)
{ {
DialogResult = DialogResult.Cancel;
Close();
} }
} }
} }

View File

@ -28,26 +28,26 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
dataGridView1 = new DataGridView(); dataGridView = new DataGridView();
buttonAdd = new Button(); buttonAdd = new Button();
buttonUpd = new Button(); buttonUpd = new Button();
buttonDel = new Button(); buttonDel = new Button();
buttonRef = new Button(); buttonRef = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// dataGridView1 // dataGridView
// //
dataGridView1.AllowUserToAddRows = false; dataGridView.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false; dataGridView.AllowUserToDeleteRows = false;
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Location = new Point(0, 0); dataGridView.Location = new Point(0, 0);
dataGridView1.Name = "dataGridView1"; dataGridView.Name = "dataGridView";
dataGridView1.ReadOnly = true; dataGridView.ReadOnly = true;
dataGridView1.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView1.RowTemplate.Height = 29; dataGridView.RowTemplate.Height = 29;
dataGridView1.Size = new Size(525, 673); dataGridView.Size = new Size(525, 673);
dataGridView1.TabIndex = 0; dataGridView.TabIndex = 0;
// //
// buttonAdd // buttonAdd
// //
@ -102,16 +102,16 @@
Controls.Add(buttonDel); Controls.Add(buttonDel);
Controls.Add(buttonUpd); Controls.Add(buttonUpd);
Controls.Add(buttonAdd); Controls.Add(buttonAdd);
Controls.Add(dataGridView1); Controls.Add(dataGridView);
Name = "FormShops"; Name = "FormShops";
Text = "Список магазинов"; Text = "Список магазинов";
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private DataGridView dataGridView1; private DataGridView dataGridView;
private Button buttonAdd; private Button buttonAdd;
private Button buttonUpd; private Button buttonUpd;
private Button buttonDel; private Button buttonDel;

View File

@ -1,40 +1,108 @@
using System; using FishFactory.Forms;
using System.Collections.Generic; using FishFactoryDataModel.Models;
using System.ComponentModel; using FishFactoryContracts.BindingModels;
using System.Data; using FishFactoryContracts.BusinessLogicsContracts;
using System.Drawing; using FishFactoryContracts.SearchModels;
using System.Linq; using Microsoft.Extensions.Logging;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FishFactory namespace FishFactory
{ {
public partial class FormShops : Form public partial class FormShops : Form
{ {
public FormShops() private readonly ILogger _logger;
private readonly IComponentLogic _logic;
public FormShops(ILogger<FormShops> logger, IComponentLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormShops_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ShopCanneds"].Visible = false;
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
private void buttonAdd_Click(object sender, EventArgs e) private void buttonAdd_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
} }
private void buttonUpd_Click(object sender, EventArgs e) private void buttonUpd_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
} }
private void buttonDel_Click(object sender, EventArgs e) private void buttonDel_Click(object sender, EventArgs e)
{ {
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление магазина");
try
{
if (!_logic.Delete(new ComponentBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления компонента");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
} }
private void buttonRef_Click(object sender, EventArgs e) private void buttonRef_Click(object sender, EventArgs e)
{ {
LoadData();
} }
} }
} }

View File

@ -38,9 +38,11 @@ namespace FishFactory
services.AddTransient<IComponentStorage, ComponentStorage>(); services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ICannedStorage, CannedStorage>(); services.AddTransient<ICannedStorage, CannedStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ICannedLogic, CannedLogic>(); services.AddTransient<ICannedLogic, CannedLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>(); services.AddTransient<FormMain>();
services.AddTransient<FormComponent>(); services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>(); services.AddTransient<FormComponents>();
@ -48,6 +50,9 @@ namespace FishFactory
services.AddTransient<FormCanned>(); services.AddTransient<FormCanned>();
services.AddTransient<FormCannedComponent>(); services.AddTransient<FormCannedComponent>();
services.AddTransient<FormCanneds>(); services.AddTransient<FormCanneds>();
services.AddTransient<FormShops>();
services.AddTransient<FormShop>();
services.AddTransient<FormShopReplenish>();
} }
} }
} }

View File

@ -4,11 +4,6 @@ using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts; using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels; using FishFactoryContracts.ViewModels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FishFactoryBusinessLogic.BusinessLogic namespace FishFactoryBusinessLogic.BusinessLogic
{ {

View File

@ -0,0 +1,154 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace FishFactoryBusinessLogic.BusinessLogic
{
public class ShopLogic : IShopLogic
{
private readonly ILogger _logger;
private readonly IShopStorage _shopStorage;
private readonly ICannedStorage _cannedStorage;
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage, ICannedStorage cannedStorage)
{
_logger = logger;
_shopStorage = shopStorage;
_cannedStorage = cannedStorage;
}
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
{
_logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{Id}", model?.ShopName, model?.Id);
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ShopViewModel? ReadElement(ShopSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{Id}", model.ShopName, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool Create(ShopBindingModel model)
{
CheckModel(model);
if (_shopStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ShopBindingModel model)
{
CheckModel(model);
if (_shopStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ShopBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_shopStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Replenish(ReplenishBindingModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (model.Count <= 0)
{
throw new ArgumentException("Количество изделий должно быть больше 0");
}
var shop = _shopStorage.GetElement(new ShopSearchModel
{
Id = model.ShopId
});
if (shop == null)
{
throw new ArgumentException("Магазина не существует");
}
if (shop.ShopCanneds.ContainsKey(model.CannedId))
{
var oldValue = shop.ShopCanneds[model.CannedId];
oldValue.Item2 += model.Count;
shop.ShopCanneds[model.CannedId] = oldValue;
}
else
{
var canned = _cannedStorage.GetElement(new CannedSearchModel
{
Id = model.CannedId
});
if (canned == null)
{
throw new ArgumentException($"Поставка: Товар с id:{model.CannedId} не найденн");
}
shop.ShopCanneds.Add(model.CannedId, (canned, model.Count));
}
return true;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Adress))
{
throw new ArgumentException("Нет адреса магазина", nameof(model.Adress));
}
if (string.IsNullOrEmpty(model.ShopName))
{
throw new ArgumentNullException("Нет названия компонента", nameof(model.ShopName));
}
_logger.LogInformation("Shop. ShopName:{ShopName}.Adress:{Adress}. Id: {Id}", model.ShopName, model.Adress, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
ShopName = model.ShopName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace FishFactoryContracts.BindingModels namespace FishFactoryContracts.BindingModels
{ {
public class ShopCannedBindingModel public class ReplenishBindingModel
{ {
public int ShopId { get; set; } public int ShopId { get; set; }
public int CannedId { get; set; } public int CannedId { get; set; }

View File

@ -1,11 +1,6 @@
using FishFactoryContracts.BindingModels; using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels; using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels; using FishFactoryContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FishFactoryContracts.BusinessLogicsContracts namespace FishFactoryContracts.BusinessLogicsContracts
{ {
@ -16,6 +11,6 @@ namespace FishFactoryContracts.BusinessLogicsContracts
bool Create(ShopBindingModel model); bool Create(ShopBindingModel model);
bool Update(ShopBindingModel model); bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model); bool Delete(ShopBindingModel model);
bool MakeSupply(ShopCannedBindingModel model); bool Replenish(ReplenishBindingModel model);
} }
} }

View File

@ -19,7 +19,7 @@ namespace FishFactoryListImplement
Components = new List<Component>(); Components = new List<Component>();
Orders = new List<Order>(); Orders = new List<Order>();
Canneds = new List<Canned>(); Canneds = new List<Canned>();
Shop = new List<Shop>(); Shops = new List<Shop>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()
{ {

View File

@ -13,7 +13,7 @@ namespace FishFactoryListImplement.Models
{ {
public int Id { get; private set; } public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty; public string ShopName { get; private set; } = string.Empty;
public string Adress { get; private set; } public string Adress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; } public DateTime OpeningDate { get; private set; }
public Dictionary<int, (ICannedModel, int)> ShopCanneds public Dictionary<int, (ICannedModel, int)> ShopCanneds
{ {