package com.robinson.sql; import java.util.*; import java.util.Date; import java.sql.*; import java.text.SimpleDateFormat; import java.text.ParseException; /** * Created by IntelliJ IDEA. * User: Sean Robinson * Date: Oct 17, 2006 * Time: 1:42:38 PM * To change this template use File | Settings | File Templates. */ public class CRSManager { public Date getMaxDate(Connection con, String equipmentid) throws SQLException { Date date = null; try { int id = Integer.parseInt(equipmentid); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT dateend FROM inventory WHERE ID="+id); while(rs.next()){ date = rs.getDate("dateend"); } } catch(Exception e){ e.printStackTrace(); throw new SQLException("Error in getMaxDate method"); } return date; } public Date getMinDate(Connection con, String equipmentid) throws SQLException { Date date = null; try { int id = Integer.parseInt(equipmentid); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT datestart FROM inventory WHERE ID="+id); while(rs.next()){ date = rs.getDate("datestart"); } } catch(Exception e){ e.printStackTrace(); throw new SQLException("Error in getMinDate method"); } return date; } public String convertDateToString(Date date) throws SQLException { SimpleDateFormat sf = new SimpleDateFormat("MM/dd/yyyy"); Date date1 = new Date(); String boo = sf.format(date1); return boo; } public Date convertStringToDate(String date) throws ParseException { SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy"); Date current = new Date(); String datestring = "10/11/2007"; Date date1 = df.parse(date); return date1; } public void createPeriod(Connection con, int period, String labid, String desc ) throws SQLException { try { // int per = Integer.parseInt(period); int lab = Integer.parseInt(labid); PreparedStatement st = con.prepareStatement("INSERT INTO periods(name,fullname,equip) VALUES(?,?,?)"); st.setInt(1,period); st.setString(2,desc); st.setInt(3,lab); st.executeUpdate(); st.close(); } catch(Exception e){ System.out.println(e.getMessage()); throw new SQLException("Error in createPeriod method"); } } public List getPeriods(Connection con) throws SQLException { List periods = new ArrayList(); try { Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT ID FROM periods ORDER by ID ASC"); while(rs.next()){ periods.add(new PeriodList(rs.getInt("ID"))); } } catch(Exception e){ System.out.println(e.getMessage()); throw new SQLException("Error in getPeriods method"); } return periods; } public void createEquipmentDefaultReservations(Connection con, List periods, Date startdate, Date enddate, String equipmentid, int room, String username) throws SQLException { try { List pers = periods; GregorianCalendar minCal = new GregorianCalendar(); GregorianCalendar maxCal = new GregorianCalendar(); minCal.setTime(startdate); maxCal.setTime(enddate); while(!minCal.equals(maxCal)){ for(int i=0;i