private void wbntLoaiphong_ButtonClick(object sender, DevExpress.XtraBars.Docking2010.ButtonEventArgs e) { switch (e.Button.Properties.Caption.ToString()) { case "Thêm Loại Phòng": themLoaiPhong1.Initialize(); LoaiPhongPagecontrol.SelectedPage = PageThemloaiphong; break; case "Sửa Loại Phòng": if (gridViewLoaiPhong.DataRowCount == 0) { XtraMessageBox.Show("Không có loại phòng nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } suaLoaiPhong1.RefreshDataBinding(new DTO.LoaiPhongDTO((int)dtLoaiPhong.Rows[gridViewLoaiPhong.GetFocusedDataSourceRowIndex()]["MaLP"], dtLoaiPhong.Rows[gridViewLoaiPhong.GetFocusedDataSourceRowIndex()]["TenLoaiPhong"].ToString())); LoaiPhongPagecontrol.SelectedPage = PageSualoaiphong; break; case "Xóa Loại Phòng": if (gridViewLoaiPhong.DataRowCount == 0) { XtraMessageBox.Show("Không có loại phòng nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //Xác nhận xóa? if (XtraMessageBox.Show("Bạn có chắc muốn xóa loại phòng '" + dtLoaiPhong.Rows[gridViewLoaiPhong.GetFocusedDataSourceRowIndex()]["TenLoaiPhong"].ToString() + "' ?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) { return; } //Kiểm tra xem loại phòng có phòng nào không DataRowView rowView = gridViewLoaiPhong.GetRow(gridViewLoaiPhong.FocusedRowHandle) as DataRowView; DataView view = rowView.CreateChildView("Thông tin phòng"); if (view.Count == 0) { LoaiPhongBUS.XoaDonGiaPhong((int)dtLoaiPhong.Rows[gridViewLoaiPhong.GetFocusedDataSourceRowIndex()]["MaLP"]); LoaiPhongBUS.XoaLoaiPhong(new DTO.LoaiPhongDTO((int)dtLoaiPhong.Rows[gridViewLoaiPhong.GetFocusedDataSourceRowIndex()]["MaLP"], dtLoaiPhong.Rows[gridViewLoaiPhong.GetFocusedDataSourceRowIndex()]["TenLoaiPhong"].ToString())); //Thông báo xóa loại phòng thành công XtraMessageBox.Show("Xóa loại phòng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); RefreshDataBinding(); } else { //Thông báo không thể xóa loại phòng do có phòng có loại phòng đó XtraMessageBox.Show("Không thể xóa loại phòng do tồn tại phòng chứa mã phòng này!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } break; case "Quản Lý Phòng": goToQuanLyPhong(); break; } }