Beispiel #1
0
        private void ScoreTableData(string Player, double time)
        {
            // Save the Player and time under the variable userAndTime.
            string userAndTime = Player + "-" + time;

            // Save the information from this file as the variable filePath.
            string filePath = FileLocationManager.GetFileTime();

            // If filePath does not exist...
            if (!File.Exists(filePath))
            {
                // Create a new instance of the FileStream class and call it aFile. Create a new file.
                FileStream aFile = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                // Create a new instance of the StreamWriter class and call it sw. Pass aFile into this class.
                StreamWriter sw = new StreamWriter(aFile);
                // Write the userAndTime to sw.
                sw.WriteLine(userAndTime);
                // Close sw.
                sw.Close();
                // Close aFile.
                aFile.Close();
            }
            // Otherwise...
            else
            {
                // Create a new instance of the FileStream class and call it aFile. Add to the existing file.
                FileStream aFile = new FileStream(filePath, FileMode.Append, FileAccess.Write);
                // Create a new instance of the StreamWriter class and call it sw. Pass aFile into this class.
                StreamWriter sw = new StreamWriter(aFile);
                // Write the userAndTime to sw.
                sw.WriteLine(userAndTime);
                // Close sw.
                sw.Close();
                // Close aFile.
                aFile.Close();
            }
        }
Beispiel #2
0
        private void ShowResults()
        {
            // Create a new List call it column and populate it with the information below.
            List <string> column = new List <string>()
            {
                "Name", "Time (sec)"
            };
            // Create a new List and call it Row.
            List <string[]> Row = new List <string[]>();

            // Create a new two-dimensional string array and call it timeArray.
            string[,] timeArray;
            // Create a new string array and call it users.
            string[] users = new string[0];

            // If this file exists...
            if (File.Exists(FileLocationManager.GetFileTime()))
            {
                // Pass the information from this file into users.
                users = File.ReadLines(FileLocationManager.GetFileTime()).ToArray();
            }

            // Add the information from the users array.
            timeArray = new string[users.Length, 2];

            // Create a for loop.
            for (int i = 0; i < users.Length; i++)
            {
                // For every piece of information from the users array, split the name and time using a '-'.
                string[] userNameAndTime = users[i].Split('-');

                // Assign the appropiate information to the appropiate place in the table.
                timeArray[i, 0] = userNameAndTime[0];
                timeArray[i, 1] = userNameAndTime[1];
            }

            // Create another for loop.
            for (int i = 0; i < users.Length; i++)
            {
                // Add a new row. Create a new array and display the information that was split above.
                Row.Add(new string[] { timeArray[i, 0], timeArray[i, 1].ToString() });
            }

            // Create a new instance of the DataTable class and call it table.
            DataTable table = new DataTable();

            // Create a foreach statement.
            foreach (string text in column)
            {
                // Add the text into the column.
                table.Columns.Add(text);
            }

            // Create another foreach statement.
            foreach (string[] cell in Row)
            {
                // Add the cell into the row.
                table.Rows.Add(cell);
            }

            // Show the dataScoreTable.
            dataScoreTable.DataSource = table.AsDataView();
            dataScoreTable.Sort(dataScoreTable.Columns["Time (sec)"], ListSortDirection.Ascending);
        }