From 7a496566f759a5aac8b56d46c1b9eb36bdcb3f52 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 23 Aug 2017 17:18:38 +0200 Subject: Editor for BWS names --- Aktywator/Tournament.cs | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'Aktywator/Tournament.cs') diff --git a/Aktywator/Tournament.cs b/Aktywator/Tournament.cs index cbe9bf9..87fa759 100644 --- a/Aktywator/Tournament.cs +++ b/Aktywator/Tournament.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Text; +using System.Windows.Forms; +using System.Drawing; namespace Aktywator { @@ -38,6 +40,77 @@ namespace Aktywator return new Dictionary>(); } + virtual public void displayNameList(DataGridView grid) + { + Dictionary> names = this.getNameList(); + foreach (KeyValuePair> item in names) { + if (!this.updateNameListRow(grid, item.Key, item.Value)) + { + this.addNameListRow(grid, item.Key, item.Value); + } + } + List toDelete = new List(); + foreach (DataGridViewRow row in grid.Rows) + { + if (!names.ContainsKey(Int32.Parse(row.Cells[0].Value.ToString()))) + { + toDelete.Add(row); + } + } + foreach (DataGridViewRow r in toDelete) + { + grid.Rows.Remove(r); + } + } + + virtual internal bool updateNameListRow(DataGridView grid, int pairNumber, List names) + { + foreach (DataGridViewRow row in grid.Rows) + { + if (Int32.Parse(row.Cells[0].Value.ToString()) == pairNumber) + { + for (int i = 1; i < 3; i++) + { + if (!(bool)row.Cells[i].Tag) + { + row.Cells[i].Value = names[i - 1]; + row.Cells[i].Tag = false; + row.Cells[i].Style.BackColor = Color.White; + } + } + return true; + } + } + return false; + } + + virtual internal void addNameListRow(DataGridView grid, int pairNumber, List names) + { + DataGridViewRow row = new DataGridViewRow(); + row.Cells.Add(new DataGridViewTextBoxCell()); + row.Cells[0].Value = pairNumber.ToString(); + foreach (string name in names) + { + DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell(); + cell.Value = name; + cell.Tag = false; + row.Cells.Add(cell); + } + grid.Rows.Add(row); + } + + virtual internal void clearCellLocks(DataGridView grid) + { + foreach (DataGridViewRow row in grid.Rows) + { + for (int i = 1; i < 3; i++) + { + row.Cells[i].Tag = false; + row.Cells[i].Style.BackColor = Color.White; + } + } + } + virtual internal string shortenNameToBWS(string name) { if ("pauza".Equals(name.Trim())) @@ -54,5 +127,21 @@ namespace Aktywator return String.Join(" ", nameParts); } } + + virtual public Dictionary> getBWSNames(DataGridView grid) + { + Dictionary> dict = new Dictionary>(); + foreach (DataGridViewRow row in grid.Rows) + { + List names = new List(); + for (int i = 1; i < 3; i++) + { + names.Add(this.shortenNameToBWS(row.Cells[i].Value.ToString())); + } + dict.Add(Int32.Parse(row.Cells[0].Value.ToString()), names); + } + return dict; + } + } } -- cgit v1.2.3