private void btnEdit_Click(object sender, EventArgs e) { User obj = usersBindingSource.Current as User; if (obj != null) { using (AddEditUserForm frm = new AddEditUserForm(obj)) { if (frm.ShowDialog() == DialogResult.OK) { try { usersBindingSource.EndEdit(); _context.SaveChanges(); AddOrRemoveTimeTables(frm.UserInfo); 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 (AddEditUserForm frm = new AddEditUserForm(new User())) { if (frm.ShowDialog() == DialogResult.OK) { try { usersBindingSource.Add(frm.UserInfo); _context.Users.Add(frm.UserInfo); _context.SaveChanges(); AddOrRemoveTimeTables(frm.UserInfo); MetroMessageBox.Show(this, "Success", "Message", MessageBoxButtons.OK, MessageBoxIcon.Question); } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }