public detCartera detCartera() { try { detCartera ct = new detCartera(); List <Facturas> detFacturas = new List <Facturas>(); PROC_CLEINTES_DB pros = new PROC_CLEINTES_DB(); DataTable dt = new DataTable(); dt = pros.DET_CARTERA(); detFacturas = (from DataRow dr in dt.Rows select new Facturas() { CORRIENTE = dr["CORRIENTE"].ToString(), MES1 = dr["MES1"].ToString(), MES2 = dr["MES2"].ToString(), MES3 = dr["MES3"].ToString(), MES4 = dr["MES4"].ToString() }).ToList(); int contCorr = 0; double totalSumaCorr = 0; int contMes1 = 0; double totalSumaMes1 = 0; int contMes2 = 0; double totalSumaMes2 = 0; int contMes3 = 0; double totalSumaMes3 = 0; int contMes4 = 0; double totalSumaMes4 = 0; foreach (Facturas s in detFacturas) { if (double.Parse(s.CORRIENTE) != 0) { totalSumaCorr += double.Parse(s.CORRIENTE); contCorr++; } if (double.Parse(s.MES1) != 0) { totalSumaMes1 += double.Parse(s.MES1); contMes1++; } if (double.Parse(s.MES2) != 0) { totalSumaMes2 += double.Parse(s.MES2); contMes2++; } if (double.Parse(s.MES3) != 0) { totalSumaMes3 += double.Parse(s.MES3); contMes3++; } if (double.Parse(s.MES4) != 0) { totalSumaMes4 += double.Parse(s.MES4); contMes4++; } } ct.TOTAL_CARTERA = (totalSumaCorr + totalSumaMes1 + totalSumaMes2 + totalSumaMes3 + totalSumaMes4); ct.TOTAL_FAC_CORRIENTE = contCorr; ct.SUMA_VALOR_CORRIENTE = totalSumaCorr; ct.TOTAL_FAC_MES1 = contMes1; ct.SUMA_VALOR_MES1 = totalSumaMes1; ct.TOTAL_FAC_MES2 = contMes2; ct.SUMA_VALOR_MES2 = totalSumaMes2; ct.TOTAL_FAC_MES3 = contMes3; ct.SUMA_VALOR_MES3 = totalSumaMes3; ct.TOTAL_FAC_MES4 = contMes4; ct.SUMA_VALOR_MES4 = totalSumaMes4; return(ct); } catch (Exception Ex) { throw Ex; } }