Exemplo n.º 1
0
 private async void btnAddStudent_Click(object sender, EventArgs e)
 {
     using (frmStudentInfo frm = new frmStudentInfo(new Student()
     {
         StudyForm = false
     }))
     {
         if (frm.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 studentBindingSource3.Add(frm.StudentInfo);
                 db.Students.Add(frm.StudentInfo);
                 await db.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Exemplo n.º 2
0
        private async void btnEdit_Click(object sender, EventArgs e)
        {
            Student obj = studentBindingSource3.Current as Student;

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