private void dg_Room_CellContentClick(object sender, DataGridViewCellEventArgs e) { int id = Convert.ToInt32(dg_Room.Rows[e.RowIndex].Cells["RoomId"].Value); if (dg_Room.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) { string command = dg_Room.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (command.ToLower() == "delete") { try { if (MessageBox.Show("Do you want to delete", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var Room = db.Rooms.Where(r => r.RoomId == id).FirstOrDefault(); db.Rooms.Remove(Room); db.SaveChanges(); MessageBox.Show("Room Successfully deleted"); LoadRoom(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (command.ToLower() == "edit") { AddRoom addRoom = new AddRoom(); addRoom.Show(); } } }
private void addRoomToolStripMenuItem_Click(object sender, EventArgs e) { AddRoom add = new AddRoom(); add.Show(); }