This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomersList.cs
56 lines (47 loc) · 1.62 KB
/
CustomersList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Windows.Forms;
using Microsoft.EntityFrameworkCore;
namespace CheckReport
{
public partial class CustomersList : Form
{
private PostgresDataBaseContext db;
public CustomersList(PostgresDataBaseContext db)
{
this.db = db;
InitializeComponent();
}
private void CustomersList_Load(object sender, EventArgs e)
{
db.Customers.Load();
this.dataGridView1.DataSource = db.Customers.Local.ToBindingList();
}
private void BtnAdd_Click(object sender, EventArgs e)
{
CustomerDetailForm add = new CustomerDetailForm(this.db);
add.Show();
}
private void BtnChange_Click(object sender, EventArgs e)
{
if (this.dataGridView1.SelectedRows.Count != 1)
{
MessageBox.Show("Выберите одну строку");
return;
}
var selectedId = this.dataGridView1.SelectedRows[0].Cells["Id"].Value;
Customer selected = db.Customers.Find(selectedId);
CustomerDetailForm add = new CustomerDetailForm(this.db, selected);
add.Show();
}
private void BtnDelete_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow selectedRow in this.dataGridView1.SelectedRows)
{
var selectedId = selectedRow.Cells["Id"].Value;
Customer selected = db.Customers.Find(selectedId);
db.Customers.Remove(selected);
}
db.SaveChanges();
}
}
}