亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 Firestore 增加價值

從 Firestore 增加價值

達令說 2024-01-28 16:26:03
我的條目看起來像這樣:在輸入數據之前,必須使用條碼掃描儀填寫條碼。當 Firestore 中存在條形碼時,我希望增加產品數量。當條形碼在Firestore中不可用時,Intent到另一個類。代碼 :@Overridepublic void handleResult(Result result) {    final String scanResult = result.getText();    ToneGenerator toneNotification = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);    toneNotification.startTone(ToneGenerator.TONE_PROP_BEEP, 150);    collectionReference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {        @Override        public void onComplete(@NonNull Task<QuerySnapshot> task) {            if (task.isSuccessful()) {                for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {                    // if barcode is existing, then product quantity to increment                    if (queryDocumentSnapshot.getString("barCode") != null) {                        collectionReference.document(queryDocumentSnapshot.getId()).update("productQuantity", FieldValue.increment(1));                        Intent moveView = new Intent(ScannersActivity.this, ViewData.class);                        moveView.putExtra("documentID", documentID);                        startActivity(moveView);                        finish();                    } else { // If barcode is not available in firestore, then intent to another class                        Intent moveCode = new Intent(ScannersActivity.this, AddItems.class);                        moveCode.putExtra("sendDocumentID", documentID);                        moveCode.putExtra("ScanResult", scanResult);                        startActivity(moveCode);                        finish();                    }                }            }        }    });}
查看完整描述

2 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

productQuantity要根據財產的存在增加財產的價值barCode,請嘗試以下代碼行:


collectionReference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

    @Override

    public void onComplete(@NonNull Task<QuerySnapshot> task) {

        if (task.isSuccessful()) {

            for (QueryDocumentSnapshot document : task.getResult()) {

                if (document.getString("barCode") != null) {

                    collectionReference.document(document.getId()).update(

                        "productQuantity", FieldValue.increment(1)

                    );

                }

            }

        }

    }

});


查看完整回答
反對 回復 2024-01-28
?
ITMISS

TA貢獻1871條經驗 獲得超8個贊

這將確定條形碼是否存在。您可以填寫交易TODO注釋來更新數量值。


public void handleResult(Result result) {

? String scanResult = result.getText();

? // ...


? collectionReference

? ? .whereEqualTo("barCode", scanResult)

? ? .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

? ? ? @Override

? ? ? public void onComplete(@NonNull Task<QuerySnapshot> task) {

? ? ? ? if (task.isSuccessful() && task.getResult().size() > 0) {

? ? ? ? ? // TODO barcode exists; increase qty

? ? ? ? }

? ? ? ? else {

? ? ? ? ? // barcode not found, new Intent

? ? ? ? }

? ? ? }

? ? });

}


查看完整回答
反對 回復 2024-01-28
  • 2 回答
  • 0 關注
  • 163 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號