Пример #1
0
        private void MainWindow_OnLoaded(object sender, EventArgs e)
        {
            try
            {
                //use a reader to get text from txt file
                StreamReader sr = new StreamReader("BabyNames.txt");

                while (!sr.EndOfStream)
                {
                    //read one line at a time
                    var CurrentLine = sr.ReadLine();
                    //make new baby
                    BabyName currentBaby = new BabyName(CurrentLine);
                    //add to list
                    babies.Add(currentBaby);
                }
                //shows the total loaded babies
                MainLSTDecadeTopNames.Items.Add("total: " + babies.Count + " Babies");

                //add decade selections
                for (int i = 1900; i <= 2000; i += 10)
                {
                    MainLSTDecadeSelect.Items.Add(i);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error loading text file, put BabyNames.txt in \"bin/debug/\"");
            }
        }
Пример #2
0
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            var fs = new FileStream("../../babynames.txt", FileMode.Open);
            var sr = new StreamReader(fs, Encoding.Default);

            string line;

            while ((line = sr.ReadLine()) != null)
            {
                Console.WriteLine(line);
                var bab = new BabyName(line);
                _babyNames.Add(bab);
            }


            foreach (var babyName in _babyNames)
            {
                for (var i = 0; i < 11; i++)
                {
                    var rank = babyName.Rank((i * 10) + 1900);

                    if ((rank <= 10) && (rank > 0))
                    {
                        if (string.IsNullOrEmpty(_topTenArray[i, rank - 1, 0]))
                        {
                            _topTenArray[i, rank - 1, 0] = babyName.Name;
                        }
                        else
                        {
                            _topTenArray[i, rank - 1, 1] = babyName.Name;
                        }
                    }
                }
            }
        }
Пример #3
0
        private void ListDecadeTopNames_Loaded(object sender, RoutedEventArgs e)
        {
            bool         fileFound = true;
            string       filePath  = @".\babynames.txt";
            FileStream   fs        = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            StreamReader sr        = new StreamReader(fs, Encoding.Default);

            BabyName babyName;

            try
            {
                while (!sr.EndOfStream)
                {
                    string str = sr.ReadLine();
                    decadeTopNames.Add(str);
                    babyName = new BabyName(str);
                    babyNames.Add(babyName);
                }
            }

            catch
            {
                MessageBox.Show("Error loading baby names");
                fileFound = false;
            }

            if (fileFound)
            {
                foreach (BabyName name in babyNames)
                {
                    for (int decade = 1900; decade <= 2000; decade += 10)
                    {
                        int rank = name.Rank(decade);
                        if (rank > 0 && rank < 11)
                        {
                            int decadeIndex = (decade - 1900) / 10;
                            if (rankMatrix[decadeIndex, rank - 1] == null)
                            {
                                rankMatrix[decadeIndex, rank - 1] = name.Name;
                            }
                            else
                            {
                                rankMatrix[decadeIndex, rank - 1] += " and " + name.Name;
                            }
                        }
                    }
                }
            }
        }