public int DeleteCatalogue(CatalogueDTO catalogue, SqlTransaction trans) { CatalogueDAO dao = new CatalogueDAO(); CopyBUS copyBus = new CopyBUS(); bool isInScopeCreated = false; int rs = 1; if (trans == null) { isInScopeCreated = true; trans = ConnectionManager.Con.BeginTransaction("CAT_DEL_TRANSACT"); } List<CopyDTO> list = copyBus.GetCopyByISBN(catalogue.ISBN); foreach (CopyDTO copyDTO in list) { rs = rs & copyBus.DeleteCopy(copyDTO, trans); if (rs == 0) break; } if (rs == 0) { if (isInScopeCreated) trans.Rollback(); } else { rs = rs & dao.DeleteCatalogue(catalogue, trans); if (isInScopeCreated) if (rs == 0) trans.Rollback(); else trans.Commit(); } return rs; }
private void ribeAction_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (e.Button.Kind == ButtonPredefines.Ellipsis) { } else { if (e.Button.Kind == ButtonPredefines.Delete) { CopyBUS copyBus = new CopyBUS(); CopyDTO dto = (CopyDTO)grvCopyDetail.GetFocusedRow(); if (dto.Status == (int)CopyStatus.AVAILABLE) { if (copyBus.DeleteCopy(dto, null) == 1) { _listCopy.Remove(dto); _copyResult.Remove(dto); grdDetailedCopy.RefreshDataSource(); _catalogue.NumberOfCopies--; if (dto.Status == (int) CopyStatus.AVAILABLE) { _catalogue.AvailableCopies--; } CatalogueBUS bus = new CatalogueBUS(); if (bus.UpdateCatalogue(_catalogue, null) == 0) { MessageBox.Show("Có lỗi trong quá trình xóa bản sao !!!"); } MessageBox.Show("Đã xóa bản sao thành công !!!"); } else { MessageBox.Show("Xóa bản sao thất bại !!!"); } } else { MessageBox.Show("Không thể xoá bản sao này vì bản sao đã bị xoá hoặc đang được mượn!"); } } } }