Exemplo n.º 1
0
  public String saveMyCustomer() throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();

    String json = "";

    String flag = StringUtil.formatNullString(request.getParameter("flag"));
    String ischeck = StringUtil.formatNullString(request.getParameter("ischeck"));
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("shop_no,string," + myCustomer.getShop_no().trim());
    arrayList.add("pos_no,string," + myCustomer.getPos_no().trim());
    arrayList.add("pan,string," + myCustomer.getPan().trim());
    List myCustomerList = myCustomerBean.execHql("myCustomer", "findMyCustomer", arrayList);

    MyCustomer mc = null;
    if (myCustomerList != null && !myCustomerList.isEmpty()) {
      mc = (MyCustomer) myCustomerList.get(0);
    }
    if (!flag.equalsIgnoreCase("edit") && mc != null) {
      json = DATA_EXIST_EXCEPTION; // 数据存在异常
    } else {
      if (flag.equalsIgnoreCase("new") && !ischeck.equalsIgnoreCase("check")) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat timeFormat = new SimpleDateFormat("HHmmss");
        Date now = new Date();
        String nowDate = dateFormat.format(now);
        // 加上rec_no
        String rec_no = myCustomerBean.getMaxId("myCustomer", "getMaxId", null);
        myCustomer.setRec_no(Integer.parseInt(rec_no));
        myCustomer.setRegister_date(nowDate);
        myCustomerBean.addData(myCustomer);
        json = SAVE_SUCCESS;
      }
      if (flag.equalsIgnoreCase("edit") && !ischeck.equalsIgnoreCase("check")) {
        myCustomer.setShop_no(mc.getShop_no());
        myCustomer.setPos_no(mc.getPos_no());
        myCustomer.setPan(mc.getPan());
        myCustomer.setRec_no(mc.getRec_no());

        myCustomer.setRegister_date(mc.getRegister_date());

        myCustomerBean.updateData(myCustomer);
        json = UPDATE_SUCCESS;
      }
      if (ischeck.equalsIgnoreCase("check")) {
        json = JsonFormat.outputJson(true, "", "");
      }
    }
    response.setContentType("text/html;charset=utf-8");
    response.getWriter().write(json);
    return null;
  }
Exemplo n.º 2
0
  public String delMyCustomers() throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();

    Oper operSess = (Oper) request.getSession().getAttribute("oper");
    String json = "";
    String editid = StringUtil.formatNullString(request.getParameter("datagrid_editId"));
    String[] ids = editid.split(",");
    HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
    String sql = PreparedSqlHelper.getEntityExtendSql("myCustomer", "delete");
    ArrayList<String> list = new ArrayList<String>();
    for (String id : ids) {
      String shop_no = id.split("\\|")[0];
      String pos_no = id.split("\\|")[1];
      String pan = id.split("\\|")[2];
      list.add("shop_no,string," + shop_no + "#pos_no,string," + pos_no + "#pan,string," + pan);
    }

    map.put(sql, list);
    myCustomerBean.iudData(map);
    json = DELETE_SUCCESS;
    response.setContentType("text/html;charset=utf-8");
    response.getWriter().write(json);
    return null;
  }
Exemplo n.º 3
0
  public String myCustomerGrid() throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();
    Oper operSess = (Oper) request.getSession().getAttribute("oper");
    String dept_no = operSess.getDept_no().trim();
    int start;
    try {
      start = Integer.parseInt(request.getParameter("start"));
    } catch (NumberFormatException e1) {
      start = 0;
    }
    int limit;
    try {
      limit = Integer.parseInt(request.getParameter("limit"));
    } catch (NumberFormatException e1) {
      limit = 10;
    }
    if (start > 0) start = start / limit;
    String json = "";

    FieldEntity entity = FieldMapConf.findMapFieldEntity("myCustomer");

    String select_parameter =
        super.getSearchParameters(request, "shop_name", "begin_date", "end_date");
    // 组织 开始日期和结束日期
    String begin_date = StringUtil.formatNullString(request.getParameter("sbegin_date"));
    String end_date = StringUtil.formatNullString(request.getParameter("send_date"));
    if (!("").equalsIgnoreCase(begin_date)) {
      begin_date = StringUtil.formatDate(begin_date);
      select_parameter += " and trim(t.register_date) >= '" + begin_date + "' ";
    }
    if (!("").equalsIgnoreCase(end_date)) {
      end_date = StringUtil.formatDate(end_date);
      select_parameter += " and trim(t.register_date) <= '" + end_date + "' ";
    }
    json = this.getListJson(entity, select_parameter, null, start, limit);

    response.setContentType("text/html;charset=utf-8");
    response.getWriter().write(json);

    return null;
  }
Exemplo n.º 4
0
  // 将对象组装成json格式的字符串
  // 重写上面的方法,目前对于时间进行过滤,需要编写者自己组织
  public static String objectToJson(Object obj, String... filters) {
    String tempjson = JSONSerializer.toJSON(obj).toString();
    String json = "";
    tempjson = tempjson.replaceAll("\"", ""); // 将全部的 " 去掉
    System.out.println("==========" + tempjson);
    // 特殊处理
    tempjson = tempjson.substring(1, tempjson.length() - 1); // 去掉"{","}"
    String[] array = tempjson.split(",");
    for (int i = 0; i < array.length; i++) {
      // 以':'分割对时间处理会出错,采用另一种方法(取第一个':'作为分割符)
      if (array[i] == null || array[i].equalsIgnoreCase("")) {
        continue;
      }
      String[] kv = new String[2];
      int index = 0;
      index = array[i].indexOf(":");
      if (index < 0) {
        continue;
      }
      kv[0] = array[i].substring(0, index); // kv[0]为key
      System.out.println(kv[0]);
      kv[1] = array[i].substring(index + 1); // kv[1]为value
      // 如果kv[1]为时间的话,处理一下
      // kv[1] = kv[1].replaceAll(":", ":");

      // 对value进行处理
      try {
        kv[1] = StringUtil.formatNullString(kv[1]);
      } catch (Exception e) {
        e.printStackTrace();
      }
      // 重新组装
      json += kv[0];
      json += ":'";
      json += kv[1];
      json += "',";
    }
    json = json.substring(0, json.length() - 1); // 去掉最后一个","
    return json;
  }