/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package web;



import java.util.*;
import java.sql.*;

public class HTMLUtil
{
    public static String getFilmSelectHtml(ResultSet results)
            throws SQLException
    {
        if(results.next()){
            results.beforeFirst();

            StringBuffer htmlRows = new StringBuffer();

            htmlRows.append("<form method=\"get\"  action=\"getShowTimes\">");
            htmlRows.append("Film Title : ");
            htmlRows.append("<select name=\"filmId\" style=\"width: 350px;\" onchange='submit()'>");


            while (results.next())
            {

               htmlRows.append("<option value=\"" + results.getString(2) + "\">" + results.getString(1) + "</option>");
            }
            htmlRows.append("</select>");
            htmlRows.append("<input type=\"submit\" value=\"Submit\" name=\"Submit\">");
            htmlRows.append("</form>");
            return htmlRows.toString();
        }
        else{
            return "<b>No film will be shown on that date!</b>";
        }
    }


    public static String getShowTimeSelectHtml(ResultSet results)
            throws SQLException
    {
        StringBuffer htmlRows = new StringBuffer();
        
        htmlRows.append("<form method=\"get\"  action=\"getReservationShow\">");
        htmlRows.append("Show Time : ");
        htmlRows.append("<select name=\"showTime\" onchange='submit()'>");
        

        while (results.next())
        {
            htmlRows.append("<option value=\"" + results.getString(2) + "\">" + results.getString(1) + "</option>");
        }
        htmlRows.append("</select>");
        htmlRows.append("<input type=\"submit\" value=\"Submit\" name=\"Submit\">");
        htmlRows.append("</form>");
        return htmlRows.toString();
    }
    
    public static String getReservationSelectHtml(ResultSet results)
            throws SQLException
    {
     if(results.next()){
        results.beforeFirst();

        StringBuffer htmlRows = new StringBuffer();
        ResultSetMetaData metaData = results.getMetaData();
        int columnCount = metaData.getColumnCount();

        htmlRows.append("<table id=\"reservationstable\">");

        htmlRows.append("<tr>");
        for (int i = 2; i <= columnCount; i++)
            htmlRows.append("<th>" + metaData.getColumnName(i) + "</th>");
        htmlRows.append("</tr>");

        int index = 0;
        while (results.next())
        {
            if(index % 2 == 0)
                htmlRows.append("<tr>");
            else
               htmlRows.append("<tr class=\"alt\">");

            index++;
            for (int i = 2; i <= columnCount - 1; i++){
                if (i == 3){
                htmlRows.append("<td><center>" + TimeDateUtil.changeFormatDate(results.getString(i)) + "</center></td>");
                }
                else if (i == 4){
                htmlRows.append("<td><center>" + TimeDateUtil.changeFormatTime(results.getString(i)) + "</center></td>");
                }
                else{
                htmlRows.append("<td><center>" + results.getString(i) + "</center></td>");
                }

            }

            if(results.getString(columnCount).equalsIgnoreCase(""))
            {
                htmlRows.append("<td>");
                htmlRows.append("<form method=\"get\"  action=\"delivreTickets\">");
                htmlRows.append("<input type=\"hidden\" value =\"" + results.getString(1)+ "\" name=\"reservationId\">");
                htmlRows.append("<b><center><input type=\"submit\" value=\"deliverNow\"></center></b>");
                htmlRows.append("</form>");
                htmlRows.append("</td>");
            }
            else
                htmlRows.append("<td><center>" + TimeDateUtil.changeFormatDateTimeDelivery(results.getString(columnCount)) + "</center></td>");
        }

        htmlRows.append("</tr>");
        htmlRows.append("</table>");

        return htmlRows.toString();
     }
     else
         return "<b>No reservation has been made to this show yet!</b>";
    }


}