2024-04-06 17:15:38 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using SushiBarContracts.BindingModel;
|
|
|
|
|
using SushiBarContracts.BusinessLogicsContracts;
|
|
|
|
|
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;
|
|
|
|
|
|
2024-04-07 00:01:10 +04:00
|
|
|
|
namespace SushiBarView
|
2024-04-06 17:15:38 +04:00
|
|
|
|
{
|
|
|
|
|
public partial class FormClients : Form
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IClientLogic _clientLogic;
|
|
|
|
|
|
|
|
|
|
public FormClients(ILogger<FormClients> logger, IClientLogic logic)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_clientLogic = logic;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormClients_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _clientLogic.ReadList(null);
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.DataSource = list;
|
|
|
|
|
dataGridView.Columns["Id"].Visible = false;
|
|
|
|
|
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
|
_logger.LogInformation("Клиенты успешно загружены");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex.Message, "Ошибка загрузки клиентов");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка загрузки клиентов");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-07 00:01:10 +04:00
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
2024-04-06 17:15:38 +04:00
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("Вы серьезно хотите удалить клиента? :_) та за что...", "Вопрос",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
2024-04-07 00:01:10 +04:00
|
|
|
|
_logger.LogInformation($"Удален клиент под номером {id}");
|
2024-04-06 17:15:38 +04:00
|
|
|
|
|
|
|
|
|
if (!_clientLogic.Delete(new ClientBindingModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
2024-04-07 00:01:10 +04:00
|
|
|
|
catch (Exception ex)
|
2024-04-06 17:15:38 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message, "Не удалось удалить клиента");
|
|
|
|
|
_logger.LogError(ex.Message, "Не удалось удалить клиента");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-07 00:01:10 +04:00
|
|
|
|
}
|