private void buttonCreate_Click(object sender, EventArgs e) { FormElementPartner formElementPartner = new FormElementPartner(); DialogResult result = formElementPartner.ShowDialog(this); if (result == DialogResult.OK) { Partner Partner = new Partner(); Partner.supplier = formElementPartner.checkBoxSupplier.Checked; Partner.email = formElementPartner.textBoxEmail.Text.ToString(); Partner.fio = formElementPartner.textBoxFIO.Text.ToString(); Partner.address = formElementPartner.textBoxAddress.Text.ToString(); Partner.phone = formElementPartner.textBoxPhone.Text.ToString(); Partner.country = formElementPartner.textBoxCountry.Text.ToString(); db.Partner.Add(Partner); db.SaveChanges(); checkFilter(); dataGridView.Refresh(); } }
private void dataGridView_MouseDoubleClick(object sender, MouseEventArgs e) { var currentRow = dataGridView.CurrentRow; if (currentRow != null) { FormElementPartner formElementPartner = new FormElementPartner(); int idPartner = Int32.Parse(currentRow.Cells["id"].Value.ToString()); Partner Partner = db.Partner.Find(idPartner); formElementPartner.textBoxId.Text = currentRow.Cells["id"].Value.ToString(); formElementPartner.checkBoxSupplier.Checked = (bool)currentRow.Cells["Supplier"].Value; formElementPartner.textBoxEmail.Text = currentRow.Cells["email"].Value.ToString(); formElementPartner.textBoxFIO.Text = currentRow.Cells["fio"].Value.ToString(); formElementPartner.textBoxAddress.Text = currentRow.Cells["address"].Value.ToString(); formElementPartner.textBoxPhone.Text = currentRow.Cells["phone"].Value.ToString(); formElementPartner.textBoxCountry.Text = currentRow.Cells["country"].Value.ToString(); DialogResult result = formElementPartner.ShowDialog(this); if (result == DialogResult.OK && Partner != null) { Partner.supplier = formElementPartner.checkBoxSupplier.Checked; Partner.email = formElementPartner.textBoxEmail.Text.ToString(); Partner.fio = formElementPartner.textBoxFIO.Text.ToString(); Partner.address = formElementPartner.textBoxAddress.Text.ToString(); Partner.phone = formElementPartner.textBoxPhone.Text.ToString(); Partner.country = formElementPartner.textBoxCountry.Text.ToString(); db.SaveChanges(); checkFilter(); dataGridView.Refresh(); } } }