【问题标题】:How to put the increment invoice number to DatabaseReference如何将增量发票编号放入 DatabaseReference
【发布时间】:2019-11-04 07:03:25
【问题描述】:

我正在创建一个增量编号从 #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;
    }

如何在模型中添加增量?

【问题讨论】:

  • 您可以在 sharedPreference 中添加最后一个增量 Integer 并在工作时将其添加 +1,保存它..

标签: java android firebase firebase-realtime-database


【解决方案1】:

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

在您的数据库中,更合适的方法是使用由push() 方法生成的随机密钥作为发票的密钥,而不是那些递增的语音数字。主要原因是可扩展性,正如@FrankvanPuffelen 在以下帖子中所解释的那样:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-27
    • 2012-02-23
    • 1970-01-01
    • 2012-08-11
    • 2018-11-23
    • 2023-03-12
    • 2021-10-26
    • 2019-05-10
    相关资源
    最近更新 更多