Динамическая сводная HTML-таблицаC#

Место общения программистов C#
Anonymous
Динамическая сводная HTML-таблица

Сообщение Anonymous »

Код: Выделить всё

now when i pass more then 1 row group then sr number is proper add in table but when only one roe group then sr no td skip please see my method (C#)

Код: Выделить всё

Category    Chair   Desk    Jeans   Laptop  Phone   Shirt   Sofa    Table   Tablet  Total

Код: Выделить всё

Clothing           280         500             780

Код: Выделить всё

Electronics                2450    1600    700         1020    5770

Код: Выделить всё

Furniture  150 850                 1300    200     2500

Код: Выделить всё

Grand Total    150 850 280 2450    1600    1200    1300    200 1020    9050

Код: Выделить всё

public string NestedLoopsSum(Dictionary dict, int depth, List `RowGroup, List ColumnGroup)

Код: Выделить всё

string key = String.Empty;
Int32 rowspan;
//When Function reaches at last level

//Starting of HTML Table Row
if (depth == RowGroup.Count)
{
htmlcode += "";
cellIndex = 0;

Int32 n = 0;
while (n < RowGroup.Count)
{`your text`
rowspan = 0;
string intString = string.Empty;

if (n + 1 < RowGroup.Count)
{
rspanIndex = n;
rowspan = RowSpan(ds, RowGroup, n);
loopCount = 0;
rspanSum = 0;
if (dsRspan.Tables.Count > 0)
{
for (Int32 i = 0; i < dsRspan.Tables.Count; i++)
dsRspan.Tables.Remove(dsRspan.Tables[i]);
}
//for (Int32 k = n + 1; k < RowGroup.Count; k++)
//{
//    rowspan *= dict[RowGroup[(RowGroup.Count - (k - n))].ToString()].Count;
//    rowspan++;
//}
if (n == 0 && rNum[n] % rowspan == 0)
{
intString += "" + srNo + "";
srNo++;
}
if (rNum[n] % rowspan == 0)
intString += "" + values.ElementAt(n).ToString() + "";
}
else
htmlcode += "" + values.ElementAt(n).ToString() + "";

rSpan.Clear();
htmlcode += intString;
n++;

}
//MessageBox.Show(rowNumber.ToString());
//rowNumber++;
for (Int32 len = 0; len < RowGroup.Count; len++)
rNum[len] = rNum[len] + 1;
}

if (depth == dict.Count)
{
Int32 ct1 = 0;

foreach (DataRow dr in ds.Tables[RowGroup.Count - 1].Rows)
{
ct = 0;
for (Int32 p = 0; p < values.Count; p++)
{
if (dr[p].ToString() == values.ElementAt(p).ToString())
ct++;

if (ct == values.Count)
{
htmlcode += "" + dr["SUM"] + "";
//MessageBox.Show((vSum[0][cellIndex]).ToString());
foreach (int vskey in vSum.Keys)
vSum[vskey][cellIndex] += Convert.ToDecimal(dr["SUM"]);
cellIndex++;
ct1++;

for (Int32 t = 0; t < ColumnGroup.Count; t++)
{
hSum[t] += Convert.ToDecimal(dr["SUM"]);
}

}
}
}
if (ct1 == 0)
{
htmlcode += "";
foreach (var vskey in vSum.Keys)
vSum[vskey][cellIndex] += 0;
cellIndex++;
}

}

//Nesting of Dynamic For loops
if (depth < dict.Count)
{
if (depth < RowGroup.Count)
{
key = dict.Keys.ElementAt(depth);
int maxValue = dict[key].Count;

for (Int32 i = 0; i   0)
{
ds.Tables.Add(dtIMTable.Select(Expression).CopyToDataTable());
NestedLoopsSum(dict, depth + 1, RowGroup, ColumnGroup);

ds.Tables.Remove(ds.Tables[depth]);
}

values.RemoveAt(values.Count - 1);
}
else
{
DataRow[] filteredRows = ds.Tables[depth - 1].Select(Expression);
if (filteredRows.Length > 0)
{
ds.Tables.Add(ds.Tables[depth - 1].Select(Expression).CopyToDataTable());
NestedLoopsSum(dict, depth + 1, RowGroup, ColumnGroup);

ds.Tables.Remove(ds.Tables[depth]);
}
values.RemoveAt(values.Count - 1);
}
}
else if (i == maxValue)
{
if (depth == 0)
htmlcode += "Grand Total";
else
htmlcode += "Total";

for (Int32 z = 0; z < cellNo; z++)
htmlcode += "" + vSum[values.Count][z] + "";

for (Int32 length = 0; length < RowGroup.Count; length++)
rNum[length]++;

if (values.Count > 0)
{
for (Int32 k = values.Count - 1; k < RowGroup.Count; k++)
rNum[k] = 0;
}

htmlcode += "";
//rowNumber++;
//MessageBox.Show(rowNumber.ToString());
}
}
}
else
{
key = dict.Keys.ElementAt(depth);
int maxValue = dict[key].Count;
for (Int32 i = 0; i < maxValue; i++)
{
values.Add(dict[key].ElementAt(i));
NestedLoopsSum(dict, depth + 1, RowGroup, ColumnGroup);
values.RemoveAt(values.Count - 1);
}
}

if (depth > RowGroup.Count)
{
for (Int32 r = 1; r < ColumnGroup.Count; r++)
{
if (depth == AllColumns.Count - r)
{
htmlcode += "" + hSum[AllColumns.Count - depth] + "";
foreach (var vskey in vSum.Keys)
vSum[vskey][cellIndex] += hSum[AllColumns.Count - depth];
cellIndex++;
hSum[AllColumns.Count - depth] = 0;

}
}
}
if (depth == RowGroup.Count)
{
htmlcode += "" + hSum[0] + "";
foreach (var vskey in vSum.Keys)
vSum[vskey][cellIndex] += hSum[0];
cellIndex++;
hSum[0] = 0;
htmlcode += "";
}
if (depth < RowGroup.Count)
{
for (Int32 z = 0; z < cellNo; z++)
vSum[depth][z] = 0;
}
}
return htmlcode;
}

Код: Выделить всё

Thank you


Подробнее здесь: https://stackoverflow.com/questions/790 ... html-table

Вернуться в «C#»