<%@ page language="java" import="java.util.*,java.sql.*,java.beans.*,iDSS.*,iDSS.utils.*,iDSS.webBeans.*,iDSS.beans.*,iDSS.beans2.*,iDSS.grids.*" errorPage="../error/error.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
	<TITLE><%=IDSSAppConstants.programTitle%></TITLE>

<META HTTP-EQUIV="KEYWORDS" CONTENT="internet-based, DSS, decision support system, Java, Enterprise edition, J2EE">
<META HTTP-EQUIV="DESCRIPTION" CONTENT="">		
</HEAD>

<jsp:useBean id="gridManagerJBean" scope="session" class="iDSS.beans2.GridManagerJBean"/>
<jsp:useBean id="modelSetupControllerJBean" scope="session" class="iDSS.beans2.ModelSetupControllerJBean"/>
<jsp:useBean id="statusJBean" scope="session" class="iDSS.beans2.StatusJBean"/>
<jsp:useBean id="tidalStationsLocalJBean" scope="session" class="iDSS.beans2.TidalStationsLocalJBean"/>
<jsp:useBean id="dataManagerJBean" scope="session" class="iDSS.beans2.DataManagerJBean"/>


<body>
<h2><%=IDSSAppConstants.modelSetupTidalData%></h2>



<%

    PropertyChangeSupport pcs = new PropertyChangeSupport(this);

    String actionButtonName = request.getParameter("action");

    gridManagerJBean.removePropertyChangeListener(modelSetupControllerJBean);
    gridManagerJBean.addPropertyChangeListener(modelSetupControllerJBean);
    statusJBean = modelSetupControllerJBean.getStatusBean();
    Vector remoteStations = tidalStationsLocalJBean.getRemoteStations();
    tidalStationsLocalJBean.removePropertyChangeListener(dataManagerJBean);
    tidalStationsLocalJBean.addPropertyChangeListener(dataManagerJBean);

    if(actionButtonName != null) {

%>
        <p>The button you clicked is <%=actionButtonName%>. </p>
<%


        if (actionButtonName.equals(IDSSAppConstants.fetchDataButtonText)) {

            String[] stationNames = request.getParameterValues(IDSSAppConstants.fetchDataButtonCommand);

            if(stationNames != null) {

                if(stationNames.length > 0) {

                    String stationName = stationNames[0];

                    int startYear = Integer.parseInt(request.getParameter("startYear"));
                    int startMonth = Integer.parseInt(request.getParameter("startMonth"))-1;
                    int startDay = Integer.parseInt(request.getParameter("startDay"));
                    int startHour = Integer.parseInt(request.getParameter("startHour"));
                    int startMinute = Integer.parseInt(request.getParameter("startMinute"));
                    int startSecond = Integer.parseInt(request.getParameter("startSecond"));

                    Calendar startCal = Calendar.getInstance();
                    startCal.set(startYear,startMonth,startDay,startHour,startMinute,startSecond);
                    Timestamp startTimestamp = new Timestamp(startCal.getTime().getTime());

                    int endYear = Integer.parseInt(request.getParameter("endYear"));
                    int endMonth = Integer.parseInt(request.getParameter("endMonth"))-1;
                    int endDay = Integer.parseInt(request.getParameter("endDay"));
                    int endHour = Integer.parseInt(request.getParameter("endHour"));
                    int endMinute = Integer.parseInt(request.getParameter("endMinute"));
                    int endSecond = Integer.parseInt(request.getParameter("endSecond"));

                    Calendar endCal = Calendar.getInstance();
                    endCal.set(endYear,endMonth,endDay,endHour,endMinute,endSecond);
                    Timestamp endTimestamp = new Timestamp(endCal.getTime().getTime());

                    tidalStationsLocalJBean.fetchData(
                            stationName,startTimestamp,endTimestamp,stationName,
                                            IDSSAppConstants.dataLocationRemote);



                    %>
                        <P>stationName : <%=stationName%></P>
                        <P>startTimestamp : <%=startTimestamp.toString()%></P>
                        <P>endTimestamp : <%=endTimestamp.toString()%></P>
                    <%

                } //if(stationNames.length > 0)

            } //if(stationNames != null)

        } //else if (actionButtonName.equals(IDSSAppConstants.selectButtonText))






    } //if(actionButtonName != null)
