using Microsoft.Extensions.Logging; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModel; using SushiBarDataModels.Models; 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 static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace SushiBarView.Shops { public partial class FormShop : Form { private readonly ILogger _logger; private readonly IShopLogic _logic; private int? _id; public int Id { set { _id = value; } } private Dictionary _shopSushis; public FormShop(ILogger logger, IShopLogic shopLogic) { _logger = logger; _logic = shopLogic; _shopSushis = new Dictionary(); InitializeComponent(); } 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(); 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); } } } }