68 lines
2.1 KiB
C#
68 lines
2.1 KiB
C#
using Data.Models;
|
|
using Data.Repositories;
|
|
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 View
|
|
{
|
|
public partial class ManufacturerForm : Form
|
|
{
|
|
private readonly IManufacturerRepository _manufacturerRepository;
|
|
|
|
public ManufacturerForm(IManufacturerRepository manufacturerRepository)
|
|
{
|
|
InitializeComponent();
|
|
_manufacturerRepository = manufacturerRepository;
|
|
LoadManufacturers();
|
|
}
|
|
|
|
private void LoadManufacturers()
|
|
{
|
|
var manufacturers = _manufacturerRepository.GetAllManufacturers().ToList();
|
|
dataGridView.DataSource = manufacturers;
|
|
}
|
|
|
|
private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if (e.RowIndex >= 0)
|
|
{
|
|
var manufacturer = dataGridView.Rows[e.RowIndex].DataBoundItem as Manufacturer;
|
|
if (manufacturer != null)
|
|
{
|
|
_manufacturerRepository.UpdateManufacturer(manufacturer);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
|
|
{
|
|
var manufacturer = e.Row.DataBoundItem as Manufacturer;
|
|
if (manufacturer != null)
|
|
{
|
|
if (MessageBox.Show("Are you sure you want to delete this manufacturer?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
_manufacturerRepository.DeleteManufacturer(manufacturer.Id);
|
|
}
|
|
else
|
|
{
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dataGridView_UserAddedRow(object sender, DataGridViewRowEventArgs e)
|
|
{
|
|
var manufacturer = new Manufacturer { Name = "" };
|
|
_manufacturerRepository.AddManufacturer(manufacturer);
|
|
LoadManufacturers();
|
|
}
|
|
}
|
|
}
|