public void btnAddToCartClick(View view) { Log.i("StoreMainActivity - btnAddToCartClick", "Start"); try { TransactionDetailInfo transaction = StoreMainActivity.productTransactionDetailInfo; if (transaction == null || (transaction.getCategoryId() < 5 && transaction.getSizeType() == null)) { Toast.makeText(this, "Xin vui lòng chọn size sản phẩm", Toast.LENGTH_SHORT).show(); return; } TransactionDetailDB db = new TransactionDetailDB(this); ArrayList<TransactionDetailInfo> transactions = db.getTransactions(); for (TransactionDetailInfo transactionDetailInfo : transactions) { if (transaction.getProductId().equals(transactionDetailInfo.getProductId())) { Toast.makeText( this, "Sản phẩm này đã có trong giỏ hàng.\nVui lòng xem giỏ hàng để biết chi tiết.", Toast.LENGTH_SHORT) .show(); return; } } StoreMainActivity.productTransactionDetailInfo.setAddedDate(Calendar.getInstance().getTime()); db.insert(StoreMainActivity.productTransactionDetailInfo); Toast.makeText(this, "Đã thêm vào giỏ hàng", Toast.LENGTH_SHORT).show(); this.updateStoreCart(); this.storeProduct.setVisibility(FrameLayout.VISIBLE); this.storeProductDetail.setVisibility(FrameLayout.GONE); StoreMainActivity.productTransactionDetailInfo = null; } catch (Exception e) { Log.e("StoreMainActivity - btnAddToCartClick", "StoreMainActivity - btnAddToCartClick", e); } }
private void updateStoreCart() { tvStoreCart = (TextView) findViewById(R.id.tvStoreCart); TransactionDetailDB db = new TransactionDetailDB(this); ArrayList<TransactionDetailInfo> listTransactionDetail = new ArrayList<TransactionDetailInfo>(); try { listTransactionDetail = db.getTransactions(); } catch (ParseException e) { Log.e("StoreMainActivity - updateStoreCart", e.getMessage()); } if (tvStoreCart != null) { tvStoreCart.setText(listTransactionDetail.size() + ""); } }
public void btnStoreCartClick(View view) { TransactionDetailDB db = new TransactionDetailDB(this); try { if (db.getTransactions().size() > 0) { Intent intent = new Intent(this, PreviewCartActivity.class); startActivity(intent); } else { Toast.makeText(this, "Không có sản phẩm trong giỏ hàng", Toast.LENGTH_SHORT).show(); } } catch (ParseException e) { Log.e("StoreMainActivity - btnStoreCartClick", e.getMessage()); } }