forked from JerryChen/DXPDA
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
523 lines
20 KiB
523 lines
20 KiB
package com.icssoft.icspda.activity;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import android.graphics.Color;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.text.Editable;
|
|
import android.text.TextWatcher;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.view.inputmethod.EditorInfo;
|
|
import android.widget.AdapterView;
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.Spinner;
|
|
import android.widget.SpinnerAdapter;
|
|
import android.widget.TextView;
|
|
|
|
import com.bin.david.form.core.SmartTable;
|
|
import com.bin.david.form.data.column.Column;
|
|
import com.bin.david.form.data.table.TableData;
|
|
import com.google.gson.Gson;
|
|
import com.icssoft.icspda.R;
|
|
import com.icssoft.icspda.entity.OpTransferData;
|
|
import com.icssoft.icspda.entity.PoArriveConfirmData;
|
|
import com.icssoft.icspda.entity.ApplicationModel;
|
|
import com.icssoft.icspda.net.WebServiceUtil;
|
|
import com.icssoft.icspda.util.HelpUtil;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class POArriveConfirmActivity extends AppCompatActivity {
|
|
//region 变量初始化
|
|
private TextView tvMsg;
|
|
private EditText asnNo;
|
|
private Spinner spInvCode;
|
|
private Button btnConfirm;
|
|
private Button btnSubmit;
|
|
private EditText qty;
|
|
private EditText barCode;
|
|
private String result;
|
|
private ApplicationModel applicationModel;
|
|
private PoArriveConfirmData[] poData;
|
|
private List<PoArriveConfirmData> dataList;
|
|
private SmartTable smartTable;
|
|
private String ErrorMsg = "";
|
|
private boolean flag = false;
|
|
//endregion
|
|
|
|
private Handler handler = new Handler() {
|
|
@Override
|
|
public void handleMessage(Message msg) {
|
|
super.handleMessage(msg);
|
|
|
|
switch (msg.what) {
|
|
case 0:
|
|
gridBarCode();
|
|
HelpUtil.SetMsg(tvMsg, Color.BLUE, "单据扫描成功!");
|
|
break;
|
|
case 1:
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, applicationModel.getMsg());
|
|
//asnNo.requestFocus();
|
|
asnNo.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
asnNo.requestFocus();
|
|
}
|
|
},1000);
|
|
break;
|
|
case 3:
|
|
clear();
|
|
HelpUtil.SetMsg(tvMsg, Color.BLUE, "到货成功,到货单号:" + applicationModel.getMsg() + "!");
|
|
break;
|
|
case 4:
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, applicationModel.getMsg());
|
|
asnNo.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
asnNo.requestFocus();
|
|
}
|
|
},1000);
|
|
break;
|
|
case 99:
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, ErrorMsg);
|
|
asnNo.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
asnNo.requestFocus();
|
|
}
|
|
},1000);
|
|
break;
|
|
case 98:
|
|
HelpUtil.SetMsg(tvMsg, Color.BLUE, "实收总重修改成功!");
|
|
qty.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
qty.requestFocus();
|
|
}
|
|
},1000);
|
|
break;
|
|
case 97:
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, "实际总重不能为0!");
|
|
qty.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
qty.requestFocus();
|
|
}
|
|
},1000);
|
|
break;
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_poarriveconfirm);
|
|
bindView();
|
|
}
|
|
|
|
private void bindView() {
|
|
this.setTitle("到货确认");
|
|
tvMsg = findViewById(R.id.tv_msg);
|
|
asnNo = findViewById(R.id.et_asnno);
|
|
barCode = findViewById(R.id.et_lotno);
|
|
spInvCode = findViewById(R.id.sp_invcode);
|
|
qty = findViewById(R.id.et_qty);
|
|
smartTable = findViewById(R.id.table);
|
|
btnConfirm = findViewById(R.id.btn_confirm);
|
|
btnSubmit = findViewById(R.id.btn_submit);
|
|
// HelpUtil.disableShowSoftInput(asnNo);
|
|
|
|
asnNo.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
@Override
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
try {
|
|
if (actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT
|
|
|| (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {
|
|
if (v.getText().length() > 0) {
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
checkAsnNo();
|
|
}
|
|
}).start();
|
|
}
|
|
}
|
|
return false;
|
|
} catch (Exception ex) {
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
});
|
|
barCode.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
@Override
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
try {
|
|
if (actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT
|
|
|| (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {
|
|
if (v.getText().length() > 0) {
|
|
checkExist();
|
|
}
|
|
}
|
|
return false;
|
|
} catch (Exception ex) {
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
});
|
|
|
|
spInvCode.setOnItemSelectedListener(
|
|
new AdapterView.OnItemSelectedListener() {
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
if ((spInvCode.getSelectedItem().toString().equals("--请选择--"))) {
|
|
barCode.setText("");
|
|
}else{
|
|
barCode.setText(spInvCode.getSelectedItem().toString());
|
|
qty.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
qty.requestFocus();
|
|
}
|
|
},1000);
|
|
}
|
|
}
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
}
|
|
});
|
|
qty.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
@Override
|
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
try {
|
|
if (actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT
|
|
|| (event != null && KeyEvent.KEYCODE_ENTER == event.getKeyCode() && KeyEvent.ACTION_DOWN == event.getAction())) {
|
|
if (qty.getText().toString().trim().equals("")||Double.parseDouble(qty.getText().toString().trim())<=0) {
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, "请输入正确数量");
|
|
return false;
|
|
}
|
|
|
|
String invCode = spInvCode.getSelectedItem().toString();
|
|
if ((invCode.equals("--请选择--"))) {
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, "请选择物料条码");
|
|
return false;
|
|
} else {
|
|
HelpUtil.SetMsg(tvMsg, Color.BLUE, "");
|
|
}
|
|
|
|
for (PoArriveConfirmData item : dataList) {
|
|
if (item.getLOTNO().equals(invCode)) {
|
|
item.setReceiveQTY(qty.getText().toString().trim());
|
|
break;
|
|
}
|
|
}
|
|
smartTable.setData(dataList);
|
|
handler.sendEmptyMessage(98);
|
|
chooseRow();
|
|
}
|
|
return false;
|
|
} catch (Exception ex) {
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
});
|
|
|
|
btnConfirm.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
try {
|
|
if (qty.getText().toString().trim().equals("")||Double.parseDouble(qty.getText().toString().trim())<=0) {
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, "请输入正确数量");
|
|
return;
|
|
}
|
|
|
|
String invCode = barCode.getText().toString();
|
|
if ((invCode.equals(""))) {
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, "请扫描条码");
|
|
return;
|
|
} else {
|
|
HelpUtil.SetMsg(tvMsg, Color.BLUE, "");
|
|
}
|
|
|
|
for (PoArriveConfirmData item : dataList) {
|
|
if (item.getLOTNO().equals(invCode)) {
|
|
item.setReceiveQTY(qty.getText().toString().trim());
|
|
break;
|
|
}
|
|
}
|
|
smartTable.setData(dataList);
|
|
handler.sendEmptyMessage(98);
|
|
chooseRow();
|
|
}catch (Exception ex) {
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, "请先扫描单据");
|
|
}
|
|
}
|
|
});
|
|
|
|
btnSubmit.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
try{
|
|
if (dataList==null||dataList.size() <= 0) {
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, "请先扫描正确单据!");
|
|
asnNo.requestFocus();
|
|
return;
|
|
}
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
// checkAsnNo();
|
|
asnConfirm();
|
|
}
|
|
}).start();
|
|
}catch (Exception ex){
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
private void checkExist() {
|
|
String lotNo = barCode.getText().toString();
|
|
//获取下拉列表的视图
|
|
SpinnerAdapter spinnerAdapter = spInvCode.getAdapter();
|
|
//下拉列表元素总个数
|
|
int spIncodeCount = spinnerAdapter.getCount();
|
|
if (dataList!=null){
|
|
for (PoArriveConfirmData data : dataList) {
|
|
if (barCode.getText().toString().equals(data.getLOTNO())){
|
|
|
|
for (int i = 0; i < spIncodeCount; i++) {
|
|
if (lotNo.equals(spinnerAdapter.getItem(i).toString())){
|
|
spInvCode.setSelection(i);
|
|
break;
|
|
}
|
|
}
|
|
qty.setText("");
|
|
ErrorMsg = "扫描成功";
|
|
HelpUtil.SetMsg(tvMsg, Color.BLUE, ErrorMsg);
|
|
qty.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
qty.requestFocus();
|
|
}
|
|
},1000);
|
|
return;
|
|
}
|
|
}
|
|
ErrorMsg = "此条码不在本次送货单内,请重新扫码!";
|
|
barCode.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
barCode.requestFocus();
|
|
}
|
|
},1000);
|
|
for (int i = 0; i < spIncodeCount; i++) {
|
|
if ("--请选择--".equals(spinnerAdapter.getItem(i).toString())){
|
|
spInvCode.setSelection(i);
|
|
break;
|
|
}
|
|
}
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, ErrorMsg);
|
|
}else{
|
|
ErrorMsg = "请先扫描正确单据";
|
|
HelpUtil.SetMsg(tvMsg, Color.RED, ErrorMsg);
|
|
}
|
|
|
|
}
|
|
|
|
private void chooseRow(){
|
|
try{
|
|
smartTable.getTableData().setOnRowClickListener(new TableData.OnRowClickListener<PoArriveConfirmData>() {
|
|
@Override
|
|
public void onClick(Column column, PoArriveConfirmData poArriveConfirmData, int col,final int row) {
|
|
try{
|
|
//改变选中行的颜色
|
|
HelpUtil.ChangeRowBackgroundColor(smartTable, row);
|
|
String lotNo =poArriveConfirmData.getLOTNO();
|
|
//获取下拉列表的视图
|
|
SpinnerAdapter spinnerAdapter = spInvCode.getAdapter();
|
|
//下拉列表元素总个数
|
|
int spIncodeCount = spinnerAdapter.getCount();
|
|
for (int i = 0; i < spIncodeCount; i++) {
|
|
if (lotNo.equals(spinnerAdapter.getItem(i).toString())){
|
|
spInvCode.setSelection(i);
|
|
break;
|
|
}
|
|
}
|
|
barCode.setText(lotNo);
|
|
qty.setText("");
|
|
}catch (Exception ex){
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
}
|
|
});
|
|
}catch (Exception ex){
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
}
|
|
|
|
private void gridBarCode() {
|
|
try{
|
|
ArrayList<CharSequence> spList = new ArrayList<>();
|
|
dataList = new ArrayList<>();
|
|
spList.add("--请选择--");
|
|
for (PoArriveConfirmData data : poData) {
|
|
spList.add(data.getLOTNO());
|
|
dataList.add(data);
|
|
}
|
|
ArrayAdapter<CharSequence> arrayAdapter = new ArrayAdapter<CharSequence>(this, R.layout.simple_spinner_dropdown_item, spList);
|
|
arrayAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
|
|
spInvCode.setAdapter(arrayAdapter);
|
|
|
|
HelpUtil.InitSmartTable(smartTable, this.getApplicationContext());
|
|
smartTable.setData(dataList);
|
|
chooseRow();
|
|
}catch(Exception ex){
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
|
|
}
|
|
|
|
private void checkAsnNo() {
|
|
Map params = new HashMap();
|
|
params.put("BarCode", asnNo.getText().toString());
|
|
params.put("WorkPointCode", LoginActivity.user.getWorkPointCode());
|
|
try {
|
|
result = "";
|
|
result = WebServiceUtil.GetWSReturnInfo("CheckASNNo", params);
|
|
if (result != null && result.length() != 0) {
|
|
applicationModel = new Gson().fromJson(result, ApplicationModel.class);
|
|
int code = Integer.parseInt(applicationModel.getCode());
|
|
if (code == 0) {
|
|
getAsnData();
|
|
if (poData.length!=0){
|
|
handler.sendEmptyMessage(0);
|
|
return;
|
|
}
|
|
handler.sendEmptyMessage(99);
|
|
} else {
|
|
handler.sendEmptyMessage(1);
|
|
}
|
|
}
|
|
} catch (Exception ex) {
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
}
|
|
|
|
private void getAsnData() {
|
|
Map params = new HashMap();
|
|
params.put("BarCode", asnNo.getText().toString());
|
|
params.put("WorkPointCode", LoginActivity.user.getWorkPointCode());
|
|
try {
|
|
result = "";
|
|
result = WebServiceUtil.GetWSReturnInfo("GetASNData", params);
|
|
if (result != null && result.length() != 0) {
|
|
poData = new Gson().fromJson(result, PoArriveConfirmData[].class);
|
|
}
|
|
} catch (Exception ex) {
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
|
|
}
|
|
}
|
|
|
|
private void asnConfirm() {
|
|
String poRowList = "";
|
|
String poRowQtyList = "";
|
|
String invCodeList = "";
|
|
String lotNoList= "";
|
|
for (PoArriveConfirmData item : dataList) {
|
|
if (poRowList.equals("")) {
|
|
poRowList += item.getSTLine();
|
|
// if (Double.parseDouble(item.getReceiveQTY())<=0){
|
|
// handler.sendEmptyMessage(97);
|
|
// return;
|
|
// }
|
|
poRowQtyList += item.getReceiveQTY();
|
|
invCodeList += item.getINVCODE();
|
|
lotNoList += item.getLOTNO();
|
|
} else {
|
|
poRowList += "," + item.getSTLine() + "";
|
|
// if (Double.parseDouble(item.getReceiveQTY())<=0){
|
|
// handler.sendEmptyMessage(97);
|
|
// return;
|
|
// }
|
|
poRowQtyList += "," + item.getReceiveQTY() + "";
|
|
invCodeList += "," + item.getINVCODE() + "";
|
|
lotNoList += "," + item.getLOTNO() + "";
|
|
}
|
|
}
|
|
Map params = new HashMap();
|
|
params.put("POCode", asnNo.getText().toString());
|
|
params.put("PoRowList", poRowList);
|
|
params.put("PoRowQtyList", poRowQtyList);
|
|
params.put("BarCodeList", lotNoList);
|
|
params.put("InvCodeList", invCodeList);
|
|
params.put("userID", LoginActivity.user.getID());
|
|
params.put("userCode", LoginActivity.user.getUserCode());
|
|
params.put("userName", LoginActivity.user.getUserName());
|
|
params.put("workPoint", LoginActivity.user.getWorkPointCode());
|
|
params.put("Type", "收");
|
|
try {
|
|
result = "";
|
|
result = WebServiceUtil.GetWSReturnInfo("ASNConfirm", params);
|
|
if (result != null && result.length() != 0) {
|
|
applicationModel = new Gson().fromJson(result, ApplicationModel.class);
|
|
int code = Integer.parseInt(applicationModel.getCode());
|
|
if (code == 0) {
|
|
handler.sendEmptyMessage(3);
|
|
} else {
|
|
handler.sendEmptyMessage(1);
|
|
}
|
|
}
|
|
} catch (Exception ex) {
|
|
ErrorMsg = ex.getMessage();
|
|
handler.sendEmptyMessage(99);
|
|
}
|
|
}
|
|
|
|
private void clear() {
|
|
asnNo.setText("");
|
|
asnNo.requestFocus();
|
|
spInvCode.setAdapter(null);
|
|
qty.setText("");
|
|
barCode.setText("");
|
|
dataList.clear();
|
|
// smartTable.getTableData().clear();
|
|
PoArriveConfirmData a = new PoArriveConfirmData();
|
|
a.setINVCODE("");
|
|
a.setLOTNO("");
|
|
a.setINVName("");
|
|
a.setINVSTD("");
|
|
a.setPlanQTY("");
|
|
a.setReceiveQTY("");
|
|
dataList.add(a);
|
|
smartTable.setData(dataList);
|
|
}
|
|
}
|