コード例 #1
0
        /// <summary>
        ///     Handles the Click event of the btnOK control. The conference is renamed, the divisions are deleted and recreated, and if any
        ///     teams are left in division IDs that no longer exist, they get reassigned.
        /// </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 btnOK_Click(object sender, RoutedEventArgs e)
        {
            var db = new SQLiteDatabase(MainWindow.CurrentDB);
            if (String.IsNullOrWhiteSpace(txtName.Text))
            {
                txtName.Text = "League";
            }

            MainWindow.Conferences.Single(conference => conference.ID == _curConf.ID).Name = txtName.Text;
            db.Update("Conferences", new Dictionary<string, string> { { "Name", txtName.Text } }, "ID = " + _curConf.ID);

            MainWindow.Divisions.RemoveAll(division => division.ConferenceID == _curConf.ID);
            db.Delete("Divisions", "Conference = " + _curConf.ID);

            var usedIDs = new List<int>();
            db.GetDataTable("SELECT ID FROM Divisions")
              .Rows.Cast<DataRow>()
              .ToList()
              .ForEach(row => usedIDs.Add(ParseCell.GetInt32(row, "ID")));

            var list = Tools.SplitLinesToList(txtDivisions.Text, false);
            foreach (var newDiv in list)
            {
                var newName = newDiv.Replace(':', '-');
                var i = 0;
                while (usedIDs.Contains(i))
                {
                    i++;
                }
                MainWindow.Divisions.Add(new Division { ID = i, Name = newName, ConferenceID = _curConf.ID });
                usedIDs.Add(i);
            }

            if (MainWindow.Divisions.Any(division => division.ConferenceID == _curConf.ID) == false)
            {
                var i = 0;
                while (usedIDs.Contains(i))
                {
                    i++;
                }
                MainWindow.Divisions.Add(new Division { ID = i, Name = txtName.Text, ConferenceID = _curConf.ID });
                usedIDs.Add(i);
            }

            foreach (var div in MainWindow.Divisions.Where(division => division.ConferenceID == _curConf.ID))
            {
                db.Insert(
                    "Divisions",
                    new Dictionary<string, string>
                        {
                            { "ID", div.ID.ToString() },
                            { "Name", div.Name },
                            { "Conference", div.ConferenceID.ToString() }
                        });
            }

            TeamStats.CheckForInvalidDivisions();

            ListWindow.MustUpdate = true;
            Close();
        }
コード例 #2
0
        /// <summary>Checks for teams in divisions that don't exist anymore, and reassings them to the first available division.</summary>
        public static void CheckForInvalidDivisions()
        {
            var db = new SQLiteDatabase(MainWindow.CurrentDB);
            var usedIDs = new List<int>();
            db.GetDataTable("SELECT ID FROM Divisions")
              .Rows.Cast<DataRow>()
              .ToList()
              .ForEach(row => usedIDs.Add(ParseCell.GetInt32(row, "ID")));

            var teamsChanged = new List<string>();

            var maxSeason = SQLiteIO.GetMaxSeason(MainWindow.CurrentDB);
            for (var i = maxSeason; i >= 1; i--)
            {
                var teamsT = "Teams";
                var plTeamsT = "PlayoffTeams";
                var oppT = "Opponents";
                var plOppT = "PlayoffOpponents";
                if (i != maxSeason)
                {
                    var toAdd = "S" + i;
                    teamsT += toAdd;
                    plTeamsT += toAdd;
                    oppT += toAdd;
                    plOppT += toAdd;
                }

                var tables = new List<string> { teamsT, plTeamsT, oppT, plOppT };
                foreach (var table in tables)
                {
                    var q = "SELECT ID, Name, Division FROM " + table;
                    var res = db.GetDataTable(q);

                    foreach (DataRow r in res.Rows)
                    {
                        if (usedIDs.Contains(ParseCell.GetInt32(r, "Division")) == false)
                        {
                            db.Update(
                                table,
                                new Dictionary<string, string> { { "Division", MainWindow.Divisions.First().ID.ToString() } },
                                "ID = " + ParseCell.GetString(r, "ID"));
                            var teamid = MainWindow.TST.Values.Single(ts => ts.Name == ParseCell.GetString(r, "Name")).ID;
                            MainWindow.TST[teamid].Division = MainWindow.Divisions.First().ID;
                            if (teamsChanged.Contains(MainWindow.TST[teamid].DisplayName) == false)
                            {
                                teamsChanged.Add(MainWindow.TST[teamid].DisplayName);
                            }
                        }
                    }
                }
            }

            if (teamsChanged.Count > 0)
            {
                teamsChanged.Sort();
                var s = "Some teams were in divisions that were deleted and have been reset to the "
                        + MainWindow.Divisions.First().Name + " division.\n\n";
                teamsChanged.ForEach(s1 => s += s1 + "\n");
                s = s.TrimEnd(new[] { '\n' });
                SQLiteIO.SaveSeasonToDatabase();
                MessageBox.Show(s);
            }
        }
コード例 #3
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (_mode == Mode.HiddenTeams)
            {
                var db = new SQLiteDatabase(_currentDB);

                var teamsT = "Teams";
                var plTeamsT = "PlayoffTeams";
                var oppT = "Opponents";
                var plOppT = "PlayoffOpponents";
                if (_curSeason != _maxSeason)
                {
                    var s = "S" + _curSeason;
                    teamsT += s;
                    plTeamsT += s;
                    oppT += s;
                    plOppT += s;
                }

                foreach (string name in lstEnabled.Items)
                {
                    var dict = new Dictionary<string, string> { { "isHidden", "False" } };
                    db.Update(teamsT, dict, "DisplayName LIKE \"" + name + "\"");
                    db.Update(plTeamsT, dict, "DisplayName LIKE \"" + name + "\"");
                    db.Update(oppT, dict, "DisplayName LIKE \"" + name + "\"");
                    db.Update(plOppT, dict, "DisplayName LIKE \"" + name + "\"");
                }

                foreach (string name in lstDisabled.Items)
                {
                    var q = "select * from GameResults where SeasonNum = " + _curSeason + " AND (Team1ID = "
                            + getTeamIDFromDisplayName(name) + " OR Team2ID = " + getTeamIDFromDisplayName(name) + ")";
                    var res = db.GetDataTable(q);

                    if (res.Rows.Count > 0)
                    {
                        var r = MessageBox.Show(
                            name + " have box scores this season. Are you sure you want to disable this team?",
                            "NBA Stats Tracker",
                            MessageBoxButton.YesNo,
                            MessageBoxImage.Question);

                        if (r == MessageBoxResult.No)
                        {
                            continue;
                        }
                    }

                    var dict = new Dictionary<string, string> { { "isHidden", "True" } };
                    db.Update(teamsT, dict, "DisplayName LIKE \"" + name + "\"");
                    db.Update(plTeamsT, dict, "DisplayName LIKE \"" + name + "\"");
                    db.Update(oppT, dict, "DisplayName LIKE \"" + name + "\"");
                    db.Update(plOppT, dict, "DisplayName LIKE \"" + name + "\"");
                }

                MainWindow.AddInfo = "$$TEAMSENABLED";
                Close();
            }
            else if (_mode == Mode.HiddenPlayers)
            {
                var db = new SQLiteDatabase(_currentDB);

                var dataList = new List<Dictionary<string, string>>();
                var whereList = new List<string>();

                foreach (KeyValuePair<int, string> item in lstEnabled.Items)
                {
                    var dict = new Dictionary<string, string> { { "isHidden", "False" } };
                    dataList.Add(dict);
                    whereList.Add("ID = " + item.Key);
                }
                db.UpdateManyTransaction(_playersT, dataList, whereList);

                dataList = new List<Dictionary<string, string>>();
                whereList = new List<string>();
                foreach (KeyValuePair<int, string> item in lstDisabled.Items)
                {
                    var q =
                        "select * from PlayerResults INNER JOIN GameResults ON GameResults.GameID = PlayerResults.GameID where SeasonNum = "
                        + _curSeason + " AND PlayerID = " + item.Key;
                    var res = db.GetDataTable(q, true);

                    if (res.Rows.Count > 0)
                    {
                        var r = MessageBox.Show(
                            item.Value + " has box scores this season. Are you sure you want to disable them?",
                            "NBA Stats Tracker",
                            MessageBoxButton.YesNo,
                            MessageBoxImage.Question);

                        if (r == MessageBoxResult.No)
                        {
                            continue;
                        }
                    }

                    var dict = new Dictionary<string, string> { { "isHidden", "True" }, { "isActive", "False" }, { "TeamFin", "" } };
                    dataList.Add(dict);
                    whereList.Add("ID = " + item.Key);
                }
                db.UpdateManyTransaction(_playersT, dataList, whereList);

                MainWindow.AddInfo = "$$PLAYERSENABLED";
                Close();
            }
            else if (_mode == Mode.REDitor)
            {
                if (lstEnabled.Items.Count != 30)
                {
                    MessageBox.Show(
                        "You can't have less or more than 30 teams enabled. You currently have " + lstEnabled.Items.Count + ".");
                    return;
                }

                //MainWindow.selectedTeams = new List<Dictionary<string, string>>(_activeTeams);
                MainWindow.SelectedTeams = new List<Dictionary<string, string>>();
                foreach (string team in lstEnabled.Items)
                {
                    var teamName = team.Split(new[] { " (ID: " }, StringSplitOptions.None)[0];
                    MainWindow.SelectedTeams.Add(
                        _validTeams.Find(
                            delegate(Dictionary<string, string> t)
                                {
                                    if (t["Name"] == teamName)
                                    {
                                        return true;
                                    }
                                    return false;
                                }));
                }
                MainWindow.SelectedTeamsChanged = _changed;
                DialogResult = true;
                Close();
            }
            else if (_mode == Mode.TradePlayers)
            {
                foreach (var pair in _rosters)
                {
                    var newTeam = pair.Key;
                    foreach (var pID in pair.Value)
                    {
                        var oldTeam = MainWindow.PST[pID].TeamF;
                        var oldTeamS = MainWindow.PST[pID].TeamS;
                        if (newTeam != oldTeam)
                        {
                            if (oldTeamS == -1)
                            {
                                MainWindow.PST[pID].TeamS = MainWindow.PST[pID].TeamF;
                            }
                            MainWindow.PST[pID].TeamF = newTeam;
                            MainWindow.PST[pID].IsSigned = newTeam != -1;
                        }
                    }
                }

                DialogResult = true;
                Close();
            }
        }