PDA

View Full Version : [CLOSED] Dynamic Menu Error



ucaneto
May 02, 2014, 11:02 PM
I'm trying to create a dynamic menu, the aspx code like this



<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" Theme="Gray" />
<div>
<ext:Viewport ID="Viewport1" runat="server" Layout="border">
<Items>
<ext:Panel ID="Panel1" runat="server" AutoHeight="true" Region="North" Header="false">
<TopBar>
<ext:Toolbar ID="ToolbarTop" runat="server" EnableOverflow="true">
<Items>
</Items>
</ext:Toolbar>
</TopBar>
</ext:Panel>
<ext:Panel ID="Panel9" runat="server" Layout="Fit" Region="Center" BodyStyle="background-image: url('../imagens/fundos/fundo1.gif'); background-repeat: inherit; background-size: cover;">
</ext:Panel>
</Items>
</ext:Viewport>
</div>
</form>
</body>
</html>


In Code Behind



protected void Page_Load(object sender, EventArgs e)
{
TblmenuCollection coll = new TblmenuCollection();
XPerfilPermissoesCollection pcoll = new XPerfilPermissoesCollection();
XPerfilPermissoesQuery odq = new XPerfilPermissoesQuery("odq");

TblmenuQuery oq = new TblmenuQuery("oq");
oq.Select(oq.Idpai, oq.Id, oq.Menu, oq.Formulario, odq.Inclui, odq.Altera, odq.Exclui, odq.Idperfil, oq.Icone);
oq.InnerJoin(odq).On(oq.Id == odq.Idmenu);

oq.Where(odq.Visualiza == 1);
oq.Where(oq.Idpai == 0);
oq.OrderBy(oq.Ordem.Ascending, oq.Idpai.Ascending);
coll.Load(oq);
SplitButton spButton = new SplitButton();
Ext.Net.Menu menu = new Ext.Net.Menu();
foreach (var item in coll)
{
spButton = new SplitButton();
spButton.ID = item.Id.ToString();
spButton.Text = item.Menu;
Icon MeuIcone = ParseEnum<Icon>(item.Icone);

spButton.Icon = MeuIcone;

menu = new Ext.Net.Menu();
SubItens(item, spButton, menu);
spButton.Menu.Add(menu);
this.ToolbarTop.Items.Add(spButton);
}
}

public static T ParseEnum<T>(string value)
{
return (T)Enum.Parse(typeof(T), value, true);
}


private void SubItens(Tblmenu dataRow, Ext.Net.SplitButton spButton, Ext.Net.Menu menu)
{
TblmenuCollection coll = new TblmenuCollection();
XPerfilPermissoesCollection pcoll = new XPerfilPermissoesCollection();
XPerfilPermissoesQuery odq = new XPerfilPermissoesQuery("odq");

TblmenuQuery oq = new TblmenuQuery("oq");
oq.Select(oq.Idpai, oq.Id, oq.Menu, oq.Formulario, odq.Inclui, odq.Altera, odq.Exclui, odq.Idperfil, oq.Icone);
oq.InnerJoin(odq).On(oq.Id == odq.Idmenu);

oq.Where(odq.Visualiza == 1);
oq.Where(oq.Idpai == dataRow.Id);
oq.OrderBy(oq.Ordem.Ascending, oq.Idpai.Ascending);
coll.Load(oq);

foreach (var menuitem in coll)
{
Ext.Net.MenuItem Mitem = new Ext.Net.MenuItem();
Mitem.Text = menuitem.Menu;
Icon MeuIcone1 = ParseEnum<Icon>(menuitem.Icone);
Mitem.Icon = MeuIcone1;
menu.Items.Add(Mitem);
SubItens(menuitem, spButton, menu);
}
}

After running the project the menu is as image1, which would be the same as image2.

The structure of the data in this database equals image3.

Help me how to solve this problem.

Ulisses

Image1 http://forums.ext.net/attachment.php?attachmentid=10371&stc=1
Image2 http://forums.ext.net/attachment.php?attachmentid=10381&stc=1
Image3 http://forums.ext.net/attachment.php?attachmentid=10391&stc=1

Daniil
May 05, 2014, 7:26 AM
Hi @ucaneto,

Do you mean the result Menu doesn't match the config in the database?

ucaneto
May 05, 2014, 12:54 PM
Hi @ucaneto,

Do you mean the result Menu doesn't match the config in the database?

yes
The result should be equal to image2 and this being equal to image1

Ulisses

Daniil
May 05, 2014, 3:22 PM
There is probably a logical error in your code. I don't see where exactly.

You should debug the SubItens method step by step.

ucaneto
May 05, 2014, 9:20 PM
There is probably a logical error in your code. I don't see where exactly.

You should debug the SubItens method step by step.

Do you have any examples of recursive menu to send me?

Ulisses

Daniil
May 06, 2014, 6:51 AM
Unfortunately, I don't have such an example.

I guess the problem as here:

SubItens(menuitem, spButton, menu);

You pass the same "menu" for each call. You should populate a MenuItem's Menu.

RCN
Feb 04, 2015, 3:18 AM
Example: http://forums.ext.net/showthread.php?53142