public void GUardarEnBaseDeDatos()
 {
     foreach (var item in ObtenerMuestrasConsistentes())
     {
         RespuestaProceso <Muestra> respuesta = servicioBdMuestra.Guardar(item);
         if (respuesta.Error == true)
         {
             Mensajes.MostrarError(respuesta.Mesaje);
         }
     }
 }
Esempio n. 2
0
        public async void btnIngresarClicked(object sender, EventArgs e)
        {
            btnLogin.IsEnabled = false;
            IsBusy             = true;

            SeguridadBLL bll = new SeguridadBLL();

            //Se borran las credeciales almacenadas
            bll.EliminarCredencialesUsuario();

            if (await ParametrosSistema.isOnline)
            {
                TokenSeguridad token = null;

                try
                {
                    lblEstado.Text = "Autenticando usuario.";
                    token          = await bll.Autenticar(txtUsuario.Text, txtPassword.Text);

                    if (token != null)
                    {
                        lblEstado.Text = "Autenticación correcta.";
                        Com.OneSignal.OneSignal.IdsAvailable idsPrinterDelegate = async delegate(string playerID, string pushToken)
                        {
                            try
                            {
                                NotificacionBLL notificacionBLL       = new NotificacionBLL();
                                CodigoNotificacionAplicacionMovil not = new CodigoNotificacionAplicacionMovil();
                                not.OneSignalId = playerID;
                                not.PushToken   = string.Empty;
                                not.Plataforma  = "android";
                                not.Usuario     = Common.ParametrosSistema.UsuarioActual;
                                await notificacionBLL.RegistrarDispositivo(not);

                                lblEstado.Text = "Dispositivo registrado correctamente.";
                            }
                            catch (Exception ex)
                            {
                                lblEstado.Text = "Error registrando dispositivo para notificaciones.";
                            }
                        };
                        lblEstado.Text = "Registrando dispositivo para notificaciones.";
                        Com.OneSignal.OneSignal.GetIdsAvailable(idsPrinterDelegate);


                        //Se crea la base de datos local
                        lblEstado.Text = "Creando base de datos local.";
                        DatabaseBLL      dbBLL     = new DatabaseBLL();
                        RespuestaProceso respuesta = await dbBLL.CrearBaseDeDatos();

                        lblEstado.Text = "Base de datos creada correctamente.";
                        if (respuesta.ProcesadoCorrectamente == true)
                        {
                            btnLogin.IsEnabled = true;
                            IsBusy             = false;
                            await Navigation.PopAsync();

                            await Navigation.PushAsync(new HomeView());
                        }
                        else
                        {
                            btnLogin.IsEnabled = true;
                            IsBusy             = false;
                            await Navigation.PushAsync(new ErrorView(respuesta.Respuesta));
                        }
                    }
                    else
                    {
                        btnLogin.IsEnabled = true;
                        IsBusy             = false;
                        DisplayAlert("Error al Ingresar", "Ocurrió un error inesperado en la autenticación.", "Aceptar");
                    }
                }
                catch (Exception ex)
                {
                    btnLogin.IsEnabled = true;
                    IsBusy             = false;
                    if (ex.Message.Contains("Bad Request"))
                    {
                        DisplayAlert("Error al Ingresar", "Nombre de usuario y/o contraseña no válidos.", "Aceptar");
                    }
                    else
                    {
                        DisplayAlert("Error al Ingresar", "Ocurrió un error inesperado en la autenticación.", "Aceptar");
                    }
                }
            }
            else
            {
                DisplayAlert("ERROR", "No tiene conexión a Internet", "Aceptar");
                IsBusy             = false;
                btnLogin.IsEnabled = true;
            }
        }
