Exemplo n.º 1
0
 @Override
 public void onClick(View v) {
   // TODO 自动生成的方法存根
   btSent = false;
   String bufString =
       "QUERY□" + barcode.getText().toString() + "□" + "DH001" + "□" + "UD" + "□" + "CK001";
   barString = barcode.getText().toString().trim();
   if (isconnect) {
     isSearchinf = true;
     mysocket.writeData(SYS.SenData(bufString, fwq, androidID));
   } else {
     SearchINF(barcode.getText().toString());
   }
 }
Exemplo n.º 2
0
 /*条码扫描返回的结果处理*/
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   String bufString = "";
   switch (requestCode) {
     case SCANNIN_GREQUEST_CODE:
       if (resultCode == RESULT_OK) {
         Bundle bundle = data.getExtras();
         barcode.setText(bundle.getString("result"));
         btSent = false;
         bufString =
             "QUERY□" + barcode.getText().toString() + "□" + "DH001" + "□" + "UD" + "□" + "CK001";
         barString = barcode.getText().toString().trim();
         /*发送查询指令*/
         if (isconnect) {
           isSearchinf = true;
           mysocket.writeData(SYS.SenData(bufString, fwq, androidID));
         } else {
           SearchINF(barcode.getText().toString());
         }
       }
       break;
     case REQUEST_CONNECT_DEVICE:
       if (resultCode == RESULT_OK) {
         String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
         WriteReadSD.writex(address, "BTMAC", log.fdir);
         _device = MainActivity._bluetooth.getRemoteDevice(address);
         RKScan.mChatService.connect(_device);
       }
       break;
     case REQUEST_ENABLE_BT:
       // 判断蓝牙是否启用
       if (resultCode == Activity.RESULT_OK) {
         setupChat();
       } else {
         finish();
       }
       break;
     case 4:
       if (resultCode == RESULT_OK) {
         String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
         _device = MainActivity._bluetooth.getRemoteDevice(address);
         WriteReadSD.writex(address, "PTMAC", log.fdir); // 存放打印机的地址
         RKScan.printService.connect(_device);
       }
       break;
   }
 }
Exemplo n.º 3
0
        @Override
        public void onClick(View v) {
          // TODO 自动生成的方法存根

          String string = "";
          int len = 0;
          string = pass.getText().toString();
          if (string.length() < 0) {
            Toast.makeText(Register.this, "注册码不能为空!", Toast.LENGTH_SHORT).show();

          } else {
            try {
              len = SYS.crc_r(androidID.getBytes(bm), androidID.getBytes(bm).length);
              len = len % 99;
            } catch (UnsupportedEncodingException e) {
              // TODO 自动生成的 catch 块
              e.printStackTrace();
            }

            String s = String.format("%02d", len);
            String pasString =
                androidID.substring(1, 2)
                    + s
                    + androidID.substring(9, 10)
                    + androidID.substring(5, 6)
                    + androidID.substring(6, 7);
            System.out.println("密码:" + pasString);
            if (pasString.equals(string)) {

              SQLiteDatabase dw =
                  LoginOpenHelper.getInstance(mContext, log.DB_NAME).getWritableDatabase();
              ContentValues values = new ContentValues();
              values.put("mm", string);
              String where = "zcm = ? ";
              String[] whereValue = {androidID};
              dw.update("ZC", values, where, whereValue);
              log.isRes = true;
              Register.this.finish();
              Intent intent = new Intent();
              intent.setClass(Register.this, YGDL.class);
              startActivity(intent);
            } else {
              Toast.makeText(Register.this, "注册码错误", Toast.LENGTH_SHORT).show();
            }
          }
        }
