<%@ page contentType="text/html; charset=Shift_JIS" %>
<%@ page import="javax.naming.*,
                 java.text.*,
                 java.util.*,
                 trail.entity.beans.*, trail.entity.update.*"%>

<%!
  private Calculator cal = null;
  private NumberFormat nf = null;

  public void jspInit () {
    try {
      InitialContext ctx = new InitialContext();
      cal = (Calculator) ctx.lookup(
                  "EJB3Trail/UpdateCalculator/local");
    } catch (Exception e) {
      e.printStackTrace ();
    }

    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
  }
%>

<%
    if ("Update".equals(request.getParameter("action"))) {
        cal.updateExchangeRate(
            Double.parseDouble(
                request.getParameter("newrate")));
    }
%>

<html><body>

<p>新しい為替で計算記録を更新する<br/>
<form action="update.jsp" method="POST">
  変換レート = <input type="text" name="newrate" value="1.5">
  <input type="hidden" name="action" value="Update"><br/>
  <input type="submit" value="Update">
  <INPUT type="button" value="Close Window" onClick="window.close()">
</form><br/>

過去の計算記録<br/>
<table>
<tr>
<td>タイムスタンプ</td>
<td>投資会社</td>
<td>個人投資家</td>
<td>月掛金額</td>
<td><b>合計投資額</b></td>
</tr>

<%
    Collection records = cal.getRecords ();
    for (Iterator iter = records.iterator(); iter.hasNext();) {
        TimedRecord record = (TimedRecord) iter.next();
%>

<tr>
<td><%=record.getTs()%></td>
<td><%=record.getFund().getName()%></td>
<td><%=record.getInvestor().getName()%></td>
<td><%=nf.format(record.getSaving())%></td>
<td><%=nf.format(record.getResult())%></td>
</tr>

<%
    }
%>
</table>

</p>
</body></html>