public Ver_Reporte_Form(List<SampleDesignItem> datos, List<string> opciones) { InitializeComponent(); try { tStudentTable = new TStudentBL(Program.ContextData); stratums = new StratumBL(Program.ContextData); project = new PROYECTO(); PROYECTO currentProject = (PROYECTO)Program.Cache.Get("project"); //Cargando datos del proyecto al reporte if (project != null) { TypeSampleDesignBl tipoDiseno = new TypeSampleDesignBl(Program.ContextData); ObjectiveInventoryBL objetivoInventario = new ObjectiveInventoryBL(Program.ContextData); project.NOMTIPODISEMUEST = tipoDiseno.GetTypeSampleDesign(currentProject.NOMTIPODISEMUEST).DESCRIPTIPODISEMUEST; project.NOMBRETIPOINV = objetivoInventario.GetObjectiveInventory(currentProject.NOMBRETIPOINV).DESCRIPOBJETINV; project.INTMUE = Math.Round(currentProject.INTMUE, 3); project.TAMANO = Math.Round(currentProject.TAMANO, 3); project.DESCRIPCION = currentProject.DESCRIPCION; project.LUGAR = currentProject.LUGAR; project.FECHA = currentProject.FECHA; project.SUPMUE = Math.Round(currentProject.SUPMUE, 3); project.SUPTOT = Math.Round(currentProject.SUPTOT, 3); Decimal confianza = currentProject.CONFIANZA != null ? (decimal)currentProject.CONFIANZA : 0; project.CONFIANZA = Math.Round(confianza, 3); this.estratificado = currentProject.LISTADODEESTRATOS.Count != 0 ? true : false; proyectoBS.DataSource = project; } Dictionary<string, object> resultados = new Dictionary<string, object>(); if (datos.Count != 0) { double tamanoParcela = project != null ? (double)project.TAMANO : 1; double totalParcelas = project != null ? (int)(project.SUPTOT / project.TAMANO) : 0; int totalParcelasMuestra = datos.Count; double superficieTotal = project != null ?(double)project.SUPTOT:0; RESULTADOMUESTREO resultado; TOTALESMUESTREOESTRATIFICADOS totales; TSTUDENT resulttStudent = tStudentTable.GetTStudent((decimal)(1 - currentProject.CONFIANZA / 100), (totalParcelasMuestra - 1)); TSTUDENT tStudent = resulttStudent != null ? resulttStudent : new TSTUDENT(); if (!estratificado) { // SampleDesign diseno = new SampleDesign(currentProject, tStudent, datos, totalParcelasMuestra, totalParcelas, 0); resultados = diseno.Execute(0); //Cargando resultado de los datos al reporte if (opciones.Contains("NA")) { resultado = new RESULTADOMUESTREO(); resultado.VARIABLE = "Numero de arboles (#)"; resultado.TOTAL = superficieTotal * Math.Round((double)resultados["Mean"], 3); resultado.PROMEDIO = Math.Round((double)resultados["Mean"], 3); resultado.DESVIACIONESTANDAR = Math.Round((double)resultados["StandardDeviation"], 3); resultado.COEFICIENTEDEVARIACION = Math.Round((double)resultados["VariationCoefficient"], 3); resultado.ERRORDESVIACION = Math.Round((double)resultados["StandardError"], 3); resultado.ERRORABSOLUTOMUESTREO = Math.Round((double)resultados["AbsoulteErrorSample"], 3); resultado.LIMITEINF = Math.Round((double)resultados["LowLimit"], 3); resultado.LIMITESUP = Math.Round((double)resultados["HightLimit"], 3); resultado.ERRORRELATIVO = Math.Round((double)resultados["RelativeErrorSample"], 3); resultadosBS.Add(resultado); } if (opciones.Contains("AB")) { resultados = diseno.Execute(3); resultado = new RESULTADOMUESTREO(); resultado.VARIABLE = "Area Basal (Mtrs2)"; resultado.TOTAL = superficieTotal * Math.Round((double)resultados["Mean"], 3); resultado.PROMEDIO = Math.Round((double)resultados["Mean"], 3); resultado.DESVIACIONESTANDAR = Math.Round((double)resultados["StandardDeviation"], 3); resultado.COEFICIENTEDEVARIACION = Math.Round((double)resultados["VariationCoefficient"], 3); resultado.ERRORDESVIACION = Math.Round((double)resultados["StandardError"], 3); resultado.ERRORABSOLUTOMUESTREO = Math.Round((double)resultados["AbsoulteErrorSample"], 3); resultado.LIMITEINF = Math.Round((double)resultados["LowLimit"], 3); resultado.LIMITESUP = Math.Round((double)resultados["HightLimit"], 3); resultado.ERRORRELATIVO = Math.Round((double)resultados["RelativeErrorSample"], 3); resultadosBS.Add(resultado); } if (opciones.Contains("VC")) { resultados = diseno.Execute(1); resultado = new RESULTADOMUESTREO(); resultado.VARIABLE = "Volumen Comercial (Mtrs3)"; resultado.TOTAL = superficieTotal * Math.Round((double)resultados["Mean"], 3); resultado.PROMEDIO = Math.Round((double)resultados["Mean"], 3); resultado.DESVIACIONESTANDAR = Math.Round((double)resultados["StandardDeviation"], 3); resultado.COEFICIENTEDEVARIACION = Math.Round((double)resultados["VariationCoefficient"], 3); resultado.ERRORDESVIACION = Math.Round((double)resultados["StandardError"], 3); resultado.ERRORABSOLUTOMUESTREO = Math.Round((double)resultados["AbsoulteErrorSample"], 3); resultado.LIMITEINF = Math.Round((double)resultados["LowLimit"], 3); resultado.LIMITESUP = Math.Round((double)resultados["HightLimit"], 3); resultado.ERRORRELATIVO = Math.Round((double)resultados["RelativeErrorSample"], 3); resultadosBS.Add(resultado); } if (opciones.Contains("VT")) { resultados = diseno.Execute(2); resultado = new RESULTADOMUESTREO(); resultado.VARIABLE = "Volumen Total (Mtrs3)"; resultado.TOTAL = superficieTotal * Math.Round((double)resultados["Mean"], 3); resultado.PROMEDIO = Math.Round((double)resultados["Mean"], 3); resultado.DESVIACIONESTANDAR = Math.Round((double)resultados["StandardDeviation"], 3); resultado.COEFICIENTEDEVARIACION = Math.Round((double)resultados["VariationCoefficient"], 3); resultado.ERRORDESVIACION = Math.Round((double)resultados["StandardError"], 3); resultado.ERRORABSOLUTOMUESTREO = Math.Round((double)resultados["AbsoulteErrorSample"], 3); resultado.LIMITEINF = Math.Round((double)resultados["LowLimit"], 3); resultado.LIMITESUP = Math.Round((double)resultados["HightLimit"], 3); resultado.ERRORRELATIVO = Math.Round((double)resultados["RelativeErrorSample"], 3); resultadosBS.Add(resultado); } } else { //Cargar datos del analisis de los datos estratificados al proyecto SampleDesign diseno = new SampleDesign(currentProject, tStudent, datos, totalParcelasMuestra, totalParcelas, 1); //Cargando resultado de los datos al reporte Dictionary<string, object> resultadosTemporales = null; if (opciones.Contains("NA")) { resultados = diseno.Execute(0); foreach (KeyValuePair<string, object> resultStratum in resultados) { resultadosTemporales = (Dictionary<string, object>)resultStratum.Value; resultado = new RESULTADOMUESTREO(); if (resultStratum.Key != "totales") { ESTRATO stratum = stratums.GetStratum(int.Parse(resultStratum.Key)); resultado.ESTRATO = stratum != null ? stratum.DESCRIPESTRATO : resultStratum.Key; resultado.PESOESTRATO = Math.Round((double)resultadosTemporales["Weight"], 3); resultado.VARIABLE = "Numero de arboles (#)"; resultado.N = resultadosTemporales["N"].ToString(); resultado.TOTAL = totalParcelas * Math.Round((double)resultadosTemporales["Mean"], 3); resultado.TOTALPORHECTAREA = resultado.TOTAL / (double)currentProject.SUPTOT; resultado.PROMEDIO = Math.Round((double)resultadosTemporales["Mean"], 3); resultado.DESVIACIONESTANDAR = Math.Round((double)resultadosTemporales["StandardDeviation"], 3); resultado.COEFICIENTEDEVARIACION = Math.Round((double)resultadosTemporales["VariationCoefficient"], 3); resultado.ERRORDESVIACION = Math.Round((double)resultadosTemporales["StandardError"], 3); resultado.ERRORABSOLUTOMUESTREO = Math.Round((double)resultadosTemporales["AbsoulteErrorSample"], 3); resultado.LIMITEINF = Math.Round((double)resultadosTemporales["LowLimit"], 3); resultado.LIMITESUP = Math.Round((double)resultadosTemporales["HightLimit"], 3); resultado.ERRORRELATIVO = Math.Round((double)resultadosTemporales["RelativeErrorSample"], 3); resultadosBS.Add(resultado); } } //TODO:añadir total los cuales se encuntran al final resultadosTemporales = (Dictionary<string, object>)resultados.Last().Value; totales = new TOTALESMUESTREOESTRATIFICADOS(); totales.VARIABLE = "Numero de arboles (#)"; totales.TOTALPROMEDIOESTRATIFICADO = Math.Round((double)resultadosTemporales["Mean"], 3); totales.TOTALDESESTANDARESTRATIFICADO = Math.Round((double)resultadosTemporales["StandardError"], 3); totales.TOTALERRORMUESTREO = Math.Round((double)resultadosTemporales["AbsoulteErrorSample"], 3); totales.TOTALERRRORELATIVO = Math.Round((double)resultadosTemporales["RelativeErrorSample"], 3); totalEstratificadoBS.Add(totales); } if (opciones.Contains("AB")) { resultados = diseno.Execute(3); //Cargando resultado de los datos al reporte foreach (KeyValuePair<string, object> resultStratum in resultados) { resultadosTemporales = (Dictionary<string, object>)resultStratum.Value; resultado = new RESULTADOMUESTREO(); if (resultStratum.Key != "totales") { ESTRATO stratum = stratums.GetStratum(int.Parse(resultStratum.Key)); resultado.ESTRATO = stratum != null ? stratum.DESCRIPESTRATO : resultStratum.Key; resultado.PESOESTRATO = Math.Round((double)resultadosTemporales["Weight"], 3); resultado.N = resultadosTemporales["N"].ToString(); resultado.VARIABLE = "Area Basal (Mtrs2)"; resultado.TOTAL = totalParcelas * Math.Round((double)resultadosTemporales["Mean"], 3); resultado.TOTALPORHECTAREA = resultado.TOTAL / (double)currentProject.SUPTOT; resultado.PROMEDIO = Math.Round((double)resultadosTemporales["Mean"], 3); resultado.DESVIACIONESTANDAR = Math.Round((double)resultadosTemporales["StandardDeviation"], 3); resultado.COEFICIENTEDEVARIACION = Math.Round((double)resultadosTemporales["VariationCoefficient"], 3); resultado.ERRORDESVIACION = Math.Round((double)resultadosTemporales["StandardError"], 3); resultado.ERRORABSOLUTOMUESTREO = Math.Round((double)resultadosTemporales["AbsoulteErrorSample"], 3); resultado.LIMITEINF = Math.Round((double)resultadosTemporales["LowLimit"], 3); resultado.LIMITESUP = Math.Round((double)resultadosTemporales["HightLimit"], 3); resultado.ERRORRELATIVO = Math.Round((double)resultadosTemporales["RelativeErrorSample"], 3); resultadosBS.Add(resultado); } } resultadosTemporales = (Dictionary<string, object>)resultados.Last().Value; totales = new TOTALESMUESTREOESTRATIFICADOS(); totales.VARIABLE = "Area Basal (Mtrs2)"; totales.TOTALPROMEDIOESTRATIFICADO = Math.Round((double)resultadosTemporales["Mean"], 3); totales.TOTALDESESTANDARESTRATIFICADO = Math.Round((double)resultadosTemporales["StandardError"], 3); totales.TOTALERRORMUESTREO = Math.Round((double)resultadosTemporales["AbsoulteErrorSample"], 3); totales.TOTALERRRORELATIVO = Math.Round((double)resultadosTemporales["RelativeErrorSample"], 3); totalEstratificadoBS.Add(totales); } if (opciones.Contains("VC")) { resultados = diseno.Execute(1); //Cargando resultado de los datos al reporte foreach (KeyValuePair<string, object> resultStratum in resultados) { resultadosTemporales = (Dictionary<string, object>)resultStratum.Value; resultado = new RESULTADOMUESTREO(); if (resultStratum.Key != "totales") { ESTRATO stratum = stratums.GetStratum(int.Parse(resultStratum.Key)); resultado.ESTRATO = stratum != null ? stratum.DESCRIPESTRATO : resultStratum.Key; resultado.PESOESTRATO = Math.Round((double)resultadosTemporales["Weight"], 3); resultado.N =resultadosTemporales["N"].ToString(); resultado.VARIABLE = "Volumen Comercial (Mtrs3)"; resultado.TOTAL = totalParcelas * Math.Round((double)resultadosTemporales["Mean"], 3); resultado.TOTALPORHECTAREA = resultado.TOTAL / (double)currentProject.SUPTOT; resultado.PROMEDIO = Math.Round((double)resultadosTemporales["Mean"], 3); resultado.DESVIACIONESTANDAR = Math.Round((double)resultadosTemporales["StandardDeviation"], 3); resultado.COEFICIENTEDEVARIACION = Math.Round((double)resultadosTemporales["VariationCoefficient"], 3); resultado.ERRORDESVIACION = Math.Round((double)resultadosTemporales["StandardError"], 3); resultado.ERRORABSOLUTOMUESTREO = Math.Round((double)resultadosTemporales["AbsoulteErrorSample"], 3); resultado.LIMITEINF = Math.Round((double)resultadosTemporales["LowLimit"], 3); resultado.LIMITESUP = Math.Round((double)resultadosTemporales["HightLimit"], 3); resultado.ERRORRELATIVO = Math.Round((double)resultadosTemporales["RelativeErrorSample"], 3); resultadosBS.Add(resultado); } } resultadosTemporales = (Dictionary<string, object>)resultados.Last().Value; totales = new TOTALESMUESTREOESTRATIFICADOS(); totales.VARIABLE = "Volumen Comercial (Mtrs3)"; totales.TOTALPROMEDIOESTRATIFICADO = Math.Round((double)resultadosTemporales["Mean"], 3); totales.TOTALDESESTANDARESTRATIFICADO = Math.Round((double)resultadosTemporales["StandardError"], 3); totales.TOTALERRORMUESTREO = Math.Round((double)resultadosTemporales["AbsoulteErrorSample"], 3); totales.TOTALERRRORELATIVO = Math.Round((double)resultadosTemporales["RelativeErrorSample"], 3); totalEstratificadoBS.Add(totales); } if (opciones.Contains("VT")) { resultados = diseno.Execute(2); //Cargando resultado de los datos al reporte foreach (KeyValuePair<string, object> resultStratum in resultados) { resultadosTemporales = (Dictionary<string, object>)resultStratum.Value; resultado = new RESULTADOMUESTREO(); if (resultStratum.Key != "totales") { ESTRATO stratum = stratums.GetStratum(int.Parse(resultStratum.Key)); resultado.ESTRATO = stratum != null ? stratum.DESCRIPESTRATO : resultStratum.Key; resultado.PESOESTRATO = Math.Round((double)resultadosTemporales["Weight"], 3); resultado.N = resultadosTemporales["N"].ToString(); resultado.VARIABLE = "Volumen Total (Mtrs3)"; resultado.TOTAL = totalParcelas * Math.Round((double)resultadosTemporales["Mean"], 3); resultado.TOTALPORHECTAREA = resultado.TOTAL / (double)currentProject.SUPTOT; resultado.PROMEDIO = Math.Round((double)resultadosTemporales["Mean"], 3); resultado.DESVIACIONESTANDAR = Math.Round((double)resultadosTemporales["StandardDeviation"], 3); resultado.COEFICIENTEDEVARIACION = Math.Round((double)resultadosTemporales["VariationCoefficient"], 3); resultado.ERRORDESVIACION = Math.Round((double)resultadosTemporales["StandardError"], 3); resultado.ERRORABSOLUTOMUESTREO = Math.Round((double)resultadosTemporales["AbsoulteErrorSample"], 3); resultado.LIMITEINF = Math.Round((double)resultadosTemporales["LowLimit"], 3); resultado.LIMITESUP = Math.Round((double)resultadosTemporales["HightLimit"], 3); resultado.ERRORRELATIVO = Math.Round((double)resultadosTemporales["RelativeErrorSample"], 3); resultadosBS.Add(resultado); } } resultadosTemporales = (Dictionary<string, object>)resultados.Last().Value; totales = new TOTALESMUESTREOESTRATIFICADOS(); totales.VARIABLE = "Volumen Total (Mtrs3)"; totales.TOTALPROMEDIOESTRATIFICADO = Math.Round((double)resultadosTemporales["Mean"], 3); totales.TOTALDESESTANDARESTRATIFICADO = Math.Round((double)resultadosTemporales["StandardError"], 3); totales.TOTALERRORMUESTREO = Math.Round((double)resultadosTemporales["AbsoulteErrorSample"], 3); totales.TOTALERRRORELATIVO = Math.Round((double)resultadosTemporales["RelativeErrorSample"], 3); totalEstratificadoBS.Add(totales); } } } } catch (Exception ex) { Error_Form er = new Error_Form(ex.Message); er.MdiParent = this.MdiParent; er.Show(); } }
private void reporteEstratos() { try { this.DtgDatos.ColumnCount = 0; Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); Column1.HeaderText = "Estrato"; Column1.Name = "estrato"; Column1.SortMode = DataGridViewColumnSortMode.NotSortable; DtgDatos.Columns.Add(Column1); Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); Column1.HeaderText = "Variable"; Column1.Name = "ColVariable"; Column1.SortMode = DataGridViewColumnSortMode.NotSortable; DtgDatos.Columns.Add(Column1); decimal posClase = this.DIM; for (int i = 0; i < NumClass; i++) { Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); Column1.HeaderText = posClase + " - " + (posClase + rangeDAP); Column1.Name = "Clase" + (i + 1); DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle(); dataGridViewCellStyle1.Format = "0.000###"; Column1.DefaultCellStyle = dataGridViewCellStyle1; Column1.SortMode = DataGridViewColumnSortMode.NotSortable; DtgDatos.Columns.Add(Column1); posClase = posClase + rangeDAP; } Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); Column1.HeaderText = "Otros"; Column1.Name = "ClaseOtros"; Column1.SortMode = DataGridViewColumnSortMode.NotSortable; DtgDatos.Columns.Add(Column1); Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); Column1.HeaderText = "Total"; Column1.Name = "Clase" + (nUd_NumClases.Value + 3); Column1.SortMode = DataGridViewColumnSortMode.NotSortable; DtgDatos.Columns.Add(Column1); StratumBL StBL = new StratumBL(Program.ContextData); InventoryLineBL lnBL = new InventoryLineBL(Program.ContextData); decimal[] totalConteoClase = new decimal[NumClass + 1]; decimal[] totalABClase = new decimal[NumClass + 1]; decimal[] totalVolComClase = new decimal[NumClass + 1]; decimal[] totalVolTotClase = new decimal[NumClass + 1]; ArrayList RowsData = new ArrayList(); this.progressBar.Value = 0; this.progressBar.Minimum = 0; this.progressBar.Maximum = project.LISTADODEESTRATOS.Count; foreach (LISTADODEESTRATOS st in project.LISTADODEESTRATOS) { string RowConteo = "", RowAB = " ,Area Basal,", RowVolCom = " ,Volumen comercial,", RowVolTot = " ,Volumen total,"; decimal totalConteo = 0, totalAB = 0, totalVolCom = 0, totalVolTot = 0; RowConteo += (StBL.GetStratum((int)st.CODEST)).DESCRIPESTRATO + ", Densidad,"; decimal ValorClase = this.DIM; List<REPORTECLASESDIAMETRICAS> resultReportCD = new List<REPORTECLASESDIAMETRICAS>(); for (int i = 0; i <= NumClass; i++, ValorClase = ValorClase + rangeDAP) { REPORTECLASESDIAMETRICAS rpCD = new REPORTECLASESDIAMETRICAS(); foreach (FORMULARIO fr in project.FORMULARIO.Where(f => f.CODEST == st.CODEST)) { if (i == NumClass) { rpCD.CLASE = "otros"; rpCD = lnBL.searchDiametricClass(Guid.Empty, fr.NROFORMULARIO, tipoClaseCbx.Text, ValorClase, -1, rpCD); } else { rpCD.CLASE = i + " - " + (i + rangeDAP); rpCD = lnBL.searchDiametricClass(Guid.Empty, fr.NROFORMULARIO, tipoClaseCbx.Text, ValorClase, ValorClase + rangeDAP, rpCD); } } rpCD.PORCENTAJE = rpCD.TOTAL * 100; if (rpCD.CONTEO > 0) { rpCD.AREABASAL = rpCD.AREABASAL / rpCD.CONTEO; rpCD.VOLUMENCOMERCIAL = rpCD.VOLUMENCOMERCIAL / rpCD.CONTEO; rpCD.VOLUMENTOTAL = rpCD.VOLUMENTOTAL / rpCD.CONTEO; } RowConteo += Decimal.Round(rpCD.CONTEO, 4) + ","; RowAB += Decimal.Round(rpCD.AREABASAL, 4).ToString().Replace(",", ".") + ","; RowVolCom += Decimal.Round(rpCD.VOLUMENCOMERCIAL, 4).ToString().Replace(",", ".") + ","; RowVolTot += Decimal.Round(rpCD.VOLUMENTOTAL, 4).ToString().Replace(",", ".") + ","; totalConteo += rpCD.CONTEO; totalAB += rpCD.AREABASAL; totalVolCom += rpCD.VOLUMENCOMERCIAL; totalVolTot += rpCD.VOLUMENTOTAL; //Se realiza para los totales por clase de densidad,AB, vol totalConteoClase[i] += rpCD.CONTEO; totalABClase[i] += rpCD.AREABASAL; totalVolComClase[i] += rpCD.VOLUMENCOMERCIAL; totalVolTotClase[i] += rpCD.VOLUMENTOTAL; } //Se hace fuera del for porque en este for se lleva todos los valores de esa especie para cada clase diametrica y todas las variables //entonces ahora se lleva los valores de la especie y las clases diametricas if (opcionCheck.Checked) { RowConteo += Decimal.Round(totalConteo, 4).ToString().Replace(",", ".") + ","; RowAB += Decimal.Round(totalAB, 4).ToString().Replace(",", ".") + ","; RowVolCom += Decimal.Round(totalVolCom, 4).ToString().Replace(",", ".") + ","; RowVolTot += Decimal.Round(totalVolTot, 4).ToString().Replace(",", ".") + ","; RowsData.Add(RowConteo); RowsData.Add(RowAB); RowsData.Add(RowVolCom); RowsData.Add(RowVolTot); } else { if (totalConteo > 0) { RowConteo += Decimal.Round(totalConteo, 4).ToString().Replace(",", ".") + ","; RowAB += Decimal.Round(totalAB, 4).ToString().Replace(",", ".") + ","; RowVolCom += Decimal.Round(totalVolCom, 4).ToString().Replace(",", ".") + ","; RowVolTot += Decimal.Round(totalVolTot, 4).ToString().Replace(",", ".") + ","; RowsData.Add(RowConteo); RowsData.Add(RowAB); RowsData.Add(RowVolCom); RowsData.Add(RowVolTot); } } this.progressBar.Value++; } string RowTotalC = "TOTALES,Densidad,", RowTotalAB = " ,Area Basal,", RowTotalVolCom = " ,Volumen comercial,", RowTotalVolTot = " ,Volumen total,"; foreach (decimal d in totalConteoClase) { RowTotalC += decimal.Round(d, 4).ToString().Replace(",", ".") + ","; } foreach (decimal d in totalABClase) { RowTotalAB += decimal.Round(d, 4).ToString().Replace(",", ".") + ","; } foreach (decimal d in totalVolComClase) { RowTotalVolCom += decimal.Round(d, 4).ToString().Replace(",", ".") + ","; } foreach (decimal d in totalVolTotClase) { RowTotalVolTot += decimal.Round(d, 4).ToString().Replace(",", ".") + ","; } RowTotalC += Decimal.Round(totalConteoClase.Sum(), 4).ToString().Replace(",", ".") + ","; RowTotalAB += Decimal.Round(totalABClase.Sum(), 4).ToString().Replace(",", ".") + ","; RowTotalVolCom += Decimal.Round(totalVolComClase.Sum(), 4).ToString().Replace(",", ".") + ","; RowTotalVolTot += Decimal.Round(totalVolTotClase.Sum(), 4).ToString().Replace(",", ".") + ","; Column1 = new DataGridViewTextBoxColumn(); Column1.HeaderText = "Porcentaje"; Column1.Name = "Clase" + (nUd_NumClases.Value + 4); Column1.SortMode = DataGridViewColumnSortMode.NotSortable; DtgDatos.Columns.Add(Column1); int numCampos = 3; for (int i = 0; i < RowsData.Count; i = i + 4) { //Se arregla la fila que corresponde a la densidad string cadena = (string)RowsData[i]; string[] fila = cadena.Split(','); decimal total = decimal.Parse(fila[NumClass + numCampos].Replace('.', ',')); decimal p = 0; if (totalConteoClase.Sum() > 0) p = ((total) / totalConteoClase.Sum()) * 100; string result = cadena + decimal.Round(p, 2).ToString().Replace(',', '.') + ""; DtgDatos.Rows.Add(result.Split(',')); //Se arregla la fila que corresponde la area basal cadena = (string)RowsData[i + 1]; fila = cadena.Split(','); total = decimal.Parse(fila[NumClass + numCampos].Replace('.', ',')); p = 0; if (totalConteoClase.Sum() > 0) p = (total / totalABClase.Sum()) * 100; result = cadena + decimal.Round(p, 2).ToString().Replace(',', '.') + ""; DtgDatos.Rows.Add(result.Split(',')); //Se arregla la fila que corresponde al volumen comercial cadena = (string)RowsData[i + 2]; fila = cadena.Split(','); total = decimal.Parse(fila[NumClass + numCampos].Replace('.', ',')); p = 0; if (totalConteoClase.Sum() > 0) p = (total / totalVolComClase.Sum()) * 100; result = cadena + decimal.Round(p, 2).ToString().Replace(',', '.') + ""; DtgDatos.Rows.Add(result.Split(',')); //Se arregla la fila que corresponde al volumen total cadena = (string)RowsData[i + 3]; fila = cadena.Split(','); total = decimal.Parse(fila[NumClass + numCampos].Replace('.', ',')); p = 0; if (totalConteoClase.Sum() > 0) p = (total / totalVolTotClase.Sum()) * 100; result = cadena + decimal.Round(p, 2).ToString().Replace(',', '.') + ""; DtgDatos.Rows.Add(result.Split(',')); } DtgDatos.AutoResizeColumns(); DtgDatos.Rows.Add(RowTotalC.Split(',')); DtgDatos.Rows.Add(RowTotalAB.Split(',')); DtgDatos.Rows.Add(RowTotalVolCom.Split(',')); DtgDatos.Rows.Add(RowTotalVolTot.Split(',')); DtgDatos.Refresh(); } catch (Exception ex) { Error_Form er = new Error_Form(ex.Message); er.MdiParent = this.MdiParent; er.Show(); } }