// done button private void pictureBox2_Click(object sender, EventArgs e) { if (listBox1.SelectedItem != null && listBox2.SelectedItem != null && listBox3.SelectedItem != null && listBox1.SelectedItem != listBox2.SelectedItem) { Program.matchUpListFinal.Clear(); // add games played, times played and played against to both teams foreach (Team value in Program.itemList) { if (value.TeamName == listBox1.SelectedItem.ToString()) { value.GamesPlayed++; value.TimesPlayed.Add(listBox3.SelectedItem.ToString()); value.PlayedAgainst.Add(listBox2.SelectedItem.ToString()); } if (value.TeamName == listBox2.SelectedItem.ToString()) { value.GamesPlayed++; value.TimesPlayed.Add(listBox3.SelectedItem.ToString()); value.PlayedAgainst.Add(listBox1.SelectedItem.ToString()); } } if (checkBox1.Checked) { Program.week++; } if (File.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\week" + Program.week + ".csv")) { string lineOfText; var filestream = new FileStream(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\week" + Program.week + ".csv", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var file = new StreamReader(filestream, Encoding.UTF8, true, 128); while ((lineOfText = file.ReadLine()) != null) { // splits the values MatchUp newItem = new MatchUp(); string[] elements = lineOfText.Split(','); //assign values newItem.Time = elements[0]; newItem.TeamName = elements[1]; newItem.OpponentTeamName = elements[2]; // add to main list Program.matchUpListFinal.Add(newItem); } filestream.Close(); } // make some kind of match record MatchUp temp = new MatchUp(); temp.Time = listBox3.SelectedItem.ToString(); temp.TeamName = listBox1.SelectedItem.ToString(); temp.OpponentTeamName = listBox2.SelectedItem.ToString(); Program.matchUpListFinal.Add(temp); WriteBackData.writeBackData(); this.Close(); } }
private void pictureBox1_Click(object sender, EventArgs e) { LoadTeamData.loadTeamData(); foreach (Team value in Program.itemList) { value.LSOP = 0; value.GamesPlayed = 0; value.Byes = 0; } Program.week = 0; WriteBackData.writeBackData(); // if not exist create a folder if (!Directory.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp")) { Directory.CreateDirectory(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp"); } File.Copy(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\teams.csv", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp\\teams.csv"); File.Copy(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\settings.csv", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp\\settings.csv"); foreach (var sourceFilePath in Directory.GetFiles(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\", "*.csp")) { string fileName = Path.GetFileName(sourceFilePath); string destinationFilePath = Path.Combine(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp\\", fileName); System.IO.File.Copy(sourceFilePath, destinationFilePath, true); } Array.ForEach(Directory.GetFiles(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\"), File.Delete); File.Copy(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp\\teams.csv", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\teams.csv"); File.Copy(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp\\settings.csv", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\settings.csv"); foreach (var sourceFilePath in Directory.GetFiles(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp\\", "*.csp")) { string fileName = Path.GetFileName(sourceFilePath); string destinationFilePath = Path.Combine(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\", fileName); System.IO.File.Copy(sourceFilePath, destinationFilePath, true); } if (Directory.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp")) { Array.ForEach(Directory.GetFiles(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\"), File.Delete); } System.IO.DirectoryInfo di = new DirectoryInfo(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\temp\\"); foreach (FileInfo file in di.GetFiles()) { file.Delete(); } foreach (DirectoryInfo dir in di.GetDirectories()) { dir.Delete(true); } // copy team and settings // del all .csv // copy back files this.Close(); }
private void AddNewTeam() { // creates a new team and adds can't play times (if any) try { Program.currentTeamName = textBox1.Text.ToString(); Team value = new Team(); value.TeamName = Program.currentTeamName; if (checkBox1.Checked) { value.CantPlay.Add(Program.settingsList[0].GameTime); } if (checkBox2.Checked) { value.CantPlay.Add(Program.settingsList[1].GameTime); } if (checkBox3.Checked) { value.CantPlay.Add(Program.settingsList[2].GameTime); } if (checkBox4.Checked) { value.CantPlay.Add(Program.settingsList[4].GameTime); } if (checkBox5.Checked) { value.CantPlay.Add(Program.settingsList[4].GameTime); } if (checkBox6.Checked) { value.CantPlay.Add(Program.settingsList[5].GameTime); } if (checkBox7.Checked) { value.CantPlay.Add(Program.settingsList[6].GameTime); } if (checkBox8.Checked) { value.CantPlay.Add(Program.settingsList[7].GameTime); } Program.itemList.Add(value); WriteBackData.writeBackData(); // Lsop still not added } catch (Exception) { // not a string } }
// edit another team button private void pictureBox1_Click(object sender, EventArgs e) { Program.currentTeamName = listBox1.SelectedItem.ToString(); foreach (Team value in Program.itemList) { if (value.TeamName == Program.currentTeamName) { value.CantPlay.Clear(); if (checkBox1.Checked && Program.settingsList[0].GameTime != null) { value.CantPlay.Add(Program.settingsList[0].GameTime); } if (checkBox2.Checked && Program.settingsList[1].GameTime != null) { value.CantPlay.Add(Program.settingsList[1].GameTime); } if (checkBox3.Checked && Program.settingsList[2].GameTime != null) { value.CantPlay.Add(Program.settingsList[2].GameTime); } if (checkBox4.Checked && Program.settingsList[3].GameTime != null) { value.CantPlay.Add(Program.settingsList[3].GameTime); } if (checkBox5.Checked && Program.settingsList[4].GameTime != null) { value.CantPlay.Add(Program.settingsList[4].GameTime); } if (checkBox6.Checked && Program.settingsList[5].GameTime != null) { value.CantPlay.Add(Program.settingsList[5].GameTime); } if (checkBox7.Checked && Program.settingsList[6].GameTime != null) { value.CantPlay.Add(Program.settingsList[6].GameTime); } if (checkBox8.Checked && Program.settingsList[7].GameTime != null) { value.CantPlay.Add(Program.settingsList[7].GameTime); } WriteBackData.writeBackData(); } } this.Close(); EditTeam editTeam = new EditTeam(); editTeam.ShowDialog(); }
private void pictureBox1_Click(object sender, EventArgs e) { if (listBox1.SelectedItem != null) { Program.currentTeamName = listBox1.SelectedItem.ToString(); List <Team> temp = new List <Team>(); foreach (Team value in Program.itemList) { if (value.TeamName != Program.currentTeamName) { temp.Add(value); } } File.Delete(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "PA.csv"); File.Delete(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "TP.csv"); File.Delete(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "CP.csp"); Program.itemList = temp; WriteBackData.writeBackData(); this.Close(); } }
// done button private void pictureBox2_Click(object sender, EventArgs e) { int fail = 0; try { List <Settings> tmpLst = new List <Settings>(); if (textBox1.Text != "" && textBox2.Text == "" || textBox1.Text == "" && textBox2.Text != "") { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); fail++; } if (textBox1.Text != "" && textBox2.Text != "") { Settings value = new Settings(); value.GameTime = textBox1.Text; value.NumberOfGameAtThatTime = Int32.Parse(textBox2.Text); tmpLst.Add(value); } if (fail == 0) { if (textBox3.Text != "" && textBox4.Text == "" || textBox3.Text == "" && textBox4.Text != "") { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); fail++; } } if (textBox3.Text != "" && textBox4.Text != "") { Settings value = new Settings(); value.GameTime = textBox3.Text; value.NumberOfGameAtThatTime = Int32.Parse(textBox4.Text); tmpLst.Add(value); } if (fail == 0) { if (textBox5.Text != "" && textBox6.Text == "" || textBox5.Text == "" && textBox6.Text != "") { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); fail++; } } if (textBox5.Text != "" && textBox6.Text != "") { Settings value = new Settings(); value.GameTime = textBox5.Text; value.NumberOfGameAtThatTime = Int32.Parse(textBox6.Text); tmpLst.Add(value); } if (fail == 0) { if (textBox7.Text != "" && textBox8.Text == "" || textBox7.Text == "" && textBox8.Text != "") { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); fail++; } } if (textBox7.Text != "" && textBox8.Text != "") { Settings value = new Settings(); value.GameTime = textBox7.Text; value.NumberOfGameAtThatTime = Int32.Parse(textBox8.Text); tmpLst.Add(value); } if (fail == 0) { if (textBox9.Text != "" && textBox10.Text == "" || textBox9.Text == "" && textBox10.Text != "") { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); fail++; } } if (textBox9.Text != "" && textBox10.Text != "") { Settings value = new Settings(); value.GameTime = textBox9.Text; value.NumberOfGameAtThatTime = Int32.Parse(textBox10.Text); tmpLst.Add(value); } if (fail == 0) { if (textBox11.Text != "" && textBox12.Text == "" || textBox11.Text == "" && textBox12.Text != "") { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); fail++; } } if (textBox11.Text != "" && textBox12.Text != "") { Settings value = new Settings(); value.GameTime = textBox11.Text; value.NumberOfGameAtThatTime = Int32.Parse(textBox12.Text); tmpLst.Add(value); } if (fail == 0) { if (textBox13.Text != "" && textBox14.Text == "" || textBox13.Text == "" && textBox14.Text != "") { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); fail++; } } if (textBox13.Text != "" && textBox14.Text != "") { Settings value = new Settings(); value.GameTime = textBox13.Text; value.NumberOfGameAtThatTime = Int32.Parse(textBox14.Text); tmpLst.Add(value); } if (fail == 0) { if (textBox15.Text != "" && textBox16.Text == "" || textBox15.Text == "" && textBox16.Text != "") { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); fail++; } } if (textBox15.Text != "" && textBox16.Text != "") { Settings value = new Settings(); value.GameTime = textBox15.Text; value.NumberOfGameAtThatTime = Int32.Parse(textBox16.Text); tmpLst.Add(value); } if (fail == 0) { // check if a timeslot has been removed // remove timeslot from cantplay files LoadTeamData.loadTeamData(); foreach (Settings value in Program.settingsList) { if (value.GameTime != textBox1.Text && value.GameTime != textBox3.Text && value.GameTime != textBox5.Text && value.GameTime != textBox7.Text && value.GameTime != textBox9.Text && value.GameTime != textBox11.Text && value.GameTime != textBox13.Text && value.GameTime != textBox15.Text) { Program.currentGameTime = value.GameTime; foreach (Team team in Program.itemList) { List <string> temp = new List <string>(); foreach (string str in team.CantPlay) { if (str != Program.currentGameTime) { temp.Add(str); } } team.CantPlay = temp; } } } WriteBackData.writeBackData(); List <Settings> settingsTemp = tmpLst.OrderBy(o => o.GameTime).ToList(); Program.settingsList = settingsTemp; WriteSettingsData.writeSettingsData(); this.Close(); } } catch (Exception) { if (fail == 0) { SettingsError settingsError = new SettingsError(); settingsError.ShowDialog(); } } }
private void pictureBox2_Click(object sender, EventArgs e) { if (textBox1.Text != "") { if (File.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "PA.csv")) { File.Move(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "PA.csv", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + textBox1.Text + "PA.csv"); } if (File.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "TP.csv")) { File.Move(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "TP.csv", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + textBox1.Text + "TP.csv"); } if (File.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "CP.csp")) { File.Move(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + Program.currentTeamName + "CP.csp", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\" + textBox1.Text + "CP.csp"); } if (File.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + Program.currentTeamName + "PA.csv")) { File.Move(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + Program.currentTeamName + "PA.csv", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + textBox1.Text + "PA.csv"); } if (File.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + Program.currentTeamName + "TP.csv")) { File.Move(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + Program.currentTeamName + "TP.csv", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + textBox1.Text + "TP.csv"); } if (File.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + Program.currentTeamName + "CP.csp")) { File.Move(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + Program.currentTeamName + "CP.csp", @Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\backup\\" + textBox1.Text + "CP.csp"); } // address problem if team is on forced bye list Program.forcedByeList.Clear(); if (File.Exists(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\bye.csv")) { var filestream = new FileStream(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\bye.csv", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var file = new StreamReader(filestream, Encoding.UTF8, true, 128); string lineOfText; while ((lineOfText = file.ReadLine()) != null) { foreach (Team value in Program.itemList) { if (lineOfText == value.TeamName) { Program.forcedByeList.Add(value); } } } filestream.Close(); } // check if team is in bye list // if so change team name foreach (Team value in Program.forcedByeList) { if (value.TeamName == Program.currentTeamName) { value.TeamName = textBox1.Text.ToString(); } } using (TextWriter tw = new StreamWriter(@Program.filePath + Program.currentSport + "\\" + Program.currentLeague + "\\bye.csv")) { foreach (Team value in Program.forcedByeList) { tw.WriteLine(value.TeamName); } } foreach (Team value in Program.itemList) { if (Program.currentTeamName == value.TeamName) { value.TeamName = textBox1.Text.ToString(); } } WriteBackData.writeBackData(); this.Close(); // still need to update teams file in backup with renamed teams name? meh } }