<%@ Page language="c#" Debug="true"%><%
//! Support file only, run AjaxGrid.html instead !
// This file is used as Data_Url for TreeGrid
// It generates source data for TreeGrid from database
// --------------------------------------------------------------------------
   
// --- Database initialization ---
string Path = System.IO.Path.GetDirectoryName(Context.Request.PhysicalPath);
System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data Source=\"" + Path + "\\Database.mdb\";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=\"Microsoft.Jet.OLEDB.4.0\";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1");
Conn.Open();
System.Data.OleDb.OleDbCommand Cmd = Conn.CreateCommand();

// --- Response initialization ---
Response.ContentType = "text/xml";
Response.Charset = "utf-8";
Response.AppendHeader("Cache-Control","max-age=1, must-revalidate");
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

// --- Generating data ---
Cmd.CommandText = "SELECT * FROM TableData ORDER BY Project,Resource";
System.Data.OleDb.OleDbDataReader R = Cmd.ExecuteReader();

//Dim Prj, Res, S, P, R
string Prj = "", Res = "", S = "";

while(R.Read())
{
   string p = R[1].ToString();  // Project
   string r = R[2].ToString();  // Resource
   if (r != Res && Res != "") S += "/>";     // End previous resource row
   
   if (p != Prj)                // New project row
   {
      if(Prj != "") S += "</I>"; // Ends previous project row
      Prj = p;
      S += "<I Def='Node' Project='" + Prj.Replace("&","&amp;").Replace("'","&apos;").Replace("<","&lt;") + "'>";
   }
   
   if(r != Res)                  // New resource row
   {
      Res = r;
      S += "<I Project='" + Res.Replace("&","&amp;").Replace("'","&apos;").Replace("<","&lt;") + "' ";
   }
   
   S = S + "W" + R[3].ToString() + "='" + R[4].ToString() + "' "; // Week = Hours (like W42='17')
}

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