чем был сильней контроль, тем хаос безграничней
This commit is contained in:
parent
676d37152f
commit
c65f7168a8
26
FishFactory/FormMain.Designer.cs
generated
26
FishFactory/FormMain.Designer.cs
generated
@ -33,12 +33,14 @@
|
||||
toolStripDropDownButton1 = new ToolStripDropDownButton();
|
||||
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||
консервыToolStripMenuItem = new ToolStripMenuItem();
|
||||
магазиныToolStripMenuItem = new ToolStripMenuItem();
|
||||
buttonCreateOrder = new Button();
|
||||
buttonTakeOrderInWork = new Button();
|
||||
buttonOrderReady = new Button();
|
||||
buttonIssuedOrder = new Button();
|
||||
buttonRef = new Button();
|
||||
dataGridView = new DataGridView();
|
||||
toolStripLabelReplenish = new ToolStripLabel();
|
||||
toolStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -46,7 +48,7 @@
|
||||
// toolStrip1
|
||||
//
|
||||
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.Name = "toolStrip1";
|
||||
toolStrip1.Size = new Size(1107, 27);
|
||||
@ -56,7 +58,7 @@
|
||||
// toolStripDropDownButton1
|
||||
//
|
||||
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.ImageTransparentColor = Color.Magenta;
|
||||
toolStripDropDownButton1.Name = "toolStripDropDownButton1";
|
||||
@ -66,17 +68,24 @@
|
||||
// компонентыToolStripMenuItem
|
||||
//
|
||||
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||
компонентыToolStripMenuItem.Size = new Size(182, 26);
|
||||
компонентыToolStripMenuItem.Size = new Size(224, 26);
|
||||
компонентыToolStripMenuItem.Text = "Компоненты";
|
||||
компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click;
|
||||
//
|
||||
// консервыToolStripMenuItem
|
||||
//
|
||||
консервыToolStripMenuItem.Name = "консервыToolStripMenuItem";
|
||||
консервыToolStripMenuItem.Size = new Size(182, 26);
|
||||
консервыToolStripMenuItem.Size = new Size(224, 26);
|
||||
консервыToolStripMenuItem.Text = "Консервы";
|
||||
консервыToolStripMenuItem.Click += консервыToolStripMenuItem_Click;
|
||||
//
|
||||
// магазиныToolStripMenuItem
|
||||
//
|
||||
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||
магазиныToolStripMenuItem.Size = new Size(224, 26);
|
||||
магазиныToolStripMenuItem.Text = "Магазины";
|
||||
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
|
||||
//
|
||||
// buttonCreateOrder
|
||||
//
|
||||
buttonCreateOrder.Location = new Point(914, 75);
|
||||
@ -145,6 +154,13 @@
|
||||
dataGridView.Size = new Size(872, 580);
|
||||
dataGridView.TabIndex = 6;
|
||||
//
|
||||
// toolStripLabelReplenish
|
||||
//
|
||||
toolStripLabelReplenish.Name = "toolStripLabelReplenish";
|
||||
toolStripLabelReplenish.Size = new Size(168, 24);
|
||||
toolStripLabelReplenish.Text = "Пополнение магазина";
|
||||
toolStripLabelReplenish.Click += toolStripLabelReplenish_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
@ -180,5 +196,7 @@
|
||||
private ToolStripDropDownButton toolStripDropDownButton1;
|
||||
private ToolStripMenuItem компонентыToolStripMenuItem;
|
||||
private ToolStripMenuItem консервыToolStripMenuItem;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private ToolStripLabel toolStripLabelReplenish;
|
||||
}
|
||||
}
|
@ -65,6 +65,27 @@ namespace FishFactory.Forms
|
||||
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)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
|
||||
|
16
FishFactory/FormShop.Designer.cs
generated
16
FishFactory/FormShop.Designer.cs
generated
@ -38,7 +38,7 @@
|
||||
CannedName = new DataGridViewTextBoxColumn();
|
||||
Count = new DataGridViewTextBoxColumn();
|
||||
label3 = new Label();
|
||||
dateTimePicker = new DateTimePicker();
|
||||
openingDatePicker = new DateTimePicker();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -133,19 +133,19 @@
|
||||
label3.TabIndex = 7;
|
||||
label3.Text = "Дата открытия:";
|
||||
//
|
||||
// dateTimePicker
|
||||
// openingDatePicker
|
||||
//
|
||||
dateTimePicker.Location = new Point(557, 20);
|
||||
dateTimePicker.Name = "dateTimePicker";
|
||||
dateTimePicker.Size = new Size(294, 27);
|
||||
dateTimePicker.TabIndex = 8;
|
||||
openingDatePicker.Location = new Point(557, 20);
|
||||
openingDatePicker.Name = "openingDatePicker";
|
||||
openingDatePicker.Size = new Size(294, 27);
|
||||
openingDatePicker.TabIndex = 8;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(863, 568);
|
||||
Controls.Add(dateTimePicker);
|
||||
Controls.Add(openingDatePicker);
|
||||
Controls.Add(label3);
|
||||
Controls.Add(dataGridView);
|
||||
Controls.Add(buttonCancel);
|
||||
@ -173,6 +173,6 @@
|
||||
private DataGridViewTextBoxColumn CannedName;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
private Label label3;
|
||||
private DateTimePicker dateTimePicker;
|
||||
private DateTimePicker openingDatePicker;
|
||||
}
|
||||
}
|
@ -1,30 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.BusinessLogicsContracts;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryDataModel.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FishFactory
|
||||
{
|
||||
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();
|
||||
_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)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.BusinessLogicsContracts;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FishFactory
|
||||
{
|
||||
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();
|
||||
_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)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
32
FishFactory/FormShops.Designer.cs
generated
32
FishFactory/FormShops.Designer.cs
generated
@ -28,26 +28,26 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridView1 = new DataGridView();
|
||||
dataGridView = new DataGridView();
|
||||
buttonAdd = new Button();
|
||||
buttonUpd = new Button();
|
||||
buttonDel = new Button();
|
||||
buttonRef = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridView1
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView1.AllowUserToAddRows = false;
|
||||
dataGridView1.AllowUserToDeleteRows = false;
|
||||
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView1.Location = new Point(0, 0);
|
||||
dataGridView1.Name = "dataGridView1";
|
||||
dataGridView1.ReadOnly = true;
|
||||
dataGridView1.RowHeadersWidth = 51;
|
||||
dataGridView1.RowTemplate.Height = 29;
|
||||
dataGridView1.Size = new Size(525, 673);
|
||||
dataGridView1.TabIndex = 0;
|
||||
dataGridView.AllowUserToAddRows = false;
|
||||
dataGridView.AllowUserToDeleteRows = false;
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.ReadOnly = true;
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(525, 673);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
@ -102,16 +102,16 @@
|
||||
Controls.Add(buttonDel);
|
||||
Controls.Add(buttonUpd);
|
||||
Controls.Add(buttonAdd);
|
||||
Controls.Add(dataGridView1);
|
||||
Controls.Add(dataGridView);
|
||||
Name = "FormShops";
|
||||
Text = "Список магазинов";
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView1;
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonAdd;
|
||||
private Button buttonUpd;
|
||||
private Button buttonDel;
|
||||
|
@ -1,40 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using FishFactory.Forms;
|
||||
using FishFactoryDataModel.Models;
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.BusinessLogicsContracts;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FishFactory
|
||||
{
|
||||
public partial class FormShops : Form
|
||||
{
|
||||
public FormShops()
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentLogic _logic;
|
||||
|
||||
public FormShops(ILogger<FormShops> logger, IComponentLogic logic)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,11 @@ namespace FishFactory
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<ICannedStorage, CannedStorage>();
|
||||
services.AddTransient<IShopStorage, ShopStorage>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<ICannedLogic, CannedLogic>();
|
||||
services.AddTransient<IShopLogic, ShopLogic>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
@ -48,6 +50,9 @@ namespace FishFactory
|
||||
services.AddTransient<FormCanned>();
|
||||
services.AddTransient<FormCannedComponent>();
|
||||
services.AddTransient<FormCanneds>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShopReplenish>();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,11 +4,6 @@ using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.StoragesContracts;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryBusinessLogic.BusinessLogic
|
||||
{
|
||||
|
154
FishFactoryBusinessLogic/BusinessLogic/ShopLogic.cs
Normal file
154
FishFactoryBusinessLogic/BusinessLogic/ShopLogic.cs
Normal 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("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryContracts.BindingModels
|
||||
{
|
||||
public class ShopCannedBindingModel
|
||||
public class ReplenishBindingModel
|
||||
{
|
||||
public int ShopId { get; set; }
|
||||
public int CannedId { get; set; }
|
@ -1,11 +1,6 @@
|
||||
using FishFactoryContracts.BindingModels;
|
||||
using FishFactoryContracts.SearchModels;
|
||||
using FishFactoryContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FishFactoryContracts.BusinessLogicsContracts
|
||||
{
|
||||
@ -16,6 +11,6 @@ namespace FishFactoryContracts.BusinessLogicsContracts
|
||||
bool Create(ShopBindingModel model);
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool MakeSupply(ShopCannedBindingModel model);
|
||||
bool Replenish(ReplenishBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace FishFactoryListImplement
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Canneds = new List<Canned>();
|
||||
Shop = new List<Shop>();
|
||||
Shops = new List<Shop>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ namespace FishFactoryListImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
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 Dictionary<int, (ICannedModel, int)> ShopCanneds
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user