public boolean increaseProductQty(String id, int amount) throws AppException {
boolean success = true;
ProductManager dataObjectManager = new ProductManager();
Product dataObject = null;
try {
dataObject = dataObjectManager.selectProduct(id);
} catch (AppException ex) {
Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
return false;
}
if (dataObject != null) {
int currQty = dataObject.getQuantityAvailable();
int newQty = currQty + amount;
Product newDataObject = new Product();
newDataObject.setProductID(dataObject.getProductID());
newDataObject.setProductName(dataObject.getProductName());
newDataObject.setProductDescription(dataObject.getProductDescription());
newDataObject.setQuantityAvailable(newQty);
newDataObject.setProductPrice(dataObject.getProductPrice());
newDataObject.setBarcodeNumber(dataObject.getBarcodeNumber());
newDataObject.setReorderQuantity(dataObject.getReorderQuantity());
newDataObject.setOrderQuantity(dataObject.getOrderQuantity());
try {
success = dataObjectManager.updateProduct(dataObject, newDataObject);
if (success) {
//update caching
Hashtable<String, Product> productDataSet = DataSet.getProductDataSet();
if (productDataSet != null) {
Product oldone = productDataSet.get(id);
Product newone = newDataObject;
newone.setCategory(oldone.getCategory());
productDataSet.remove(id);
productDataSet.put(id, newone);
Hashtable<String, Category> categoryDataSet = DataSet.getCategoryDataSet();
if (categoryDataSet.get(newone.getCategoryCode(newone.getCategoryCode(id))) != null) {
categoryDataSet.get(newone.getCategoryCode(id)).addProduct(newone);
}
}
}
} catch (AppException ex) {
Logger.getLogger(AppController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);