//delete buttons private void buttonDelRowBakery_Click(object sender, EventArgs e) { try { bakery bkr = (bakery)dataGridView1.CurrentRow.DataBoundItem; var emp = (from c in ctx.employee where (c.EM_BK == bkr.BK_ID) select c).Any(); if (emp) { MessageBox.Show("Нельзя удалить пекарню - увольте работников!"); } else { bakeryBindingSource.RemoveCurrent(); ctx.SaveChanges(); } } catch (Exception) { MessageBox.Show("Error."); throw; } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int r = -1; r = Convert.ToInt32(dataGridView1.CurrentRow.Cells["BK_ID"].Value); try { textBoxBakeryId.Text = r.ToString(); textBoxBakeryAdrs.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString() + Environment.NewLine + dataGridView1.CurrentRow.Cells[2].Value.ToString(); bakery bkr = (bakery)dataGridView1.CurrentRow.DataBoundItem; var b = (from c in ctx.employee where (c.EM_BK == bkr.BK_ID) select c).Count(); textBoxBakeryCount.Text = b.ToString(); } catch (Exception) { MessageBox.Show("error"); } }