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 Account getAccount(int ID, String owner)
        {
            SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandText = "getAccountID";
            command.CommandType = System.Data.CommandType.StoredProcedure;

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

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

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

            Account returnValue = new Account();

            returnValue.ID = Convert.ToInt32(ds.Tables[0].Rows[0]["ID"]);
            returnValue.Nome = Convert.ToString(ds.Tables[0].Rows[0]["Nome"]);
            returnValue.MoradaL1 = Convert.IsDBNull(ds.Tables[0].Rows[0]["MoradaL1"]) ? "" : Convert.ToString(ds.Tables[0].Rows[0]["MoradaL1"]);
            returnValue.MoradaL2 = Convert.IsDBNull(ds.Tables[0].Rows[0]["MoradaL2"]) ? "" : Convert.ToString(ds.Tables[0].Rows[0]["MoradaL2"]);
            returnValue.CodigoPostal = Convert.IsDBNull(ds.Tables[0].Rows[0]["CodigoPostal"]) ? "" : Convert.ToString(ds.Tables[0].Rows[0]["CodigoPostal"]);
            returnValue.Pais = Convert.IsDBNull(ds.Tables[0].Rows[0]["Pais"]) ? "" : Convert.ToString(ds.Tables[0].Rows[0]["Pais"]);
            returnValue.Nif = Convert.IsDBNull(ds.Tables[0].Rows[0]["Nif"]) ? "" : Convert.ToString(ds.Tables[0].Rows[0]["Nif"]);
            returnValue.Email = Convert.IsDBNull(ds.Tables[0].Rows[0]["Email"]) ? "" : Convert.ToString(ds.Tables[0].Rows[0]["Email"]);
            returnValue.AccountSignature = Convert.IsDBNull(ds.Tables[0].Rows[0]["AccountSignature"]) ? "" : Convert.ToString(ds.Tables[0].Rows[0]["AccountSignature"]);
            returnValue.Owner = Convert.IsDBNull(ds.Tables[0].Rows[0]["owner"]) ? "" : Convert.ToString(ds.Tables[0].Rows[0]["owner"]);
            returnValue.PaisID = Convert.IsDBNull(ds.Tables[0].Rows[0]["PaisID"]) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[0]["PaisID"]);
            returnValue.IdiomaID = Convert.IsDBNull(ds.Tables[0].Rows[0]["IdiomaID"]) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[0]["IdiomaID"]);
            returnValue.Idioma = Lang.getLang(returnValue.IdiomaID).Name;

            return returnValue;
        }
Ejemplo n.º 3
0
        public static List<Account> getAllAccounts(String owner)
        {
            SqlConnection conn = new SqlConnection(DBHelper.ConnectionString);
            SqlCommand command = new SqlCommand();
            command.Connection = conn;
            command.CommandText = "getAllAccounts";
            command.Parameters.Add(new SqlParameter("owner", owner));
            command.CommandType = System.Data.CommandType.StoredProcedure;

            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<Account> returnValue = new List<Account>();
            Account acc;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                acc = new Account();

                acc.ID = Convert.ToInt32(dr["ID"]);
                acc.Nome = Convert.ToString(dr["Nome"]);
                acc.MoradaL1 = Convert.IsDBNull(dr["MoradaL1"]) ? "" : Convert.ToString(dr["MoradaL1"]);
                acc.MoradaL2 = Convert.IsDBNull(dr["MoradaL2"]) ? "" : Convert.ToString(dr["MoradaL2"]);
                acc.CodigoPostal = Convert.IsDBNull(dr["CodigoPostal"]) ? "" : Convert.ToString(dr["CodigoPostal"]);
                acc.Pais = Convert.IsDBNull(dr["Pais"]) ? "" : Convert.ToString(dr["Pais"]);
                acc.Nif = Convert.IsDBNull(dr["Nif"]) ? "" : Convert.ToString(dr["Nif"]);
                acc.Email = Convert.IsDBNull(dr["Email"]) ? "" : Convert.ToString(dr["Email"]);
                acc.AccountSignature = Convert.IsDBNull(dr["AccountSignature"]) ? "" : Convert.ToString(dr["AccountSignature"]);
                acc.Owner = Convert.IsDBNull(dr["owner"]) ? "" : Convert.ToString(dr["owner"]);
                acc.PaisID = Convert.IsDBNull(dr["PaisID"]) ? -1 : Convert.ToInt32(dr["PaisID"]);
                acc.IdiomaID = Convert.IsDBNull(ds.Tables[0].Rows[0]["IdiomaID"]) ? -1 : Convert.ToInt32(ds.Tables[0].Rows[0]["IdiomaID"]);
                acc.Idioma = Lang.getLang(acc.IdiomaID).Name;

                returnValue.Add(acc);
            }
            return returnValue;
        }