Package oss.ngocminh.lego.data

Examples of oss.ngocminh.lego.data.Entity


    String message = null;
    try {
      Connection conn = getConnection();
      categoryDAO.setConnection(conn);
      int id = Integer.parseInt(request.getParameter("id"));
      Entity category = categoryDAO.findById(id);
      if (category == null) {
        message = "Không tìm thấy chủ đề #" + id;
      } else {
        category.put("name", request.getParameter("name"));
        category.put("image", request.getParameter("image"));
        categoryDAO.update(category);
        message = "Đã lưu chủ đề " + category.get("name");
      }
      conn.close();
    } catch (NumberFormatException e) {
      message = "Mã chủ đề không hợp lệ: " + request.getParameter("id");
    } catch (SQLException e) {
View Full Code Here


      throws ServletException, IOException {
    try {
      Connection conn = getConnection();
      ProductDAO productDAO = new ProductDAO(conn);
      int productId = Integer.parseInt(req.getParameter("product"));
      Entity product = productDAO.findById(productId);
      productDAO.fetchImage(product);
      int quantity = Integer.parseInt(req.getParameter("quantity"));
      conn.close();
     
      List<Entity> orders = (List<Entity>) req.getSession().getAttribute("orders");
      if (orders == null) {
        orders = new LinkedList<Entity>();
        req.getSession().setAttribute("orders", orders);
      }
      Entity order = new EntityImpl();
      order.put("product_id", productId);
      order.put("product", product);
      order.put("quantity", quantity);
      addOrMerge(orders, order);
     
      redirect("cart_view", resp);
    } catch (SQLException e) {
      throw new ServletException(e);
View Full Code Here

  protected void doPost(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
    Errors errors = new Errors();
    String email = request.getParameter("email");
    String password = request.getParameter("password");
    Entity user = getUser(email);
    if (user == null) {
      errors.put("email", "Không tìm thấy người dùng");
    } else {
      if (StringUtils.isEmpty(password)) {
        errors.put("password", "Hãy nhập mật khẩu");
      }
      if (!password.equals(user.get("password"))) {
        errors.put("password", "Mật khẩu không đúng");
      }
    }
   
    if (errors.isEmpty()) {
View Full Code Here

  private Entity getUser(String email) throws ServletException {
    try {
      Connection conn = getConnection();
      UserDAO userDAO = new UserDAO(conn);
      Entity user = userDAO.findByEmail(email);
      conn.close();
      return user;
    } catch (SQLException e) {
      throw new ServletException(e);
    }
View Full Code Here

    try {
      Connection conn = getConnection();
      productDAO.setConnection(conn);
      categoryDAO.setConnection(conn);
      int id = Integer.parseInt(request.getParameter("id"));
      Entity category = categoryDAO.findById(id);
      List<Entity> products = productDAO.findByCategory(category);
      productDAO.fetchImage(products);
      request.setAttribute("category", category);
      request.setAttribute("products", products);
      conn.close();
View Full Code Here

        String quantityStr = request.getParameter("quantity" + i);
        int quantity = Integer.parseInt(quantityStr);
        if (quantity <= 0) {
          orders.remove(i);
        } else {
          Entity order = orders.get(i);
          order.put("quantity", quantity);
        }
      }
    } else if (action.startsWith("delete")) {
      int productId = Integer.parseInt(action.substring(6));
      for (int i = orders.size()-1; i >= 0; i--) {
View Full Code Here

    String message = "";
    try {
      Connection conn = getConnection();
      categoryDAO.setConnection(conn);
      int id = Integer.parseInt(request.getParameter("id"));
      Entity category = categoryDAO.findById(id);
      if (category == null) {
        message = "Không tìm thấy chủ đề #" + id;
      } else {
        categoryDAO.delete(category);
        message = "Đã xoá chủ đề " + category.get("name");
      }
      conn.close();
    } catch (NumberFormatException e) {
      message = "Mã chủ đề không hợp lệ: " + request.getParameter("id");
    } catch (SQLException e) {
View Full Code Here

    try {
      Connection conn = getConnection();
      productDAO.setConnection(conn);
      imageDAO.setConnection(conn);
      int id = Integer.parseInt(request.getParameter("id"));
      Entity product = productDAO.findById(id);
      if (product == null) {
        renderView("notfound", request, response);
        return;
      }
      request.setAttribute("product", product);
      request.setAttribute("images", imageDAO.findByCollection(
          product.getInt("imageCollection")));
      conn.close();
      renderView(request, response);
    } catch (NumberFormatException e) {
      renderView("notfound", request, response);
    } catch (SQLException e) {
View Full Code Here

   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
      Connection conn = getConnection();
      categoryDAO.setConnection(conn);
      Entity category = new EntityImpl();
      category.put("name", request.getParameter("name"));
      category.put("image", request.getParameter("image"));
      categoryDAO.save(category);
      conn.close();
     
      String message = "Tạo thành công chủ đề " + category.get("name");
      redirect("cat_manage?message=" + URLEncoder.encode(message, "UTF-8"), response);
    } catch (SQLException e) {
      throw new ServletException(e);
    }
  }
View Full Code Here

    if (!error.isEmpty()) {
      renderView(request, response);
      return;
    }

    Entity product = new EntityImpl();
    product.put("name", name);
    product.put("imageCollection", request.getParameter("imageCollection"));
    product.put("description", description);
    product.put("quantity", quantity);
    product.put("price", price);
    product.put("discount", discount);
    product.put("type", type);
    product.put("category", category);
    try {
      Connection conn = getConnection();
      conn.setAutoCommit(false);
      productDAO.setConnection(conn);
      imageCollectionDAO.setConnection(conn);
      imageDAO.setConnection(conn);

      Entity imageCollection = new EntityImpl();
      imageCollectionDAO.save(imageCollection);
      for (Entity image : images) {
        image.put("collection", imageCollection.get("id"));
        imageDAO.save(image);
      }
      product.put("imageCollection", imageCollection.get("id"));
      productDAO.save(product);

      conn.commit();
      conn.close();
View Full Code Here

TOP

Related Classes of oss.ngocminh.lego.data.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.