Esempio n. 3
0
        public async Task <RespuestaProceso> CrearBaseDeDatos()
        {
            RespuestaProceso respuesta = new RespuestaProceso();

            respuesta.ProcesadoCorrectamente = true;

            List <Type> tablasRequeridas = new List <Type>();

            //Se verifica si el usuario debe tener base de datos local
            tablasRequeridas.Add(typeof(Entities.Operaciones.Agencia));

            if (ParametrosSistema.PermisosUsuarioAlmacenado.Count(p => p.NombreOpcion.ToLower() == "registrar_evento_logistico" || p.NombreOpcion.ToLower() == "eventoslogisticosterceros") > 0)
            {
                tablasRequeridas.Add(typeof(Entities.Operaciones.TipoEventoLogistico));
                tablasRequeridas.Add(typeof(Entities.Operaciones.EventoLogistico));
                tablasRequeridas.Add(typeof(Entities.Operaciones.CampoEventoLogistico));
                tablasRequeridas.Add(typeof(Entities.Operaciones.ItemCampoEventoLogistico));
                tablasRequeridas.Add(typeof(Entities.Operaciones.SubItemCampoEventoLogistico));
                tablasRequeridas.Add(typeof(Entities.Operaciones.JerarquiaTipoEventoLogistico));
                //tablasRequeridas.Add(typeof(Entities.Operaciones.RemesasPorNumeroEntrega));

                tablasRequeridas.Add(typeof(Entities.Operaciones.HistorialActivacionManifiesto));
                tablasRequeridas.Add(typeof(Entities.Comercial.Entrega));

                tablasRequeridas.Add(typeof(Entities.IT.ConfiguracionApp));
            }
            if (tablasRequeridas.Count > 0)
            {
                DatabaseDAO dao     = new DatabaseDAO();
                bool        esNueva = false;
                if (!DependencyService.Get <ISQLite>().ExisteBaseDeDatos() || true)
                {
                    dao.CrearBaseDeDatos(tablasRequeridas);
                    esNueva = true;
                }
                if (esNueva)
                {
                    if (await Common.ParametrosSistema.isOnline)
                    {
                        try
                        {
                            //Se llenan las tablas maestras
                            EventoLogisticoBLL eventoBLL = new EventoLogisticoBLL();

                            bool?aplicaTerceros = null;
                            if (ParametrosSistema.PermisosUsuarioAlmacenado.Count(p => p.NombreOpcion.ToLower() == "eventoslogisticosterceros") > 0)
                            {
                                aplicaTerceros = true;
                            }
                            foreach (Type tabla in tablasRequeridas)
                            {
                                switch (tabla.Name)
                                {
                                case "TipoEventoLogistico":
                                    var tiposEventos = await eventoBLL.SeleccionarTiposEventoLogistico(consultaLocal : false, aplicaTerceros : aplicaTerceros);

                                    dao.GuardarRegistros(tiposEventos);
                                    break;

                                case "EventoLogistico":
                                    if (!String.IsNullOrEmpty(ParametrosSistema.UsuarioActual))
                                    {
                                        //Se consultan los ultimos eventos del usuario actual
                                        var eventos = await eventoBLL.SeleccionarEventosLogisticosUsuarioActual();

                                        if (eventos != null)
                                        {
                                            dao.GuardarRegistros(eventos);
                                        }
                                    }
                                    break;

                                case "CampoEventoLogistico":
                                    var camposTiposEventos = await eventoBLL.SeleccionarCamposPorEvento(null, consultaLocal : false);

                                    dao.GuardarRegistros(camposTiposEventos);
                                    break;

                                case "ItemCampoEventoLogistico":
                                    var itemsCampoEventoLogistico = await eventoBLL.SeleccionarItemsPorCamposEvento(null, null, consultaLocal : false);

                                    dao.GuardarRegistros(itemsCampoEventoLogistico);
                                    break;

                                case "SubItemCampoEventoLogistico":
                                    var subItemsCampoEventoLogistico = await eventoBLL.SeleccionarSubItemsPorCamposEvento(null, consultaLocal : false);

                                    dao.GuardarRegistros(subItemsCampoEventoLogistico);
                                    break;

                                case "JerarquiaTipoEventoLogistico":
                                    var jerarquiaTiposEventosLogisticos = await eventoBLL.SeleccionarJerarquiaTipoEventosLogisticos(consultaLocal : false, aplicaTerceros : aplicaTerceros);

                                    dao.GuardarRegistros(jerarquiaTiposEventosLogisticos);
                                    break;

                                case "HistorialActivacionManifiesto":
                                    var transportes = await eventoBLL.SeleccionarTransporteHabilitadoRegistroEventos(consultaLocal : false, tercero : aplicaTerceros);

                                    if (transportes != null && transportes.Count > 0)
                                    {
                                        Transporte transporte = transportes[0];

                                        HistorialActivacionManifiesto historial = new HistorialActivacionManifiesto();
                                        historial.Activo             = true;
                                        historial.FechaActivacion    = DateTime.Now;
                                        historial.NumeroManifiesto   = transporte.NumeroTransporte;
                                        historial.Placa              = transporte.Placa;
                                        historial.NumeroDocConductor = transporte.NumeroDocConductor.ToString();
                                        historial.NombreRuta         = transporte.NombreRuta;
                                        historial.UsuarioActivacion  = ParametrosSistema.UsuarioActual;

                                        //Se busca localmente el evento de activación del transporte activo
                                        var eventosActivacionTransporte = eventoBLL.SeleccionarEventosLogisticos(transporte.NumeroTransporte, codigoTipoEvento: (int)TipoEventoLogisticoEnum.ActivarViaje, consultaLocal: true);
                                        if (eventosActivacionTransporte != null & eventosActivacionTransporte.Count > 0)
                                        {
                                            historial.FechaActivacion = eventosActivacionTransporte[0].FechaEvento;
                                        }

                                        HistorialActivacionManifiestoDAO historialActivacionDAO = new HistorialActivacionManifiestoDAO();
                                        historialActivacionDAO.GuardarHistorialActivacionManifiesto(historial);

                                        //Se guardan las entregas del transporte
                                        if (transporte.Entregas != null && transporte.Entregas.Count > 0)
                                        {
                                            EntregaBLL entregaBLL = new EntregaBLL();
                                            foreach (Entrega entrega in transporte.Entregas)
                                            {
                                                entregaBLL.GuardarEntrega(entrega);
                                            }
                                        }
                                    }
                                    break;

                                case "Agencia":
                                    List <Agencia> agencias = new List <Agencia>();
                                    agencias = CargarAgencias();
                                    dao.GuardarRegistros(agencias);
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            respuesta.ProcesadoCorrectamente = false;
                            respuesta.Respuesta = "Ocurrió un error configurando la aplicación.";
                        }
                    }
                    else
                    {
                        respuesta.ProcesadoCorrectamente = false;
                        respuesta.Respuesta = "Se necesita una conexión a Internet para que la aplicación pueda configurarse correctamente. Esto sólo se necesita la primera vez.";
                    }
                }
            }



            return(respuesta);
        }