我正在做收银员应用程序。有人可以告诉我如何为购买清单保留增量编号吗?出纳员要列出客户的项目清单,然后客户去拿一些要保留的物品。收银员可以首先扫描其他客户的项目。例如,我持有号码帐单1,因此下一个帐单是2。当我为帐单2付款时,它将是帐单3,所以现在我回叫已付款的帐单1。当我为第一笔账单付款时,该笔账单又回到第二笔账单。但是第二笔账单我已经付款了。如何保存账单的增量号?
这是MainActivity.class
Hold.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String invoice = txt_referName.getText().toString() + txt_referNum.getText().toString();
insertHoldListMaster(invoice);
myDb.deleteAllItemPurchased();
displayItemPurchased(MainActivity.this);
}
});
AdapterHoldList.class
公共类AdapterHoldList扩展了RecyclerView.Adapter {
private Context ctx;
private LayoutInflater inflater;
private ArrayList<Product_Item> itemsList;
//SQLite
DatabaseHelper myDb;
DecimalFormat format = new DecimalFormat("0.00");
public AdapterHoldList(Context ctx, ArrayList<Product_Item> itemsList){
inflater = LayoutInflater.from(ctx);
this.ctx = ctx;
this.itemsList = itemsList;
}
public class HoldListViewHolder extends RecyclerView.ViewHolder{
public TextView invoice, timestamp, totalPrice;
public Button btnReadyPay, btnDel;
public HoldListViewHolder(@NonNull View itemView) {
super(itemView);
invoice = itemView.findViewById(R.id.txt_holdReferBill);
timestamp = itemView.findViewById(R.id.txtHold_DateTimeBill);
totalPrice = itemView.findViewById(R.id.txtHold_TotalPriceBill);
btnReadyPay = itemView.findViewById(R.id.btn_holdReadyPay);
btnDel = itemView.findViewById(R.id.btn_holdDel);
}
}
@NonNull
@Override
public HoldListViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = inflater.inflate(R.layout.recycler_view_hold_list, viewGroup, false);
myDb = new DatabaseHelper(ctx);
return new HoldListViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final HoldListViewHolder holder, final int position) {
DecimalFormat format = new DecimalFormat("0.00");
final Product_Item item = itemsList.get(position);
final Double itemAmt = item.getItemTotalPrice();
final String invoice = item.getInvoice();
String strItemPrice = format.format(itemAmt);
holder.invoice.setText(item.getInvoice());
holder.timestamp.setText(item.getTimestamp());
holder.totalPrice.setText(strItemPrice);
holder.btnReadyPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean success = AddToList(invoice);
if (success) {
MainActivity.displayItemPurchased(ctx);
((Activity)ctx).finish();
}
}
});
holder.btnDel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteHoldList(holder.getAdapterPosition(), invoice);
}
});
}
@Override
public int getItemCount() {
return itemsList.size();
}
private void deleteHoldList(int position, String invoice){
myDb.deleteHoldListDt(invoice);
myDb.deleteHoldList(invoice);
itemsList.remove(position);
notifyItemRemoved(position);
HoldListActivity.displayHoldList(ctx);
myDb.close();
}
private boolean AddToList(String invoice){
myDb.deleteAllItemPurchased();
Cursor cursorHold = myDb.getAllHoldListDtByInvoice(invoice);
while (cursorHold.moveToNext()) {
String itemId = cursorHold.getString(1);
String itemDescription = cursorHold.getString(2);
Double itemUnitPrice = cursorHold.getDouble(3);
int itemQty = cursorHold.getInt(4);
Double itemTotalPrice = cursorHold.getDouble(5);
myDb.insertItemPurchased(itemId,itemDescription,itemUnitPrice,itemQty,itemTotalPrice);
}
myDb.close();
return true;
}
}
PaymentMethod.class
btn_paymentPayNow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (txtCard.getVisibility() == View.VISIBLE){
PaymentPayCredit();
}else{
PaymentPayCash();
}
}
});
public void PaymentPayCash(){
Double paid = Double.valueOf(txtPaid.getText().toString());
Double change = Double.valueOf(txtChange.getText().toString());
if (paid > 0 && change >= 0) {
AlertDialog.Builder alertDialog = (new AlertDialog.Builder(PaymentMethod.this));
alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Double totalPay = Double.valueOf(txt_AmtDue.getText().toString());
Double totalDisc = Double.valueOf(txtDetailDiscount.getText().toString());
Double UserPaid = Double.valueOf(txtPaid.getText().toString());
Double BalancePaid = Double.valueOf(txtChange.getText().toString());
myDb.insertSuccessPayMaster(prefix + suffix,"","","",totalPay,totalDisc, UserPaid, BalancePaid);
insertSuccessPayDt();
myDb.deleteAllItemPurchased();
MainActivity.displayItemPurchased(PaymentMethod.this);
//exit cash sales
progressDialog = new ProgressDialog(PaymentMethod.this);
progressDialog.setMessage("Processing...");
progressDialog.show();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
Toast.makeText(PaymentMethod.this,"Payment Succesfull",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(PaymentMethod.this,PrintSuccessPayCash.class);
intent.putExtra("InvoiceNo", prefix + suffix );
startActivity(intent);
suffix++;
myDb.insertPrefix(prefix, suffix,"invoice");
finish();
}
}
}, 2000);
}
});
alertDialog.setNegativeButton("No", null);
alertDialog.setMessage("Confirm to Pay & Print " + prefix + suffix + " ?");
alertDialog.setTitle("Confirmation");
alertDialog.show();
} else {
Toast.makeText(PaymentMethod.this,"Please pay enough amount",Toast.LENGTH_SHORT).show();
}
}
我在后缀++上进行增量操作。如何解决?如果您可以帮助我的代码正常运行,请帮助我提出保留增量票据编号功能的想法。。谢谢。
答案 0 :(得分:0)
当用户在文本字段中输入数据时,可以使用TextWatcher触发事件。然后,您可以进行计算。
https://developer.android.com/reference/android/text/TextWatcher
public class MyFragment extends Fragment implements TextWatcher {
//some other code...
@Override
public void afterTextChanged(Editable s) {
//TODO: Calculations...
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//Nothing to do here...
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//Nothing to do here...
}
}