private void savingContact(ContactDB contact) { //this.contact = contact; client.ContactDB.Add(contact); //Data.db.ContactDB.Add(contact); Data.db.SaveChanges(); contactDBBindingSource.ResetBindings(false); }
public void addContact() { String nom = txtContactName.Text.Trim(); String fonction = txtContactFonction.Text; String email = txtContactEmail.Text; String telephone = txtContactTelephone.Text; contact = new ContactDB(); contact.ClientDB = client; contact.nom = nom; contact.fonction = fonction; contact.email = email; contact.telephone = telephone; contact.idClient = client.idClient; }
private void grdContact_SelectionChanged(object sender, EventArgs e) { foreach (DataGridViewRow row in grdContact.SelectedRows) { if (row != null && row.Cells[0].Value != null) { Int32 id; Boolean b = Int32.TryParse(row.Cells[0].Value.ToString(), out id); if (b && id != 0) { contact = Data.db.ContactDB.Find(id); } } } }
private void btnSupprimerContact_Click(object sender, EventArgs e) { if (contact != null) { if (MessageBox.Show("Voulez-vous supprimer le contact " + contact.nom, "Supprimer un contact", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //Delete from the DB Data.db.ContactDB.Remove(contact); Data.db.SaveChanges(); //check if the grdContact isn't empty if (grdContact.Rows.Count > 0) { //set the selected row to the first one grdContact.Rows[0].Selected = true; } else { //if no more row in the gridView then set the client to null after deleting the last client contact = null; } } } }
private void UpdatingContact(ContactDB contact) { Data.db.SaveChanges(); contactDBBindingSource.ResetBindings(false); }