예제 #1
0
파일: Program.cs 프로젝트: oscmonlop98/ad
        private static void modificar() {

            string seleccionado = "0";
            int idSelected = 0;

            mostrar();
            IDbCommand dbCommand = dbConnection.CreateCommand();

            Console.WriteLine("Selecciona un artículo: ");
            seleccionado = Console.ReadLine();
            idSelected = Int32.Parse(seleccionado);

            Console.Write("Introduce el nombre del artículo: ");
            string nombre = Console.ReadLine();
            Console.Write("Introduce el precio de " + nombre + ": ");
            string precio = Console.ReadLine();
            Console.Write("Introduce la categoria de " + nombre + ": ");
            string categoria = Console.ReadLine();

            //Actualización de datos
            dbCommand.CommandText = "UPDATE articulo SET nombre = @nombre, precio = @precio, categoria = @categoria WHERE id = @idSelected;";
            DbCommandHelper.AddParameter(dbCommand, "idSelected", idSelected);
            DbCommandHelper.AddParameter(dbCommand, "nombre", nombre);
            DbCommandHelper.AddParameter(dbCommand, "precio", precio);
            DbCommandHelper.AddParameter(dbCommand, "categoria", categoria);
            dbCommand.ExecuteNonQuery();

        }
예제 #2
0
파일: Program.cs 프로젝트: FdezGuillen/ad
        public static bool Consultar(int id)
        {
            bool       recordExists = false;
            IDbCommand dbCommand    = dbConnection.CreateCommand();

            dbCommand.CommandText = "select * from articulo where id=@id";

            try {
                DbCommandHelper.AddParameter(dbCommand, "id", id);

                IDataReader dataReader = dbCommand.ExecuteReader();
                if (dataReader.Read())
                {
                    Console.WriteLine("id={0} nombre={1} precio={2} id categoria={3}", dataReader["id"], dataReader["nombre"],
                                      dataReader["precio"], dataReader["idCategoria"]);
                    recordExists = true;
                }
                else
                {
                    throw new Exception("No existe ningún artículo con este ID.");
                }
                dataReader.Close();
            }
            catch (Exception e) {
                Console.WriteLine("ERROR. {0}", e);
            }
            return(recordExists);
        }
예제 #3
0
파일: Program.cs 프로젝트: Benito-B/ad
        private static void NewArticle()
        {
            string     name;
            float      price;
            int        cat;
            IDbCommand dbCommand = dbConn.CreateCommand();

            dbCommand.CommandText = "insert into articulo( nombre, categoria, precio) values ( @name, @cat, @price)";

            Console.Write("Introduce nombre del artículo: ");
            name = Console.ReadLine();
            GetCategories();
            Console.Write("Introduce categoría del artículo: ");
            cat = int.Parse(Console.ReadLine());
            Console.Write("Introduce precio del artículo: ");
            price = float.Parse(Console.ReadLine());

            DbCommandHelper.AddParameter(dbCommand, "@name", name);
            DbCommandHelper.AddParameter(dbCommand, "@cat", cat);
            DbCommandHelper.AddParameter(dbCommand, "@price", price);
            if (dbCommand.ExecuteNonQuery() >= 1)
            {
                Console.WriteLine("Artículo {0} con categoría {1} y precio {2} insertado correctamente.", name, cat, price);
            }
            else
            {
                Console.WriteLine("Error insertando el artículo");
            }
        }
예제 #4
0
        public static Articulo Load(object id)
        {
            IDbCommand dbCommand = App.Instance.Connection.CreateCommand();

            dbCommand.CommandText = "select * from articulo where id = @id";
            DbCommandHelper.AddParameter(dbCommand, "id", id);
            IDataReader dataReader = dbCommand.ExecuteReader();

            dataReader.Read();

            string  nombre    = (string)dataReader["nombre"];
            decimal precio    = (decimal)dataReader["precio"];
            long    categoria = dataReader["categoria"] is DBNull ?
                                0 : (long)dataReader["categoria"];

            dataReader.Close();

            Articulo articulo = new Articulo();

            articulo.Id        = Convert.ToInt64(id);
            articulo.Nombre    = nombre;
            articulo.Precio    = precio;
            articulo.Categoria = categoria;

            return(articulo);
        }
