如何将增量发票编号放入DatabaseReference

我正在创建编号从#1#2#3 ....开始的发票,但是我不知道如何开始。这是我想要的结构:

Invoice#1
|- info...
Invoice#2
|- info...
Invoice#3
|- info...
DatabaseReference ref 
 = FirebaseDatabase.getInstance().getReference().child("Invoice#" {increment}); //how to put increment here? if I declare i=1 in myactivity.java,it only runs in one

这是我拥有的发票模型的一部分

public class Invoice {
    String buyer,seller,typeOfPymt;
    int total;
    String billdate;
    int invoice_num;
    int discount;
    int tax;
    int grand_total;


    public Invoice(String buyer,String seller,int grand_total,String billdate,int invoice_num,int discount) {
        this.buyer = buyer;
        this.seller = seller;
        this.billdate = billdate;
        this.invoice_num = invoice_num;
        this.discount = discount;
        this.grand_total = grand_total;
    }

如何在模型内部添加增量?

comind 回答:如何将增量发票编号放入DatabaseReference

您无法将{crement“参数传递给child()方法,该方法可以帮助您读取最后一个发票编号并生成新的递增编号。

在您的数据库中,一种更合适的方法是使用push()方法生成的随机密钥作为发票的密钥,而那些递增的语音号码则使用该密钥。主要原因是可伸缩性,正如@FrankvanPuffelen在以下文章中解释的那样:

使用上述方法,发票编号将成为发票对象中的一个属性。

本文链接:https://www.f2er.com/3168588.html

大家都在问