/// <summary>Handles the Click event of the btnAdd control. Allows the user to add teams or players the database.</summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="RoutedEventArgs" /> instance containing the event data. /// </param> private async void btnAdd_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(CurrentDB)) { return; } if (Tf.IsBetween) { IsEnabled = false; Tf = new Timeframe(CurSeason); await UpdateAllData(); IsEnabled = true; } AddInfo = ""; var aw = new AddWindow(ref PST); aw.ShowDialog(); if (!String.IsNullOrEmpty(AddInfo)) { if (AddInfo != "$$NST Players Added") { var parts = Tools.SplitLinesToArray(AddInfo); var newTeams = parts.Where(s => !String.IsNullOrWhiteSpace(s)).ToList(); var oldlen = TST.Count; if (SQLiteIO.IsTSTEmpty()) { oldlen = 0; } for (var i = 0; i < newTeams.Count; i++) { if (TST.Count(pair => pair.Value.Name == newTeams[i]) == 1) { MessageBox.Show( "There's a team with the name " + newTeams[i] + " already in the database so it won't be added again."); continue; } var newid = oldlen + i; TST[newid] = new TeamStats(newid, newTeams[i]); TSTOpp[newid] = new TeamStats(newid, newTeams[i]); } await saveAndReloadSeason(); UpdateStatus("Teams were added, database saved."); } else { await saveAndReloadSeason(); UpdateStatus("Players were added, database saved."); } } }
/// <summary> /// Handles the Click event of the btnAdd control. /// Allows the user to add teams or players the database. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e"> /// The <see cref="RoutedEventArgs" /> instance containing the event data. /// </param> private void btnAdd_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrEmpty(CurrentDB)) { return; } AddInfo = ""; var aw = new AddWindow(ref PST); aw.ShowDialog(); if (!String.IsNullOrEmpty(AddInfo)) { if (AddInfo != "$$NST Players Added") { string[] parts = Tools.SplitLinesToArray(AddInfo); List<string> newTeams = parts.Where(s => !String.IsNullOrWhiteSpace(s)).ToList(); int oldlen = TST.Count; if (SQLiteIO.IsTSTEmpty()) { oldlen = 0; } for (int i = 0; i < newTeams.Count; i++) { if (TST.Count(pair => pair.Value.Name == newTeams[i]) == 1) { MessageBox.Show("There's a team with the name " + newTeams[i] + " already in the database so it won't be added again."); continue; } int newid = oldlen + i; TST[newid] = new TeamStats(newid, newTeams[i]); TSTOpp[newid] = new TeamStats(newid, newTeams[i]); } SQLiteIO.SaveSeasonToDatabase(); UpdateStatus("Teams were added, database saved."); } else { SQLiteIO.SavePlayersToDatabase(CurrentDB, PST, CurSeason, SQLiteIO.GetMaxSeason(CurrentDB)); UpdateStatus("Players were added, database saved."); } } }