Sunteți pe pagina 1din 11

COBEHIND

-------------------------------
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class TreeGrid : Inherits System.Web.UI.Page
Dim G, BB, B, I, cfg, col, c1, c2, c3, c4, a1, a2, a3, a4, a5 As System.Xml.
XmlElement
Dim w1, w2, w3, w4, w5, w6 As System.Xml.XmlElement
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' --- Database initialization ---
Dim Path As String : Path = System.IO.Path.GetDirectoryName(Context.Requ
est.PhysicalPath)
Dim Conn As System.Data.SqlClient.SqlConnection : Conn = New System.Data
.SqlClient.SqlConnection("Data Source=serbifcorvu4;Initial Catalog=bpm;uid=user_
app;password=APPBIF%1")
Dim Sql As System.Data.SqlClient.SqlDataAdapter : Sql = New System.Data.
SqlClient.SqlDataAdapter("sp_prueba_treegrid", Conn)
Dim D As System.Data.DataTable : D = New System.Data.DataTable()
Sql.SelectCommand.CommandType = CommandType.StoredProcedure
Sql.Fill(D)
' --- 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.Globalizat
ion.CultureInfo.CreateSpecificCulture("en-US")
Dim X As System.Xml.XmlDocument : X = New System.Xml.XmlDocument()
' --- Save data to database ---
Dim XML As String : XML = Request("TGData")
If XML <> "" And XML <> Nothing Then
'X.LoadXml(HttpUtility.HtmlDecode(XML))
'Dim Ch As System.Xml.XmlNodeList : Ch = X.GetElementsByTagName("Cha
nges")
'If Ch.Count > 0 Then
' For Each I As System.Xml.XmlElement In Ch(0)
' Dim id As String : id = I.GetAttribute("id")
' Dim R As System.Data.DataRow
' If I.GetAttribute("Added") = "1" Then
' R = D.NewRow()
' R("ID") = id
' D.Rows.Add(R)
' Else
' R = D.Select("[ID]='" + id + "'")(0)
' End If
' If I.GetAttribute("Deleted") = "1" Then
' R.Delete()
' ElseIf I.GetAttribute("Added") = "1" Or I.GetAttribute("Cha
nged") = "1" Then
' If I.HasAttribute("codigo") Then R("codigo") = I.GetAtt
ribute("codigo")
' If I.HasAttribute("descripcion") Then R("descripcion")
= I.GetAttribute("descripcion")
' End If
' Next I
'End If
'Dim Bld As System.Data.SqlClient.SqlCommandBuilder : Bld = New Syst
em.Data.SqlClient.SqlCommandBuilder(Sql)
'Sql.Update(D) ' Updates changed to database
'D.AcceptChanges()
'Response.Write("<Grid><IO Result='0'/></Grid>")
Else
' --- Load data from database ---
'<?xml version="1.0" encoding="utf-8" ?>
'<Grid>
' <Cfg id='Simple6' MainCol='id'/>
' <Cols>
' <C Name='id' Width='150'/>
' <C Name='codigo'/>
' <C Name='descripcion'/>
' </Cols>
' - <Body>
' - <B>
G = X.CreateElement("Grid") : X.AppendChild(G)
cfg = X.CreateElement("Cfg") : G.AppendChild(cfg)
cfg.SetAttribute("id", "Simpl")
cfg.SetAttribute("MainCol", "id")
cfg.SetAttribute("Editing", "0")
col = X.CreateElement("Cols") : G.AppendChild(col)
c1 = X.CreateElement("C") : col.AppendChild(c1)
c1.SetAttribute("Name", "id")
c2 = X.CreateElement("C") : col.AppendChild(c2)
c2.SetAttribute("Name", "codigo")
c2.SetAttribute("Visible", "0")
c3 = X.CreateElement("C") : col.AppendChild(c3)
c3.SetAttribute("Name", "descripcion")
c4 = X.CreateElement("C") : col.AppendChild(c4)
c4.SetAttribute("Name", "combo")
c4.SetAttribute("Type", "Html")

BB = X.CreateElement("Body") : G.AppendChild(BB)
B = X.CreateElement("B") : BB.AppendChild(B)
Dim valida As Boolean
valida = True
For h As Integer = 0 To D.Rows.Count - 1
If h = 0 Then
w1 = X.CreateElement("I")
B.AppendChild(w1)
w1.SetAttribute("id", D.Rows(h).Item("grupo_codigo1").ToStri
ng)
w1.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo1").To
String)
w1.SetAttribute("descripcion", D.Rows(h).Item("grupo_descrip
cion1").ToString)
w1.SetAttribute("combo", " <select onchange = forward(this.v
alue)><option value=0>Pagina 1</option> <option value=1>Pagina 2</option><option
value=2>Pagina 3</option> </select> ")
w1.SetAttribute("Expanded", "0")
w2 = X.CreateElement("I")
w1.AppendChild(w2)
w2.SetAttribute("id", D.Rows(h).Item("grupo_codigo2").ToStri
ng)
w2.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo2").To
String)
w2.SetAttribute("descripcion", D.Rows(h).Item("grupo_descrip
cion2").ToString)
w2.SetAttribute("Expanded", "0")
w3 = X.CreateElement("I")
w2.AppendChild(w3)
w3.SetAttribute("id", D.Rows(h).Item("grupo_codigo3").ToStri
ng)
w3.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo3").To
String)
w3.SetAttribute("descripcion", D.Rows(h).Item("grupo_descrip
cion3").ToString)
w3.SetAttribute("Expanded", "0")
w4 = X.CreateElement("I")
w3.AppendChild(w4)
w4.SetAttribute("id", D.Rows(h).Item("grupo_codigo4").ToStri
ng)
w4.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo4").To
String)
w4.SetAttribute("descripcion", D.Rows(h).Item("grupo_descrip
cion4").ToString)
w4.SetAttribute("Expanded", "0")
w5 = X.CreateElement("I")
w4.AppendChild(w5)
w5.SetAttribute("id", D.Rows(h).Item("grupo_codigo5").ToStri
ng)
w5.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo5").To
String)
w5.SetAttribute("descripcion", D.Rows(h).Item("grupo_descrip
cion5").ToString)
w5.SetAttribute("Expanded", "0")
w6 = X.CreateElement("I")
w5.AppendChild(w6)
w6.SetAttribute("id", D.Rows(h).Item("cuenta_codigo").ToStri
ng)
w6.SetAttribute("codigo", D.Rows(h).Item("cuenta_codigo").To
String)
w6.SetAttribute("descripcion", D.Rows(h).Item("cuenta_descri
pcion").ToString)
w6.SetAttribute("Expanded", "0")
Else
If D.Rows(h).Item("grupo_codigo1") <> D.Rows(h - 1).Item("gr
upo_codigo1") Then
w1 = Nothing
w2 = Nothing
w3 = Nothing
w4 = Nothing
w5 = Nothing
w6 = Nothing
' Dim w1 As System.Xml.XmlElement
w1 = X.CreateElement("I")
B.AppendChild(w1)
w1.SetAttribute("id", D.Rows(h).Item("grupo_codigo1").To
String)
w1.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo1"
).ToString)
w1.SetAttribute("descripcion", D.Rows(h).Item("grupo_des
cripcion1").ToString)
w1.SetAttribute("Expanded", "0")
w2 = X.CreateElement("I")
w1.AppendChild(w2)
w2.SetAttribute("id", D.Rows(h).Item("grupo_codigo2").To
String)
w2.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo2"
).ToString)
w2.SetAttribute("descripcion", D.Rows(h).Item("grupo_des
cripcion2").ToString)
w2.SetAttribute("Expanded", "0")
w3 = X.CreateElement("I")
w2.AppendChild(w3)
w3.SetAttribute("id", D.Rows(h).Item("grupo_codigo3").To
String)
w3.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo3"
).ToString)
w3.SetAttribute("descripcion", D.Rows(h).Item("grupo_des
cripcion3").ToString)
w3.SetAttribute("Expanded", "0")
w4 = X.CreateElement("I")
w3.AppendChild(w4)
w4.SetAttribute("id", D.Rows(h).Item("grupo_codigo4").To
String)
w4.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo4"
).ToString)
w4.SetAttribute("descripcion", D.Rows(h).Item("grupo_des
cripcion4").ToString)
w4.SetAttribute("Expanded", "0")
w5 = X.CreateElement("I")
w4.AppendChild(w5)
w5.SetAttribute("id", D.Rows(h).Item("grupo_codigo5").To
String)
w5.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo5"
).ToString)
w5.SetAttribute("descripcion", D.Rows(h).Item("grupo_des
cripcion5").ToString)
w5.SetAttribute("Expanded", "0")
w6 = X.CreateElement("I")
w5.AppendChild(w6)
w6.SetAttribute("id", D.Rows(h).Item("cuenta_codigo").To
String)
w6.SetAttribute("codigo", D.Rows(h).Item("cuenta_codigo"
).ToString)
w6.SetAttribute("descripcion", D.Rows(h).Item("cuenta_de
scripcion").ToString)
w6.SetAttribute("Expanded", "0")
'w1 = X.CreateElement("I")
'B.AppendChild(w1)
'w1.SetAttribute("id", D.Rows(h).Item("grupo_codigo1").T
oString)
'w1.SetAttribute("codigo", D.Rows(h).Item("grupo_codigo1
").ToString)
'w1.SetAttribute("descripcion", D.Rows(h).Item("grupo_de
scripcion1").ToString)
Else
If D.Rows(h).Item("grupo_codigo1") = D.Rows(h - 1).Item(
"grupo_codigo1") _
And D.Rows(h).Item("grupo_codigo2"
) <> D.Rows(h - 1).Item("grupo_codigo2") Then
w2 = Nothing
w3 = Nothing
w4 = Nothing
w5 = Nothing
w6 = Nothing
w2 = X.CreateElement("I")
w1.AppendChild(w2)
w2.SetAttribute("id", D.Rows(h).Item("grupo_codigo2"
).ToString)
w2.SetAttribute("codigo", D.Rows(h).Item("grupo_codi
go2").ToString)
w2.SetAttribute("descripcion", D.Rows(h).Item("grupo
_descripcion2").ToString)
w2.SetAttribute("Expanded", "0")
w3 = X.CreateElement("I")
w2.AppendChild(w3)
w3.SetAttribute("id", D.Rows(h).Item("grupo_codigo3"
).ToString)
w3.SetAttribute("codigo", D.Rows(h).Item("grupo_codi
go3").ToString)
w3.SetAttribute("descripcion", D.Rows(h).Item("grupo
_descripcion3").ToString)
w3.SetAttribute("Expanded", "0")
w4 = X.CreateElement("I")
w3.AppendChild(w4)
w4.SetAttribute("id", D.Rows(h).Item("grupo_codigo4"
).ToString)
w4.SetAttribute("codigo", D.Rows(h).Item("grupo_codi
go4").ToString)
w4.SetAttribute("descripcion", D.Rows(h).Item("grupo
_descripcion4").ToString)
w4.SetAttribute("Expanded", "0")
w5 = X.CreateElement("I")
w4.AppendChild(w5)
w5.SetAttribute("id", D.Rows(h).Item("grupo_codigo5"
).ToString)
w5.SetAttribute("codigo", D.Rows(h).Item("grupo_codi
go5").ToString)
w5.SetAttribute("descripcion", D.Rows(h).Item("grupo
_descripcion5").ToString)
w5.SetAttribute("Expanded", "0")
w6 = X.CreateElement("I")
w5.AppendChild(w6)
w6.SetAttribute("id", D.Rows(h).Item("cuenta_codigo"
).ToString)
w6.SetAttribute("codigo", D.Rows(h).Item("cuenta_cod
igo").ToString)
w6.SetAttribute("descripcion", D.Rows(h).Item("cuent
a_descripcion").ToString)
w6.SetAttribute("Expanded", "0")
'' Dim w2 As System.Xml.XmlElement
'w2 = X.CreateElement("I")
'w1.AppendChild(w2)
'w2.SetAttribute("id", D.Rows(h).Item("grupo_codigo2
").ToString)
'w2.SetAttribute("codigo", D.Rows(h).Item("grupo_cod
igo2").ToString)
'w2.SetAttribute("descripcion", D.Rows(h).Item("grup
o_descripcion2").ToString)
Else
If D.Rows(h).Item("grupo_codigo1") = D.Rows(h - 1).I
tem("grupo_codigo1") _
And D.Rows(h).Item("grupo_codigo2") =
D.Rows(h - 1).Item("grupo_codigo2") _
And D.Rows(h).Item("grupo_codigo3") <> D
.Rows(h - 1).Item("grupo_codigo3") Then
' Dim w3 As System.Xml.XmlElement
w3 = Nothing
w4 = Nothing
w5 = Nothing
w6 = Nothing
w3 = X.CreateElement("I")
w2.AppendChild(w3)
w3.SetAttribute("id", D.Rows(h).Item("grupo_codi
go3").ToString)
w3.SetAttribute("codigo", D.Rows(h).Item("grupo_
codigo3").ToString)
w3.SetAttribute("descripcion", D.Rows(h).Item("g
rupo_descripcion3").ToString)
w3.SetAttribute("Expanded", "0")
w4 = X.CreateElement("I")
w3.AppendChild(w4)
w4.SetAttribute("id", D.Rows(h).Item("grupo_codi
go4").ToString)
w4.SetAttribute("codigo", D.Rows(h).Item("grupo_
codigo4").ToString)
w4.SetAttribute("descripcion", D.Rows(h).Item("g
rupo_descripcion4").ToString)
w4.SetAttribute("Expanded", "0")
w5 = X.CreateElement("I")
w4.AppendChild(w5)
w5.SetAttribute("id", D.Rows(h).Item("grupo_codi
go5").ToString)
w5.SetAttribute("codigo", D.Rows(h).Item("grupo_
codigo5").ToString)
w5.SetAttribute("descripcion", D.Rows(h).Item("g
rupo_descripcion5").ToString)
w5.SetAttribute("Expanded", "0")
w6 = X.CreateElement("I")
w5.AppendChild(w6)
w6.SetAttribute("id", D.Rows(h).Item("cuenta_cod
igo").ToString)
w6.SetAttribute("codigo", D.Rows(h).Item("cuenta
_codigo").ToString)
w6.SetAttribute("descripcion", D.Rows(h).Item("c
uenta_descripcion").ToString)
w6.SetAttribute("Expanded", "0")
'w3 = X.CreateElement("I")
'w2.AppendChild(w3)
'w3.SetAttribute("id", D.Rows(h).Item("grupo_cod
igo3").ToString)
'w3.SetAttribute("codigo", D.Rows(h).Item("grupo
_codigo3").ToString)
'w3.SetAttribute("descripcion", D.Rows(h).Item("
grupo_descripcion3").ToString)

Else
If D.Rows(h).Item("grupo_codigo1") = D.Rows(h -
1).Item("grupo_codigo1") _
And D.Rows(h).Item("grupo
_codigo2") = D.Rows(h - 1).Item("grupo_codigo2") _
And D.Rows(h).Item("grupo_c
odigo3") = D.Rows(h - 1).Item("grupo_codigo3") _
And D.Rows(h).Item("grupo
_codigo4") <> D.Rows(h - 1).Item("grupo_codigo4") Then
w4 = Nothing
w5 = Nothing
w6 = Nothing
w4 = X.CreateElement("I")
w3.AppendChild(w4)
w4.SetAttribute("id", D.Rows(h).Item("grupo_
codigo4").ToString)
w4.SetAttribute("codigo", D.Rows(h).Item("gr
upo_codigo4").ToString)
w4.SetAttribute("descripcion", D.Rows(h).Ite
m("grupo_descripcion4").ToString)
w4.SetAttribute("Expanded", "0")
w5 = X.CreateElement("I")
w4.AppendChild(w5)
w5.SetAttribute("id", D.Rows(h).Item("grupo_
codigo5").ToString)
w5.SetAttribute("codigo", D.Rows(h).Item("gr
upo_codigo5").ToString)
w5.SetAttribute("descripcion", D.Rows(h).Ite
m("grupo_descripcion5").ToString)
w5.SetAttribute("Expanded", "0")
w6 = X.CreateElement("I")
w5.AppendChild(w6)
w6.SetAttribute("id", D.Rows(h).Item("cuenta
_codigo").ToString)
w6.SetAttribute("codigo", D.Rows(h).Item("cu
enta_codigo").ToString)
w6.SetAttribute("descripcion", D.Rows(h).Ite
m("cuenta_descripcion").ToString)
w6.SetAttribute("Expanded", "0")
Else
If D.Rows(h).Item("grupo_codigo5") <> D.Rows
(h - 1).Item("grupo_codigo5") _
And D.Rows(h).Item(
"grupo_codigo4") = D.Rows(h - 1).Item("grupo_codigo4") _
And D.Rows(h).Item("g
rupo_codigo3") = D.Rows(h - 1).Item("grupo_codigo3") _
And D.Rows(h).Item(
"grupo_codigo2") = D.Rows(h - 1).Item("grupo_codigo2") _
And D.Rows(h).Item("
grupo_codigo1") = D.Rows(h - 1).Item("grupo_codigo1") Then
w5 = Nothing
w6 = Nothing
'w8 = X.CreateElement("I")
'w7.appendchild(w5)
'w8.setattribute("id", D.Rows(h).Item("g
rupo_codigo7").ToString)
'w8.setattribute("id", D.Rows(h).Item("g
rupo_codigo7").ToString)

w5 = X.CreateElement("I")
w4.AppendChild(w5)
w5.SetAttribute("id", D.Rows(h).Item("gr
upo_codigo5").ToString)
w5.SetAttribute("codigo", D.Rows(h).Item
("grupo_codigo5").ToString)
w5.SetAttribute("descripcion", D.Rows(h)
.Item("grupo_descripcion5").ToString)
w5.SetAttribute("Expanded", "0")
w6 = X.CreateElement("I")
w5.AppendChild(w6)
w6.SetAttribute("id", D.Rows(h).Item("cu
enta_codigo").ToString)
w6.SetAttribute("codigo", D.Rows(h).Item
("cuenta_codigo").ToString)
w6.SetAttribute("descripcion", D.Rows(h)
.Item("cuenta_descripcion").ToString)
w6.SetAttribute("Expanded", "0")
'w5 = X.CreateElement("I")
'w4.AppendChild(w5)
'w5.SetAttribute("id", D.Rows(h).Item("g
rupo_codigo5").ToString)
'w5.SetAttribute("codigo", D.Rows(h).Ite
m("grupo_codigo5").ToString)
'w5.SetAttribute("descripcion", D.Rows(h
).Item("grupo_descripcion5").ToString)
Else
' If D.Rows(h).Item("grupo_codigo5") =
D.Rows(h - 1).Item("grupo_codigo5") _
' And D.Rows(h).Item("grupo_codigo4") =
D.Rows(h - 1).Item("grupo_codigo4") _
'And D.Rows(h).Item("grupo_codigo3") = D
.Rows(h - 1).Item("grupo_codigo3") _
' And D.Rows(h).Item("grupo_codigo2") =
D.Rows(h - 1).Item("grupo_codigo2") _
' And D.Rows(h).Item("grupo_codigo1") =
D.Rows(h - 1).Item("grupo_codigo1") _
' And D.Rows(h).Item("cuenta_codigo") <>
D.Rows(h - 1).Item("cuenta_codigo") Then
w6 = Nothing
w6 = X.CreateElement("I")
w5.AppendChild(w6)
w6.SetAttribute("id", D.Rows(h).Item("cu
enta_codigo").ToString)
w6.SetAttribute("codigo", D.Rows(h).Item
("cuenta_codigo").ToString)
w6.SetAttribute("descripcion", D.Rows(h)
.Item("cuenta_descripcion").ToString)
w6.SetAttribute("Expanded", "0")
'End If
End If
End If
End If
End If
End If
End If
Next
'For Each R As System.Data.DataRow In D.Rows
' If valida = True Then
' I = X.CreateElement("I")
' B.AppendChild(I)
' I.SetAttribute("id", R(0).ToString())
' I.SetAttribute("codigo", R(1).ToString())
' I.SetAttribute("descripcion", R(2).ToString())
' valida = False
' Else
' if R(0).ToString<>
' End If
'Next R
Response.Write(X.InnerXml)
End If
End Sub
End Class

HTML
------------------------------------------------------------------------
<html>
<head>
<script src="../../../Grid/GridE.js"> </script>
<link href="../../../Styles/Examples.css" rel="stylesheet" type="text/css"
/>

<script type="text/javascript">
var url = new Array();
//Agregar urls aqui
url[0] = "pagina1.html";
url[1] = "pagina2.html";
url[2] = "pagina3.html";
url[3] = "pagina4.html";

function forward(index) {
// location.href='http://misitio.com/' + url[index];
location.href="javascript:void(window.open('http://serbifcorvu3/seguimie
nto_propuestas/principal.aspx?cod="+ index +"'))";
//alert('christian');
}
</script>

</head>
<body>
<h2>Page with code behind</h2>
<div style="WIDTH:100%;HEIGHT:99%">
<bdo Debug='1'
Layout_Url="DBDef.xml"
Data_Url="CodeBehind.aspx"
Upload_Url="CodeBehind.aspx" Upload_Format="Internal" Upload_Data=
"TGData"></bdo>
</div>

</body>
</html>

XML
------------------------------------------
<?xml version="1.0"?>
<Grid>
<!-- Cfg tag is splitted by attributes just for comments, you should merge th
em in your standard applications -->
<Cfg id="DB"/> <!-- Grid identification for saving configuration to cook
ies -->
<Cfg Paging='0' ChildPaging='5'/> <!-- Both paging set to client -->
<Cfg PageLength='40'/> <!-- count of rows at one page -->
<Cfg SaveSession='1'/> <!-- Stores IO Session to cookies to identify the clie
nt on server and access appropriate grid instance -->
<Cfg ShowDeleted='1'/> <!-- This example hides deleted row instead of colorin
g them red -->
<Cfg MaxHeight='1'/> <!-- Grid maximizes height of the main tag on page -->
<Cfg IdChars='0123456789' NumberId='1'/> <!-- row ids are set by numbers -->
<Cfg Sort='codigo,descripcion'/>
<Cfg GroupMain='codigo'/> <!-- Shows grouping tree in column Project -->
<Cfg Dragging='0'/> <!-- In this example is dragging not permitted -->
<Cfg UsePrefix='0'/><!-- Uses prefix (GS,GL,GO,GM,GB,GP,GR) for custom class
names to support all style -->
<Cfg Alternate='5'/> <!-- Custom style setting, every third row will have dif
ferent color -->
<Cols>
<C Name='id' Width='250' Type='Text'/>
<C Name='codigo' Width='250' Type='Text'/>
<C Name='descripcion' Width='220' Type='Text'/>
<!--
<C Name='Project' Width='250' Type='Text'/>
<C Name='Resource' Width='120' Type='Text'/>
<C Name='Week' Width='60' Type='Int'/>
<C Name='Hours' Width='60' Type='Float' Format='0.###'/>
-->
</Cols>
<Def>
<!-- <D Name='Group' ProjectVisible='0' ResourceVisible='0' AggChildr
en='1'
Calculated='1' WeekFormula='min()+"-"+max()' WeekType='Text' WeekClassI
nner='Number' HoursFormula='sum()'/>
Default row for grouping, calculates summary for its group
-->
</Def>
<Head>
<!-- Filter row -->
<!--
<Group Space='1' Panel='1'
Cells='List,Custom'
List='|Group by none|Group by Project|Group by Resource|Group by Projec
t -> Resource'
ListCustom='Custom grouping'
ListWidth='180'
Cols='||Project|Resource|Project,Resource'
/>
-->
<!-- Grouping row -->
</Head>
<Pager Width='170'/> <!-- Right side pager -->
</Grid>