9
I have a list of users in which each has a sponsor (sponsor is also a user). Each user has points and is of one type. I want to know which branch of the tree has the highest number of points and for each branch to know how many equal types I have. Suppose I have the tree:
The result would be: For the number of Points of each branch:
and for the number of equal types:
What’s the best way to get this? I created a function that goes through the whole tree and in an array places the points and in another array places the types. Anyway, it is giving error. I’ve been driving around, but I could use some help. The function I created is:
//
// FUNÇÃO TreeBranchPath
int[] TotalPontosRamo = new int[1];
int[,] FolhaInfoPontos = new int[6, 6];
int[,] FolhaInfoPatamar = new int[6, 6];
int CountRamos = 1;
int CountFilhos = 0;
private void TreeBranchPath(int idusr, int usrpnts, int usrpata, int ramo, int filho, bool FirstInteract)
{
FolhaInfoPontos[ramo, filho] = usrpnts;
FolhaInfoPatamar[ramo, filho] = usrpata;
if (FirstInteract)
{
ramo = ramo + 1;
}
/* Inicio - Verifica se tem descendentes - afilhados */
Session["ConfDados"] = Session["ConfDados"] + "Verifica se o User " + idusr + " tem descendentes<br>";
var AfilhadosList = (from af in db.NRV_USERS
where af.idpatrocinador == idusr
select af).ToList();
if (AfilhadosList.Count() != 0)
{
foreach (var descid in AfilhadosList)
{
CountFilhos = CountFilhos + 1;
/* Inicio - Quantos Pontos o User tem */
var UserPoints = (from pnt in db.NRV_USERPONTOS
where pnt.iduser == descid.id_user && pnt.usrpntact == true
select pnt).FirstOrDefault();
int TotalUserPoints = UserPoints.pontosgrupo + UserPoints.pontosproprios;
Session["ConfDados"] = Session["ConfDados"] + "O User " + descid.id_user + " tem " + TotalUserPoints + " pontos (" + UserPoints.pontosgrupo + " + " + UserPoints.pontosproprios + ")<br>";
/* Fim - Quantos Pontos o User tem */
/* Inicio - Em que Patamar o User está */
var AuxUserPatamar = (from cp in db.NRV_USERPATAMAR
where cp.iduser == descid.id_user
select cp.idpatamax).FirstOrDefault();
Session["ConfDados"] = Session["ConfDados"] + "O User " + descid.id_user + " está no Patamar Maximo " + AuxUserPatamar + "<br>";
/* Fim - Em que Patamar o User está */
//FolhaInfoPontos = ResizeArray(FolhaInfoPontos, ramo + 1, numfilho + 1);
//FolhaInfoPatamar = ResizeArray(FolhaInfoPatamar, ramo + 1, numfilho + 1);
TreeBranchPath(descid.id_user, TotalUserPoints, AuxUserPatamar, ramo, CountFilhos, false);
// TotalPontosRamo[ramo] = TotalPontosRamo[ramo] + TotalUserPoints;
ramo = ramo + 1;
}
}
else
{
//ramo = ramo + 1;
CountRamos = CountRamos + 1;
CountFilhos = 0;
Session["ConfDados"] = Session["ConfDados"] + "O User " + idusr + " do Ramo " + ramo + " não descendentes<br><br>";
}
}
I wonder if someone could help me?
I set the arrays to limit 6, but the truth is I don’t know what the limit is. The array should be dynamic in order to always increase the number of branches and children.
– Ricardo Sousa
That’s it! Thank you all for your help and/or tips
– Ricardo Sousa
Ricardo, it seems from the comments that this question was answered, or solved. If it is, consider answering it with its final solution, or has the option of remove the question.
– brazilianldsjaguar