Exemplo n.º 1
0
 private async void tbAdd_Click(object sender, EventArgs e)
 {
     using (frmBuildingInfo frm = new frmBuildingInfo(new Building()))
     {
         if (frm.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 buildingBindingSource.Add(frm.BuildingInfo);
                 db.Buildings.Add(frm.BuildingInfo);
                 await db.SaveChangesAsync();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Exemplo n.º 2
0
        private async void tbEdit_Click(object sender, EventArgs e)
        {
            Building obj = buildingBindingSource.Current as Building;

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