diff --git a/PlumbingRepair/PlumbingRepair/FormStore.cs b/PlumbingRepair/PlumbingRepair/FormStore.cs index 0b7e3ac..9530dd3 100644 --- a/PlumbingRepair/PlumbingRepair/FormStore.cs +++ b/PlumbingRepair/PlumbingRepair/FormStore.cs @@ -1,14 +1,17 @@ using Microsoft.Extensions.Logging; using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; using PlumbingRepairContracts.ViewModels; using PlumbingRepairDataModels.Models; +using PlumbingRepairListImplement.Models; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -20,6 +23,7 @@ namespace PlumbingRepairView private readonly List? _listStores; private readonly IStoreLogic _logic; private readonly ILogger _logger; + private Dictionary _works; public int Id { get; set; } public FormStore(ILogger logger, IStoreLogic logic) @@ -28,6 +32,7 @@ namespace PlumbingRepairView _logger = logger; _listStores = logic.ReadList(null); _logic = logic; + _works = new Dictionary(); } private IStoreModel? GetStore(int id) @@ -69,7 +74,8 @@ namespace PlumbingRepairView { StoreName = NameTextBox.Text, StoreAdress = AdressTextBox.Text, - OpeningDate = dateTime + OpeningDate = dateTime, + Works = _works }; var vmodel = GetStore(Id); bool operationResult = false; @@ -108,25 +114,38 @@ namespace PlumbingRepairView private void FormStore_Load(object sender, EventArgs e) { - LoadData(); - } - private void LoadData(bool extendDate = true) - { + _logger.LogInformation("Загрузка изделия"); try { - var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text)); - if (model != null) + var view = _logic.ReadElement(new StoreSearchModel { Id = Id }); + if (view != null) + { + NameTextBox.Text = view.StoreName; + AdressTextBox.Text = view.StoreAdress; + OpeningDatePicker.Value = view.OpeningDate; + _works = view.Works ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadData() + { + try + { + if (_works != null) { - NameTextBox.Text = model.StoreName; - AdressTextBox.Text = model.StoreAdress; - OpeningDatePicker.Text = Convert.ToString(model.OpeningDate); DataGridView.Rows.Clear(); - foreach (var el in model.Works.Values) + foreach (var pc in _works) { - DataGridView.Rows.Add(new object[] { el.Item1.WorkName, el.Item1.Price, el.Item2 }); + DataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.WorkName, pc.Value.Item2 }); } } - _logger.LogInformation("Загрузка магазинов"); + _logger.LogInformation("Загрузка магазинов"); } catch (Exception ex) { @@ -138,7 +157,7 @@ namespace PlumbingRepairView private void NameComboBox_SelectedIndexChanged(object sender, EventArgs e) { - LoadData(false); + LoadData(); } } }