Esempio n. 1
0
        public IActionResult Index()
        {
            //CARGAR
            Electron.IpcMain.On("async-pagarOrden-clientes", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    List <Cliente> clientes = pagarOrdenService.getClienteMesa();

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-clientes", clientes);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-clientes", ex.Message);
                }
            });


            //CARGAR
            Electron.IpcMain.On("async-pagarOrden-clienteDetalle", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    int idCliente = int.Parse(args.ToString());

                    Cliente cliente = pagarOrdenService.getClienteApagar(idCliente);

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-clienteDetalle", cliente);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-clienteDetalle", ex.Message);
                }
            });

            //CARGAR
            Electron.IpcMain.On("async-pagarOrden-totalOrdenClienteDetalle", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    int idCliente = int.Parse(args.ToString());

                    int total = pagarOrdenService.getClienteApagarTotalOrden(idCliente);

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-totalOrdenClienteDetalle", total);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-totalOrdenClienteDetalle", ex.Message);
                }
            });

            //CARGAR
            Electron.IpcMain.On("async-pagarOrden-totalPagarClienteDetalle", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    int idCliente = int.Parse(args.ToString());

                    int total = pagarOrdenService.getClienteTotalApagarOrden(idCliente);

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-totalPagarClienteDetalle", total);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-totalOrdenClienteDetalle", ex.Message);
                }
            });


            Electron.IpcMain.On("information-dialog-cambiarTotalPagar", async(args) =>
            {
                var options = new MessageBoxOptions("¿Seguro que desea cambiar el valor total a pagar del cliente?")
                {
                    Type    = MessageBoxType.info,
                    Title   = "Informatión",
                    Buttons = new string[] { "Si", "No" }
                };

                var result = await Electron.Dialog.ShowMessageBoxAsync(options);

                var mainWindow = Electron.WindowManager.BrowserWindows.First();
                Electron.IpcMain.Send(mainWindow, "information-dialog-reply-cambiarTotalPagar", result.Response);
            });


            //CARGAR
            Electron.IpcMain.On("async-pagarOrden-pagarClienteOrdenes", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                int result = 1;

                try
                {
                    int idCliente = int.Parse(args.ToString());

                    result = pagarOrdenService.pagar(idCliente);

                    if (result == 1)
                    {
                        //carga una notificacion
                        var options = new NotificationOptions("Exito", "Cliente marcado como confirmado y sus ordenes pagadas")
                        {
                            OnClick = async() => await Electron.Dialog.ShowMessageBoxAsync(""),
                            Icon    = "/images/cerdito.png"
                        };

                        Electron.Notification.Show(options);
                        //termina de cargar una notificacion
                    }
                    else
                    {
                        //carga una notificacion
                        var options = new NotificationOptions("Error", "Algo esta pasando")
                        {
                            OnClick = async() => await Electron.Dialog.ShowMessageBoxAsync(""),
                            Icon    = "/images/cerdito.png"
                        };
                        Electron.Notification.Show(options);
                        //termina de cargar una notificacion
                    }

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-pagarClienteOrdenes", result);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-pagarClienteOrdenes", ex.Message);
                }
            });


            //pagar personalizaso
            Electron.IpcMain.On("async-pagarOrden-pagarClientePersonalizado", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                int result = -1;

                try
                {
                    Boleta boleta = new Boleta();


                    List <Boleta> boletas = ((JArray)args).Select(x => new Boleta
                    {
                        IdBoleta         = (int)x["id_cliente"],
                        MontoExtra       = (int)x["valor_a_pagar"],
                        Operacion        = (int)x["operacion"],
                        MotivoMontoExtra = (string)x["motivo"]
                    }).ToList();



                    boleta = boletas[0];


                    result = pagarOrdenService.pagarPersonalizado(boleta);

                    if (result == 1)
                    {
                        //carga una notificacion
                        var options = new NotificationOptions("Exito", "Cliente marcado como confirmado y sus ordenes pagadas")
                        {
                            OnClick = async() => await Electron.Dialog.ShowMessageBoxAsync(""),
                            Icon    = "/images/cerdito.png"
                        };

                        Electron.Notification.Show(options);
                        //termina de cargar una notificacion
                    }
                    else
                    {
                        //carga una notificacion
                        var options = new NotificationOptions("Error", "Algo esta pasando")
                        {
                            OnClick = async() => await Electron.Dialog.ShowMessageBoxAsync(""),
                            Icon    = "/images/cerdito.png"
                        };
                        Electron.Notification.Show(options);
                        //termina de cargar una notificacion
                    }

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-pagarClientePersonalizado", result);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-pagarClientePersonalizado", ex.Message);
                }
            });



            //CARGAR ordenes del cliente
            Electron.IpcMain.On("async-pagarOrden-ordenesClienteInbox", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    //
                    //FALTAAAAAAAAAAAAAAAAA
                    //
                    //

                    int idCliente = int.Parse(args.ToString());

                    int total = pagarOrdenService.getClienteTotalApagarOrden(idCliente);

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-ordenesClienteInbox", total);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pagarOrden-ordenesClienteInbox", ex.Message);
                }
            });


            //CARGAR LAS ORDENES DEL MAIN   async-Nombre  cliente
            Electron.IpcMain.On("async-receta-pagarOrden-cliente", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                CocinaService cocinaService = new CocinaService();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    int idCliente = int.Parse(args.ToString());


                    List <OrdenCocina> ordenesCocina = pagarOrdenService.getOrdenesByCliente(idCliente);



                    cocinaService = null;

                    cocinaService = new CocinaService();


                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-pagarOrden-cliente", cocinaService.completarOrden(ordenesCocina));
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-pagarOrden-cliente", ex.Message);
                }
            });


            //buscar los clientes
            Electron.IpcMain.On("async-receta-pagarOrden-buscarCliente", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();


                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    string busqueda = args.ToString();

                    List <Cliente> resultados = pagarOrdenService.getClienteMesaBuscar(busqueda);

                    pagarOrdenService = null;

                    pagarOrdenService  = new PagarOrdenService();
                    List <Cliente> all = pagarOrdenService.getClienteMesa();


                    List <Cliente> final = pagarOrdenService.completarClienteBusqueda(resultados, all, busqueda);

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-pagarOrden-buscarCliente", final);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-pagarOrden-buscarCliente", ex.Message);
                }
            });



            //cargar el modal
            Electron.IpcMain.On("modalReceta-pagarOrden-window", async(argument) =>
            {
                //carga el puerto disponible
                string viewPath = $"http://localhost:{BridgeSettings.WebPort}/PagarOrden/modalrecetapago?idReceta={argument}";

                var optionsWindows = new BrowserWindowOptions
                {
                    Frame = false
                };
                await Electron.WindowManager.CreateWindowAsync(optionsWindows, viewPath);
            });
            //cargar un modal



            return(View());
        }
        public IActionResult Index()
        {
            //CARGAR LAS ORDENES DEL MAIN   async-Nombre
            Electron.IpcMain.On("async-receta", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                CocinaService cocinaService = new CocinaService();

                try
                {
                    List <OrdenCocina> ordenesCocina = cocinaService.getOrdenesByEstadoEnCocina();

                    cocinaService = null;

                    cocinaService = new CocinaService();


                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta", cocinaService.completarOrden(ordenesCocina));
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta", ex.Message);
                }
            });


            //CARGAR LAS ORDENES DEL MAIN   async-Nombre
            Electron.IpcMain.On("async-receta-cantidad", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                CocinaService cocinaService = new CocinaService();

                try
                {
                    List <OrdenCocina> ordenesCocina = cocinaService.getOrdenesByEstadoEnCocina();

                    cocinaService = null;

                    cocinaService = new CocinaService();

                    List <OrdenCocina> ordenes = cocinaService.completarOrden(ordenesCocina);

                    List <RecetaCantidad> recetaCantidad = cocinaService.obtenerRecetasWithCantidad(ordenes);

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-cantidad", recetaCantidad);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-cantidad", ex.Message);
                }
            });

            //completar la orden
            Electron.IpcMain.On("async-receta-completarOrden", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                CocinaService cocinaService = new CocinaService();

                try
                {
                    int idOrden = int.Parse(args.ToString());

                    int result = cocinaService.completarOrden(idOrden);

                    if (result == 1)
                    {
                        cocinaService = null;

                        cocinaService = new CocinaService();

                        Notificacion notificacion = new Notificacion();

                        notificacion.Descripcion = $"La orden Número: {args.ToString()} esta lista para llevar a mesa.";

                        notificacion.Asunto = "Cocina: Orden Lista Para Servir";

                        Rol rol = new Rol();

                        rol.Id_rol = 4;

                        notificacion.Rol = rol;

                        int resultNotificacion = cocinaService.insertarNotificacion(notificacion);

                        if (resultNotificacion == 1)
                        {
                            //carga una notificacion
                            var options = new NotificationOptions("Orden Completa", "La orden Número: " + args + " fue notificada a garzón para llevar a mesa.")
                            {
                                OnClick = async() => await Electron.Dialog.ShowMessageBoxAsync("La orden Número: " + args + " fue notificada a garzón para llevar a mesa, Puedes ver los detalles en la opción de notificaciones"),
                                Icon    = "~/images/clienteCerdos.png"
                            };

                            Electron.Notification.Show(options);
                            //termina de cargar una notificacion
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-completarOrden", "listo");
                }
                catch (Exception ex)
                {
                    //carga una notificacion
                    var options = new NotificationOptions("Error", "Algo mal ocurrio")
                    {
                        OnClick = async() => await Electron.Dialog.ShowMessageBoxAsync("Sorry"),
                        Icon    = "/images/cerdito.png"
                    };

                    Electron.Notification.Show(options);
                    //termina de cargar una notificacion

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-completarOrden", ex.Message);
                }
            });
            //fin completar la orden



            //cargar el modal
            Electron.IpcMain.On("modalReceta-window", async(argument) =>
            {
                //carga el puerto disponible
                string viewPath = $"http://localhost:{BridgeSettings.WebPort}/cocina/modalreceta?idReceta={argument}";

                var optionsWindows = new BrowserWindowOptions
                {
                    Frame = false
                };
                await Electron.WindowManager.CreateWindowAsync(optionsWindows, viewPath);
            });
            //cargar un modal



            return(View());
        }
        public IActionResult Index()
        {
            //CARGAR  los clientes
            Electron.IpcMain.On("async-pedirOrdenGarzon-clientes", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    List <Cliente> clientes = pagarOrdenService.getClienteMesa();

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pedirOrdenGarzon-clientes", clientes);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pedirOrdenGarzon-clientes", ex.Message);
                }
            });

            //CARGAR cliente
            Electron.IpcMain.On("async-pedirOrdenGarzon-clienteDetalle", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    int idCliente = int.Parse(args.ToString());

                    Cliente cliente = pagarOrdenService.getClienteApagar(idCliente);

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pedirOrdenGarzon-clienteDetalle", cliente);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pedirOrdenGarzon-clienteDetalle", ex.Message);
                }
            });

            //CARGAR LAS ORDENES DEl cliente
            Electron.IpcMain.On("async-pedirOrdenGarzon-ordenes-cargar", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                CocinaService cocinaService = new CocinaService();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    int idCliente = int.Parse(args.ToString());


                    List <OrdenCocina> ordenesCocina = pagarOrdenService.getOrdenesByCliente(idCliente);


                    cocinaService = null;

                    cocinaService = new CocinaService();


                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pedirOrdenGarzon-ordenes-cargar", cocinaService.completarOrden(ordenesCocina));
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pedirOrdenGarzon-ordenes-cargar", ex.Message);
                }
            });

            //buscar los clientes
            Electron.IpcMain.On("async-receta-pedirOrdenGarzon-buscarCliente", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();


                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    string busqueda = args.ToString();

                    List <Cliente> resultados = pagarOrdenService.getClienteMesaBuscar(busqueda);

                    pagarOrdenService = null;

                    pagarOrdenService  = new PagarOrdenService();
                    List <Cliente> all = pagarOrdenService.getClienteMesa();


                    List <Cliente> final = pagarOrdenService.completarClienteBusqueda(resultados, all, busqueda);

                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-pedirOrdenGarzon-buscarCliente", final);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-receta-pedirOrdenGarzon-buscarCliente", ex.Message);
                }
            });


            //CARGAR
            Electron.IpcMain.On("async-pedirOrden-eliminarCliente", (args) =>
            {
                var mainWindow = Electron.WindowManager.BrowserWindows.First();

                PagarOrdenService pagarOrdenService = new PagarOrdenService();

                try
                {
                    int idCliente = int.Parse(args.ToString());

                    Cliente cliente = new Cliente();

                    cliente.IdCliente = idCliente;

                    int exito = pagarOrdenService.eliminarClienteById(cliente);


                    if (exito == 1)
                    {
                        //carga una notificacion
                        var options = new NotificationOptions("Exito", "Cliente número " + idCliente + " fue eliminado")
                        {
                            OnClick = async() => await Electron.Dialog.ShowMessageBoxAsync(""),
                            Icon    = "/images/cerdito.png"
                        };

                        Electron.Notification.Show(options);
                        //termina de cargar una notificacion
                    }
                    else
                    {
                        //carga una notificacion
                        var options = new NotificationOptions("Error", "Algo mal paso")
                        {
                            OnClick = async() => await Electron.Dialog.ShowMessageBoxAsync(""),
                            Icon    = "/images/cerdito.png"
                        };
                        Electron.Notification.Show(options);
                        //termina de cargar una notificacion
                    }


                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pedirOrden-eliminarCliente", cliente);
                }
                catch (Exception ex)
                {
                    Electron.IpcMain.Send(mainWindow, "asynchronous-reply-pedirOrden-eliminarCliente", ex.Message);
                }
            });


            return(View());
        }