Пример #1
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);
        }
Пример #2
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);
        }