예제 #1
0
        public static async Task <SpeciesZone[]> GetZonesAsync(long speciesId)
        {
            List <SpeciesZone> zones = new List <SpeciesZone>();

            using (SQLiteConnection conn = await Database.GetConnectionAsync())
                using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM SpeciesZones WHERE species_id = $species_id")) {
                    cmd.Parameters.AddWithValue("$species_id", speciesId);

                    using (DataTable rows = await Database.GetRowsAsync(conn, cmd))
                        foreach (DataRow row in rows.Rows)
                        {
                            Zone zone = await ZoneUtils.GetZoneAsync(row.Field <long>("zone_id"));

                            if (zone is null)
                            {
                                continue;
                            }

                            zones.Add(new SpeciesZone {
                                Zone      = zone,
                                Notes     = row.Field <string>("notes"),
                                Timestamp = row.IsNull("timestamp") ? 0 : row.Field <long>("timestamp")
                            });
                        }
                }

            zones.Sort((lhs, rhs) => new ArrayUtils.NaturalStringComparer().Compare(lhs.Zone.Name, rhs.Zone.Name));

            return(zones.ToArray());
        }
예제 #2
0
        // Public members

        public static async Task <Zone> GetZoneAsync(long zoneId)
        {
            using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Zones WHERE id = $zone_id")) {
                cmd.Parameters.AddWithValue("$zone_id", zoneId);

                DataRow row = await Database.GetRowAsync(cmd);

                if (!(row is null))
                {
                    return(ZoneUtils.ZoneFromDataRow(row));
                }
            }

            return(null);
        }
예제 #3
0
 public string GetFullName()
 {
     return(ZoneUtils.FormatZoneName(Name));
 }