Tournament Dashboard fixed, started to wire up tournamentviewer form
This commit is contained in:
@ -13,5 +13,6 @@ namespace TrackerLibrary.DataAccess
|
||||
void CreateTournament(TournamentModel model);
|
||||
List<TeamModel> GetTeam_All();
|
||||
List<PersonModel> GetPerson_All();
|
||||
List<TournamentModel> GetTournament_All();
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ namespace TrackerLibrary.DataAccess
|
||||
SaveTournamentEntries(model, connection);
|
||||
|
||||
SaveTournamentRounds(model, connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveTournament(TournamentModel model, IDbConnection connection)
|
||||
@ -157,7 +157,7 @@ namespace TrackerLibrary.DataAccess
|
||||
|
||||
p = new DynamicParameters();
|
||||
p.Add("@MatchupId", matchup.Id);
|
||||
if(entry.ParentMatchup == null)
|
||||
if (entry.ParentMatchup == null)
|
||||
{
|
||||
p.Add("@ParentMatchupId", null);
|
||||
}
|
||||
@ -185,7 +185,7 @@ namespace TrackerLibrary.DataAccess
|
||||
|
||||
}
|
||||
|
||||
private static void SaveTournamentPrizes(TournamentModel model, IDbConnection connection)
|
||||
private static void SaveTournamentPrizes(TournamentModel model, IDbConnection connection)
|
||||
{
|
||||
foreach (PrizeModel pz in model.Prizes)
|
||||
{
|
||||
@ -226,5 +226,75 @@ namespace TrackerLibrary.DataAccess
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public List<TournamentModel> GetTournament_All()
|
||||
{
|
||||
List<TournamentModel> output;
|
||||
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
|
||||
{
|
||||
output = connection.Query<TournamentModel>("dbo.spTournaments_GetAll").ToList();
|
||||
var p = new DynamicParameters();
|
||||
foreach (TournamentModel t in output)
|
||||
{
|
||||
// Populate prizes
|
||||
p.Add("@TournamentId", t.Id);
|
||||
t.Prizes = connection.Query<PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
|
||||
// Populate Teams
|
||||
t.EnteredTeams = connection.Query<TeamModel>("dbo.spTeam_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
|
||||
foreach (TeamModel team in t.EnteredTeams)
|
||||
{
|
||||
p = new DynamicParameters();
|
||||
p.Add("@TeamId", team.Id);
|
||||
team.TeamMembers = connection.Query<PersonModel>("dbo.spTeamMembers_GetByTeam", p, commandType: CommandType.StoredProcedure).ToList();
|
||||
}
|
||||
// Populate Rounds
|
||||
p = new DynamicParameters();
|
||||
p.Add("@TournamentId", t.Id);
|
||||
List<MatchupModel> matchups = connection.Query<MatchupModel>("dbo.spMatchups_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
|
||||
foreach (MatchupModel m in matchups)
|
||||
{
|
||||
p = new DynamicParameters();
|
||||
p.Add("@MatchupId", m.Id);
|
||||
m.Entries = connection.Query<MatchupEntryModel>("dbo.spMatchupEntries_GetByMatchup", p, commandType: CommandType.StoredProcedure).ToList();
|
||||
|
||||
List<TeamModel> allTeams = GetTeam_All();
|
||||
|
||||
if (m.WinnerId > 0)
|
||||
{
|
||||
m.Winner = allTeams.Where(x => x.Id == m.WinnerId).First();
|
||||
}
|
||||
|
||||
foreach (var me in m.Entries)
|
||||
{
|
||||
if (me.TeamCompetingId > 0)
|
||||
{
|
||||
me.TeamCompeting = allTeams.Where(x => x.Id == me.TeamCompetingId).First();
|
||||
}
|
||||
if (me.ParentMatchupId > 0)
|
||||
{
|
||||
me.ParentMatchup = matchups.Where(x => x.Id == me.ParentMatchupId).First();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// List<List<MatchupModel>>
|
||||
List<MatchupModel> currRow = new List<MatchupModel>();
|
||||
int currRound = 1;
|
||||
foreach (MatchupModel m in matchups)
|
||||
{
|
||||
if(m.MatchupRound > currRound)
|
||||
{
|
||||
t.Rounds.Add(currRow);
|
||||
currRow = new List<MatchupModel>();
|
||||
currRound += 1;
|
||||
}
|
||||
currRow.Add(m);
|
||||
}
|
||||
|
||||
t.Rounds.Add(currRow);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,5 +124,12 @@ namespace TrackerLibrary.DataAccess
|
||||
tournaments.SaveToTournamentFile(TournamentFile);
|
||||
}
|
||||
|
||||
public List<TournamentModel> GetTournament_All()
|
||||
{
|
||||
return TournamentFile
|
||||
.FullFilePath()
|
||||
.LoadFile()
|
||||
.ConvertToTournamentModels(TeamFile, PeopleFile, PrizesFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,6 +108,8 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
List<TournamentModel> output = new List<TournamentModel>();
|
||||
List<TeamModel> teams = teamFileName.FullFilePath().LoadFile().ConvertToTeamModels(peopleFileName);
|
||||
List<PrizeModel> prizes = prizesFileName.FullFilePath().LoadFile().ConvertToPrizeModels();
|
||||
List<MatchupModel> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile().ConvertToMatchupModels();
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] cols = line.Split(',');
|
||||
@ -120,13 +122,27 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
{
|
||||
tm.EnteredTeams.Add(teams.Where(x => x.Id == int.Parse(teamId)).First());
|
||||
}
|
||||
string[] prizeIds = cols[4].Split('|');
|
||||
foreach (string prizeId in prizeIds)
|
||||
if (cols[4].Length > 0)
|
||||
{
|
||||
tm.Prizes.Add(prizes.Where(x => x.Id == int.Parse(prizeId)).First());
|
||||
string[] prizeIds = cols[4].Split('|');
|
||||
foreach (string prizeId in prizeIds)
|
||||
{
|
||||
tm.Prizes.Add(prizes.Where(x => x.Id == int.Parse(prizeId)).First());
|
||||
}
|
||||
}
|
||||
|
||||
// Capture rounds information
|
||||
string[] rounds = cols[5].Split('|');
|
||||
foreach (string round in rounds)
|
||||
{
|
||||
List<MatchupModel> ms = new List<MatchupModel>();
|
||||
string[] mstext = round.Split('^');
|
||||
foreach (string matchupModelTextId in mstext)
|
||||
{
|
||||
ms.Add(matchups.Where(x => x.Id == int.Parse(matchupModelTextId)).First());
|
||||
}
|
||||
tm.Rounds.Add(ms);
|
||||
}
|
||||
|
||||
output.Add(tm);
|
||||
|
||||
@ -197,7 +213,14 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
string[] cols = line.Split(',');
|
||||
MatchupEntryModel me = new MatchupEntryModel();
|
||||
me.Id = int.Parse(cols[0]);
|
||||
me.TeamCompeting = LookupTeamById(int.Parse( cols[1]));
|
||||
if(cols[1].Length == 0)
|
||||
{
|
||||
me.TeamCompeting = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
me.TeamCompeting = LookupTeamById(int.Parse(cols[1]));
|
||||
}
|
||||
me.Score = double.Parse( cols[2]);
|
||||
|
||||
int parentId = 0;
|
||||
@ -207,7 +230,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
}
|
||||
else
|
||||
{
|
||||
me.ParentMatchup = null);
|
||||
me.ParentMatchup = null;
|
||||
}
|
||||
|
||||
output.Add(me);
|
||||
@ -219,25 +242,54 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
{
|
||||
string[] ids = input.Split('|');
|
||||
List<MatchupEntryModel> output = new List<MatchupEntryModel>();
|
||||
List<MatchupEntryModel> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile().ConvertToMatchupEntryModels();
|
||||
|
||||
List<string> entries = GlobalConfig.MatchupEntryFile.FullFilePath().LoadFile();
|
||||
List<string> matchingEntries = new List<string>();
|
||||
foreach (string id in ids)
|
||||
{
|
||||
output.Add(entries.Where(x => x.Id == int.Parse(id)).First());
|
||||
foreach (string entry in entries)
|
||||
{
|
||||
string[] cols = entry.Split(',');
|
||||
if (cols[0] == id) {
|
||||
matchingEntries.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output = matchingEntries.ConvertToMatchupEntryModels();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static TeamModel LookupTeamById(int id)
|
||||
{
|
||||
List<TeamModel> teams = GlobalConfig.TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(GlobalConfig.PeopleFile);
|
||||
return teams.Where(x => x.Id == id).First();
|
||||
List<string> teams = GlobalConfig.TeamFile.FullFilePath().LoadFile();
|
||||
foreach (string team in teams)
|
||||
{
|
||||
string[] cols = team.Split(',');
|
||||
if (cols[0] == id.ToString())
|
||||
{
|
||||
List<string> matchingTeams = new List<string>();
|
||||
matchingTeams.Add(team);
|
||||
return matchingTeams.ConvertToTeamModels(GlobalConfig.PeopleFile).First();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static MatchupModel LookupMatchupById(int id)
|
||||
{
|
||||
List<MatchupModel> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile().ConvertToMatchupModels();
|
||||
return matchups.Where(x => x.Id == id).First();
|
||||
List<string> matchups = GlobalConfig.MatchupFile.FullFilePath().LoadFile();
|
||||
foreach (string matchup in matchups)
|
||||
{
|
||||
string[] cols = matchup.Split(',');
|
||||
if (cols[0] == id.ToString())
|
||||
{
|
||||
List<string> matchingMatchups = new List<string>();
|
||||
matchingMatchups.Add(matchup);
|
||||
return matchingMatchups.ConvertToMatchupModels().First();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<MatchupModel> ConvertToMatchupModels(this List<string> lines)
|
||||
@ -251,7 +303,14 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
MatchupModel p = new MatchupModel();
|
||||
p.Id = int.Parse(cols[0]);
|
||||
p.Entries = ConvertStringToMatchupEntryModels(cols[1]);
|
||||
p.Winner = LookupTeamById(int.Parse(cols[2]));
|
||||
if (cols[2].Length == 0)
|
||||
{
|
||||
p.Winner = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.Winner = LookupTeamById(int.Parse(cols[2]));
|
||||
}
|
||||
p.MatchupRound = int.Parse(cols[3]);
|
||||
output.Add(p);
|
||||
}
|
||||
@ -268,6 +327,9 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
currentId = matchups.OrderByDescending(x => x.Id).First().Id + 1;
|
||||
}
|
||||
matchup.Id = currentId;
|
||||
|
||||
matchups.Add(matchup);
|
||||
|
||||
foreach (MatchupEntryModel entry in matchup.Entries)
|
||||
{
|
||||
entry.SaveEntryToFile(matchupEntryFile);
|
||||
@ -304,9 +366,14 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
string parent = "";
|
||||
if(e.ParentMatchup != null)
|
||||
{
|
||||
parent = e.ParentMatchup.Id.ToString(); ;
|
||||
parent = e.ParentMatchup.Id.ToString();
|
||||
}
|
||||
lines.Add($"{e.Id},{e.TeamCompeting.Id},{e.Score},{parent}");
|
||||
string teamCompeting = "";
|
||||
if(e.TeamCompeting != null)
|
||||
{
|
||||
teamCompeting = e.TeamCompeting.Id.ToString();
|
||||
}
|
||||
lines.Add($"{e.Id},{teamCompeting},{e.Score},{parent}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(GlobalConfig.MatchupEntryFile.FullFilePath(), lines);
|
||||
@ -319,12 +386,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
||||
List<string> lines = new List<string>();
|
||||
foreach (TournamentModel tm in models)
|
||||
{
|
||||
lines.Add($@"{tm.Id},
|
||||
{tm.TournamentName},
|
||||
{tm.EntryFee},
|
||||
{ConvertTeamListToString(tm.EnteredTeams)},
|
||||
{ConvertPrizeListToString(tm.Prizes)},
|
||||
{ConvertRoundListToString(tm.Rounds)}");
|
||||
lines.Add($@"{tm.Id},{tm.TournamentName},{tm.EntryFee},{ConvertTeamListToString(tm.EnteredTeams)},{ConvertPrizeListToString(tm.Prizes)},{ConvertRoundListToString(tm.Rounds)}");
|
||||
}
|
||||
|
||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||
|
||||
@ -11,6 +11,10 @@ namespace TrackerLibrary.Models
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// The unique identifier for the team
|
||||
/// </summary>
|
||||
public int TeamCompetingId { get; set; }
|
||||
/// <summary>
|
||||
/// Represents one team in the matchup
|
||||
/// </summary>
|
||||
public TeamModel TeamCompeting { get; set; }
|
||||
@ -19,6 +23,10 @@ namespace TrackerLibrary.Models
|
||||
/// </summary>
|
||||
public double Score { get; set; }
|
||||
/// <summary>
|
||||
/// The unique identifier for the parent matchup (team)
|
||||
/// </summary>
|
||||
public int ParentMatchupId { get; set; }
|
||||
/// <summary>
|
||||
/// Represents the matchup that this team came
|
||||
/// from as winner
|
||||
/// </summary>
|
||||
|
||||
@ -12,12 +12,16 @@ namespace TrackerLibrary.Models
|
||||
/// <summary>
|
||||
/// The unique identifier for the matchup
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// The set of teams that were involved in this match.
|
||||
/// </summary>
|
||||
public List<MatchupEntryModel> Entries { get; set; } = new List<MatchupEntryModel>();
|
||||
/// <summary>
|
||||
/// The Id from database that will be used to lookup the winner
|
||||
/// </summary>
|
||||
public int WinnerId { get; set; }
|
||||
/// <summary>
|
||||
/// The winner of the match.
|
||||
/// </summary>
|
||||
public TeamModel Winner { get; set; }
|
||||
@ -25,5 +29,34 @@ namespace TrackerLibrary.Models
|
||||
/// Which round this match is a part of.
|
||||
/// </summary>
|
||||
public int MatchupRound { get; set; }
|
||||
|
||||
public string DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
string output = "";
|
||||
foreach (MatchupEntryModel me in Entries)
|
||||
{
|
||||
if (me.TeamCompeting != null)
|
||||
{
|
||||
if (output.Length == 0)
|
||||
{
|
||||
output = me.TeamCompeting.TeamName;
|
||||
}
|
||||
else
|
||||
{
|
||||
output += $" vs. {me.TeamCompeting.TeamName}";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
output = "Matchup not yet Determined";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,9 +20,7 @@ namespace TrackerUI
|
||||
|
||||
// Initialize the database connections
|
||||
GlobalConfig.InitializeConnections(DatabaseType.Sql);
|
||||
Application.Run(new CreateTournamentForm());
|
||||
|
||||
//Application.Run(new TournamentDashboardForm());
|
||||
Application.Run(new TournamentDashboardForm());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
TrackerUI/TournamentDashboardForm.Designer.cs
generated
2
TrackerUI/TournamentDashboardForm.Designer.cs
generated
@ -80,6 +80,7 @@
|
||||
this.loadTournamentButton.TabIndex = 25;
|
||||
this.loadTournamentButton.Text = "Load Tournament";
|
||||
this.loadTournamentButton.UseVisualStyleBackColor = true;
|
||||
this.loadTournamentButton.Click += new System.EventHandler(this.loadTournamentButton_Click);
|
||||
//
|
||||
// createTournamentButton
|
||||
//
|
||||
@ -94,6 +95,7 @@
|
||||
this.createTournamentButton.TabIndex = 26;
|
||||
this.createTournamentButton.Text = "Create Tournament";
|
||||
this.createTournamentButton.UseVisualStyleBackColor = true;
|
||||
this.createTournamentButton.Click += new System.EventHandler(this.createTournamentButton_Click);
|
||||
//
|
||||
// TournamentDashboardForm
|
||||
//
|
||||
|
||||
@ -7,14 +7,37 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TrackerLibrary;
|
||||
using TrackerLibrary.Models;
|
||||
|
||||
namespace TrackerUI
|
||||
{
|
||||
public partial class TournamentDashboardForm : Form
|
||||
{
|
||||
List<TournamentModel> tournaments = GlobalConfig.Connection.GetTournament_All();
|
||||
public TournamentDashboardForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
WireUpLists();
|
||||
}
|
||||
|
||||
private void WireUpLists()
|
||||
{
|
||||
loadExistingTournamentDropDown.DataSource = tournaments;
|
||||
loadExistingTournamentDropDown.DisplayMember = "TournamentName";
|
||||
}
|
||||
|
||||
private void createTournamentButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateTournamentForm frm = new CreateTournamentForm();
|
||||
frm.Show();
|
||||
}
|
||||
|
||||
private void loadTournamentButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TournamentModel tm = (TournamentModel)loadExistingTournamentDropDown.SelectedItem;
|
||||
TournamentViewerForm frm = new TournamentViewerForm(tm);
|
||||
frm.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
TrackerUI/TournamentViewerForm.Designer.cs
generated
1
TrackerUI/TournamentViewerForm.Designer.cs
generated
@ -86,6 +86,7 @@
|
||||
this.roundDropDown.Name = "roundDropDown";
|
||||
this.roundDropDown.Size = new System.Drawing.Size(245, 38);
|
||||
this.roundDropDown.TabIndex = 3;
|
||||
this.roundDropDown.SelectedIndexChanged += new System.EventHandler(this.roundDropDown_SelectedIndexChanged);
|
||||
//
|
||||
// unplayedOnlyCheckbox
|
||||
//
|
||||
|
||||
@ -7,14 +7,74 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TrackerLibrary.Models;
|
||||
|
||||
namespace TrackerUI
|
||||
{
|
||||
public partial class TournamentViewerForm : Form
|
||||
{
|
||||
public TournamentViewerForm()
|
||||
private readonly TournamentModel tournament;
|
||||
List<int> rounds = new List<int>();
|
||||
List<MatchupModel> selectedMatchups = new List<MatchupModel>();
|
||||
public TournamentViewerForm(TournamentModel tournamentModel)
|
||||
{
|
||||
InitializeComponent();
|
||||
tournament = tournamentModel;
|
||||
LoadFormData();
|
||||
LoadRounds();
|
||||
}
|
||||
|
||||
private void LoadFormData()
|
||||
{
|
||||
tournamentName.Text = tournament.TournamentName;
|
||||
}
|
||||
|
||||
private void WireUpRoundsLists()
|
||||
{
|
||||
roundDropDown.DataSource = null;
|
||||
roundDropDown.DataSource = rounds;
|
||||
|
||||
}
|
||||
private void WireUpMatchupsLists()
|
||||
{
|
||||
MatchUpListBox.DataSource = null;
|
||||
MatchUpListBox.DataSource = selectedMatchups;
|
||||
MatchUpListBox.DisplayMember = "DisplayName";
|
||||
}
|
||||
private void LoadRounds()
|
||||
{
|
||||
rounds = new List<int>();
|
||||
|
||||
rounds.Add(1);
|
||||
int currRound = 1;
|
||||
foreach (List<MatchupModel> matchups in tournament.Rounds)
|
||||
{
|
||||
if (matchups.First().MatchupRound > currRound)
|
||||
{
|
||||
currRound = matchups.First().MatchupRound;
|
||||
rounds.Add(currRound);
|
||||
}
|
||||
}
|
||||
WireUpRoundsLists();
|
||||
}
|
||||
|
||||
private void roundDropDown_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadMatchups();
|
||||
}
|
||||
|
||||
|
||||
private void LoadMatchups()
|
||||
{
|
||||
int round = (int)roundDropDown.SelectedItem;
|
||||
foreach (List<MatchupModel> matchups in tournament.Rounds)
|
||||
{
|
||||
if (matchups.First().MatchupRound == round)
|
||||
{
|
||||
selectedMatchups = matchups;
|
||||
}
|
||||
}
|
||||
WireUpMatchupsLists();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user