示例#1
0
 private async void tbAdd_Click(object sender, EventArgs e)
 {
     using (frmLecturerInfo frm = new frmLecturerInfo(new Lecturer()))
     {
         if (frm.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 lecturerBindingSource.Add(frm.LecturerInfo);
                 db.Lecturers.Add(frm.LecturerInfo);
                 await db.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
示例#2
0
        private async void tbEdit_Click(object sender, EventArgs e)
        {
            Lecturer obj = lecturerBindingSource.Current as Lecturer;

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