예제 #5
0
파일: Program.cs 프로젝트: FdezGuillen/ad
        public static void Nuevo()
        {
            string  nombre;
            Decimal precio;
            int     idCategoria;

            IDbCommand dbCommand = dbConnection.CreateCommand();

            dbCommand.CommandText = "insert into articulo(nombre, precio, idCategoria) values(@nombre, @precio, @idCategoria)";

            try {
                Console.WriteLine("Nombre del artículo: ");
                nombre = Console.ReadLine();

                precio = ConsoleHelper.ReadDecimal("Precio del artículo: ");

                idCategoria = ConsoleHelper.ReadInteger("ID de la categoría: ");

                DbCommandHelper.AddParameter(dbCommand, "nombre", nombre);
                DbCommandHelper.AddParameter(dbCommand, "precio", precio);
                DbCommandHelper.AddParameter(dbCommand, "idCategoria", idCategoria);

                dbCommand.ExecuteNonQuery();
            }
            catch (Exception e) {
                Console.WriteLine("ERROR. {0}", e);
            }
        }
예제 #6
0
파일: Articulo.cs 프로젝트: brdebr/DAM2_AD
        public static void Delete(Articulo articulo)
        {
            IDbCommand dbCommand = SingletonConnection.Connection.CreateCommand();

            dbCommand.CommandText = "DELETE FROM articulo WHERE id=@id";
            DbCommandHelper.addParameter(dbCommand, "id", articulo.id);
            dbCommand.ExecuteNonQuery();
        }
예제 #7
0
파일: ArticuloDao.cs 프로젝트: edudejuan/ad
        private static void insert(Articulo articulo)
        {
            IDbCommand dbCommand = App.Instance.Connection.CreateCommand();

            dbCommand.CommandText = "insert into articulo (nombre) values (@nombre)";
            DbCommandHelper.AddParameter(dbCommand, "nombre", articulo.Nombre);
            dbCommand.ExecuteNonQuery();
        }
예제 #8
0
파일: ArticuloDao.cs 프로젝트: edudejuan/ad
        public static void Delete(object id)
        {
            IDbCommand dbCommand = App.Instance.Connection.CreateCommand();

            dbCommand.CommandText = "delete from articulo where id = @id";
            DbCommandHelper.AddParameter(dbCommand, "id", id);
            dbCommand.ExecuteNonQuery();
        }
예제 #9
0
파일: ArticuloDao.cs 프로젝트: edudejuan/ad
        private static void update(Articulo articulo)
        {
            IDbCommand dbCommand = App.Instance.Connection.CreateCommand();

            dbCommand.CommandText = "update articulo set nombre=@nombre where id = @id";
            DbCommandHelper.AddParameter(dbCommand, "id", articulo.Id);
            DbCommandHelper.AddParameter(dbCommand, "nombre", articulo.Nombre);
            dbCommand.ExecuteNonQuery();
        }
예제 #10
0
파일: Articulo.cs 프로젝트: brdebr/DAM2_AD
        public static void Insert(Articulo articulo)
        {
            IDbCommand dbCommand = SingletonConnection.Connection.CreateCommand();

            dbCommand.CommandText = "INSERT INTO articulo (nombre, precio, categoria) VALUES (@nombre, @precio, @categoria);";
            DbCommandHelper.addParameter(dbCommand, "nombre", articulo.nombre);
            DbCommandHelper.addParameter(dbCommand, "precio", articulo.precio);
            DbCommandHelper.addParameter(dbCommand, "categoria", articulo.categoria_fk);
            dbCommand.ExecuteNonQuery();
        }
예제 #11
0
파일: Articulo.cs 프로젝트: brdebr/DAM2_AD
        public static void Update(Articulo articulo, Articulo nuevo)
        {
            IDbCommand dbCommand = SingletonConnection.Connection.CreateCommand();

            dbCommand.CommandText = "UPDATE articulo SET nombre = @nombre, precio=@precio, categoria=@categoria WHERE id =@id;";
            DbCommandHelper.addParameter(dbCommand, "id", articulo.id);
            DbCommandHelper.addParameter(dbCommand, "nombre", nuevo.nombre);
            DbCommandHelper.addParameter(dbCommand, "precio", nuevo.precio);
            DbCommandHelper.addParameter(dbCommand, "categoria", nuevo.categoria_fk);
            dbCommand.ExecuteNonQuery();
        }
예제 #12
0
        protected static void InsertValue()
        {
            IDbCommand dbCommand = dbConnection.CreateCommand();

            Console.Write("Nombre: ");
            string nombre = Console.ReadLine();

            dbCommand.CommandText = "insert into categoria (nombre) values (@nombre)";
            DbCommandHelper.AddParameter(dbCommand, "nombre", nombre);
            dbCommand.ExecuteNonQuery();
        }
예제 #13
0
        private static void insert(Articulo articulo)
        {
            IDbCommand dbCommand = App.Instance.Connection.CreateCommand();

            dbCommand.CommandText = "insert into articulo (nombre, precio, categoria) " +
                                    "values (@nombre, @precio, @categoria)";
            DbCommandHelper.AddParameter(dbCommand, "nombre", articulo.Nombre);
            DbCommandHelper.AddParameter(dbCommand, "precio", articulo.Precio);
            DbCommandHelper.AddParameter(dbCommand, "categoria",
                                         articulo.Categoria == 0 ? (object)null : articulo.Categoria);
            dbCommand.ExecuteNonQuery();
        }
예제 #14
0
        public static void borrar()
        {
            Console.WriteLine("Ha entrado en borrar");
            Show();
            IDbCommand dbCommand = dbConnection.CreateCommand();

            Console.WriteLine("Dime el id de la linea que deseas borrar: ");
            string id = Console.ReadLine();

            dbCommand.CommandText = "delete from articulo where id=@id";
            DbCommandHelper.AddParameter(dbCommand, "id", id);
            dbCommand.ExecuteNonQuery();
        }
예제 #15
0
        private static void update(Articulo articulo)
        {
            IDbCommand dbCommand = App.Instance.Connection.CreateCommand();

            dbCommand.CommandText = "update articulo set nombre=@nombre , precio=@precio, categoria=@categoria" +
                                    " where id = @id";
            DbCommandHelper.AddParameter(dbCommand, "id", articulo.Id);
            DbCommandHelper.AddParameter(dbCommand, "nombre", articulo.Nombre);
            DbCommandHelper.AddParameter(dbCommand, "precio", articulo.Precio);
            DbCommandHelper.AddParameter(dbCommand, "categoria",
                                         articulo.Categoria == 0 ? (object)null : articulo.Categoria);
            dbCommand.ExecuteNonQuery();
        }
예제 #16
0
파일: Program.cs 프로젝트: Benito-B/ad
        private static void NewCategory()
        {
            IDbCommand dbCommand = dbConn.CreateCommand();

            Console.Write("Introduce el nombre de la nueva categoría: ");
            string cat = Console.ReadLine();

            dbCommand.CommandText = "Insert into categoria(nombre) values (@cat)";
            DbCommandHelper.AddParameter(dbCommand, "@cat", cat);
            if (dbCommand.ExecuteNonQuery() >= 1)
            {
                Console.WriteLine("Categoría {0} insertada correctamente.", cat);
            }
            else
            {
                Console.WriteLine("Error insertando la categoría");
            }
        }
예제 #17
0
파일: Program.cs 프로젝트: oscmonlop98/ad
        private static void borrar() {

            string seleccionado = "0";
            int idSelected = 0;

            mostrar();

            IDbCommand dbCommand = dbConnection.CreateCommand();

            Console.WriteLine("Selecciona un artículo: ");
            seleccionado = Console.ReadLine();
            idSelected = Int32.Parse(seleccionado);

            dbCommand.CommandText = "DELETE FROM articulo WHERE id = @idSelected;";
            DbCommandHelper.AddParameter(dbCommand, "idSelected", idSelected);
            dbCommand.ExecuteNonQuery();

        }
예제 #18
0
파일: Articulo.cs 프로젝트: brdebr/DAM2_AD
        public static string IdCategoria(string nombre)
        {
            IDbCommand dbCommand = SingletonConnection.Connection.CreateCommand();

            dbCommand.CommandText = "SELECT id FROM categoria WHERE nombre=@nombre";
            DbCommandHelper.addParameter(dbCommand, "nombre", nombre);
            IDataReader datareader = dbCommand.ExecuteReader();

            //while ( datareader.Read() )
            //{
            //	lista.Add( datareader["nombre"].ToString() );
            //}
            //return lista.ToArray();
            datareader.Read();
            string retorno = datareader["id"].ToString();

            datareader.Close();
            return(retorno);
        }
