PIbd22_Kuznetsov_A.V._Sewin.../SewingDresses/SewingDressesView/ImplementsForm.cs

95 lines
2.4 KiB
C#
Raw Permalink Normal View History

2024-05-26 13:40:22 +04:00
using Microsoft.Extensions.Logging;
using SewingDressesContracts.BusinessLogicsContracts;
using SewingDressesContracts.BindingModels;
using SewingDressesDatabaseImplement.Models;
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-06-22 21:11:56 +04:00
using SewingDressesContracts.DI;
2024-05-26 13:40:22 +04:00
namespace SewingDressesView
{
public partial class ImplementsForm : Form
{
private readonly ILogger _logger;
private readonly IImplementLogic _logic;
public ImplementsForm(ILogger<ImplementsForm> logger, IImplementLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void LoadData()
{
try
{
2024-06-22 21:11:56 +04:00
dataGridView.FillAndConfigGrid(_logic.ReadList(null));
2024-05-26 13:40:22 +04:00
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading employees");
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
2024-06-22 21:11:56 +04:00
var form = DependencyManager.Instance.Resolve<ImplementForm>();
if (form.ShowDialog() == DialogResult.OK)
2024-05-26 13:40:22 +04:00
{
2024-06-22 21:11:56 +04:00
LoadData();
2024-05-26 13:40:22 +04:00
}
2024-06-22 21:11:56 +04:00
2024-05-26 13:40:22 +04:00
}
private void ImplementsForm_Load(object sender, EventArgs e)
{
LoadData();
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
2024-06-22 21:11:56 +04:00
var form = DependencyManager.Instance.Resolve<ImplementForm>();
form.ID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
2024-05-26 13:40:22 +04:00
{
2024-06-22 21:11:56 +04:00
LoadData();
2024-05-26 13:40:22 +04:00
}
2024-06-22 21:11:56 +04:00
2024-05-26 13:40:22 +04:00
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
_logger.LogInformation("Delete component: {ComponentName}- {Count}", dataGridView.SelectedRows[0].Cells[1].Value);
_logic?.Delete(new ImplementBindingModel{ Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
}
}