@POST
  @Consumes(MediaType.APPLICATION_JSON)
  public Response addEvent(Event event) {
    if (authenticated) {
      Event evt = new Event(event);

      String sql =
          "INSERT INTO event (eventName, eventDescription, dateFrom, dateTo) VALUES( '"
              + evt.getEventName()
              + "', '"
              + evt.getEventDescription()
              + "', '"
              + evt.getDateFromString()
              + "'"
              + ",'"
              + evt.getDateToString()
              + "')";
      try {
        sqlCon.getStatement().executeUpdate(sql);
        return Response.status(Status.ACCEPTED).build();
      } catch (Exception e) {
        e.printStackTrace();
        return Response.status(Status.BAD_REQUEST).build();
      } finally {
        sqlCon.closeConnection();
      }
    } else {
      return Response.status(Status.FORBIDDEN).build();
    }
  }
Exemple #2
0
  public ArrayList<NhanVien> getTatCaNhanVien() {
    this.listNhanVien = new ArrayList<NhanVien>();

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlGetTatCaNhanVien);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        this.nhanVien =
            new NhanVien(
                rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5));
        this.listNhanVien.add(this.nhanVien);
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
      SQLConnection.closeResultSet(rs);
    }

    return this.listNhanVien;
  }
Exemple #3
0
  public NhanVien getNhanVienTheoTenDangNhapVaMatKhau(String tenDangNhap, String matKhau) {
    this.nhanVien = null;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlGetNhanVienTheoTenDangNhapVaMatKhau);

      pstmt.setString(1, tenDangNhap);
      pstmt.setString(2, matKhau);

      rs = pstmt.executeQuery();

      if (rs.next()) {
        this.nhanVien =
            new NhanVien(
                rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5));
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
      SQLConnection.closeResultSet(rs);
    }

    return this.nhanVien;
  }
 @DELETE
 @Path("/{eventId}")
 public Response deleteEvent(@PathParam("eventId") String eventId) {
   if (authenticated) {
     try {
       sqlCon.getStatement().executeUpdate("DELETE FROM event WHERE eventId = " + eventId);
       return Response.status(Status.ACCEPTED).build();
     } catch (Exception e) {
       e.printStackTrace();
       return Response.status(Status.BAD_REQUEST).build();
     } finally {
       sqlCon.closeConnection();
     }
   } else {
     return Response.status(Status.FORBIDDEN).build();
   }
 }
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @Path("register/{userId}")
  public Response getEventsAvailableForRegistration(@PathParam("userId") String userId) {

    List<Event> events = new ArrayList<Event>();
    if (authenticated) {
      try {

        ResultSet rs =
            sqlCon
                .getStatement()
                .executeQuery(
                    "SELECT event.eventId, event.eventName, event.eventDescription, event.dateFrom, event.dateTo "
                        + "FROM event where not exists ( select eventId from user_event where event.eventId = user_event.eventId "
                        + "AND user_event.userId = "
                        + userId
                        + " );");

        while (rs.next()) {
          Event event = new Event();

          long eventId = Long.parseLong(rs.getString("eventId"));
          event.setEventId(eventId);
          event.setEventName(rs.getString("eventName"));
          event.setEventDescription(rs.getString("eventDescription"));
          Calendar cal = new GregorianCalendar();
          cal.set(2012, Calendar.AUGUST, 15, 15, 30);
          // event.setDateFrom(cal);
          // event.setDateTo(rs.getString("dateTo"));

          events.add(event);
        }
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        sqlCon.closeConnection();
      }

      GenericEntity<List<Event>> entity = new GenericEntity<List<Event>>(events) {};
      return Response.status(Status.ACCEPTED).entity(entity).build();
    } else {
      return Response.status(Status.FORBIDDEN).build();
    }
  }
Exemple #6
0
  public int deleteNhanVien(int maNhanVien) {
    int result = 0;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlDeleteNhanVien);

      pstmt.setInt(1, maNhanVien);

      result = pstmt.executeUpdate();

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
    }

    return result;
  }
  public int addLoaiSanPham(LoaiSanPham lsp) {
    int result = 0;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlAddLoaiSanPham);

      pstmt.setString(1, lsp.getTen());
      pstmt.setString(2, lsp.getMoTa());

      result = pstmt.executeUpdate();

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
    }

    return result;
  }
Exemple #8
0
  public int addNhanVien(NhanVien nv) {
    int result = 0;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlAddNhanVien);

      pstmt.setString(1, nv.getTen());
      pstmt.setString(2, nv.getTenDangNhap());
      pstmt.setString(3, nv.getMatKhau());
      pstmt.setString(4, nv.getGhiChu());

      result = pstmt.executeUpdate();

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
    }

    return result;
  }
  public LoaiSanPham getLoaiSanPhamTheoMa(int maLoaiSanPham) {
    this.loaiSanPham = null;

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlGetLoaiSanPhamTheoMa);
      pstmt.setInt(1, maLoaiSanPham);
      rs = pstmt.executeQuery();

      if (rs.next()) {
        this.loaiSanPham = new LoaiSanPham(rs.getInt(1), rs.getString(2), rs.getString(3));
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
      SQLConnection.closeResultSet(rs);
    }

    return this.loaiSanPham;
  }
Exemple #10
0
  public ArrayList<LoaiSanPham> getTatCaLoaiSanPham() {
    this.listLoaiSanPham = new ArrayList<LoaiSanPham>();

    try {
      con = SQLConnection.getConnection();
      pstmt = con.prepareStatement(sqlGetTatCaLoaiSanPham);
      rs = pstmt.executeQuery();

      while (rs.next()) {
        this.loaiSanPham = new LoaiSanPham(rs.getInt(1), rs.getString(2), rs.getString(3));
        this.listLoaiSanPham.add(this.loaiSanPham);
      }

    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      SQLConnection.closeConnection(this.con);
      SQLConnection.closePrepareStatement(pstmt);
      SQLConnection.closeResultSet(rs);
    }

    return this.listLoaiSanPham;
  }
  @PUT
  @Path("/{eventId}")
  @Consumes(MediaType.APPLICATION_JSON)
  public Response updateEvent(Event event, @PathParam("eventId") String eventId) {
    if (authenticated) {
      Event evt = new Event(event);

      String sql =
          "UPDATE event SET eventName = '"
              + evt.getEventName()
              + "', eventDescription = "
              + "'"
              + evt.getEventDescription()
              + "', dateFrom = "
              + "'"
              + evt.getDateFrom()
              + "'"
              + ", dateTo = "
              + "'"
              + evt.getDateTo()
              + "'"
              + " WHERE eventId ="
              + eventId;

      try {
        sqlCon.getStatement().executeUpdate(sql);
        return Response.status(Status.ACCEPTED).build();
      } catch (Exception e) {
        e.printStackTrace();
        return Response.status(Status.BAD_REQUEST).build();
      } finally {
        sqlCon.closeConnection();
      }
    } else {
      return Response.status(Status.FORBIDDEN).build();
    }
  }
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response getEvents() {

    List<Event> events = new ArrayList<Event>();
    if (authenticated) {
      try {

        ResultSet rs = sqlCon.getStatement().executeQuery("SELECT * FROM event");

        while (rs.next()) {
          Event event = new Event();

          long eventId = Long.parseLong(rs.getString("eventId"));
          event.setEventId(eventId);
          event.setEventName(rs.getString("eventName"));
          event.setEventDescription(rs.getString("eventDescription"));
          Calendar cal = new GregorianCalendar();
          cal.set(2012, Calendar.AUGUST, 15, 15, 30);
          // event.setDateFrom(cal);
          // event.setDateTo(rs.getString("dateTo"));

          events.add(event);
        }
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        sqlCon.closeConnection();
      }

      GenericEntity<List<Event>> entity = new GenericEntity<List<Event>>(events) {};
      return Response.status(Status.ACCEPTED).entity(entity).build();
    } else {
      return Response.status(Status.FORBIDDEN).build();
    }
  }