package com.jiaju.activity; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.KeyStore.PrivateKeyEntry; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import com.jiaju.activity.ComponentsBreakageQuantityOkActivity.SaveRunnableScanOk; import com.jiaju.activity.MakeBilletActivity.BarcodeRunnable; import com.jiaju.adapter.CarBrandSpinnerAdapter; import com.jiaju.adapter.GlazeSpinnerAdapter; import com.jiaju.adapter.ReceiveSpinnerAdapter; import com.jiaju.adapter.SendOutGoodsListMessageAdapter; import com.jiaju.adapter.SendOutSpinnerAdapter; import com.jiaju.model.BarcodeInfo; import com.jiaju.model.Billet; import com.jiaju.model.CarBrandModel; import com.jiaju.model.DutyPerson; import com.jiaju.model.GlazeModel; import com.jiaju.model.Procedure; import com.jiaju.model.ReceiveModel; import com.jiaju.model.ResponsibilityProcedure; import com.jiaju.model.ScrapReason; import com.jiaju.model.SendOutModel; import com.jiaju.model.WorkNo; import com.jiaju.net.WebClient; import com.jiaju.utils.CommonUtil; import com.jiaju.utils.Constants; import com.jiaju.utils.CustomToast; import com.jiaju.utils.MultiChoicDialog; import com.jiaju.utils.MultiChoicePopWindow; import com.jiaju.utils.MultiChoiceProcedureDialog; import com.jiaju.utils.MultiChoiceProcedurePopWindow; import com.jiaju.utils.ProcessDialogUtils; import com.jiaju.utils.Removeduplicate; import com.jiaju.utils.TimePickerInfo; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.Notification; import android.content.Context; import android.content.DialogInterface; 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.text.method.ScrollingMovementMethod; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemSelectedListener; public class SendOutGoods extends Activity { private String serverAddress_ip; private String serverAddress_port; private String accountCode; private String password; private String sessionkey; private WebClient client; private String send_userCode; private SharedPreferences preferences; private HandlerThread thread; private Handler mHandler; private List procedureList; private List checkedProcedureList; private TextView title; private TextView backtext; private TextView sGoodsLogcode; private ImageButton backbtn; private Object obj = new Object(); boolean booleans[]; boolean booleansTemp[]; boolean[] selItems; private View mRootView; private MultiChoiceProcedurePopWindow mMultiChoicePopWindow; private EditText barcodeEdt; private EditText descEdt; private String barcodeUpper; private String Lgort;// 发出仓 private TextView procedureTv; private List barcodeList; private List sendOutList; private List receiveList; private List carBrandList; private JSONArray storageJArray;// 库存 private ListView messageLst; public Button saveBtn; private TimePickerInfo mTimePickerInfo; private TimePickerInfo mTimePickerInfo1; private long timeMillis; private Date mSelectedDate; private Date mSelectedDate1; private Spinner sendOutSpinner; private Spinner receiveSpinner; private Spinner carBrandSpinner; private TextView TextView04; private TextView TextView01; protected String selectedDate; protected String selectedDate1; protected String sendOutGoodLogId; private SendOutModel sendOutModel; private SendOutModel lastSendOutModel; private String desc; private ImageView dateSelector; private ImageView dateSelector1; private SendOutSpinnerAdapter sendOutAdapter; private ReceiveSpinnerAdapter receiveAdapter; private CarBrandSpinnerAdapter carBrandAdapter; private Handler barcodeUpperH = new Handler(); private SendOutGoodsListMessageAdapter adapter; private boolean isCancel=false; private boolean isFirst=true; private String IsSYNCSTATUS="0"; private int Height=188; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_send_out_goods); preferences = getSharedPreferences("user", Context.MODE_PRIVATE); serverAddress_ip = preferences.getString("ServerAddress_ip", ""); serverAddress_port = preferences.getString("ServerAddress_duankou", ""); accountCode = preferences.getString("AccountCode", ""); send_userCode = preferences.getString("UserCode", ""); password = preferences.getString("UserPassword", ""); sessionkey = preferences.getString("SessionKey", ""); barcodeList = new ArrayList(); loadProcedureDataSource(); initView(); sendOutGoodLogId=""; sendOutGoodLogId = this.getIntent().getStringExtra("sendoutCode"); IsSYNCSTATUS = this.getIntent().getStringExtra("SYNCSTATUS"); if(IsSYNCSTATUS==null||IsSYNCSTATUS.equals("")) { IsSYNCSTATUS="0"; } if(sendOutGoodLogId==null||sendOutGoodLogId=="") { ((LinearLayout) findViewById(R.id.LinearLayout06)).setVisibility(View.GONE); }else { sGoodsLogcode.setText(sendOutGoodLogId); } procedureTv.setText(send_userCode); selectedDate = CommonUtil.getCurrentDate(); TextView04.setText(selectedDate); timeMillis = System.currentTimeMillis(); mTimePickerInfo = new TimePickerInfo(SendOutGoods.this, TimePickerInfo.Type.YEAR_MONTH_DAY); mTimePickerInfo.setCyclic(true); mTimePickerInfo.setCancelable(true); mTimePickerInfo.setOnTimeSelectListener(new TimePickerInfo.OnTimeSelectListener() { @SuppressLint("SimpleDateFormat") @Override public void onTimeSelect(Date date) { // 存储当前选中的date SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd"); mSelectedDate = date; selectedDate = dateFormater.format(mSelectedDate); TextView04.setText(selectedDate); } }); selectedDate1 = CommonUtil.getCurrentDate(); TextView01.setText(selectedDate1); timeMillis = System.currentTimeMillis(); mTimePickerInfo1 = new TimePickerInfo(SendOutGoods.this, TimePickerInfo.Type.YEAR_MONTH_DAY); mTimePickerInfo1.setCyclic(true); mTimePickerInfo1.setCancelable(true); mTimePickerInfo1.setOnTimeSelectListener(new TimePickerInfo.OnTimeSelectListener() { @SuppressLint("SimpleDateFormat") @Override public void onTimeSelect(Date date) { // 存储当前选中的date SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd"); mSelectedDate1 = date; selectedDate1 = dateFormater.format(mSelectedDate1); TextView01.setText(selectedDate1); } }); allListeners(); thread = new HandlerThread("sendOutThread3", 5); thread.start(); mHandler = new Handler(thread.getLooper()); SendOutRunnable glazeRunnable = new SendOutRunnable(obj); mHandler.post(glazeRunnable); thread = new HandlerThread("sendOutThread1", 5); thread.start(); mHandler = new Handler(thread.getLooper()); CarBrandRunnable CarBrandRunnable = new CarBrandRunnable(obj); mHandler.post(CarBrandRunnable); thread = new HandlerThread("sendOutThread2", 5); thread.start(); mHandler = new Handler(thread.getLooper()); ReceiveRunnable ReceiveRunnable = new ReceiveRunnable(obj); mHandler.post(ReceiveRunnable); } //protected void onResume() { // super.onResume(); // 如果值已经在onCreate()中加载完成,可以在这里直接调用方法 //HandlerThread thread = new HandlerThread("worThread", 5); //thread.start(); //mHandler = new Handler(thread.getLooper()); // mHandler.post(responsibilityWorkNoRunnable); //isFirst=false; // } private class CarBrandRunnable implements Runnable { private Object object; public CarBrandRunnable(Object object) { this.object = object; } @Override public void run() { synchronized (object) { try { client = null; client = new WebClient(); JSONObject js = new JSONObject(); js.put("accountCode", accountCode); js.put("userCode", send_userCode); js.put("userPassword", password); js.put("sessionKey", sessionkey); js.put("dicType", "TPC029"); String result = client.doPost("http://" + serverAddress_ip + ":" + serverAddress_port + Constants.serverAction + "/GetDataDictionaryByType", js.toString(), "application/json"); Message m = new Message(); m.what = 5; Bundle b = new Bundle(); b.putString("carBrandResult", 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); } } } }; private class ReceiveRunnable implements Runnable { private Object object; public ReceiveRunnable(Object object) { this.object = object; } @Override public void run() { synchronized (object) { try { client = null; client = new WebClient(); JSONObject js = new JSONObject(); js.put("accountCode", accountCode); js.put("userCode", send_userCode); js.put("userPassword", password); js.put("sessionKey", sessionkey); js.put("dicType", "TPC028"); String result = client.doPost("http://" + serverAddress_ip + ":" + serverAddress_port + Constants.serverAction + "/GetDataDictionaryByType", js.toString(), "application/json"); Message m = new Message(); m.what = 4; Bundle b = new Bundle(); b.putString("receiveResult", 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); } } } }; private class SendOutRunnable implements Runnable { private Object object; public SendOutRunnable(Object object) { this.object = object; } @Override public void run() { synchronized (object) { try { ProcessDialogUtils .showProcessDialog(SendOutGoods.this); client = null; client = new WebClient(); JSONObject js = new JSONObject(); js.put("accountCode", accountCode); js.put("userCode", send_userCode); js.put("userPassword", password); js.put("sessionKey", sessionkey); js.put("dicType", "TPC027"); String result = client.doPost("http://" + serverAddress_ip + ":" + serverAddress_port + Constants.serverAction + "/GetDataDictionaryByType", js.toString(), "application/json"); Message m = new Message(); m.what = 3; Bundle b = new Bundle(); b.putString("glazeResult", 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); } } } }; private void allListeners() { dateSelector.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mSelectedDate == null) { mTimePickerInfo.show(new Date(timeMillis)); } else { mTimePickerInfo.show(mSelectedDate); } } }); dateSelector1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mSelectedDate1 == null) { mTimePickerInfo1.show(new Date(timeMillis)); } else { mTimePickerInfo1.show(mSelectedDate1); } } }); backbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); backtext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); sendOutSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { if (arg0 != null) { lastSendOutModel=sendOutModel; sendOutModel = (SendOutModel) arg0.getItemAtPosition(arg2); Lgort = sendOutModel.getSendOutId(); if(isCancel) { return; } ProcessDialogUtils.showProcessDialog( SendOutGoods.this); if(!isFirst) { Dialog alertDialog = new AlertDialog.Builder( SendOutGoods.this).setMessage("确定是否切换发出仓库,需要重新扫码校验出库数量是否充足") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { HandlerThread thread = new HandlerThread("worknoThread", 5); thread.start(); mHandler = new Handler(thread.getLooper()); mHandler.post(responsibilityWorkNoRunnable); } }).setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { isCancel=true; int index = sendOutList.indexOf(lastSendOutModel); if (index >= 0) { sendOutSpinner.setSelection(index); // 这将更新 Spinner 的选中项,但不会触发任何监听器 } ProcessDialogUtils.closeProgressDilog(); // 添加一秒延时 new Handler().postDelayed(new Runnable() { @Override public void run() { isCancel=false; } }, 1500); // 1000 毫秒即一秒延时 } }).create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); return; } else { sendOutModel = (SendOutModel) arg0.getItemAtPosition(arg2); Lgort = sendOutModel.getSendOutId(); HandlerThread thread = new HandlerThread("worknoThread", 5); thread.start(); mHandler = new Handler(thread.getLooper()); mHandler.post(responsibilityWorkNoRunnable); } if (!sendOutModel.getSendOutName().equals("请选择发出仓库")) { } } // flag = true; } @Override public void onNothingSelected(AdapterView arg0) { } }); saveBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String procedure = procedureTv.getText().toString().trim(); if (TextUtils.isEmpty(procedure)) { Toast.makeText(getApplicationContext(), "请选择工序", Toast.LENGTH_SHORT).show(); return; } if (sendOutList == null || sendOutList.size() == 0) { Toast.makeText(getApplicationContext(), "请选择发货仓库", Toast.LENGTH_SHORT).show(); return; } //if (barcodeList == null || barcodeList.size() == 0) { // Toast.makeText(getApplicationContext(), "请添加发货单信息", Toast.LENGTH_SHORT).show(); // return; //} ProcessDialogUtils.showProcessDialog(SendOutGoods.this); SendOutModel sendOut = (SendOutModel) sendOutSpinner.getSelectedItem(); if (sendOut == null) { CustomToast.showToast(getApplicationContext(), "不能为空", 2000); return; } //desc = descEdt.getText().toString(); thread = new HandlerThread("SaveThread", 5); thread.start(); mHandler = new Handler(thread.getLooper()); SaveRunnable saveRunnable = new SaveRunnable(); mHandler.post(saveRunnable); } }); barcodeEdt.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { if (barcodeEdt.getText().toString().contains("\n")) { String barcode = barcodeEdt.getText().toString().trim().replaceAll("\\n", ""); 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) : ""; } } }); ProcessDialogUtils.showProcessDialog(SendOutGoods.this); if (TextUtils.isEmpty(barcode)) { 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; } } }); CommonUtil.BarcodeMaxLength(barcodeEdt, 50); CustomToast.showToast(getApplicationContext(), "条码不能为空", 2000); return; } else { thread = new HandlerThread("BarCodeThread", 5); thread.start(); mHandler = new Handler(thread.getLooper()); BarcodeRunnable barcodeRunnable = new BarcodeRunnable(barcode); mHandler.post(barcodeRunnable); } } } @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(); // 判断输入的文字是否是小写 for (int i = 0; i < barcodeUpper.length(); i++) { if (barcodeUpper.charAt(i) - 0 >= 97 && barcodeUpper.charAt(i) - 0 <= 122) { barcodeUpperH.postDelayed(BarcodeUpperCase, 300); } } } }); barcodeEdt.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_GO) { String barcode = barcodeEdt.getText().toString().trim(); 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) : ""; } } }); ProcessDialogUtils.showProcessDialog(SendOutGoods.this); if (TextUtils.isEmpty(barcode)) { 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; } } }); CommonUtil.BarcodeMaxLength(barcodeEdt, 50); CustomToast.showToast(getApplicationContext(), "条码不能为空", 2000); return true; } else { thread = new HandlerThread("BarCodeThread", 5); thread.start(); mHandler = new Handler(thread.getLooper()); BarcodeRunnable barcodeRunnable = new BarcodeRunnable(barcode); mHandler.post(barcodeRunnable); } } return true; } }); } Runnable BarcodeUpperCase = new Runnable() { @Override public void run() { // 小写转大写 barcodeEdt.setText(barcodeUpper.toUpperCase()); // 设置EditText光标位置 barcodeEdt.setSelection(barcodeUpper.length()); } }; public void showMultiChoiceWindow() { initProcedurePopWindow(booleans); mMultiChoicePopWindow.show(true); } public boolean removeFinishedBarCode(String code, List data) { boolean rem = false; for (int i = 0; i < data.size(); i++) { Object S = data.get(i); Class clss = S.getClass(); String clssName = clss.getName(); Method m = null; Method mouldId = null; try { m = clss.getMethod("getFinishedBarCode"); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } String bar; try { bar = (String) m.invoke(S); if (bar.equals(code)) { rem = true; return rem; } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return rem; } private Handler exceptionHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 0: ProcessDialogUtils.closeProgressDilog(); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } Bundle b = msg.getData(); String message = b.getString("message"); CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show(); 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://关闭转圈 ProcessDialogUtils.closeProgressDilog(); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } Bundle b1 = msg.getData(); String message1 = b1.getString("message"); CommonUtil.showRepeatDialog(message1, SendOutGoods.this); break; } } }; private void initView() { title = (TextView) findViewById(R.id.title); backbtn = (ImageButton) findViewById(R.id.left_img); backtext = (TextView) findViewById(R.id.back); title.setText("发货单"); procedureTv = (TextView) findViewById(R.id.procedureTv); procedureTv.setMovementMethod(ScrollingMovementMethod.getInstance()); procedureTv.setEllipsize(TextUtils.TruncateAt.MARQUEE); procedureTv.setMarqueeRepeatLimit(6); mRootView = findViewById(R.id.parentRel); barcodeEdt = (EditText) findViewById(R.id.barcodeEdt); barcodeEdt.setRawInputType(InputType.TYPE_CLASS_NUMBER); CommonUtil.BarcodeMaxLength(barcodeEdt, 50); descEdt = (EditText) findViewById(R.id.descEdt); messageLst = (ListView) findViewById(R.id.message_listview); saveBtn = (Button) findViewById(R.id.btnSave); sendOutSpinner = (Spinner) findViewById(R.id.trademarksource); receiveSpinner = (Spinner) findViewById(R.id.Spinner02); carBrandSpinner = (Spinner) findViewById(R.id.Spinner01); TextView04 = (TextView) findViewById(R.id.TextView04); TextView01 = (TextView) findViewById(R.id.TextView01); dateSelector = (ImageView) findViewById(R.id.ImageView02); dateSelector1 = (ImageView) findViewById(R.id.ImageView01); sGoodsLogcode = (TextView) findViewById(R.id.sendOutGoodsLogidTxt); } public void loadProcedureDataSource() { } private Runnable responsibilityWorkNoRunnable = new Runnable() { @Override public void run() { try { client = null; client = new WebClient(); JSONObject js = new JSONObject(); js.put("accountCode", accountCode); js.put("userCode", send_userCode); js.put("userPassword", password); js.put("sessionKey", sessionkey); js.put("module", "SendOutGoods"); js.put("action", "GetSendOutGoodsLogs"); JSONObject data = new JSONObject(); data.put("Lgort", Lgort);// 发出仓 data.put("sendoutgoodslogid", sendOutGoodLogId);// 日志id js.put("jsonData", data.toString()); if(Lgort!=null) { String result = client.doPost( "http://" + serverAddress_ip + ":" + serverAddress_port + Constants.serverAction + "/DoAction", js.toString(), "application/json"); JSONObject j = new JSONObject(result); JSONObject jo = (JSONObject) j.opt("d"); int status = jo.optInt("Status"); String message = jo.optString("Message"); if (status == 0) { Message m = new Message(); m.what = 10; Bundle b = new Bundle(); b.putString("result", result); m.setData(b); handler.sendMessage(m); // String result1 = jo.optString("Result"); // JSONArray jarray = new JSONArray(result1); // for (int i = 0; i < jarray.length(); i++) { // JSONObject jobj = (JSONObject) jarray.opt(i); // WorkNo w = new WorkNo(); // double userId = jobj.optDouble("USERID"); // w.setUserId(userId); // String userCode = jobj.optString("USERCODE"); // w.setUserCode(userCode); // String userName1 = jobj.optString("USERNAME"); // w.setUserName(userName1); // worknolist.add(w); // } }} } catch (Exception e) { Message m = new Message(); m.what = 0; Bundle b = new Bundle(); b.putString("message", "网络连接异常"); m.setData(b); exceptionHandler.sendMessage(m); e.printStackTrace(); } } }; private class SaveRunnable implements Runnable { @Override public void run() { client = new WebClient(); try { JSONObject js = new JSONObject(); JSONObject js6 = new JSONObject(); js6.put("SENDOUTCODE", sendOutGoodLogId); js6.put("USERCODE", send_userCode); if(TextView04.getText()== null|| TextView04.getText().toString()== "") { CustomToast.showToast(getApplicationContext(), "记账日期不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; }else { js6.put("ACCOUNTDATE", TextView04.getText().toString()); } if(TextView01.getText()== null|| TextView01.getText().toString()== "") { CustomToast.showToast(getApplicationContext(), "送货日期不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; }else { js6.put("DELIVERDATE", TextView01.getText().toString()); } if (sendOutSpinner.getSelectedItem() == null) { CustomToast.showToast(getApplicationContext(), "损坯原因不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; } else if (sendOutSpinner.getSelectedItem() != null) { SendOutModel model = (SendOutModel) sendOutSpinner.getSelectedItem(); if (model != null && model.getSendOutId() == "") { CustomToast.showToast(getApplicationContext(), "发货仓库不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; }else { js6.put("WAREHOUSINGID", model.getSendOutId()); } } if (receiveSpinner.getSelectedItem() == null) { CustomToast.showToast(getApplicationContext(), "损坯原因不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; } else if (receiveSpinner.getSelectedItem() != null) { ReceiveModel rm = (ReceiveModel) receiveSpinner.getSelectedItem(); if (rm != null && rm.getReceiveId() == "") { CustomToast.showToast(getApplicationContext(), "接收仓库不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; }else { js6.put("RECEIVEID", rm.getReceiveId()); } } if (carBrandSpinner.getSelectedItem() == null) { CustomToast.showToast(getApplicationContext(), "损坯原因不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; } else if (carBrandSpinner.getSelectedItem() != null) { CarBrandModel model = (CarBrandModel) carBrandSpinner.getSelectedItem(); if (model != null && model.getCarBrandId() == "") { CustomToast.showToast(getApplicationContext(), "车牌号不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; }else { js6.put("CARPLATEID", model.getCarBrandId()); } } js.put("setEntity", js6); if (barcodeList != null && barcodeList.size() > 0) { JSONArray jarray6 = new JSONArray(); for (BarcodeInfo bd : barcodeList) { JSONObject jo6 = new JSONObject(); jo6.put("Banma", bd.getBanMa()); jo6.put("GOODSCODE", bd.getGoodsCode()); jo6.put("MATERIALCODE", bd.getLogoCode()); jo6.put("MATERIALREMARK", bd.getLogoName()); jo6.put("BINDINGCount", bd.getOrderNo()); jo6.put("FINISHEDLOADBATCHNO", bd.getFinishedBarCode()); jarray6.put(jo6); } js.put("setDetailEntity", jarray6); }else { CustomToast.showToast(getApplicationContext(), "发货单信息不能为空", 2000); ProcessDialogUtils.closeProgressDilog(); return; } JSONObject js5 = new JSONObject(); js5.put("accountCode", accountCode); js5.put("userCode", send_userCode); js5.put("userPassword", password); js5.put("sessionKey", sessionkey); js5.put("module", "SendOutGoods"); js5.put("action", "SaveSendOutGoods"); js5.put("jsonData",js.toString()); String result = client.doPost( "http://" + serverAddress_ip + ":" + serverAddress_port + Constants.serverAction + "/DoAction", js5.toString(), "application/json"); Message m = new Message(); m.what = 2; Bundle b = new Bundle(); b.putString("result", result); m.setData(b); handler.sendMessage(m); } catch (Exception e) { Message m = new Message(); m.what = 0; Bundle b = new Bundle(); b.putString("message", "网络连接异常"); m.setData(b); exceptionHandler.sendMessage(m); e.printStackTrace(); } } } //扫码 private class BarcodeRunnable implements Runnable { String barcode; public BarcodeRunnable(String barcode) { super(); this.barcode = barcode; } @Override public void run() { client = new WebClient(); try { JSONObject js = new JSONObject(); js.put("accountCode", accountCode); js.put("userCode", send_userCode); js.put("userPassword", password); js.put("sessionKey", sessionkey); js.put("module", "SendOutGoods"); js.put("action", "CheckSendOutBarcode"); JSONObject data = new JSONObject(); data.put("banma", barcode); js.put("jsonData", data.toString()); String result = client.doPost( "http://" + serverAddress_ip + ":" + serverAddress_port + Constants.serverAction + "/DoAction", js.toString(), "application/json"); Message m = new Message(); m.what = 1; Bundle b = new Bundle(); b.putString("result", result); m.setData(b); handler.sendMessage(m); } catch (Exception e) { Message m = new Message(); m.what = 0; Bundle b = new Bundle(); b.putString("message", "网络连接异常"); m.setData(b); exceptionHandler.sendMessage(m); e.printStackTrace(); } } } Handler handler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case 0: Bundle b = msg.getData(); String json = b.getString("result"); ProcessDialogUtils.closeProgressDilog(); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } try { JSONObject jObject = new JSONObject(json); JSONObject object = (JSONObject) jObject.opt("d"); int status = object.optInt("Status"); String message = object.optString("Message"); if (status == 0) { String result = object.optString("Result"); JSONArray jArray = new JSONArray(result); if (jArray != null && jArray.length() > 0) { procedureList = new ArrayList(); for (int i = 0; i < jArray.length(); i++) { JSONObject jObject1 = (JSONObject) jArray.opt(i); int procedureId = jObject1.optInt("PROCEDUREID"); String procedureName = jObject1.optString("PROCEDURENAME"); Procedure procedure = new Procedure(); procedure.setProcedureId(String.valueOf(procedureId)); procedure.setProcedureName(procedureName); procedureList.add(procedure); } booleans = new boolean[procedureList.size()]; initProcedurePopWindow(booleans); } } else { CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CommonUtil.showBarCodeAlertDialog(status, message, SendOutGoods.this, null, null, null); } } catch (Exception e) { e.printStackTrace(); } break; case 1: ProcessDialogUtils.closeProgressDilog(); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } Bundle bundle = msg.getData(); String json1 = bundle.getString("result"); try { JSONObject jObject = new JSONObject(json1); JSONObject object = (JSONObject) jObject.opt("d"); int status = object.optInt("Status"); String message = object.optString("Message"); if (status == 0) { String result = object.optString("Result"); JSONArray jArray = new JSONArray(result); String mCODE = ((JSONObject) jArray.opt(0)).optString("MATERIALCODE"); String Count = ((JSONObject) jArray.opt(0)).optString("COUNT"); int mcount = 0; for (BarcodeInfo bd : barcodeList) { if (bd.getLogoCode() == mCODE) { mcount = mcount + Integer.parseInt(bd.getOrderNo()); } } int storageConout = 0; if (storageJArray != null && storageJArray.length() > 0) { for (int i = 0; i < storageJArray.length(); i++) { JSONObject sobject = (JSONObject) storageJArray.opt(i); String MATERIALCODE = sobject.optString("MATNR"); if (MATERIALCODE.equals(mCODE)) { storageConout = storageConout + (int)Double.parseDouble(sobject.optString("LABST"));// sap库存 } } } if ((Double.parseDouble(Count)) >(double)(storageConout-mcount)) { //CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CommonUtil.showBarCodeAlertDialog(0, "库存不足", SendOutGoods.this, barcodeEdt, null, null); return; } else { if (jArray != null && jArray.length() > 0) { for (int i = 0; i < jArray.length(); i++) { JSONObject object2 = (JSONObject) jArray.opt(i); String barcode = object2.optString("BANMA"); String goodsCode = object2.optString("GOODSCODE"); String LogoCode = object2.optString("MATERIALCODE"); String LogoName = object2.optString("MATERIALREMARK"); int orderNo = object2.optInt("COUNT"); boolean isHas =removeFinishedBarCode(object2.optString("FINISHEDLOADBATCHNO"), barcodeList); if(isHas) { CommonUtil.BarcodeMaxLength(barcodeEdt, 50); CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CustomToast.showToast(getApplicationContext(), "条码重复", 2000); break; } BarcodeInfo barcodeInfo = new BarcodeInfo(); barcodeInfo.setBanMa(barcode=="null"?"":barcode); barcodeInfo.setGoodsCode(goodsCode); barcodeInfo.setLogoCode(LogoCode); barcodeInfo.setLogoName(LogoName); barcodeInfo.setOrderNo(String.valueOf(orderNo)); barcodeInfo.setFinishedBarCode(object2.optString("FINISHEDLOADBATCHNO"));//判断是否重复 barcodeList.add(barcodeInfo); } if (adapter == null) { adapter = new SendOutGoodsListMessageAdapter(SendOutGoods.this, barcodeList); messageLst.setAdapter(adapter); } else { adapter.notifyDataSetChanged(); //messageLst.getLayoutParams().height=(messageLst.getHeight()+Height); messageLst.getLayoutParams().height=(barcodeList.size()*Height); } saveBtn.setText("保存(" + barcodeList.size() + ")"); 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); // InputMethodManager im = (InputMethodManager) barcodeEdt // .getContext().getSystemService( // Context.INPUT_METHOD_SERVICE); // im.hideSoftInputFromWindow(ProductSuspendActivity.this // .getCurrentFocus().getWindowToken(), // InputMethodManager.HIDE_NOT_ALWAYS); ProcessDialogUtils.closeProgressDilog(); } } } else if (status==-1) { message="此产品已发货,不能进行该操作"; CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CommonUtil.showBarCodeAlertDialog(0, message, SendOutGoods.this, barcodeEdt, null, null); return; }else if (status==-102) { message="此产品未交接,不能进行该操作"; CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CommonUtil.showBarCodeAlertDialog(0, message, SendOutGoods.this, barcodeEdt, null, null); return; }else if (status==-100) { message="此产品已被废弃,不能进行该操作"; CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CommonUtil.showBarCodeAlertDialog(0, message, SendOutGoods.this, barcodeEdt, null, null); return; }else if (status==-999) { message="此产品无效条码,不能进行该操作"; CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CommonUtil.showBarCodeAlertDialog(0, message, SendOutGoods.this, barcodeEdt, null, null); return; } } catch (JSONException e) { e.printStackTrace(); } break; case 2: if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } ProcessDialogUtils.closeProgressDilog(); Bundle bundle2 = msg.getData(); String json2 = bundle2.getString("result"); JSONObject jObject; try { jObject = new JSONObject(json2); JSONObject object = (JSONObject) jObject.opt("d"); int status = object.optInt("Status"); String message = object.optString("Message"); //JSONObject result3 =(JSONObject) object.opt("Result"); //JSONArray resArray = (JSONArray)result3.opt("Result"); if (status == 0) { barcodeList.removeAll(barcodeList); adapter.notifyDataSetChanged(); messageLst.getLayoutParams().height=(barcodeList.size()*Height); saveBtn.setText("保存(" + barcodeList.size() + ")"); CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CommonUtil.showSaveAlertDialog(0,message , SendOutGoods.this, null, barcodeEdt, 2); // CustomToast.showToast(getApplicationContext(), "成功", 2000); // CommonUtil.playSound(getApplicationContext()); //checkedProcedureList.clear(); //procedureTv.setText(""); //descEdt.setText(""); //desc = ""; //booleans = new boolean[procedureList.size()]; sendOutGoodLogId=""; ((LinearLayout) findViewById(R.id.LinearLayout06)).setVisibility(View.GONE); HandlerThread thread = new HandlerThread("worknoThreads", 5); thread.start(); mHandler = new Handler(thread.getLooper()); mHandler.post(responsibilityWorkNoRunnable); } else{ CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); CommonUtil.showSaveAlertDialog(0,message , SendOutGoods.this, null, barcodeEdt, 2); } } catch (JSONException e) { e.printStackTrace(); } break; case 3: Bundle b3 = msg.getData(); String json3 = b3.getString("glazeResult"); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } ProcessDialogUtils.closeProgressDilog(); JSONObject j2; try { j2 = new JSONObject(json3); JSONObject j3 = j2.optJSONObject("d"); int status3 = j3.optInt("Status"); if (status3 == 0) { String result3 = j3.optString("Result"); JSONArray resultArray = new JSONArray(result3); if (resultArray != null && resultArray.length() > 0) { sendOutList = new ArrayList(); for (int i = 0; i < resultArray.length(); i++) { JSONObject resultObj = (JSONObject) resultArray.opt(i); int dictionaryId = resultObj.optInt("DICTIONARYID"); String dictionaryValue = resultObj.optString("DICTIONARYVALUE"); SendOutModel sendOutModel = new SendOutModel(); sendOutModel.setSendOutId(String.valueOf(dictionaryId)); sendOutModel.setSendOutName(dictionaryValue); sendOutList.add(sendOutModel); } sendOutAdapter = new SendOutSpinnerAdapter(SendOutGoods.this, sendOutList); sendOutSpinner.setAdapter(sendOutAdapter); } } } catch (JSONException e) { e.printStackTrace(); } break; case 4: Bundle b3r = msg.getData(); String json3r = b3r.getString("receiveResult"); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } JSONObject j2r; try { j2r = new JSONObject(json3r); JSONObject j3 = j2r.optJSONObject("d"); int status3 = j3.optInt("Status"); if (status3 == 0) { String result3 = j3.optString("Result"); JSONArray resultArray = new JSONArray(result3); if (resultArray != null && resultArray.length() > 0) { receiveList = new ArrayList(); for (int i = 0; i < resultArray.length(); i++) { JSONObject resultObj = (JSONObject) resultArray.opt(i); int dictionaryId = resultObj.optInt("DICTIONARYID"); String dictionaryValue = resultObj.optString("DICTIONARYVALUE"); ReceiveModel receiveModel = new ReceiveModel(); receiveModel.setReceiveId(String.valueOf(dictionaryId)); receiveModel.setReceiveName(dictionaryValue); receiveList.add(receiveModel); } receiveAdapter = new ReceiveSpinnerAdapter(SendOutGoods.this, receiveList); receiveSpinner.setAdapter(receiveAdapter); } } } catch (JSONException e) { e.printStackTrace(); } break; case 5: Bundle b3c = msg.getData(); String json3c = b3c.getString("carBrandResult"); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } JSONObject j2c; try { j2c = new JSONObject(json3c); JSONObject j3 = j2c.optJSONObject("d"); int status3 = j3.optInt("Status"); if (status3 == 0) { String result3 = j3.optString("Result"); JSONArray resultArray = new JSONArray(result3); if (resultArray != null && resultArray.length() > 0) { carBrandList = new ArrayList(); for (int i = 0; i < resultArray.length(); i++) { JSONObject resultObj = (JSONObject) resultArray.opt(i); int dictionaryId = resultObj.optInt("DICTIONARYID"); String dictionaryValue = resultObj.optString("DICTIONARYVALUE"); CarBrandModel carBrandModel = new CarBrandModel(); carBrandModel.setCarBrandId(String.valueOf(dictionaryId)); carBrandModel.setCarBrandName(dictionaryValue); carBrandList.add(carBrandModel); } carBrandAdapter = new CarBrandSpinnerAdapter(SendOutGoods.this, carBrandList); carBrandSpinner.setAdapter(carBrandAdapter); } } } catch (JSONException e) { e.printStackTrace(); } break; case 10: ProcessDialogUtils.closeProgressDilog(); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); mHandler.getLooper().quit(); } Bundle bundle10 = msg.getData(); String json10 = bundle10.getString("result"); try { JSONObject jObject10 = new JSONObject(json10); JSONObject object = (JSONObject) jObject10.opt("d"); int status = object.optInt("Status"); String message = object.optString("Message"); if (status == 0) { String result = object.optString("Result"); JSONArray jArr = new JSONArray(result); storageJArray=(JSONArray)jArr.opt(0); JSONArray jArray = (JSONArray)jArr.opt(1); barcodeList.removeAll(barcodeList); if (jArray != null && jArray.length() > 0) { for (int i = 0; i < jArray.length(); i++) { JSONObject object2 = (JSONObject) jArray.opt(i); String barcode = object2.optString("BANMA"); String goodsCode = object2.optString("GOODSCODE"); String LogoCode = object2.optString("MATERIALCODE"); // groutingDate = CommonUtil.commonDateConverter(groutingDate); String LogoName = object2.optString("MATERIALREMARK"); // String userCode = object2.optString("USERCODE"); String orderNo =String.valueOf((int) Double.parseDouble(object2.optString("COUNT"))); BarcodeInfo barcodeInfo = new BarcodeInfo(); barcodeInfo.setBanMa(barcode==null||barcode.equals("null")?"":barcode); barcodeInfo.setGoodsCode(goodsCode); barcodeInfo.setLogoCode(LogoCode); barcodeInfo.setLogoName(LogoName); // barcodeInfo.setUserCode(userCode); barcodeInfo.setOrderNo(orderNo); barcodeInfo.setFinishedBarCode(object2.optString("FINISHEDLOADBATCHNO")); barcodeList.add(barcodeInfo); } } if (adapter == null) { adapter = new SendOutGoodsListMessageAdapter(SendOutGoods.this, barcodeList); messageLst.setAdapter(adapter); } else { adapter.notifyDataSetChanged(); } messageLst.getLayoutParams().height=(barcodeList.size()*Height); saveBtn.setText("保存(" + barcodeList.size() + ")"); barcodeEdt.setEnabled(true); barcodeEdt.setText(""); barcodeEdt.setFocusable(true); barcodeEdt.setFocusableInTouchMode(true); barcodeEdt.requestFocus(); barcodeEdt.findFocus(); isFirst=false; barcodeEdt.setFilters(new InputFilter[] { new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { return null; } } }); if(IsSYNCSTATUS.equals("1")) { barcodeEdt.setEnabled(false); saveBtn.setEnabled(false); //sendOutSpinner.setSpinnerMode(DialogFragment.MODE_DIALOG); } CommonUtil.BarcodeMaxLength(barcodeEdt, 50); // InputMethodManager im = (InputMethodManager) barcodeEdt // .getContext().getSystemService( // Context.INPUT_METHOD_SERVICE); // im.hideSoftInputFromWindow(ProductSuspendActivity.this // .getCurrentFocus().getWindowToken(), // InputMethodManager.HIDE_NOT_ALWAYS); ProcessDialogUtils.closeProgressDilog(); } //else { // CommonUtil.setDefault(Notification.DEFAULT_VIBRATE, getApplicationContext()); // CommonUtil.showBarCodeAlertDialog(status, message, SendOutGoods.this, barcodeEdt, null, null); // return; //} } catch (JSONException e) { e.printStackTrace(); } break; } } }; public void initProcedurePopWindow(boolean[] bool) { mMultiChoicePopWindow = new MultiChoiceProcedurePopWindow(this, mRootView, procedureList, bool); mMultiChoicePopWindow.setTitle("工序列表"); mMultiChoicePopWindow.setOnOKButtonListener(new OnClickListener() { @Override public void onClick(View v) { selItems = mMultiChoicePopWindow.getSelectItem(); booleansTemp = selItems.clone(); checkedProcedureList = new ArrayList(); StringBuffer stringBuffer = new StringBuffer(); if (selItems != null && selItems.length > 0) { int size = selItems.length; stringBuffer.append("【"); for (int i = 0; i < size; i++) { if (selItems[i]) { stringBuffer.append(procedureList.get(i).getProcedureName()); stringBuffer.append("、"); checkedProcedureList.add(procedureList.get(i)); } } if (checkedProcedureList != null && checkedProcedureList.size() > 0) { String procedure = stringBuffer.toString(); if (procedure.length() > 0) { procedure = procedure.substring(0, procedure.length() - 1); StringBuffer procedureStringBuffer = new StringBuffer(); procedureStringBuffer.append(procedure); procedureStringBuffer.append("】"); procedure = procedureStringBuffer.toString(); procedureTv.setText(procedure); } } else { checkedProcedureList = null; procedureTv.setText(""); } } } }); mMultiChoicePopWindow.setOnCancelButtonListener(new OnClickListener() { @Override public void onClick(View v) { if (booleansTemp != null && booleansTemp.length > 0) { booleans = booleansTemp.clone(); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.product_suspend, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }