Ejemplo n.º 1
0
        //ELIMINAR CATEGORIA MEDIANTE LA CLAVE DESDE LA BASE DE DATOS (MYSLQ)
        public bool EliminarCategoria(string clave)
        {
            MySqlConnection conexion = ServiciosBD.ObtenerConexion();

            try
            {
                StringBuilder sentencia = new StringBuilder();
                sentencia.AppendLine(" DELETE FROM  CATEGORIA WHERE  ID_CATEGORIA = @CLAVE ");

                MySqlCommand comando = ServiciosBD.ObtenerComando(conexion, sentencia.ToString());
                comando.Parameters.Add(new MySqlParameter("CLAVE", clave));

                comando.CommandText = sentencia.ToString();

                return(comando.ExecuteNonQuery() > 0);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
                MySqlConnection.ClearPool(conexion);
            }
        }
Ejemplo n.º 2
0
        //MÉTODO PARA EDITAR Ó MODIFICAR CATEGORIA EN LA BASE DE DATOS (MYSQL)
        public bool EditarCategoria(Categoria categoria)
        {
            MySqlConnection conexion = ServiciosBD.ObtenerConexion();

            try
            {
                StringBuilder sentencia = new StringBuilder();
                sentencia.AppendLine(" UPDATE CATEGORIA ");
                sentencia.AppendLine(" SET DESCRIPCION = @NOMBRE ");
                sentencia.AppendLine(" WHERE ID_CATEGORIA = @CLAVE ");

                MySqlCommand comando = ServiciosBD.ObtenerComando(conexion, sentencia.ToString());
                comando.Parameters.Add(new MySqlParameter("CLAVE", categoria.IdCategoria));
                comando.Parameters.Add(new MySqlParameter("NOMBRE", categoria.Descripcion));
                comando.CommandText = sentencia.ToString();

                return(comando.ExecuteNonQuery() > 0);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
                MySqlConnection.ClearPool(conexion);
            }
        }
Ejemplo n.º 3
0
        // MÉTODO PARA OBTENER TODAS LAS CATEGORIAS EN LA BASE DE DATOS (MYSQL)
        public ListaCategoria ObteberCategoria()
        {
            ListaCategoria  lista    = new ListaCategoria();
            MySqlConnection conexion = ServiciosBD.ObtenerConexion();

            try
            {
                StringBuilder sentencia = new StringBuilder(" SELECT *FROM CATEGORIA ");

                MySqlCommand comando = ServiciosBD.ObtenerComando(conexion, sentencia.ToString());

                comando.CommandText = sentencia.ToString();
                MySqlDataReader lector = comando.ExecuteReader();
                while (lector.Read())
                {
                    Categoria entidad = ConvertEntity(lector);
                    lista.Add(entidad);
                }
                lector.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
                MySqlConnection.ClearPool(conexion);
            }
            return(lista);
        }
        public bool InsertarSubCategoria(SubCategoria entidad)
        {
            MySqlConnection conexion = ServiciosBD.ObtenerConexion();

            try
            {
                StringBuilder sentencia = new StringBuilder(" INSERT INTO SUBCATEGORIA ( ID_CATEGORIA, ID_SUBCATEGORIA, DESCRIPCION) ");
                sentencia.AppendLine(" VALUES ( @ID_CATEGORIA, @ID_SUBCATEGORIA, @DESCRIPCION ) ");
                MySqlCommand comando = ServiciosBD.ObtenerComando(conexion, sentencia.ToString());
                comando.Parameters.Add(new MySqlParameter("ID_CATEGORIA", entidad.IdCategoria));
                comando.Parameters.Add(new MySqlParameter("ID_SUBCATEGORIA", entidad.IdSubCategoria));
                comando.Parameters.Add(new MySqlParameter("DESCRIPCION", entidad.Descripcion));
                return(comando.ExecuteNonQuery() > 0);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
                MySqlConnection.ClearPool(conexion);
                conexion.Dispose();
            }
        }
Ejemplo n.º 5
0
        public bool EditarCliente(Cliente entidad)
        {
            MySqlConnection conexion = ServiciosBD.ObtenerConexion();

            try
            {
                //string Nombre = new System.Globalization.CultureInfo("es-ES", false).TextInfo.ToTitleCase(entidad.Nombre.ToLower());
                //string ApellidoPaterno = new System.Globalization.CultureInfo("es-ES", false).TextInfo.ToTitleCase(entidad.ApellidoPaterno.ToLower());
                //string ApellidoMaterno = new System.Globalization.CultureInfo("es-ES", false).TextInfo.ToTitleCase(entidad.ApellidoMaterno.ToLower());
                //string idcliente = GetIdCliente(entidad);
                StringBuilder sentencia = new StringBuilder(" UPDATE CLIENTES ");
                sentencia.AppendLine(" SET NOMBRE = @NOMBRE, APEPAT = @APEPAT, APEMAT = @APEMAT, FECHANACIMIENTO = @FECHANACIMIENTO, ");
                sentencia.AppendLine(" DIRECCION = @DIRECCION, CORREO = @CORREO, TELEFONO = @TELEFONO, FECHAMODIFICACION = CURDATE(), SEXO = @SEXO ");
                sentencia.AppendLine(" WHERE ID_CLIENTE = @ID_CLIENTE ");
                MySqlCommand comando = ServiciosBD.ObtenerComando(conexion, sentencia.ToString());
                comando.Parameters.Add(new MySqlParameter("ID_CLIENTE", entidad.IdCliente));
                comando.Parameters.Add(new MySqlParameter("NOMBRE", entidad.Nombre.Trim()));
                comando.Parameters.Add(new MySqlParameter("APEPAT", entidad.ApellidoPaterno.Trim()));
                comando.Parameters.Add(new MySqlParameter("APEMAT", entidad.ApellidoMaterno.Trim()));
                comando.Parameters.Add(new MySqlParameter("FECHANACIMIENTO", entidad.FechaNacimiento));
                comando.Parameters.Add(new MySqlParameter("DIRECCION", entidad.Direccion.Trim()));
                comando.Parameters.Add(new MySqlParameter("CORREO", entidad.Correo.Trim().ToLower()));
                comando.Parameters.Add(new MySqlParameter("TELEFONO", entidad.Telefono.Trim()));
                //comando.Parameters.Add(new MySqlParameter("FECHAALTA", entidad.FechaAlta));
                //comando.Parameters.Add(new MySqlParameter("FECHAMODIFICACION", entidad.FechaModificacion));
                //comando.Parameters.Add(new MySqlParameter("PASSWORD", GetSHA256(entidad.Password.Trim())));
                //comando.Parameters.Add(new MySqlParameter("FOTO", entidad.Foto));
                comando.Parameters.Add(new MySqlParameter("SEXO", entidad.Sexo));
                return(comando.ExecuteNonQuery() > 0);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
                MySqlConnection.ClearPool(conexion);
                conexion.Dispose();
            }
        }
Ejemplo n.º 6
0
        public ListaCliente ObtenerClientes(string idCliente)
        {
            ListaCliente lista = new ListaCliente();

            MySqlConnection conexion = ServiciosBD.ObtenerConexion();

            try
            {
                StringBuilder sentencia = new StringBuilder(" SELECT ID, ID_CLIENTE, NOMBRE, APEPAT, APEMAT, FECHANACIMIENTO, DIRECCION, " +
                                                            "CORREO, TELEFONO, FECHAALTA, FECHAMODIFICACION, PASSWORD, FOTO, SEXO FROM CLIENTES ");
                sentencia.AppendLine(" WHERE 1 = 1 ");
                if (idCliente != "All")
                {
                    sentencia.AppendLine(" AND ID_CLIENTE = @IDCLIENTE ");
                }
                MySqlCommand comando = ServiciosBD.ObtenerComando(conexion, sentencia.ToString());
                if (idCliente != "All")
                {
                    comando.Parameters.Add(new MySqlParameter("IDCLIENTE", idCliente));
                }
                comando.CommandText = sentencia.ToString();
                MySqlDataReader lector = comando.ExecuteReader();
                while (lector.Read())
                {
                    Cliente entidad = ConvertirEntidad(lector);
                    lista.Add(entidad);
                }
                lector.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
                MySqlConnection.ClearPool(conexion);
            }
            return(lista);
        }
Ejemplo n.º 7
0
        public bool EliminarCliente(string idCliente)
        {
            MySqlConnection conexion = ServiciosBD.ObtenerConexion();

            try
            {
                StringBuilder sentencia = new StringBuilder(" DELETE FROM CLIENTES ");
                sentencia.AppendLine(" WHERE ID_CLIENTE = @IDCLIENTE ");
                MySqlCommand comando = ServiciosBD.ObtenerComando(conexion, sentencia.ToString());
                comando.Parameters.Add(new MySqlParameter("IDCLIENTE", idCliente));
                comando.CommandText = sentencia.ToString();
                return(comando.ExecuteNonQuery() > 0);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conexion.Close();
                MySqlConnection.ClearPool(conexion);
            }
        }