public void DeleteActividad(ComboBox cbSeccion, DataGridView dgv, ComboBox ma, ComboBox gr,
                             RadioButton r1, RadioButton r2, RadioButton r3,
                             RadioButton r11, RadioButton r22, RadioButton r33)
 {
     try
     {
         Procesos      p            = new Procesos();
         SqlConnection getconexion3 = Conexion.Cnn();
         int           y            = dgv.CurrentCellAddress.Y;
         string        deletea;
         deletea = "DeleteAct";
         scomand = new SqlCommand(deletea, getconexion3);
         scomand.Parameters.AddWithValue("@Actividad", dgv[0, y].Value.ToString());
         scomand.Parameters.AddWithValue("@Materia", ma.Text.ToString());
         scomand.Parameters.AddWithValue("@Grado", gr.Text.ToString());
         scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(r11, r22, r33));
         scomand.Parameters.AddWithValue("@Periodo", p.Periodo(r1, r2, r3));
         scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text);
         scomand.CommandType = CommandType.StoredProcedure;
         scomand.ExecuteNonQuery();
         getconexion3.Close();
     }
     catch (Exception)
     {
         throw;
     }
 }//Delete Actividades
 public void InAct(ComboBox cbSeccion, TextBox txtact, ComboBox cbm, ComboBox cbg,
                   RadioButton r1, RadioButton r2, RadioButton r3, TextBox txtp, DataGridView dgv,
                   RadioButton r11, RadioButton r22, RadioButton r33)
 {
     try
     {
         Procesos      p           = new Procesos();
         SqlConnection getconexion = Conexion.Cnn();
         int           cont        = dgv.RowCount;
         string        ingresaract;
         ingresaract = "IngresarActividades";
         scomand     = new SqlCommand(ingresaract, getconexion);
         scomand.Parameters.AddWithValue("@Actividad", txtact.Text.ToString());
         scomand.Parameters.AddWithValue("@Materia", cbm.Text.ToString());
         scomand.Parameters.AddWithValue("@Grado", cbg.Text.ToString());
         scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(r11, r22, r33));
         scomand.Parameters.AddWithValue("@Periodo", p.Periodo(r1, r2, r3));
         scomand.Parameters.AddWithValue("@Ponderacion", Convert.ToDecimal(txtp.Text.ToString()));
         scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text);
         scomand.CommandType = CommandType.StoredProcedure;
         scomand.ExecuteNonQuery();
         getconexion.Close();
         dgv.Rows.Add();
         dgv[0, cont].Value = txtact.Text.ToString();
         dgv[1, cont].Value = txtp.Text.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error al ingresar los datos " + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public decimal Periodoporcentaje(RadioButton r1, RadioButton r2, RadioButton r3)
        {
            Procesos p      = new Procesos();
            decimal  porcen = 0m;

            try
            {
                if (p.Periodo(r1, r2, r3) == 1)
                {
                    porcen = 3.5m;
                }
                if (p.Periodo(r1, r2, r3) == 2)
                {
                    porcen = 3.5m;
                }
                if (p.Periodo(r1, r2, r3) == 3)
                {
                    porcen = 3.0m;
                }
                return(porcen);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error " + ex);
                return(0);
            }
        }
        public void LlenarActividades(ComboBox cbs, ComboBox cbGrado, ComboBox cbMateria, DataGridView dgv
                                      , RadioButton r1, RadioButton r2, RadioButton r3, RadioButton r11,
                                      RadioButton r22, RadioButton r33)
        {
            try
            {
                Procesos      p           = new Procesos();
                SqlConnection getconexion = Conexion.Cnn();
                string        getActividades;
                getActividades = "GetActividades";
                scomand        = new SqlCommand(getActividades, getconexion);
                scomand.Parameters.AddWithValue("@Grado", cbGrado.Text);
                scomand.Parameters.AddWithValue("@Materia", cbMateria.Text);
                scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(r11, r22, r33));
                scomand.Parameters.AddWithValue("@Periodo", p.Periodo(r1, r2, r3));
                scomand.Parameters.AddWithValue("@Seccion", cbs.Text);
                scomand.CommandType = CommandType.StoredProcedure;
                scomand.ExecuteNonQuery();
                sreader = scomand.ExecuteReader();

                while (sreader.Read())
                {
                    dgv.Columns.Add(sreader["Actividad"].ToString(), sreader["Actividad"].ToString());
                }
                getconexion.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Error", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }//LlenarActividades
        }//LlenarActividades

        public void LlenarCalificaciones(ComboBox ma, ComboBox gr, ComboBox sec, DataGridView dgv,
                                         RadioButton r1, RadioButton r2, RadioButton r3, RadioButton r11, RadioButton r22, RadioButton r33)
        {
            try
            {
                int alumnos = 0, actividades = 0, notas = 0;
                alumnos     = dgv.RowCount;
                actividades = dgv.ColumnCount - 3;
                notas       = alumnos * actividades;
                Procesos p = new Procesos();

                for (int i = 0; i < alumnos; i++)
                {
                    for (int j = 2; j < actividades + 3; j++)
                    {
                        SqlConnection getconexion = Conexion.Cnn();
                        string        getNotas;
                        getNotas = "NOTASPORGRADOSECCION";
                        scomand  = new SqlCommand(getNotas, getconexion);
                        scomand.Parameters.AddWithValue("@Materia", ma.Text.ToString());
                        scomand.Parameters.AddWithValue("@Grado", gr.Text.ToString());
                        scomand.Parameters.AddWithValue("@Seccion", sec.Text.ToString());
                        scomand.Parameters.AddWithValue("@Alumno", dgv[1, i].Value.ToString());
                        scomand.Parameters.AddWithValue("@Actividad", dgv.Columns[j].Name.ToString());
                        scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(r11, r22, r33));
                        scomand.Parameters.AddWithValue("@Periodo", p.Periodo(r1, r2, r3));
                        scomand.CommandType = CommandType.StoredProcedure;
                        scomand.ExecuteNonQuery();
                        sreader = scomand.ExecuteReader();

                        if (sreader.Read())
                        {
                            dgv[j, i].Value = sreader["Calificacion"].ToString();
                        }
                        getconexion.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error calificaion" + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }//LlenarCalificaciones
        }//LlenarCalificaciones

        public void LlenarPorcentajes(ComboBox ma, DataGridView dgv,
                                      RadioButton r1, RadioButton r2, RadioButton r3, RadioButton r11, RadioButton r22
                                      , RadioButton r33)
        {
            try
            {
                int alumnos  = dgv.RowCount;
                int columnas = dgv.ColumnCount;

                Procesos p = new Procesos();

                for (int i = 0; i < alumnos; i++)
                {
                    SqlConnection getconexion = Conexion.Cnn();
                    string        fillpor;
                    fillpor = "getPorcentajes";
                    scomand = new SqlCommand(fillpor, getconexion);
                    scomand.Parameters.AddWithValue("@Alumno", dgv[1, i].Value.ToString());
                    scomand.Parameters.AddWithValue("@Materia", ma.Text.ToString());
                    scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(r11, r22, r33));
                    scomand.Parameters.AddWithValue("@Periodo", p.Periodo(r1, r2, r3));
                    scomand.CommandType = CommandType.StoredProcedure;
                    scomand.ExecuteNonQuery();
                    sreader = scomand.ExecuteReader();
                    if (sreader.Read())
                    {
                        dgv[columnas - 1, i].Value = sreader["Porcentaje"].ToString();
                    }
                    getconexion.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error porcentaje" + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }//LlenarPorcentajes
Ejemplo n.º 7
0
        private void btnactu_Click(object sender, EventArgs e)
        {
            decimal total1 = 0;

            total1 += Convert.ToDecimal(txtnp.Text) + Sumatoria();
            if (total1 > pr.Periodoporcentaje(rbp35, rbs35, rb30) || decimal.Parse(txtnp.Text.ToString()) <= 0 || validaractu(dgvactividades) != 0 || txtnn.Text == "")
            {
                if (total1 > pr.Periodoporcentaje(rbp35, rbs35, rb30))
                {
                    MessageBox.Show("La sumatoria de los porcentajes de las actividades" +
                                    "\n exceden el pocentaje del periodo", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (total1 < 0)
                {
                    MessageBox.Show("Ingrese un porcentaje válido", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (txtnn.Text == "")
                {
                    MessageBox.Show("Ingrese una actividad", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                string        nuevonombre;
                SqlConnection getconexion = Conexion.Cnn();
                nuevonombre = "NnombreAct";
                scomand     = new SqlCommand(nuevonombre, getconexion);
                scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
                scomand.Parameters.AddWithValue("@Trimestre", pr.Trimestre(rbt1, rbt2, rbt3).ToString());
                scomand.Parameters.AddWithValue("@Periodo", pr.Periodo(rbp35, rbs35, rb30).ToString());
                scomand.Parameters.AddWithValue("@nombre", actividada);
                scomand.Parameters.AddWithValue("@Nnombre", txtnn.Text);
                scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text);
                scomand.CommandType = CommandType.StoredProcedure;
                scomand.ExecuteNonQuery();
                getconexion.Close();

                List <string>  Alumnos           = new List <string>();
                List <decimal> calificacion      = new List <decimal>();
                List <decimal> PorcentajeMateria = new List <decimal>();
                bool           flag         = false;
                Procesos       p            = new Procesos();
                SqlConnection  getconexion0 = Conexion.Cnn();
                string         step1;
                step1   = "UpdatePorstep1";
                scomand = new SqlCommand(step1, getconexion0);
                scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                scomand.Parameters.AddWithValue("@Actividad", txtnn.Text.ToString());
                scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
                scomand.Parameters.AddWithValue("@Trimestre", pr.Trimestre(rbp35, rbs35, rb30));
                scomand.Parameters.AddWithValue("@Periodo", pr.Periodo(rbt1, rbt2, rbt3));
                scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text);
                scomand.CommandType = CommandType.StoredProcedure;
                scomand.ExecuteNonQuery();
                sreader = scomand.ExecuteReader();
                while (sreader.Read())
                {
                    Alumnos.Add(sreader["Nombre"].ToString());
                    calificacion.Add(decimal.Parse(sreader["Calificacion"].ToString()));
                    flag = true;
                }
                getconexion0.Close();
                if (flag)
                {
                    for (int i = 0; i < Alumnos.Count; i++)
                    {
                        SqlConnection getconexion1 = Conexion.Cnn();
                        string        fillpor;
                        fillpor = "getPorcentajes";
                        scomand = new SqlCommand(fillpor, getconexion1);
                        scomand.Parameters.AddWithValue("@Alumno", Alumnos[i].ToString());
                        scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                        scomand.Parameters.AddWithValue("@Trimestre", pr.Trimestre(rbt1, rbt2, rbt3));
                        scomand.Parameters.AddWithValue("@Periodo", pr.Periodo(rbp35, rbs35, rb30));
                        scomand.CommandType = CommandType.StoredProcedure;
                        scomand.ExecuteNonQuery();
                        sreader = scomand.ExecuteReader();
                        if (sreader.Read())
                        {
                            PorcentajeMateria.Add(decimal.Parse(sreader["Porcentaje"].ToString()));
                        }
                        getconexion1.Close();
                    }
                    decimal nuevoporcentaje = decimal.Parse(txtnp.Text.ToString()) - decimal.Parse(ponderaa);
                    for (int i = 0; i < Alumnos.Count; i++)
                    {
                        SqlConnection getconexion2     = Conexion.Cnn();
                        string        updatePorcentaje = "UpdatePorcentaje";
                        scomand = new SqlCommand(updatePorcentaje, getconexion2);
                        scomand.Parameters.AddWithValue("@Alumno", Alumnos[i].ToString());
                        scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                        scomand.Parameters.AddWithValue("@NPorcentaje", PorcentajeMateria[i] + (calificacion[i] * nuevoporcentaje) / 10);
                        scomand.Parameters.AddWithValue("@Trimestre", pr.Trimestre(rbt1, rbt2, rbt3));
                        scomand.Parameters.AddWithValue("@Periodo", pr.Periodo(rbp35, rbs35, rb30));
                        scomand.CommandType = CommandType.StoredProcedure;
                        scomand.ExecuteNonQuery();
                        sreader = scomand.ExecuteReader();
                        getconexion2.Close();
                    }
                }
                SqlConnection getconexion3      = Conexion.Cnn();
                string        updatePonderacion = "UpdatePonderacion";
                scomand = new SqlCommand(updatePonderacion, getconexion3);
                scomand.Parameters.AddWithValue("@Actividad", txtnn.Text);
                scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
                scomand.Parameters.AddWithValue("@Trimestre", pr.Trimestre(rbt1, rbt2, rbt3));
                scomand.Parameters.AddWithValue("@Periodo", pr.Periodo(rbp35, rbs35, rb30));
                scomand.Parameters.AddWithValue("@Npodenra", decimal.Parse(txtnp.Text.ToString()));
                scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text);
                scomand.CommandType = CommandType.StoredProcedure;
                scomand.ExecuteNonQuery();
                sreader = scomand.ExecuteReader();
                getconexion3.Close();
                Alumnos.Clear();
                PorcentajeMateria.Clear();
                calificacion.Clear();

                int conteo = dgvactividades.RowCount;
                dgvactividades.Rows.Add();
                dgvactividades[0, conteo].Value = txtnn.Text;
                dgvactividades[1, conteo].Value = txtnp.Text;
                lbltotal.Text   = Sumatoria().ToString();
                lblnn.Visible   = false;
                lblnp.Visible   = false;
                txtnn.Visible   = false;
                txtnp.Visible   = false;
                btnactu.Visible = false;


                MessageBox.Show("Datos actualizados", "MENSAJE", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        }//Delete Actividades

        public void CuadroNotas(DataGridView dgvRegistro, ComboBox cbGrado, ComboBox cbMateria, ComboBox cbSeccion,
                                RadioButton rbt1, RadioButton rbt2, RadioButton rbt3, RadioButton rbp35,
                                RadioButton rbs35, RadioButton rb30)
        {
            Procesos p = new Procesos();

            if (Convert.ToString(dgvRegistro.CurrentCell.Value) == "")
            {
                dgvRegistro.CurrentCell.Value = 0;
            }

            if (decimal.Parse(dgvRegistro.CurrentCell.Value.ToString()) < 0 || decimal.Parse(dgvRegistro.CurrentCell.Value.ToString()) > 10)
            {
                MessageBox.Show("Nota inválida", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dgvRegistro.CurrentCell.Value = 0;
            }

            int  x, y, columnas;
            bool flag = false;

            x        = dgvRegistro.CurrentCellAddress.X;
            y        = dgvRegistro.CurrentCellAddress.Y;
            columnas = dgvRegistro.ColumnCount - 1;



            SqlConnection getconexion = Conexion.Cnn();
            string        updatenotas;

            updatenotas = "UpdateNotas";
            scomand     = new SqlCommand(updatenotas, getconexion);
            scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
            scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
            scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text.ToString());
            scomand.Parameters.AddWithValue("@Alumno", dgvRegistro[1, y].Value.ToString());
            scomand.Parameters.AddWithValue("@Actividad", dgvRegistro.Columns[x].Name.ToString());
            scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
            scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
            scomand.Parameters.AddWithValue("@NCalificaion", decimal.Parse(dgvRegistro.CurrentCell.Value.ToString()));
            scomand.CommandType = CommandType.StoredProcedure;
            scomand.ExecuteNonQuery();
            sreader = scomand.ExecuteReader();

            if (sreader.Read())
            {
                flag = true;
            }
            getconexion.Close();
            if (flag.Equals(false))
            {
                string InsertRegistro;
                InsertRegistro = "IngresarRegistro";
                scomand        = new SqlCommand(InsertRegistro, getconexion);
                getconexion.Open();
                scomand.Parameters.AddWithValue("@Alumno", dgvRegistro[1, y].Value.ToString());
                scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                scomand.Parameters.AddWithValue("@Actividad", dgvRegistro.Columns[x].Name.ToString());
                scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
                scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text.ToString());
                scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
                scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
                scomand.Parameters.AddWithValue("@Calificacion", decimal.Parse(dgvRegistro.CurrentCell.Value.ToString()));
                scomand.CommandType = CommandType.StoredProcedure;
                scomand.ExecuteNonQuery();
            }
            getconexion.Close();


            //PORCENTAJE
            decimal        total = 0;
            double         t     = 0;
            string         porcentaje;
            List <decimal> porcentajes = new List <decimal>();

            porcentaje = "getPonderacion";         //valor de la nota en el 35%
            scomand    = new SqlCommand(porcentaje, getconexion);
            getconexion.Open();
            scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
            scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
            scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
            scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
            scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text);
            scomand.CommandType = CommandType.StoredProcedure;
            scomand.ExecuteNonQuery();
            sreader = scomand.ExecuteReader();
            while (sreader.Read())
            {
                porcentajes.Add(decimal.Parse(sreader["Ponderacion"].ToString()));
            }
            getconexion.Close();


            for (int po = 2; po < dgvRegistro.ColumnCount - 1; po++)
            {
                if (Convert.ToString(dgvRegistro[po, y].Value) != "")
                {
                    total = total + decimal.Parse(dgvRegistro[po, y].Value.ToString()) * (porcentajes[po - 2]) / 10;
                }
            }
            porcentajes.Clear();
            string updatePorcentaje;
            bool   flag1 = false;

            updatePorcentaje = "UpdatePorcentaje";
            scomand          = new SqlCommand(updatePorcentaje, getconexion);
            getconexion.Open();
            scomand.Parameters.AddWithValue("@Alumno", dgvRegistro[1, y].Value.ToString());
            scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
            scomand.Parameters.AddWithValue("@NPorcentaje", total);
            scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
            scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
            scomand.CommandType = CommandType.StoredProcedure;
            scomand.ExecuteNonQuery();
            sreader = scomand.ExecuteReader();
            if (sreader.Read())
            {
                flag1 = true;
            }
            getconexion.Close();
            if (flag1.Equals(false))
            {
                string insertarporcen;
                insertarporcen = "IngresarPorcentaje";
                scomand        = new SqlCommand(insertarporcen, getconexion);
                getconexion.Open();
                scomand.Parameters.AddWithValue("@Alumno", dgvRegistro[1, y].Value.ToString());
                scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
                scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
                scomand.Parameters.AddWithValue("@Porcentaje", total);
                scomand.CommandType = CommandType.StoredProcedure;
                scomand.ExecuteNonQuery();
                getconexion.Close();
            }
            t = (double)total;
            t = Math.Round(t, 2);
            dgvRegistro[columnas, y].Value = t.ToString();
        }    //Cuadro de notas
        public void UpdateActividad(ComboBox cbSeccion, DataGridView dgv, ComboBox ma, ComboBox gr,
                                    RadioButton r1, RadioButton r2, RadioButton r3,
                                    RadioButton r11, RadioButton r22, RadioButton r33)
        {
            try
            {
                List <string>  Alumnos           = new List <string>();
                List <decimal> calificacion      = new List <decimal>();
                List <decimal> PorcentajeMateria = new List <decimal>();
                decimal        ponderacionact    = 0;
                bool           flag         = false;
                int            y            = dgv.CurrentCellAddress.Y;
                Procesos       p            = new Procesos();
                SqlConnection  getconexion0 = Conexion.Cnn();
                string         step1;
                step1   = "UpdatePorstep1";
                scomand = new SqlCommand(step1, getconexion0);
                scomand.Parameters.AddWithValue("@Materia", ma.Text.ToString());
                scomand.Parameters.AddWithValue("@Actividad", dgv[0, y].Value.ToString());
                scomand.Parameters.AddWithValue("@Grado", gr.Text.ToString());
                scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(r11, r22, r33));
                scomand.Parameters.AddWithValue("@Periodo", p.Periodo(r1, r2, r3));
                scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text);
                scomand.CommandType = CommandType.StoredProcedure;
                scomand.ExecuteNonQuery();
                sreader = scomand.ExecuteReader();
                while (sreader.Read())
                {
                    Alumnos.Add(sreader["Nombre"].ToString());
                    calificacion.Add(decimal.Parse(sreader["Calificacion"].ToString()));
                    flag = true;
                }
                getconexion0.Close();
                if (flag)
                {
                    ponderacionact = decimal.Parse(dgv[1, y].Value.ToString());


                    for (int i = 0; i < Alumnos.Count; i++)
                    {
                        SqlConnection getconexion1 = Conexion.Cnn();
                        string        fillpor;
                        fillpor = "getPorcentajes";
                        scomand = new SqlCommand(fillpor, getconexion1);
                        scomand.Parameters.AddWithValue("@Alumno", Alumnos[i].ToString());
                        scomand.Parameters.AddWithValue("@Materia", ma.Text.ToString());
                        scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(r11, r22, r33));
                        scomand.Parameters.AddWithValue("@Periodo", p.Periodo(r1, r2, r3));
                        scomand.CommandType = CommandType.StoredProcedure;
                        scomand.ExecuteNonQuery();
                        sreader = scomand.ExecuteReader();
                        if (sreader.Read())
                        {
                            PorcentajeMateria.Add(decimal.Parse(sreader["Porcentaje"].ToString()));
                        }
                        getconexion1.Close();
                    }

                    for (int i = 0; i < Alumnos.Count; i++)
                    {
                        SqlConnection getconexion2     = Conexion.Cnn();
                        string        updatePorcentaje = "UpdatePorcentaje";
                        scomand = new SqlCommand(updatePorcentaje, getconexion2);
                        scomand.Parameters.AddWithValue("@Alumno", Alumnos[i].ToString());
                        scomand.Parameters.AddWithValue("@Materia", ma.Text.ToString());
                        scomand.Parameters.AddWithValue("@NPorcentaje", PorcentajeMateria[i] - (calificacion[i] * ponderacionact) / 10);
                        scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(r11, r22, r33));
                        scomand.Parameters.AddWithValue("@Periodo", p.Periodo(r1, r2, r3));
                        scomand.CommandType = CommandType.StoredProcedure;
                        scomand.ExecuteNonQuery();
                        sreader = scomand.ExecuteReader();
                        getconexion2.Close();
                    }
                }
                Alumnos.Clear();
                PorcentajeMateria.Clear();
                calificacion.Clear();
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                MessageBox.Show("hola");
                Importar im = new Importar();
                im.importwithquestion(dgvauxiliar);
            }
            catch (Exception)
            {
                MessageBox.Show("Asegúrese de no dejar espacios en blanco en el documento", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            DialogResult dialog = MessageBox.Show("Desea importar este archivo a: \n\n" +
                                                  "\nGrado:   " + cbGrado.Text + "\nSección: " + cbSeccion.Text +
                                                  "\nMateria: " + cbMateria.Text, "IMPORTAR", MessageBoxButtons.YesNo);

            if (dialog == DialogResult.Yes)
            {
                try
                {
                    for (int i = 0; i < dgvauxiliar.RowCount; i++)
                    {
                        for (int j = 2; j < dgvauxiliar.ColumnCount - 1; j++)
                        {
                            Procesos p = new Procesos();

                            if (Convert.ToString(dgvauxiliar[j, i].Value) == "")
                            {
                                dgvauxiliar[j, i].Value = 0;
                            }

                            if (decimal.Parse(dgvauxiliar[j, i].Value.ToString()) < 0 || decimal.Parse(dgvauxiliar[j, i].Value.ToString()) > 10)
                            {
                                MessageBox.Show("Nota inválida", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                dgvauxiliar[j, i].Value = 0;
                            }

                            int  columnas;
                            bool flag = false;
                            //x = dgvRegistro.CurrentCellAddress.X;
                            //y = dgvRegistro.CurrentCellAddress.Y;
                            columnas = dgvauxiliar.ColumnCount - 1;



                            SqlConnection getconexion = Conexion.Cnn();
                            string        updatenotas;
                            updatenotas = "UpdateNotas";
                            scomand     = new SqlCommand(updatenotas, getconexion);
                            scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                            scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
                            scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text.ToString());
                            scomand.Parameters.AddWithValue("@Alumno", dgvauxiliar[1, i].Value.ToString());
                            scomand.Parameters.AddWithValue("@Actividad", dgvauxiliar.Columns[j].Name.ToString());
                            scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
                            scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
                            scomand.Parameters.AddWithValue("@NCalificaion", decimal.Parse(dgvauxiliar[j, i].Value.ToString()));
                            scomand.CommandType = CommandType.StoredProcedure;
                            scomand.ExecuteNonQuery();
                            sreader = scomand.ExecuteReader();

                            if (sreader.Read())
                            {
                                flag = true;
                            }
                            getconexion.Close();
                            if (flag.Equals(false))
                            {
                                string InsertRegistro;
                                InsertRegistro = "IngresarRegistro";
                                scomand        = new SqlCommand(InsertRegistro, getconexion);
                                getconexion.Open();
                                scomand.Parameters.AddWithValue("@Alumno", dgvauxiliar[1, i].Value.ToString());
                                scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                                scomand.Parameters.AddWithValue("@Actividad", dgvauxiliar.Columns[j].Name.ToString());
                                scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
                                scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text.ToString());
                                scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
                                scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
                                scomand.Parameters.AddWithValue("@Calificacion", decimal.Parse(dgvauxiliar[j, i].Value.ToString()));
                                scomand.CommandType = CommandType.StoredProcedure;
                                scomand.ExecuteNonQuery();
                            }
                            getconexion.Close();


                            //PORCENTAJE
                            decimal        total = 0;
                            double         t     = 0;
                            string         porcentaje;
                            List <decimal> porcentajes = new List <decimal>();
                            porcentaje = "getPonderacion";//valor de la nota en el 35%
                            scomand    = new SqlCommand(porcentaje, getconexion);
                            getconexion.Open();
                            scomand.Parameters.AddWithValue("@Grado", cbGrado.Text.ToString());
                            scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                            scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
                            scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
                            scomand.Parameters.AddWithValue("@Seccion", cbSeccion.Text);
                            scomand.CommandType = CommandType.StoredProcedure;
                            scomand.ExecuteNonQuery();
                            sreader = scomand.ExecuteReader();
                            while (sreader.Read())
                            {
                                porcentajes.Add(decimal.Parse(sreader["Ponderacion"].ToString()));
                            }
                            getconexion.Close();


                            for (int po = 2; po < dgvauxiliar.ColumnCount - 1; po++)
                            {
                                if (Convert.ToString(dgvauxiliar[po, i].Value) != "")
                                {
                                    total = total + decimal.Parse(dgvauxiliar[po, i].Value.ToString()) * (porcentajes[po - 2]) / 10;
                                }
                            }
                            porcentajes.Clear();
                            string updatePorcentaje;
                            bool   flag1 = false;
                            updatePorcentaje = "UpdatePorcentaje";
                            scomand          = new SqlCommand(updatePorcentaje, getconexion);
                            getconexion.Open();
                            scomand.Parameters.AddWithValue("@Alumno", dgvauxiliar[1, i].Value.ToString());
                            scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                            scomand.Parameters.AddWithValue("@NPorcentaje", total);
                            scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
                            scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
                            scomand.CommandType = CommandType.StoredProcedure;
                            scomand.ExecuteNonQuery();
                            sreader = scomand.ExecuteReader();
                            if (sreader.Read())
                            {
                                flag1 = true;
                            }
                            getconexion.Close();
                            if (flag1.Equals(false))
                            {
                                string insertarporcen;
                                insertarporcen = "IngresarPorcentaje";
                                scomand        = new SqlCommand(insertarporcen, getconexion);
                                getconexion.Open();
                                scomand.Parameters.AddWithValue("@Alumno", dgvauxiliar[1, i].Value.ToString());
                                scomand.Parameters.AddWithValue("@Materia", cbMateria.Text.ToString());
                                scomand.Parameters.AddWithValue("@Trimestre", p.Trimestre(rbt1, rbt2, rbt3));
                                scomand.Parameters.AddWithValue("@Periodo", p.Periodo(rbp35, rbs35, rb30));
                                scomand.Parameters.AddWithValue("@Porcentaje", total);
                                scomand.CommandType = CommandType.StoredProcedure;
                                scomand.ExecuteNonQuery();
                                getconexion.Close();
                            }
                            t = (double)total;
                            t = Math.Round(t, 2);
                            dgvauxiliar[columnas, i].Value = t.ToString();
                        }
                    }
                    dgvauxiliar.DataSource = null;
                    pr.Vaciardgv(dgvRegistro);
                    dgvRegistro.Columns.Add("No", "No");
                    dgvRegistro.Columns.Add("ALUMNOS", "Alumnos");
                    pr.LlenarAlumnos(cbGrado, cbSeccion, dgvRegistro);
                    pr.LlenarActividades(cbSeccion, cbGrado, cbMateria, dgvRegistro, rbp35, rbs35, rb30, rbt1, rbt2, rbt3);
                    dgvRegistro.Columns.Add("Porcentaje", "Porcentaje");
                    pr.LlenarCalificaciones(cbMateria, cbGrado, cbSeccion, dgvRegistro, rbp35, rbs35, rb30, rbt1, rbt2, rbt3);
                    pr.LlenarPorcentajes(cbMateria, dgvRegistro, rbp35, rbs35, rb30, rbt1, rbt2, rbt3);
                    int c = dgvRegistro.ColumnCount;
                    dgvRegistro.Columns["Porcentaje"].ReadOnly = true;
                    dgvRegistro.Columns["ALUMNOS"].ReadOnly    = true;
                    dgvRegistro.Columns["No"].ReadOnly         = true;
                    btnExcel.Enabled = true;
                    MessageBox.Show("Porcentajes actulizados", "ACTUALIZACION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR" + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }