Example #1
0
        /// <summary>
        /// inserta un nuevo producto en la BD
        /// </summary>
        /// <param name="producto">producto a insertar</param>
        public static void Insertar(Producto producto)
        {
            try
            {
                string command = "INSERT INTO Producto(nombre,marca, precio,stock) VALUES(@nombre,@marca, @precio,@stock)";

                SqlCommand sqlCommand = new SqlCommand(command, ConexionDB.SqlConnection);

                sqlCommand.Parameters.AddWithValue("nombre", producto.Nombre);
                sqlCommand.Parameters.AddWithValue("marca", producto.Marca);
                sqlCommand.Parameters.AddWithValue("precio", producto.Precio);
                sqlCommand.Parameters.AddWithValue("stock", producto.Stock);

                ConexionDB.AbrirConexion();
                if (sqlCommand.ExecuteNonQuery() == 0)
                {
                    throw new ProductoDuplicadoExcepcion();
                }
            }
            finally
            {
                ConexionDB.CerrarConexion();
            }
        }
        /// <summary>
        /// insterta un nuevo registro de movimiento en la BD
        /// </summary>
        /// <param name="tipoOperacion">tipo de operacion realizada(venta o alquiler)</param>
        /// <param name="cliente">cliente que realizo la compra</param>
        /// <param name="producto">producto comprado</param>
        /// <param name="cantidad">cantidad del producto</param>
        /// <param name="totalPago">total abonado</param>
        public static void Insertar(string tipoOperacion, Cliente cliente, Producto producto, int cantidad, float totalPago)
        {
            try
            {
                string command = "INSERT INTO Movimiento(comprador,producto,cantidad, totalPago,fecha,operacion) VALUES(@comprador,@producto,@cantidad, @totalPago,@fecha,@operacion)";

                SqlCommand sqlCommand = new SqlCommand(command, ConexionDB.SqlConnection);

                sqlCommand.Parameters.AddWithValue("comprador", cliente.Dni);
                sqlCommand.Parameters.AddWithValue("producto", producto.Nombre);
                sqlCommand.Parameters.AddWithValue("cantidad", cantidad);
                sqlCommand.Parameters.AddWithValue("totalPago", totalPago);
                sqlCommand.Parameters.AddWithValue("fecha", DateTime.Today);
                sqlCommand.Parameters.AddWithValue("operacion", tipoOperacion);


                ConexionDB.AbrirConexion();
                sqlCommand.ExecuteNonQuery();
            }
            finally
            {
                ConexionDB.CerrarConexion();
            }
        }
Example #3
0
        /// <summary>
        /// agrega stock de un producto
        /// </summary>
        /// <param name="producto">producto a manipular</param>
        /// <param name="cantidad">cantidad a agregar</param>
        public static void AgregarStock(Producto producto, int cantidad)
        {
            try
            {
                string command = "UPDATE Producto SET stock = @stock WHERE id = @id";

                SqlCommand sqlCommand = new SqlCommand(command, ConexionDB.SqlConnection);


                sqlCommand.Parameters.AddWithValue("id", producto.Id);

                sqlCommand.Parameters.AddWithValue("stock", (producto.Stock + cantidad));

                ConexionDB.AbrirConexion();
                if (sqlCommand.ExecuteNonQuery() == 0)
                {
                    throw new ProducInexistenteExcepcion("No existe el producto");
                }
            }
            finally
            {
                ConexionDB.CerrarConexion();
            }
        }