Пример #1
0
        /// <summary>
        /// Removes a product from the db.
        /// </summary>
        /// <param name="idProduct">ID of the product to remove from the DB.</param>
        public static bool DeleteProduct(int idProduct)
        {
            bool success = false;

            try {
                ConnectionDAO.MyConection.Open();
                ConnectionDAO.MyCommand.CommandText = $"DELETE FROM Productos WHERE Codigo=@id;";
                ConnectionDAO.MyCommand.Parameters.AddWithValue("@id", idProduct);
                ConnectionDAO.Execute();
                success = true;
                ConnectionDAO.EventDelegateChange.Invoke(AccionesDB.Delete);
            } catch (Exception e) {
                throw new ComiqueriaException("Error Deleting a product", e);
            }

            return(success);
        }
Пример #2
0
        /// <summary>
        /// Adds a register in the db.
        /// </summary>
        /// <param name="myProduct">Product to add into the db.</param>
        /// <returns>True if can add the product, otherwise returns false.</returns>
        public static bool InsertData(Producto myProduct)
        {
            bool success = false;

            try {
                if (!(myProduct is null))
                {
                    ConnectionDAO.MyCommand.CommandText = $"INSERT INTO Productos Values(@Description, @Price, @Stock);";
                    ConnectionDAO.MyCommand.Parameters.AddWithValue("@Description", myProduct.Descripcion);
                    ConnectionDAO.MyCommand.Parameters.AddWithValue("@Price", myProduct.Precio);
                    ConnectionDAO.MyCommand.Parameters.AddWithValue("@Stock", myProduct.Stock);
                    ConnectionDAO.Execute();
                    success = true;
                    ConnectionDAO.EventDelegateChange.Invoke(AccionesDB.Insert);
                    ConnectionDAO.MyCommand.Parameters.Clear();
                }
            } catch (Exception exe) {
                throw new ComiqueriaException("Error While insert a Product into the DB.", exe);
            }

            return(success);
        }
Пример #3
0
        /// <summary>
        /// Updates a product in the DB.
        /// </summary>
        /// <param name="myProduct">Producto to update into the db.</param>
        /// <returns>True if can update the producto, otherwise returns false.</returns>
        public static bool UpdateData(Producto myProduct)
        {
            bool success = false;

            try {
                if (!(myProduct is null))
                {
                    ConnectionDAO.MyConection.Open();
                    ConnectionDAO.MyCommand.CommandText = $"UPDATE Productos SET Descripcion = @Description, Precio = @Price, Stock = @Stock Where Codigo = @Codigo;";
                    ConnectionDAO.MyCommand.Parameters.AddWithValue("@Codigo", myProduct.Codigo);
                    ConnectionDAO.MyCommand.Parameters.AddWithValue("@Description", myProduct.Descripcion);
                    ConnectionDAO.MyCommand.Parameters.AddWithValue("@Price", myProduct.Precio);
                    ConnectionDAO.MyCommand.Parameters.AddWithValue("@Stock", myProduct.Stock);
                    ConnectionDAO.Execute();
                    success = true;
                    ConnectionDAO.EventDelegateChange.Invoke(AccionesDB.Update);
                }
            } catch (Exception exe) {
                throw new ComiqueriaException("Error While Update a Product into the DB.", exe);
            }

            return(success);
        }