Exemplo n.º 4
0
        public void handleMessage(Message msg) {

          super.handleMessage(msg);
          switch (msg.what) {
            case 54:
              byte[] writeBuf = (byte[]) msg.obj;
              String writeMessage = new String(writeBuf);
              System.out.println(writeMessage);
              break;
            case 17: // 获取接收到的数据
              String name = msg.getData().getString("REC");
              String num = "";
              int len = 0;
              String sqlString =
                  new String().format("talk%s%s%s%s,", "□", androidID, "□条码,", barString);
              String sql =
                  new String().format("talk%s%s%s%s,%s", "□", androidID, "□", barString, "无-");
              String[] string = null;
              String[] buf = null;
              if (isSearchinf) {
                isSearchinf = false;
                if (SYS.indexofString(name, sqlString)) {
                  buf = SYS.splitString(name.trim(), "■");
                  try {
                    len = SYS.crc_r(buf[0].getBytes(bm), buf[0].getBytes(bm).length);
                    len = len % 99;
                    if (len == Integer.parseInt(buf[1].trim())) {
                      string = SYS.splitString(buf[0], ",");

                      b1.setText(string[2]);
                      b2.setText(string[4]);
                      b3.setText(string[6]);
                      b4.setText(string[8]);
                      b5.setText(string[10]);
                      b6.setText(string[12]);
                      b7.setText(string[14]);
                      b8.setText(string[16]);
                      b9.setText(string[18]);
                      b10.setText(string[20]);
                      inf1.setText(string[3]);
                      inf2.setText(string[5]);
                      inf3.setText(string[7]);
                      inf4.setText(string[9]);
                      inf5.setText(string[11]);
                      inf6.setText(string[13]);
                      inf7.setText(string[15]);
                      inf8.setText(string[17]);
                      inf9.setText(string[19]);
                      inf10.setText(string[21]);

                      isSearchOK = true;
                    } else {
                      isSearchOK = false;
                    }
                  } catch (UnsupportedEncodingException e) {
                    // TODO 自动生成的 catch 块
                    e.printStackTrace();
                    isSearchOK = false;
                  }
                } else if (SYS.indexofString(name, sql)) {
                  isSearchOK = false;
                  SearchINF(barcode.getText().toString());
                  isSearchOK = false;
                } else {
                  isSearchOK = false;
                }
              } else {
                isSent = false;
                if (Running >= 20) num = "01";
                else num = String.format("%02d", Running + 1);
                String bufx = "talk" + "□" + androidID + "□" + num + "□";
                try {
                  len = SYS.crc_r(bufx.getBytes(bm), bufx.getBytes(bm).length);
                  len = len % 99;
                  bufx = bufx + "■" + String.format("%02d", len) + "■";
                  if (bufx.equals(name)) {
                    SQLiteDatabase dbe =
                        LoginOpenHelper.getInstance(mContext, log.DB_NAME).getWritableDatabase();
                    ContentValues values = new ContentValues();
                    values.put("ISsent", "0"); // 这个表示的是已传
                    dbe.update("SENT", values, "BAR=? and BH=?", new String[] {SentData, BH});
                    Log.e("条码:", SentData);
                    SentData = "";
                    BH = "";
                    if (Running >= 20) Running = 1;
                    else Running++;
                    if (MainActivity.sentpovit < MainActivity.sentall) MainActivity.sentpovit++;
                    yc.setText("已传:" + MainActivity.sentpovit + "");
                    wc.setText("未传:" + (MainActivity.sentall - MainActivity.sentpovit) + "");
                  } else {
                    if (Running > 20) Running++;
                  }
                } catch (UnsupportedEncodingException e) {
                  // TODO 自动生成的 catch 块
                  e.printStackTrace();
                  if (Running > 20) Running++;
                }
              }

              break;
            case 1: // 这个是蓝牙状态的,用蓝牙名称来区分是蓝牙枪还是打印机
              String btname = msg.getData().getString(MainActivity.DEVICE_NAME);
              switch (msg.arg1) {
                case BluetoothChatService.STATE_CONNECTED:
                  if (SYS.indexofString(btname, BTNAME) || SYS.indexofString(btname, "HC")) {
                    btzt.setText(R.string.title_connected_to);
                    RKScan.Isbt = true;
                  } else {
                    RKScan.isPrint = true;
                    printTextView.setText(R.string.printer_connected_to);
                  }
                  break;
                case BluetoothChatService.STATE_CONNECTING:
                  if (SYS.indexofString(btname, BTNAME) || SYS.indexofString(btname, "HC"))
                    btzt.setText(R.string.title_connecting);
                  else {
                    printTextView.setText(R.string.printer_connecting);
                  }
                  break;
                case BluetoothChatService.STATE_LISTEN:
                  if (SYS.indexofString(btname, BTNAME) || SYS.indexofString(btname, "HC")) {
                    RKScan.Isbt = false;
                    btzt.setText(R.string.title_not_connected);
                  } else {
                    RKScan.isPrint = false;
                    printTextView.setText(R.string.printer_not_connected);
                    // printerTextView.setText(R.string.printer_connecting);
                  }
                  break;
                case BluetoothChatService.STATE_NONE:
                  if (SYS.indexofString(btname, BTNAME) || SYS.indexofString(btname, "HC")) {
                    btzt.setText(R.string.title_not_connected);
                    RKScan.Isbt = false;
                  } else {
                    RKScan.isPrint = false;
                    printTextView.setText(R.string.printer_not_connected);
                  }
                  break;
              }
              break;
            case 4:
              // 保存该连接装置的名字
              String name1 = msg.getData().getString(MainActivity.DEVICE_NAME);
              System.out.println("蓝牙名称是:" + name1);
              if (SYS.indexofString(name1, BTNAME) || SYS.indexofString(name1, "HC")) {
                btzt.setText(R.string.title_connected_to);
                RKScan.Isbt = true;
              } else {
                RKScan.isPrint = true;
                printTextView.setText(R.string.printer_connected_to);
              }
              break;
            case 16:
              switch (msg.arg1) {
                case 0:
                  ConnectButton.setText(R.string.Noconnected);
                  // vibrator.vibrate(800);
                  isconnect = false; // 网络连接失败
                  break;
                case 1:
                  ConnectButton.setText(R.string.Noconnected);
                  // vibrator.vibrate(800);
                  isconnect = false;
                  break;
                case 2:
                  ConnectButton.setText(R.string.connectting);
                  break;
                case 3:
                  ConnectButton.setText(R.string.SKconnected);
                  isconnect = true;
                  break;
                case 7:
                  ConnectButton.setText(R.string.Noconnected);
                  isconnect = false;
                  break;
                case 6:
                  if (isSearchinf) {
                    isSearchinf = false;
                    SearchINF(barcode.getText().toString());
                  }
                  if (isSent) {
                    if (Running > 21) Running++;
                  }
                  break;
                default:
                  break;
              }
              break;
            case 13:
              byte[] readBuf = (byte[]) msg.obj;
              try {
                String s = new String(readBuf, 0, msg.arg1, bm);
                recvMessageserver += s;
                if (recvMessageserver
                    .substring(recvMessageserver.length() - 1, recvMessageserver.length())
                    .equals("\n")) {
                  recvMessageClient = recvMessageserver;
                  String bar = "";
                  String bufString = "";
                  bar = SYS.BTistrue(recvMessageserver);
                  recvMessageserver = "";
                  if (bar.length() > 0) {
                    btSent = true;
                    MainActivity.playScanOK(mContext);
                    recvMessageClient = "";
                    barcode.setText(bar);
                    barString = bar;
                    inf1.setText("");
                    inf2.setText("");
                    inf3.setText("");
                    inf4.setText("");
                    inf5.setText("");
                    inf6.setText("");
                    inf7.setText("");
                    inf8.setText("");
                    inf9.setText("");
                    inf10.setText("");
                    bufString =
                        "QUERY□"
                            + barcode.getText().toString()
                            + "□"
                            + "DH001"
                            + "□"
                            + "UD"
                            + "□"
                            + "CK001";
                    /*发送查询指令*/
                    if (isconnect) {
                      isSearchinf = true;
                      mysocket.writeData(SYS.SenData(bufString, fwq, androidID));
                    } else {
                      SearchINF(barcode.getText().toString());
                    }
                  } else {
                    String btpowerString = SYS.BTisPOWER(recvMessageClient);
                    if (btpowerString.length() > 0) {
                      MainActivity.BTPOWER = btpowerString;
                      BTpower.setText(R.string.power);
                      BTpower.append(MainActivity.BTPOWER + "");
                      BTpower.append("%");
                    } else {
                      /*dis.setText("");
                      			sView.scrollTo(0,dis.getMeasuredHeight());
                      SYS.disPlay(sView, dis,R.string.SB+"\n");*/
                      return;
                    }
                  }
                  BTpower.setText(R.string.power);
                  BTpower.append(MainActivity.BTPOWER + "");
                  BTpower.append("%");
                }
              } catch (UnsupportedEncodingException e) {
                // TODO 自动生成的 catch 块
                e.printStackTrace();
              }
              break;
            case 38:
              Log.i("基本资料进来", Running + "");
              SentData = "";
              BH = "";
              // LoginOpenHelper tb=new  LoginOpenHelper(JBZL.this,"AndroidPosJxc.db", null, 1);
              SQLiteDatabase db =
                  LoginOpenHelper.getInstance(mContext, log.DB_NAME).getReadableDatabase();
              Cursor cursor = null;
              try {
                cursor =
                    db.query(
                        "SENT",
                        new String[] {"BAR", "ISsent", "BH"},
                        "ISsent= ?",
                        new String[] {"1"},
                        null,
                        null,
                        null);
                if (cursor != null) {
                  if (cursor.getCount() != 0 && cursor.moveToFirst()) {
                    SentData = cursor.getString(cursor.getColumnIndex("BAR"));
                    BH = cursor.getString(cursor.getColumnIndex("BH"));
                    if (MainActivity.sentall > MainActivity.sentpovit && isconnect && !isSent) {
                      Log.i("发送的数据:", SentData + ":" + BH);
                      mysocket.writeData(SYS.SenData(SentData, fwq, androidID, Running));
                      isSent = true;
                    } else {
                      return;
                    }
                  }
                } else {
                  Log.i("没有啊", "*****");
                }
              } catch (Exception e) {
                Log.i("也没有啊", "*****");
                // return ;
              } finally {
                if (cursor != null) {
                  cursor.close();
                }
              }
              break;
            default:
              break;
          }
        }
