Ejemplo n.º 1
0
        public static List<Ocupado> VistaOcupadoT_Anestesista(String T_Anestesista, DateTime tiempo)
        {
            List<Ocupado> ocupado = new List<Ocupado>();
            int validar = Vistas.VistaAgenda().Where(a => a.Fk_Tanestesia.Ruttanestesista == T_Anestesista).Where(a => a.Fecha == tiempo || a.Fecha == tiempo.AddDays(-1)).Count();
            if (validar > 0)
            {
                DateTime prueba = tiempo.AddDays(-1);
                DateTime sumar = new DateTime();
                String[] horas = { "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00", "00:00" };

                while (prueba <= tiempo)
                {

                    for (int x = 0; x < horas.Length - 1; x++)
                    {

                        int das = Vistas.VistaAgenda().Where(a => a.Horainicio == horas[x]).Where(b => b.Fecha == prueba).Where(a => a.Fk_Tanestesia.Ruttanestesista == T_Anestesista).Count();

                        if (das == 0)
                        {
                            Ocupado oc = new Ocupado();
                            oc.Hora = horas[x] + "-" + horas[x + 1];
                            oc.Estado = "Libre";
                            oc.Fecha = prueba;
                            ocupado.Add(oc);

                        }
                        else
                        {
                            int duracion = Vistas.VistaAgenda().Where(a => a.Horainicio == horas[x]).Where(b => b.Fecha == prueba).Where(a => a.Fk_Tanestesia.Ruttanestesista == T_Anestesista).Select(a => a.Duracion).First();
                            for (int i = 0; i < duracion; i++)
                            {

                                if (x >= 24)
                                {
                                    if (x == 24)
                                    {
                                        sumar = prueba.AddDays(1);
                                        prueba = sumar;
                                        x = 0;
                                    }
                                    Ocupado oc = new Ocupado();
                                    oc.Hora = horas[x] + "-" + horas[x + 1];
                                    oc.Estado = "Ocupado";
                                    oc.Fecha = prueba;
                                    ocupado.Add(oc);
                                    x++;
                                }

                                else
                                {
                                    Ocupado oc = new Ocupado();
                                    oc.Hora = horas[x] + "-" + horas[x + 1]; ;
                                    oc.Estado = "Ocupado";
                                    oc.Fecha = prueba;
                                    ocupado.Add(oc);

                                    if (duracion != i + 1)    //Para que no hayan dos dt.Rows.Add seguidos
                                    {
                                        x++;
                                    }

                                }

                            }
                        }

                    }

                    sumar = prueba.AddDays(1);
                    prueba = sumar;
                }
            }
            else
            {
                String[] horas = { "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00", "00:00" };

                for (int x = 0; x < horas.Length - 1; x++)
                {

                    Ocupado oc = new Ocupado();
                    oc.Hora = horas[x] + "-" + horas[x + 1]; ;
                    oc.Estado = "Libre";
                    oc.Fecha = tiempo;
                    ocupado.Add(oc);

                }
            }

            return ocupado;
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            /* DateTime tiempo=new DateTime(2008,11,10);
             Console.WriteLine(tiempo.ToString("dd/MM/yyyy"));
             Console.ReadLine();
             TimeSpan hora = new TimeSpan(10,10,00);
             Console.WriteLine(hora.ToString("hh\\:mm"));
             Console.ReadLine();
             try
             {
                 //Insertar.InsertarAgenda(2, "31:12", "31:12", 232, "02/02/2015", "dasd", "dasd", "dasd", "dasd", "170812506", "1170812506", 1, "170812506", "890800", "170812506", "170812506", "170812506", "170812506");
                 Console.ReadLine();
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex);
                 Console.ReadLine();
             }
            */
            List<Ocupado> ocupado = new List<Ocupado>();
            DateTime nuevo = Vistas.VistaAgenda().Select(a => a.Fecha).Min();
            DateTime nuevo4 = Vistas.VistaAgenda().Select(a => a.Fecha).Max();
            DateTime sumar = new DateTime();
            String[] horas = { "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00" };

            while (nuevo <= nuevo4)
            {

                for (int x = 0; x < horas.Length; x++)
                {

                    int das = Vistas.VistaAgenda().Where(a => a.Horainicio == horas[x]).Where(b => b.Fecha == nuevo).Count();

                    if (das == 0)
                    {
                        Ocupado oc = new Ocupado();
                        oc.Hora = horas[x];
                        oc.Estado = "Libre";
                        oc.Fecha = nuevo;
                        ocupado.Add(oc);

                    }
                    else
                    {
                        int duracion = Vistas.VistaAgenda().Where(a => a.Horainicio == horas[x]).Where(b => b.Fecha == nuevo).Select(a => a.Duracion).First();
                        for (int i = 0; i < duracion; i++)
                        {

                            if (x >= 24)
                            {
                                if (x == 24)
                                {
                                    sumar = nuevo.AddDays(1);
                                    nuevo = sumar;
                                    x = 0;
                                }
                                Ocupado oc = new Ocupado();
                                oc.Hora = horas[x];
                                oc.Estado = "Ocupado";
                                oc.Fecha = nuevo;
                                ocupado.Add(oc);
                                x++;
                            }

                            else
                            {
                                Ocupado oc = new Ocupado();
                                oc.Hora = horas[x];
                                oc.Estado = "Ocupado";
                                oc.Fecha = nuevo;
                                ocupado.Add(oc);

                                if (duracion != i + 1)    //Para que no hayan dos dt.Rows.Add seguidos
                                {
                                    x++;
                                }

                            }

                        }
                    }

                }

                sumar = nuevo.AddDays(1);
                nuevo = sumar;
            }
            Console.WriteLine(ocupado.Count);
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public static bool Validar(int Cirugia, String pabellon, String horaInicio, DateTime tiempo, int durar)
        {
            String[] horas = { "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00", "00:00" };

            bool valido = true;
            List<Ocupado> ocupado = new List<Ocupado>();
            int validar = Vistas.VistaAgenda().Where(a => a.Fk_Especialidad.Idespecialidad == Cirugia).Where(a => a.Fk_Pabellon.Codigo == pabellon).Where(a => a.Fecha == tiempo || a.Fecha == tiempo.AddDays(-1)).Count();
            if (validar > 0)
            {

                DateTime prueba = tiempo.AddDays(-1);
                DateTime sumar = new DateTime();

                while (prueba <= tiempo)
                {

                    for (int x = 0; x < horas.Length - 1; x++)
                    {

                        int das = Vistas.VistaAgenda().Where(a => a.Horainicio == horas[x]).Where(b => b.Fecha == prueba).Count();

                        if (das != 0)
                        {
                            int duracion = Vistas.VistaAgenda().Where(a => a.Horainicio == horas[x]).Where(b => b.Fecha == prueba).Select(a => a.Duracion).First();
                            for (int i = 0; i < duracion; i++)
                            {

                                if (x >= 24)
                                {
                                    if (x == 24)
                                    {
                                        sumar = prueba.AddDays(1);
                                        prueba = sumar;
                                        x = 0;
                                    }
                                    if (horas[x] == horaInicio)
                                    {
                                        valido = false;
                                    }
                                }

                                else
                                {
                                    if (horas[x] == horaInicio)
                                    {
                                        valido = false;
                                    }

                                    if (duracion != i + 1)    //Para que no hayan dos dt.Rows.Add seguidos
                                    {
                                        x++;
                                    }

                                }

                            }
                        }

                    }

                    sumar = prueba.AddDays(1);
                    prueba = sumar;
                }
            }
            else
            {

                for (int x = 0; x < horas.Length - 1; x++)
                {

                    Ocupado oc = new Ocupado();
                    oc.Hora = horas[x] + "-" + horas[x + 1]; ;
                    oc.Estado = "Libre";
                    oc.Fecha = tiempo;
                    ocupado.Add(oc);

                }
            }

            return valido;
        }