public static Telefone SelectFromFuncionario(int i) { Telefone t = new Telefone(); try { using (conn = new SqlConnection(connectionString)) { conn.Open(); string s = "SELECT * FROM Telefone WHERE Funcionario_id = @id"; SqlCommand c = new SqlCommand(s, conn); c.Parameters.Add("@id", SqlDbType.Int).Value = i; SqlDataReader d; using (d = c.ExecuteReader()) { if (d.HasRows) { while (d.Read()) { string n = d["telefone"].ToString(); int id = Convert.ToInt32(d["id"]); t = new Telefone(id, n); t.setFuncionario(i); } } } } } catch (Exception) { throw; } return(t); }
public static List <Telefone> SelectAll() { Telefone t; List <Telefone> ts = new List <Telefone>(); try { using (conn = new SqlConnection(connectionString)) { conn.Open(); string s = "SELECT * FROM Telefone"; SqlCommand c = new SqlCommand(s, conn); SqlDataReader d; using (d = c.ExecuteReader()) { if (d.HasRows) { while (d.Read()) { int i = Convert.ToInt32(d["id"]); string n = d["telefone"].ToString(); int idU = (d["Cliente_id"] != null) ? Convert.ToInt32(d["Cliente_id"]) : 0; int idF = (d["Funcionario_id"] != null) ? Convert.ToInt32(d["Funcionario_id"]) : 0; t = new Telefone(i, n); if (idU != 0) { t.setCliente(idU); } else { t.setFuncionario(idF); } ts.Add(t); } } } } } catch (Exception) { throw; } return(ts); }