Example #1
0
 public void Borrar()
 {
     Docente docente = new Docente();
     docente.Id = Convert.ToInt32(this.txtId.Text);
     db.borrarDocente(docente);
     cargarDataGrid();
     edicion(false);
 }
Example #2
0
        public bool Guardar()
        {
            edicion(false);
            if (this.txtId.Text == "")
            {
                /*------------INSERTAR FACULTAD----------------*/
                if (this.txtNombre.Text != "")
                {
                    Docente docente = new Docente();
                    docente.Nombre= this.txtNombre.Text;
                    insertDocente(docente);
                    this.dgDocentes.Enabled = true;
                    cargarDataGrid();
                    this.txtId.DataBindings.Add("Text", DocentesBindingSource, "Id");
                    this.txtNombre.DataBindings.Add("Text", DocentesBindingSource, "Nombre");
                    this.DocentesBindingSource.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.txtNombre.Text != "")
                {
                    Docente docente = new Docente();
                    docente.Id = Convert.ToInt32(this.txtId.Text);
                    docente.Nombre = this.txtNombre.Text;
                    actualizarDocente(docente);
                    this.dgDocentes.Enabled = true;
                    cargarDataGrid();
                    return true;
                }
                else
                {
                    MessageBox.Show("Descripción no puede estar vacio","Error",MessageBoxButtons.OK);
                    return false;
                }
                /*---------FIN Actualizar FACULTAD----------------*/

            }
        }
        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 #4
0
        public Boolean actualizarDocente(Docente docente)
        {
            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 docente set nombre=@nombre where id_docente=@id;";
                this.command.Parameters.Add(new SqlParameter("@nombre", SqlDbType.NVarChar, 50));
                this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                this.command.Parameters["@nombre"].Value = docente.Nombre;
                this.command.Parameters["@id"].Value = docente.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 #5
0
        public Boolean insertDocente(Docente docente)
        {
            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 docente(nombre) values(@nombre);" + "SELECT CAST(scope_identity() AS int)";
                this.command.Parameters.Add(new SqlParameter("@nombre", SqlDbType.NVarChar, 50));
                this.command.Parameters["@nombre"].Value = docente.Nombre;
                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 #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
 /*--------------------FIN CATALOGO Edificios------------------------*/
 /*--------------------Catalogo de Docentes-------------------------*/
 public List<Docente> getDocentes()
 {
     SqlDataReader dataReader = null;
     List<Docente> docentes = new List<Docente>();
     try
     {
         string query = "Select * from docente";
         command = new SqlCommand(query, connection);
         command.Connection.Open();
         dataReader = command.ExecuteReader();
         while (dataReader.Read())
         {
             Docente docente = new Docente();
             docente.Id = Convert.ToInt32(dataReader["id_docente"].ToString());
             docente.Nombre = dataReader["nombre"].ToString();
             docentes.Add(docente);
         }
         return docentes;
     }
     catch (Exception e)
     {
         throw new Exception("Error al obtener datos de Docente. " + e.Message.ToString());
     }
     finally
     {
         command.Connection.Close();
     }
 }
Example #8
0
        public Boolean borrarDocente(Docente docente)
        {
            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 docente where id_docente=@id;";
                this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                this.command.Parameters["@id"].Value = docente.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 #9
0
        private bool insertDocente(Docente docente)
        {
            try
            {
                db.insertDocente(docente);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

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

            return true;
        }