2024-05-13 23:32:57 +04:00
|
|
|
|
using FurnitureAssemblyContracts.BindingModels;
|
|
|
|
|
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
namespace FurnitureAssemblyView
|
|
|
|
|
{
|
2024-05-22 10:14:48 +04:00
|
|
|
|
public partial class FormClients : Form
|
2024-05-13 23:32:57 +04:00
|
|
|
|
{
|
2024-05-22 10:14:48 +04:00
|
|
|
|
private readonly ILogger _logger;
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
private readonly IClientLogic _clientLogic;
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
public FormClients(ILogger<FormClients> logger, IClientLogic clientLogic)
|
2024-05-13 23:32:57 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-22 10:14:48 +04:00
|
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_clientLogic = clientLogic;
|
|
|
|
|
}
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
|
|
|
|
private void FormClients_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-05-22 10:14:48 +04:00
|
|
|
|
LoadData();
|
|
|
|
|
}
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("Загрузка клиентов");
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _clientLogic.ReadList(null);
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.DataSource = list;
|
|
|
|
|
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
|
}
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
_logger.LogInformation("Успешная загрузка клиентов");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки клиентов");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
private void ButtonDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
_logger.LogInformation("Удаление клиента");
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!_clientLogic.Delete(new ClientBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
|
|
|
|
}
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления компонента");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-13 23:32:57 +04:00
|
|
|
|
|
2024-05-22 10:14:48 +04:00
|
|
|
|
private void ButtonRef_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-13 23:32:57 +04:00
|
|
|
|
}
|