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

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

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

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

<%
    String status = "The update is successful";
    if ("Update".equals(request.getParameter("action"))) {
      try {
        cal.updateExchangeRate2(
            Double.parseDouble(
                request.getParameter("newrate")));
      } catch (Exception e) {
        status = "The update failed";
      }
    }
%>

<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="更新">
  <INPUT type="button" value="閉じる" onClick="window.close()">
</form><br/>
<b>Status:</b> <%=status%><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>