97 lines
3.5 KiB
C#
97 lines
3.5 KiB
C#
using Data;
|
|
using Data.Repositories;
|
|
using View;
|
|
using System.Windows.Forms;
|
|
using Microsoft.Office.Interop.Excel;
|
|
using Data.Models;
|
|
|
|
namespace Laba3
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
private readonly IProductRepository _productRepository;
|
|
private readonly IManufacturerRepository _manufacturerRepository;
|
|
|
|
public MainForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository)
|
|
{
|
|
InitializeComponent();
|
|
_productRepository = productRepository;
|
|
_manufacturerRepository = manufacturerRepository;
|
|
InitializeOutputTableResults();
|
|
LoadProducts();
|
|
}
|
|
|
|
private void InitializeOutputTableResults()
|
|
{
|
|
outputTableResults.ConfigureColumns(new List<Library15Gerimovich.ColumnInfo>
|
|
{
|
|
new Library15Gerimovich.ColumnInfo("", 0, false, "Id"),
|
|
new Library15Gerimovich.ColumnInfo("Name", 150, true, "Name"),
|
|
new Library15Gerimovich.ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"),
|
|
new Library15Gerimovich.ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"),
|
|
});
|
|
/*TestObject TestOB = new TestObject(1, "Ôàìèëèÿ", "èìÿ", 10);
|
|
TestObject TestOB2 = new TestObject(1, "Èâàíîâ", "Èâàí", 29);
|
|
|
|
outputTableResults.InsertValue(TestOB);
|
|
outputTableResults.InsertValue(TestOB2);*/
|
|
|
|
}
|
|
|
|
private void LoadProducts()
|
|
{
|
|
var products = _productRepository.GetAllProducts();
|
|
outputTableResults.ClearGrid();
|
|
foreach (var product in products)
|
|
{
|
|
outputTableResults.InsertValue(product);
|
|
}
|
|
}
|
|
|
|
/*private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
outputTableResults.ContextMenuStrip = contextMenuStrip;
|
|
}*/
|
|
|
|
private void addToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var productForm = new ProductForm(_productRepository, _manufacturerRepository);
|
|
if (productForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadProducts();
|
|
}
|
|
}
|
|
|
|
private void editToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
/*if (outputTableResults.SelectedItems.Count > 0)
|
|
{*/
|
|
|
|
var selectedProductId = outputTableResults.GetSelectedObject<Product>().Id;
|
|
var selectedProduct = _productRepository.GetProductById(selectedProductId);
|
|
var productForm = new ProductForm(_productRepository, _manufacturerRepository, selectedProduct);
|
|
if (productForm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadProducts();
|
|
}
|
|
//}
|
|
}
|
|
|
|
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var selectedProductId = outputTableResults.GetSelectedObject<Product>().Id;
|
|
if (MessageBox.Show("Are you sure you want to delete this product?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
_productRepository.DeleteProduct(selectedProductId);
|
|
LoadProducts();
|
|
}
|
|
}
|
|
|
|
private void manufacturersToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var manufacturerForm = new ManufacturerForm(_manufacturerRepository);
|
|
manufacturerForm.ShowDialog();
|
|
}
|
|
}
|
|
}
|