//删除房间的时候 private void button3_Click(object sender, EventArgs e) { //选中 if (dgvRoomInfo.SelectedRows.Count > 0) { if (DialogResult.OK == MessageBox.Show("是否删除", "删除", MessageBoxButtons.OKCancel)) { //开始删除 int id = Convert.ToInt32(dgvRoomInfo.SelectedRows[0].Cells[0].Value); DeskInfoBLL bll = new DeskInfoBLL(); //有正在使用的餐桌 if (Convert.ToInt32(bll.GetDeskState(id)) > 0) { MessageBox.Show("有餐桌正在使用不能删除"); } else { //删除房间,删除该房间下的餐桌 RoomInfoBLL rbll = new RoomInfoBLL(); //判断一个该房间下是否有餐桌,有就删,没有就直接删房间 if (bll.DeleteDesk(id) && rbll.DeleteRoomById(id)) { MessageBox.Show("操作成功"); LoadRoomInfoByDelFlag(0); LoadDeskInfoByDelFlag(0); } else { MessageBox.Show("操作失败"); } } } } }
//删除 private void btnDelete_Click(object sender, EventArgs e) { if (dgvDeskInfo.SelectedRows.Count > 0) { //删除餐桌的时候要判断该餐桌是否被使用 int id = Convert.ToInt32(dgvDeskInfo.SelectedRows[0].Cells[0].Value); //省略了 DeskInfoBLL bll = new DeskInfoBLL(); string str = bll.DeleteDesk(id) ? "操作成功" : "操作失败"; MessageBox.Show(str); LoadDeskInfoByDelFlag(0); } }