private void toolStripButtonLishkaEdit_Click(object sender, EventArgs e) { if (dataGridViewLishkot.SelectedRows.Count > 0) { int index = dataGridViewLishkot.SelectedRows[0].Index; int lishkat_mana_code; bool converted = Int32.TryParse(dataGridViewLishkot[0, index].Value.ToString(), out lishkat_mana_code); if (converted == false) { return; } Lishka lishka = db.Lishkot.Find(lishkat_mana_code); FormLishka formLishka = new FormLishka(); formLishka.textBoxLishkaCode.Text = lishka.lishkat_mana_code.ToString(); formLishka.textBoxLishkaName.Text = lishka.lishka; formLishka.textBoxLishkaCode.Enabled = false; DialogResult result = formLishka.ShowDialog(this); if (result == DialogResult.Cancel) { return; } lishka.lishka = formLishka.textBoxLishkaName.Text; db.SaveChanges(); dataGridViewLishkot.Refresh(); // обновляем грид MessageBox.Show("Object updated"); } }
private void toolStripButtonLishkaAdd_Click(object sender, EventArgs e) { FormLishka formLishka = new FormLishka(); DialogResult result = formLishka.ShowDialog(this); if (result == DialogResult.Cancel) { return; } Lishka lishka = new Lishka(); int lishkat_mana_code; bool converted = Int32.TryParse(formLishka.textBoxLishkaCode.Text, out lishkat_mana_code); if (converted == false) { return; } lishka.lishkat_mana_code = lishkat_mana_code; lishka.lishka = formLishka.textBoxLishkaName.Text; db.Lishkot.Add(lishka); db.SaveChanges(); MessageBox.Show("New object added"); }