コード例 #1
0
 //Import the data from csv file chosen
 private void btnImport_Click(object sender, EventArgs e)
 {
     if (openFileDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             var    fileName = openFileDialog.FileName;
             string error    = "";
             if (Helpers.FileAccess.ValidateFormat(fileName))
             {
                 _peoplelist = People_Class.ReadAllPeople(fileName, out error);
                 if (string.IsNullOrEmpty(error))//File imported succesfully
                 {
                     toolStripStatusLabel.Text = "File Imported Succesfully";
                     dataGridView1.DataSource  = _peoplelist;
                     SetVisibility();
                 }
                 else
                 {
                     toolStripStatusLabel.Text = error;
                 }
             }
             else
             {
                 toolStripStatusLabel.Text = "File format incorrect, [Name, Surname, Address]";
             }
         }
         catch (Exception ex)
         {
             toolStripStatusLabel.Text = ex.Message;
         }
     }
 }
コード例 #2
0
        public void TestMissingData()
        {
            string file = System.IO.Path.GetFullPath(@"..\..\..\Data\\MissingData.csv");

            if (FileAccess.ValidateFormat(file))
            {
                string error = null;
                if (FileAccess.ValidateFormat(file))
                {
                    People_Class.ReadAllPeople(file, out error);
                }
                Assert.AreEqual("Index was outside the bounds of the array.", error);
            }
        }
コード例 #3
0
        public void TestResults()
        {
            string file = System.IO.Path.GetFullPath(@"..\..\..\Data\\data.csv");

            if (FileAccess.ValidateFormat(file))
            {
                string error = null;
                People_Class.ReadAllPeople(file, out error);

                List <string> expectedFirstNameList = new List <string>();
                expectedFirstNameList.AddRange(new string[] { "Iago Tieman", "Cordie Bleibaum", "Shandie Rowles", "Genny Seys", "Renault Millichap", "Shandie Rowles", "Iago Tieman", "Genny Seys", "Iago Tieman" });
                List <string> expectedAddressList = new List <string>();
                expectedAddressList.AddRange(new string[] { "42 Basil Park", "74584 Moose Parkway", "81075 Killdeer Road", "2 Nova Circle", "32 Butterfield Drive" });

                List <string> actualFirstNameList = People_Class.GetFullNameList();
                List <string> actualAddressList   = People_Class.GetAddressList();

                CollectionAssert.AreEqual(expectedFirstNameList, actualFirstNameList);
                CollectionAssert.AreEqual(expectedAddressList, actualAddressList);
            }
        }
コード例 #4
0
        //Populate the addresses alphabetically of the items passed from the csv file, populate to grid and ask to open file
        private void btnAlphabetically_Click(object sender, EventArgs e)
        {
            var addresses = Sorter.GetAsendingListIgnoringNumbers(People_Class.GetAddressList());

            dataGridView1.DataSource = addresses.Select(x => new { Address = x }).ToList();

            string error = null;

            Helpers.FileAccess.WriteAllLines(_file2, addresses.ToArray(), out error);

            if (string.IsNullOrEmpty(error))
            {
                if (MessageBox.Show("File generated succesfully, would you like to open the file now?", "Open File", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    Process.Start("notepad.exe", _file2);
                }
            }
            else
            {
                toolStripStatusLabel.Text = error;
            }
        }
コード例 #5
0
        //Populate the count of the items passed from the csv file, populate to grid and ask to open file
        private void btnPopularity_Click(object sender, EventArgs e)
        {
            var firstNameSurnameCount = Sorter.GetWordCountDescendingOrder(People_Class.GetFullNameList());
            var names = (from row in firstNameSurnameCount select new { Name = row.Key, Count = row.Value });

            dataGridView1.DataSource = names.ToList();

            string error = null;

            Helpers.FileAccess.WriteAllLines(_file1, names.Select(x => x.Name + "\t" + x.Count), out error);

            if (string.IsNullOrEmpty(error))
            {
                toolStripStatusLabel.Text = "File with Names Count generated";
                if (MessageBox.Show("File generated succesfully, would you like to open the file now?", "Open File", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    Process.Start("notepad.exe", _file1);
                }
            }
            else
            {
                toolStripStatusLabel.Text = error;
            }
        }