Ejemplo n.º 1
0
        public static List <Funcionario> SelectAll()
        {
            Funcionario        c;
            List <Funcionario> cs = new List <Funcionario>();

            try
            {
                using (conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string        s   = "SELECT * FROM Funcionario";
                    SqlCommand    cmd = new SqlCommand(s, conn);
                    SqlDataReader d;
                    using (d = cmd.ExecuteReader())
                    {
                        if (d.HasRows)
                        {
                            while (d.Read())
                            {
                                int      i   = Convert.ToInt32(d["id"]);
                                string   n   = d["Nome"].ToString();
                                string   rg  = d["Identidade"].ToString();
                                string   clt = d["CLT"].ToString();
                                string   obs = d["Observacao"].ToString();
                                bool     m   = Convert.ToBoolean(d["Motorista"]);
                                bool     t   = Convert.ToBoolean(d["Tecnico"]);
                                double   sal = Convert.ToDouble(d["Salario"]);
                                Endereco end = DALEndereco.SelectFromFuncionario(i);
                                Telefone tel = DALTelefone.SelectFromFuncionario(i);
                                c = new Funcionario(i, n, m, t, rg, clt, sal, obs, end, tel);
                                cs.Add(c);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(cs);
        }
Ejemplo n.º 2
0
        public static Funcionario Select(int i)
        {
            Funcionario c = new Funcionario();

            try
            {
                using (conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string     s   = "SELECT * FROM Funcionario WHERE id = @id";
                    SqlCommand cmd = new SqlCommand(s, conn);
                    cmd.Parameters.Add("@id", SqlDbType.Int).Value = i;
                    SqlDataReader d;
                    using (d = cmd.ExecuteReader())
                    {
                        if (d.HasRows)
                        {
                            while (d.Read())
                            {
                                string   n   = d["Nome"].ToString();
                                string   rg  = d["Identidade"].ToString();
                                string   clt = d["CLT"].ToString();
                                string   obs = d["Observacao"].ToString();
                                bool     m   = Convert.ToBoolean(d["Motorista"]);
                                bool     t   = Convert.ToBoolean(d["Tecnico"]);
                                double   sal = Convert.ToDouble(d["Salario"]);
                                Endereco end = DALEndereco.SelectFromFuncionario(i);
                                Telefone tel = DALTelefone.SelectFromFuncionario(i);
                                c = new Funcionario(i, n, m, t, rg, clt, sal, obs, end, tel);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(c);
        }