diff --git a/src/android_serialport_api/print_tool/MobilePrintTool.java b/src/android_serialport_api/print_tool/MobilePrintTool.java index b26bea5..c6d7d88 100644 --- a/src/android_serialport_api/print_tool/MobilePrintTool.java +++ b/src/android_serialport_api/print_tool/MobilePrintTool.java @@ -14,6 +14,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; +import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.view.WindowManager; @@ -95,17 +96,19 @@ public class MobilePrintTool extends Activity { }); } - public void init(String info) { - this.info = info; - if (printer == null) { - printer = new PrinterEscCmd(); - } - type = SharedPreferences2Obj.getInstance(MobilePrintTool.this) - .setName("MachineType").getObject("type", Integer.class); - if (initBlu()) { - initBS(); - } - } + public void init(String info) { + LogUtil.d(TAG, "info = " + info); + this.info = info; + if (printer == null) { + printer = new PrinterEscCmd(); + } + type = SharedPreferences2Obj.getInstance(MobilePrintTool.this) + .setName("MachineType").getObject("type", Integer.class); + LogUtil.d(TAG, "type = " + type); + if (initBlu()) { + initBS(); + } + } private boolean initBlu() { // 判断是否有蓝牙功能 // 得到本地的适配器 @@ -265,7 +268,7 @@ public class MobilePrintTool extends Activity { break; } - } + } private void print(final String str) { if (isprint && isprint2) { @@ -385,59 +388,60 @@ public class MobilePrintTool extends Activity { } } - @SuppressLint("SimpleDateFormat") private void printThread(int printNum, String str) { - for (int x = 0; x < printNum; x++) { - if (x == 1 && isStatistic.equals("1")) { - if (dialog != null) { - dialog.dismiss(); - } - return; - } - try { - if (isStatistic != null && isStatistic.equals("1")) { - printer.escPrintText(" 统计信息" + "\n"); - } else { - printer.escPrintText(" 订单信息"); - // 当时重打小票的时候,多打一段字符 - int Select = SharedPreferences2Obj - .getInstance(MobilePrintTool.this) - .setName("SelectAction") - .getObject("Select", Integer.class); - if (Select == 2) { - printer.escEnter(); - printer.escPrintText(" (重打小票)"); - } - } - printer.escEnter(); - } catch (Exception e) { - e.printStackTrace(); - } - - if (str == null) { - return; - } - // 打印信息 - try { - if (isStatistic != null && isStatistic.equals("1")) { - System.out.println(str); - try { - printer.escPrintText(str);// 订单信息 - } catch (Exception e) { - e.printStackTrace(); - } - } else { - // 重打时间 - int Select = SharedPreferences2Obj - .getInstance(MobilePrintTool.this) - .setName("SelectAction") - .getObject("Select", Integer.class); - if (Select == 2) { - SimpleDateFormat df = new SimpleDateFormat( - "yyyy-MM-dd HH:mm:ss");// 设置日期格式 - printer.escPrintText("重打时间:" + df.format(new Date()));// new - printer.escEnter(); - // Date()为获取当前系统时间 - } + @SuppressLint("SimpleDateFormat") + private void printThread(int printNum, String str) { + for (int x = 0; x < printNum; x++) { + if (x == 1 && isStatistic.equals("1")) { + if (dialog != null) { + dialog.dismiss(); + } + return; + } + try { + if (isStatistic != null && isStatistic.equals("1")) { + printer.escPrintText(" 统计信息" + "\n"); + } else { + printer.escPrintText(" 订单信息"); + // 当时重打小票的时候,多打一段字符 + int Select = SharedPreferences2Obj + .getInstance(MobilePrintTool.this) + .setName("SelectAction") + .getObject("Select", Integer.class); + if (Select == 2) { + printer.escEnter(); + printer.escPrintText(" (重打小票)"+ "\n"); + } + } + printer.escEnter(); + } catch (Exception e) { + e.printStackTrace(); + } + + if (TextUtils.isEmpty(str)) { + return; + } + // 打印信息 + try { + if (isStatistic != null && isStatistic.equals("1")) { + System.out.println(str); + try { + printer.escPrintText(str);// 订单信息 + } catch (Exception e) { + e.printStackTrace(); + } + } else { + // 重打时间 + int Select = SharedPreferences2Obj + .getInstance(MobilePrintTool.this) + .setName("SelectAction") + .getObject("Select", Integer.class); + if (Select == 2) { + SimpleDateFormat df = new SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss");// 设置日期格式 + printer.escPrintText("重打时间:" + df.format(new Date()));// new + printer.escEnter(); + // Date()为获取当前系统时间 + } printer.escPrintText(str);// 订单信息 printer.escEnter(); diff --git a/src/com/ectrip/cyt/center/ReprintHandle.java b/src/com/ectrip/cyt/center/ReprintHandle.java index fa48c15..3b5449b 100644 --- a/src/com/ectrip/cyt/center/ReprintHandle.java +++ b/src/com/ectrip/cyt/center/ReprintHandle.java @@ -34,6 +34,7 @@ import com.ectrip.cyt.response.OrderConsumedItem; import com.ectrip.cyt.response.QueryConsumedDetailResponse; import com.ectrip.cyt.response.ReprintVoucherResponse; import com.ectrip.cyt.ui.BaseActivity; +import com.ectrip.cyt.utils.LogUtil; import com.ectrip.cyt.utils.SharedPreferences2Obj; import com.ectrip.trips.check.R; import com.ectrip.trips.net.DataTool; @@ -42,467 +43,472 @@ import com.ectrip.trips.net.HttpHelper; /** * @author jigo 补打小票 */ -public class ReprintHandle implements ReprintInteface,OnItemClickListener { - private String orid; - private View v; - private AtomicBoolean isClick; - private BaseActivity activity; - private Integer type; - private Resources resources; - - @Override - public void reprintHandle(String orid, ListOnclickCallback callback, - final View v, final AtomicBoolean isClick, BaseActivity activity) { - this.resources = activity.getResources(); - this.orid = orid; - this.v = v; - this.isClick = isClick; - this.activity = activity; - type = SharedPreferences2Obj.getInstance(activity) - .setName("MachineType").getObject("type", Integer.class); - if (isClick.get()) { - isClick.set(false); - v.setClickable(false); - HttpHelper.getInstance(activity).queryConsumedDetail(orid, - new ReprintListCallback()); - } else { - activity.MToast(activity, "点击过快,稍等两秒!", Toast.LENGTH_SHORT); - } - } - - /** - * @author jigo 获取补打列表 - */ - public class ReprintListCallback extends HttpCallback { - private String signed; - private String data; - ProgressDialog progressDialog = null; - - @Override - public void onPreCallback() { - if (progressDialog == null) { - // 显示ProgressDialog - progressDialog = new ProgressDialog(activity); - progressDialog.setMessage(resources - .getString(R.string.get_ticket_info)); - progressDialog.setCanceledOnTouchOutside(false); - progressDialog.setCancelable(true); - if (type == 8) { - progressDialog.getWindow().setType( - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); - } - try { - if (progressDialog != null && !progressDialog.isShowing()) { - progressDialog.show(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } else { - progressDialog.setMessage(resources - .getString(R.string.get_ticket_info)); - } - } - - @Override - public void onCompletedCallback(DataTrans result) { - } - - @Override - public void afterCompletedCallback(DataTrans result) { - if (result != null) { - signed = result.getSigned(); - data = result.getData(); - parse2(result.getData(), QueryConsumedDetailResponse.class,activity); - } else { - isClick.set(true); - v.setClickable(true); - if (progressDialog != null && progressDialog.isShowing()) { - try { - progressDialog.dismiss(); - } catch (Exception e) { - e.printStackTrace(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - activity.MToast(activity, - resources.getString(R.string.get_order_error), - Toast.LENGTH_SHORT); - } - - } - - @Override - public void onAgainParseCallback(Object parse) { - isClick.set(true); - v.setClickable(true); - if (progressDialog != null && progressDialog.isShowing()) { - try { - progressDialog.dismiss(); - } catch (Exception e) { - e.printStackTrace(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - if (parse != null) { - QueryConsumedDetailResponse detailResponse = (QueryConsumedDetailResponse) parse; - String code = detailResponse.getCode(); - if (code != null && OrderCode.SUCESS.getValue().equals(code)) { - if (signed == null - || signed.equals(DataTool.getSign(MyApp - .getInstance().getSignkey(), data))) { - // 获取一个订单中每个记录 - List items = detailResponse - .getOrderConsumedItems(); - dialog(items); - } else { - onFailureCallback(resources - .getString(R.string.sign_not_pass)); - activity.MToast(activity, - resources.getString(R.string.sign_not_pass), - Toast.LENGTH_SHORT); - } - } else { - onFailureCallback(detailResponse.getDescribe()); - activity.MToast(activity, detailResponse.getDescribe(), - Toast.LENGTH_SHORT); - } - } - } - - @Override - public void onFailureCallback(String FailureStr) { - isClick.set(true); - v.setClickable(true); - if (progressDialog != null && progressDialog.isShowing()) { - try { - progressDialog.dismiss(); - } catch (Exception e) { - e.printStackTrace(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - try { - activity.MToast(activity, FailureStr, Toast.LENGTH_SHORT); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void onStopCallback() { - } - } - - /** - * @author jigo 获取打票信息 - */ - public class ReprintInfoCallback extends HttpCallback { - - private String signed; - private String data; - ProgressDialog progressDialog = null; - - @Override - public void onPreCallback() { - if (progressDialog == null) { - // 显示ProgressDialog - progressDialog = new ProgressDialog(activity); - progressDialog.setMessage(resources - .getString(R.string.ready_to_print)); - progressDialog.setCanceledOnTouchOutside(false); - progressDialog.setCancelable(true); - if (type == 8) { - progressDialog.getWindow().setType( - WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); - } - try { - if (progressDialog != null && !progressDialog.isShowing()) { - progressDialog.show(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } else { - progressDialog.setMessage(resources - .getString(R.string.ready_to_print)); - } - } - - @Override - public void onCompletedCallback(DataTrans result) { - } - - @Override - public void afterCompletedCallback(DataTrans result) { - if (result != null) { - signed = result.getSigned(); - data = result.getData(); - parse2(result.getData(), ReprintVoucherResponse.class,activity); - } else { - isClick.set(true); - v.setClickable(true); - if (progressDialog != null && progressDialog.isShowing()) { - try { - progressDialog.dismiss(); - } catch (Exception e) { - e.printStackTrace(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - activity.MToast(activity, - resources.getString(R.string.get_order_error), - Toast.LENGTH_SHORT); - } - - } - - @Override - public void onAgainParseCallback(Object parse) { - isClick.set(true); - v.setClickable(true); - if (progressDialog != null && progressDialog.isShowing()) { - try { - progressDialog.dismiss(); - } catch (Exception e) { - e.printStackTrace(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - if (parse != null) { - ReprintVoucherResponse voucherResponse = (ReprintVoucherResponse) parse; - String code = voucherResponse.getCode(); - if (code != null && OrderCode.SUCESS.getValue().equals(code)) { - if (signed == null - || signed.equals(DataTool.getSign(MyApp - .getInstance().getSignkey(), data))) { - // 获取一个订单中每个记录 +public class ReprintHandle implements ReprintInteface, OnItemClickListener { + private String orid; + private View v; + private AtomicBoolean isClick; + private BaseActivity activity; + private Integer type; + private Resources resources; + + @Override + public void reprintHandle(String orid, ListOnclickCallback callback, + final View v, final AtomicBoolean isClick, BaseActivity activity) { + this.resources = activity.getResources(); + this.orid = orid; + this.v = v; + this.isClick = isClick; + this.activity = activity; + type = SharedPreferences2Obj.getInstance(activity) + .setName("MachineType").getObject("type", Integer.class); + if (isClick.get()) { + isClick.set(false); + v.setClickable(false); + HttpHelper.getInstance(activity).queryConsumedDetail(orid, + new ReprintListCallback()); + } else { + activity.MToast(activity, "点击过快,稍等两秒!", Toast.LENGTH_SHORT); + } + } + + /** + * @author jigo 获取补打列表 + */ + public class ReprintListCallback extends HttpCallback { + private String signed; + private String data; + ProgressDialog progressDialog = null; + + @Override + public void onPreCallback() { + if (progressDialog == null) { + // 显示ProgressDialog + progressDialog = new ProgressDialog(activity); + progressDialog.setMessage(resources + .getString(R.string.get_ticket_info)); + progressDialog.setCanceledOnTouchOutside(false); + progressDialog.setCancelable(true); + if (type == 8) { + progressDialog.getWindow().setType( + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + } + try { + if (progressDialog != null && !progressDialog.isShowing()) { + progressDialog.show(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } else { + progressDialog.setMessage(resources + .getString(R.string.get_ticket_info)); + } + } + + @Override + public void onCompletedCallback(DataTrans result) { + } + + @Override + public void afterCompletedCallback(DataTrans result) { + if (result != null) { + signed = result.getSigned(); + data = result.getData(); + parse2(result.getData(), QueryConsumedDetailResponse.class, activity); + } else { + isClick.set(true); + v.setClickable(true); + if (progressDialog != null && progressDialog.isShowing()) { + try { + progressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + activity.MToast(activity, + resources.getString(R.string.get_order_error), + Toast.LENGTH_SHORT); + } + + } + + @Override + public void onAgainParseCallback(Object parse) { + isClick.set(true); + v.setClickable(true); + if (progressDialog != null && progressDialog.isShowing()) { + try { + progressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + if (parse != null) { + QueryConsumedDetailResponse detailResponse = (QueryConsumedDetailResponse) parse; + String code = detailResponse.getCode(); + if (code != null && OrderCode.SUCESS.getValue().equals(code)) { + if (signed == null + || signed.equals(DataTool.getSign(MyApp + .getInstance().getSignkey(), data))) { + // 获取一个订单中每个记录 + List items = detailResponse + .getOrderConsumedItems(); + dialog(items); + } else { + onFailureCallback(resources + .getString(R.string.sign_not_pass)); + activity.MToast(activity, + resources.getString(R.string.sign_not_pass), + Toast.LENGTH_SHORT); + } + } else { + onFailureCallback(detailResponse.getDescribe()); + activity.MToast(activity, detailResponse.getDescribe(), + Toast.LENGTH_SHORT); + } + } + } + + @Override + public void onFailureCallback(String FailureStr) { + isClick.set(true); + v.setClickable(true); + if (progressDialog != null && progressDialog.isShowing()) { + try { + progressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + try { + activity.MToast(activity, FailureStr, Toast.LENGTH_SHORT); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void onStopCallback() { + } + } + + /** + * @author jigo 获取打票信息 + */ + public class ReprintInfoCallback extends HttpCallback { + + private String signed; + private String data; + ProgressDialog progressDialog = null; + + @Override + public void onPreCallback() { + if (progressDialog == null) { + // 显示ProgressDialog + progressDialog = new ProgressDialog(activity); + progressDialog.setMessage(resources + .getString(R.string.ready_to_print)); + progressDialog.setCanceledOnTouchOutside(false); + progressDialog.setCancelable(true); + if (type == 8) { + progressDialog.getWindow().setType( + WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + } + try { + if (progressDialog != null && !progressDialog.isShowing()) { + progressDialog.show(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } else { + progressDialog.setMessage(resources + .getString(R.string.ready_to_print)); + } + } + + @Override + public void onCompletedCallback(DataTrans result) { + } + + @Override + public void afterCompletedCallback(DataTrans result) { + if (result != null) { + signed = result.getSigned(); + data = result.getData(); + parse2(result.getData(), ReprintVoucherResponse.class, activity); + } else { + isClick.set(true); + v.setClickable(true); + if (progressDialog != null && progressDialog.isShowing()) { + try { + progressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + activity.MToast(activity, + resources.getString(R.string.get_order_error), + Toast.LENGTH_SHORT); + } + + } + + @Override + public void onAgainParseCallback(Object parse) { + isClick.set(true); + v.setClickable(true); + if (progressDialog != null && progressDialog.isShowing()) { + try { + progressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + if (parse != null) { + ReprintVoucherResponse voucherResponse = (ReprintVoucherResponse) parse; + String code = voucherResponse.getCode(); + if (code != null && OrderCode.SUCESS.getValue().equals(code)) { + if (signed == null + || signed.equals(DataTool.getSign(MyApp + .getInstance().getSignkey(), data))) { + // 获取一个订单中每个记录 // List> items = voucherResponse // .getPrintInfos(); - List items = voucherResponse - .getPrintInfos(); - PrintHandle.getInstance().print(saveInfo(items), - activity); - } else { - onFailureCallback(resources - .getString(R.string.sign_not_pass)); - activity.MToast(activity, - resources.getString(R.string.sign_not_pass), - Toast.LENGTH_SHORT); - } - } else { - onFailureCallback(voucherResponse.getDescribe()); - activity.MToast(activity, voucherResponse.getDescribe(), - Toast.LENGTH_SHORT); - } - } - } - - @Override - public void onFailureCallback(String FailureStr) { - isClick.set(true); - v.setClickable(true); - if (progressDialog != null && progressDialog.isShowing()) { - try { - progressDialog.dismiss(); - } catch (Exception e) { - e.printStackTrace(); - } catch (Throwable e) { - e.printStackTrace(); - } - } - try { - activity.MToast(activity, FailureStr, Toast.LENGTH_SHORT); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void onStopCallback() { - } - } - - private LayoutInflater inflater; - private AlertDialog dialog; // 打票列表 - private View layout; - private RePrintAdapter adapter; - private ListView orderListView; - private List rePrintList; - - @SuppressLint("InflateParams") - private void dialog(final List items) { - try { - if (dialog == null) { - rePrintList = new ArrayList(); - adapter = new RePrintAdapter(activity, items, rePrintList); - inflater = LayoutInflater.from(activity); - layout = inflater.inflate(R.layout.dialog_order_consumed, null); - orderListView = (ListView) layout - .findViewById(R.id.orderListView); - orderListView.setOnItemClickListener(this); - Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.select_print); - builder.setPositiveButton(R.string.btn_ok, null); - builder.setView(layout); - builder.setNegativeButton(R.string.btn_cancel, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, - int which) { - if (dialog != null) { - dialog.dismiss(); - } - } - }); - orderListView.setAdapter(adapter); - dialog = builder.create(); - } - - if (dialog != null && !dialog.isShowing()) { - if (MyApp.getInstance().isHandset) { - dialog.getWindow().setType( - WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); - } - dialog.show(); - } - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener( - new View.OnClickListener() { - @Override - public void onClick(View v) { - getPrintInfo(items, dialog); - return; - } - }); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /********************** 获取信息,再请求 **************************/ - List orderDetailIds; - - private void getPrintInfo(List items, AlertDialog dialog) { - if (orderDetailIds == null) { - orderDetailIds = new ArrayList(); - } else { - orderDetailIds.clear(); - } - if (rePrintList != null && rePrintList.size() == 0) { - activity.MToast(activity, - activity.getString(R.string.select_at_least_one_item), - Toast.LENGTH_SHORT); - return; - } - if (dialog != null && dialog.isShowing()) { - dialog.dismiss(); - } - for (int i = 0; i < rePrintList.size(); i++) { - orderDetailIds.add(items.get(rePrintList.get(i)).getOrderDetailId() - + ""); - } - rePrintList.clear(); - HttpHelper.getInstance(activity).reprintVoucher(orid, orderDetailIds, - new ReprintInfoCallback()); - } - - /******************** 打印信息转化 *************************/ - private String list2Str(List> list) { - StringBuffer sb = new StringBuffer(); - if (list != null && list.size() > 0) { - for (LinkedHashMap temp : list) { - for (LinkedHashMap.Entry entry : temp.entrySet()) { - if (entry != null) { - if (entry.getValue() != null) { - sb.append(entry.getValue() + "\n"); - } - } - } - sb.append("\n\n\n"); - } - try {// 加了时间有问题 - if (type != null && type == 8) { - } else { - sb.append("\n"); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - return sb.toString(); - } - - @Override - public void onItemClick(AdapterView parent, View view, final int position, - long id) { - if(parent.getId()==R.id.orderListView){ - CheckBox check=(CheckBox) view.findViewById(R.id.check); - if (!check.isChecked()) { - rePrintList.add(position); - check.setChecked(true); - } else { - if (rePrintList.contains(new Integer(position))) { - rePrintList.remove(rePrintList.indexOf(new Integer(position))); - } - check.setChecked(false); - } - } - } - - - - - - /**************************打印数据******************************/ - /** - * @param PrintInfos - * @return 保存打印信息 - */ - @SuppressLint("SimpleDateFormat") - public String saveInfo(List PrintInfos) { - // 保存打印票的信息 - String[] str = null; - String orderNumber = null; - StringBuilder sb = new StringBuilder(); - for (String temp : PrintInfos) { - if (temp != null) { - - if (temp.contains("证件号码")&&temp.length()>24){ - String buf = temp.substring(13, 21); - temp = temp.replace(buf, "****"); - } - if (temp.contains(resources.getString(R.string.orderid))) { - try { - str = temp.split(resources.getString(R.string.orderid)); - orderNumber = str[1].split(":")[1].trim(); - } catch (Exception e) { - e.printStackTrace(); - } - } - sb.append(temp + "\n"); - } - } - - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式 - String currentData = df.format(new Date());// new - // Date()为获取当前系统时间 - try { - if (orderNumber != null - && DbManager.queryOrderNumber(orderNumber) == null) { - DbManager - .insertPrint(currentData, sb.toString(), str[1].trim()); - } else { - DbManager - .ModifyPrint(currentData, sb.toString(), str[1].trim()); - } - } catch (Exception e) { - e.printStackTrace(); - } - return sb.toString(); - } + List items = voucherResponse + .getPrintInfos(); + LogUtil.d("ReprintHandle",items.size()+""); + LogUtil.d("ReprintHandle2",items+""); + if (items.size() > 0) { + PrintHandle.getInstance().print(saveInfo(items), + activity); + } else { + activity.MToast(activity, + resources.getString(R.string.no_data_print), + Toast.LENGTH_SHORT); + } + } else { + onFailureCallback(resources + .getString(R.string.sign_not_pass)); + activity.MToast(activity, + resources.getString(R.string.sign_not_pass), + Toast.LENGTH_SHORT); + } + } else { + onFailureCallback(voucherResponse.getDescribe()); + activity.MToast(activity, voucherResponse.getDescribe(), + Toast.LENGTH_SHORT); + } + } + } + + @Override + public void onFailureCallback(String FailureStr) { + isClick.set(true); + v.setClickable(true); + if (progressDialog != null && progressDialog.isShowing()) { + try { + progressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + try { + activity.MToast(activity, FailureStr, Toast.LENGTH_SHORT); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void onStopCallback() { + } + } + + private LayoutInflater inflater; + private AlertDialog dialog; // 打票列表 + private View layout; + private RePrintAdapter adapter; + private ListView orderListView; + private List rePrintList; + + @SuppressLint("InflateParams") + private void dialog(final List items) { + try { + if (dialog == null) { + rePrintList = new ArrayList(); + adapter = new RePrintAdapter(activity, items, rePrintList); + inflater = LayoutInflater.from(activity); + layout = inflater.inflate(R.layout.dialog_order_consumed, null); + orderListView = (ListView) layout + .findViewById(R.id.orderListView); + orderListView.setOnItemClickListener(this); + Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(R.string.select_print); + builder.setPositiveButton(R.string.btn_ok, null); + builder.setView(layout); + builder.setNegativeButton(R.string.btn_cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, + int which) { + if (dialog != null) { + dialog.dismiss(); + } + } + }); + orderListView.setAdapter(adapter); + dialog = builder.create(); + } + + if (dialog != null && !dialog.isShowing()) { + if (MyApp.getInstance().isHandset) { + dialog.getWindow().setType( + WindowManager.LayoutParams.TYPE_SYSTEM_ERROR); + } + dialog.show(); + } + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + getPrintInfo(items, dialog); + return; + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /********************** 获取信息,再请求 **************************/ + List orderDetailIds; + + private void getPrintInfo(List items, AlertDialog dialog) { + if (orderDetailIds == null) { + orderDetailIds = new ArrayList(); + } else { + orderDetailIds.clear(); + } + if (rePrintList != null && rePrintList.size() == 0) { + activity.MToast(activity, + activity.getString(R.string.select_at_least_one_item), + Toast.LENGTH_SHORT); + return; + } + if (dialog != null && dialog.isShowing()) { + dialog.dismiss(); + } + for (int i = 0; i < rePrintList.size(); i++) { + orderDetailIds.add(items.get(rePrintList.get(i)).getOrderDetailId() + + ""); + } + rePrintList.clear(); + HttpHelper.getInstance(activity).reprintVoucher(orid, orderDetailIds, + new ReprintInfoCallback()); + } + + /******************** 打印信息转化 *************************/ + private String list2Str(List> list) { + StringBuffer sb = new StringBuffer(); + if (list != null && list.size() > 0) { + for (LinkedHashMap temp : list) { + for (LinkedHashMap.Entry entry : temp.entrySet()) { + if (entry != null) { + if (entry.getValue() != null) { + sb.append(entry.getValue() + "\n"); + } + } + } + sb.append("\n\n\n"); + } + try {// 加了时间有问题 + if (type != null && type == 8) { + } else { + sb.append("\n"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return sb.toString(); + } + + @Override + public void onItemClick(AdapterView parent, View view, final int position, + long id) { + if (parent.getId() == R.id.orderListView) { + CheckBox check = (CheckBox) view.findViewById(R.id.check); + if (!check.isChecked()) { + rePrintList.add(position); + check.setChecked(true); + } else { + if (rePrintList.contains(new Integer(position))) { + rePrintList.remove(rePrintList.indexOf(new Integer(position))); + } + check.setChecked(false); + } + } + } + + + /**************************打印数据******************************/ + /** + * @param PrintInfos + * @return 保存打印信息 + */ + @SuppressLint("SimpleDateFormat") + public String saveInfo(List PrintInfos) { + // 保存打印票的信息 + String[] str = null; + String orderNumber = null; + StringBuilder sb = new StringBuilder(); + for (String temp : PrintInfos) { + if (temp != null) { + + if (temp.contains("证件号码") && temp.length() > 24) { + String buf = temp.substring(13, 21); + temp = temp.replace(buf, "****"); + } + if (temp.contains(resources.getString(R.string.orderid))) { + try { + str = temp.split(resources.getString(R.string.orderid)); + orderNumber = str[1].split(":")[1].trim(); + } catch (Exception e) { + e.printStackTrace(); + } + } + sb.append(temp + "\n"); + } + } + + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 设置日期格式 + String currentData = df.format(new Date());// new + // Date()为获取当前系统时间 + try { + if (orderNumber != null + && DbManager.queryOrderNumber(orderNumber) == null) { + DbManager + .insertPrint(currentData, sb.toString(), str[1].trim()); + } else { + DbManager + .ModifyPrint(currentData, sb.toString(), str[1].trim()); + } + } catch (Exception e) { + e.printStackTrace(); + } + return sb.toString(); + } } diff --git a/src/com/ectrip/cyt/request/ConsumeCodeRequest.java b/src/com/ectrip/cyt/request/ConsumeCodeRequest.java new file mode 100644 index 0000000..5c1a8ee --- /dev/null +++ b/src/com/ectrip/cyt/request/ConsumeCodeRequest.java @@ -0,0 +1,190 @@ +package com.ectrip.cyt.request; + +import com.ectrip.cyt.base.Request; + +import java.util.List; + +/** + * 作者:dufang on 2026/3/3 17:07 + */ +public class ConsumeCodeRequest extends Request { + public String orderId;// 订单 ID + public String consumedAmount;// 消费数量 + public String password;// 密码 + public String verifyPassword;// 验证密码 + private Long accountId; //操作员ID + public List products;//产品信息 + private String voucher; + + public String consumedSeq;//流水号 + public String code; + public String credentials; + public String note2;// + public String note3;// + public String note4;// + public String note5;// + public String note6;// + public String note7;// + public String note8;// + + public ConsumeCodeRequest(String orderId, String consumeCount, + String password, String verifyPassword,String consumedSeq,List products) { + super(); + this.orderId = orderId; + this.consumedAmount = consumeCount; + this.password = password; + this.verifyPassword = verifyPassword; + this.products = products; + this.consumedSeq = consumedSeq; + + } + + public void setOrderId(String orderId) { + this.orderId = orderId; + } + + public String getOrderId() { + + return orderId; + } + + public void setAccountId(Long accountId) { + + this.accountId = accountId; + } + + public Long getAccountId() { + + return accountId; + } + + public List getProducts() { + return products; + } + + public void setProducts(List products) { + this.products = products; + } + + public String getorderId() { + return orderId; + } + + public void setorderId(String orderId) { + this.orderId = orderId; + } + + public String getConsumedAmount() { + return consumedAmount; + } + + public void setConsumedAmount(String consumedAmount) { + this.consumedAmount = consumedAmount; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getVerifyPassword() { + return verifyPassword; + } + + public void setVerifyPassword(String verifyPassword) { + this.verifyPassword = verifyPassword; + } + + public String getConsumedSeq() { + return consumedSeq; + } + + public void setConsumedSeq(String consumedSeq) { + this.consumedSeq = consumedSeq; + } + + public String getNote2() { + return note2; + } + + public void setNote2(String note2) { + this.note2 = note2; + } + + public String getNote3() { + return note3; + } + + public void setNote3(String note3) { + this.note3 = note3; + } + + public String getNote4() { + return note4; + } + + public void setNote4(String note4) { + this.note4 = note4; + } + + public String getNote5() { + return note5; + } + + public void setNote5(String note5) { + this.note5 = note5; + } + + public String getNote6() { + return note6; + } + + public void setNote6(String note6) { + this.note6 = note6; + } + + public String getNote7() { + return note7; + } + + public void setNote7(String note7) { + this.note7 = note7; + } + + public String getNote8() { + return note8; + } + + public void setNote8(String note8) { + this.note8 = note8; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getCredentials() { + return credentials; + } + + public void setCredentials(String credentials) { + this.credentials = credentials; + } + + public String getVoucher() { + return voucher; + } + + public void setVoucher(String voucher) { + this.voucher = voucher; + }{ + + } +} diff --git a/src/com/ectrip/cyt/ui/MainActivity.java b/src/com/ectrip/cyt/ui/MainActivity.java index 94a22b6..5f96213 100644 --- a/src/com/ectrip/cyt/ui/MainActivity.java +++ b/src/com/ectrip/cyt/ui/MainActivity.java @@ -162,7 +162,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V // 得到存储的类型 Integer type = SharedPreferences2Obj.getInstance(MainActivity.this) .setName("MachineType").getObject("type", Integer.class); - + LogUtil.d(TAG, "MachineType = " + type); //如果未存储类型 if (type == null || type == 0) { DisplayMetrics metrics = new DisplayMetrics(); diff --git a/src/com/ectrip/cyt/ui/PhomeScanerOrderActivity.java b/src/com/ectrip/cyt/ui/PhomeScanerOrderActivity.java index d345aa4..b658c0c 100644 --- a/src/com/ectrip/cyt/ui/PhomeScanerOrderActivity.java +++ b/src/com/ectrip/cyt/ui/PhomeScanerOrderActivity.java @@ -181,10 +181,10 @@ public class PhomeScanerOrderActivity extends BaseActivity implements Callback { } catch (Exception e) { e.printStackTrace(); } - Intent intent; + Intent intent = null; if (resultString.startsWith("OCP_")) { - intent = new Intent(PhomeScanerOrderActivity.this, - PhoneCodeListActivity.class); +// intent = new Intent(PhomeScanerOrderActivity.this, +// PhoneCodeListActivity.class); } else { intent = new Intent(PhomeScanerOrderActivity.this, QRCodeOrderListActivity.class);