//========================================================================
// Program: IDEA_ScheduleActivity.java
//
// Author:  F2-Team2
// This is a program written for the UIT2201 Project
//
// This program takes input a schedule id
// output: Note, else "No Note".
//
//
package IDEA_Schedule;
import java.sql.*;   // LHW: this imports sql related classes
import java.util.*;
import DBClasses.*;  // LHW: imports database manager and other classes


class IDEA_Schedule_Activity {

  public static void main(String[] args) {

	String sch_id = args[0];
     // LHW: Create a database connection
     // LHW:  by using the dbManager class provided
     dbManager dbman = new dbManager();
     Connection conn = dbman.getConnection();


     try {
       // To execute query,
       //   first create the sql statement
       //   execute the statement
       //   "catch" the output in "rs" (rs is a set of tuples)
       Statement stmt = conn.createStatement();
       String sql = "SELECT sch_id,sch_start,sch_end,sch_activity,sch_notes FROM Schedule WHERE sch_id = '"+sch_id+"'";

            // prepare sql stmt
       ResultSet rs = stmt.executeQuery(sql);          // execute query



       if (rs.next())// output the result;
       {


       		String start = rs.getString("sch_start");
       		String date = start.substring(0,10);
       		start=start.substring(11,start.length()-1);
       		String year = date.substring(0,4);
			String mon = date.substring(5,7);
			String day = date.substring(8,10);
			date = day + mon + year;
			String end = rs.getString("sch_end");
			end=end.substring(11,end.length()-1);
			String activity = rs.getString("sch_activity");

			String note = rs.getString("sch_notes");
			System.out.println("Date : " + date+ " Time : " + start+ "-" + end + " Activity: " + activity);
			System.out.println("Note : " + note);
		}
		else
		{
			System.out.println("No Notes");
		}

       rs.close();       // close everything (rs, stmt, conn)
       stmt.close();
       conn.close();
    } catch (Exception e) {
      //System.out.println("DB Error!"); // error message if exception occurs
      //e.printStackTrace();
      System.out.println("No Notes");
    }

  }


}
