using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace WebApplication1
{
///
/// Summary description for WebForm1.
///
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection conn;
private void Page_Load(object sender, System.EventArgs e)
{
// establishes a connection to the database
conn = new SqlConnection();
conn.ConnectionString = "server=(local); database=ranking;persist security info=False;user id=sa;Password=tiramesu; packet size=4096";
//retrieve all information from each table
SqlDataAdapter teamAdapter = new SqlDataAdapter("SELECT * FROM TEAMS",conn);
SqlDataAdapter scoreAdapter = new SqlDataAdapter("SELECT * FROM SCORES",conn);
results resultsTDS = new results();
teamAdapter.Fill (resultsTDS,"Teams");
scoreAdapter.Fill (resultsTDS,"Scores");
// iterate through each entry in the TEAM table and output information
// about each team
foreach (results.TeamsRow tr in resultsTDS.Teams)
{
// prints out the id of the team, its rank(position) and the region it's in
Response.Write(String.Format("TeamID: {0}, Name: {1},Position: {2}
", tr.TEAMID, tr.name, tr.IsdescriptionNull()? (short)-1 : tr.position));
// for each team look at its results in the scores table
foreach (results.ScoresRow wsr in tr.WeWonFrom())
{
// output the id of the result, the id of the team we're looking at
// and the id of the team that was beat
Response.Write (String.Format(" Wins: RecordID: {0}, selfID: {1},: TeamBeatID: {2}
",wsr.ID, wsr.winner_id, wsr.loser_id));
// for each team beat find it in the TEAM table
foreach (results.TeamsRow tq in resultsTDS.Teams)
{
if(tq.TEAMID == wsr.loser_id)
{
// check if the 2 teams are from the same region
if(tq.description == tr.description)
{
// calculate points
if(tq.position > 1 && tq.position <=5)
tr.points += 30;
if(tq.position > 5 && tq.position <=8)
tr.points += 25;
if(tq.position > 8 && tq.position <= 12)
tr.points += 20;
if(tq.position > 12 && tq.position <= 16)
tr.points += 15;
if(tq.position > 16 && tq.position <=20)
tr.points += 10;
if(tq.position > 20 && tq.position <=30)
tr.points += 5;
}
// if the teams are from different regions
else
{
if(tq.position >= 1 && tq.position <=5)
tr.points += 20;
if(tq.position > 5 && tq.position <=8)
tr.points += 12;
if(tq.position > 8 && tq.position <= 12)
tr.points += 8;
if(tq.position > 12 && tq.position <= 16)
tr.points += 6;
if(tq.position > 16 && tq.position <=20)
tr.points += 4;
if(tq.position > 20 && tq.position <=30)
tr.points += 2;
}
}
}
}
}
Response.Write("
");
// go through each team in the TEAM table
foreach (results.TeamsRow tr in resultsTDS.Teams)
{
// scale each team's score from region c2 by 1.3
// this is the regional strength constant which can
// be updated on a yearly basis
if(tr.description == "c2")
tr.points *=1.3;
// add 20 points to each team from region c1. this
// is the constant that accounts for the size difference
// between the regions
else
tr.points +=20;
// output each team's information and point value
Response.Write(String.Format("TeamID: {0}, Name: {1},Position: {2}
", tr.TEAMID, tr.name, tr.IsdescriptionNull()? (short)-1 : tr.position));
Response.Write (String.Format("Points: points: {0}
",tr.points));
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
//
// sqlConnection
//
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}