SCSMTChangeFragment.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. package com.uas.uaspda.fragment;
  2. import android.content.Context;
  3. import android.os.Handler;
  4. import android.os.Message;
  5. import android.text.TextUtils;
  6. import android.util.Log;
  7. import android.view.KeyEvent;
  8. import android.view.View;
  9. import android.view.inputmethod.EditorInfo;
  10. import android.view.inputmethod.InputMethodManager;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.RelativeLayout;
  14. import android.widget.TextView;
  15. import com.alibaba.fastjson.JSON;
  16. import com.android.volley.AuthFailureError;
  17. import com.android.volley.DefaultRetryPolicy;
  18. import com.android.volley.Request;
  19. import com.android.volley.Response;
  20. import com.android.volley.VolleyError;
  21. import com.android.volley.toolbox.StringRequest;
  22. import com.uas.uaspda.R;
  23. import com.uas.uaspda.application.PdaApplication;
  24. import com.uas.uaspda.bean.LineInfoBean;
  25. import com.uas.uaspda.bean.SmtDslBean;
  26. import com.uas.uaspda.global.GloableParams;
  27. import com.uas.uaspda.tools.SharedPreUtil;
  28. import com.uas.uaspda.tools.VolleyUtil;
  29. import com.uas.uaspda.util.CommonUtil;
  30. import com.uas.uaspda.util.Constants;
  31. import com.uas.uaspda.util.FastjsonUtil;
  32. import com.uas.uaspda.util.HttpCallback;
  33. import com.uas.uaspda.util.HttpParams;
  34. import com.uas.uaspda.util.JsonUtils;
  35. import com.uas.uaspda.util.VolleyRequest;
  36. import com.uas.uaspda.view.ClearableEditText;
  37. import com.uas.uaspda.view.TextViewWithButton;
  38. import org.json.JSONArray;
  39. import org.json.JSONException;
  40. import org.json.JSONObject;
  41. import java.util.HashMap;
  42. import java.util.Map;
  43. /**
  44. * @note:SMTChild换料操作 modify:2017-05-15
  45. */
  46. public class SCSMTChangeFragment extends BaseFragment implements TextViewWithButton.TvHintHelper, View.OnClickListener {
  47. JSONObject makeCraft;
  48. TextViewWithButton tvLocation, tvBarcode, tvRemainqty, mLocationTextView, mFeederTextView;
  49. TextView tvMsgNotice, tvMsgLocation, tvMsgProdcode, tvMsgBarcode, tvMsgQuantity, tvMsgSpec;
  50. RelativeLayout rlCollect;
  51. int wrongColor, rightColor;
  52. int requestType;
  53. JSONArray smtLocation;
  54. JSONObject mslChange;
  55. boolean isAgain = false;
  56. private LineInfoBean mLineInfoBean;
  57. private TextView mLinecodeTextView, mTableTextView, mMacodeTextView;
  58. private ClearableEditText mCollectEditText;
  59. private String mSmtLocationCache;
  60. private SmtDslBean mSmtDslBean = new SmtDslBean();
  61. private StringRequest mStringRequest;
  62. private TextViewWithButton.OnTextClearListener mLocationClearListener;
  63. private TextViewWithButton.OnTextClearListener mFeederClearListener;
  64. @Override
  65. protected int getLayout() {
  66. return R.layout.fragment_scmake_smtfeederchild_jointchange;
  67. }
  68. @Override
  69. protected void initViews() {
  70. //->采集
  71. tvLocation = (TextViewWithButton) root.findViewById(R.id.tv_location_smtchildadd);
  72. tvBarcode = (TextViewWithButton) root.findViewById(R.id.tv_barcode_smtchildadd);
  73. tvRemainqty = (TextViewWithButton) root.findViewById(R.id.tv_remainqty_smtchildadd);
  74. rlCollect = (RelativeLayout) root.findViewById(R.id.rl_innernotice_smtchildadd);
  75. //->提示信息
  76. tvMsgNotice = (TextView) root.findViewById(R.id.tv_innernotice_msgtitle_scmake);
  77. tvMsgProdcode = (TextView) root.findViewById(R.id.tv_innernotice_1_scmake);
  78. tvMsgLocation = (TextView) root.findViewById(R.id.tv_innernotice_2_scmake);
  79. tvMsgBarcode = (TextView) root.findViewById(R.id.tv_innernotice_3_scmake);
  80. tvMsgQuantity = (TextView) root.findViewById(R.id.tv_innernotice_4_scmake);
  81. tvMsgSpec = (TextView) root.findViewById(R.id.tv_innernotice_5_scmake);
  82. mLinecodeTextView = (TextView) root.findViewById(R.id.smt_change_linecode_tv);
  83. mTableTextView = (TextView) root.findViewById(R.id.smt_change_table_tv);
  84. mMacodeTextView = (TextView) root.findViewById(R.id.smt_change_macode_tv);
  85. mLocationTextView = (TextViewWithButton) root.findViewById(R.id.smt_change_location_tv);
  86. mCollectEditText = (ClearableEditText) root.findViewById(R.id.smt_change_collect_et);
  87. mFeederTextView = root.findViewById(R.id.smt_change_feeder_tv);
  88. mCollectEditText.requestFocus();
  89. mCollectEditText.setHint("请采集飞达编号");
  90. wrongColor = getResources().getColor(R.color.text_error);
  91. rightColor = getResources().getColor(R.color.green);
  92. //接口回调
  93. VolleyUtil.setVolleyHandler(volleyHandler);
  94. mLineInfoBean = (LineInfoBean) PdaApplication.getDataCacheFromMap(Constants.FLAG.SMT_DEVICE_LINE_CACHE);
  95. // JSONObject paramJson = new JSONObject();
  96. // try {
  97. // makeCraft = new JSONObject(makeCraftStr);
  98. // Log.e(TAG, "makeCraft" + makeCraft);
  99. // String psId = makeCraft.getString("ps_id");
  100. // String prodcode = makeCraft.getString("mc_prodcode");
  101. // paramJson.put("ps_id", psId);
  102. // paramJson.put("prodcode", prodcode);
  103. // } catch (JSONException e) {
  104. // e.printStackTrace();
  105. // }
  106. //if(jobCode.equals("")||jobCode == null||jobCode.equals("null")){jobCode = "无";}
  107. //
  108. // //获取网络数据
  109. // requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_DETAIL;
  110. // VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMTDETAIL_APPLY, VolleyUtil.METHOD_POST,
  111. // requestType, paramJson);
  112. }
  113. @Override
  114. protected void initEvents() {
  115. tvLocation.setTvHintHelper(this);
  116. tvBarcode.setTvHintHelper(this);
  117. tvRemainqty.setTvHintHelper(this);
  118. mCollectEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  119. @Override
  120. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  121. String collect = mCollectEditText.getText().toString().trim();
  122. if (!TextUtils.isEmpty(collect)) {
  123. if (actionId == EditorInfo.IME_ACTION_DONE
  124. || actionId == EditorInfo.IME_ACTION_SEND
  125. || (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
  126. confirmEvent(collect);
  127. return true;
  128. }
  129. }
  130. return false;
  131. }
  132. });
  133. mFeederClearListener = new TextViewWithButton.OnTextClearListener() {
  134. @Override
  135. public void onTextClear() {
  136. mLocationTextView.setOnTextClearListener(null);
  137. mLocationTextView.setText("");
  138. mLocationTextView.setOnTextClearListener(mLocationClearListener);
  139. mCollectEditText.setHint("请采集飞达编号");
  140. mCollectEditText.setText("");
  141. }
  142. };
  143. mLocationClearListener = new TextViewWithButton.OnTextClearListener() {
  144. @Override
  145. public void onTextClear() {
  146. mFeederTextView.setOnTextClearListener(null);
  147. mFeederTextView.setText("");
  148. mFeederTextView.setOnTextClearListener(mFeederClearListener);
  149. mCollectEditText.setHint("请采集飞达编号");
  150. mCollectEditText.setText("");
  151. }
  152. };
  153. mLocationTextView.setOnTextClearListener(mLocationClearListener);
  154. mFeederTextView.setOnTextClearListener(mFeederClearListener);
  155. }
  156. private void confirmEvent(String collect) {
  157. String location = mLocationTextView.getText().toString().trim();
  158. if (TextUtils.isEmpty(location)) {
  159. feederGetLocation(collect);
  160. } else {
  161. mSmtDslBean.setDsl_barcode(collect);
  162. //接料操作
  163. smtChangeMaterial();
  164. }
  165. }
  166. private void feederGetLocation(String collect) {
  167. progressDialog.show();
  168. VolleyRequest.getInstance().stringRequest(new HttpParams.Builder()
  169. .url(GloableParams.ADDRESS_SMT_GETFEEDERBARCODE)
  170. .method(Request.Method.POST)
  171. .addParam("fe_code", collect)
  172. .build(), new HttpCallback() {
  173. @Override
  174. public void onSuccess(int flag, Object o) throws Exception {
  175. try {
  176. progressDialog.dismiss();
  177. String result = o.toString();
  178. com.alibaba.fastjson.JSONObject resultObject = JSON.parseObject(result);
  179. com.alibaba.fastjson.JSONObject dataObject = resultObject.getJSONObject("data");
  180. if (dataObject != null) {
  181. String fe_code = FastjsonUtil.getText(dataObject, "fe_code");
  182. String fe_location = FastjsonUtil.getText(dataObject, "fe_location");
  183. locationCheck(fe_location, fe_code);
  184. } else {
  185. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  186. tvMsgNotice.setText("数据为空");
  187. CommonUtil.makeNotice();
  188. mCollectEditText.setText("");
  189. }
  190. } catch (Exception e) {
  191. e.printStackTrace();
  192. }
  193. }
  194. @Override
  195. public void onFail(int flag, String failStr) throws Exception {
  196. progressDialog.dismiss();
  197. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  198. tvMsgNotice.setText(failStr);
  199. CommonUtil.makeNotice();
  200. mCollectEditText.setText("");
  201. }
  202. });
  203. }
  204. private void locationCheck(String collect, String feeder) {
  205. tvMsgProdcode.setText("");
  206. tvMsgLocation.setText("");
  207. tvMsgBarcode.setText("");
  208. tvMsgQuantity.setText("");
  209. tvMsgSpec.setText("");
  210. if (!TextUtils.isEmpty(mSmtLocationCache)) {
  211. try {
  212. JSONArray locationArray = new JSONArray(mSmtLocationCache);
  213. boolean isExist = false;
  214. for (int i = 0; i < locationArray.length(); i++) {
  215. JSONObject locationObject = locationArray.getJSONObject(i);
  216. if (collect.equals(JsonUtils.optStringNotNull(locationObject, "PSL_LOCATION"))) {
  217. isExist = true;
  218. mLocationTextView.setText(collect);
  219. mFeederTextView.setText(feeder);
  220. mCollectEditText.setText("");
  221. String psl_prodcode = JsonUtils.optStringNotNull(locationObject, "PSL_PRODCODE");
  222. String psl_repcode = JsonUtils.optStringNotNull(locationObject, "PSL_REPCODE");
  223. mSmtDslBean = new SmtDslBean();
  224. mSmtDslBean.setDsl_location(collect);
  225. mSmtDslBean.setDsl_prodcode(psl_prodcode);
  226. mCollectEditText.setHint("请录入料卷编号/物料编号");
  227. if (!TextUtils.isEmpty(psl_repcode)) {
  228. // if (TextUtils.isEmpty(psl_repcode) || "null".equals(psl_repcode))
  229. // tvMsgNotice.setText("站位采集成功,请采集首选料[" + psl_prodcode + "]的料卷编号");
  230. // else
  231. String[] repcodes = psl_repcode.split(",");
  232. String notice = "飞达采集成功,请采集物料\n";
  233. for (int j = 0; j < repcodes.length; j++) {
  234. String repcode = repcodes[j];
  235. notice = notice + repcode + "\n";
  236. }
  237. notice = notice + "的料卷编号/物料编号";
  238. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  239. tvMsgNotice.setText(notice);
  240. } else if (!TextUtils.isEmpty(psl_prodcode)) {
  241. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  242. tvMsgNotice.setText("飞达采集成功,请采集物料\n" + psl_prodcode + "\n的料卷编号/物料编号");
  243. } else {
  244. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  245. tvMsgNotice.setText("飞达采集成功,物料编号获取失败");
  246. }
  247. }
  248. }
  249. if (!isExist) {
  250. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  251. tvMsgNotice.setText("站位编号错误");
  252. CommonUtil.makeNotice();
  253. mCollectEditText.setText("");
  254. }
  255. } catch (JSONException e) {
  256. e.printStackTrace();
  257. }
  258. } else {
  259. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  260. tvMsgNotice.setText("站位编号错误");
  261. CommonUtil.makeNotice();
  262. mCollectEditText.setText("");
  263. }
  264. }
  265. /**
  266. * SMT接料
  267. */
  268. private void smtChangeMaterial() {
  269. progressDialog.show();
  270. PdaApplication.mRequestQueue.cancelAll(TAG + "loading");
  271. final String smtDsl = JSON.toJSONString(mSmtDslBean);
  272. String deviceLineMake = "";
  273. if (mLineInfoBean != null)
  274. deviceLineMake = JSON.toJSONString(mLineInfoBean);
  275. final String finalDeviceLineMake = deviceLineMake;
  276. mStringRequest = new StringRequest(Request.Method.POST, GloableParams.ADDRESS_SMT_CHANGE_MATERIAL,
  277. new Response.Listener<String>() {
  278. @Override
  279. public void onResponse(String s) {
  280. try {
  281. Log.d("smtchange", s);
  282. if (progressDialog.isShowing())
  283. progressDialog.dismiss();
  284. JSONObject jsonObject = new JSONObject(s);
  285. JSONObject dataObject = jsonObject.optJSONObject("data");
  286. if (dataObject != null) {
  287. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  288. tvMsgNotice.setText("换料成功");
  289. tvMsgProdcode.setText("料号:" + JsonUtils.optStringNotNull(dataObject, "DSL_PRODCODE"));
  290. tvMsgLocation.setText("位号:" + JsonUtils.optStringNotNull(dataObject, "DSL_LOCATION"));
  291. tvMsgBarcode.setText("料卷号:" + JsonUtils.optStringNotNull(dataObject, "DSL_BARCODE"));
  292. tvMsgQuantity.setText("数量:" + CommonUtil.doubleFormat(JsonUtils.optDoubleNotNull(dataObject, "DSL_REMAINQTY")));
  293. tvMsgSpec.setText("飞达规格:" + JsonUtils.optStringNotNull(dataObject, "DSL_FESPEC"));
  294. mLocationTextView.setText("");
  295. mCollectEditText.setText("");
  296. mSmtDslBean = new SmtDslBean();
  297. mCollectEditText.setHint("请采集飞达编号");
  298. }
  299. } catch (JSONException e) {
  300. e.printStackTrace();
  301. }
  302. }
  303. },
  304. new Response.ErrorListener() {
  305. @Override
  306. public void onErrorResponse(VolleyError volleyError) {
  307. if (progressDialog.isShowing())
  308. progressDialog.dismiss();
  309. String errorToast = CommonUtil.showErrorToast(volleyError, false);
  310. if (errorToast != null) {
  311. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  312. tvMsgNotice.setText(errorToast);
  313. if (errorToast.contains("站位已经有在线料卷号")) {
  314. mLocationTextView.setText("");
  315. mCollectEditText.setText("");
  316. } else {
  317. mCollectEditText.setText("");
  318. }
  319. }
  320. }
  321. }) {
  322. @Override
  323. protected Map<String, String> getParams() throws AuthFailureError {
  324. Map<String, String> params = new HashMap<String, String>();
  325. params.put("dsl", smtDsl);
  326. params.put("deviceLineMake", finalDeviceLineMake);
  327. return params;
  328. }
  329. @Override
  330. public Map<String, String> getHeaders() throws AuthFailureError {
  331. return VolleyUtil.getVolleyUtil().setCookies();
  332. }
  333. };
  334. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  335. mStringRequest.setTag(TAG + "loading");
  336. PdaApplication.mRequestQueue.add(mStringRequest);
  337. }
  338. @Override
  339. protected void initDatas() {
  340. //界面配置
  341. //->Actionbar
  342. ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_feederchange_smt);
  343. ((Button) (getActivity().findViewById(R.id.btn_actionbar_right))).setVisibility(View.GONE);
  344. mSmtLocationCache = SharedPreUtil.getString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, null);
  345. if (mLineInfoBean != null) {
  346. mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE());
  347. mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面");
  348. mMacodeTextView.setText(mLineInfoBean.getDL_MACODE());
  349. }
  350. }
  351. @Override
  352. public void onDestroy() {
  353. VolleyUtil.distoryVolley();
  354. super.onDestroy();
  355. }
  356. @Override
  357. public void onDestroyView() {
  358. CommonUtil.closeKeybord(mCollectEditText, mActivity);
  359. super.onDestroyView();
  360. }
  361. String code;
  362. //采集栏enter事件、按钮点击事件
  363. private void disposeOnClick() {
  364. //->获取输入框文字内容
  365. // code = etCollect.getText().toString().trim();
  366. if (code.equals("") || code == null) {
  367. return;
  368. }
  369. Log.e("SCSMT:code", "" + code);
  370. //获取站位\料卷\飞达编号
  371. String locationStr = tvLocation.getText().toString().trim();
  372. String barcodeStr = tvBarcode.getText().toString().trim();
  373. String qtyStr = tvRemainqty.getText().toString().trim();
  374. //->if(msl_location为空),如果站位为null,或者是新一轮采集
  375. if (isAgain || locationStr.equals("") || locationStr == null) {
  376. disposeOnClickLocation();
  377. }
  378. //->else if(msl_barcode为空) 如果站位不为空,料卷号为空
  379. else if (barcodeStr.equals("") || barcodeStr == null) {
  380. disposeOnClickBarcode();
  381. }
  382. }
  383. //按钮点击事件:当Location为空的时候
  384. private void disposeOnClickLocation() {
  385. Log.e("SMTChildInOnclick", "站位为空");
  386. String tmpLocation = null;
  387. String title = null;
  388. String content = null;
  389. int color = 0;
  390. isAgain = false;
  391. //信息框都清空
  392. tvBarcode.setText("");
  393. tvRemainqty.setText("");
  394. try {
  395. //比对smtLocation
  396. for (int i = 0; i < smtLocation.length(); i++) {
  397. JSONObject tmpJson = smtLocation.getJSONObject(i);
  398. tmpLocation = tmpJson.getString("psl_location").trim();
  399. //如果匹配
  400. if (tmpLocation.equals(code)) {
  401. //显示在站位输入框,添加数据项
  402. tvLocation.setText(tmpLocation);
  403. mslChange = new JSONObject();
  404. mslChange.put("msl_location", code);
  405. mslChange.put("msl_prodcode", tmpJson.getString("psl_prodcode").trim());
  406. mslChange.put("msl_repcode", tmpJson.getString("psl_repcode").trim());
  407. mslChange.put("psl_id", tmpJson.getString("psl_id").trim());
  408. Log.e("SMTCHILD", mslChange.toString());
  409. //更改etCollect的Hint
  410. setEtHint();
  411. //提示框中显示信息
  412. title = "站位采集成功";
  413. content = "站位采集成功,请采集物料" + mslChange.get("msl_prodcode") + "的条码";
  414. color = getResources().getColor(R.color.green);
  415. setNotice(title, content, color);
  416. break;
  417. }
  418. //如果不匹配
  419. else {
  420. title = "错误";
  421. content = getString(R.string.notice_smtchild_barcode);
  422. color = getResources().getColor(R.color.text_error);
  423. }
  424. }
  425. } catch (JSONException e) {
  426. e.printStackTrace();
  427. }
  428. setNotice(title, content, color);
  429. }
  430. //按钮点击事件:当料卷号为空的时候
  431. private void disposeOnClickBarcode() {
  432. //请求判断料卷编号是否正确,获取料卷数量
  433. JSONObject paramJson = new JSONObject();
  434. try {
  435. paramJson.put("bar_code", code);
  436. paramJson.put("prod_code", mslChange.getString("msl_prodcode"));
  437. paramJson.put("rep_code", mslChange.getString("msl_repcode"));
  438. } catch (JSONException e) {
  439. e.printStackTrace();
  440. }
  441. showLoadingView();
  442. requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_BARREMAIN;
  443. VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMT_BARREMAIN_APPLY, VolleyUtil.METHOD_POST,
  444. requestType, paramJson);
  445. }
  446. //扫描料卷编号成功
  447. String mslBarcode = null, mslRemainQty = null;
  448. private void disposeBarcodeSuccess(JSONObject resultJson) {
  449. String title, content;
  450. int color;
  451. JSONObject tmpJson, msgJson;
  452. try {
  453. //tmpJson = new JSONObject(resultJson);
  454. tmpJson = resultJson;
  455. msgJson = tmpJson.getJSONObject("message");
  456. //将message中的值赋值给变量msl中的值
  457. mslChange.put("msl_barcode", msgJson.getString("bar_code"));
  458. mslChange.put("msl_prodcode", msgJson.get("bar_prodcode"));
  459. mslChange.put("msl_remainqty", msgJson.get("bar_remain"));
  460. mslBarcode = code;
  461. mslRemainQty = msgJson.getString("bar_remain");
  462. //料卷编号和数量输入框显示对应的值,清空采集栏中的值
  463. tvBarcode.setText(mslBarcode);
  464. tvRemainqty.setText(mslRemainQty);
  465. //发送接料请求至服务器进行换料操作
  466. changeMaterial();
  467. } catch (JSONException e) {
  468. e.printStackTrace();
  469. }
  470. }
  471. //换料操作
  472. private void changeMaterial() {
  473. try {
  474. String mcCode = makeCraft.getString("mc_code");
  475. int mcId = makeCraft.getInt("mc_id");
  476. String mcDevcode = makeCraft.getString("mc_devcode");
  477. String mcSourcecode = makeCraft.getString("mc_sourcecode");
  478. mslChange.put("mc_code", mcCode);
  479. mslChange.put("mc_id", "" + mcId);
  480. mslChange.put("mc_devcode", mcDevcode);
  481. mslChange.put("mc_sourcecode", mcSourcecode);
  482. } catch (JSONException e) {
  483. e.printStackTrace();
  484. }
  485. requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_CHANGE;
  486. showLoadingView();
  487. VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMTCHANGE_APPLY, VolleyUtil.METHOD_POST,
  488. requestType, mslChange);
  489. }
  490. //Volley请求换料成功
  491. private void disposeVolleyJoint(JSONObject resultJson) {
  492. JSONObject msgJson;
  493. String productStr = "无", locationStr = "无", fecodeStr = "无", barcodeStr = "无", qtyStr = "无";
  494. try {
  495. msgJson = resultJson.getJSONObject("message");
  496. productStr = msgJson.getString("msl_prodcode");
  497. locationStr = msgJson.getString("msl_location");
  498. fecodeStr = msgJson.getString("msl_fecode");
  499. barcodeStr = msgJson.getString("msl_barcode");
  500. qtyStr = msgJson.getString("msl_remainqty");
  501. } catch (JSONException e) {
  502. e.printStackTrace();
  503. }
  504. //信息提示框
  505. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  506. tvMsgNotice.setText(getString(R.string.notice_smtchange_success));
  507. tvMsgLocation.setText("物料号:" + productStr);
  508. tvMsgProdcode.setText("站位:" + locationStr);
  509. tvMsgBarcode.setText("飞达:" + fecodeStr);
  510. tvMsgQuantity.setText("料卷号:" + barcodeStr);
  511. tvMsgSpec.setText("数量:" + qtyStr);
  512. //新一轮采集
  513. mslChange = null;
  514. isAgain = true;
  515. setEtHint();
  516. }
  517. /*=================================Volley Handler====================================*/
  518. Handler volleyHandler = new Handler() {
  519. @Override
  520. public void handleMessage(Message msg) {
  521. switch (msg.what) {
  522. case VolleyUtil.SUCCESS_SUCCESS:
  523. disposeVolleySuccess(msg);
  524. break;
  525. case VolleyUtil.FAILED_FAILED:
  526. disposeVolleyFailed(msg);
  527. break;
  528. }
  529. progressDialog.dismiss();
  530. }
  531. };
  532. //Volley响应成功
  533. private void disposeVolleySuccess(Message msg) {
  534. JSONObject tmpJson;
  535. switch (requestType) {
  536. //页面加载:获取详细信息
  537. case VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_DETAIL:
  538. disposeVolleyDetail(msg);
  539. break;
  540. //页面加载:获取详细信息
  541. case VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_BARREMAIN:
  542. tmpJson = (JSONObject) msg.obj;
  543. disposeBarcodeSuccess(tmpJson);
  544. break;
  545. //页面加载:获取详细信息
  546. case VolleyUtil.FRAGMENT_SCMAKE_SMTCHANGE_CHANGE:
  547. tmpJson = (JSONObject) msg.obj;
  548. disposeVolleyJoint(tmpJson);
  549. break;
  550. }
  551. }
  552. //Volley响应失败
  553. private void disposeVolleyFailed(Message msg) {
  554. String noticeMsg = (String) msg.obj;
  555. String title = "失败";
  556. String content = noticeMsg;
  557. setNotice(title, content, getResources().getColor(R.color.red));
  558. }
  559. //Volley请求页面详细数据
  560. private void disposeVolleyDetail(Message msg) {
  561. JSONObject tmpJson = (JSONObject) msg.obj;
  562. try {
  563. boolean isNull = tmpJson.isNull("message");
  564. //如果服务器没有返回值
  565. if (isNull) {
  566. disposeNullServerData();
  567. } else {
  568. smtLocation = tmpJson.getJSONArray("message");
  569. Log.e(TAG, "smtLocation:" + smtLocation.toString());
  570. }
  571. } catch (JSONException e) {
  572. e.printStackTrace();
  573. }
  574. }
  575. /*=================================公用方法===========================================*/
  576. /**
  577. * 设置采集框提示信息
  578. */
  579. @Override
  580. public void setEtHint() {
  581. //获取站位\料卷\飞达编号
  582. String locationStr = tvLocation.getText().toString().trim();
  583. String barcodeStr = tvBarcode.getText().toString().trim();
  584. String remainQty = tvRemainqty.getText().toString().trim();
  585. // //->if(msl_location为空),如果站位为null
  586. // if (isAgain || locationStr.equals("") || locationStr == null) {
  587. // etCollect.setHint(R.string.hint_smtchild_location);
  588. // }
  589. // //->else if(msl_barcode为空) 如果站位不为空,料卷号为空
  590. // else if (barcodeStr.equals("") || barcodeStr == null) {
  591. // etCollect.setHint(R.string.hint_smtchild_barcode);
  592. // }
  593. // //->else if(msl_remainqty为空) 如果数量为空
  594. // else if (remainQty.equals("") || remainQty == null) {
  595. // etCollect.setHint(R.string.hint_smtchild_barcode);
  596. // }
  597. }
  598. /**
  599. * 隐藏采集界面
  600. */
  601. private void disposeNullServerData() {
  602. rlCollect.setVisibility(View.GONE);
  603. String title = getString(R.string.notice_smtin_nulldata);
  604. setNotice(title, "", getResources().getColor(R.color.text_error));
  605. }
  606. /**
  607. * 隐藏键盘
  608. */
  609. private void hideKeyboard(final EditText view) {
  610. InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
  611. //获取键盘管理对象
  612. inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
  613. }
  614. /**
  615. * 显示loadingView
  616. */
  617. private void showLoadingView() {
  618. if (!progressDialog.isShowing()) {
  619. progressDialog.show();
  620. }
  621. }
  622. /**
  623. * 设置提示信息
  624. */
  625. private void setNotice(String title, String content, int pid) {
  626. tvMsgNotice.setText(title);
  627. tvMsgNotice.setTextColor(pid);
  628. tvMsgLocation.setText(content);
  629. //清除其它信息
  630. tvMsgSpec.setText("");
  631. tvMsgBarcode.setText("");
  632. tvMsgLocation.setText("");
  633. tvMsgQuantity.setText("");
  634. }
  635. /**
  636. * 获取输入框焦点
  637. */
  638. private void editTextGetFocus(EditText editText) {
  639. editText.setFocusable(true);
  640. editText.setFocusableInTouchMode(true);
  641. editText.setEnabled(true);
  642. editText.setClickable(true);
  643. editText.requestFocus();
  644. }
  645. @Override
  646. public void onClick(View v) {
  647. disposeOnClick();
  648. }
  649. @Override
  650. public boolean onKeyDown(int keyCode, KeyEvent event) {
  651. if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  652. if (progressDialog != null && progressDialog.isShowing()) {
  653. // loadingView.dismiss();
  654. // VolleyUtil.distoryVolley();
  655. return true;
  656. }
  657. }
  658. return false;
  659. }
  660. @Override
  661. public boolean onFragmentBackPressed() {
  662. return false;
  663. }
  664. }