<%@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","");

// --- Parses sorting settings ---
org.w3c.dom.Document XML = parseXML(request.getParameter("TGData"));
String[] SC = getSortCols(XML);
int[] ST = getSortTypes(XML);
String S = "";
if (SC!=null) {
   for (int i = 0; i < SC.length; i++) {
      if (S.length()>0) S += ", ";
      S += SC[i];
      if (ST[i] >= 1) S += " DESC";
      }
   if (S.length()>0) S = " ORDER BY " + S;
   }

// --- Gets information about page number ---
int pos = getPagePos(XML);
int start = pos*20;      // 20 = PageLength

// --- Reads data from database ---
java.sql.ResultSet R = Cmd.executeQuery("SELECT * FROM TableData" + S);

// --- Throws away data in front of requested page ---
for(int i=0;i<start && R.next();i++);

// --- Writes data for requested page ---
out.print("<Grid><Body><B Pos=" + toXML(pos) + ">");
String[] Names = {"id","Project","Resource","Week","Hours"};
for(int i=0;i<20 && R.next();i++) out.print(getRowXML(R,Names));
out.print("</B></Body></Grid>");
//------------------------------------------------------------------------------------------------------------------
%>
