public void Borrar()
 {
     Facultad fac = new Facultad();
     fac.Id = Convert.ToInt32(this.txtId.Text);
     db.borrarFacultad(fac);
     cargarDataGrid();
     edicion(false);
 }
Exemple #2
0
        public Boolean actualizarFacultad(Facultad facultad)
        {
            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 Facultad set descripcion=@descripcion,color=@color where id_facultad=@id;";
                this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.NVarChar, 50));
                this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                this.command.Parameters.Add(new SqlParameter("@color", SqlDbType.Int));
                this.command.Parameters["@descripcion"].Value = facultad.Descripcion;
                this.command.Parameters["@color"].Value = facultad.Color.ToArgb();
                this.command.Parameters["@id"].Value = facultad.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();
            }
        }
Exemple #3
0
        public Boolean insertFacultad(Facultad facultad)
        {
            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 Facultad(Descripcion,color) values(@descripcion,@color);" + "SELECT CAST(scope_identity() AS int)";
                this.command.Parameters.Add(new SqlParameter("@descripcion", SqlDbType.VarChar, 50));
                this.command.Parameters.Add(new SqlParameter("@color", SqlDbType.Int));
                this.command.Parameters["@descripcion"].Value = facultad.Descripcion;
                this.command.Parameters["@color"].Value = facultad.Color.ToArgb();
                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 roolback accion. " + ex.Message);
                }
            }
            finally
            {
                this.connection.Close();
            }
        }
Exemple #4
0
 /*--------------------Catalogo de Facultades-------------------------*/
 public List<Facultad> getFacultades()
 {
     SqlDataReader dataReader = null;
     List<Facultad> facultades = new List<Facultad>();
     try
     {
         string query = "Select * from facultad";
         command = new SqlCommand(query, connection);
         command.Connection.Open();
         dataReader = command.ExecuteReader();
         while (dataReader.Read())
         {
             Facultad fac = new Facultad();
             fac.Id = Convert.ToInt32(dataReader["id_facultad"].ToString());
             fac.Descripcion = dataReader["descripcion"].ToString();
             fac.Color = Color.FromArgb((int)dataReader["color"]);
             facultades.Add(fac);
         }
         return facultades;
     }
     catch (Exception e)
     {
         throw new Exception("Error al obtener datos de Facultad. "+e.Message.ToString());
     }
     finally
     {
         command.Connection.Close();
     }
 }
Exemple #5
0
        public Boolean borrarFacultad(Facultad facultad)
        {
            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 Facultad where id_facultad=@id;";
                this.command.Parameters.Add(new SqlParameter("@id", SqlDbType.Int));
                this.command.Parameters["@id"].Value = facultad.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();
            }
        }
        public bool Guardar()
        {
            edicion(false);
            if (this.txtId.Text == "")
            {
                /*------------INSERTAR FACULTAD----------------*/
                if (this.txtDescripcion.Text != "")
                {
                    Facultad fac = new Facultad();
                    fac.Descripcion = this.txtDescripcion.Text;
                    fac.Color = colorPickerButton1.SelectedColor;
                    insertFacultad(fac);
                    this.dgFacultades.Enabled = true;
                    cargarDataGrid();
                    this.txtId.DataBindings.Add("Text", FacultadesBindingSource, "Id");
                    this.txtDescripcion.DataBindings.Add("Text", FacultadesBindingSource, "Descripcion");
                    this.FacultadesBindingSource.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 != "")
                {
                    Facultad fac = new Facultad();
                    fac.Id = Convert.ToInt32(this.txtId.Text);
                    fac.Descripcion = this.txtDescripcion.Text;
                    fac.Color = this.colorPickerButton1.SelectedColor;
                    actualizarFacultad(fac);
                    this.dgFacultades.Enabled = true;
                    cargarDataGrid();
                    return true;
                }
                else
                {
                    MessageBox.Show("Descripción no puede estar vacio","Error",MessageBoxButtons.OK);
                    return false;
                }
                /*---------FIN Actualizar FACULTAD----------------*/

            }
        }
        private bool insertFacultad(Facultad fac)
        {
            try
            {
                db.insertFacultad(fac);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return true;
        }
        private bool actualizarFacultad(Facultad fac)
        {
            try
            {
                db.actualizarFacultad(fac);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return true;
        }