|
|
@@ -0,0 +1,972 @@
|
|
|
+package com.jiaju.activity;
|
|
|
+
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import com.jiaju.adapter.ProductTestListAdapter;
|
|
|
+import com.jiaju.adapter.ProductTestListAdapter.OnDeleteItemClickListener;
|
|
|
+import com.jiaju.adapter.ProductTestOrderAdapter;
|
|
|
+import com.jiaju.model.BarcodeInfo;
|
|
|
+import com.jiaju.model.Order;
|
|
|
+import com.jiaju.net.OkAsyncHttpClient;
|
|
|
+import com.jiaju.utils.CommonUtil;
|
|
|
+import com.jiaju.utils.Constants;
|
|
|
+import com.jiaju.utils.CustomToast;
|
|
|
+import com.jiaju.utils.IBossBasePopupWindow;
|
|
|
+import com.jiaju.utils.IBossBasePopupWindow.IPopUpWindowCallBack;
|
|
|
+import com.jiaju.utils.ProcessDialogUtils;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.Notification;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.content.SharedPreferences;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.HandlerThread;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.InputFilter;
|
|
|
+import android.text.InputType;
|
|
|
+import android.text.Spanned;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.View.OnClickListener;
|
|
|
+import android.view.inputmethod.EditorInfo;
|
|
|
+import android.widget.AdapterView;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.ImageButton;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.Spinner;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 实验产品-20210902 添加测试产品
|
|
|
+ *
|
|
|
+ * @author lenovo
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class ProductTestSheetActivity extends Activity {
|
|
|
+
|
|
|
+ private TextView tvTitle;
|
|
|
+ private SharedPreferences preferences;
|
|
|
+ private String ServerAddress_ip;
|
|
|
+ private String ServerAddress_port;
|
|
|
+ private String handover_usercode;
|
|
|
+
|
|
|
+ private HandlerThread thread;
|
|
|
+ private Handler mHandler;
|
|
|
+ private OkAsyncHttpClient client;
|
|
|
+ private List<Order> orderList;
|
|
|
+ private Spinner orderSpinner;
|
|
|
+ private ProductTestOrderAdapter adapter;
|
|
|
+ private EditText barcodeEdt;
|
|
|
+ private TextView tvBack;
|
|
|
+ private ImageView ivBack;
|
|
|
+ private Object obj = new Object();
|
|
|
+ private List<BarcodeInfo> barcodeInfoList = new ArrayList<BarcodeInfo>();
|
|
|
+ private ListView barcodeLst;
|
|
|
+ private ProductTestListAdapter productTestListAdapter;
|
|
|
+
|
|
|
+ private LinearLayout llpurpose;
|
|
|
+ private TextView tvpurpose;
|
|
|
+ // 实验单号
|
|
|
+ private LinearLayout llOrderNo;
|
|
|
+ private TextView tvOrderNo;
|
|
|
+ // 负责人
|
|
|
+ private LinearLayout llPerson;
|
|
|
+ private TextView tvPerson;
|
|
|
+ // 实验背景
|
|
|
+ private LinearLayout llContext;
|
|
|
+ private TextView tvContext;
|
|
|
+ // 实验方法
|
|
|
+ private LinearLayout llMethod;
|
|
|
+ private TextView tvMethod;
|
|
|
+ // 实验结果
|
|
|
+ private LinearLayout llResult;
|
|
|
+ private TextView tvResult;
|
|
|
+ private TextView tvProductCount;
|
|
|
+
|
|
|
+ private Handler barcodeUpperH = new Handler();
|
|
|
+ private String barcodeUpper;
|
|
|
+ private boolean orderisgon = true; // 是否显示 true 不显示 false 显示
|
|
|
+ private int orderId = -1;// 实验单
|
|
|
+ private IBossBasePopupWindow iBossBasePopupWindowDelete;
|
|
|
+
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_product_test_sheet);
|
|
|
+ initView();
|
|
|
+ // 获得账户信息;获取服务ip和端口号
|
|
|
+ preferences = getSharedPreferences("user", Context.MODE_PRIVATE);
|
|
|
+ ServerAddress_ip = preferences.getString("WebServerAddress_ip", "");
|
|
|
+ ServerAddress_port = preferences.getString("WebServerAddress_port", "");
|
|
|
+ handover_usercode = preferences.getString("UserCode", "");
|
|
|
+ client = OkAsyncHttpClient.getInstance(ProductTestSheetActivity.this);
|
|
|
+ Bundle b = getIntent().getExtras();
|
|
|
+ String title = b.getString("procedureName");
|
|
|
+ tvTitle.setText(title);
|
|
|
+
|
|
|
+ CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
|
|
|
+ allListeners();
|
|
|
+ thread = new HandlerThread("trademarkThread", 5);
|
|
|
+ thread.start();
|
|
|
+ mHandler = new Handler(thread.getLooper());
|
|
|
+ OrderListRunnable orderListRunnable = new OrderListRunnable(obj);
|
|
|
+ mHandler.post(orderListRunnable);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
+ switch (ev.getAction()) {
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
+ View view = getCurrentFocus();
|
|
|
+ CommonUtil.hideKeyboard(ev, view, ProductTestSheetActivity.this);// 调用方法判断是否需要隐藏键盘
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return super.dispatchTouchEvent(ev);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
+
|
|
|
+ if (requestCode == 101 && resultCode == 103) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化view
|
|
|
+ */
|
|
|
+ private void initView() {
|
|
|
+ tvTitle = (TextView) findViewById(R.id.title);
|
|
|
+ ivBack = (ImageButton) findViewById(R.id.left_img);
|
|
|
+ tvBack = (TextView) findViewById(R.id.back);
|
|
|
+
|
|
|
+ View head = View.inflate(this, R.layout.product_test_sheet_head_view, null);
|
|
|
+ orderSpinner = (Spinner) head.findViewById(R.id.orderSpinner);
|
|
|
+ llpurpose = (LinearLayout) head.findViewById(R.id.llpurpose);
|
|
|
+ tvpurpose = (TextView) head.findViewById(R.id.tvpurpose);
|
|
|
+ // 实验单号
|
|
|
+ llOrderNo = (LinearLayout) head.findViewById(R.id.llOrderNo);
|
|
|
+ tvOrderNo = (TextView) head.findViewById(R.id.tvOrderNo);
|
|
|
+ // 负责人
|
|
|
+ llPerson = (LinearLayout) head.findViewById(R.id.llPerson);
|
|
|
+ tvPerson = (TextView) head.findViewById(R.id.tvPerson);
|
|
|
+ // 实验背景
|
|
|
+ llContext = (LinearLayout) head.findViewById(R.id.llContext);
|
|
|
+ tvContext = (TextView) head.findViewById(R.id.tvContext);
|
|
|
+ // 实验方法
|
|
|
+ llMethod = (LinearLayout) head.findViewById(R.id.llMethod);
|
|
|
+ tvMethod = (TextView) head.findViewById(R.id.tvMethod);
|
|
|
+ // 实验结果
|
|
|
+ llResult = (LinearLayout) head.findViewById(R.id.llResult);
|
|
|
+ tvResult = (TextView) head.findViewById(R.id.tvResult);
|
|
|
+ tvProductCount = (TextView) head.findViewById(R.id.tvProductCount);
|
|
|
+
|
|
|
+ barcodeEdt = (EditText) head.findViewById(R.id.barcodeEdt);
|
|
|
+ barcodeEdt.setRawInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
+ barcodeLst = (ListView) findViewById(R.id.productlst);
|
|
|
+ barcodeLst.addHeaderView(head, null, false);
|
|
|
+
|
|
|
+ productTestListAdapter = new ProductTestListAdapter(ProductTestSheetActivity.this, barcodeInfoList);
|
|
|
+ barcodeLst.setAdapter(productTestListAdapter);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置单据的其他信息是否显示
|
|
|
+ *
|
|
|
+ * @param blValue
|
|
|
+ */
|
|
|
+ private void orderisgon(boolean blValue) {
|
|
|
+ if (!blValue) {
|
|
|
+ llOrderNo.setVisibility(View.VISIBLE);
|
|
|
+ llPerson.setVisibility(View.VISIBLE);
|
|
|
+ llContext.setVisibility(View.VISIBLE);
|
|
|
+ llMethod.setVisibility(View.VISIBLE);
|
|
|
+ llResult.setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ llOrderNo.setVisibility(View.GONE);
|
|
|
+ llPerson.setVisibility(View.GONE);
|
|
|
+ llContext.setVisibility(View.GONE);
|
|
|
+ llMethod.setVisibility(View.GONE);
|
|
|
+ llResult.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化view-清空
|
|
|
+ */
|
|
|
+ private void initClearView() {
|
|
|
+ tvpurpose.setText("");
|
|
|
+ tvOrderNo.setText("");
|
|
|
+ tvPerson.setText("");
|
|
|
+ tvContext.setText("");
|
|
|
+ tvMethod.setText("");
|
|
|
+ tvResult.setText("");
|
|
|
+ barcodeEdt.setText("");
|
|
|
+ barcodeEdt.setFocusable(true);
|
|
|
+ barcodeEdt.requestFocus();
|
|
|
+ barcodeEdt.findFocus();
|
|
|
+ tvProductCount.setText("产品信息");
|
|
|
+ if (productTestListAdapter != null) {
|
|
|
+ barcodeInfoList.removeAll(barcodeInfoList);
|
|
|
+ productTestListAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * view注册事件
|
|
|
+ */
|
|
|
+ private void allListeners() {
|
|
|
+ // 返回
|
|
|
+ ivBack.setOnClickListener(new OnClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 返回
|
|
|
+ tvBack.setOnClickListener(new OnClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 返回
|
|
|
+ llpurpose.setOnClickListener(new OnClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ orderisgon = !orderisgon;
|
|
|
+ orderisgon(orderisgon);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 实验单
|
|
|
+ orderSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
|
|
+ Order order = (Order) arg0.getItemAtPosition(arg2);
|
|
|
+ orderId = order.getOrderId();
|
|
|
+
|
|
|
+ initClearView();
|
|
|
+ if (orderId == -1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ thread = new HandlerThread("trademarkThread", 5);
|
|
|
+ thread.start();
|
|
|
+ mHandler = new Handler(thread.getLooper());
|
|
|
+ OrderItemByRunnable ordeitemRunnable = new OrderItemByRunnable(obj, orderId);
|
|
|
+ mHandler.post(ordeitemRunnable);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNothingSelected(AdapterView<?> arg0) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 扫描
|
|
|
+ barcodeEdt.addTextChangedListener(new TextWatcher() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable arg0) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
+
|
|
|
+ barcodeUpper = barcodeEdt.getText().toString().trim();
|
|
|
+ // 判断输入的文字是否是小写
|
|
|
+ for (int i = 0; i < barcodeUpper.length(); i++) {
|
|
|
+ if (barcodeUpper.charAt(i) - 0 >= 97 && barcodeUpper.charAt(i) - 0 <= 122) {
|
|
|
+ barcodeUpperH.postDelayed(UpperCase, 300);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (start == 0 && before == 0 && count > 1) {
|
|
|
+ String barcode = barcodeEdt.getText().toString();
|
|
|
+ barcode = barcode.trim();
|
|
|
+ if (!TextUtils.isEmpty(barcode)) {
|
|
|
+ if (orderId == -1) {
|
|
|
+ barcodeEdt.setText("");
|
|
|
+ barcodeEdt.setFocusable(true);
|
|
|
+ barcodeEdt.requestFocus();
|
|
|
+ barcodeEdt.findFocus();
|
|
|
+ Toast.makeText(ProductTestSheetActivity.this, "请选择实验单号", Toast.LENGTH_SHORT).show();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ProcessDialogUtils.showProcessDialog(ProductTestSheetActivity.this);
|
|
|
+ barcodeEdt.setEnabled(false);
|
|
|
+ barcodeEdt.setFocusable(false);
|
|
|
+ barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
|
|
|
+ @Override
|
|
|
+ public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
|
|
|
+ int dstart, int dend) {
|
|
|
+
|
|
|
+ return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
|
|
|
+ }
|
|
|
+ } });
|
|
|
+ thread = new HandlerThread("barcodeThread", 5);
|
|
|
+ thread.start();
|
|
|
+ mHandler = new Handler(thread.getLooper());
|
|
|
+ BarcodeRunnable barcodeRunnable = new BarcodeRunnable(obj, barcode);
|
|
|
+ mHandler.post(barcodeRunnable);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 扫描
|
|
|
+ barcodeEdt.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
|
+
|
|
|
+ if (actionId == EditorInfo.IME_ACTION_GO) {
|
|
|
+ if (orderId == -1) {
|
|
|
+ barcodeEdt.setText("");
|
|
|
+ barcodeEdt.setFocusable(true);
|
|
|
+ barcodeEdt.requestFocus();
|
|
|
+ barcodeEdt.findFocus();
|
|
|
+ Toast.makeText(ProductTestSheetActivity.this, "请选择实验单号", Toast.LENGTH_SHORT).show();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ String barcode = barcodeEdt.getText().toString();
|
|
|
+ if (!TextUtils.isEmpty(barcode)) {
|
|
|
+ ProcessDialogUtils.showProcessDialog(ProductTestSheetActivity.this);
|
|
|
+ barcodeEdt.setEnabled(false);
|
|
|
+ barcodeEdt.setFocusable(false);
|
|
|
+ barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
|
|
|
+ @Override
|
|
|
+ public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
|
|
|
+ int dstart, int dend) {
|
|
|
+
|
|
|
+ return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
|
|
|
+ }
|
|
|
+ } });
|
|
|
+ thread = new HandlerThread("barcodeThread", 5);
|
|
|
+ thread.start();
|
|
|
+ mHandler = new Handler(thread.getLooper());
|
|
|
+ BarcodeRunnable barcodeRunnable = new BarcodeRunnable(obj, barcode);
|
|
|
+ mHandler.post(barcodeRunnable);
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 删除item的注册事件
|
|
|
+ productTestListAdapter.setOnDeleteItemClickListener(new OnDeleteItemClickListener() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDeleteItemClick(View v, final int position) {
|
|
|
+
|
|
|
+ if (iBossBasePopupWindowDelete == null) {
|
|
|
+ iBossBasePopupWindowDelete = new IBossBasePopupWindow(ProductTestSheetActivity.this,
|
|
|
+ R.layout.popup_window_exit);
|
|
|
+ }
|
|
|
+ iBossBasePopupWindowDelete.setPopUpWindowCallBack(new IPopUpWindowCallBack() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void popUpWindowCallBack(View view) {
|
|
|
+ TextView tvPopupWindowMessage = (TextView) view.findViewById(R.id.tv_popup_window_message);
|
|
|
+ TextView tvPopupWindowTitle = (TextView) view.findViewById(R.id.tv_popup_window_title);
|
|
|
+ tvPopupWindowTitle.setText("提示");
|
|
|
+ try {
|
|
|
+ tvPopupWindowMessage.setText("是否要删除? ");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 对布局文件进行初始化
|
|
|
+ RelativeLayout llCancel = (RelativeLayout) view.findViewById(R.id.ll_cancel);
|
|
|
+ // 对布局中的控件添加事件监听
|
|
|
+ llCancel.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ iBossBasePopupWindowDelete.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ RelativeLayout llOK = (RelativeLayout) view.findViewById(R.id.ll_ok);
|
|
|
+ // 对布局中的控件添加事件监听
|
|
|
+ llOK.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ iBossBasePopupWindowDelete.dismiss();
|
|
|
+ BarcodeInfo barcodeInfo = barcodeInfoList.get(position);
|
|
|
+ thread = new HandlerThread("barcodeThread", 5);
|
|
|
+ thread.start();
|
|
|
+ mHandler = new Handler(thread.getLooper());
|
|
|
+ DelRunnable delRunnable = new DelRunnable(obj, barcodeInfo.getBarcode());
|
|
|
+ mHandler.post(delRunnable);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ iBossBasePopupWindowDelete.show(false, v, 0, 0);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 小写转大写
|
|
|
+ */
|
|
|
+ Runnable UpperCase = new Runnable() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ // 小写转大写
|
|
|
+ barcodeEdt.setText(barcodeUpper.toUpperCase());
|
|
|
+ // 设置EditText光标位置
|
|
|
+ barcodeEdt.setSelection(barcodeUpper.length());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存插入条码数据
|
|
|
+ *
|
|
|
+ * @author lenovo
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private class DelRunnable implements Runnable {
|
|
|
+ private Object object;
|
|
|
+ private String barcode;
|
|
|
+
|
|
|
+ public DelRunnable(Object object, String barcode) {
|
|
|
+ this.object = object;
|
|
|
+ this.barcode = barcode;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ synchronized (object) {
|
|
|
+ try {
|
|
|
+ HashMap<String, String> params = new LinkedHashMap<String, String>();
|
|
|
+ params.put("BARCODE", barcode);
|
|
|
+ params.put("USERCODE", handover_usercode);
|
|
|
+ params.put("TESTFORMID", orderId + "");
|
|
|
+ params.put("MODE", "delete");
|
|
|
+ String result = client.requestGetBySyn(
|
|
|
+ "http://" + ServerAddress_ip + ":" + ServerAddress_port + Constants.SET_TEST_FORM_GOODS,
|
|
|
+ params);
|
|
|
+
|
|
|
+ Message m = new Message();
|
|
|
+ m.what = 2;
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putString("saveResult", result);
|
|
|
+ m.setData(b);
|
|
|
+ handler.sendMessage(m);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
+ Message m = new Message();
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putString("message", "网络连接异常");
|
|
|
+ m.setData(b);
|
|
|
+ m.what = 0;
|
|
|
+ exceptionHandler.sendMessage(m);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 扫码插入
|
|
|
+ *
|
|
|
+ * @author lenovo
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private class BarcodeRunnable implements Runnable {
|
|
|
+ private Object object;
|
|
|
+ private String barcode;
|
|
|
+
|
|
|
+ public BarcodeRunnable(Object object, String barcode) {
|
|
|
+ this.object = object;
|
|
|
+ this.barcode = barcode;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ synchronized (object) {
|
|
|
+ try {
|
|
|
+ HashMap<String, String> params = new LinkedHashMap<String, String>();
|
|
|
+ params.put("BARCODE", barcode);
|
|
|
+ params.put("USERCODE", handover_usercode);
|
|
|
+ params.put("TESTFORMID", orderId + "");
|
|
|
+ params.put("MODE", "add");
|
|
|
+
|
|
|
+ String result = client.requestGetBySyn(
|
|
|
+ "http://" + ServerAddress_ip + ":" + ServerAddress_port + Constants.SET_TEST_FORM_GOODS,
|
|
|
+ params);
|
|
|
+
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ Message message = new Message();
|
|
|
+ message.what = 3;
|
|
|
+ b.putString("barcode", barcode);
|
|
|
+ b.putString("saveResult", result);
|
|
|
+ message.setData(b);
|
|
|
+ handler.sendMessage(message);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
+ Message m = new Message();
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putString("message", "网络连接异常");
|
|
|
+ m.setData(b);
|
|
|
+ m.what = 0;
|
|
|
+ exceptionHandler.sendMessage(m);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实验单的查询
|
|
|
+ *
|
|
|
+ * @author lenovo
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private class OrderListRunnable implements Runnable {
|
|
|
+ private Object object;
|
|
|
+
|
|
|
+ public OrderListRunnable(Object object) {
|
|
|
+ this.object = object;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ synchronized (object) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ HashMap<String, String> params = new LinkedHashMap<String, String>();
|
|
|
+ params.put("USERCODE", handover_usercode);
|
|
|
+ String result = client.requestGetBySyn(
|
|
|
+ "http://" + ServerAddress_ip + ":" + ServerAddress_port + Constants.GET_TEST_FORM_LIST,
|
|
|
+ params);
|
|
|
+ JSONObject jobj = new JSONObject(result);
|
|
|
+ boolean successFlag = jobj.optBoolean("success");
|
|
|
+ String message = jobj.optString("message");
|
|
|
+ int status = jobj.optInt("status");
|
|
|
+ if (status != 0) {
|
|
|
+ Message m = new Message();
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putString("message", "网络连接失败!请查看服务器");
|
|
|
+ m.setData(b);
|
|
|
+ m.what = 0;
|
|
|
+ exceptionHandler.sendMessage(m);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (successFlag) {
|
|
|
+ JSONArray jarray = (JSONArray) jobj.opt("rows");
|
|
|
+ if (jarray != null && jarray.length() > 0) {
|
|
|
+ orderList = new ArrayList<Order>();
|
|
|
+ Order order = new Order();
|
|
|
+ order.setOrderId(-1);
|
|
|
+ order.setOrderNo("请选择实验单");
|
|
|
+ orderList.add(order);
|
|
|
+ for (int i = 0; i < jarray.length(); i++) {
|
|
|
+ JSONObject obj = jarray.optJSONObject(i);
|
|
|
+ int orderId = obj.optInt("ID");
|
|
|
+ String orderNo = obj.optString("NAME");
|
|
|
+ Order orderdetail = new Order();
|
|
|
+ orderdetail.setOrderId(orderId);
|
|
|
+ orderdetail.setOrderNo(orderNo);
|
|
|
+ orderList.add(orderdetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Message m = new Message();
|
|
|
+ m.what = 0;
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putSerializable("orderList", (Serializable) orderList);
|
|
|
+ m.setData(b);
|
|
|
+ handler.sendMessage(m);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putInt("status", status);
|
|
|
+ b.putString("message", message);
|
|
|
+ Message m = new Message();
|
|
|
+ m.what = 1;
|
|
|
+ m.setData(b);
|
|
|
+ exceptionHandler.sendMessage(m);
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
+ Message m = new Message();
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putString("message", "网络连接异常");
|
|
|
+ m.setData(b);
|
|
|
+ m.what = 0;
|
|
|
+ exceptionHandler.sendMessage(m);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实验单详细
|
|
|
+ *
|
|
|
+ * @author lenovo
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private class OrderItemByRunnable implements Runnable {
|
|
|
+ private Object object;
|
|
|
+ private int orderid;
|
|
|
+
|
|
|
+ public OrderItemByRunnable(Object object, int orderid) {
|
|
|
+ this.object = object;
|
|
|
+ this.orderid = orderid;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ synchronized (object) {
|
|
|
+ try {
|
|
|
+ HashMap<String, String> params = new LinkedHashMap<String, String>();
|
|
|
+ params.put("ID", orderid + "");
|
|
|
+ String result = client.requestGetBySyn(
|
|
|
+ "http://" + ServerAddress_ip + ":" + ServerAddress_port + Constants.GET_TEST_FORM_DETAIL,
|
|
|
+ params);
|
|
|
+ JSONObject jobj = new JSONObject(result);
|
|
|
+ boolean successFlag = jobj.optBoolean("success");
|
|
|
+ String message = jobj.optString("message");
|
|
|
+ int status = jobj.optInt("status");
|
|
|
+ if (status != 0) {
|
|
|
+ Message m = new Message();
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putString("message", "网络连接失败!请查看服务器");
|
|
|
+ m.setData(b);
|
|
|
+ m.what = 0;
|
|
|
+ exceptionHandler.sendMessage(m);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (successFlag) {
|
|
|
+ String reval = jobj.optString("rows");
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ Message rmessage = new Message();
|
|
|
+ rmessage.what = 1;
|
|
|
+ b.putString("result", reval);
|
|
|
+ rmessage.setData(b);
|
|
|
+ handler.sendMessage(rmessage);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putInt("status", status);
|
|
|
+ b.putString("message", message);
|
|
|
+ Message m = new Message();
|
|
|
+ m.what = 1;
|
|
|
+ m.setData(b);
|
|
|
+ exceptionHandler.sendMessage(m);
|
|
|
+ return;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ Message m = new Message();
|
|
|
+ Bundle b = new Bundle();
|
|
|
+ b.putString("message", "网络连接异常");
|
|
|
+ m.setData(b);
|
|
|
+ m.what = 0;
|
|
|
+ exceptionHandler.sendMessage(m);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异常处理
|
|
|
+ */
|
|
|
+ Handler exceptionHandler = new Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ switch (msg.what) {
|
|
|
+ case 0:
|
|
|
+ Bundle b = msg.getData();
|
|
|
+ String message = b.getString("message");
|
|
|
+ ProcessDialogUtils.closeProgressDilog();
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.removeCallbacksAndMessages(null);
|
|
|
+ mHandler.getLooper().quit();
|
|
|
+ }
|
|
|
+ CustomToast.showToast(getApplicationContext(), message, 2000);
|
|
|
+
|
|
|
+ CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext());
|
|
|
+ barcodeEdt.setEnabled(true);
|
|
|
+ barcodeEdt.setText("");
|
|
|
+ barcodeEdt.setFocusable(true);
|
|
|
+ barcodeEdt.setFocusableInTouchMode(true);
|
|
|
+ barcodeEdt.requestFocus();
|
|
|
+ barcodeEdt.findFocus();
|
|
|
+ barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
|
|
|
+ int dend) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } });
|
|
|
+ CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ Bundle b1 = msg.getData();
|
|
|
+ int status1 = b1.getInt("status");
|
|
|
+ String message1 = b1.getString("message");
|
|
|
+ ProcessDialogUtils.closeProgressDilog();
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.removeCallbacksAndMessages(null);
|
|
|
+ mHandler.getLooper().quit();
|
|
|
+ }
|
|
|
+
|
|
|
+ CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext());
|
|
|
+ CommonUtil.showBarCodeAlertDialog(status1, message1, ProductTestSheetActivity.this, barcodeEdt, null,
|
|
|
+ null);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调用接口的返回操作
|
|
|
+ */
|
|
|
+ Handler handler = new Handler() {
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ switch (msg.what) {
|
|
|
+
|
|
|
+ case 0:
|
|
|
+ // 实验单的接口返回逻辑
|
|
|
+ Bundle b = msg.getData();
|
|
|
+ orderList = (List<Order>) b.getSerializable("orderList");
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.removeCallbacksAndMessages(null);
|
|
|
+ mHandler.getLooper().quit();
|
|
|
+ }
|
|
|
+ ProcessDialogUtils.closeProgressDilog();
|
|
|
+
|
|
|
+ if (orderList != null && orderList.size() > 0) {
|
|
|
+ adapter = new ProductTestOrderAdapter(ProductTestSheetActivity.this, orderList);
|
|
|
+ orderSpinner.setAdapter(adapter);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ // 选取实验单查询总单和明细的接口返回逻辑
|
|
|
+ ProcessDialogUtils.closeProgressDilog();
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.removeCallbacksAndMessages(null);
|
|
|
+ mHandler.getLooper().quit();
|
|
|
+ }
|
|
|
+ if (productTestListAdapter != null) {
|
|
|
+ barcodeInfoList.removeAll(barcodeInfoList);
|
|
|
+ productTestListAdapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ }
|
|
|
+ Bundle bd = msg.getData();
|
|
|
+ String resultdetail = bd.getString("result");
|
|
|
+ try {
|
|
|
+ JSONObject jobjdetail = new JSONObject(resultdetail);
|
|
|
+ JSONObject joborder = jobjdetail.optJSONObject("order");
|
|
|
+ JSONArray arrdetail = jobjdetail.optJSONArray("data");
|
|
|
+ // 总单的信息
|
|
|
+ tvpurpose.setText(isEmpty(jobjdetail.optString("NAME")) ? "" : jobjdetail.optString("NAME"));// 目的
|
|
|
+ tvOrderNo.setText(isEmpty(jobjdetail.optString("ID")) ? "" : jobjdetail.optString("ID"));// 单号
|
|
|
+ tvPerson.setText(isEmpty(jobjdetail.optString("PERSON")) ? "" : jobjdetail.optString("PERSON"));// 负责人
|
|
|
+ tvContext.setText(isEmpty(jobjdetail.optString("STATE")) ? "" : jobjdetail.optString("STATE"));// 背景------------------------??
|
|
|
+ tvMethod.setText(isEmpty(jobjdetail.optString("METHOD")) ? "" : jobjdetail.optString("METHOD"));// 方法
|
|
|
+ tvResult.setText(isEmpty(jobjdetail.optString("RESULT")) ? "" : jobjdetail.optString("RESULT")); // 结果
|
|
|
+ if (arrdetail != null && arrdetail.length() > 0) {
|
|
|
+ // 明细的信息
|
|
|
+ for (int i = 0; i < arrdetail.length(); i++) {
|
|
|
+ JSONObject jobj5 = arrdetail.optJSONObject(i);
|
|
|
+ String barCode = jobj5.optString("BARCODE");
|
|
|
+ String goodsCode = jobj5.optString("GOODSCODE");
|
|
|
+ String goodsTypeName = jobj5.optString("GOODSTYPENAME");
|
|
|
+ BarcodeInfo info = new BarcodeInfo();
|
|
|
+ info.setBarcode(barCode);
|
|
|
+ info.setGoodsCode(goodsCode);
|
|
|
+ info.setGoodsTypeName(goodsTypeName);
|
|
|
+ //
|
|
|
+ barcodeInfoList.add(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (productTestListAdapter == null) {
|
|
|
+ productTestListAdapter = new ProductTestListAdapter(ProductTestSheetActivity.this,
|
|
|
+ barcodeInfoList);
|
|
|
+ barcodeLst.setAdapter(productTestListAdapter);
|
|
|
+ } else {
|
|
|
+ productTestListAdapter.notifyDataSetChanged();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (barcodeInfoList != null && barcodeInfoList.size() > 0) {
|
|
|
+ tvProductCount.setText("产品信息(" + barcodeInfoList.size() + ")条");
|
|
|
+ } else {
|
|
|
+ tvProductCount.setText("产品信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ barcodeEdt.setEnabled(true);
|
|
|
+ barcodeEdt.setText("");
|
|
|
+ barcodeEdt.setFocusable(true);
|
|
|
+ barcodeEdt.setFocusableInTouchMode(true);
|
|
|
+ barcodeEdt.requestFocus();
|
|
|
+ barcodeEdt.findFocus();
|
|
|
+ barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
|
|
|
+ int dstart, int dend) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } });
|
|
|
+ CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tvProductCount.setText("产品信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (JSONException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 2:
|
|
|
+
|
|
|
+ case 3:
|
|
|
+ // 保存
|
|
|
+ Bundle b4 = msg.getData();
|
|
|
+ String saveResult = b4.getString("saveResult");
|
|
|
+ if (mHandler != null) {
|
|
|
+ mHandler.removeCallbacksAndMessages(null);
|
|
|
+ mHandler.getLooper().quit();
|
|
|
+ }
|
|
|
+
|
|
|
+ ProcessDialogUtils.closeProgressDilog();
|
|
|
+ barcodeEdt.setEnabled(true);
|
|
|
+ barcodeEdt.setText("");
|
|
|
+ barcodeEdt.setFocusable(true);
|
|
|
+ barcodeEdt.setFocusableInTouchMode(true);
|
|
|
+ barcodeEdt.requestFocus();
|
|
|
+ barcodeEdt.findFocus();
|
|
|
+ barcodeEdt.setFilters(new InputFilter[] { new InputFilter() {
|
|
|
+ @Override
|
|
|
+ public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
|
|
|
+ int dend) {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } });
|
|
|
+ try {
|
|
|
+ JSONObject jos = new JSONObject(saveResult);
|
|
|
+ int status = jos.optInt("status");
|
|
|
+ String message = jos.optString("message");
|
|
|
+ boolean successFlag = jos.optBoolean("success");
|
|
|
+ if (status != 0) {
|
|
|
+ CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext());
|
|
|
+ CommonUtil.showBarCodeAlertDialog(status, "网络连接失败!请查看服务器", ProductTestSheetActivity.this,
|
|
|
+ barcodeEdt, null, null);
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (successFlag) {
|
|
|
+ if (msg.what == 2) {
|
|
|
+ CustomToast.showToast(getApplicationContext(), "删除成功", 2000);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ CustomToast.showToast(getApplicationContext(), "保存成功", 2000);
|
|
|
+ }
|
|
|
+
|
|
|
+ CommonUtil.playSound(getApplicationContext());
|
|
|
+ // 查询数据
|
|
|
+ thread = new HandlerThread("trademarkThread", 5);
|
|
|
+ thread.start();
|
|
|
+ mHandler = new Handler(thread.getLooper());
|
|
|
+ OrderItemByRunnable ordeitemRunnable = new OrderItemByRunnable(obj, orderId);
|
|
|
+ mHandler.post(ordeitemRunnable);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext());
|
|
|
+ CommonUtil.showBarCodeAlertDialog(status, message, ProductTestSheetActivity.this, barcodeEdt,
|
|
|
+ null, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 字符串是否为空
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isEmpty(String str) {
|
|
|
+ boolean ret = false;
|
|
|
+ if (str == null || "".equals(str) || "NaN".equals(str) || "null".equals(str)) {
|
|
|
+ ret = true;
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|