Esempio n. 1
0
        public static Telefone SelectFromFornecedor(int i)
        {
            Telefone t = new Telefone();

            try
            {
                using (conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string     s = "SELECT * FROM TelefoneFornecedor WHERE Fornecedor_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.setCliente(i);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(t);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public static Telefone Select(int i)
        {
            Telefone t = new Telefone();

            try
            {
                using (conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string     s = "SELECT * FROM Telefone WHERE 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    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);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(t);
        }