private void btnEdit_Click(object sender, EventArgs e) { Patient obj = patientBindingSource.Current as Patient; if (obj != null) { using (AddEditPatientForm frm = new AddEditPatientForm(obj)) { if (frm.ShowDialog() == DialogResult.OK) { try { patientBindingSource.EndEdit(); _context.SaveChanges(); MetroFramework.MetroMessageBox.Show(this, "Success", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void btnAdd_Click(object sender, EventArgs e) { using (AddEditPatientForm frm = new AddEditPatientForm(new Patient())) { if (frm.ShowDialog() == DialogResult.OK) { try { patientBindingSource.Add(frm.PatientInfo); _context.Patients.Add(frm.PatientInfo); _context.SaveChanges(); MetroFramework.MetroMessageBox.Show(this, "Success", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }