SCSMTInFragment.java 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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.SpannableString;
  6. import android.text.TextUtils;
  7. import android.util.Log;
  8. import android.view.KeyEvent;
  9. import android.view.View;
  10. import android.view.inputmethod.EditorInfo;
  11. import android.view.inputmethod.InputMethodManager;
  12. import android.widget.Button;
  13. import android.widget.EditText;
  14. import android.widget.RelativeLayout;
  15. import android.widget.TextView;
  16. import com.alibaba.fastjson.JSON;
  17. import com.android.volley.AuthFailureError;
  18. import com.android.volley.DefaultRetryPolicy;
  19. import com.android.volley.Request;
  20. import com.android.volley.Response;
  21. import com.android.volley.VolleyError;
  22. import com.android.volley.toolbox.StringRequest;
  23. import com.uas.uaspda.R;
  24. import com.uas.uaspda.application.PdaApplication;
  25. import com.uas.uaspda.bean.LineInfoBean;
  26. import com.uas.uaspda.bean.SmtDslBean;
  27. import com.uas.uaspda.global.GloableParams;
  28. import com.uas.uaspda.tools.SharedPreUtil;
  29. import com.uas.uaspda.tools.VolleyUtil;
  30. import com.uas.uaspda.util.CommonUtil;
  31. import com.uas.uaspda.util.Constants;
  32. import com.uas.uaspda.util.JsonUtils;
  33. import com.uas.uaspda.util.LogUtil;
  34. import com.uas.uaspda.util.SoundUtil;
  35. import com.uas.uaspda.view.ClearableEditText;
  36. import com.uas.uaspda.view.TextViewWithButton;
  37. import org.json.JSONArray;
  38. import org.json.JSONException;
  39. import org.json.JSONObject;
  40. import java.util.HashMap;
  41. import java.util.Map;
  42. /**
  43. * SMT上料:上料子页面
  44. * modify:2017-05-15
  45. */
  46. public class SCSMTInFragment extends BaseFragment implements View.OnClickListener, TextViewWithButton.TvHintHelper {
  47. private TextViewWithButton tvLocation, tvBarcode, tvRemainqty, tvFecode, mLocationTextView;
  48. private TextView tvMsgNotice, tvMsgLocation, tvMsgProdcode, tvMsgBarcode, tvMsgQuantity, tvMsgSpec;
  49. private RelativeLayout rlCollect;
  50. private JSONArray smtLocation;
  51. private JSONObject makeCraft;
  52. private TextView mLinecodeTextView, mTableTextView, mMacodeTextView;
  53. private ClearableEditText mCollectEditText;
  54. int requestType = -1;
  55. private Button btnCollect;
  56. private LineInfoBean mLineInfoBean;
  57. private String mSmtLocationCache;
  58. private SmtDslBean mSmtDslBean = new SmtDslBean();
  59. private StringRequest mStringRequest;
  60. private String mNoticeStr = "";
  61. @Override
  62. protected int getLayout() {
  63. return R.layout.fragment_scmake_smtfeederchild_in;
  64. }
  65. @Override
  66. protected void initViews() {
  67. //获取组件
  68. //->采集信息
  69. btnCollect = (Button) root.findViewById(R.id.btn_collect_smtchildin);
  70. tvLocation = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_location_smtchildin);
  71. tvFecode = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_fecode_smtchildin);
  72. tvBarcode = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_barcode_smtchildin);
  73. tvRemainqty = (TextViewWithButton) root.findViewById(R.id.tv_innernotice_remainqty_smtchildin);
  74. rlCollect = (RelativeLayout) root.findViewById(R.id.rl_innernotice_smtchildin);
  75. mLocationTextView = (TextViewWithButton) root.findViewById(R.id.smt_feeding_in_location_tv);
  76. mLinecodeTextView = (TextView) root.findViewById(R.id.smt_feeding_in_linecode_tv);
  77. mTableTextView = (TextView) root.findViewById(R.id.smt_feeding_in_table_tv);
  78. mMacodeTextView = (TextView) root.findViewById(R.id.smt_feeding_in_macode_tv);
  79. mCollectEditText = (ClearableEditText) root.findViewById(R.id.smt_feeding_in_collect_et);
  80. mCollectEditText.requestFocus();
  81. //->提示信息
  82. tvMsgNotice = (TextView) root.findViewById(R.id.tv_innernotice_msgtitle_scmake);
  83. tvMsgProdcode = (TextView) root.findViewById(R.id.tv_innernotice_1_scmake);
  84. tvMsgLocation = (TextView) root.findViewById(R.id.tv_innernotice_2_scmake);
  85. tvMsgBarcode = (TextView) root.findViewById(R.id.tv_innernotice_3_scmake);
  86. tvMsgQuantity = (TextView) root.findViewById(R.id.tv_innernotice_4_scmake);
  87. tvMsgSpec = (TextView) root.findViewById(R.id.tv_innernotice_5_scmake);
  88. //接口回调
  89. VolleyUtil.setVolleyHandler(handler);
  90. mLineInfoBean = (LineInfoBean) PdaApplication.getDataCacheFromMap(Constants.FLAG.SMT_DEVICE_LINE_CACHE);
  91. // JSONObject paramJson = new JSONObject();
  92. // try {
  93. // makeCraft = new JSONObject(makeCraftStr);
  94. // String ps_id = makeCraft.get("ps_id").toString();
  95. // String mcjob = makeCraft.get("mc_prodcode").toString();
  96. // paramJson.put("ps_id", ps_id);
  97. // paramJson.put("prodcode", mcjob);
  98. // } catch (JSONException e) {
  99. // e.printStackTrace();
  100. // }
  101. // Log.e("SMTINCHILD", "makecraft" + makeCraft.toString());
  102. // //获取网络数据
  103. // showLoadingView();
  104. // requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL;
  105. // VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMTDETAIL_APPLY, VolleyUtil.METHOD_POST,
  106. // VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL, paramJson);
  107. }
  108. @Override
  109. protected void initEvents() {
  110. tvLocation.setTvHintHelper(this);
  111. tvBarcode.setTvHintHelper(this);
  112. tvRemainqty.setTvHintHelper(this);
  113. tvFecode.setTvHintHelper(this);
  114. mLocationTextView.setTvHintHelper(this);
  115. btnCollect.setOnClickListener(this);
  116. mCollectEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
  117. @Override
  118. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  119. String collect = mCollectEditText.getText().toString().trim();
  120. if (!TextUtils.isEmpty(collect)) {
  121. if (actionId == EditorInfo.IME_ACTION_DONE
  122. || actionId == EditorInfo.IME_ACTION_SEND
  123. || (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
  124. confirmEvent(collect);
  125. return true;
  126. }
  127. }
  128. return false;
  129. }
  130. });
  131. mLocationTextView.setOnTextClearListener(new TextViewWithButton.OnTextClearListener() {
  132. @Override
  133. public void onTextClear() {
  134. mCollectEditText.setHint("请录入站位编号");
  135. mCollectEditText.setText("");
  136. // tvMsgNotice.setText("");
  137. // tvMsgProdcode.setText("");
  138. // tvMsgLocation.setText("");
  139. // tvMsgBarcode.setText("");
  140. // tvMsgQuantity.setText("");
  141. // tvMsgSpec.setText("");
  142. }
  143. });
  144. }
  145. private void confirmEvent(String collect) {
  146. String location = mLocationTextView.getText().toString().trim();
  147. if (TextUtils.isEmpty(location)) {
  148. locationCheck(collect);
  149. } else {
  150. /* mSmtDslBean.setDsl_barcode(collect);
  151. String dsl_repcode = mSmtDslBean.getDsl_repcode();
  152. if (!TextUtils.isEmpty(dsl_repcode)) {
  153. boolean isExist = false;
  154. String[] repcodes = dsl_repcode.split(",");
  155. for (int j = 0; j < repcodes.length; j++) {
  156. String repcode = repcodes[j];
  157. if (repcode != null && repcode.equals(collect)) {
  158. isExist = true;
  159. }
  160. }
  161. if (isExist) {
  162. } else {
  163. //上料操作
  164. feedLoading();
  165. }
  166. } else {*/
  167. mSmtDslBean.setDsl_fecode(collect);
  168. feedLoading();
  169. // }
  170. }
  171. }
  172. /**
  173. * 站位本地校验
  174. *
  175. * @param collect 采集框采集内容
  176. */
  177. private void locationCheck(String collect) {
  178. tvMsgProdcode.setText("");
  179. tvMsgLocation.setText("");
  180. tvMsgBarcode.setText("");
  181. tvMsgQuantity.setText("");
  182. tvMsgSpec.setText("");
  183. if (!TextUtils.isEmpty(mSmtLocationCache)) {
  184. try {
  185. JSONArray locationArray = new JSONArray(mSmtLocationCache);
  186. boolean isExist = false;
  187. for (int i = 0; i < locationArray.length(); i++) {
  188. JSONObject locationObject = locationArray.getJSONObject(i);
  189. if (collect.equals(JsonUtils.optStringNotNull(locationObject, "PSL_LOCATION"))) {
  190. isExist = true;
  191. mLocationTextView.setText(collect);
  192. mCollectEditText.setText("");
  193. String psl_prodcode = JsonUtils.optStringNotNull(locationObject, "PSL_PRODCODE");
  194. String psl_repcode = JsonUtils.optStringNotNull(locationObject, "PSL_REPCODE");
  195. mSmtDslBean = new SmtDslBean();
  196. mSmtDslBean.setDsl_location(collect);
  197. mSmtDslBean.setDsl_prodcode(psl_prodcode);
  198. mCollectEditText.setHint("请录入飞达编号");
  199. if (!TextUtils.isEmpty(psl_repcode)) {
  200. // if (TextUtils.isEmpty(psl_repcode) || "null".equals(psl_repcode))
  201. // tvMsgNotice.setText("站位采集成功,请采集首选料[" + psl_prodcode + "]的料卷编号");
  202. // else
  203. String[] repcodes = psl_repcode.split(",");
  204. String notice = "站位采集成功,请采集物料\n";
  205. for (int j = 0; j < repcodes.length; j++) {
  206. String repcode = repcodes[j];
  207. notice = notice + repcode + "\n";
  208. }
  209. notice = notice + "的料卷编号/物料编号";
  210. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  211. tvMsgNotice.setText(notice);
  212. } else if (!TextUtils.isEmpty(psl_prodcode)) {
  213. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  214. tvMsgNotice.setText("站位采集成功,请采集物料\n" + psl_prodcode + "\n的飞达编号");
  215. } else {
  216. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  217. tvMsgNotice.setText("站位采集成功,物料编号获取失败");
  218. }
  219. }
  220. }
  221. if (!isExist) {
  222. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  223. String notice = "站位编号错误\n" + mNoticeStr;
  224. SpannableString spannableString = CommonUtil.spanString(notice, mActivity, "站位编号错误\n".length(), notice.length(), R.color.green);
  225. tvMsgNotice.setText(spannableString);
  226. CommonUtil.makeNotice();
  227. mCollectEditText.setText("");
  228. }
  229. } catch (JSONException e) {
  230. e.printStackTrace();
  231. }
  232. } else {
  233. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  234. String notice = "站位编号错误\n" + mNoticeStr;
  235. SpannableString spannableString = CommonUtil.spanString(notice, mActivity, "站位编号错误\n".length(), notice.length(), R.color.green);
  236. tvMsgNotice.setText(spannableString);
  237. CommonUtil.makeNotice();
  238. mCollectEditText.setText("");
  239. }
  240. }
  241. /**
  242. * 站位上料
  243. */
  244. private void feedLoading() {
  245. progressDialog.show();
  246. PdaApplication.mRequestQueue.cancelAll(TAG + "loading");
  247. final String smtDsl = JSON.toJSONString(mSmtDslBean);
  248. String deviceLineMake = "";
  249. if (mLineInfoBean != null)
  250. deviceLineMake = JSON.toJSONString(mLineInfoBean);
  251. final String finalDeviceLineMake = deviceLineMake;
  252. mStringRequest = new StringRequest(Request.Method.POST, GloableParams.ADDRESS_SMT_LOADING,
  253. new Response.Listener<String>() {
  254. @Override
  255. public void onResponse(String s) {
  256. try {
  257. LogUtil.i("inloading", s);
  258. if (progressDialog.isShowing())
  259. progressDialog.dismiss();
  260. JSONObject jsonObject = new JSONObject(s);
  261. JSONObject dataObject = jsonObject.optJSONObject("data");
  262. if (dataObject != null) {
  263. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  264. tvMsgNotice.setText("上料成功");
  265. tvMsgProdcode.setText("料号:" + JsonUtils.optStringNotNull(dataObject, "DSL_PRODCODE"));
  266. tvMsgLocation.setText("位号:" + JsonUtils.optStringNotNull(dataObject, "DSL_LOCATION"));
  267. tvMsgBarcode.setText("料卷号:" + JsonUtils.optStringNotNull(dataObject, "DSL_BARCODE"));
  268. tvMsgQuantity.setText("数量:" + CommonUtil.doubleFormat(JsonUtils.optDoubleNotNull(dataObject, "DSL_REMAINQTY")));
  269. double notCheckCount = JsonUtils.optDoubleNotNull(dataObject, "NotFeedCount");
  270. String notice = "飞达规格:" + JsonUtils.optStringNotNull(dataObject, "DSL_FESPEC");
  271. if (notCheckCount == 0) {
  272. notice = notice + "\n\n上料已完成";
  273. mNoticeStr = "上料已完成";
  274. SoundUtil.play(SoundUtil.SOUND_CERES);
  275. tvMsgSpec.setText(notice);
  276. } else {
  277. String buffer = notice;
  278. notice = notice + "\n\n未上料站位"
  279. + CommonUtil.doubleFormat(notCheckCount) + "条";
  280. String noticeStr = "未上料站位" + CommonUtil.doubleFormat(notCheckCount) + "条";
  281. JSONArray notFeedArray = dataObject.optJSONArray("NotFeedLocation");
  282. if (notFeedArray != null && notFeedArray.length() != 0) {
  283. notice = notice + "\n站位:";
  284. noticeStr = noticeStr + "\n站位:";
  285. for (int i = 0; i < notFeedArray.length(); i++) {
  286. JSONObject notCheckObject = notFeedArray.optJSONObject(i);
  287. if (notCheckObject != null) {
  288. String psl_location = JsonUtils.optStringNotNull(notCheckObject, "PSL_LOCATION");
  289. notice = notice + psl_location + ",";
  290. noticeStr = noticeStr + psl_location + ",";
  291. }
  292. }
  293. notice = notice.substring(0, notice.length() - 1);
  294. noticeStr = noticeStr.substring(0, noticeStr.length() - 1);
  295. }
  296. mNoticeStr = noticeStr;
  297. SpannableString spannableString = CommonUtil.spanString(notice, mActivity, (buffer + "\n\n未上料站位").length(), (buffer + "\n\n未上料站位").length() + CommonUtil.doubleFormat(notCheckCount).length(), R.color.blue_800);
  298. tvMsgSpec.setText(spannableString);
  299. }
  300. mLocationTextView.setText("");
  301. mCollectEditText.setText("");
  302. mSmtDslBean = new SmtDslBean();
  303. mCollectEditText.setHint("请录入站位编号");
  304. }
  305. } catch (JSONException e) {
  306. e.printStackTrace();
  307. }
  308. }
  309. },
  310. new Response.ErrorListener() {
  311. @Override
  312. public void onErrorResponse(VolleyError volleyError) {
  313. if (progressDialog.isShowing())
  314. progressDialog.dismiss();
  315. String errorToast = CommonUtil.showErrorToast(volleyError, false);
  316. if (errorToast != null) {
  317. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  318. String errorNotice = errorToast + "\n" + mNoticeStr;
  319. SpannableString spannableString = CommonUtil.spanString(errorNotice, mActivity, (errorToast + "\n").length(), errorNotice.length(), R.color.green);
  320. tvMsgNotice.setText(spannableString);
  321. if (errorToast.contains("站位已经有在线料卷号")) {
  322. mLocationTextView.setText("");
  323. mCollectEditText.setText("");
  324. } else {
  325. mCollectEditText.setText("");
  326. }
  327. }
  328. }
  329. }) {
  330. @Override
  331. protected Map<String, String> getParams() throws AuthFailureError {
  332. Map<String, String> params = new HashMap<String, String>();
  333. params.put("dsl", smtDsl);
  334. params.put("deviceLineMake", finalDeviceLineMake);
  335. return params;
  336. }
  337. @Override
  338. public Map<String, String> getHeaders() throws AuthFailureError {
  339. return VolleyUtil.getVolleyUtil().setCookies();
  340. }
  341. };
  342. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  343. mStringRequest.setTag(TAG + "loading");
  344. PdaApplication.mRequestQueue.add(mStringRequest);
  345. }
  346. @Override
  347. protected void initDatas() {
  348. //配置界面
  349. ((TextView) (getActivity().findViewById(R.id.tv_actionbar_withback))).setText(R.string.title_feederin_smt);
  350. mSmtLocationCache = SharedPreUtil.getString(mActivity, Constants.FLAG.SMT_LOCATION_CACHE, null);
  351. if (mSmtLocationCache != null) {
  352. Log.d("smtLocation", mSmtLocationCache);
  353. }
  354. if (mLineInfoBean != null) {
  355. mLinecodeTextView.setText(mLineInfoBean.getDL_LINECODE());
  356. mTableTextView.setText(mLineInfoBean.getDL_TABLE() + "面");
  357. mMacodeTextView.setText(mLineInfoBean.getDL_MACODE());
  358. }
  359. getUnloadingLocation();
  360. }
  361. /**
  362. * 获取未上料站位
  363. */
  364. private void getUnloadingLocation() {
  365. progressDialog.show();
  366. String url = GloableParams.ADDRESS_SMT_GET_UNLOADING_LOCATION + "?linecode=" + (mLineInfoBean == null ? "" : mLineInfoBean.getDL_LINECODE());
  367. PdaApplication.mRequestQueue.cancelAll(TAG + "unloading");
  368. mStringRequest = new StringRequest(Request.Method.GET, url,
  369. new Response.Listener<String>() {
  370. @Override
  371. public void onResponse(String s) {
  372. try {
  373. if (progressDialog.isShowing())
  374. progressDialog.dismiss();
  375. JSONObject resultObject = new JSONObject(s);
  376. JSONObject dataObject = resultObject.optJSONObject("data");
  377. if (dataObject != null) {
  378. double NotFeedCount = JsonUtils.optDoubleNotNull(dataObject, "NotFeedCount");
  379. String notice = "";
  380. if (NotFeedCount == 0) {
  381. notice = notice + "上料已完成";
  382. mNoticeStr = notice;
  383. SoundUtil.play(SoundUtil.SOUND_CERES);
  384. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  385. tvMsgNotice.setText(notice);
  386. } else {
  387. notice = notice + "未上料站位"
  388. + CommonUtil.doubleFormat(NotFeedCount) + "条";
  389. JSONArray notFeedArray = dataObject.optJSONArray("NotFeedLocation");
  390. if (notFeedArray != null && notFeedArray.length() != 0) {
  391. notice = notice + "\n站位:";
  392. for (int i = 0; i < notFeedArray.length(); i++) {
  393. JSONObject notCheckObject = notFeedArray.optJSONObject(i);
  394. if (notCheckObject != null) {
  395. String psl_location = JsonUtils.optStringNotNull(notCheckObject, "PSL_LOCATION");
  396. notice = notice + psl_location + ",";
  397. }
  398. }
  399. notice = notice.substring(0, notice.length() - 1);
  400. }
  401. mNoticeStr = notice;
  402. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  403. SpannableString spannableString = CommonUtil.spanString(notice, mActivity, 5, 5 + CommonUtil.doubleFormat(NotFeedCount).length(), R.color.blue_800);
  404. tvMsgNotice.setText(spannableString);
  405. }
  406. }
  407. } catch (Exception e) {
  408. }
  409. }
  410. },
  411. new Response.ErrorListener() {
  412. @Override
  413. public void onErrorResponse(VolleyError volleyError) {
  414. if (progressDialog.isShowing())
  415. progressDialog.dismiss();
  416. String errorToast = CommonUtil.showErrorToast(volleyError, false);
  417. tvMsgNotice.setTextColor(getResources().getColor(R.color.red));
  418. tvMsgNotice.setText(errorToast);
  419. }
  420. }) {
  421. @Override
  422. public Map<String, String> getHeaders() throws AuthFailureError {
  423. return VolleyUtil.getVolleyUtil().setCookies();
  424. }
  425. };
  426. mStringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 0, 1f));
  427. mStringRequest.setTag(TAG + "unloading");
  428. PdaApplication.mRequestQueue.add(mStringRequest);
  429. }
  430. @Override
  431. public void onDestroy() {
  432. VolleyUtil.distoryVolley();
  433. super.onDestroy();
  434. }
  435. @Override
  436. public void onDestroyView() {
  437. CommonUtil.closeKeybord(mCollectEditText, mActivity);
  438. super.onDestroyView();
  439. }
  440. //按钮点击事件:当Location为空的时候
  441. private void disposeOnClickLocation() {
  442. Log.e("SMTChildInOnclick", "站位为空");
  443. String tmpLocation = null;
  444. String title = null;
  445. String content = null;
  446. int color = 0;
  447. isAgain = false;
  448. //信息框都清空
  449. tvBarcode.setText("");
  450. tvRemainqty.setText("");
  451. tvFecode.setText("");
  452. try {
  453. //比对smtLocation
  454. for (int i = 0; i < smtLocation.length(); i++) {
  455. JSONObject tmpJson = smtLocation.getJSONObject(i);
  456. tmpLocation = tmpJson.getString("psl_location").trim();
  457. //如果匹配
  458. if (tmpLocation.equals(code)) {
  459. Log.e("SMTCHILD", "匹配");
  460. //显示在站位输入框,添加数据项
  461. tvLocation.setText(tmpLocation);
  462. msl = new JSONObject();
  463. msl.put("msl_location", code);
  464. msl.put("msl_prodcode", tmpJson.getString("psl_prodcode").trim());
  465. msl.put("msl_repcode", tmpJson.getString("psl_repcode").trim());
  466. // msl.put("msl_repcode","无");
  467. msl.put("psl_id", tmpJson.getString("psl_id").trim());
  468. msl.put("msl_fespec", tmpJson.getString("psl_feeder").trim());
  469. //msl = smtLocation.getJSONObject(i);
  470. Log.e("SMTCHILD", msl.toString());
  471. //更改etCollect的Hint
  472. setEtHint();
  473. //提示框中显示信息
  474. title = "站位采集成功";
  475. content = "站位采集成功,请采集物料" + msl.get("msl_prodcode") + "的条码";
  476. color = getResources().getColor(R.color.green);
  477. setNotice(title, content, color);
  478. break;
  479. }
  480. //如果不匹配
  481. else {
  482. Log.e("SMTCHILD", "不匹配");
  483. title = "错误";
  484. content = getString(R.string.notice_smtchild_barcode);
  485. color = getResources().getColor(R.color.text_error);
  486. }
  487. }
  488. } catch (JSONException e) {
  489. e.printStackTrace();
  490. }
  491. setNotice(title, content, color);
  492. }
  493. //按钮点击事件:当料卷号为空的时候
  494. private void disposeOnClickBarcode() {
  495. Log.e("SMTChildInOnclick", "料卷为空");
  496. //请求判断料卷编号是否正确,获取料卷数量
  497. JSONObject paramJson = new JSONObject();
  498. try {
  499. paramJson.put("bar_code", code);
  500. paramJson.put("prod_code", msl.getString("msl_prodcode"));
  501. paramJson.put("rep_code", msl.getString("msl_repcode"));
  502. } catch (JSONException e) {
  503. e.printStackTrace();
  504. }
  505. showLoadingView();
  506. requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN;
  507. VolleyUtil.getVolleyUtil().requestJsonObject(getActivity(), GloableParams.ADDRESS_SMT_BARREMAIN_APPLY, VolleyUtil.METHOD_POST,
  508. VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN, paramJson);
  509. }
  510. //按钮点击事件:当飞达编号为空时
  511. private void disposeOnClickFecode() {
  512. //获取飞达编号
  513. String fecodeStr = tvFecode.getText().toString().trim();
  514. //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时
  515. if (fecodeStr.equals("") || fecodeStr == null) {
  516. //tvFecode.setText(code);
  517. try {
  518. msl.put("msl_fecode", code);
  519. } catch (JSONException e) {
  520. e.printStackTrace();
  521. }
  522. //上料操作
  523. requestType = VolleyUtil.FRAGMENT_SCMAKE_SMTIN_UPLOAD;
  524. showLoadingView();
  525. VolleyUtil.getVolleyUtil().requestSMTInUpLoad(getActivity(), GloableParams.ADDRESS_SMTIN_UPLOAD_APPLY, VolleyUtil.METHOD_POST,
  526. requestType, msl.toString(), makeCraft.toString());
  527. }
  528. }
  529. //扫描料卷编号成功
  530. String mslBarcode = null, mslRemainQty = null;
  531. private void disposeBarcodeSuccess(String result) {
  532. String title, content;
  533. int color;
  534. JSONObject tmpJson, msgJson;
  535. try {
  536. tmpJson = new JSONObject(result);
  537. msgJson = tmpJson.getJSONObject("message");
  538. //将message中的值赋值给变量msl中的值
  539. msl.put("msl_barcode", msgJson.getString("bar_code"));
  540. msl.put("msl_prodcode", msgJson.get("bar_prodcode"));
  541. msl.put("msl_remainqty", msgJson.get("bar_remain"));
  542. mslBarcode = code;
  543. mslRemainQty = msgJson.getString("bar_remain");
  544. //料卷编号和数量输入框显示对应的值,清空采集栏中的值
  545. tvBarcode.setText(mslBarcode);
  546. tvRemainqty.setText(mslRemainQty);
  547. //将采集栏中的提示文字修改为“请录入飞达编号”
  548. setEtHint();
  549. //清空提示栏信息
  550. title = "料卷采集成功";
  551. content = "请采集物料" + msl.get("msl_prodcode") + "的飞达编号";
  552. color = getResources().getColor(R.color.green);
  553. setNotice(title, content, color);
  554. } catch (JSONException e) {
  555. e.printStackTrace();
  556. }
  557. }
  558. //上料成功
  559. private void disposeUpLoadSuccess(String result) {
  560. JSONObject msgJson;
  561. String productStr = "无", locationStr = "无", fecodeStr = "无", barcodeStr = "无", qtyStr = "无";
  562. try {
  563. JSONObject tmpJson = new JSONObject(result);
  564. msgJson = tmpJson.getJSONObject("message");
  565. productStr = msgJson.getString("msl_prodcode");
  566. locationStr = msgJson.getString("msl_location");
  567. fecodeStr = msgJson.getString("msl_fecode");
  568. barcodeStr = msgJson.getString("msl_barcode");
  569. qtyStr = msgJson.getString("msl_remainqty");
  570. } catch (JSONException e) {
  571. e.printStackTrace();
  572. }
  573. tvFecode.setText(code);
  574. //信息提示框
  575. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  576. tvMsgNotice.setText("上料成功");
  577. tvMsgNotice.setTextColor(getResources().getColor(R.color.green));
  578. tvMsgLocation.setText("物料号:" + productStr);
  579. tvMsgProdcode.setText("站位:" + locationStr);
  580. tvMsgBarcode.setText("飞达:" + fecodeStr);
  581. tvMsgQuantity.setText("料卷号:" + barcodeStr);
  582. tvMsgSpec.setText("数量:" + qtyStr);
  583. //新一轮采集
  584. msl = null;
  585. isAgain = true;
  586. setEtHint();
  587. }
  588. /*========================Volley Handler=================================*/
  589. Handler handler = new Handler() {
  590. @Override
  591. public void handleMessage(Message msg) {
  592. switch (msg.what) {
  593. case VolleyUtil.SUCCESS_SUCCESS:
  594. disposeVolleySuccess(msg);
  595. break;
  596. case VolleyUtil.FAILED_FAILED:
  597. disposeVolleyFaild(msg);
  598. break;
  599. }
  600. }
  601. };
  602. //Volley响应失败
  603. private void disposeVolleyFaild(Message msg) {
  604. String noticeMsg = (String) msg.obj;
  605. String title = "失败";
  606. String content = noticeMsg;
  607. setNotice(title, content, getResources().getColor(R.color.red));
  608. progressDialog.dismiss();
  609. }
  610. //Volley响应成功函数
  611. private void disposeVolleySuccess(Message msg) {
  612. Log.e("SCSMTFEEDER", "HandlerSuccess");
  613. String result = (String) msg.obj;
  614. switch (requestType) {
  615. //请求详细数据
  616. case VolleyUtil.FRAGMENT_SCMAKE_SMTINDETAIL:
  617. Log.e("SCSMTFEEDER", "requestType:" + requestType);
  618. String smtLocationStr = (String) msg.obj;
  619. try {
  620. //保存请求的变量
  621. JSONObject tmpJson = new JSONObject(smtLocationStr);
  622. //如果没有获取到网络数据
  623. boolean isNull = tmpJson.isNull("message");
  624. if (isNull) {
  625. disposeNullServerData();
  626. } else {
  627. smtLocation = tmpJson.getJSONArray("message");
  628. //这里获取了数据 没有填充上去
  629. Log.e("SMTINChild", "smtLocation:" + smtLocation.toString());
  630. }
  631. } catch (JSONException e) {
  632. e.printStackTrace();
  633. }
  634. break;
  635. //物料
  636. case VolleyUtil.FRAGMENT_SCMAKE_SMTIN_BARREMAIN:
  637. Log.e("SMTWULIAO", "BARREMAIN");
  638. disposeBarcodeSuccess(result);
  639. // disposeFecodeCollect();
  640. break;
  641. //上料操作:上料成功以后,需要重新获取输入框文字
  642. case VolleyUtil.FRAGMENT_SCMAKE_SMTIN_UPLOAD:
  643. disposeUpLoadSuccess(result);
  644. break;
  645. }
  646. progressDialog.dismiss();
  647. }
  648. //隐藏采集界面
  649. private void disposeNullServerData() {
  650. rlCollect.setVisibility(View.GONE);
  651. String title = getString(R.string.notice_smtin_nulldata);
  652. setNotice(title, "", getResources().getColor(R.color.text_error));
  653. }
  654. /*========================公用方法=================================*/
  655. /**
  656. * 显示loadingView
  657. */
  658. private void showLoadingView() {
  659. if (!progressDialog.isShowing()) {
  660. progressDialog.show();
  661. }
  662. }
  663. /**
  664. * 键盘
  665. */
  666. InputMethodManager inputManager;
  667. private void hideKeyboard(final EditText view) {
  668. inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
  669. //获取键盘管理对象
  670. inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
  671. }
  672. /**
  673. * 获取输入框焦点
  674. */
  675. private void editTextGetFocus(EditText editText) {
  676. editText.setFocusable(true);
  677. editText.setFocusableInTouchMode(true);
  678. editText.setEnabled(true);
  679. editText.setClickable(true);
  680. editText.requestFocus();
  681. }
  682. /**
  683. * 设置提示信息
  684. */
  685. private void setNotice(String title, String content, int pid) {
  686. tvMsgNotice.setText(title);
  687. tvMsgNotice.setTextColor(pid);
  688. tvMsgProdcode.setText(content);
  689. //清除其它信息
  690. tvMsgSpec.setText("");
  691. tvMsgBarcode.setText("");
  692. tvMsgLocation.setText("");
  693. tvMsgQuantity.setText("");
  694. }
  695. /**
  696. * 设置采集框提示信息
  697. */
  698. @Override
  699. public void setEtHint() {
  700. //获取站位\料卷\飞达编号
  701. String locationStr = tvLocation.getText().toString().trim();
  702. String barcodeStr = tvBarcode.getText().toString().trim();
  703. String remainQty = tvRemainqty.getText().toString().trim();
  704. String fecodeStr = tvFecode.getText().toString().trim();
  705. /*//->if(msl_location为空),如果站位为null
  706. if (isAgain || locationStr.equals("") || locationStr == null) {
  707. etCollect.setHint(R.string.hint_smtchild_location);
  708. }
  709. //->else if(msl_barcode为空) 如果站位不为空,料卷号为空
  710. else if (barcodeStr.equals("") || barcodeStr == null) {
  711. etCollect.setHint(R.string.hint_smtchild_barcode);
  712. }
  713. //->else if(msl_remainqty为空) 如果数量为空
  714. else if (remainQty.equals("") || remainQty == null) {
  715. etCollect.setHint(R.string.hint_smtchild_barcode);
  716. }
  717. //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时
  718. else if (fecodeStr.equals("") || barcodeStr == null) {
  719. etCollect.setHint(R.string.hint_smtchild_fecode);
  720. }*/
  721. }
  722. /**
  723. * 按钮点击事件
  724. */
  725. @Override
  726. public void onClick(View v) {
  727. disposeOnClick();
  728. }
  729. JSONObject msl = new JSONObject();
  730. String code = null;
  731. boolean isAgain = false;
  732. private void disposeOnClick() {
  733. //->获取输入框文字内容
  734. // code = etCollect.getText().toString().trim();
  735. if (code.equals("") || code == null) {
  736. return;
  737. }
  738. Log.e("SCSMT:code", "" + code);
  739. //获取站位\料卷\飞达编号
  740. String locationStr = tvLocation.getText().toString().trim();
  741. String barcodeStr = tvBarcode.getText().toString().trim();
  742. String fecodeStr = tvFecode.getText().toString().trim();
  743. //->if(msl_location为空),如果站位为null,或者是新一轮采集
  744. if (isAgain || locationStr.equals("") || locationStr == null) {
  745. disposeOnClickLocation();
  746. }
  747. //->else if(msl_barcode为空) 如果站位不为空,料卷号为空
  748. else if (barcodeStr.equals("") || barcodeStr == null) {
  749. disposeOnClickBarcode();
  750. }
  751. //->else if(msl_fecode为空),料卷号不为空,飞达编号为空时
  752. else if (fecodeStr.equals("") || barcodeStr == null) {
  753. disposeOnClickFecode();
  754. }
  755. }
  756. @Override
  757. public boolean onKeyDown(int keyCode, KeyEvent event) {
  758. if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
  759. if (progressDialog != null && progressDialog.isShowing()) {
  760. // loadingView.dismiss();
  761. return true;
  762. }
  763. }
  764. return false;
  765. }
  766. @Override
  767. public boolean onFragmentBackPressed() {
  768. return false;
  769. }
  770. }