友链:汪菜菜

友链:隔壁老王

GroupTrayOnline

package com.example.wms;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.wms.entity.GroupTrayOnlineEntity_data;
import com.example.wms.util.HttpHelper;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class GroupTrayOnline extends AppCompatActivity {

    private ImageButton btn_1;

    GroupTrayOnlineEntity_data groupTrayOnlineEntity_data = new GroupTrayOnlineEntity_data();
    GroupTrayOnlineEntity groupTrayOnlineEntity = new GroupTrayOnlineEntity();
    ProgressDialog progressDialog;
    private String result = "";
    private EditText txtPalletCode;
    private EditText txtMaterialCode;
    private EditText txtMaterialName;
    private EditText txtQty;
    private EditText txtBatchNo;
    private EditText txtPlatformNo;
    private int number;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_group_tray_online);

        txtPalletCode = findViewById(R.id.editPalletCode);//托盘条码
        txtMaterialCode = findViewById(R.id.editMaterialCode);//物料编号
        txtMaterialName = findViewById(R.id.editMaterialName);//物料名称
        txtQty = findViewById(R.id.editQty);//数量
        txtBatchNo = findViewById(R.id.BatchNo);//批次号
        txtPlatformNo = findViewById(R.id.PlatformNo);//站台编号


        //清空
        Button button_over = findViewById(R.id.btn_over);
        button_over.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                txtPalletCode.setText("");
                txtMaterialCode.setText("");
                txtMaterialName.setText("");
                txtQty.setText("");
                txtBatchNo.setText("");
                txtPlatformNo.setText("");
            }
        });
        //返回
        btn_1 = findViewById(R.id.fh_btn);
        btn_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        //保存
        Button btn_save = findViewById(R.id.btn_save);
        btn_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String PalletCode = txtPalletCode.getText().toString();
                String MaterialCode = txtMaterialCode.getText().toString();
                String MaterialName = txtMaterialName.getText().toString();
                String BatchNo = txtBatchNo.getText().toString();
                String PlatformNo = txtPlatformNo.getText().toString();
                int Qty = Integer.parseInt(txtQty.getText().toString());



                if (Qty <= 0) {
                    Toast.makeText(GroupTrayOnline.this, "输入数量必须大于0", Toast.LENGTH_LONG).show();
                    return;
                } else if (number < Qty) {
                    Toast.makeText(GroupTrayOnline.this, "输入数量超过最大值", Toast.LENGTH_LONG).show();
                    return;
                }
                String msg = "条码[" + PalletCode + "]数量[" + Qty + "]确定要保存吗?";
                new AlertDialog.Builder(GroupTrayOnline.this).setTitle("系统提示")
                        .setMessage(msg)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                progressDialog = new ProgressDialog(GroupTrayOnline.this);
                                progressDialog.setTitle("CATL");
                                progressDialog.setMessage("正在保存,请稍等......");
                                progressDialog.setIndeterminate(true);
                                progressDialog.setCancelable(false);
                                progressDialog.show();

                                String abc = HttpHelper.EncryptTokenNo;

                                new Thread(new Runnable() {
                                    public void run() {
                                        Log.d("111111111111111111", "2222222222222222222222");
                                        try {
                                            Thread.sleep(3000);
                                            Log.d("111111111111111111", "3333333333333333333333333");
                                            SaveReceipt(PalletCode, Qty);
                                            Log.d("111111111111111111", "444444444444444444444444444");
                                            Message msg = new Message();
                                            msg.what = 0;
                                            HttpHelper.handler.sendMessage(msg);
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }).start();

                                HttpHelper.handler = new Handler() {
                                    public void handleMessage(Message msg) {
                                        Log.d("111111111111111111", "55555555555555555555555");
                                        try {
                                            if (progressDialog != null) {
                                                progressDialog.dismiss();
                                            }
                                            JSONObject jsonObjectALL = new JSONObject(result);
                                            String code = jsonObjectALL.optString("code", null);
                                            String baseinfo = jsonObjectALL.optString("info", null);
                                            //String data = jsonObjectALL.optString("data", null);

                                            if (code.equals("1")) {
                                                Toast.makeText(GroupTrayOnline.this, "保存成功" + baseinfo, Toast.LENGTH_LONG).show();
                                                txtPalletCode.setText("");
                                                txtMaterialCode.setText("");
                                                txtMaterialName.setText("");
                                                txtBatchNo.setText("");
                                                txtPlatformNo.setText("");
                                                txtQty.setText("");
                                            } else {
                                                Toast.makeText(GroupTrayOnline.this, "保存失败" + baseinfo, Toast.LENGTH_SHORT).show();
                                            }
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                };
                            }
                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                }).show();
            }
        });

        //扫描条码触发接口
        txtPalletCode = findViewById(R.id.editPalletCode);//托盘条码
        txtPalletCode.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //1.判断条码长度
                if (s.length() != 4) return;
                //2.根据条码转换成json调用接口
                Gson gson = new Gson();
                groupTrayOnlineEntity_data.setPalletcode(s.toString());
                groupTrayOnlineEntity_data.setQty(1);
                String value = gson.toJson(groupTrayOnlineEntity_data);
                JSONObject root = new JSONObject();
                try {
                    //存data的值
                    root.put("EncryptTokenNo", HttpHelper.EncryptTokenNo);
                    root.put("AppDeviceNo", HttpHelper.AppDeviceNo);
                    root.put("IPAddress", HttpHelper.IPAddress);
                    root.put("JsonData", value);
                    root.put("apptype", HttpHelper.AppType);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                result = PostInfo(HttpHelper.url_GroupTrayOnline, root.toString());
                //3.接口返回数据转换成实体
                try {
                    JSONObject jsonObjectALL = new JSONObject(result);
                    String code = jsonObjectALL.optString("code", null);
                    String baseinfo = jsonObjectALL.optString("info", null);
                    String data = jsonObjectALL.optString("data", null);
                    if (code.equals("1")) {
                        if (!TextUtils.isEmpty(data)) {
                            JSONArray jsonArrayData = new JSONArray(data);
                            JSONObject jsonObjectData = (JSONObject) jsonArrayData.get(0);
/*                            String PalletCode = jsonObjectData.optString("PalletCode", null);
                            String Qty = jsonObjectData.optString("Qty", null);*/

                            String PLMatType = jsonObjectData.optString("PLMatType", null);
                            number = jsonObjectData.optInt("Capacity", 0);



                            if (PLMatType.equals("0")) {
                                PLMatType = "顶盖";
                            } else if (PLMatType.equals("1")) {
                                PLMatType = "铝壳";
                            }

                            //绑定数据
/*                            txtPalletCode.setText(PalletCode);//名称
                            txtQty.setText(Qty);//目标库位*/
                            txtMaterialName.setText(PLMatType);
                            Toast.makeText(GroupTrayOnline.this, "接口调用成功" + baseinfo, Toast.LENGTH_LONG).show();
                        }
                    } else {
                        //提示信息
                        Toast.makeText(GroupTrayOnline.this, "接口调用失败" + baseinfo, Toast.LENGTH_LONG).show();
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private String PostInfo(String aaa, String json) {
        return HttpHelper.Post(aaa, json);
    }

    public void SaveReceipt(String PalletCode, int Qty) {
        //实体类转化为JSON
        groupTrayOnlineEntity_data = new GroupTrayOnlineEntity_data();
        groupTrayOnlineEntity_data.setPalletcode(PalletCode);
        groupTrayOnlineEntity_data.setQty(Qty);

        Gson gson = new Gson();
        String value = gson.toJson(groupTrayOnlineEntity_data);
        JSONObject root = new JSONObject();
        try {
            //存data的值
            Log.d("11111111111", "16161616161616161616");
            root.put("EncryptTokenNo", HttpHelper.EncryptTokenNo); //Token值
            Log.d("11111111111", "17171717");
            root.put("AppDeviceNo", HttpHelper.AppDeviceNo); //MAC地址
            Log.d("11111111111", "18181818");
            root.put("IPAddress", HttpHelper.IPAddress); //设备IP
            Log.d("11111111111", "19191919");
            root.put("apptype:", "OnLineRF");
            Log.d("11111111111", "2020202020");
            root.put("JsonData", value);
            Log.d("11111111111", "2121212121");
//                    root.put("apptype", HttpHelper.AppType);
        } catch (JSONException e) {
            Log.d("11111111111", "101010101010");
            e.printStackTrace();

        }
        result = PostInfo(HttpHelper.url_GroupTrayOnline_qqq, root.toString());
        Log.d("11111111111", "12121212121221");
    }

}

 

posted @ 2022-06-08 10:27  長安憶ღ  阅读(53)  评论(0)    收藏  举报