Beispiel #1
0
 private async void btnAdd_Click(object sender, EventArgs e)
 {
     using (frmAddEditUser frm = new frmAddEditUser(new UsersTable()))
     {
         if (frm.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 usersTableBindingSource.Add(frm.Users);
                 db.UsersTables.Add(frm.Users);
                 await db.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Beispiel #2
0
        private async void btnEdit_Click(object sender, EventArgs e)
        {
            UsersTable obj = usersTableBindingSource.Current as UsersTable;

            if (obj != null)
            {
                using (frmAddEditUser frm = new frmAddEditUser(obj))
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            usersTableBindingSource.EndEdit();
                            await db.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }