Esempio n. 1
0
 /**
  * Method that creates a ClassAttendance object
  *
  * @author Ognjen Mišiæ
  * @param classDescription argument describing the class
  * @param date of the class
  * @param duration duration of the class
  * @return an object
  * @throws ParseException
  */
 public static ClassAttendance createClass(String classDescription, String date, double duration)
     throws ParseException {
   ClassAttendance ca = new ClassAttendance();
   if (classDescription.length() > 2 && classDescription.length() < 45) {
     ca.setClassDescription(classDescription);
   } else {
     setErrorMessage("Class description invalid.");
   }
   // we reverse validation cause the point is to plan classes ahead and
   // enter them to table
   if (!isValidDate(date)) {
     ca.setDate(date);
   } else {
     setErrorMessage("Can't plan classes in past.");
   }
   if (duration > 0) {
     ca.setDuration((int) duration);
   } else {
     setErrorMessage("Invalid duraton.");
   }
   // this checks if there is anything in errormessage so it returns a null
   // object if there is an error
   if (getErrorMessage() != null && !getErrorMessage().isEmpty()) {
     return null;
   } else {
     return ca;
   }
 }
Esempio n. 2
0
 /**
  * Method that returns object of class attendance
  *
  * @author Ognjen Mišiæ
  * @param classID we identify entry by its classID
  * @return Object ClassAttendance
  * @throws SQLException
  */
 public static ClassAttendance returnClassAttendance(int classID) throws SQLException {
   ClassAttendance ca = new ClassAttendance();
   try {
     conn = connectToDb();
     stmnt = createReadOnlyStatement(conn);
     rs = stmnt.executeQuery(SELECT_ALL_FROM_CLASSES_ATTENDANCE);
     while (rs.next()) {
       if (rs.getInt("class_id") == classID) {
         ca.setClassDescription(rs.getString("class_description"));
         ca.setDate(rs.getString("date"));
         ca.setDuration(rs.getInt("duration"));
         ca.setClassID(rs.getInt("class_id"));
         setErrorMessage(null);
         break;
       } else {
         setErrorMessage("Could not find selected class id");
       }
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     if (rs != null) {
       rs.close();
     }
     closeStatement(stmnt);
     closeConnection(conn);
   }
   // this checks if there is anything in errormessage so it returns a null
   // object if there is an error
   if (getErrorMessage() != null && !getErrorMessage().isEmpty()) {
     return null;
   } else {
     return ca;
   }
 }