Пример #1
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);
        }
        protected async override void OnAppearing()
        {
            base.OnAppearing();

            activityIndicator.IsRunning = true;
            activityIndicator.IsVisible = true;

            ScrollView scrollView = new ScrollView();

            StackLayout stackPanel = new StackLayout();

            scrollView.Content = stackPanel;
            stackPanel.Padding = new Thickness(10);

            EventoLogisticoBLL eventoLogisticosBLL = new EventoLogisticoBLL();
            EventoLogistico    evento = new EventoLogistico();

            evento = eventoLogisticosBLL.SeleccionarEventosLogisticoporID(_idEvento);

            if (evento != null)
            {
                List <CampoEventoLogistico> camposTipoEvento = await eventoLogisticosBLL.SeleccionarCamposPorEvento(evento.IdTipoEvento, consultaLocal : true);

                if (camposTipoEvento != null)
                {
                    List <TipoEventoLogistico> tiposEventos = await eventoLogisticosBLL.SeleccionarTiposEventoLogistico(consultaLocal : true);

                    TipoEventoLogistico tipoEvento = (from t in tiposEventos
                                                      where t.CodigoEvento == evento.IdTipoEvento
                                                      select t).FirstOrDefault();

                    if (tipoEvento != null)
                    {
                        Label lblNombreEvento = new Label();
                        lblNombreEvento.Text     = tipoEvento.NombreEvento;
                        lblNombreEvento.FontSize = 30;
                        stackPanel.Children.Add(lblNombreEvento);
                    }

                    Label lblTituloFechaEvento = new Label();
                    lblTituloFechaEvento.Text     = "Fecha Evento";
                    lblTituloFechaEvento.FontSize = 25;
                    stackPanel.Children.Add(lblTituloFechaEvento);

                    Label lblFechaEvento = new Label();
                    lblFechaEvento.Text     = evento.FechaEvento.Value.ToString();
                    lblFechaEvento.FontSize = 20;
                    stackPanel.Children.Add(lblFechaEvento);

                    Label lblTituloNumeroManifiesto = new Label();
                    lblTituloNumeroManifiesto.Text     = "Número Manifiesto";
                    lblTituloNumeroManifiesto.FontSize = 25;
                    stackPanel.Children.Add(lblTituloNumeroManifiesto);

                    Label lblNumeroViaje = new Label();
                    lblNumeroViaje.Text     = evento.NumeroManifiesto.ToString();
                    lblNumeroViaje.FontSize = 20;
                    stackPanel.Children.Add(lblNumeroViaje);

                    Label tituloCampo;
                    Label valorCampo;

                    foreach (CampoEventoLogistico campo in camposTipoEvento)
                    {
                        tituloCampo = new Label();
                        valorCampo  = new Label();

                        tituloCampo.Text     = campo.TituloCampoEventoLogistico;
                        tituloCampo.FontSize = 25;

                        valorCampo.Text     = Util.ObtenerValorDinamicamente(evento, campo.NombreCampoEventoLogistico);
                        valorCampo.FontSize = 20;

                        stackPanel.Children.Add(tituloCampo);
                        stackPanel.Children.Add(valorCampo);
                    }
                    if (!string.IsNullOrEmpty(evento.ErrorSincronizacion))
                    {
                        //Label lblTituloError = new Label();
                        //lblTituloError.Text = "Resultado Evento";
                        //stackPanel.Children.Add(lblTituloError);
                        Label lblError = new Label();
                        lblError.Text      = evento.ErrorSincronizacion;
                        lblError.TextColor = Color.Red;
                        stackPanel.Children.Add(lblError);
                    }

                    Content = scrollView;
                }
            }

            activityIndicator.IsRunning = false;
            activityIndicator.IsVisible = false;
        }