Made AllPokemon page, some beautification

This commit is contained in:
Greg Edwards 2014-05-05 03:26:10 -04:00
parent a6353bc2be
commit e3268208d2
10 changed files with 304 additions and 19 deletions

62
gts/AllPokemon.aspx Normal file
View File

@ -0,0 +1,62 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeBehind="AllPokemon.aspx.cs" Inherits="PkmnFoundations.GTS.AllPokemon" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cpHead" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMain" runat="server">
<h1>Generation IV</h1>
<asp:Repeater ID="rptPokemon4" runat="server">
<HeaderTemplate>
<table>
<thead>
<td>Offer</td>
<td>Wanted</td>
<td>Trainer</td>
</thead>
</HeaderTemplate>
<ItemTemplate>
<td><%# CreateOffer4(Container.DataItem) %></td>
<td><%# CreateWanted4(Container.DataItem) %></td>
<td><%# CreateTrainer4(Container.DataItem) %></td>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<h1>Generation V</h1>
<asp:Repeater ID="rptPokemon5" runat="server">
<HeaderTemplate>
<table>
<thead>
<td>Offer</td>
<td>Wanted</td>
<td>Trainer</td>
</thead>
</HeaderTemplate>
<ItemTemplate>
<td><%# CreateOffer5(Container.DataItem) %></td>
<td><%# CreateWanted5(Container.DataItem) %></td>
<td><%# CreateTrainer5(Container.DataItem) %></td>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Content>

82
gts/AllPokemon.aspx.cs Normal file
View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PkmnFoundations.Data;
using PkmnFoundations.Structures;
namespace PkmnFoundations.GTS
{
public partial class AllPokemon : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GtsRecord4[] records4 = DataAbstract.Instance.GtsSearch4(0, 0, Genders.Either, 0, 0, 0, -1);
rptPokemon4.DataSource = records4;
rptPokemon4.DataBind();
GtsRecord5[] records5 = DataAbstract.Instance.GtsSearch5(0, 0, Genders.Either, 0, 0, 0, -1);
rptPokemon5.DataSource = records5;
rptPokemon5.DataBind();
}
private String FormatLevels(byte min, byte max)
{
if (min == 0 && max == 0)
{
return "Any";
}
else if (min == 0)
{
return String.Format("{0} and under", max);
}
else if (max == 0)
{
return String.Format("{0} and up", min);
}
else
{
return String.Format("{0} to {1}", min, max);
}
}
protected String CreateOffer4(object DataItem)
{
GtsRecord4 record = (GtsRecord4)DataItem;
return String.Format("Species: {0}<br />Gender: {1}<br />Level: {2}", record.Species, record.Gender, record.Level);
}
protected String CreateWanted4(object DataItem)
{
GtsRecord4 record = (GtsRecord4)DataItem;
return String.Format("Species: {0}<br />Gender: {1}<br />Level: {2}", record.RequestedSpecies, record.RequestedGender, FormatLevels(record.RequestedMinLevel, record.RequestedMaxLevel));
}
protected String CreateTrainer4(object DataItem)
{
return "Trainer";
}
protected String CreateOffer5(object DataItem)
{
GtsRecord5 record = (GtsRecord5)DataItem;
return String.Format("Species: {0}<br />Gender: {1}<br />Level: {2}", record.Species, record.Gender, record.Level);
}
protected String CreateWanted5(object DataItem)
{
GtsRecord5 record = (GtsRecord5)DataItem;
return String.Format("Species: {0}<br />Gender: {1}<br />Level: {2}", record.RequestedSpecies, record.RequestedGender, FormatLevels(record.RequestedMinLevel, record.RequestedMaxLevel));
}
protected String CreateTrainer5(object DataItem)
{
return "Trainer";
}
}
}

33
gts/AllPokemon.aspx.designer.cs generated Normal file
View File

@ -0,0 +1,33 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PkmnFoundations.GTS {
public partial class AllPokemon {
/// <summary>
/// rptPokemon4 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Repeater rptPokemon4;
/// <summary>
/// rptPokemon5 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Repeater rptPokemon5;
}
}

