Ejemplo n.º 1
0
 private async void addbtn_Click(object sender, EventArgs e)
 {
     using (contactsaddformcs conadd = new contactsaddformcs(new Contacts()))
     {
         if (conadd.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 contactsBindingSource.Add(conadd.ContactInfo);
                 test.Contacts.Add(conadd.ContactInfo);
                 await test.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Ejemplo n.º 2
0
        private async void editbtn_Click(object sender, EventArgs e)
        {
            Contacts obj = contactsBindingSource.Current as Contacts;

            if (obj != null)
            {
                using (contactsaddformcs conadd = new contactsaddformcs(obj))
                {
                    if (conadd.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            contactsBindingSource.EndEdit();
                            await test.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }