Ejemplo n.º 1
0
        public objRes Delete(string Cedula)
        {
            using (ctx = new tvEntities())
            {
                objRes Res = new objRes();
                try
                {
                    personas oPer = ctx.personas.Where(t => t.Cedula == Cedula).FirstOrDefault();
                    if (oPer != null)
                    {
                        List <documentospersona> lDocumentos = ctx.documentospersona.Where(t => t.cedula == Cedula).ToList();
                        foreach (documentospersona item in lDocumentos)
                        {
                            ctx.documentospersona.Remove(item);
                        }

                        ctx.personas.Remove(oPer);
                        ctx.SaveChanges();
                        Res.Error   = false;
                        Res.Mensaje = "Operacion realizada satisfactoriamente!!!";
                    }
                    else
                    {
                        Res.Error   = true;
                        Res.Mensaje = "No existe persona con esa cedula!!!";
                    }
                    return(Res);
                }
                catch (Exception e)
                {
                    Res.Error   = true;
                    Res.Mensaje = e.Message;
                    return(Res);
                }
            }
        }
Ejemplo n.º 2
0
        private List <List <detallesplanillaDTO> > crearRotacionesBuses(ref string[] nBus, ref int mes, ref DateTime fcha,
                                                                        ref int grupo, ref List <rutagrupo> lrGrupo,
                                                                        ref List <buses> lBus)
        {
            planillacontrol pC;

            int diasMes = DateTime.DaysInMonth(fcha.Year, fcha.Month);
            int d       = 1;
            int k       = 1;
            int daysToToday;

            daysToToday = Convert.ToInt32((fcha - (new DateTime(DateTime.Now.Year, 1, 1))).TotalDays);
            string[] mBus = new string[30];
            List <List <detallesplanillaDTO> > lldP = new List <List <detallesplanillaDTO> >();

            for (int i = 1; i <= mesTurno.GetLength(1); i++)
            {
                mBus[i] = nBus[mesTurno[mes - 1, i - 1]];
            }

            for (int i = 0; i < dia.GetLength(0); i++)
            {
                if (diasMes == lldP.Count)
                {
                    break;
                }

                List <detallesplanillaDTO> ldP = new List <detallesplanillaDTO>();
                for (int j = 0; j < dia.GetLength(1); j++)
                {
                    detallesplanillaDTO dP = new detallesplanillaDTO();
                    dP.Vial     = mBus[dia[i, j]];
                    dP.PlacaBus = lBus.Find(t => t.Vial == dP.Vial).Placa;
                    ldP.Add(dP);
                    k++;
                }

                if (i == dia.GetLength(0) - 1)
                {
                    i = 0;
                }


                lldP.Add(ldP);

                /////////////// Rutas para cada dia //////////////////
                //En el primer objeto de la lista de detallesplanilla
                if ((lldP.Count + daysToToday) % 2 == 0)
                {
                    ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(0).Ruta;
                }
                else
                {
                    try
                    {
                        ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(1).Ruta;
                    }
                    catch (ArgumentOutOfRangeException e)
                    {
                        ldP.ElementAt(0).Ruta = lrGrupo.ElementAt(0).Ruta;
                    }
                }
                /////////////////////////////////////////////////////
            }

            ///Guardar Detalles de Planilla (Rotaciones del mes)
            ///
            using (ctx = new tvEntities()){
                foreach (List <detallesplanillaDTO> lDp in lldP)
                {
                    ////Creo una nueva Planilla control
                    pC       = new planillacontrol();
                    pC.Fecha = new DateTime(DateTime.Now.Year, mes, d);
                    pC.Grupo = grupo;
                    ctx.planillacontrol.Add(pC);
                    ctx.SaveChanges();
                    d++;

                    string ru   = lDp.ElementAt(0).Ruta;
                    rutas  ruta = ctx.rutas.Where(t => t.NomRuta == ru).FirstOrDefault();
                    int    frec = ruta.Frecuencia.Value;
                    time = ctx.horario.Where(t => t.id == ruta.idHorario).FirstOrDefault().hora.Value;

                    foreach (detallesplanillaDTO DpDTO in lDp)
                    {
                        DpDTO.idPlanillaControl = pC.id;
                        DpDTO.Ruta       = lDp.ElementAt(0).Ruta;
                        DpDTO.HoraSalida = time;
                        detallesplanilla dP = new detallesplanilla();
                        Mapper.Map(DpDTO, dP);
                        ctx.detallesplanilla.Add(dP);
                        ctx.SaveChanges();
                        DpDTO.id = dP.id;

                        time = time + new TimeSpan(0, frec, 0);
                    }
                }
            }
            ////////////////////////////////


            return(lldP);
        }
Ejemplo n.º 3
0
 public objRes Insert(entradassalidasDTO Reg)
 {
     using (ctx = new tvEntities())
     {
         objRes Respuesta = new objRes();
         try
         {
             buses Bus = ctx.buses.Where(t => t.Placa == Reg.Placa).FirstOrDefault();
             if (Bus != null)
             {
                 entradassalidas ESOld = ctx.entradassalidas.Where(t => t.Placa == Reg.Placa).OrderByDescending(t => t.Fecha).FirstOrDefault();
                 if (ESOld == null)
                 {
                     entradassalidas ES = new entradassalidas();
                     ES.Fecha  = DateTime.Now;
                     ES.Estado = "S";
                     ES.Placa  = Reg.Placa;
                     ctx.entradassalidas.Add(ES);
                     ctx.SaveChanges();
                     Respuesta.Error   = false;
                     Respuesta.Mensaje = "Operacion realizada satisfactoriamente!!!";
                     return(Respuesta);
                 }
                 else
                 {
                     DateTime FechaActual = DateTime.Now;
                     TimeSpan Diferencia  = FechaActual - ESOld.Fecha;
                     if (Diferencia.TotalMinutes < 10)
                     {
                         Respuesta.Error   = true;
                         Respuesta.Mensaje = "Este bus ya tiene un evento registrado en menos de 10 minutos, por favor verifique o espere!!!";
                         return(Respuesta);
                     }
                     else
                     {
                         entradassalidas ES = new entradassalidas();
                         ES.Fecha = FechaActual;
                         if (ESOld.Estado == "E")
                         {
                             ES.Estado = "S";
                         }
                         else
                         {
                             ES.Estado = "E";
                         }
                         ES.Placa = Reg.Placa;
                         ctx.entradassalidas.Add(ES);
                         ctx.SaveChanges();
                         Respuesta.Error   = false;
                         Respuesta.Mensaje = "Operacion realizada satisfactoriamente!!!";
                         return(Respuesta);
                     }
                 }
             }
             else
             {
                 Respuesta.Error   = true;
                 Respuesta.Mensaje = "No existe un bus registrado con placa: " + Reg.Placa;
                 return(Respuesta);
             }
         }
         catch (Exception e)
         {
             Respuesta.Error   = true;
             Respuesta.Mensaje = e.Message;
             return(Respuesta);
         }
     }
 }
Ejemplo n.º 4
0
        public objRes insert(historialmovimientoDTO hMDto)
        {
            using (ctx = new tvEntities())
            {
                objRes  Respuesta = new objRes();
                decimal latitud, longitud, latPunto, lonPunto, dec;

                try
                {
                    historialmovimiento hM = new historialmovimiento();

                    hMDto.Placa = ctx.buses.Where(t => t.Vial == hMDto.Vial).FirstOrDefault().Placa;

                    List <puntoscontrol> lpC = ctx.puntoscontrol.ToList();
                    foreach (var pCtr in lpC)
                    {
                        latitud  = Convert.ToDecimal(hMDto.Latitud, CultureInfo.InvariantCulture);
                        longitud = Convert.ToDecimal(hMDto.Longitud, CultureInfo.InvariantCulture);

                        latPunto = Convert.ToDecimal(pCtr.Latitud, CultureInfo.InvariantCulture);
                        lonPunto = Convert.ToDecimal(pCtr.Longitud, CultureInfo.InvariantCulture);

                        dec = (decimal)0.001;

                        if ((latitud <= latPunto + dec) &&
                            (latitud >= latPunto - dec))
                        {
                            if (longitud <= lonPunto + dec &&
                                longitud >= lonPunto - dec)
                            {
                                hMDto.Punto = pCtr.id;
                                break;
                            }
                        }
                    }

                    historialmovimiento hmAux = ctx.historialmovimiento.
                                                OrderByDescending(t => t.Fecha).
                                                Where(t => t.buses.Vial == hMDto.Vial && t.Fecha > hMDto.Fecha.Date && t.Punto != null).
                                                FirstOrDefault();

                    if (hmAux.Punto == hMDto.Punto)
                    {
                        hMDto.Punto = null;
                    }

                    Mapper.Map(hMDto, hM);
                    ctx.historialmovimiento.Add(hM);
                    ctx.SaveChanges();
                    Respuesta.Mensaje = "Guardado con Exito";
                    Respuesta.Error   = false;
                    return(Respuesta);
                }
                catch (Exception e)
                {
                    Respuesta.Error   = true;
                    Respuesta.Mensaje = e.Message;
                    return(Respuesta);
                }
            }
        }
Ejemplo n.º 5
0
        public List <planillarecaudoDTO> get(DateTime fecha, int grupo)
        {
            fecha = fecha.Date;//new DateTime(fecha.Year,fecha.Month,fecha.d)
            DateTime fechaFin = new DateTime(fecha.Year, fecha.Month, fecha.Day, 23, 59, 59);
            List <planillarecaudoDTO> lPlaRecDto;
            planillarecaudo           pR;
            planillarecaudo           pRaux;
            planillarecaudoDTO        pRDto;
            gastos   gastos;
            DateTime fecha2;

            using (ctx = new tvEntities()) {
                planillacontrol PlaCtr = ctx.planillacontrol.Where(t => t.Fecha == fecha && t.Grupo == grupo).FirstOrDefault();

                if (PlaCtr != null)
                {
                    lPlaRecDto = new List <planillarecaudoDTO>();

                    List <detallesplanilla> lDePla = PlaCtr.detallesplanilla.OrderBy(t => t.id).Where(t => t.idPlanillaControl == PlaCtr.id).ToList();

                    foreach (detallesplanilla dP in lDePla)
                    {
                        pR    = ctx.planillarecaudo.OrderBy(t => t.idDetallesPlanilla).Where(t => t.idDetallesPlanilla == dP.id).FirstOrDefault();
                        pRDto = new planillarecaudoDTO();

                        if (pR == null)
                        {
                            pR     = new planillarecaudo();
                            gastos = new gastos();
                            pR.idDetallesPlanilla = dP.id;
                            pR.Recorridos         = ctx.entradassalidas.Where(t => t.Fecha > fecha &&
                                                                              t.Fecha < fechaFin &&
                                                                              t.Placa == dP.PlacaBus && t.Estado == "E").Count();// Calcular el numero de Recorridos. Corregir
                            pR.Fecha = fecha;
                            ctx.planillarecaudo.Add(pR);
                            ctx.SaveChanges();

                            gastos.idplanillarecaudo = pR.id;
                            ctx.gastos.Add(gastos);
                            ctx.SaveChanges();

                            //pRaux=ctx.planillarecaudo.OrderByDescending(t=> t.detallesplanilla.id)
                            //    .Where(t=> t.detallesplanilla.id<pR.idDetallesPlanilla &&
                            //        t.detallesplanilla.PlacaBus==
                            //        (ctx.detallesplanilla.Where(y=>y.id==pR.idDetallesPlanilla).FirstOrDefault().PlacaBus))
                            //    .FirstOrDefault();
                            fecha2 = fecha.AddDays(-1);
                            pRaux  = ctx.planillarecaudo.Where(t => t.Fecha == fecha2 && t.detallesplanilla.PlacaBus == dP.PlacaBus).FirstOrDefault();

                            if (pRaux == null)
                            {
                                pR.InicioTorniquete = 0;
                            }
                            else
                            {
                                pR.InicioTorniquete = pRaux.FinTorniquete;
                            }

                            ctx.SaveChanges();
                        }

                        Mapper.Map(pR, pRDto);
                        pRDto.Time = dP.HoraSalida.ToString();
                        Mapper.Map(pR.gastos, pRDto.gastos);
                        lPlaRecDto.Add(pRDto);
                    }

                    return(lPlaRecDto);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 6
0
        public List <List <horarioDTO> > getHorarioPlanilla(string nomRuta, DateTime fecha, int grupo)
        {
            List <List <horarioDTO> > llHorDTO = new List <List <horarioDTO> >();
            List <horarioDTO>         lHorDTO  = new List <horarioDTO>();
            horarioDTO horDTO = new horarioDTO();
            TimeSpan   extra;
            int        cap = 0;

            using (ctx = new tvEntities()) {
                rutas           ruta = ctx.rutas.Where(t => t.NomRuta == nomRuta).FirstOrDefault();
                horario         Hor  = ctx.horario.Where(t => t.id == ruta.idHorario).FirstOrDefault();
                planillacontrol pC   = ctx.planillacontrol.Where(t => t.Fecha == fecha && t.Grupo == grupo).FirstOrDefault();
                cap = ctx.detallesplanilla.Where(t => t.Ruta == nomRuta && t.idPlanillaControl == pC.id).Count();

                if (ruta != null || Hor != null || pC != null || cap != 0)
                {
                    ruta.Capacidad = cap;/// capacidad del Bus

                    for (int i = 1; i <= ruta.NumeroRecorridos; i++)
                    {
                        createListaHor(ref lHorDTO, ruta, Hor);

                        if (nomRuta.ToUpper() != "RUTA 10B")
                        {
                            if (i % 2 == 0 && i != 1)
                            {
                                extra = new TimeSpan(0, 8, 0);
                            }
                            else
                            {
                                extra = new TimeSpan(0, 0, 0);
                            }
                        }
                        else
                        {
                            if (nomRuta.ToUpper() == "RUTA 8" || nomRuta.ToUpper() == "RUTA 12" || nomRuta.ToUpper() == "RUTA 10A")
                            {
                                if (i % 2 == 0 && i != 1)
                                {
                                    extra = new TimeSpan(0, 0, 0);
                                }
                                else
                                {
                                    extra = new TimeSpan(0, 8, 0);
                                }
                            }
                            else
                            {
                                extra = new TimeSpan(0, 0, 0);
                            }
                        }

                        Hor.hora = lHorDTO.ElementAt(0).hora + new TimeSpan(0, ruta.TiempoRecorrido.Value, 0) + extra;
                        llHorDTO.Add(lHorDTO);
                        lHorDTO = new List <horarioDTO>();
                    }

                    return(llHorDTO);
                }
                else
                {
                    return(null);
                }
            }
        }