2024-03-10 23:53:01 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SushiBarContracts.BusinessLogicsContracts;
|
|
|
|
|
using SushiBarContracts.SearchModel;
|
|
|
|
|
using SushiBarDataModels.Models;
|
|
|
|
|
using System;
|
2024-03-10 23:03:51 +04:00
|
|
|
|
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;
|
2024-03-10 23:53:01 +04:00
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
2024-03-10 23:03:51 +04:00
|
|
|
|
|
|
|
|
|
namespace SushiBarView.Shops
|
|
|
|
|
{
|
|
|
|
|
public partial class FormShop : Form
|
|
|
|
|
{
|
2024-03-10 23:53:01 +04:00
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IShopLogic _logic;
|
|
|
|
|
private int? _id;
|
|
|
|
|
public int Id
|
2024-03-10 23:03:51 +04:00
|
|
|
|
{
|
2024-03-10 23:53:01 +04:00
|
|
|
|
set { _id = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Dictionary<int, (ISushiModel, int)> _shopSushis;
|
|
|
|
|
public FormShop(ILogger logger, IShopLogic shopLogic)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = shopLogic;
|
|
|
|
|
_shopSushis = new Dictionary<int, (ISushiModel, int)>();
|
2024-03-10 23:03:51 +04:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2024-03-10 23:53:01 +04:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
textBoxName.Text = view.Name;
|
|
|
|
|
textBoxAddress.Text = view.Address;
|
|
|
|
|
dateTimePickerDateOpening.Text = view.DateOpening.ToString();
|
|
|
|
|
_shopSushis = view.ShopSushis ?? new Dictionary<int, (ISushiModel, int)>();
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки магазина");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData() {
|
|
|
|
|
_logger.LogInformation("Загрузка изделий магазина");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_shopSushis != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.Rows.Clear();
|
|
|
|
|
foreach (var elem in _shopPlanes)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.Rows.Add(new object[]
|
|
|
|
|
{
|
|
|
|
|
elem.Key,
|
|
|
|
|
elem.Value.Item1.PlaneName,
|
|
|
|
|
elem.Value.Item2
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-10 23:03:51 +04:00
|
|
|
|
}
|
|
|
|
|
}
|