Example #1
0
 public void Borrar()
 {
     Periodo Periodo = new Periodo();
     Periodo.Id = Convert.ToInt32(this.txtId.Text);
     db.borrarPeriodo(Periodo);
     cargarDataGrid();
     edicion(false);
 }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            try
            {
                Grupo grupo = new Grupo();
                Asignatura asignatura = new Asignatura();
                asignatura.Id = Convert.ToInt32(gruposForm.cbAsignatura.SelectedValue);
                grupo.Asignatura = asignatura;
                Docente docente = new Docente();
                docente.Id = Convert.ToInt32(gruposForm.cbDocente.SelectedValue);
                grupo.Docente = docente;
                if(gruposForm.txtInscritos.Text.Equals(""))
                {
                    grupo.CantidadEstudiantes=0;
                }
                else
                {
                    grupo.CantidadEstudiantes = Convert.ToInt32(gruposForm.txtInscritos.Text);
                }
                Periodo periodo = new Periodo();
                periodo.Id = Convert.ToInt32(gruposForm.cbPeriodo.SelectedValue);
                grupo.Periodo = periodo;
                db.insertGrupo(grupo);
                gruposForm.Hide();
                cargarDataGridGrupos();
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
        }
Example #3
0
        public Boolean actualizarPeriodo(Periodo Periodo)
        {
            this.connection.Open();
            this.command = this.connection.CreateCommand();
            this.transaction = this.connection.BeginTransaction();
            this.command.Connection = this.connection;
            this.command.Transaction = this.transaction;

            try
            {
                this.command.CommandText = "Update Periodo set periodo_inicio=@fechaInicio,periodo_fin=@fechaFin,descripcion=@descripcion where id_Periodo=@id;";
                this.command.Parameters.Add(new SqlParameter("@fechaInicio",SqlDbType.DateTime));
                this.command.Parameters.Add(new SqlParameter("@fechaFin",SqlDbType.DateTime));
                this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.NVarChar, 50));
                this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                this.command.Parameters["@fechaInicio"].Value = Periodo.FechaInicio;
                this.command.Parameters["@fechaFin"].Value = Periodo.FechaFin;
                this.command.Parameters["@descripcion"].Value = Periodo.Descripcion;
                this.command.Parameters["@id"].Value = Periodo.Id;
                this.command.ExecuteNonQuery();
                this.transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                try
                {
                    this.transaction.Rollback();
                    throw new Exception("Error al Actualizar." + e.Message);
                    return false;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error al rollback accion." + ex.Message);
                    return false;
                }
            }
            finally
            {
                this.connection.Close();
            }
        }
Example #4
0
        public Boolean insertPeriodo(Periodo Periodo)
        {
            this.connection.Open();
            this.command = this.connection.CreateCommand();
            this.transaction = this.connection.BeginTransaction();
            this.command.Connection = this.connection;
            this.command.Transaction = this.transaction;

            try
            {
                this.command.CommandText = "insert into periodo(periodo_inicio,periodo_fin,descripcion) values(@fechaInicio,@fechaFin,@descripcion);" + "SELECT CAST(scope_identity() AS int)";
                this.command.Parameters.Add(new SqlParameter("@fechaInicio",SqlDbType.DateTime));
                this.command.Parameters.Add(new SqlParameter("@fechaFin", SqlDbType.DateTime));
                this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.NVarChar, 50));
                this.command.Parameters["@fechaInicio"].Value = Periodo.FechaInicio;
                this.command.Parameters["@fechaFin"].Value = Periodo.FechaFin;
                this.command.Parameters["@descripcion"].Value = Periodo.Descripcion;
                this.lastUpdated = this.command.ExecuteScalar().ToString();
                this.transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                try
                {
                    transaction.Rollback();
                    throw new Exception("Error al insertar registro. " + e.Message);
                    return false;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error al rollback accion. " + ex.Message);
                }
            }
            finally
            {
                this.connection.Close();
            }
        }
Example #5
0
 /*--------------------FIN CATALOGO DOCENTES------------------------*/
 /*--------------------Catalogo de Periodos-------------------------*/
 public List<Periodo> getPeriodos()
 {
     SqlDataReader dataReader = null;
     List<Periodo> Periodos = new List<Periodo>();
     try
     {
         string query = "Select * from periodo";
         command = new SqlCommand(query, connection);
         command.Connection.Open();
         dataReader = command.ExecuteReader();
         while (dataReader.Read())
         {
             Periodo Periodo = new Periodo();
             Periodo.Id = Convert.ToInt32(dataReader["id_periodo"].ToString());
             Periodo.FechaInicio = Convert.ToDateTime(dataReader["periodo_inicio"].ToString());
             Periodo.FechaFin = Convert.ToDateTime(dataReader["periodo_fin"].ToString());
             Periodo.Descripcion = dataReader["descripcion"].ToString();
             Periodos.Add(Periodo);
         }
         return Periodos;
     }
     catch (Exception e)
     {
         throw new Exception("Error al obtener datos de Periodo. " + e.Message.ToString());
     }
     finally
     {
         command.Connection.Close();
     }
 }
