public AddTimeSlot(AllocateTime at, int id) { date = at.getDate(); starttime = at.getStartTime(); endtime = at.getEndTime(); userid = id; count = TimeSlotHelpers.count(at.getStartTime(), at.getEndTime()); msg = "Unable to add time slot."; }
@Override public void queryDB() { try { String command = "INSERT INTO ADVISING_SCHEDULE (date,start,end,studentid,userid) VALUES(?,?,?,null,?)"; PreparedStatement statement = conn.prepareStatement(command); for (int i = 0; i < count; i++) { statement.setString(1, date); statement.setString(2, TimeSlotHelpers.add(starttime, i)); statement.setString(3, TimeSlotHelpers.add(starttime, i + 1)); statement.setInt(4, userid); statement.executeUpdate(); } msg = "Time slot has been added."; } catch (Exception e) { System.out.printf("Add Time Slot error : " + e.toString()); } }
public ArrayList<TimeSlotComponent> getAdvisorSchedule(String name) { ArrayList<TimeSlotComponent> array = new ArrayList<TimeSlotComponent>(); try { Connection conn = this.connectDB(); PreparedStatement statement; if (name.equals("all")) { String command = "SELECT pname,advising_date,advising_starttime,advising_endtime,id FROM user,advising_schedule,advisor_settings " + "WHERE user.userid=advisor_settings.userid AND user.userid=advising_schedule.userid AND studentid is null"; statement = conn.prepareStatement(command); } else { String command = "SELECT pname,advising_date,advising_starttime,advising_endtime,id FROM USER,ADVISING_SCHEDULE,ADVISOR_SETTINGS " + "WHERE USER.userid=ADVISOR_SETTINGS.userid AND USER.userid=ADVISING_SCHEDULE.userid AND USER.userid=ADVISING_SCHEDULE.userid AND ADVISOR_SETTINGS.pname=? AND studentid is null"; statement = conn.prepareStatement(command); statement.setString(1, name); } ResultSet res = statement.executeQuery(); while (res.next()) { // Use flyweight factory to avoid build cost if possible PrimitiveTimeSlot set = (PrimitiveTimeSlot) TimeSlotFlyweightFactory.getInstance() .getFlyweight(res.getString(1) + "-" + res.getString(2), res.getString(3)); set.setName(res.getString(1)); set.setDate(res.getString(2)); set.setStartTime(res.getString(3)); set.setEndTime(res.getString(4)); set.setUniqueId(res.getInt(5)); array.add(set); } array = TimeSlotHelpers.createCompositeTimeSlot(array); conn.close(); } catch (Exception e) { System.out.printf(e.toString()); } return array; }