예제 #19
0
파일: Program.cs 프로젝트: Benito-B/ad
        private static void DeleteArticle()
        {
            int        id;
            IDbCommand dbCommand = dbConn.CreateCommand();

            dbCommand.CommandText = "delete from articulo where id = @id";
            Console.Write("Introduce ID del artículo a borrar: ");
            id = int.Parse(Console.ReadLine());

            DbCommandHelper.AddParameter(dbCommand, "@id", id);
            if (dbCommand.ExecuteNonQuery() >= 1)
            {
                Console.WriteLine("Eliminado artículo con id: {0}\n", id);
            }
            else
            {
                Console.WriteLine("Error eliminando artículo.\n");
            }
        }
예제 #20
0
파일: Program.cs 프로젝트: FdezGuillen/ad
        public static void Modificar()
        {
            int     id;
            string  nombre;
            Decimal precio;
            int     idCategoria;

            IDbCommand dbCommand = dbConnection.CreateCommand();

            dbCommand.CommandText = "update articulo " +
                                    "set nombre=@nombre, precio=@precio, idCategoria=@idCategoria " +
                                    "where id = @id";

            try {
                id = ConsoleHelper.ReadInteger("ID del artículo a modificar: ");

                Console.WriteLine("Datos actuales del artículo: ");
                bool articuloExists = Consultar(id);

                if (!articuloExists)
                {
                    throw new Exception();
                }

                Console.WriteLine("Nombre del artículo: ");
                nombre = Console.ReadLine();

                precio = ConsoleHelper.ReadDecimal("Precio del artículo: ");

                idCategoria = ConsoleHelper.ReadInteger("ID de la categoría: ");

                DbCommandHelper.AddParameter(dbCommand, "nombre", nombre);
                DbCommandHelper.AddParameter(dbCommand, "precio", precio);
                DbCommandHelper.AddParameter(dbCommand, "idCategoria", idCategoria);
                DbCommandHelper.AddParameter(dbCommand, "id", id);

                dbCommand.ExecuteNonQuery();
            }
            catch (Exception e) {
                Console.WriteLine("ERROR. {0}", e);
            }
        }
예제 #21
0
파일: ArticuloDao.cs 프로젝트: edudejuan/ad
        public static Articulo Load(object id)
        {
            IDbCommand dbCommand = App.Instance.Connection.CreateCommand();

            dbCommand.CommandText = "select * from articulo where id = @id";
            DbCommandHelper.AddParameter(dbCommand, "id", id);
            IDataReader dataReader = dbCommand.ExecuteReader();

            dataReader.Read();
            string nombre = (string)dataReader["nombre"];

            dataReader.Close();


            Articulo articulo = new Articulo();

            articulo.Id     = Convert.ToInt64(id);
            articulo.Nombre = nombre;
            return(articulo);
        }
예제 #22
0
파일: Program.cs 프로젝트: FdezGuillen/ad
        public static void Eliminar()
        {
            int id;

            IDbCommand dbCommand = dbConnection.CreateCommand();

            dbCommand.CommandText = "delete from articulo where id = @id";

            try {
                id = ConsoleHelper.ReadInteger("ID del artículo a eliminar: ");

                Console.WriteLine("Datos del artículo: ");
                bool articuloExists = Consultar(id);

                if (!articuloExists)
                {
                    throw new Exception();
                }

                DbCommandHelper.AddParameter(dbCommand, "id", id);

                Console.WriteLine("¿Seguro que quieres eliminar este artículo? (Sí/No)");
                string opcion = Console.ReadLine().ToLower();

                if (opcion[0] == 's')
                {
                    dbCommand.ExecuteNonQuery();
                    Console.WriteLine("Artículo eliminado.");
                }
                else
                {
                    Console.WriteLine("Operación cancelada.");
                }
            }
            catch (FormatException) {
                Console.WriteLine("Entrada incorrecta. Por favor, vuelve a intentarlo.");
            }
            catch (Exception e) {
                Console.WriteLine("ERROR. {0}", e);
            }
        }
