Сдано
This commit is contained in:
parent
707fe27294
commit
d1757bfd2a
@ -1,14 +1,17 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PlumbingRepairContracts.BindingModels;
|
using PlumbingRepairContracts.BindingModels;
|
||||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||||
|
using PlumbingRepairContracts.SearchModels;
|
||||||
using PlumbingRepairContracts.ViewModels;
|
using PlumbingRepairContracts.ViewModels;
|
||||||
using PlumbingRepairDataModels.Models;
|
using PlumbingRepairDataModels.Models;
|
||||||
|
using PlumbingRepairListImplement.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@ -20,6 +23,7 @@ namespace PlumbingRepairView
|
|||||||
private readonly List<StoreViewModel>? _listStores;
|
private readonly List<StoreViewModel>? _listStores;
|
||||||
private readonly IStoreLogic _logic;
|
private readonly IStoreLogic _logic;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
private Dictionary<int, (IWorkModel, int)> _works;
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public FormStore(ILogger<FormStore> logger, IStoreLogic logic)
|
public FormStore(ILogger<FormStore> logger, IStoreLogic logic)
|
||||||
@ -28,6 +32,7 @@ namespace PlumbingRepairView
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
_listStores = logic.ReadList(null);
|
_listStores = logic.ReadList(null);
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
|
_works = new Dictionary<int, (IWorkModel, int)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IStoreModel? GetStore(int id)
|
private IStoreModel? GetStore(int id)
|
||||||
@ -69,7 +74,8 @@ namespace PlumbingRepairView
|
|||||||
{
|
{
|
||||||
StoreName = NameTextBox.Text,
|
StoreName = NameTextBox.Text,
|
||||||
StoreAdress = AdressTextBox.Text,
|
StoreAdress = AdressTextBox.Text,
|
||||||
OpeningDate = dateTime
|
OpeningDate = dateTime,
|
||||||
|
Works = _works
|
||||||
};
|
};
|
||||||
var vmodel = GetStore(Id);
|
var vmodel = GetStore(Id);
|
||||||
bool operationResult = false;
|
bool operationResult = false;
|
||||||
@ -108,25 +114,38 @@ namespace PlumbingRepairView
|
|||||||
|
|
||||||
private void FormStore_Load(object sender, EventArgs e)
|
private void FormStore_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
_logger.LogInformation("Загрузка изделия");
|
||||||
}
|
|
||||||
private void LoadData(bool extendDate = true)
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text));
|
var view = _logic.ReadElement(new StoreSearchModel { Id = Id });
|
||||||
if (model != null)
|
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();
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -138,7 +157,7 @@ namespace PlumbingRepairView
|
|||||||
|
|
||||||
private void NameComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
private void NameComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData(false);
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user