public TradeDepartmentDetailForm(PostgresDataBaseContext db, TradeDepartment department = null) { InitializeComponent(); this.db = db; this.department = department; if (department != null) { this.TbName.Text = this.department.Name; } }
private void BtnDelete_Click(object sender, EventArgs e) { foreach (DataGridViewRow selectedRow in this.dataGridView1.SelectedRows) { var selectedId = selectedRow.Cells["Id"].Value; TradeDepartment selected = db.TradeDepartments.Find(selectedId); db.TradeDepartments.Remove(selected); } db.SaveChanges(); }
private void BtnOk_Click(object sender, EventArgs e) { if (this.department == null) { this.department = new TradeDepartment(); db.TradeDepartments.Add(this.department); } this.department.Name = this.TbName.Text; db.SaveChanges(); this.Close(); }
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; TradeDepartment selected = db.TradeDepartments.Find(selectedId); TradeDepartmentDetailForm add = new TradeDepartmentDetailForm(this.db, selected); add.Show(); }