116 lines
3.7 KiB
C#
116 lines
3.7 KiB
C#
using System.Windows.Forms;
|
|
using System;
|
|
|
|
namespace Dem41
|
|
|
|
public partial class MainForm : Form
|
|
{
|
|
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
context.SaveChanges();
|
|
dataGridView1.Refresh();
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
context = new();
|
|
context.Database.EnsureCreated();
|
|
|
|
context.Tovars.Include(x => x.Categoria)
|
|
.Include(x => x.Proizvoditel).
|
|
Include(x => x.Postavshick).
|
|
Include(x => x.EdIzm).Load();
|
|
|
|
context.Categories.Load();
|
|
context.Proizvoditels.Load();
|
|
context.Postovshiks.Load();
|
|
context.EdenitsaIzmerenia.Load();
|
|
|
|
tovarBindingSource.DataSource = context.Tovars.Local.ToBindingList();
|
|
categoriaBindingSource.DataSource = context.Categories.Local.ToBindingList();
|
|
postovshickBindingSource.DataSource = context.Postovshiks.Local.ToBindingList();
|
|
proizvoditelBindingSource.DataSource = context.Proizvoditels.Local.ToBindingList();
|
|
edenitsa_izmereniaBindingSource.DataSource = context.EdenitsaIzmerenia.Local.ToBindingList();
|
|
|
|
Populate();
|
|
}
|
|
|
|
private void saveButton_Click(object sender, EventArgs e) => Save();
|
|
|
|
private void addButton_Click(object sender, EventArgs e)
|
|
{
|
|
EditForm addForm = new EditForm();
|
|
addForm.tovarBindingSource.DataSource = tovarBindingSource.AddNew();
|
|
((Tovar)addForm.tovarBindingSource.DataSource).CategoriaId = 0;
|
|
((Tovar)addForm.tovarBindingSource.DataSource).ProizvoditelId = 0;
|
|
((Tovar)addForm.tovarBindingSource.DataSource).EdIzmId = 0;
|
|
|
|
addForm.proizvoditelBindingSource.DataSource = proizvoditelBindingSource.DataSource;
|
|
addForm.postovshikBindingSource.DataSource = postovshickBindingSource.DataSource;
|
|
addForm.edenitsaIzmereniumBindingSource.DataSource = edenitsa_izmereniaBindingSource.DataSource;
|
|
|
|
addForm.onSave += () =>
|
|
{
|
|
Save();
|
|
};
|
|
|
|
addForm.ShowDialog();
|
|
}
|
|
|
|
private void editButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (tovarBindingSource.Current == null)
|
|
{
|
|
MessageBox.Show("Выберите столбец"); return;
|
|
}
|
|
|
|
EditForm editForm = new EditForm();
|
|
editForm.tovarBindingSource.DataSource = tovarBindingSource.Current;
|
|
editForm.proizvoditelBindingSource.DataSource = proizvoditelBindingSource.DataSource;
|
|
editForm.postovshikBindingSource.DataSource = postovshickBindingSource.DataSource;
|
|
editForm.edenitsaIzmereniumBindingSource.DataSource = edenitsa_izmereniaBindingSource.DataSource;
|
|
|
|
editForm.onSave += () =>
|
|
{
|
|
Save();
|
|
};
|
|
|
|
editForm.ShowDialog();
|
|
}
|
|
|
|
private void backButton_Click(object sender, EventArgs e)
|
|
{
|
|
new AutorizationForm().Show();
|
|
Hide();
|
|
}
|
|
|
|
private void Populate()
|
|
{
|
|
foreach (var item in tovarBindingSource)
|
|
{
|
|
TovarCard tovarCard = new();
|
|
tovarCard.tovarBindingSource.DataSource = item;
|
|
flowLayoutPanel1.Controls.Add(tovarCard);
|
|
}
|
|
}
|
|
|
|
private void nameFilterBox_TextChanged(object sender, EventArgs e)
|
|
{
|
|
tovarBindingSource.Filter = nameFilterBox.Text;
|
|
dataGridView1.Refresh();
|
|
}
|
|
}
|
|
}
|