Exemple #1
0
        public OutGetRegistrosHistorial GetRegistrosHistorial(InGetRegistrosHistorial Input)
        {
            //var response = new ResponseServices<List<MasterBue>>();

            var connectionString = ConfigurationManager.ConnectionStrings["AbcMedicalContext"].ConnectionString;
            var response         = new OutGetRegistrosHistorial();

            try
            {
                var conn = new MySqlConnection(connectionString);


                conn.Open();
                MySqlCommand command = new MySqlCommand();
                command.CommandTimeout = 0;
                command.Connection     = conn;

                var PI_PacienteId        = new MySqlParameter("_PacienteId", Input.PacienteId);
                var PI_RegistroClinicoId = new MySqlParameter("_registroClinicoId", Input.RegistroClinicoId);
                command.Parameters.Add(PI_PacienteId);
                command.Parameters.Add(PI_RegistroClinicoId);

                command.CommandText = "getRegistrosHistorial";
                command.CommandType = CommandType.StoredProcedure;

                MySqlDataReader datos = command.ExecuteReader();

                var list       = new List <RegistroHistorial>();
                int numeroFila = 0;
                while (datos.Read())
                {
                    if (numeroFila == 1)
                    {
                        numeroFila = 2;
                    }
                    else
                    {
                        numeroFila = 1;
                    }
                    var master = new RegistroHistorial
                    {
                        NumeroFila         = numeroFila,
                        RegistroHistoriaId = datos["RegistroHistoriaId"].ToString(),
                        Asunto             = datos["Asunto"].ToString(),
                        Fecha           = datos["Fecha"].ToString().Substring(0, 10),
                        Hora            = datos["Hora"].ToString(),
                        Profesional     = datos["Profesional"].ToString(),
                        RegistroClinico = datos["RegistroClinico"].ToString()
                    };
                    list.Add(master);
                }
                response.RegistrosHistorial = list.OrderByDescending(x => x.RegistroHistoriaId).ToList();
                response.State   = true;
                response.Message = "OK";
                datos.Close();
                command.Dispose();
                conn.Dispose();
            }
            catch (Exception ex)
            {
                response.State   = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Exemple #2
0
        //POST: odata/Autos/ActualizarVelocidadLista
        //Parametros: Id,Registros
        //(FechaHora,Valor)
        public string ActualizarVelocidadListaDX(ODataActionParameters parameters)
        {
            if (parameters == null)
            {
                return("Error");
            }

            try
            {
                int size = 10;

                int id        = (int)parameters["Id"];
                var registros = parameters["Registros"] as IEnumerable <RegistroHistorial>;
                List <RegistroHistorial> listaRegistros = registros.ToList();

                if (listaRegistros.Count == 1)
                {
                    return("Ok");
                }

                //SE CREAN GRUPOS DE 10 EN 10 O DEPENDE DE "size"
                List <List <RegistroHistorial> > gruposDeRegistros = new List <List <RegistroHistorial> >();

                for (int i = 0; i < listaRegistros.Count; i += size)
                {
                    gruposDeRegistros.Add(listaRegistros.GetRange(i, Math.Min(size, listaRegistros.Count - i)));
                }


                Auto auto = db.Autos.Where(a => a.Id == id).FirstOrDefault();
                if (auto == null)
                {
                    return("Error");
                }


                List <HistorialVelocidad> historialesVelocidadCreados = new List <HistorialVelocidad>();

                //SE RECORREN LOS GRUPOS Y SE CREA UN HISTORIAL VELOCIDAD POR CADA UNO,
                //Se agrega a la lista

                for (int r = 0; r < gruposDeRegistros.Count; r++)
                {
                    List <RegistroHistorial> grupoActual = gruposDeRegistros[r];

                    for (int i = 0; i < grupoActual.Count; i++)
                    {
                        //Se recorren los registros y se le asigna la fecha correspondiente

                        string   horaRegistroString = grupoActual[i].FechaHora;
                        DateTime horaRegistro;
                        bool     result = DateTime.TryParseExact(horaRegistroString,
                                                                 FormatoFecha.formato, FormatoFecha.provider, DateTimeStyles.None, out horaRegistro);

                        if (result == false)
                        {
                            return("Error");
                        }

                        grupoActual[i].FechaDateTime = horaRegistro;
                    }

                    grupoActual = grupoActual.OrderBy(u => u.FechaDateTime).ToList();

                    RegistroHistorial registroInicio   = grupoActual.First();
                    RegistroHistorial registroFinal    = grupoActual.Last();
                    RegistroHistorial registro1Cuarto  = null;
                    RegistroHistorial registroMitad    = null;
                    RegistroHistorial registro3Cuartos = null;
                    RegistroHistorial registroMayor    = null;
                    RegistroHistorial registrosMenor   = null;

                    float valorMayor    = 0;
                    float valorMenor    = float.MaxValue;
                    float valor1Cuarto  = (grupoActual.Count / 4);
                    float valorMitad    = (grupoActual.Count / 2);
                    float valor3Cuartos = (grupoActual.Count / 4) * 3;


                    for (int i = 0; i < grupoActual.Count; i++)
                    {
                        RegistroHistorial regActual = grupoActual[i];

                        if (regActual.Valor >= valorMayor)
                        {
                            registroMayor = regActual;
                            valorMayor    = regActual.Valor;
                        }

                        if (regActual.Valor <= valorMenor)
                        {
                            registrosMenor = regActual;
                            valorMenor     = regActual.Valor;
                        }

                        if (registro1Cuarto == null && i >= valor1Cuarto)
                        {
                            registro1Cuarto = regActual;
                        }

                        if (registroMitad == null && i >= valorMitad)
                        {
                            registroMitad = regActual;
                        }

                        if (registro3Cuartos == null && i >= valor3Cuartos)
                        {
                            registro3Cuartos = regActual;
                        }
                    }

                    HistorialVelocidad nuevoHistorial = new HistorialVelocidad();
                    nuevoHistorial.HoraRegistro    = DateTime.Now;
                    nuevoHistorial.HoraInicio      = registroInicio.FechaDateTime;
                    nuevoHistorial.HoraFinal       = registroFinal.FechaDateTime;
                    nuevoHistorial.HoraMenor       = registrosMenor.FechaDateTime;
                    nuevoHistorial.HoraMayor       = registroMayor.FechaDateTime;
                    nuevoHistorial.HoraMitad       = registroMitad.FechaDateTime;
                    nuevoHistorial.HoraUnCuarto    = registro1Cuarto.FechaDateTime;
                    nuevoHistorial.HoraTresCuartos = registro3Cuartos.FechaDateTime;

                    nuevoHistorial.ValorInicio      = registroInicio.Valor;
                    nuevoHistorial.ValorFinal       = registroFinal.Valor;
                    nuevoHistorial.ValorMayor       = registroMayor.Valor;
                    nuevoHistorial.ValorMenor       = registrosMenor.Valor;
                    nuevoHistorial.ValorMitad       = registroMitad.Valor;
                    nuevoHistorial.ValorUnCuarto    = registro1Cuarto.Valor;
                    nuevoHistorial.ValorTresCuartos = registro3Cuartos.Valor;

                    historialesVelocidadCreados.Add(nuevoHistorial);
                }


                List <HistorialDiario> HistDiarioEnRango = CrearHistorialesDiariosEnRango(historialesVelocidadCreados.First().HoraInicio, historialesVelocidadCreados.Last().HoraFinal, auto);


                //Se registran en la base de datos los historiales creados
                for (int i = 0; i < historialesVelocidadCreados.Count; i++)
                {
                    HistorialDiario histCorrespondiente = HistDiarioEnRango.Where(h => h.Fecha.Year == historialesVelocidadCreados[i].HoraMitad.Year &&
                                                                                  h.Fecha.Month == historialesVelocidadCreados[i].HoraMitad.Month &&
                                                                                  h.Fecha.Day == historialesVelocidadCreados[i].HoraMitad.Day).FirstOrDefault();

                    histCorrespondiente.historialesVelocidad.Add(historialesVelocidadCreados[i]);
                }


                db.SaveChanges();

                return("Ok");
            }
            catch
            {
                return("CatchWebService");
            }
        }