%>







<form method=get>


    <table width="100%" border="0" VSPACE="5" HSPACE="5" CELLPADDING="5">
        <tr BGCOLOR="#C0C0C0">
            <th width="10%">Sel</th>
            <th width="15%">Station name</th>
            <th width="30%">Start date</th>
            <th width="30%">End date</th>
            <th width="15%">Data table</th>
        </tr>

    <%


        for(int i=0;i<remoteStations.size();i++) {

            Vector oneRow = (Vector)remoteStations.elementAt(i);
            String stationName = (String)oneRow.elementAt(0);
            String startDate = ((Timestamp)oneRow.elementAt(1)).toString();
            String endDate = ((Timestamp)oneRow.elementAt(2)).toString();
            String dataTable = (String)oneRow.elementAt(3);

    %>

            <tr BGCOLOR="#90FFFF">
                <td align="center"><input type=checkbox name="<%=IDSSAppConstants.fetchDataButtonCommand%>" value="<%=dataTable%>" justify="center"></td>
                <td><%=stationName%> </td>
                <td><%=startDate%> </td>
                <td><%=endDate%> </td>
                <td><%=dataTable%> </td>
            </tr>



    <%
        } //for(int i=0;i<remoteStations.size();i++)
    %>

    </table>

    <table border="0">
        <tr>
            <td><input type=submit value="<%=IDSSAppConstants.fetchDataButtonText%>" name="action" ></td>
            <td>
                <table border="0">

                    <tr>
                        <td>

                            <select name="startYear" size="1">
                                <%
                                    for(int i=1980;i<=1999;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=1900;i<=2000;i++)
                                %>

                            </select>

                        </td>
                        <td>

                            <select name="startMonth" size="1">
                                <%
                                    for(int i=1;i<=12;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=1;i<=12;i++)
                                %>

                            </select>

                        </td>
                        <td>

                            <select name="startDay" size="1">
                                <%
                                    for(int i=1;i<=31;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>"><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=1;i<=31;i++)
                                %>
                                </select>

                        </td>
                        <td>
                            <select name="startHour" size="1">
                                <%
                                    for(int i=0;i<=23;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=0;i<=23;i++)
                                %>
                            </select>
                        </td>
                        <td>
                            <select name="startMinute" size="1">
                                <%
                                    for(int i=0;i<=59;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=0;i<=59;i++)
                                %>
                            </select>
                        </td>
                        <td>
                            <select name="startSecond" size="1">
                                <%
                                    for(int i=0;i<=59;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=0;i<=59;i++)
                                %>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <td>

                            <select name="endYear" size="1">
                                <%
                                    for(int i=1980;i<=1999;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=1900;i<=2000;i++)
                                %>

                            </select>

                        </td>
                        <td>

                            <select name="endMonth" size="1">
                                <%
                                    for(int i=1;i<=12;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=1;i<=12;i++)
                                %>

                            </select>

                        </td>
                        <td>

                            <select name="endDay" size="1">
                                <%
                                    for(int i=1;i<=31;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=1;i<=31;i++)
                                %>
                                </select>

                        </td>
                        <td>
                            <select name="endHour" size="1">
                                <%
                                    for(int i=0;i<=23;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=0;i<=23;i++)
                                %>
                            </select>
                        </td>
                        <td>
                            <select name="endMinute" size="1">
                                <%
                                    for(int i=0;i<=59;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=0;i<=59;i++)
                                %>
                            </select>
                        </td>
                        <td>
                            <select name="endSecond" size="1">
                                <%
                                    for(int i=0;i<=59;i++) {
                                %>
                                        <option value="<%=String.valueOf(i)%>" ><%=String.valueOf(i)%></option>
                                <%
                                    } //for(int i=0;i<=59;i++)
                                %>
                            </select>
                        </td>
                    </tr>

                </table>
            </td>
        </tr>
    </table>



</form>






</body>

</HTML>

