<%@page contentType="text/xml"%><%@page pageEncoding="UTF-8"%><%@include file="TreeGridFramework.jsp"%><%
/*-----------------------------------------------------------------------------------------------------------------
Sample JSP web page, using java.sql.ResultSet object to read and write TreeGrid data from and to database.
By default, connection string is ODBC to MS Access db in ../Data/CalcData.mdf.
Shows sending data by page submit to server in hidden input.
Form is submitted by TreeGrid Save button or by external submit button.
------------------------------------------------------------------------------------------------------------------*/

//------------------------------------------------------------------------------------------------------------------
response.addHeader("Cache-Control","max-age=1, must-revalidate");

// --- Database connection ---
java.sql.Statement Cmd = getHsqlStatement(request,out,"Database","sa","");

// --- Generating data ---
java.sql.ResultSet R = Cmd.executeQuery("SELECT * FROM TableData ORDER BY Project,Resource");
String Prj = "", Res = "", S = "";
while(R.next()) {
   String p = R.getString(2);  // Project
   String r = R.getString(3);  // Resource
   if (!r.equals(Res) && Res.length()>0) S += "/>";     // End previous resource row
   
   if (!p.equals(Prj)) {                // New project row
      if(Prj.length()>0) S += "</I>";                   // Ends previous project row
      Prj = p;
      S += "<I Def='Node' Project=" + toXML(Prj) + ">";
      }
   
   if(!r.equals(Res)) {                 // New resource row
      Res = r;
      S += "<I Project=" + toXML(Res) + " ";
   }
   
   S = S + "W" + String.valueOf(R.getInt(4)) + "='" + R.getString(5) + "' "; // Week = Hours (like W42='17')
   }

if(Res.length()>0) S += "/>";                           // Ends previous resource row
if(Prj.length()>0) S += "</I>";                         // Ends previous project row
// --------------------------------------------------------------------------
%><?xml version="1.0" ?>
<Grid>
   <Body>
      <B>
         <%=S%>
      </B>
   </Body>
</Grid>