private void toolStripButtonMuacaEdit_Click(object sender, EventArgs e) { if (dataGridViewMuacot.SelectedRows.Count > 0) { int index = dataGridViewMuacot.SelectedRows[0].Index; int muaca_ezorit_code; bool converted = Int32.TryParse(dataGridViewMuacot[0, index].Value.ToString(), out muaca_ezorit_code); if (converted == false) { return; } Muaca muaca = db.Muacot.Find(muaca_ezorit_code); FormMuaca formMuaca = new FormMuaca(); formMuaca.textBoxMuacaCode.Text = muaca.muaca_ezorit_code.ToString(); formMuaca.textBoxMuacaName.Text = muaca.muaca_name; formMuaca.textBoxMuacaCode.Enabled = false; DialogResult result = formMuaca.ShowDialog(this); if (result == DialogResult.Cancel) { return; } muaca.muaca_name = formMuaca.textBoxMuacaName.Text; db.SaveChanges(); dataGridViewMuacot.Refresh(); // обновляем грид MessageBox.Show("Object updated"); } }
private void toolStripButtonMuacaAdd_Click(object sender, EventArgs e) { FormMuaca formMuaca = new FormMuaca(); DialogResult result = formMuaca.ShowDialog(this); if (result == DialogResult.Cancel) { return; } Muaca muaca = new Muaca(); int muaca_ezorit_code; bool converted = Int32.TryParse(formMuaca.textBoxMuacaCode.Text, out muaca_ezorit_code); if (converted == false) { return; } muaca.muaca_ezorit_code = muaca_ezorit_code; muaca.muaca_name = formMuaca.textBoxMuacaName.Text; db.Muacot.Add(muaca); db.SaveChanges(); MessageBox.Show("New object added"); }