예제 #23
0
파일: Program.cs 프로젝트: oscmonlop98/ad
        private static void nuevo() {

            Console.WriteLine("\n Ha entrado en nuevo\n");
            IDbCommand dbCommand = dbConnection.CreateCommand();

            Console.Write("Introduce el nombre del artículo: ");
            string nombre = Console.ReadLine();
            Console.Write("Introduce el precio de " + nombre + ": ");
            string precio = Console.ReadLine();
            Console.Write("Introduce la categoria de " + nombre + ": ");
            string categoria = Console.ReadLine();

            //Inserción de datos
            dbCommand.CommandText = "insert into articulo (nombre, precio, categoria) values (@nombre, @precio, @categoria)";

            DbCommandHelper.AddParameter(dbCommand, "nombre", nombre);
            DbCommandHelper.AddParameter(dbCommand, "precio", precio);
            DbCommandHelper.AddParameter(dbCommand, "categoria", categoria);

            dbCommand.ExecuteNonQuery();

        }
예제 #24
0
        public static void nuevo()
        {
            Console.WriteLine("Ha entrado en nuevo");

            Console.Write("Nombre: ");
            string nombre = Console.ReadLine();

            Console.Write("Precio: ");
            string precio = Console.ReadLine();

            Console.Write("Categoria: ");
            string categoria = Console.ReadLine();

            IDbCommand dbCommand = dbConnection.CreateCommand();

            dbCommand.CommandText = "insert into articulo(nombre,precio,categoria) values (@nombre,@precio,@categoria)";
            DbCommandHelper.AddParameter(dbCommand, "nombre", nombre);
            DbCommandHelper.AddParameter(dbCommand, "precio", precio);
            DbCommandHelper.AddParameter(dbCommand, "categoria", categoria);
            dbCommand.ExecuteNonQuery();

            Console.WriteLine("Añadido Nuevo Articulo");
        }
예제 #25
0
        public static void editar()
        {
            Console.WriteLine("Ha entrado en editar");
            Show(); //Es para mostrar los campos para despues modificar el que quieras
            IDbCommand dbCommand = dbConnection.CreateCommand();

            Console.WriteLine("Dime el id para entrar en la fila: ");
            string id = Console.ReadLine();

            dbCommand.CommandText = "select * from articulo where id=@id";
            DbCommandHelper.AddParameter(dbCommand, "id", id);
            IDataReader dataReader = dbCommand.ExecuteReader();

            while (dataReader.Read())
            {
                Console.WriteLine("id={0} nombre={1} precio={2} categoria={3}", dataReader["id"], dataReader["nombre"], dataReader["precio"], dataReader["categoria"]);
            }
            dataReader.Close();
            Console.WriteLine("Dime que quieres modificar de la fila: ");
            string mod = Console.ReadLine();
            string nombre, precio, categoria;

            if (mod == "nombre")
            {
                Console.WriteLine("Dime el nombre: ");
                nombre = Console.ReadLine();
                dbCommand.CommandText = "update articulo set nombre=@nombre where id=@id";

                DbCommandHelper.AddParameter(dbCommand, "nombre", nombre);
                dbCommand.ExecuteNonQuery();
            }
            if (mod == "precio")
            {
                Console.WriteLine("Dime el precio: ");
                precio = Console.ReadLine();
                dbCommand.CommandText = "update articulo set precio=@precio where id=@id";
                DbCommandHelper.AddParameter(dbCommand, "precio", precio);
                dbCommand.ExecuteNonQuery();
            }
            if (mod == "categoria")
            {
                Console.WriteLine("Dime la categoria");
                categoria             = Console.ReadLine();
                dbCommand.CommandText = "update articulo set categoria=@categoria where id=@id";
                DbCommandHelper.AddParameter(dbCommand, "categoria", categoria);
                dbCommand.ExecuteNonQuery();
            }
            if (mod == "todo")
            {
                Console.WriteLine("Dime el nombre: ");
                nombre = Console.ReadLine();
                Console.WriteLine("Dime el precio: ");
                precio = Console.ReadLine();
                Console.WriteLine("Dime la categoria");
                categoria             = Console.ReadLine();
                dbCommand.CommandText = "update articulo set nombre=@nombre,precio=@precio,categoria=@categoria where id=@id";
                DbCommandHelper.AddParameter(dbCommand, "nombre", nombre);
                DbCommandHelper.AddParameter(dbCommand, "precio", precio);
                DbCommandHelper.AddParameter(dbCommand, "categoria", categoria);


                dbCommand.ExecuteNonQuery();
            }
            dbCommand.ExecuteNonQuery();
        }