Beispiel #1
0
        private void mtEdit_Click(object sender, EventArgs e)
        {
            Student obj = studentBindingSource.Current as Student;

            if (obj != null)
            {
                using (frmAddEditStudent frm = new frmAddEditStudent(obj))
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            studentBindingSource.EndEdit();
                            await db.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            {
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
 private async void mtAdd_Click(object sender, EventArgs e)
 {
     using (frmAddEditStudent frm = new frmAddEditStudent(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);
             }
         }
     }
 }