Exemplo n.º 1
0
        public SpeciesData(SpeciesData species)
        {
            species_id = species.species_id;
            name = species.name;
            description = species.description;
            biomass = species.biomass;
            diet_type = species.diet_type;
            trophic_level = species.trophic_level;

            predatorList = new Dictionary<int, string>();
            foreach (KeyValuePair<int, string> predator in species.predatorList) {
                predatorList.Add(predator.Key, predator.Value);
            }

            preyList = new Dictionary<int, string>();
            foreach (KeyValuePair<int, string> prey in species.preyList) {
                preyList.Add(prey.Key, prey.Value);
            }

            categoryList = new string[0];

            image = species.image;
        }
Exemplo n.º 2
0
        public static void initialize()
        {
            SqliteConnection con = new SqliteConnection("URI=file:" + Application.dataPath + "/Database/WoB_DB.db");
            con.Open();

            SqliteCommand cmd = new SqliteCommand(con);
            cmd.CommandText = "" +
                "SELECT *" +
                " FROM `species`";

            cmd.Prepare();
            cmd.ExecuteNonQuery();

            SqliteDataReader reader = cmd.ExecuteReader();

            while (reader.Read()) {
                int species_id = reader.GetInt32(0);

                SpeciesData species = new SpeciesData(species_id);
                species.name = reader.GetString(1);
                species.description = reader.GetString(2);
                species.biomass = reader.GetInt32(3);
                species.diet_type = reader.GetInt16(4);
                species.trophic_level = reader.GetFloat(5);

                SqliteCommand subcmd = new SqliteCommand(con);
                subcmd.CommandText = "" +
                    "SELECT `predator_id`" +
                    " FROM `pp_relations`" +
                    " WHERE `prey_id` = @species_id";
                subcmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

                subcmd.Prepare();
                subcmd.ExecuteNonQuery();
                SqliteDataReader subreader = subcmd.ExecuteReader();

                while (subreader.Read()) {
                    int predator_id = subreader.GetInt32(0);

                    if (!species.predatorList.ContainsKey(predator_id)) {
                        species.predatorList.Add(predator_id, "");
                    }
                }

                subcmd = new SqliteCommand(con);
                subcmd.CommandText = "" +
                    "SELECT `prey_id`" +
                    " FROM `pp_relations`" +
                    " WHERE `predator_id` = @species_id";
                subcmd.Parameters.Add(new SqliteParameter("@species_id", species.species_id));

                subcmd.Prepare();
                subcmd.ExecuteNonQuery();
                subreader = subcmd.ExecuteReader();

                while (subreader.Read()) {
                    int prey_id = subreader.GetInt32(0);

                    if (!species.preyList.ContainsKey(prey_id)) {
                        species.preyList.Add(subreader.GetInt32(0), "");
                    }
                }

                speciesList.Add(species.species_id, species);
            }

            foreach (SpeciesData species in speciesList.Values) {
                foreach (int predator_id in new List<int>(species.predatorList.Keys)) {
                    if (SpeciesTable.speciesList.ContainsKey(predator_id)) {
                        species.predatorList[predator_id] = SpeciesTable.speciesList[predator_id].name;
                    } else {
                        species.predatorList.Remove(predator_id);
                    }
                }

                foreach (int prey_id in new List<int>(species.preyList.Keys)) {
                    if (SpeciesTable.speciesList.ContainsKey(prey_id)) {
                        species.preyList[prey_id] = SpeciesTable.speciesList[prey_id].name;
                    } else {
                        species.preyList.Remove(prey_id);
                    }
                }
            }

            reader.Close();
            con.Close();
        }