2024-05-24 12:23:50 +04:00
|
|
|
|
using FurnitureAssemblyContracts.BindingModels;
|
|
|
|
|
using FurnitureAssemblyContracts.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 FurnitureAssemblyView
|
|
|
|
|
{
|
|
|
|
|
// Форма со всеми созданными заготовками
|
2024-05-24 13:42:42 +04:00
|
|
|
|
public partial class FormKomments : Form
|
2024-05-24 12:23:50 +04:00
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
2024-05-24 13:05:47 +04:00
|
|
|
|
private readonly IKommentLogic _logic;
|
2024-05-24 12:23:50 +04:00
|
|
|
|
|
2024-05-24 13:42:42 +04:00
|
|
|
|
public FormKomments(ILogger<FormKomments> logger, IKommentLogic logic)
|
2024-05-24 12:23:50 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_logic = logic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FormWorkPiece_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Загрузка созданных заготовок
|
|
|
|
|
private void LoadData()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _logic.ReadList(null);
|
|
|
|
|
|
|
|
|
|
// Растягиваем колонку Название на всю ширину, колонку Id скрываем
|
|
|
|
|
if (list != null)
|
|
|
|
|
{
|
|
|
|
|
dataGridView.DataSource = list;
|
|
|
|
|
dataGridView.Columns["Id"].Visible = false;
|
|
|
|
|
dataGridView.Columns["WorkPieceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("Загрузка заготовок");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка загрузки заготовок");
|
|
|
|
|
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-05-24 13:42:42 +04:00
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormKomment));
|
2024-05-24 12:23:50 +04:00
|
|
|
|
|
2024-05-24 13:42:42 +04:00
|
|
|
|
if (service is FormKomment form)
|
2024-05-24 12:23:50 +04:00
|
|
|
|
{
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Проверяем наличие выделенной строки
|
|
|
|
|
private void ButtonUpdate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
|
|
|
{
|
2024-05-24 13:42:42 +04:00
|
|
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormKomment));
|
2024-05-24 12:23:50 +04:00
|
|
|
|
|
2024-05-24 13:42:42 +04:00
|
|
|
|
if (service is FormKomment form)
|
2024-05-24 12:23:50 +04:00
|
|
|
|
{
|
|
|
|
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("Удаление компонента");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-05-24 13:05:47 +04:00
|
|
|
|
if (!_logic.Delete(new KommentBindingModel
|
2024-05-24 12:23:50 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex, "Ошибка удаления компонента");
|
|
|
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
LoadData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|