3
Here is my query:
select
u.nome as analista,
s.descricao as situacao,
count(*) as qtd
from tb_projeto p
inner join tb_usuario u on u.id_usuario = p.id_usuario
inner join tb_situacao s on s.id_situacao = p.id_situacao
group by analista, situacao
order by analista
And the result of it:
When I receive this in a Datatable I make some rebounds and turn these 3 columns into a Cross Table, but as not all analysts have the values of the quantities "Disapproved" greater than zero it does not appear in Datatable which breaks my total in the interface:
public DataTable CrossTable(DataTable dtS, String leftColumn, String topField, String dataValue, String pFix = "F_")
{
if (dtS == null)
{
return null;
}
DataTable dtOut = new DataTable();
DataTable dtRowTitle = new DataTable();
DataTable dtColHeader = new DataTable();
dtRowTitle = dtS.DefaultView.ToTable(true, dtS.Columns[leftColumn].ColumnName);
dtColHeader = dtS.DefaultView.ToTable(true, dtS.Columns[topField].ColumnName);
DataColumn dColx = new DataColumn();
dColx.ColumnName = leftColumn;
dColx.Caption = leftColumn;
dtOut.Columns.Add(dColx);
foreach (DataRow drow in dtColHeader.Rows)
{
DataColumn dCol = new DataColumn();
dCol.ColumnName = pFix + drow[topField].ToString().Trim();
dtOut.Columns.Add(dCol);
}
DataColumn dColx2 = new DataColumn();
dColx2.ColumnName = "TOTAL";
dtOut.Columns.Add(dColx2);
DataRow drowx;
foreach (DataRow drow in dtRowTitle.Rows)
{
drowx = dtOut.NewRow();
drowx[0] = drow[leftColumn];
dtOut.Rows.Add(drowx);
}
Int32 xVal = 0, yVal = 0;
string analista = null;
int total = 0;
foreach (DataRow mRow in dtS.Rows)
{
string xRowVal = mRow[leftColumn].ToString(), dataVal = mRow[dataValue].ToString(), yColVal = mRow[topField].ToString().Trim();
foreach (DataRow nRow in dtOut.Rows)
{
if (xRowVal == nRow[0].ToString())
{
for (xVal = 0; xVal < nRow.Table.Columns.Count; xVal++)
{
if (nRow.Table.Columns[xVal].ColumnName == pFix + yColVal)
{
if (xVal == 1)
{
total = 0;
analista = xRowVal;
}
Int32 rIndex = dtOut.Rows.IndexOf(nRow);
dtOut.Rows[rIndex][xVal] = dataVal;
if (analista == xRowVal)
{
total += Convert.ToInt32(dataVal);
}
if (xVal + 2 == nRow.Table.Columns.Count)
{
dtOut.Rows[rIndex][3] = total.ToString();
}
}
}
}
}
}
dtOut.DefaultView.Sort = dtOut.Columns[0].ColumnName;
return dtOut;
}
With some analysts' "Fail" columns not even being processed my total gets wrong. How to solve this problem?
By making the ripples check if the field is
null
and assign 0. Post the code of ripples to facilitate aid.– Jothaz
Ready dude, the buzz has been added.
– Lucas Vasconcelos