Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            nbts = new List<CoordenadaTriangular>();
            try
            {
                int CANTIDAD = 0;
                List<string> GradosNombres = new List<string>();
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    CANTIDAD = dataGridView1.Columns.Count - 2;
                    string valor;
                    DataGridViewComboBoxCell currentCell = (DataGridViewComboBoxCell)dataGridView1.Rows[i].Cells[1];
                    for (int j = 0; j < currentCell.Items.Count; j++)
                    {
                        valor = currentCell.Items[j].ToString();
                        GradosNombres.Add(currentCell.Items[j].ToString());

                    }
                    CoordenadaTriangular ct =
                          new CoordenadaTriangular(GradosNombres,
                              CANTIDAD, dataGridView1.Rows[i].Cells[0].Value.ToString(), cols);
                    if (dataGridView1.Rows[i].Cells[0].Value.ToString().Contains("---"))
                        nbts.Add(ct);

                    GradosNombres.Clear();
                }

                List<NumeroTriangular> resultado = new List<NumeroTriangular>();
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    if (!dataGridView1.Rows[i].Cells[0].Value.ToString().Contains("---"))
                    {
                        continue;
                    }
                    NumeroTriangular nt = new NumeroTriangular();
                    for (int j = 0; j < indicadores.Count; j++)
                    {

                        for (int k = 0; k < indicadores.ElementAt(j).IndicadoresEspecificos.Count; k++)
                        {
                            if (dataGridView1.Rows[i].Cells[0].Value.ToString() == " ---" +
                                indicadores.ElementAt(j).IndicadoresEspecificos.ElementAt(k).descp)
                            {
                                int pos = ((DataGridViewComboBoxCell)dataGridView1.Rows[i].Cells[1]).Items.IndexOf(dataGridView1.Rows[i].Cells[1].Value.ToString());

                                for (int w = 0; w < nbts.Count; w++)
                                {
                                    if (nbts[w].Indicador ==
                                        " ---" + indicadores.ElementAt(j).IndicadoresEspecificos.ElementAt(k).descp)
                                    {
                                        nt.x = (indicadores.ElementAt(j).IndicadoresEspecificos.ElementAt(k).peso) / (100) *
                                               (indicadores.ElementAt(j).peso) / (100) *
                                               nbts[w].NumeroBorrosoTriangular.ElementAt(pos).x;
                                        nt.y = (indicadores.ElementAt(j).IndicadoresEspecificos.ElementAt(k).peso) / (100) *
                                               (indicadores.ElementAt(j).peso) / (100) *
                                               nbts[w].NumeroBorrosoTriangular.ElementAt(pos).y;
                                        nt.z = (indicadores.ElementAt(j).IndicadoresEspecificos.ElementAt(k).peso) / (100) *
                                               (indicadores.ElementAt(j).peso) / (100) *
                                               nbts[w].NumeroBorrosoTriangular.ElementAt(pos).z;
                                        resultado.Add(nt);
                                        break;
                                    }
                                }
                            }
                        }
                    }

                }

                List<float> resultadosPorCategoria = new List<float>();

                NumeroTriangular resultante = new NumeroTriangular();
                resultante.x = 0;
                resultante.y = 0;
                resultante.z = 0;
                for (int i = 0; i < resultado.Count; i++)
                {

                    resultante.x += resultado.ElementAt(i).x;
                    resultante.y += resultado.ElementAt(i).y;
                    resultante.z += resultado.ElementAt(i).z;
                    resultadosPorCategoria.Add(resultado.ElementAt(i).y);
                }

                if (con.State != ConnectionState.Open)
                    con.Open();
                SqlCommand cmd4 = new SqlCommand();
                cmd4.Connection = con;
                cmd4.CommandType = System.Data.CommandType.StoredProcedure;
                cmd4.CommandText = "SP_INSERT_EVALUACION";
                cmd4.Parameters.Add("@ID_EMPLEADO", SqlDbType.Int).Value = int.Parse(label2.Text);
                cmd4.Parameters.Add("@ID", SqlDbType.Int).Value = int.Parse(id_eval.ToString());
                cmd4.Parameters.Add("@FECHA_EVAL", SqlDbType.Date).Value = DateTime.Now;
                cmd4.Parameters.Add("@RESUL", SqlDbType.Float).Value = resultante.y;
                cmd4.ExecuteNonQuery();
                cmd4.Dispose();

                Grafica gf = new Grafica(cols.Count, resultante.x, resultante.y, resultante.z, cols, resultadosPorCategoria, resultadosPorCategoriaTexto);
                this.Hide();
                gf.ShowDialog();
                this.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                    con.Close();
            }
        }