<%@ Page language="vb" Debug="true"%><%
   ' -------------------------------------------------------------------------- 
   '! Support file only, run AjaxGrid.html instead !
   ' This file is used as Layout_Url for TreeGrid
   ' It generates layout structure 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 layout ---
   Cmd.CommandText = "SELECT MIN(Week),MAX(Week) FROM TableData"
   Dim R As System.Data.OleDb.OleDbDataReader : R = Cmd.ExecuteReader()
   R.Read()
   Dim i, Min, Max As Integer
   Min = CInt(CDbl(R(0)))
   Max = CInt(CDbl(R(1)))
   Dim Cols, CSum, DRes, DDef As String
   Cols = "" : CSum = "" : DRes = "" : DDef = ""
   For i = Min To Max - 1
      Dim Week As String : Week = "W" + i.ToString()
      Cols = Cols + "<C Name='" + Week + "' Type='Float'/>" ' Column definitions
      If CSum <> "" Then CSum = CSum + "+"
      CSum = CSum + Week                                   ' Right fixed result column formula
      DRes = DRes + Week + "Formula='sum()' "              ' Tree result row formulas
      DDef = DDef + Week + "='0' "                         ' Default values for data rows
   Next i
   ' --------------------------------------------------------------------------
%><?xml version="1.0"?>
<Grid>
   <Cfg id='ResourceGrid' MainCol='Project' MaxHeight='1' ShowDeleted="0" DateStrings='1' 
      IdNames='Project' AppendId='1' FullId='1' IdChars='0123456789' NumberId='1' LastId='1' IdCompare='4'/>
   <LeftCols>
      <C Name='id' CanEdit='0'/>
      <C Name='Project' Width='250' Type='Text'/>
   </LeftCols>
   <Cols><%=Cols%>
   </Cols>
   <RightCols>
      <C Name='Sum' Width='50' Type='Float' Formula='<%=CSum%>'/>
   </RightCols>
   <Def>
      <D Name='R' Project='New resource' CDef='' <%=DDef%>/>
      <D Name='Node' Project='New project' CDef='R' Calculated='1' SumFormula='sum()' <%=DRes%> ProjectHtmlPrefix='&lt;B>' ProjectHtmlPostfix='&lt;/B>'/>
   </Def>
   <Header CDef='Node' id='id (debug)' Project='Project / resource'/>
   <Foot>
      <I Kind='User' RelHeight='100' Class='GFillRow'/>
      <I Def='Node' Project='Total results' ProjectCanEdit='0'/>
   </Foot>
</Grid>