Сдано

This commit is contained in:
DyCTaTOR 2024-05-08 10:44:47 +04:00
parent 707fe27294
commit d1757bfd2a

View File

@ -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<StoreViewModel>? _listStores;
private readonly IStoreLogic _logic;
private readonly ILogger _logger;
private Dictionary<int, (IWorkModel, int)> _works;
public int Id { get; set; }
public FormStore(ILogger<FormStore> logger, IStoreLogic logic)
@ -28,6 +32,7 @@ namespace PlumbingRepairView
_logger = logger;
_listStores = logic.ReadList(null);
_logic = logic;
_works = new Dictionary<int, (IWorkModel, int)>();
}
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<int, (IWorkModel, int)>();
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();
}
}
}