Когда я передаю более 1 группы строк, номер SR правильно добавляется в таблицу, но если только одна группа строк, то SR не пропускается
см. мой метод (C#)`
Категория
Стул
Письменный стол
Джинсы
Ноутбук
Телефон
Рубашка
Диван
Стол
Стол
Телефон
Рубашка
Диван
Стол
th>
Планшет
Всего
Одежда
280
500
780
Электроника
2450< /td>
1600
700
1020
5770
Мебель
150
850
1300
200
< /td>
2500
Общая сумма
150
850
280
2450
1600< /td>
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);
}
//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;
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... html-table
Динамическая сводная HTML-таблица ⇐ C#
Место общения программистов C#
1728322817
Anonymous
Когда я передаю более 1 группы строк, номер SR правильно добавляется в таблицу, но если только одна группа строк, то SR не пропускается
см. мой метод (C#)`
Категория
Стул
Письменный стол
Джинсы
Ноутбук
Телефон
Рубашка
Диван
Стол
Стол
Телефон
Рубашка
Диван
Стол
th>
Планшет
Всего
Одежда
280
500
780
Электроника
2450< /td>
1600
700
1020
5770
Мебель
150
850
1300
200
< /td>
2500
Общая сумма
150
850
280
2450
1600< /td>
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;
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79062105/dynamic-pivot-html-table[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия