예제 #1
0
        protected override System.Data.DataTable GetData(HttpContext context, String query, int rows, Structures.Languages lang)
        {
            Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(context.Application);
            String          iso     = Format.ToIso639_1(lang);

            query = query.ToLowerInvariant();
            int natDex = 0;

            Int32.TryParse(query, out natDex);
            int limit = 0;

            if (context.Request.QueryString["limit"] != null)
            {
                limit = Convert.ToInt32(context.Request.QueryString["limit"]);
                if (natDex > limit)
                {
                    return(null);
                }
            }

            Func <KeyValuePair <int, Species>, bool> filter;

            if (natDex > 0)
            {
                filter = pair => pair.Key == natDex;
            }
            else
            {
                filter = pair => pair.Key <= limit && pair.Value.Name[iso].ToLowerInvariant().Contains(query);
            }

            IEnumerable <Species> data;

            data = pokedex.Species.Where(filter).OrderBy(pair => pair.Key).Take(rows).Select(pair => pair.Value);

            DataTable dt = new DataTable();

            dt.Columns.Add("Text", typeof(String));
            dt.Columns.Add("Value", typeof(int));
            dt.Columns.Add("html", typeof(String));

            foreach (Species s in data)
            {
                String name = s.Name[iso];
                String html = "<img src=\"" + Common.ResolveUrl(WebFormat.SpeciesImageSmall(s)) +
                              "\" alt=\"" + Common.HtmlEncode(name) +
                              "\" class=\"sprite speciesSmall\" width=\"40px\" height=\"32px\" />" +
                              String.Format("{0} (#{1})",
                                            Common.HtmlEncode(name),
                                            s.NationalDex);

                dt.Rows.Add(name, s.NationalDex, html);
            }

            return(dt);
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(Application);
            PokemonParty4   pkmn    = null;

            if (Request.QueryString.Count == 0 || Request.QueryString.Count > 2)
            {
                throw new WebException(400);
            }
            if (Request.QueryString["offer"] != null ||
                Request.QueryString["exchange"] != null)
            {
                String generation = Request.QueryString["g"];
                if (generation == null ||
                    Request.QueryString.Count != 2)
                {
                    throw new WebException(400);
                }

                int  tradeId;
                bool isExchanged;

                if (Request.QueryString["offer"] != null)
                {
                    tradeId     = Convert.ToInt32(Request.QueryString["offer"]);
                    isExchanged = false;
                }
                else if (Request.QueryString["exchange"] != null)
                {
                    tradeId     = Convert.ToInt32(Request.QueryString["exchange"]);
                    isExchanged = true;
                }
                else
                {
                    AssertHelper.Unreachable();
                    throw new WebException(400);
                }

                // todo: when userprofiles are ready, add checks that they allow viewing their GTS history
                switch (generation)
                {
                case "4":
                {
                    GtsRecord4 record = Database.Instance.GtsGetRecord4(pokedex, tradeId, isExchanged, true);
                    if (record != null)
                    {
                        pkmn = new PokemonParty4(pokedex, record.Data.ToArray());
                    }
                } break;

                case "5":
                {
                    GtsRecord5 record = Database.Instance.GtsGetRecord5(pokedex, tradeId, isExchanged, true);
                    if (record != null)
                    {
                        pkmn = new PokemonParty4(pokedex, record.Data.ToArray());
                    }
                } break;

                default:
                    throw new WebException(400);
                }
            }
            else if (Request.QueryString["check"] != null)
            {
                int checkId = Convert.ToInt32(Request.QueryString["check"]);
                throw new NotImplementedException();
            }
            else
            {
                throw new WebException(400);
            }

            if (pkmn == null)
            {
                throw new WebException(403);
            }

            Bind(pkmn);
        }