private void toolStripButtonStreetEdit_Click(object sender, EventArgs e) { if (dataGridViewStreets.SelectedRows.Count > 0) { int index = dataGridViewStreets.SelectedRows[0].Index; int street_code; bool converted = Int32.TryParse(dataGridViewStreets[0, index].Value.ToString(), out street_code); if (converted == false) { return; } Street street = db.Streets.Find(street_code); FormStreet formStreet = new FormStreet(db); formStreet.textBoxStreetCode.Text = street.street_code.ToString(); formStreet.textBoxStreetName.Text = street.street_name; formStreet.textBoxNameStatus.Text = street.street_name_status; formStreet.textBoxOfficialCode.Text = street.official_code.ToString(); formStreet.comboBoxCity.SelectedIndex = formStreet.comboBoxCity.FindStringExact(street.City.city_name); formStreet.textBoxStreetCode.Enabled = false; DialogResult result = formStreet.ShowDialog(this); if (result == DialogResult.Cancel) { return; } street.street_name = formStreet.textBoxStreetName.Text; street.street_name_status = formStreet.textBoxNameStatus.Text; int official_code; converted = Int32.TryParse(formStreet.textBoxOfficialCode.Text, out official_code); if (converted == false) { return; } street.official_code = official_code; street.city_code = (formStreet.comboBoxCity.SelectedItem as dynamic).Value; // db.SaveChanges(); dataGridViewStreets.Refresh(); // обновляем грид MessageBox.Show("Object updated"); } }
private void toolStripButtonStreetAdd_Click(object sender, EventArgs e) { FormStreet formStreet = new FormStreet(db); DialogResult result = formStreet.ShowDialog(this); if (result == DialogResult.Cancel) { return; } Street street = new Street(); int street_code; bool converted = Int32.TryParse(formStreet.textBoxStreetCode.Text, out street_code); if (converted == false) { return; } street.street_code = street_code; street.street_name = formStreet.textBoxStreetName.Text; street.street_name_status = formStreet.textBoxNameStatus.Text; int official_code; converted = Int32.TryParse(formStreet.textBoxOfficialCode.Text, out official_code); if (converted == false) { return; } street.official_code = official_code; street.city_code = (formStreet.comboBoxCity.SelectedItem as dynamic).Value; db.Streets.Add(street); db.SaveChanges(); MessageBox.Show("New object added"); }