Beispiel #1
0
        protected int FindSchoolId(Schools schools, string schoolName, string team)
        {
            int id = schools["TOBy"].id;

            if (schoolName != team)
            {
                var school = schools[schoolName];
                if (school != null)
                {
                    id = school.id;
                }
                else
                {
                    var schoolNames = new List <string> ();
                    schools.ForEach(s => schoolNames.Add(s.name));
                    var teamNameFound = false;

                    foreach (var s in schoolNames)
                    {
                        if (s.StartsWith(schoolName))
                        {
                            var result = MessageBox.Show(
                                string.Format("Is {0} the same as {1}", schoolName, s),
                                "Matching " + team,
                                MessageBoxButtons.YesNoCancel);

                            if (result == DialogResult.Yes)
                            {
                                teamNameFound = true;
                                id            = schools[s].id;
                            }
                            else if (result == DialogResult.Cancel)
                            {
                                teamNameFound = true;
                            }
                        }
                    }

                    while (!teamNameFound && (schoolNames.Count > 0))
                    {
                        var closestString = lblRedTeam.Text.ClosestMatchingString(schoolNames);
                        var result        = MessageBox.Show(
                            string.Format("Is {0} the same as {1}", schoolName, closestString),
                            "Matching " + team,
                            MessageBoxButtons.YesNoCancel);

                        if (result == DialogResult.Yes)
                        {
                            teamNameFound = true;
                            id            = schools[closestString].id;
                        }
                        else if (result == DialogResult.Cancel)
                        {
                            teamNameFound = true;
                        }
                        else
                        {
                            schoolNames.Remove(closestString);
                        }
                    }
                }
            }

            return(id);
        }