private void deleteObj() { try { if (XtraMessageBox.Show("Bạn có chắc là muốn xóa phòng này?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (objPhong.delete() > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Xóa phòng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); loadData(); } else { XtraMessageBox.Show("Xóa phòng không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { Debug.WriteLine(this.Name + "->deleteObj: " + ex.Message); } }
private void CRUD() { try { switch (function) { case "add": objPhong = new Phong(); setDataObj(); if (objPhong.add() > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Thêm phòng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); reLoadAndFocused(objPhong.id); function = ""; } else XtraMessageBox.Show("Có lỗi trong khi thêm"); break; case "edit": if (objPhong != null) { setDataObj(); if (objPhong.update() > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Sửa phòng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); reLoadAndFocused(objPhong.id); enableEdit(false); function = ""; } else XtraMessageBox.Show("Có lỗi trong khi sửa"); } break; case "delete": if (objPhong != null) { if (XtraMessageBox.Show("Bạn có chắc là muốn xóa phòng?", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.Yes) { int reee = objPhong.delete(); if (reee > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Xóa phòng thành công!"); reLoad(); } else if (reee == -2) { XtraMessageBox.Show("Có thiết bị trong phòng. Vui lòng xóa thiết bị trước!"); } else if (reee == -3) { XtraMessageBox.Show("Xóa sự cố trong phòng trước!"); } else { XtraMessageBox.Show("Lỗi trong khi xóa phòng!"); } } } break; } } catch (Exception ex) { Debug.WriteLine(this.Name + "->CRUD: " + ex.Message); } }
private void CRUD() { try { switch (function) { case "add": objPhong = new Phong(); setDataObj(); if (objPhong.add() > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Thêm phòng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); reLoadAndFocused(objPhong.id); function = ""; } else { XtraMessageBox.Show("Có lỗi trong khi thêm"); } break; case "edit": if (objPhong != null) { setDataObj(); if (objPhong.update() > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Sửa phòng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); reLoadAndFocused(objPhong.id); enableEdit(false); function = ""; } else { XtraMessageBox.Show("Có lỗi trong khi sửa"); } } break; case "delete": if (objPhong != null) { if (XtraMessageBox.Show("Bạn có chắc là muốn xóa phòng?", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.Yes) { int reee = objPhong.delete(); if (reee > 0 && DBInstance.commit() > 0) { XtraMessageBox.Show("Xóa phòng thành công!"); reLoad(); } else if (reee == -2) { XtraMessageBox.Show("Có thiết bị trong phòng. Vui lòng xóa thiết bị trước!"); } else if (reee == -3) { XtraMessageBox.Show("Xóa sự cố trong phòng trước!"); } else { XtraMessageBox.Show("Lỗi trong khi xóa phòng!"); } } } break; } } catch (Exception ex) { Debug.WriteLine(this.Name + "->CRUD: " + ex.Message); } }