I have a DB in which looks like this:
Game
----------------
WinningID (FK)
LoosingID (FK)
Score
Player
----------------
ID (PK)
Name
Rank
Country
My Game Table contains score of Players wins against each other. So Winnind开发者_JAVA技巧ID (Player1) Vs. LoosingID (Player2) has a score of 4.
That being said. I am creating a web page in which I have to show the score. I populated ListBoxes with the Player Names and have two labels to show the score.
- Label 1: Showing Player1 as opponent and won.
- Label 2: Showing Player2 as opponent and won.
I don't know where to start :( Can anyone give me some gist? Thanks in adv!
Without writing all the code for you, here's the general idea. Once you've started your development and need further assistance, come back and post specific questions.
This is a simplistic approach with all the logic, data and UI contained in the same project/web page. Depending on the size of your application, you'll want to create a project specifically for your data access (typically known as the DAL - data access layer). And as time goes by, you'll likely want to start using the MVC framework.
Essentially:
- Create a method to retreive all the players from the DB:
string GetPlayers(){...}
- Use the GetPlayers() method to set the DataSource of your ListBox when the page loads.
- Create an event handler on your ListBox for the SelectedIndexChanged Event.
- When the SelectedIndexChanged Event is fired:
- query the DB to retrieve the Player selected. The query will Join the Player.ID that was selected in the ListBox with Game.WinningID and then join the Game.LoosingID to Player.ID to find the loosing player.
- Set the value of Label 1's text property to the Name of the winner.
- Set the value of Lable 2's text proeprty to the Name of the looser.
Your scenario doesn't quite make sense if a player can have multiple games. If a player can have multiple games, then when the SelectedIndexChanged event is fired, you'll be retrieving several records from the DB. This means you'll have to create a repeating section on your page to show all the games the player won along with who lost.
My suggestion would be to start writing up your code and see if you can get something running. When you run into a stumbling block, search around the web and see if you can find some solutions. When you are out of ideas, come on back to SO and post your specific question.
精彩评论