Example #6
0
        /*--------------------FIN CATALOGO Asignaturas------------------------*/
        /*--------------------Catalogo de Grupos-------------------------*/
        public List<Grupo> getGrupos(Asignatura a)
        {
            SqlDataReader dataReader = null;
            List<Grupo> Grupos = new List<Grupo>();
            try
            {
                string query = "Select * from Vista_Grupos where idAsignatura=@idAsignatura";
                command = new SqlCommand(query, connection);
                command.Connection.Open();
                command.Parameters.Add(new SqlParameter("@idAsignatura", SqlDbType.Int));
                command.Parameters["@idAsignatura"].Value = a.Id;
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    Grupo Grupo = new Grupo();
                    Grupo.Id = Convert.ToInt32(dataReader["id"].ToString());
                    Grupo.CantidadEstudiantes = Convert.ToInt32(dataReader["cantEstudiantes"].ToString());

                    Asignatura asignatura = new Asignatura();
                    asignatura.Id = Convert.ToInt32(dataReader["idAsignatura"].ToString());
                    asignatura.Nombre = dataReader["nombreAsignatura"].ToString();
                    Grupo.Asignatura = asignatura;

                    Docente docente = new Docente();
                    docente.Id = Convert.ToInt32(dataReader["idDocente"].ToString());
                    docente.Nombre = dataReader["nombreDocente"].ToString();
                    Grupo.Docente = docente;

                    Periodo periodo = new Periodo();
                    periodo.Id = Convert.ToInt32(dataReader["idPeriodo"].ToString());
                    periodo.Descripcion = dataReader["descripcionPeriodo"].ToString();
                    Grupo.Periodo = periodo;

                    Grupo.NumeroGrupo = Convert.ToInt32(dataReader["Grupo"].ToString());

                    Grupos.Add(Grupo);
                }
                return Grupos;
            }
            catch (Exception e)
            {
                throw new Exception("Error al obtener datos de Grupo. " + e.Message.ToString());
            }
            finally
            {
                command.Connection.Close();
            }
        }
Example #7
0
        public Boolean borrarPeriodo(Periodo Periodo)
        {
            this.connection.Open();
            this.command = this.connection.CreateCommand();
            this.transaction = this.connection.BeginTransaction();

            this.command.Connection = this.connection;
            this.command.Transaction = this.transaction;

            try
            {
                this.command.CommandText = "delete from Periodo where id_Periodo=@id;";
                this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                this.command.Parameters["@id"].Value = Periodo.Id;
                this.command.ExecuteNonQuery();
                this.transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                try
                {
                    this.transaction.Rollback();
                    throw new Exception("Error al borrar registro. " + e.Message);
                    return false;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error al rollback acción. " + ex.Message);
                    return false;
                }
            }
            finally
            {
                this.connection.Close();
            }
        }
Example #8
0
        public bool Guardar()
        {
            edicion(false);
            if (this.txtId.Text == "")
            {
                /*------------INSERTAR FACULTAD----------------*/
                if (this.txtDescripcion.Text != "")
                {
                    Periodo Periodo = new Periodo();
                    Periodo.FechaInicio = Convert.ToDateTime(this.dtFechaInicio.Text);
                    Periodo.FechaFin = Convert.ToDateTime(this.dtFechaFin.Text);
                    Periodo.Descripcion= this.txtDescripcion.Text;
                    insertPeriodo(Periodo);
                    this.dgPeriodos.Enabled = true;
                    cargarDataGrid();
                    this.txtId.DataBindings.Add("Text", PeriodosBindingSource, "Id");
                    this.dtFechaInicio.DataBindings.Add("Text", PeriodosBindingSource, "FechaInicio");
                    this.dtFechaFin.DataBindings.Add("Text", PeriodosBindingSource, "FechaFin");
                    this.txtDescripcion.DataBindings.Add("Text", PeriodosBindingSource, "Descripcion");
                    this.PeriodosBindingSource.MoveLast();
                    return true;
                }
                else
                {
                    MessageBox.Show("Descripción no puede estar vacio.", "Error", MessageBoxButtons.OK);
                    return false;
                }

                /*---------FIN INSERTAR FACULTAD----------------*/

            }
            else
            {

                /*------------Actualizar FACULTAD----------------*/
                if (this.txtDescripcion.Text != "")
                {
                    Periodo Periodo = new Periodo();
                    Periodo.Id = Convert.ToInt32(this.txtId.Text);
                    Periodo.FechaInicio = Convert.ToDateTime(this.dtFechaInicio.Text);
                    Periodo.FechaFin = Convert.ToDateTime(this.dtFechaFin.Text);
                    Periodo.Descripcion = this.txtDescripcion.Text;
                    actualizarPeriodo(Periodo);
                    this.dgPeriodos.Enabled = true;
                    cargarDataGrid();
                    return true;
                }
                else
                {
                    MessageBox.Show("Descripción no puede estar vacio","Error",MessageBoxButtons.OK);
                    return false;
                }
                /*---------FIN Actualizar FACULTAD----------------*/

            }
        }
Example #9
0
        private bool insertPeriodo(Periodo Periodo)
        {
            try
            {
                db.insertPeriodo(Periodo);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return true;
        }
Example #10
0
        private bool actualizarPeriodo(Periodo Periodo)
        {
            try
            {
                db.actualizarPeriodo(Periodo);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return true;
        }