A lot of refactoring and both saving types work
This commit is contained in:
@ -96,6 +96,8 @@ namespace TrackerLibrary.DataAccess
|
|||||||
SaveTournamentEntries(model, connection);
|
SaveTournamentEntries(model, connection);
|
||||||
|
|
||||||
SaveTournamentRounds(model, connection);
|
SaveTournamentRounds(model, connection);
|
||||||
|
|
||||||
|
TournamentLogic.UpdateTournamentResults(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,6 +235,7 @@ namespace TrackerLibrary.DataAccess
|
|||||||
foreach (TournamentModel t in output)
|
foreach (TournamentModel t in output)
|
||||||
{
|
{
|
||||||
// Populate prizes
|
// Populate prizes
|
||||||
|
p = new DynamicParameters();
|
||||||
p.Add("@TournamentId", t.Id);
|
p.Add("@TournamentId", t.Id);
|
||||||
t.Prizes = connection.Query<PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
|
t.Prizes = connection.Query<PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
|
||||||
// Populate Teams
|
// Populate Teams
|
||||||
|
|||||||
@ -110,6 +110,8 @@ namespace TrackerLibrary.DataAccess
|
|||||||
tournaments.Add(model);
|
tournaments.Add(model);
|
||||||
|
|
||||||
tournaments.SaveToTournamentFile();
|
tournaments.SaveToTournamentFile();
|
||||||
|
|
||||||
|
TournamentLogic.UpdateTournamentResults(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TournamentModel> GetTournament_All()
|
public List<TournamentModel> GetTournament_All()
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -21,6 +22,119 @@ namespace TrackerLibrary
|
|||||||
int byes = NumberOfByes(rounds, randomizedTeams.Count);
|
int byes = NumberOfByes(rounds, randomizedTeams.Count);
|
||||||
model.Rounds.Add(CreateFirstRound(byes, randomizedTeams));
|
model.Rounds.Add(CreateFirstRound(byes, randomizedTeams));
|
||||||
CreateOtherRounds(model, rounds);
|
CreateOtherRounds(model, rounds);
|
||||||
|
//UpdateTournamentResults(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void UpdateTournamentResults(TournamentModel model)
|
||||||
|
{
|
||||||
|
List<MatchupModel> toScore = new List<MatchupModel>();
|
||||||
|
|
||||||
|
foreach (List<MatchupModel> round in model.Rounds)
|
||||||
|
{
|
||||||
|
foreach (MatchupModel rm in round)
|
||||||
|
{
|
||||||
|
if (rm.Winner == null && (rm.Entries.Any(x => x.Score != 0) || rm.Entries.Count == 1))
|
||||||
|
{
|
||||||
|
toScore.Add(rm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MarkWinnersInMatchups(toScore);
|
||||||
|
|
||||||
|
AdvanceWinners(toScore, model);
|
||||||
|
|
||||||
|
toScore.ForEach(x => GlobalConfig.Connection.UpdateMatchup(x));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AdvanceWinners(List<MatchupModel> models, TournamentModel tournament)
|
||||||
|
{
|
||||||
|
foreach (MatchupModel m in models)
|
||||||
|
{
|
||||||
|
foreach (List<MatchupModel> round in tournament.Rounds)
|
||||||
|
{
|
||||||
|
foreach (MatchupModel rm in round)
|
||||||
|
{
|
||||||
|
foreach (MatchupEntryModel me in rm.Entries)
|
||||||
|
{
|
||||||
|
if (me.ParentMatchup != null)
|
||||||
|
{
|
||||||
|
if (me.ParentMatchup.Id == m.Id)
|
||||||
|
{
|
||||||
|
me.TeamCompeting = m.Winner;
|
||||||
|
GlobalConfig.Connection.UpdateMatchup(rm);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void MarkWinnersInMatchups(List<MatchupModel> models)
|
||||||
|
{
|
||||||
|
// greaterWins
|
||||||
|
string greaterWins = ConfigurationManager.AppSettings["greaterWins"];
|
||||||
|
|
||||||
|
foreach (MatchupModel m in models)
|
||||||
|
{
|
||||||
|
if (m.Entries.Count == 1)
|
||||||
|
{
|
||||||
|
m.Winner = m.Entries[0].TeamCompeting;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "0" means false or low scare wins
|
||||||
|
if (greaterWins == "0")
|
||||||
|
{
|
||||||
|
if (m.Entries[0].Score < m.Entries[1].Score)
|
||||||
|
{
|
||||||
|
m.Winner = m.Entries[0].TeamCompeting;
|
||||||
|
}
|
||||||
|
else if (m.Entries[1].Score < m.Entries[0].Score)
|
||||||
|
{
|
||||||
|
m.Winner = m.Entries[1].TeamCompeting;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("We do not allow ties in this application");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 1 mean true, or high score wins
|
||||||
|
if (m.Entries[0].Score > m.Entries[1].Score)
|
||||||
|
{
|
||||||
|
m.Winner = m.Entries[0].TeamCompeting;
|
||||||
|
}
|
||||||
|
else if (m.Entries[1].Score > m.Entries[0].Score)
|
||||||
|
{
|
||||||
|
m.Winner = m.Entries[1].TeamCompeting;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("We do not allow ties in this application");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (teamOneScore > teamTwoScore)
|
||||||
|
//{
|
||||||
|
// // Team one winns
|
||||||
|
// m.Winner = m.Entries[0].TeamCompeting;
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
// if (teamTwoScore > teamOneScore)
|
||||||
|
//{
|
||||||
|
// // Team one winns
|
||||||
|
// m.Winner = m.Entries[1].TeamCompeting;
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// MessageBox.Show("I dont handle tie games.");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateOtherRounds(TournamentModel model, int rounds)
|
private static void CreateOtherRounds(TournamentModel model, int rounds)
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="filePath" value="D:\data\TournamentTracker"/>
|
<add key="filePath" value="D:\data\TournamentTracker"/>
|
||||||
<!--<add key="filePath" value="C:\AppData\TournamentTracker"/>-->
|
<!--<add key="filePath" value="C:\AppData\TournamentTracker"/>-->
|
||||||
|
<add key="greaterWins" value="1"/>
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<connectionStrings>
|
<connectionStrings>
|
||||||
<!--<add name="Tournaments" connectionString="Server=TOMMYASUS\SQLEXPR2017;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>-->
|
<!--<add name="Tournaments" connectionString="Server=TOMMYASUS\SQLEXPR2017;Database=Tournaments;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>-->
|
||||||
|
|||||||
@ -133,6 +133,11 @@ namespace TrackerUI
|
|||||||
// Create all of team entries
|
// Create all of team entries
|
||||||
GlobalConfig.Connection.CreateTournament(tm);
|
GlobalConfig.Connection.CreateTournament(tm);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TournamentViewerForm frm = new TournamentViewerForm(tm);
|
||||||
|
frm.Show();
|
||||||
|
this.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -199,44 +199,10 @@ namespace TrackerUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (teamOneScore > teamTwoScore)
|
TournamentLogic.UpdateTournamentResults(tournament);
|
||||||
{
|
|
||||||
// Team one winns
|
|
||||||
m.Winner = m.Entries[0].TeamCompeting;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (teamTwoScore > teamOneScore)
|
|
||||||
{
|
|
||||||
// Team one winns
|
|
||||||
m.Winner = m.Entries[1].TeamCompeting;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("I dont handle tie games.");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (List<MatchupModel> round in tournament.Rounds)
|
|
||||||
{
|
|
||||||
foreach (MatchupModel rm in round)
|
|
||||||
{
|
|
||||||
foreach (MatchupEntryModel me in rm.Entries)
|
|
||||||
{
|
|
||||||
if (me.ParentMatchup != null)
|
|
||||||
{
|
|
||||||
if (me.ParentMatchup.Id == m.Id)
|
|
||||||
{
|
|
||||||
me.TeamCompeting = m.Winner;
|
|
||||||
GlobalConfig.Connection.UpdateMatchup(rm);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadMatchups((int)roundDropDown.SelectedItem);
|
LoadMatchups((int)roundDropDown.SelectedItem);
|
||||||
|
|
||||||
GlobalConfig.Connection.UpdateMatchup(m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user