我通过使用for循环将产品数据的数量插入数据库,流程就像首先生成发票,然后将发票数据添加到数据库中,然后在productdetails表中添加产品详细信息数据,但是当我插入发票数据时,它将插入正确,但是当我在productdetails表中插入数据时,它将添加两个相同的记录,即最后一个产品。它跳过第一个产品,并添加第二个和最后一个产品两次
for产品详细信息环节
` for (int m = 0; m < orderDetailsList.size(); m++) {
// pname,unitname,quantityname,pricename,discountname;
pname = orderDetailsList.get(m).getProductname2();
Log.e("&&&&&&%%%Productname", pname);
unitname = orderDetailsList.get(m).getProductunit2();
Log.e("&&&&&&%%%price2", String.valueOf(unitname));
quantityname = orderDetailsList.get(m).getProductquantity2();
Log.e("&&&&&&%%%quantity2", String.valueOf(quantityname));
discountname = orderDetailsList.get(m).getProductdiscount2();
Log.e("&&&&&&%%%quantity2", String.valueOf(discountname));
pricename = orderDetailsList.get(m).getProductquantity2();
Log.e("&&&&&&%%%quantity2", String.valueOf(pricename));
Productwisetotalname = orderDetailsList.get(m).getProductwisetotal2();
Log.e("&&&&&&%%%quantity2", String.valueOf(Productwisetotalname));
StringRequest stringRequest = new StringRequest(Method.POST,
Constants.URL_ADDINVOICEDETAILS,
new Listener<String>() {
@Override
public void onResponse(String response) {
try {
jsonObject = new JSONObject(response);
Log.d("response2....", "" + response);
if (jsonObject.getString("message").equals("orderdetail added successfully")) {
Toast.makeText(getContext(), "orderdetail added successfully", Toast.LENGTH_SHORT).show();
Log.d("response2....", "" + jsonObject.getString("message"));
} else if (jsonObject.getString("message").equals("Some error occurred please try again")) {
Toast.makeText(getContext(), "2", Toast.LENGTH_SHORT).show();
} else if (jsonObject.getString("message").equals("It seems orderdetail is already Exist")) {
Toast.makeText(getContext(), "3", Toast.LENGTH_SHORT).show();
} else if (jsonObject.getString("message").equals("Required fields are missing")) {
Toast.makeText(getContext(), "4", Toast.LENGTH_SHORT).show();
} else if (jsonObject.getString("message").equals("Invalid Request")) {
Toast.makeText(getContext(), "5", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("invoice_id", invoice_id);
params.put("product_name", pname);
params.put("quantity", quantityname);
params.put("price", pricename);
params.put("discount", discountname);
params.put("totalamount", String.valueOf(Productwisetotalname));
return params;
}
};
RequestHandler.getInstance(getContext()).addToRequestQueue(stringRequest);
}
`