View File

@ -11,13 +11,21 @@
<body>
<div id="gtsHeader">
<div class="setWidth">
<h1>Foundations GTS</h1>
<p>Fan-operated GTS for Pokémon generations IV and V, by mm201</p>
<h1>
<asp:HyperLink ID="hlHome" NavigateUrl="~/" runat="server">Foundations GTS</asp:HyperLink>
</h1>
<p>Fan-operated GTS for Pokémon Generations IV and V, by mm201</p>
<div class="right">
<div class="dns">
<div class="dnsHeading">DNS server:</div>
<div class="dnsIp">191.236.98.208</div>
</div>
<div class="stats">
<asp:Literal ID="litPokemon" runat="server" />
Pokémon available for offer.<br />
<asp:HyperLink ID="hlAllPokemon" NavigateUrl="~/AllPokemon.aspx" runat="server">Details</asp:HyperLink>
</div>
</div>
</div>
<div class="github-contain">
<a class="github" href="https://github.com/mm201/pkmnFoundations" target="_blank">Fork me on GitHub!</a>

View File

@ -21,6 +21,15 @@ namespace PkmnFoundations.GTS {
/// </remarks>
protected global::System.Web.UI.WebControls.ContentPlaceHolder cpHead;
/// <summary>
/// hlHome control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.HyperLink hlHome;
/// <summary>
/// litPokemon control.
/// </summary>

View File

@ -2,6 +2,7 @@
{
font-family: Arial,sans-serif;
margin: 0; padding: 0;
min-width: 720px;
}
#gtsHeader
@ -9,8 +10,42 @@
background-color: #ff8063;
color: white;
font-family: Arial,sans-serif;
padding: 4px 0;
height: 120px;
padding: 20px 0 4px;
height: 108px;
}
#gtsHeader h1
{
margin: 0;
}
#gtsHeader h1 a
{
text-decoration: none;
}
#gtsHeader .dns
{
margin-bottom: 8px;
}
#gtsHeader .dnsHeading
{
font-size: 9px;
}
#gtsHeader .dnsIp
{
font-family: Consolas,'Andale Mono',monospace;
font-size: 20px;
font-weight: bold;
}
#gtsHeader .right
{
position: absolute;
top: 0;
right: 0;
}
#gtsHeader .stats
@ -18,9 +53,6 @@
background-color: #ffac9f;
border-radius: 9px;
padding: 4px;
position: absolute;
top: 8px;
right: 160px;
width: 200px;
font-size: 12px;
}
@ -39,6 +71,7 @@
{
width: 720px;
margin: 0 auto;
position: relative;
}
.github-contain
@ -70,3 +103,17 @@
font-family: Consolas,'Andale Mono',monospace
}
table
{
width: 100%;
}
thead
{
background-color: #dddddd;
}
table tr:nth-child(2n)
{
background-color: #eeeeee;
}

View File

@ -55,6 +55,7 @@
<Reference Include="System.Web.ApplicationServices" />
</ItemGroup>
<ItemGroup>
<Content Include="AllPokemon.aspx" />
<Content Include="css\main.css" />
<Content Include="Default.aspx" />
<Content Include="Global.asax" />
@ -67,6 +68,13 @@
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="AllPokemon.aspx.cs">
<DependentUpon>AllPokemon.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="AllPokemon.aspx.designer.cs">
<DependentUpon>AllPokemon.aspx</DependentUpon>
</Compile>
<Compile Include="syachi2ds.ashx.cs">
<DependentUpon>syachi2ds.ashx</DependentUpon>
</Compile>

View File

@ -329,10 +329,16 @@ namespace PkmnFoundations.GTS
return;
}
ushort species = BitConverter.ToUInt16(data, 4);
if (species < 1)
{
Error400(context);
return;
}
int resultsCount = (int)data[10];
if (resultsCount < 1) break; // optimize away requests for no rows
ushort species = BitConverter.ToUInt16(data, 4);
Genders gender = (Genders)data[6];
byte minLevel = data[7];
byte maxLevel = data[8];

View File

@ -336,11 +336,17 @@ namespace PkmnFoundations.GTS
int resultsCount = (int)data[14];
ushort species = BitConverter.ToUInt16(data, 8);
if (species < 1)
{
Error400(context);
return;
}
response.Write(new byte[] { 0x01, 0x00 }, 0, 2);
if (resultsCount < 1) break; // optimize away requests for no rows
ushort species = BitConverter.ToUInt16(data, 8);
Genders gender = (Genders)data[10];
byte minLevel = data[11];
byte maxLevel = data[12];

View File

@ -208,9 +208,14 @@ namespace PkmnFoundations.Data
using (MySqlConnection db = CreateConnection())
{
List<MySqlParameter> _params = new List<MySqlParameter>();
String where = "WHERE pid != @pid AND Species = @species";
String where = "WHERE pid != @pid";
_params.Add(new MySqlParameter("@pid", pid));
_params.Add(new MySqlParameter("@species", species));
if (species > 0)
{
where += " AND Species = @species";
_params.Add(new MySqlParameter("@species", species));
}
if (gender != Genders.Either)
{
@ -241,7 +246,12 @@ namespace PkmnFoundations.Data
_params.Add(new MySqlParameter("@country", country));
}
_params.Add(new MySqlParameter("@count", count));
String limit = "";
if (count > 0)
{
_params.Add(new MySqlParameter("@count", count));
limit = " LIMIT @count";
}
db.Open();
// todo: sort me in creative ways
@ -250,10 +260,12 @@ namespace PkmnFoundations.Data
"Unknown1, TrainerGender, Unknown2, TimeDeposited, TimeWithdrawn, pid, " +
"TrainerName, TrainerOT, TrainerCountry, TrainerRegion, TrainerClass, " +
"IsExchanged, TrainerVersion, TrainerLanguage FROM GtsPokemon4 " + where +
" ORDER BY TimeDeposited DESC LIMIT @count",
" ORDER BY TimeDeposited DESC" + limit,
_params.ToArray());
List<GtsRecord4> records = new List<GtsRecord4>(count);
List<GtsRecord4> records;
if (count > 0) records = new List<GtsRecord4>(count);
else records = new List<GtsRecord4>();
while (reader.Read())
{
@ -524,9 +536,14 @@ namespace PkmnFoundations.Data
using (MySqlConnection db = CreateConnection())
{
List<MySqlParameter> _params = new List<MySqlParameter>();
String where = "WHERE pid != @pid AND Species = @species";
String where = "WHERE pid != @pid";
_params.Add(new MySqlParameter("@pid", pid));
_params.Add(new MySqlParameter("@species", species));
if (species > 0)
{
where += " AND Species = @species";
_params.Add(new MySqlParameter("@species", species));
}
if (gender != Genders.Either)
{
@ -557,7 +574,12 @@ namespace PkmnFoundations.Data
_params.Add(new MySqlParameter("@country", country));
}
_params.Add(new MySqlParameter("@count", count));
String limit = "";
if (count > 0)
{
_params.Add(new MySqlParameter("@count", count));
limit = " LIMIT @count";
}
db.Open();
// todo: sort me in creative ways
@ -568,10 +590,12 @@ namespace PkmnFoundations.Data
"TrainerOT, TrainerName, TrainerCountry, TrainerRegion, TrainerClass, " +
"IsExchanged, TrainerVersion, TrainerLanguage, TrainerBadges, TrainerUnityTower " +
"FROM GtsPokemon5 " + where +
" ORDER BY TimeDeposited DESC LIMIT @count",
" ORDER BY TimeDeposited DESC" + limit,
_params.ToArray());
List<GtsRecord5> records = new List<GtsRecord5>(count);
List<GtsRecord5> records;
if (count > 0) records = new List<GtsRecord5>(count);
else records = new List<GtsRecord5>();
while (reader.Read())
{