111 lines
3.6 KiB
C#
111 lines
3.6 KiB
C#
using DressAtelierContracts.BindingModels;
|
|
using DressAtelierContracts.BusinessLogicContracts;
|
|
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 SewingDresses
|
|
{
|
|
public partial class FormAteliers : Form
|
|
{
|
|
private readonly ILogger<FormAteliers> _logger;
|
|
private readonly IAtelierLogic _logic;
|
|
public FormAteliers(ILogger<FormAteliers> logger, IAtelierLogic logic)
|
|
{
|
|
InitializeComponent();
|
|
_logger = logger;
|
|
_logic = logic;
|
|
}
|
|
|
|
private void FormAteliers_Load(object sender, EventArgs e)
|
|
{
|
|
LoadData();
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
try
|
|
{
|
|
var list = _logic.ReadList(null);
|
|
|
|
if (list != null)
|
|
{
|
|
atelierGridView.DataSource = list;
|
|
atelierGridView.Columns["DressesList"].Visible = false;
|
|
atelierGridView.Columns["ID"].Visible = false;
|
|
}
|
|
_logger.LogInformation("Loading atelier");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error loading atelier");
|
|
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormAtelier));
|
|
if (service is FormAtelier form)
|
|
{
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ButtonChange_Click(object sender, EventArgs e)
|
|
{
|
|
if (atelierGridView.SelectedRows.Count == 1)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormAtelier));
|
|
if (service is FormAtelier form)
|
|
{
|
|
form.ID = Convert.ToInt32(atelierGridView.SelectedRows[0].Cells["ID"].Value);
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadData();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ButtonDelete_Click(object sender, EventArgs e)
|
|
{
|
|
if (atelierGridView.SelectedRows.Count == 1)
|
|
{
|
|
if (MessageBox.Show("Delete record?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
int id = Convert.ToInt32(atelierGridView.SelectedRows[0].Cells["ID"].Value);
|
|
_logger.LogInformation("Atelier deletion");
|
|
try
|
|
{
|
|
if (!_logic.Delete(new AtelierBindingModel
|
|
{
|
|
ID = id
|
|
}))
|
|
{
|
|
throw new Exception("Deletion error. Extra information in logs.");
|
|
}
|
|
LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Atelier deletion error");
|
|
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|