Ejemplo n.º 1
0
 private async void BtnAdd_Click(object sender, EventArgs e)
 {
     using (frmAddClass frm = new frmAddClass(new Class()))
     {
         if (frm.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 classBindingSource.Add(frm.ClassInfo);
                 db.Classes.Add(frm.ClassInfo);
                 await db.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Ejemplo n.º 2
0
        private async void BtnEdit_Click(object sender, EventArgs e)
        {
            Class obj = classBindingSource.Current as Class;

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