Esempio n. 1
0
 private async void addbtn_Click(object sender, EventArgs e)
 {
     using (categoriesaddform cateadd = new categoriesaddform(new Categories()))
     {
         if (cateadd.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 categoriesBindingSource.Add(cateadd.CategoryInfo);
                 test.Categories.Add(cateadd.CategoryInfo);
                 await test.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Esempio n. 2
0
        private async void editbtn_Click(object sender, EventArgs e)
        {
            Categories obj = categoriesBindingSource.Current as Categories;

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