private async void tbAdd_Click(object sender, EventArgs e) { using (frmRoomInfo frm = new frmRoomInfo(new Room())) { if (frm.ShowDialog() == DialogResult.OK) { try { roomBindingSource.Add(frm.RoomInfo); db.Rooms.Add(frm.RoomInfo); await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private async void tbEdit_Click(object sender, EventArgs e) { Room obj = roomBindingSource.Current as Room; if (obj != null) { using (frmRoomInfo frm = new frmRoomInfo(obj)) { if (frm.ShowDialog() == DialogResult.OK) { try { roomBindingSource.EndEdit(); await db.SaveChangesAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }