Exemple #1
0
 private async void BtnAdd_Click(object sender, EventArgs e)
 {
     using (FormAddEdit frm = new FormAddEdit(new Student()
     {
         gender = false
     }))
     {
         if (frm.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 studentBindingSource.Add(frm.StudentInfo);
                 db.Students.Add(frm.StudentInfo);
                 await db.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Exemple #2
0
        private async void BtnEdit_Click(object sender, EventArgs e)
        {
            Student obj = studentBindingSource.Current as Student;

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