Example #1
0
        /// <summary>
        /// Inserta una linea de pedido en un pedido concreto.
        /// </summary>
        /// <param name="lineaPedido">Linea de pedido a insertar</param>
        /// <returns>Numero de filas afectadas</returns>
        public int insertarLineaPedidoEnPedido(clsLineaPedido lineaPedido)
        {
            int             filas           = 0;
            clsMyConnection clsMyConnection = new clsMyConnection();
            SqlConnection   connection      = null;

            try {
                connection = clsMyConnection.getConnection();
                SqlCommand cmd = new SqlCommand(
                    "crearLineaPedido", connection);

                // Decimos que se trata de un procedure
                cmd.CommandType = CommandType.StoredProcedure;

                // Añadimos los parametros al procedure
                cmd.Parameters.Add(new SqlParameter("@codigoProducto", lineaPedido.CodigoProducto));
                cmd.Parameters.Add(new SqlParameter("@codigoPedido", lineaPedido.CodigoPedido));
                cmd.Parameters.Add(new SqlParameter("@cantidad", lineaPedido.Cantidad));
                cmd.Parameters.Add(new SqlParameter("@precioUnitario", lineaPedido.PrecioUnitario));
                cmd.Parameters.Add(new SqlParameter("@Divisa", lineaPedido.Divisa));
                //Ejecutamos el procedimiento.
                filas = cmd.ExecuteNonQuery();
            } catch (Exception e) {
                throw e;
            }
            return(filas);
        }
        public List <clsLineaPedido> getLineasPedidoDeUnPedido(int codigoPedido)
        {
            clsMyConnection       miConexion          = new clsMyConnection();
            SqlConnection         connection          = null;
            SqlCommand            command             = new SqlCommand();
            SqlDataReader         dataReader          = null;
            List <clsLineaPedido> listadoLineasPedido = new List <clsLineaPedido>();
            clsLineaPedido        lineaPedido;


            try
            {
                connection = miConexion.getConnection();
                command.Parameters.AddWithValue("@codigoPedido", codigoPedido);
                command.CommandText = "SELECT * FROM ERP_LineaPedidos WHERE CodigoPedido = @codigoPedido ";
                command.Connection  = connection;
                dataReader          = command.ExecuteReader();

                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        lineaPedido = new clsLineaPedido();

                        lineaPedido.CodigoPedido   = (int)dataReader["CodigoPedido"];
                        lineaPedido.CodigoProducto = (int)dataReader["CodigoProducto"];

                        if (!dataReader.IsDBNull(dataReader.GetOrdinal("Cantidad")))
                        {
                            lineaPedido.Cantidad = (Byte)dataReader["Cantidad"];    //esto tiene que ser asi, con (int) no va y PETA
                        }

                        if (!dataReader.IsDBNull(dataReader.GetOrdinal("PrecioUnitario")))
                        {
                            lineaPedido.PrecioUnitario = (double)(Decimal)dataReader["PrecioUnitario"];
                        }

                        listadoLineasPedido.Add(lineaPedido);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
                if (connection != null)
                {
                    miConexion.closeConnection(ref connection);
                }
            }
            return(listadoLineasPedido);
        }
Example #3
0
        /// <summary>
        /// Método que actualiza un línea de pedido según el código de producto y el código de pedido
        /// </summary>
        /// <param name="lineaPedidoAModificar">Objeto clsLineaPedido que se va a modificar</param>
        /// <returns>int filasAfectadas</returns>
        public int ActualizarLineaPedidoPorIdProductoIdPedido(clsLineaPedido lineaPedidoAModificar)
        {
            //clsOperacionesDeLineaDePedido_DAL objOperaciones = new clsOperacionesDeLineaDePedido_DAL();
            //int filasAfectadas = objOperaciones.ActualizarLineaPedidoPorIdProductoIdPedido(lineaPedidoAModificar);

            //return filasAfectadas;

            //Prueba:
            return(1);
        }
Example #4
0
        /// <summary>
        /// Inserta una linea de pedido en un pedido concreto.
        /// </summary>
        /// <param name="lineaPedido">Linea de pedido a insertar</param>
        /// <returns>Numero de filas afectadas</returns>
        public int insertarLineaPedidoEnPedido(clsLineaPedido lineaPedido)
        {
            int filas;
            ClsHandlerLineaDePedido_DAL handler = new ClsHandlerLineaDePedido_DAL();

            try {
                filas = handler.insertarLineaPedidoEnPedido(lineaPedido);
            } catch (Exception e) {
                throw e;
            }

            return(filas);
        }
Example #5
0
        /// <summary>
        /// Nombre: getOrderLine
        /// Comentario: Este método nos permite obtener una línea de pedido de un producto y pedido determinado.
        /// Cabecera: public clsLineaPedido getOrderLine(int codigoProducto, int codigoPedido)
        /// </summary>
        /// <returns>Devuelve un tipo clsLineaPedido</returns>
        public clsLineaPedido getOrderLine(int codigoProducto, int codigoPedido)
        {
            clsLineaPedido  lineaDePedido   = null;
            SqlDataReader   miLector        = null;
            clsMyConnection clsMyConnection = new clsMyConnection();
            SqlConnection   connection      = null;

            try
            {
                connection = clsMyConnection.getConnection();
                SqlCommand sqlCommand = new SqlCommand();

                sqlCommand.CommandText = "SELECT * FROM ERP_LineaPedidos WHERE CodigoProducto = @CodigoProducto AND CodigoPedido = @CodigoPedido";
                sqlCommand.Parameters.Add("@CodigoProducto", System.Data.SqlDbType.Int).Value = codigoProducto;
                sqlCommand.Parameters.Add("@CodigoPedido", System.Data.SqlDbType.Int).Value   = codigoPedido;

                sqlCommand.Connection = connection;

                miLector = sqlCommand.ExecuteReader();

                if (miLector.HasRows)
                {
                    miLector.Read();
                    lineaDePedido = new clsLineaPedido();
                    //lineaDePedido.CodigoProducto = codigoProducto;
                    lineaDePedido.CodigoProducto = (int)miLector["CodigoProducto"];
                    lineaDePedido.CodigoPedido   = codigoPedido;
                    //lineaDePedido.CodigoPedido = (int)miLector["CodigoPedido"];

                    lineaDePedido.PrecioUnitario = (miLector["PrecioUnitario"] is DBNull) ? 0.0 : Convert.ToDouble(miLector["PrecioUnitario"]);
                    lineaDePedido.Cantidad       = Convert.ToInt32(miLector["Cantidad"]);
                }
            }
            catch (Exception e)
            {
                throw e;//Aquí podriamos pasar la excepción para que en caso de error el front muestre una alerta de error
            }
            finally
            {
                if (miLector != null)
                {
                    miLector.Close();
                }
                if (clsMyConnection != null)
                {
                    clsMyConnection.closeConnection(ref connection);
                }
            }

            return(lineaDePedido);
        }
        //Post
        public int Post([FromBody] clsLineaPedido lineaPedido)
        {
            int filas;
            ClsHandlerLineaDePedido_BL handler = new ClsHandlerLineaDePedido_BL();

            try {
                filas = handler.insertarLineaPedidoEnPedido(lineaPedido);
            } catch (Exception e) {
                throw new HttpResponseException(HttpStatusCode.ServiceUnavailable);
            }

            if (filas == 0)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            return(filas);
        }