public static List <Dive> GetDiversDiveInContest(int diverId, int eventId) { List <Dive> dives = new List <Dive>(); MySqlConnection conn = Database.ConnectToDatabase(); if (conn != null) { MySqlCommand comm = conn.CreateCommand(); string sql = "SELECT id FROM dive WHERE diverId=" + diverId + " AND eventId=" + eventId; comm.CommandText = sql; var dr = comm.ExecuteReader(); var dt = new DataTable(); dt.Load(dr); foreach (DataRow row in dt.Rows) { Dive d = new Dive(); d.Id = Int32.Parse(row["id"].ToString()); dives.Add(d); } conn.Close(); } return(dives); }
public Score(int ID, Dive d, Judge j, double points) { this.Id = ID; this.dive = d; this.judge = j; this.Points = points; }
/// <summary> /// Resets the points that points that are shown in the clientView /// </summary> /// <param name="judgeName">The name of the judge to have his points set</param> private void ResetJudgePoints(string judgeName) { foreach (ListViewItem clientItem in View.ListViewJudgeClients.Items) { if (judgeName == clientItem.Text) { Dive dive = GetSelectedDive(); if (dive?.Scores != null) { foreach (var score in dive.Scores) { if (score.Judge.GetFullName() == clientItem.Text) { clientItem.SubItems[1].Text = score.Value.ToString(); break; } } break; } else { clientItem.SubItems[1].Text = "-1"; } } } }
private static void _AddScoreToDive(List <Score> s, Dive d) { System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; MySqlConnection conn = Database.ConnectToDatabase(); if (conn != null) { MySqlCommand comm = new MySqlCommand(); foreach (Score sc in s) { comm = conn.CreateCommand(); comm.CommandText = "INSERT INTO score(diveId, judgeId, point) VALUES (@diveId, @judgeId, @point)"; comm.Parameters.AddWithValue("@diveId", sc.dive.Id); comm.Parameters.AddWithValue("@judgeId", sc.judge.Id); comm.Parameters.AddWithValue("@point", sc.Points); comm.ExecuteNonQuery(); } string sql = "UPDATE dive SET totalScore=" + d.Score + " WHERE id=" + d.Id; comm.CommandText = sql; comm.ExecuteNonQuery(); conn.Close(); } }
/// <summary> /// Add a new dive to the correct divelist of a Contestant /// </summary> /// <param name="diver">The Contestant who made the dive</param> /// <param name="diveToBeAdded">The dive</param> public void AddNewDive(Contestant diver, Dive diveToBeAdded) { if (this.BranchContestants.Contains(diver)) { // If this is the first dive of this Contestant, create a new DiveList connected to this branch, // and then add the dive. if (diver.DiveLists.Count == 0) { diver.DiveLists.Add(new DiveList(this)); diver.DiveLists.ElementAt(0).Add(diveToBeAdded); } // if it is not the first dive, go through the DiveList(s) and see if any of them match with // this branch. If no such list exists, create it and add the dive. else { foreach (var list in diver.DiveLists) { if (list.SubContestBranch == this) { list.Add(diveToBeAdded); break; } else { diver.DiveLists.Add(new DiveList(this)); diver.DiveLists.Last().Add(diveToBeAdded); break; } } } } }
/// <summary> /// Request points from the clients by sending a message /// </summary> /// <param name="dive">Dive to be judged</param> internal void RequestPoints(Dive dive) { foreach (var client in ClientList) { client.StreamWriter?.WriteLine("give:" + dive.Code.Code + "|" + dive.Code.Multiplier); client.StreamWriter?.Flush(); } }
public ManualJudging(Dive dive, JudgeList judgeList) { InitializeComponent(); this.dive = dive; this.judgeList = judgeList; Setup(); }
/// <summary> /// Call RequestPoints() in the Server. /// This sends out a message to every client that the head Judge wants to collect scores /// </summary> private void RequestPointsFromJudges() { Dive dive = GetSelectedDive(); if (dive != null) { Server?.RequestPoints(GetSelectedDive()); } }
public static Contest GetContest(int contestId) { Contest c = new Contest(); MySqlConnection conn = Database.ConnectToDatabase(); if (conn != null) { MySqlCommand comm = conn.CreateCommand(); string sql = "SELECT * FROM event WHERE id=" + contestId; comm.CommandText = sql; var dr = comm.ExecuteReader(); var dt = new DataTable(); dt.Load(dr); //skapar en Contest foreach (DataRow row in dt.Rows) { c = new Contest(Int32.Parse(row["id"].ToString()), row["name"].ToString(), row["date"].ToString(), row["location"].ToString(), Int32.Parse(row["discipline"].ToString()), Int32.Parse(row["sync"].ToString()), Int32.Parse(row["diveCount"].ToString()), Int32.Parse(row["sex"].ToString()), Int32.Parse(row["started"].ToString())); } //hämtar alla dommare och hoppare som är med i contesten c.AddDivers(Database.GetDiversInEvent(contestId)); c.AddJudges(Database.GetJudgesInEvent(contestId)); //lägger till hopp till alla hoppare foreach (Diver d in c.Divers) { List <DiveType> dType = new List <DiveType>(); List <Dive> dives = new List <Dive>(); List <Dive> divesId = new List <Dive>(); divesId = Database.GetDiversDiveInContest(d.Id, contestId); dType = Database.GetDiversDiveTypeInContest(d.Id, contestId); int count = 0; foreach (DiveType type in dType) { Dive dDive = new Dive(); dDive._diveType = type; dDive._diver = d; dDive.Id = divesId[count].Id; count++; dives.Add(dDive); } d.Dives = dives; } conn.Close(); } return(c); }
public void RunScoreDive() { Assert.LessOrEqual(_divers[0].Dives[0].Score, 30); Diver tDiver = new Diver(-1, "Greger"); Dive tDive = new Dive(-1, tDiver, 1, _contest); tDiver.AddDive(tDive); tDive.AddScore(new Score(0, tDive, _judges[0], 1)); tDive.AddScore(new Score(0, tDive, _judges[1], 5)); tDive.AddScore(new Score(0, tDive, _judges[2], 5)); tDive.AddScore(new Score(0, tDive, _judges[3], 5)); tDive.AddScore(new Score(0, tDive, _judges[4], 10)); Assert.AreEqual(tDive.Score, 15); }
/// <summary> /// Remove an existing dive from a contestants DiveList bound to this branch /// </summary> /// <param name="diver">The Contestant to have his dive removed</param> /// <param name="diveToBeRemoved">The dive in question</param> public bool RemoveExistingDive(Contestant diver, Dive diveToBeRemoved) { if (BranchContestants.Exists(diver)) { foreach (var list in diver.DiveLists) { if (list.Exists(diveToBeRemoved)) { list.Remove(diveToBeRemoved); return(true); } } } return(false); }
public void RunScoreGreaterThanMax() { Assert.AreEqual(1, 1); return; Diver tDiver = new Diver(-1, "Gregers kompis"); Dive tDive = new Dive(-1, tDiver, 1, _contest); tDiver.AddDive(tDive); tDive.AddScore(new Score(0, tDive, _judges[0], 11)); tDive.AddScore(new Score(0, tDive, _judges[1], 11)); tDive.AddScore(new Score(0, tDive, _judges[2], 11)); tDive.AddScore(new Score(0, tDive, _judges[3], 11)); tDive.AddScore(new Score(0, tDive, _judges[4], 11)); //Assert.AreEqual(tDive.Score, 30); }
/// <summary> /// Add a dive to the contestant. Validates the input data before adding it. /// </summary> public void AddDiveToContestant() { if (ValidateData()) { double multiplier = double.Parse(View.TextBoxDiveMultiplier.Text, CultureInfo.InvariantCulture); string code = View.TextBoxDiveCode.Text; Dive diveTobeAdded = new Dive(new DiveCode(multiplier, code)); SubContest.AddNewDive(CurrentContestant, diveTobeAdded); View.DialogResult = System.Windows.Forms.DialogResult.OK; View.Close(); } }
// Public Methods public void TestData() { ScoreList scoreList = new ScoreList(); scoreList.Add(new Score(2.5)); scoreList.Add(new Score(7.5)); scoreList.Add(new Score(3)); scoreList.Add(new Score(10)); scoreList.Add(new Score(5.5)); ScoreList scoreList2 = new ScoreList(); scoreList2.Add(new Score(2.5)); scoreList2.Add(new Score(3)); scoreList2.Add(new Score(2)); scoreList2.Add(new Score(8.5)); scoreList2.Add(new Score(5.5)); Dive dive = new Dive(new DiveCode(2.0, "10mbakåtvolt"), scoreList2); Dive dive2 = new Dive(new DiveCode(3.0, "10m"), scoreList); foreach (var sc in Model.SubContestBranches) { foreach (var c in sc.BranchContestants) { if (c.FirstName == "pelle") { sc.AddNewDive(c, dive2); } } } foreach (var sc in Model.SubContestBranches) { foreach (var c in sc.BranchContestants) { if (c.FirstName == "kalle") { sc.AddNewDive(c, dive); } } } }
private long PushDive(Dive dive, long branchID, long contestantID) { // Table info string table = "dive"; // Contest info var name = dive.Name; var code = dive.Code.Code; var multiplier = dive.Code.Multiplier; var finalScore = dive.FinalScore; // Build query string query = $"INSERT INTO {table} "; query += $"(name, code, multiplier, contestantID, branchID, finalScore) "; query += $"VALUES("; query += $"'{name}','{code}', '{multiplier}', '{contestantID}', '{branchID}', {finalScore}"; query += $")"; return(ExecuteQuery(query)); }
/// <summary> /// Updates a existing dive with new information /// </summary> private void ModifyDive() { SubContestBranch subContestBranch = GetSelectedSubContest(); Contestant contestant = GetSelectedContestant(); Dive dive = GetSelectedDive(); AddDiveView modifyView = new AddDiveView(); AddDivePresenter presenter = new AddDivePresenter(modifyView, window, subContestBranch, contestant, dive); if (subContestBranch != null && contestant != null && dive != null) { if (modifyView.ShowDialog() == DialogResult.OK) { subContestBranch.RemoveExistingDive(contestant, dive); UpdateDivesListView(); } } }
public void AddDive(Dive dive) { Dives.Add(dive); }
public Score(Dive d, Judge j, double points) { this.dive = d; this.judge = j; this.Points = points; }
public static List<Dive> GetDiversDiveInContest(int diverId, int eventId) { List<Dive> dives = new List<Dive>(); MySqlConnection conn = Database.ConnectToDatabase(); if(conn != null) { MySqlCommand comm = conn.CreateCommand(); string sql = "SELECT id FROM dive WHERE diverId=" + diverId + " AND eventId=" + eventId; comm.CommandText = sql; var dr = comm.ExecuteReader(); var dt = new DataTable(); dt.Load(dr); foreach (DataRow row in dt.Rows) { Dive d = new Dive(); d.Id = Int32.Parse(row["id"].ToString()); dives.Add(d); } conn.Close(); } return dives; }
public static void AddScoreToDive(List <Score> s, Dive d) { Thread t = new Thread(() => _AddScoreToDive(s, d)); t.Start(); }
public AddDivePresenter(AddDiveView view, ProjectMainWindow window, SubContestBranch subContest, Contestant contestant, Dive dive = null) { this.View = view; this.window = window; this.SubContest = subContest; CurrentContestant = contestant; if (dive != null) { View.TextBoxDiveCode.Text = dive.Code.Code; View.TextBoxDiveMultiplier.Text = dive.Code.Multiplier.ToString(); } View.EventAddDive += AddDiveToContestant; }
public static Contest GetContest(int contestId) { Contest c = new Contest(); MySqlConnection conn = Database.ConnectToDatabase(); if(conn != null) { MySqlCommand comm = conn.CreateCommand(); string sql = "SELECT * FROM event WHERE id=" + contestId; comm.CommandText = sql; var dr = comm.ExecuteReader(); var dt = new DataTable(); dt.Load(dr); //skapar en Contest foreach (DataRow row in dt.Rows) { c = new Contest(Int32.Parse(row["id"].ToString()), row["name"].ToString(), row["date"].ToString(), row["location"].ToString(), Int32.Parse(row["discipline"].ToString()), Int32.Parse(row["sync"].ToString()), Int32.Parse(row["diveCount"].ToString()), Int32.Parse(row["sex"].ToString()), Int32.Parse(row["started"].ToString())); } //hämtar alla dommare och hoppare som är med i contesten c.AddDivers(Database.GetDiversInEvent(contestId)); c.AddJudges(Database.GetJudgesInEvent(contestId)); //lägger till hopp till alla hoppare foreach(Diver d in c.Divers) { List<DiveType> dType = new List<DiveType>(); List<Dive> dives = new List<Dive>(); List<Dive> divesId = new List<Dive>(); divesId = Database.GetDiversDiveInContest(d.Id, contestId); dType = Database.GetDiversDiveTypeInContest(d.Id, contestId); int count = 0; foreach(DiveType type in dType) { Dive dDive = new Dive(); dDive._diveType = type; dDive._diver = d; dDive.Id = divesId[count].Id; count++; dives.Add(dDive); } d.Dives = dives; } conn.Close(); } return c; }
public static void AddScoreToDive(List<Score> s, Dive d) { Thread t = new Thread(() => _AddScoreToDive(s, d)); t.Start(); }
public void SetUp() { _judges = new List<Judge>(); _divers = new List<Diver>(); _contest = new Contest(0, "Nunit Test Contest", "2015-02-02", "Badhuset", 1, 1, 1, 5); _judges.Add(new Judge(0, "Mr. Test")); _judges.Add(new Judge(1, "Mrs. Fest")); _judges.Add(new Judge(2, "Konstapel Kuk")); _judges.Add(new Judge(3, "Domherre")); _judges.Add(new Judge(4, "McFlash")); _divers.Add(new Diver(0, "Kalle")); _divers.Add(new Diver(1, "Greger")); _divers.Add(new Diver(2, "Skitunge")); _contest.AddDivers(_divers); _contest.AddJudges(_judges); for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { Dive dive = new Dive(0, null, j + 1, _contest); _contest.Divers[i].AddDive(dive); for (int k = 0; k < 5; k++) { Score s = new Score(0, null, _judges[k], (k + j)%11); dive.AddScore(s); } } } }
private static void _AddScoreToDive(List<Score> s, Dive d) { System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; MySqlConnection conn = Database.ConnectToDatabase(); if(conn != null) { MySqlCommand comm = new MySqlCommand(); foreach(Score sc in s) { comm = conn.CreateCommand(); comm.CommandText = "INSERT INTO score(diveId, judgeId, point) VALUES (@diveId, @judgeId, @point)"; comm.Parameters.AddWithValue("@diveId", sc.dive.Id); comm.Parameters.AddWithValue("@judgeId", sc.judge.Id); comm.Parameters.AddWithValue("@point", sc.Points); comm.ExecuteNonQuery(); } string sql = "UPDATE dive SET totalScore=" + d.Score + " WHERE id=" + d.Id; comm.CommandText = sql; comm.ExecuteNonQuery(); conn.Close(); } }
/// <summary> /// Ritar upp en panel med information om ett hopp. /// Layout-sketch: /// /// [Namn] /// ([DD]) [Hopp-typ] [Hopp-poäng] /// [] [] [] [] [] < Domarpoäng /// /// </summary> /// <param name="diver">Hoppare</param> /// <param name="round">Vilket hopp i ordningen</param> /// <returns></returns> public static Panel DivePanel(Diver diver, int round, int judgeCount, EventHandler UpdateScoreDelegate) { Init(); Dive dive = diver.Dives[round]; FontFamily fontFamily = new FontFamily("Cambria"); Font fontName = new Font( fontFamily, 15, FontStyle.Bold, GraphicsUnit.Pixel); Font fontScore = new Font( fontFamily, 18, FontStyle.Bold, GraphicsUnit.Pixel); int pWidth = 402; Panel p = new Panel(); p.Width = pWidth; p.Height = 74; p.BackColor = _colors[1]; p.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; Panel panelBorder = new Panel(); panelBorder.BackColor = _colors[0]; panelBorder.Height = 2; panelBorder.Width = p.Width; panelBorder.Top = p.Height - 2; panelBorder.Left = 0; panelBorder.Anchor = AnchorStyles.Left | AnchorStyles.Right; p.Controls.Add(panelBorder); //Fulhax Panel panelCover = new Panel(); panelCover.BackColor = _colors[1]; panelCover.Top = 0; panelCover.Left = 0; panelCover.Width = 17; panelCover.Height = p.Height; p.Controls.Add(panelCover); panelCover.BringToFront(); Label name = new Label(); name.Text = diver.Name; name.Top = 2; name.Left = 20; name.Font = fontName; name.ForeColor = Color.White; p.Controls.Add(name); Label difficulty = new Label(); difficulty.Text = "[" + dive.Difficulty + "] " + dive.Name; difficulty.Top = 22; difficulty.Left = 20; difficulty.AutoSize = true; difficulty.MaximumSize = new Size(p.Width - 60, 22); difficulty.ForeColor = Color.White; difficulty.Font = new Font(fontName, FontStyle.Regular); p.Controls.Add(difficulty); Label points = new Label(); points.Text = ""; points.Left = p.Width - points.Width - 10; points.Top = 10; points.Font = fontName; points.TextAlign = ContentAlignment.MiddleRight; points.ForeColor = Color.White; points.Name = "Points"; points.Anchor = AnchorStyles.Right; p.Controls.Add(points); Panel scorePanel = new Panel(); scorePanel.Width = pWidth; scorePanel.Height = 30; scorePanel.Left = 0; scorePanel.Top = 45; scorePanel.BackColor = Color.Transparent; scorePanel.Tag = points; for (int i = 0; i < judgeCount; i++) { TextBox tb = new TextBox(); tb.Text = " "; tb.Left = 24 + i * 40; tb.Width = 32; tb.Height = 22; tb.TextAlign = HorizontalAlignment.Center; tb.BorderStyle = BorderStyle.None; tb.BackColor = _colors[1]; tb.ForeColor = Color.White; tb.Font = fontScore; tb.Name = "Score"; tb.ReadOnly = true; tb.TextChanged += UpdateScoreDelegate; tb.GotFocus += tb_GotFocus; scorePanel.Controls.Add(tb); } p.Controls.Add(scorePanel); return(p); }
public static void GetScoresToDives(Contest contest) { MySqlConnection conn = Database.ConnectToDatabase(); MySqlCommand comm = new MySqlCommand(); string sql = ""; comm = conn.CreateCommand(); if (conn != null) { foreach (Diver diver in contest.Divers) { //hämtar alla Scores som finns på hopparen sql = "SELECT * FROM score WHERE diveId IN (SELECT id FROM dive WHERE diverId=" + diver.Id + " AND eventId=" + contest.Id + ") ORDER BY id"; comm.CommandText = sql; MySqlDataReader dr = comm.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); int count = 0; int diveCount = 1; Score currentScore = new Score(); Dive currentDive = new Dive(); Judge currentJudge = new Judge(); //Alla scores som finns på alla hoppen foreach (DataRow row in dt.Rows) { if (count < diver.Dives.Count) { foreach (Judge judge in contest.Judges) { if (judge.Id.ToString().CompareTo(row["judgeId"].ToString()) == 0) { currentJudge = judge; } } try { currentDive = diver.Dives[count]; } catch (IndexOutOfRangeException) { } currentScore = new Score(Int32.Parse(row["id"].ToString()), currentDive, currentJudge, Double.Parse(row["point"].ToString())); diver.Dives[count].AddScore(currentScore); if (diveCount == contest.Judges.Count) { count++; diveCount = 1; } else { diveCount++; } } } } } }
public static void GetScoresToDives(Contest contest) { MySqlConnection conn = Database.ConnectToDatabase(); MySqlCommand comm = new MySqlCommand(); string sql = ""; comm = conn.CreateCommand(); if(conn != null) { foreach (Diver diver in contest.Divers) { //hämtar alla Scores som finns på hopparen sql = "SELECT * FROM score WHERE diveId IN (SELECT id FROM dive WHERE diverId=" + diver.Id + " AND eventId=" + contest.Id + ") ORDER BY id"; comm.CommandText = sql; MySqlDataReader dr = comm.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); int count = 0; int diveCount = 1; Score currentScore = new Score(); Dive currentDive = new Dive(); Judge currentJudge = new Judge(); //Alla scores som finns på alla hoppen foreach(DataRow row in dt.Rows) { if (count < diver.Dives.Count) { foreach (Judge judge in contest.Judges) { if (judge.Id.ToString().CompareTo(row["judgeId"].ToString()) == 0) currentJudge = judge; } try { currentDive = diver.Dives[count]; } catch (IndexOutOfRangeException) { } currentScore = new Score(Int32.Parse(row["id"].ToString()), currentDive, currentJudge, Double.Parse(row["point"].ToString())); diver.Dives[count].AddScore(currentScore); if(diveCount == contest.Judges.Count) { count++; diveCount = 1; } else { diveCount++; } } } } } }