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; }
public async Task <List <TipoEventoLogistico> > SeleccionarSiguienteEventoporManifiesto(Int64 numeroManifiesto, bool consultaLocal = false) { List <TipoEventoLogistico> eventosSucesores = new List <TipoEventoLogistico>(); Util util = new Util(); bool?usuarioTipoTercero = null; if (util.UsuarioTienePermiso("eventoslogisticosterceros")) { usuarioTipoTercero = true; } if (consultaLocal) { string numeroIdentificacionConductor = string.Empty; List <TipoEventoLogistico> tipoEventos = new List <TipoEventoLogistico>(); List <EventoLogistico> eventosRegistrados = new List <EventoLogistico>(); EventoLogisticoDAO dao = new EventoLogisticoDAO(); List <JerarquiaTipoEventoLogistico> jerarquiaTipoEventos = new List <JerarquiaTipoEventoLogistico>(); EventoLogistico ultimoEventoRegistrado = null; TipoEventoLogistico ultimoTipoEvento = new TipoEventoLogistico(); tipoEventos = await this.SeleccionarTiposEventoLogistico(consultaLocal : true, aplicaTerceros : usuarioTipoTercero); if ((usuarioTipoTercero.HasValue && !usuarioTipoTercero.Value) || !usuarioTipoTercero.HasValue) { //Se consulta si tiene jornada laboral activa var eventosInicioJornada = dao.SeleccionarEventosLogisticos(numeroManifiesto: null, estado: null, codigoTipoEvento: (int)TipoEventoLogisticoEnum.InicioJornada); var eventosFinJornada = dao.SeleccionarEventosLogisticos(numeroManifiesto: null, estado: null, codigoTipoEvento: (int)TipoEventoLogisticoEnum.FinJornada); EventoLogistico ultimoInicioJornada = null; EventoLogistico ultimoFinJornada = null; if (eventosInicioJornada != null && eventosInicioJornada.Count > 0) { eventosInicioJornada = eventosInicioJornada.OrderByDescending(e => e.FechaEvento).ToList(); ultimoInicioJornada = eventosInicioJornada.DefaultIfEmpty(null).Where(e => String.IsNullOrEmpty(e.Estado) || e.Estado != "E").FirstOrDefault(); } if (eventosFinJornada != null && eventosFinJornada.Count > 0) { eventosFinJornada = eventosFinJornada.OrderByDescending(e => e.FechaEvento).ToList(); ultimoFinJornada = eventosFinJornada.DefaultIfEmpty(null).Where(e => String.IsNullOrEmpty(e.Estado) || e.Estado != "E").FirstOrDefault(); } bool existeJornadaLaboral = false; if (ultimoInicioJornada != null) { if (ultimoFinJornada == null) { existeJornadaLaboral = true; } else { //SI existe algún evento de fin jornada registrado, se debe validar que sea anterior al ultimo inicio de jornada if (ultimoFinJornada.FechaEvento < ultimoInicioJornada.FechaEvento) { existeJornadaLaboral = true; } } } if (existeJornadaLaboral == false) { //Si no tiene jornada laboral activa se le muestra únicamente el evento de inicio jornada eventosSucesores = tipoEventos.Where(t => t.CodigoEvento == (int)TipoEventoLogisticoEnum.InicioJornada || t.CodigoEvento == (int)TipoEventoLogisticoEnum.Otro).ToList(); return(eventosSucesores); } } if (numeroManifiesto == 0) { eventosSucesores = dao.SeleccionarEventosSucesores(0); if (eventosSucesores != null) { eventosSucesores = eventosSucesores.Where(e => e.TransporteObligatorio == false).ToList(); } } else { eventosRegistrados = SeleccionarEventosLogisticos(numeroManifiesto, consultaLocal: true, estado: null); jerarquiaTipoEventos = await SeleccionarJerarquiaTipoEventosLogisticos(consultaLocal : true); if (eventosRegistrados != null && eventosRegistrados.Count > 0) { //Se excluyen los eventos con error eventosRegistrados = eventosRegistrados.Where(e => String.IsNullOrEmpty(e.Estado) || e.Estado != "E").OrderByDescending(e => e.FechaEvento).ToList(); ultimoEventoRegistrado = (from e in eventosRegistrados select e).FirstOrDefault(); } if (ultimoEventoRegistrado != null) { eventosSucesores = ValidarEventosLogisticosSucesoresPorUltimoEvento(ultimoEventoRegistrado, eventosRegistrados, tipoEventos, numeroManifiesto); if (eventosSucesores != null && eventosSucesores.Count > 0) { return(eventosSucesores); } ultimoTipoEvento = (from t in tipoEventos where t.CodigoEvento == ultimoEventoRegistrado.IdTipoEvento select t).FirstOrDefault(); if (ultimoTipoEvento.EventoTipoOtros && eventosRegistrados.Count == 1) { //Solo se ha registrado un evento y es de tipo "Otros" eventosSucesores = dao.SeleccionarEventosSucesores(0); } else if (ultimoTipoEvento.EventoTipoOtros && eventosRegistrados.Count > 1) { List <EventoLogistico> eventosRegistradosTipoOtros = new List <EventoLogistico>(); //Se valida si el anterior evento registrado es de tipo otros con restriccion //7,14,19: Parada, Entrada Taller, Inicio jornada respectivamente eventosRegistradosTipoOtros = (from e in eventosRegistrados join t in tipoEventos on e.IdTipoEvento equals t.CodigoEvento where t.EventoTipoOtros && ParametrosSistema.EventoTipoOtroconRestriccion.Contains(t.CodigoEvento) orderby e.FechaEvento descending select e).ToList(); if (eventosRegistradosTipoOtros != null && eventosRegistradosTipoOtros.Count > 0) { var grupoEventosRegistradosTipoOtros = eventosRegistradosTipoOtros.GroupBy(e => e.IdTipoEvento); foreach (IGrouping <int, EventoLogistico> grupo in grupoEventosRegistradosTipoOtros) { int cantidad = grupo.Count(); var eventoTipoRestriccion = (from j in jerarquiaTipoEventos where j.CodigoEventoPredecesor == grupo.Key select j).FirstOrDefault(); if (eventoTipoRestriccion != null) { int cantidadeventoTipoRestriccion = (from e in eventosRegistrados where e.IdTipoEvento == eventoTipoRestriccion.CodigoEvento select e).Count(); if (cantidad > cantidadeventoTipoRestriccion) { eventosSucesores = dao.SeleccionarEventosSucesores(grupo.Key); } } } if (eventosSucesores.Count() == 0) { //eventosRegistrados = eventosRegistrados.OrderByDescending(x => x.FechaEvento).OrderByDescending(x => x.ID).ToList(); eventosRegistrados = eventosRegistrados.OrderByDescending(x => x.FechaEvento).ToList(); ultimoEventoRegistrado = null; ultimoEventoRegistrado = (from e in eventosRegistrados join t in tipoEventos on e.IdTipoEvento equals t.CodigoEvento where !t.EventoTipoOtros select e).FirstOrDefault(); if (ultimoEventoRegistrado != null) { eventosSucesores = ValidarEventosLogisticosSucesoresPorUltimoEvento(ultimoEventoRegistrado, eventosRegistrados, tipoEventos, numeroManifiesto); if (eventosSucesores == null || eventosSucesores.Count == 0) { eventosSucesores = dao.SeleccionarEventosSucesores(ultimoEventoRegistrado.IdTipoEvento); } } else { eventosSucesores = dao.SeleccionarEventosSucesores(0); } } } else { eventosRegistrados = eventosRegistrados.OrderByDescending(x => x.FechaEvento).OrderByDescending(x => x.ID).ToList(); //Se busca el ultimo evento registrado que no sea de tipo otros ultimoEventoRegistrado = (from e in eventosRegistrados join t in tipoEventos on e.IdTipoEvento equals t.CodigoEvento where !t.EventoTipoOtros select e).FirstOrDefault(); if (ultimoEventoRegistrado != null) { eventosSucesores = ValidarEventosLogisticosSucesoresPorUltimoEvento(ultimoEventoRegistrado, eventosRegistrados, tipoEventos, numeroManifiesto); if (eventosSucesores == null || eventosSucesores.Count == 0) { eventosSucesores = dao.SeleccionarEventosSucesores(ultimoEventoRegistrado.IdTipoEvento); } } else { eventosSucesores = dao.SeleccionarEventosSucesores(0); } } } else { //se consulta los eventos sucesores del ultimo evento registrado eventosSucesores = ValidarEventosLogisticosSucesoresPorUltimoEvento(ultimoEventoRegistrado, eventosRegistrados, tipoEventos, numeroManifiesto); if (eventosSucesores == null || eventosSucesores.Count == 0) { eventosSucesores = dao.SeleccionarEventosSucesores(ultimoEventoRegistrado.IdTipoEvento); } } } else { //No se ha registrado ningun evento al viaje eventosSucesores = dao.SeleccionarEventosSucesores(0); } } if (eventosSucesores != null) { eventosSucesores = eventosSucesores.OrderBy(t => t.NombreEvento).ToList(); } return(eventosSucesores); } else { DataService.AppDataService ds = new DataService.AppDataService(ParametrosSistema.TokenUsuarioActual); eventosSucesores = await ds.RealizarPeticionApi <List <TipoEventoLogistico> >("Evento/SeleccionarSiguienteEventoporManifiesto?numeromanifiesto=" + numeroManifiesto.ToString() + "&aplicaTerceros=" + usuarioTipoTercero, DataService.TipoPeticionApi.Get);//.ConfigureAwait(false); } return(eventosSucesores); }