Exemplo n.º 1
0
 public static int actualizar(Categoria pData)
 {
     int retorno = 0;
     MySqlConnection conexion = Connection.ObtenerConexion();
     string squery = string.Format(" UPDATE cont_categorias SET  nombre = '{0}',color = '{1}' ,descripcion = '{2}' WHERE id_categoria = {3} ", pData.nombre, pData.color, pData.descripcion, pData.id_categoria);
     MySqlCommand cmd = new MySqlCommand(squery, conexion);
     retorno = cmd.ExecuteNonQuery();
     conexion.Close();
     return retorno;
 }
Exemplo n.º 2
0
 public static int agregar(Categoria pData)
 {
     int retorno = 0;
     MySqlConnection conexion = Connection.ObtenerConexion();
     String squery = string.Format("INSERT INTO cont_categorias (  nombre ,color ,descripcion) VALUES (  '{0}' ,'{1}' ,'{2}') ",
         pData.nombre, pData.color, pData.descripcion  );
     MySqlCommand cmd = new MySqlCommand(squery, conexion);
     retorno = cmd.ExecuteNonQuery();
     conexion.Close();
     return retorno;
 }
Exemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Categoria pCategoria = new Categoria();
            pCategoria.nombre = txtNombre.Text.Trim();
            pCategoria.descripcion = txtDescripcion.Text.Trim();

            int resultado = CategriaDal.agregar(pCategoria);
            if (resultado > 0)
            {
                fLoadForm();
                MessageBox.Show("Categoria Guardada Exitosamente", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Ocurrio un Error al Guardar la Categoría", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 4
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            Categoria pCategoria = new Categoria();
            pCategoria.nombre = txtNombre.Text.Trim();
            pCategoria.descripcion = txtDescripcion.Text.Trim();
            pCategoria.id_categoria = categoriaActual;

            int resultado = CategriaDal.actualizar(pCategoria);
            if (resultado > 0)
            {
                fLoadForm();
                MessageBox.Show("Registro Actualizado Exitosamente", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            else
            {
                MessageBox.Show("Ocurrio un Error al Actualizar el registro", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        public static Categoria obtener(Int32 pId)
        {
            MySqlConnection conexion = Connection.ObtenerConexion();
            Categoria pData = new Categoria();

            MySqlCommand cmd = new MySqlCommand(String.Format(
                "select  id_categoria, nombre ,color ,descripcion  from cont_categorias where id_categoria = {0} ", pId),
                conexion);
            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                pData.id_categoria = reader.GetInt32(0);
                pData.nombre = reader.GetString(1);
                pData.color = reader.GetString(2);
                pData.descripcion = reader.GetString(3);
            }

            conexion.Close();
            return pData;
        }
Exemplo n.º 6
0
        public static List<Categoria> buscar(string pSearch = " ")
        {
            List<Categoria> _lista = new List<Categoria>();
            MySqlConnection conexion = Connection.ObtenerConexion();
            MySqlCommand cmd = new MySqlCommand(String.Format(
                "SELECT id_categoria, nombre ,color ,descripcion FROM cont_categorias where nombre like '%{0}%' ", pSearch), conexion);

            MySqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Categoria pData = new Categoria();
                pData.id_categoria = reader.GetInt32(0);
                pData.nombre = reader.GetString(1);
                pData.color = reader.GetString(2);
                pData.descripcion = reader.GetString(3);
                _lista.Add(pData);
            }

            conexion.Close();
            return _lista;
        }