private void StartNewBtn_Click(object sender, EventArgs e) { if (show1 != null) { show1.Dispose(); show2.Dispose(); show3.Dispose(); show4.Dispose(); } show1 = new ShowControl(1, ClientRectangle, "show 1"); show2 = new ShowControl(2, ClientRectangle, "show 2"); show3 = new ShowControl(3, ClientRectangle, "show 3"); show4 = new ShowControl(4, ClientRectangle, "show 4"); this.Controls.AddRange(new Control[] { show1, show2, show3, show4 }); CastStart.Visible = true; OldColourButton.Visible = true; CastNextFlavour.Visible = true; Invalidate(); }
private void LoadFromFileBtn_Click(object sender, EventArgs e) { if (show1 != null) { show1.Dispose(); show2.Dispose(); show3.Dispose(); show4.Dispose(); } try { OpenFileDialog file = new OpenFileDialog(); file.InitialDirectory = "C:\\"; file.Filter = "CSV files|*.csv|All files (*.*)|*.*"; file.FilterIndex = 1; file.RestoreDirectory = true; if (file.ShowDialog() == DialogResult.OK) { string filePath = file.FileName; var fileStream = file.OpenFile(); using (StreamReader reader = new StreamReader(fileStream)) { List <string> lines = new List <string>(); while (!reader.EndOfStream) { lines.Add(reader.ReadLine()); } List <List <string> > data = new List <List <string> >(); for (int i = 0; i < lines.Count; i++) { data.Add(lines[i].Split(',').ToList()); } int[] showNamesPos = new int[4]; int namesFound = 0; for (int i = 0; i < lines.Count; i++) { if (data[i][0] != "" && namesFound < 4) { showNamesPos[namesFound] = i; namesFound++; } } List <string>[] roles = new List <string> [4]; List <List <string> >[] names = new List <List <string> > [4]; for (int show = 0; show < namesFound; show++) { roles[show] = new List <string>(); names[show] = new List <List <string> >(); int roleIndex = 1; while (roleIndex < data[showNamesPos[show]].Count() && data[showNamesPos[show]][roleIndex] != "") { string role = data[showNamesPos[show]][roleIndex]; roles[show].Add(role); roleIndex++; names[show].Add(new List <string>()); int namesIndex = 1; while (data[showNamesPos[show] + namesIndex][roleIndex - 1] != "") { string name = data[showNamesPos[show] + namesIndex][roleIndex - 1]; names[show][roleIndex - 2].Add(name); namesIndex++; } } } show1 = new ShowControl(1, ClientRectangle, data[showNamesPos[0]][0], roles[0], names[0]); show2 = new ShowControl(2, ClientRectangle, data[showNamesPos[1]][0], roles[1], names[1]); show3 = new ShowControl(3, ClientRectangle, data[showNamesPos[2]][0], roles[2], names[2]); show4 = new ShowControl(4, ClientRectangle, data[showNamesPos[3]][0], roles[3], names[3]); this.Controls.AddRange(new Control[] { show1, show2, show3, show4 }); CastStart.Visible = true; CastNextFlavour.Visible = true; Invalidate(); } OldColourButton.Visible = true; } } catch (Exception error) { MessageBox.Show("Something seems to have gone wrong loading the file you picked! Make sure you don't have the file open at the moment and ensure it's saved in the right format." + Environment.NewLine + Environment.NewLine + error.ToString(), "Error Loading File", MessageBoxButtons.OK); } }