Exemplo n.º 5
0
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mContext = this;
    TelephonyManager telephonyManager =
        (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    androidID = telephonyManager.getDeviceId();
    String[] str = null;
    /*读取文件获取员工编号和IP,端口号*/
    setContentView(R.layout.jbzl);
    btzt = (TextView) findViewById(R.id.zlbt);
    yc = (TextView) findViewById(R.id.zlrk);
    wc = (TextView) findViewById(R.id.zlwc);
    Running = 21;
    b1 = (Button) findViewById(R.id.B2);
    b2 = (Button) findViewById(R.id.B3);
    b3 = (Button) findViewById(R.id.B4);
    b4 = (Button) findViewById(R.id.B5);
    b5 = (Button) findViewById(R.id.B6);
    b6 = (Button) findViewById(R.id.B7);
    b7 = (Button) findViewById(R.id.B8);
    b8 = (Button) findViewById(R.id.B9);
    b9 = (Button) findViewById(R.id.B10);
    b10 = (Button) findViewById(R.id.B1);

    inf1 = (EditText) findViewById(R.id.E1);
    inf2 = (EditText) findViewById(R.id.E2);
    inf3 = (EditText) findViewById(R.id.E3);
    inf4 = (EditText) findViewById(R.id.E4);
    inf5 = (EditText) findViewById(R.id.E5);
    inf6 = (EditText) findViewById(R.id.E6);
    inf7 = (EditText) findViewById(R.id.E7);
    inf8 = (EditText) findViewById(R.id.E8);
    inf9 = (EditText) findViewById(R.id.E9);
    inf10 = (EditText) findViewById(R.id.E10);
    printTextView = (TextView) findViewById(R.id.jbprint);
    String[] bufx = null;
    priString = WriteReadSD.read("isPrint", log.fdir);
    File file = new File(log.pdir, "商品资料.TXT");
    if (file.exists()) {
      String[] bufStrings = null;
      Text_of_output = null;
      Text_of_output = WriteReadSD.readline("商品资料.TXT", log.pdir);
      if (Text_of_output.trim().length() > 0) {
        bufStrings = SYS.splitString(Text_of_output.trim(), "\n");
        System.out.println("抬头是:" + bufStrings[0].trim());

        bufx = SYS.splitString(bufStrings[0].trim(), "\t");
        for (int i = 0; i < 11; i++) {
          System.out.println(bufx[i].trim());
        }
        b1.setText(bufx[1].trim());
        b2.setText(bufx[2].trim());
        b3.setText(bufx[3].trim());
        b4.setText(bufx[4].trim());
        b5.setText(bufx[5].trim());
        b6.setText(bufx[6].trim());
        b7.setText(bufx[7].trim());
        b8.setText(bufx[8].trim());
        b9.setText(bufx[9].trim());
        b10.setText(bufx[10].trim());

      } else {
        bufx = new String[] {"条码", "名称", "货号", "规格", "型号", "进价", "售价", "单位", "备注一", "备注二", "备注三"};
      }
    } else {
      bufx = new String[] {"条码", "名称", "货号", "规格", "型号", "进价", "售价", "单位", "备注一", "备注二", "备注三"};
    }
    /*打印属性*/
    sx1 = WriteReadSD.read("Print1", log.fdir);
    if (sx1.trim().equals("-1")) sx11 = "";
    else {
      sx11 = bufx[Integer.parseInt(sx1) + 1];
    }
    sx2 = WriteReadSD.read("Print2", log.fdir);
    if (sx2.trim().equals("-1")) sx12 = "";
    else {
      sx12 = bufx[Integer.parseInt(sx2) + 1];
    }
    yc.setText(R.string.Transferall);
    wc.setText(R.string.Transferpovit);
    yc.append(MainActivity.sentpovit + "");
    wc.append((MainActivity.sentall - MainActivity.sentpovit) + "");
    BTpower = (TextView) findViewById(R.id.zlDL);
    BTpower.setText(R.string.power);
    sjsm = (Button) findViewById(R.id.zlSJ);
    sendButton = (Button) findViewById(R.id.zlbc);
    ConnectButton = (Button) findViewById(R.id.zllj);
    printTextView.setOnClickListener(printClickListener);
    vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
    btzt.setOnClickListener(Btset);
    barcode = (EditText) findViewById(R.id.zl_sendmessage);
    Text_of_output = "";
    Text_of_output = WriteReadSD.read("IP", log.fdir);
    if (Text_of_output.length() > 0) {
      str = SYS.splitString(Text_of_output.trim(), ":");
      iPString = str[0].trim();
      portString = str[1].trim();
    } else {
      //  sys.disPlay(sView, dis, getString(R.string.Noset)+"\n");   //显示数据
    }
    Text_of_output = "";
    Text_of_output = WriteReadSD.read("FWQM", log.fdir);
    if (Text_of_output.length() > 0) {
      fwq = Text_of_output.trim();
    } else {
      fwq = "RS";
    }
    mysocket = new mySocket(mContext, mHandler, iPString, Integer.parseInt(portString));
    if (iPString.length() > 0 && mysocket.getState() == mySocket.STATE_NONE) {
      mysocket.connect();
    } else {
      ConnectButton.setText(R.string.SKconnected);
    }
    if (iPString.length() > 0) {
      ConnectButton.setOnClickListener(socketconnect);
    }

    if (!RKScan.Isbt) {
      btzt.setText(R.string.title_not_connected);
    } else {
      btzt.setText(R.string.title_connected_to);
    }
    if (!RKScan.isPrint) {
      printTextView.setText(R.string.printer_not_connected);
    } else {
      printTextView.setText(R.string.printer_connected_to);
    }
    if (RKScan.setInf) {
      String barcodeString = getIntent().getStringExtra("BARCODE");
      if (barcodeString.trim().length() > 0) {
        barcode.setText(barcodeString);
        SearchINF(barcodeString.trim());
      }
    }
    mHandler.postDelayed(socketRunnable, 50);
    mHandler.postDelayed(btRunnable, 5000);
    mHandler.postDelayed(printRunnable, 5000);
    mHandler.postDelayed(socketConnect, 1000 * 60);
    btzt.setOnClickListener(Btset);
    Button search = (Button) findViewById(R.id.zlSear);
    search.setOnClickListener(searchon);
    sjsm.setOnClickListener(scanClickListener);
    sendButton.setOnClickListener(sent);
  }