Exemplo n.º 1
0
 //sử dụng Linq
 private async void MtyAdd_Click(object sender, EventArgs e)
 {
     using (frmAddFlower frm = new frmAddFlower(new hoa()
     {
         TheForest = false
     }))
     {
         if (frm.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 hoaBindingSource.Add(frm.hoa);
                 db.hoas.Add(frm.hoa);
                 await db.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Exemplo n.º 2
0
        private async void MtEdit_Click(object sender, EventArgs e)
        {
            hoa obj = hoaBindingSource.Current as hoa;

            if (obj != null)// kiểm tra data obj khác nulll thì chạy
            {
                using (frmAddFlower frm = new frmAddFlower(obj))
                {
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            hoaBindingSource.EndEdit();
                            await db.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }