public void getSalas() { List <Salas> listaSalas = new List <Salas>(); string cs = ConfigurationManager.ConnectionStrings["ConexaoSQLServer"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("SELECT * FROM Salas", con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Salas sl = new Salas(); sl.IdSala = Convert.ToInt32(dr["IdSala"]); sl.NomeSala = dr["NomeSala"].ToString(); listaSalas.Add(sl); } JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Write(js.Serialize(listaSalas)); } }
public void getAgendamentos() { List <Funcionarios> listaFuncionarios = new List <Funcionarios>(); string cs = ConfigurationManager.ConnectionStrings["ConexaoSQLServer"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("SELECT * FROM Funcionarios", con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Funcionarios func = new Funcionarios(); func.IdFuncionario = Convert.ToInt32(dr["IdFuncionario"]); func.Nome = dr["Nome"].ToString(); func.Setor = dr["Setor"].ToString(); func.Cargo = dr["Cargo"].ToString(); listaFuncionarios.Add(func); } } JavaScriptSerializer js = new JavaScriptSerializer(); Context.Response.Write(js.Serialize(listaFuncionarios)); List <Salas> listaSalas = new List <Salas>(); using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("SELECT * FROM Salas", con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Salas sl = new Salas(); sl.IdSala = Convert.ToInt32(dr["IdSala"]); sl.NomeSala = dr["NomeSala"].ToString(); listaSalas.Add(sl); } } Context.Response.Write(js.Serialize(listaSalas)); List <Periodos> listaPeriodos = new List <Periodos>(); using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("SELECT * FROM Periodos", con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Periodos pr = new Periodos(); pr.IdPeriodo = Convert.ToInt32(dr["IdPeriodo"]); pr.NomePeriodo = dr["NomePeriodo"].ToString(); listaPeriodos.Add(pr); } } Context.Response.Write(js.Serialize(listaPeriodos)); List <Reservas> listaReservas = new List <Reservas>(); using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand(@"SELECT R.DtReservada, R.DtDaReserva, S.NomeSala, P.NomePeriodo, F.Nome FROM dbo.Reservas R INNER JOIN Funcionarios F ON F.IdFuncionario = R.IdFuncionario INNER JOIN Salas S ON S.IdSala = R.IdSala INNER JOIN Periodos P ON P.IdPeriodo = R.IdPeriodo ORDER BY R.DtReservada, R.DtDaReserva, S.NomeSala, P.NomePeriodo, F.Nome", con); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Reservas rv = new Reservas(); rv.DtDaReserva = Convert.ToDateTime(dr["DtDaReserva"]); rv.DtReservada = Convert.ToDateTime(dr["DtReservada"]); rv.Funcionario = dr["Nome"].ToString(); rv.Periodo = dr["NomePeriodo"].ToString(); rv.Sala = dr["NomeSala"].ToString(); listaReservas.Add(rv); } } Context.Response.Write(js.Serialize(listaReservas)); }