2024-05-01 21:05:07 +04:00
|
|
|
|
using DinerContracts.BindingModels;
|
|
|
|
|
using DinerContracts.BusinessLogicsContracts;
|
|
|
|
|
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 DinerView {
|
|
|
|
|
public partial class FormClient : Form {
|
|
|
|
|
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly IClientLogic _logic;
|
|
|
|
|
|
|
|
|
|
public FormClient(ILogger<FormClient> logger, IClientLogic logic) {
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadData() {
|
|
|
|
|
try {
|
2024-06-14 18:52:24 +04:00
|
|
|
|
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
|
2024-05-01 21:05:07 +04:00
|
|
|
|
_logger.LogInformation("Загрузка клиентов");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки клиентов");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormClient_Load(object sender, EventArgs e) {
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
try {
|
|
|
|
|
if (!_logic.Delete(new ClientBindingModel { ID = id })) {
|
|
|
|
|
throw new Exception("Ошиюка при удалении. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("Удаление клиента");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
_logger.LogError(ex, "Ошибка удалении клиента");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonUpdate_Click(object sender, EventArgs e) {
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|