private static void fillDetail(DBCon dbCon, Staff staff, WxOrder wxOrder)
     throws SQLException, BusinessException {
   String sql;
   sql =
       " SELECT * FROM "
           + Params.dbName
           + ".weixin_order_food WHERE wx_order_id = "
           + wxOrder.getId();
   dbCon.rs = dbCon.stmt.executeQuery(sql);
   while (dbCon.rs.next()) {
     OrderFood of = new OrderFood();
     of.asFood().copyFrom(FoodDao.getById(staff, dbCon.rs.getInt("food_id")));
     of.setCount(dbCon.rs.getFloat("food_count"));
     wxOrder.addFood(of);
   }
   dbCon.rs.close();
   wxOrder.setMember(MemberDao.getByWxSerial(dbCon, staff, wxOrder.getWeixinSerial()));
 }
  private static int insert(DBCon dbCon, Staff staff, WxOrder wxOrder)
      throws SQLException, BusinessException {

    String sql;

    // Check to see whether the member to this weixin serial exist.
    if (MemberDao.getByCond(
            dbCon,
            staff,
            new MemberDao.ExtraCond().setWeixinSerial(wxOrder.getWeixinSerial()),
            null)
        .isEmpty()) {
      throw new BusinessException("微信序列号对应的会员不存在", MemberError.MEMBER_NOT_EXIST);
    }

    // Generate the operation code.
    sql =
        " SELECT IFNULL(MAX(code) + 1, 100) FROM "
            + Params.dbName
            + ".weixin_order WHERE restaurant_id = "
            + staff.getRestaurantId();
    dbCon.rs = dbCon.stmt.executeQuery(sql);
    int code = 0;
    if (dbCon.rs.next()) {
      code = dbCon.rs.getInt(1);
    }
    dbCon.rs.close();

    // Insert the weixin order.
    sql =
        " INSERT INTO "
            + Params.dbName
            + ".`weixin_order` "
            + " (restaurant_id, weixin_serial, weixin_serial_crc, birth_date, status, type, code) "
            + " VALUES( "
            + staff.getRestaurantId()
            + ","
            + "'"
            + wxOrder.getWeixinSerial()
            + "',"
            + "CRC32('"
            + wxOrder.getWeixinSerial()
            + "'),"
            + " NOW(), "
            + wxOrder.getStatus().getVal()
            + ","
            + wxOrder.getType().getVal()
            + ","
            + code
            + " ) ";
    dbCon.stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
    dbCon.rs = dbCon.stmt.getGeneratedKeys();
    int wxOrderId;
    if (dbCon.rs.next()) {
      wxOrderId = dbCon.rs.getInt(1);
    } else {
      throw new SQLException("The id to wx order is NOT generated successfully.");
    }
    dbCon.rs.close();

    // Insert the associated order foods.
    for (OrderFood of : wxOrder.getFoods()) {
      sql =
          " INSERT INTO "
              + Params.dbName
              + ".weixin_order_food "
              + " (wx_order_id, food_id, food_count) VALUES( "
              + wxOrderId
              + ","
              + of.getFoodId()
              + ","
              + of.getCount()
              + ")";
      dbCon.stmt.executeUpdate(sql);
    }

    return wxOrderId;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.pick_taste_by_pinzhu_fgm, container, false);

    final OrderFoodParcel orderFroodParcel =
        getArguments().getParcelable(OrderFoodParcel.KEY_VALUE);
    final ComboOrderFoodParcel comboParcel =
        getArguments().getParcelable(ComboOrderFoodParcel.KEY_VALUE);

    final EditText pinZhuEdtTxt = ((EditText) view.findViewById(R.id.txtView_pinzhu_pickPinzhuFgm));
    final EditText priceEdtTxt = ((EditText) view.findViewById(R.id.edtTxt_price_pickPinzhuFgm));

    if (orderFroodParcel != null) {
      OrderFood selectedFood = orderFroodParcel.asOrderFood();
      mPinZhu = selectedFood.getTasteGroup().getTmpTastePref();
      mPriceToPinZhu = selectedFood.getTasteGroup().getTmpTastePrice();

      if (selectedFood.hasTmpTaste()) {
        pinZhuEdtTxt.setText(mPinZhu);
        priceEdtTxt.setText(NumericUtil.float2String2(mPriceToPinZhu));
      }

    } else if (comboParcel != null) {
      ComboOrderFood comboFood = comboParcel.asComboOrderFood();
      mPinZhu = comboFood.getTasteGroup().getTmpTastePref();
      mPriceToPinZhu = comboFood.getTasteGroup().getTmpTastePrice();

      if (comboFood.hasTmpTaste()) {
        pinZhuEdtTxt.setText(mPinZhu);
        priceEdtTxt.setText(NumericUtil.float2String2(mPriceToPinZhu));
      }
    }

    // Request pinzhu focus and show soft keyboard automatically and select all the content
    pinZhuEdtTxt.setOnFocusChangeListener(
        new OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
              pinZhuEdtTxt.post(
                  new Runnable() {
                    @Override
                    public void run() {
                      pinZhuEdtTxt.selectAll();
                      InputMethodManager imm =
                          (InputMethodManager)
                              getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                      imm.showSoftInput(pinZhuEdtTxt, InputMethodManager.SHOW_IMPLICIT);
                      pinZhuEdtTxt.setOnFocusChangeListener(null);
                    }
                  });
            }
          }
        });
    pinZhuEdtTxt.requestFocus();

    // 点击品注EditText后全选内容并弹出软键盘
    //		pinZhuEdtTxt.setOnTouchListener(new OnTouchListener(){
    //			@Override
    //			public boolean onTouch(final View v, MotionEvent event) {
    //				v.postDelayed(new Runnable(){
    //					@Override
    //					public void run() {
    //						pinZhuEdtTxt.selectAll();
    //					}
    //
    //				}, 100);
    //				return false;
    //			}
    //
    //        });

    // 品注的EditText的处理函数
    pinZhuEdtTxt.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void afterTextChanged(Editable s) {
            mPinZhu = s.toString().trim();

            final Taste tmpTaste;
            if (mPinZhu.length() != 0 || mPriceToPinZhu != 0) {
              tmpTaste = Taste.newTmpTaste(mPinZhu, mPriceToPinZhu);
            } else {
              tmpTaste = null;
            }

            if (orderFroodParcel != null) {
              orderFroodParcel.asOrderFood().setTmpTaste(tmpTaste);
            } else if (comboParcel != null) {
              comboParcel.asComboOrderFood().setTmpTaste(tmpTaste);
            }
            if (mTmpTastePickedListener != null) {
              mTmpTastePickedListener.onTmpTastePicked(tmpTaste);
            }
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });

    // 品注的删除Button处理函数
    ((ImageButton) view.findViewById(R.id.imgButton_deletePinZhu_pickPinzhuFgm))
        .setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                pinZhuEdtTxt.setText("");
              }
            });

    // 点击价钱EditText后全选内容并弹出软键盘
    //		priceEdtTxt.setOnTouchListener(new OnTouchListener(){
    //			@Override
    //			public boolean onTouch(View v, MotionEvent event) {
    //				v.postDelayed(new Runnable(){
    //					@Override
    //					public void run() {
    //						priceEdtTxt.selectAll();
    //					}
    //
    //				}, 100);
    //				return false;
    //			}
    //
    //        });

    // 价格EditText的处理函数
    priceEdtTxt.addTextChangedListener(
        new TextWatcher() {

          @Override
          public void afterTextChanged(Editable s) {

            try {
              if (s.toString().trim().length() == 0) {
                mPriceToPinZhu = 0;

              } else if (s.toString().trim().length() > 0) {
                mPriceToPinZhu = Float.valueOf(s.toString());
              }

              final Taste tmpTaste;
              if (mPinZhu.length() != 0 || mPriceToPinZhu != 0) {
                tmpTaste = Taste.newTmpTaste(mPinZhu, mPriceToPinZhu);
              } else {
                tmpTaste = null;
              }

              if (orderFroodParcel != null) {
                orderFroodParcel.asOrderFood().setTmpTaste(tmpTaste);
              } else if (comboParcel != null) {
                comboParcel.asComboOrderFood().setTmpTaste(tmpTaste);
              }
              if (mTmpTastePickedListener != null) {
                mTmpTastePickedListener.onTmpTastePicked(tmpTaste);
              }

            } catch (NumberFormatException e) {
              Toast.makeText(getActivity(), "临时口味的价钱格式不正确,请重新输入", Toast.LENGTH_SHORT).show();
            }
          }

          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });

    // 品注价钱的删除Button处理函数
    ((ImageButton) view.findViewById(R.id.imgButton_deletePrice_pickPinzhuFgm))
        .setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                priceEdtTxt.setText("");
              }
            });

    return view;
  }