Ejemplo n.º 1
0
 public void storeProductClick(TextView view) {
   this.storeProduct.setVisibility(FrameLayout.GONE);
   this.storeProductDetail.setVisibility(FrameLayout.VISIBLE);
   Integer index = this.hsProduct.get(view.getText());
   Log.i("StoreMainActivity - storeProductClick", "index: " + index);
   this.updateDataDetail(index);
   ProductInfo product = listProduct.get(index);
   if (productTransactionDetailInfo == null) {
     productTransactionDetailInfo = new TransactionDetailInfo();
   }
   productTransactionDetailInfo.setCategoryId(product.getCategoryId());
   productTransactionDetailInfo.setProductId(product.getProductId());
   productTransactionDetailInfo.setProductName(product.getName());
   productTransactionDetailInfo.setUnitPrice(product.getUnitPrice());
 }
Ejemplo n.º 2
0
  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);
    }
  }