Ejemplo n.º 1
0
        public static List<Users> getAccountUsers(Account acc)
        {
            SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandText = "getAccountusers";
            command.CommandType = System.Data.CommandType.StoredProcedure;

            command.Parameters.Add(new SqlParameter("accountID", acc.ID));
            command.Parameters.Add(new SqlParameter("owner", acc.AccountSignature));

            SqlDataAdapter da = new SqlDataAdapter(command);
            DataSet ds = new DataSet();

            conn.Open();
            da.Fill(ds);
            conn.Close();

            if (ds.Tables[0].Rows.Count == 0)
                return null;

            List<Users> returnValue = new List<Users>();
            Users pess;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                pess = new Users();
                pess.userID = Convert.ToInt32(dr["userID"]);
                pess.userName = Convert.ToString(dr["username"]);
                pess.Nome = Convert.IsDBNull(dr["Nome"]) ? null : Convert.ToString(dr["Nome"]);
                pess.NomesMeio = Convert.IsDBNull(dr["NomesMeio"]) ? null : Convert.ToString(dr["NomesMeio"]);
                pess.Apelido = Convert.IsDBNull(dr["Apelido"]) ? null : Convert.ToString(dr["Apelido"]);
                pess.email = Convert.IsDBNull(dr["email"]) ? null : Convert.ToString(dr["email"]);
                pess.sexo = Convert.IsDBNull(dr["sexo"]) ? null : Convert.ToString(dr["sexo"]);
                pess.owner = Convert.IsDBNull(dr["owner"]) ? null : Convert.ToString(dr["owner"]);
                pess.AccountID = Convert.ToInt32(dr["AccountID"]);
                pess.funcao = Convert.IsDBNull(dr["funcao"]) ? null : Convert.ToString(dr["funcao"]);
                pess.empresa = Convert.IsDBNull(dr["empresa"]) ? null : Convert.ToString(dr["empresa"]);
                pess.Demographics = Convert.IsDBNull(dr["Demographics"]) ? null : Convert.ToString(dr["Demographics"]);
                pess.self = Convert.IsDBNull(dr["self"]) ? null : Convert.ToString(dr["self"]);
                pess.importID = Convert.IsDBNull(dr["importID"]) ? null : Convert.ToString(dr["importID"]);
                pess.accNome = Convert.IsDBNull(dr["accNome"]) ? null : Convert.ToString(dr["accNome"]);
                pess.accPais = Convert.IsDBNull(dr["accPais"]) ? null : Convert.ToString(dr["accPais"]);
                pess.accPaisID = Convert.IsDBNull(dr["accPaisID"]) ? null : Convert.ToString(dr["accPaisID"]);
                pess.resetPassword = Convert.ToInt32(dr["resetPassword"]);

                returnValue.Add(pess);
            }
            return returnValue;
        }
Ejemplo n.º 2
0
        public static Users validateUser(String userName, String password)
        {
            Users theUser; ;
            SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandText = "validateUserExtended";
            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Parameters.AddWithValue("userName", userName);
            command.Parameters.Add(new SqlParameter("password", password));

            SqlDataReader reader;
            conn.Open();
            reader = command.ExecuteReader(CommandBehavior.SingleResult);
            if (reader.Read())
            {
                theUser = new Users();
                theUser.userID = reader.GetInt32(0);
                theUser.userName = reader.IsDBNull(1) ? "" : reader.GetString(1);
                theUser.pessoaID = reader.GetInt32(2);
                theUser.Nome = reader.IsDBNull(3) ? "" : reader.GetString(3);
                theUser.NomesMeio = reader.IsDBNull(4) ? "" : reader.GetString(4);
                theUser.Apelido = reader.IsDBNull(5) ? "" : reader.GetString(5);
                theUser.email = reader.IsDBNull(6) ? "" : reader.GetString(6);
                theUser.sexo = reader.IsDBNull(7) ? "" : reader.GetString(7);
                theUser.owner = reader.IsDBNull(8) ? "" : reader.GetString(8);
                theUser.importID = reader.IsDBNull(9) ? "" : reader.GetString(9);
                theUser.funcao = reader.IsDBNull(10) ? "" : reader.GetString(10);
                theUser.empresa =reader.IsDBNull(11) ? "" : reader.GetString(11);
                theUser.Demographics = reader.IsDBNull(13) ? "" : reader.GetString(13);
                theUser.self = reader.IsDBNull(14) ? "" : reader.GetString(14);
                theUser.signature = reader.IsDBNull(15) ? "" : reader.GetString(15);
                theUser.AccountID = reader.IsDBNull(16) ? -1 : reader.GetInt32(16);
                theUser.resetPassword = reader.GetInt32(17);
            }
            else
                return null;

            conn.Close();
            return theUser;
        }