Ejemplo n.º 1
0
        private void cargarDetalleComanda()
        {
            List <ComandaDetalle> arrayDetalle = new List <ComandaDetalle>();

            Comanda comanda = new Comanda();

            comanda = (Comanda)Session["comanda_actual"];

            if (comanda.obtenerDetalle() != null && comanda.obtenerDetalle().Count > 0)
            {
                grvComandaDetalle.DataSource = comanda.obtenerDetalle();
                grvComandaDetalle.DataBind();


                cargarTotalComanda(comanda);
            }
            else
            {
                arrayDetalle = ComandaDetalleLN.ObtenerTodos(comanda.comanda_id);

                foreach (ComandaDetalle item in arrayDetalle)
                {
                    comanda.agregarPedido(item.producto, item.cantidad, item.notas);
                }

                grvComandaDetalle.DataSource = comanda.obtenerDetalle();
                grvComandaDetalle.DataBind();

                cargarTotalComanda(comanda);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Agrega los pedidos de productos a la comanda.
        /// </summary>
        /// <param name="producto_id"></param>
        /// <param name="notas"></param>
        /// <param name="cant"></param>
        private void agregarProductosAComanda(string producto_id, string notas, int cant)
        {
            Producto producto = new Producto();

            producto = ProductoLN.SeleccionarProducto(producto_id);

            if (producto != null)
            {
                comanda.agregarPedido(producto, cant, notas);

                foreach (ComandaDetalle detalle in comanda.obtenerDetalle())
                {
                    try
                    {
                        //Solo agrega nuevos productos, para los existentes, no realiza ninguna acción.
                        ComandaDetalleLN.Nuevo(comanda.comanda_id, detalle);

                        //Refrescar los productos en pantalla
                        cargarProductosPorCategoria(cboCategorias.SelectedItem.Text);
                    }
                    catch (Exception ex)
                    {
                        lblErrorMessage.Text = "Ha ocurrido un error al guardar el pedido " + comanda.comanda_id + "-" + detalle.producto.producto_id + "\n" +
                                               "Código de error: " + ex.Message;
                        lblErrorMessage.CssClass = "alert alert-danger";
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected void grvComandaDetalle_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int iRowIndex = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "Eliminar")
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "ShowPopup();", true);

                GridViewRow fila = grvComandaDetalle.Rows[iRowIndex];

                string producto_id = fila.Cells[0].Text;


                Comanda comanda = new Comanda();

                comanda = (Comanda)Session["comanda_actual"];



                try
                {
                    ComandaDetalleLN.Eliminar(comanda.comanda_id, producto_id);

                    lblErrorMessage.Text     = "Se ha eliminado el pedido con el producto Nº " + producto_id + " " + fila.Cells[1].Text + " con éxito. Proceda a seleccionar otro o formalice la orden.";
                    lblErrorMessage.CssClass = "alert alert-success";

                    Response.AppendHeader("Refresh", "1;url=administrar-comanda.aspx");
                }
                catch (Exception ex)
                {
                    lblErrorMessage.Text = "Ha ocurrido un error al eliminar el pedido.\n" +

                                           "Código de error: " + ex.Message;

                    lblErrorMessage.CssClass = "alert alert-danger";
                }
            }
        }