public List<mdlTurno> BuscarTurnoE(String idDia, String idturno) { List<mdlTurno> resp = new List<mdlTurno>(); conexion.open(); string query = "select IdTurno, HoraInicio, HoraFin from TURNO where DesAlmCen=(select DesAlmCen from TURNO where IdTurno='"+idturno+"') and IdDia='"+idDia+"' and estado<>0"; // Create a SqlCommand object and pass the constructor the connection string and the query string. SqlCommand queryCommand = new SqlCommand(query, conexion.get()); // Use the above SqlCommand object to create a SqlDataReader object. SqlDataReader queryCommandReader = queryCommand.ExecuteReader(); // Create a DataTable object to hold all the data returned by the query. DataTable dataTable = new DataTable(); // Use the DataTable.Load(SqlDataReader) function to put the results of the query into a DataTable. dataTable.Load(queryCommandReader); foreach (DataRow item in dataTable.Rows) { mdlTurno turno = new mdlTurno(); turno.IdTurno = item[0].ToString(); turno.HoraInicio = DateTime.Parse(item[1].ToString()); turno.HoraFin = DateTime.Parse(item[2].ToString()); resp.Add(turno); } conexion.close(); return resp; }
private void Buscar_turno() { //buscar el turno actual... TimeSpan ts = DateTime.Now.TimeOfDay; foreach(mdlTurno turno in ListTurno ){ if (ts >= turno.HoraInicio.TimeOfDay && ts <= turno.HoraFin.TimeOfDay) { if (idturno != turno.IdTurno.ToString()) { ok = false; } else { ok = true; return; } mdlTurno turnoAc = new mdlTurno(); turnoAc.IdTurno = turno.IdTurno.ToString(); turnoAc.DesAlmCen = int.Parse(turno.DesAlmCen.ToString()); turnoAc.HoraInicio = turno.HoraInicio; turnoAc.HoraFin = turno.HoraFin; ListTurnoActual.Add(turnoAc); return; } else { ListTurnoActual.Clear(); ok = false; } } }