BulkCollectActivity.java
12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
package com.huaheng.wms.collectgoods;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huaheng.wms.R;
import com.huaheng.wms.WMSLog;
import com.huaheng.wms.https.HttpInterface;
import com.huaheng.wms.https.Subscribers.ProgressSubscriber;
import com.huaheng.wms.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.wms.login.UserBean;
import com.huaheng.wms.login.WareHouseActivity;
import com.huaheng.wms.model.CommonActivity;
import com.huaheng.wms.util.DataBaseHelpter;
import com.huaheng.wms.util.SoundUtils;
import com.huaheng.wms.util.WMSUtils;
import com.huaheng.wms.views.LineLayout;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
** 批量收货
*/
public class BulkCollectActivity extends CommonActivity {
@BindView(R.id.snEdit)
EditText snEdit;
@BindView(R.id.scanLayout)
LinearLayout scanLayout;
@BindView(R.id.inputEdit)
EditText inputEdit;
@BindView(R.id.inputLayout)
FrameLayout inputLayout;
@BindView(R.id.wnLayout)
LineLayout wnLayout;
@BindView(R.id.cnLayout)
LineLayout cnLayout;
@BindView(R.id.barcodeLayout)
LineLayout barcodeLayout;
@BindView(R.id.commondityLayout)
LineLayout commondityLayout;
@BindView(R.id.unitLayout)
LineLayout unitLayout;
@BindView(R.id.inventoryLayout)
LineLayout inventoryLayout;
@BindView(R.id.alreadyView)
TextView alreadyView;
@BindView(R.id.tobeView)
TextView tobeView;
@BindView(R.id.ensureBtn)
Button ensureBtn;
@BindView(R.id.contentLayout)
LinearLayout contentLayout;
@BindView(R.id.ensureLayout)
LinearLayout ensureLayout;
private String wn;
private String tobeNumber = "100";
private String barcode;
private String cn;
private String receiptID;
private boolean isSubmit = false;
private boolean isEnterCN = false;
private AlertDialog mDialog;
private ReceiptInfo receiptInfo;
private List<BillsInfo> billsInfos;
@Override
protected void initActivityOnCreate(Bundle savedInstanceState) {
super.initActivityOnCreate(savedInstanceState);
setContentView(R.layout.activity_bulk_collect);
ButterKnife.bind(this);
setTitle(getString(R.string.bulk_collection));
initView();
enableButton(false);
}
private void initView() {
billsInfos = new ArrayList<>();
snEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
String number = editable.toString();
if(!isEnterCN) {
if (number != null && number.length() > 0) {
wn = number;
enableButton(true);
} else {
enableButton(false);
}
} else {
if (number != null && number.length() > 0) {
cn = number;
sanContainer(cn);
}
}
}
});
snEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if(isEnterCN) {
}
}
return false;
}
});
inputEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
barcode = editable.toString();
if (barcode != null && barcode.length() > 0) {
getCollectInfo();
} else {
enableButton(false);
}
}
});
}
private void enableButton(boolean enable) {
if (enable) {
ensureBtn.setBackgroundResource(R.drawable.blue_button_bg);
ensureLayout.setClickable(true);
} else {
ensureBtn.setBackgroundResource(R.drawable.gray_button_bg);
ensureLayout.setClickable(false);
}
}
private void getCollectInfo() {
String name = "MYR930S-X 立式饮水机 白色 S2平台网销机";
String unit = "个";
String status = "良品";
String already_received = "0";
contentLayout.setVisibility(View.VISIBLE);
wnLayout.setLineName(this.getString(R.string.warehouse_number));
wnLayout.setLineContent(receiptID);
cnLayout.setLineName(this.getString(R.string.container_number));
cnLayout.setLineContent(cn);
barcodeLayout.setLineName(this.getString(R.string.commodity_barcode));
barcodeLayout.setLineContent(barcode);
commondityLayout.setLineName(this.getString(R.string.commodity_name));
commondityLayout.setLineContent(name);
unitLayout.setLineName(this.getString(R.string.unit));
unitLayout.setLineContent(unit);
inventoryLayout.setLineName(this.getString(R.string.inventory_state));
inventoryLayout.setLineContent(status);
alreadyView.setText(already_received);
tobeView.setText(tobeNumber);
}
private void showInputLayout() {
WMSLog.d("showInputLayout");
scanLayout.setVisibility(View.GONE);
inputLayout.setVisibility(View.VISIBLE);
inputEdit.requestFocus();
}
@OnClick({R.id.inputBtn, R.id.ensureLayout})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.inputBtn:
showInputDialog();
break;
case R.id.ensureLayout:
WMSLog.d("isSubmit:" + isSubmit);
if (isSubmit) {
submit();
} else {
scanBill(wn);
}
break;
}
}
private void showInputDialog() {
final EditText et = new EditText(this);
et.setInputType(InputType.TYPE_CLASS_NUMBER);
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.input_quantity_goods))
.setView(et)
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//按下确定键后的事件
String already = et.getText().toString();
int number = Integer.parseInt(already);
if (number > 0) {
enableButton(true);
}
int tobe = Integer.parseInt(tobeNumber) - Integer.parseInt(already);
alreadyView.setText(already);
tobeView.setText(String.valueOf(tobe));
inputEdit.requestFocus();
addBillList(already);
}
}).setNegativeButton(this.getString(R.string.cancel), null);
mDialog = builder.create();
mDialog.show();
et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
String already = textView.getText().toString();
int number = Integer.parseInt(already);
if (number > 0) {
enableButton(true);
}
int tobe = Integer.parseInt(tobeNumber) - Integer.parseInt(already);
alreadyView.setText(already);
tobeView.setText(String.valueOf(tobe));
mDialog.dismiss();
}
return false;
}
});
}
private void submit() {
saveBillByBulk();
}
private void scanBill(String code) {
receiptID = code;
HttpInterface.getInsstance().scanBill(new ProgressSubscriber<ArrayList<ReceiptInfo>>(this, scanBillListener), code);
}
SubscriberOnNextListener scanBillListener = new SubscriberOnNextListener<ArrayList<ReceiptInfo>>() {
@Override
public void onNext(ArrayList<ReceiptInfo> receiptInfos) {
if(receiptInfos != null && receiptInfos.size() > 0) {
for(int i=0; i< receiptInfos.size(); i++) {
List<ReceiptInfo> receiptInfoList = DataBaseHelpter.queryAllReceiptInfo();
receiptInfo = receiptInfos.get(i);
if(receiptInfoList != null && receiptInfoList.size() >0) {
boolean insert = false;
for(int j=0; j< receiptInfoList.size(); j++) {
WMSLog.d("receiptInfoList.get(j).getId():" + receiptInfoList.get(j).getId() + " receiptInfo.getId():" + receiptInfo.getId());
if(receiptInfoList.get(j).getId().equals(receiptInfo.getId())) {
insert = false;
break;
}
insert = true;
}
if(insert) {
WMSLog.d("receiptInfoList.size():" + receiptInfoList.size());
receiptInfo.set_id(receiptInfoList.size());
try {
DataBaseHelpter.insertReceiptInfo(receiptInfo);
continue;
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
receiptInfo.set_id(0);
DataBaseHelpter.insertReceiptInfo(receiptInfo);
}
}
isEnterCN = true;
snEdit.requestFocus();
snEdit.setText("");
snEdit.setHint(R.string.enter_container_number);
enableButton(false);
}
}
};
private void sanContainer(String code) {
HttpInterface.getInsstance().sanContainer(new ProgressSubscriber<String>(this, sanContainerListener), code);
}
SubscriberOnNextListener sanContainerListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String s) {
isSubmit = true;
showInputLayout();
}
};
private void addBillList(String number) {
BillsInfo billsInfo = new BillsInfo(cn, receiptInfo.getId(), number);
billsInfos.add(billsInfo);
}
private void saveBillByBulk() {
HttpInterface.getInsstance().saveBillByBulk(new ProgressSubscriber<List<GoodsInfo>>(this, saveBillByBulkListener), billsInfos);
}
SubscriberOnNextListener saveBillByBulkListener = new SubscriberOnNextListener<List<GoodsInfo>>() {
@Override
public void onNext(List<GoodsInfo> goodsInfos) {
SoundUtils.getInstance(BulkCollectActivity.this).dingSound();
finish();
WMSUtils.startActivity(BulkCollectActivity.this, BulkCollectActivity.class);
}
};
}