<%@ Page language="vb" 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 ---
   Dim Path As String : Path = System.IO.Path.GetDirectoryName(Context.Request.PhysicalPath)
   Dim Conn As 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()
   Dim Cmd As 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"
   Dim X As System.Data.OleDb.OleDbDataReader : X = Cmd.ExecuteReader()
   Dim Prj, Res, S, P, R As String
   Prj = "" : Res = "" : S = ""

   Do While X.Read()

      P = X(1).ToString()  ' Project
      R = X(2).ToString()  ' Resource
      If R <> Res And Res <> "" Then S = S + "/>" ' End previous resource row
   
      If P <> Prj Then                ' New project row
         If Prj <> "" Then S = S + "</I>" ' Ends previous project row
         Prj = P
         S = S + "<I Def='Node' Project='" + Prj.Replace("&", "&amp;").Replace("'", "&apos;").Replace("<", "&lt;") + "'>"
      End If
   
      If R <> Res Then                  ' New resource row
         Res = R
         S = S + "<I Project='" + Res.Replace("&", "&amp;").Replace("'", "&apos;").Replace("<", "&lt;") + "' "
      End If
   
      S = S + "W" + X(3).ToString() + "='" + X(4).ToString() + "' " ' Week = Hours (like W42='17')
   Loop

   If Res <> "" Then S = S + "/>" ' End previous resource row
   If Prj <> "" Then S = S + "</I>" ' Ends previous project row
   ' --------------------------------------------------------------------------
%><?xml version="1.0" ?>
<Grid>
   <Body>
      <B>
         <%=S%>
      </B>
   </Body>
</Grid>