Exemplo n.º 1
0
        /*
         *   NAME
         *
         *        IO::Import - Imports the data from a file
         *
         *   SYNOPSIS
         *
         *        void Import(string filename);
         *
         *             filename      --> the name of the file to import
         *
         *   DESCRIPTION
         *
         *        This function contains the brunt of the importing work. It takes a filename,
         *        reads the file line by line and converts it into data to be stored on the database.
         */
        private static void Import(string filename)
        {
            StreamReader reader = new StreamReader(filename);
            int          count  = 0;
            string       line;

            while ((line = reader.ReadLine()) != null) //https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-read-a-text-file-one-line-at-a-time
            {
                if (count == 0)                        //if we are on the first line, then it is student data
                {
                    try
                    {
                        Student import_student = String_To_Student(line);
                        Database_Interface.Add_Student(import_student);
                    }
                    catch (Exception e)
                    {
                        new Log(e, "IO.cs: Import.", "Could not import file.");
                        MessageBox.Show("Error importing student.");
                        return;
                    }
                }
                else if (line.Substring(0, 4).ToLower() == "note")
                {
                    Note import_note = String_To_Note(line);
                    Database_Interface.Add_Note(import_note);
                }
                else if (line.Substring(0, 4).ToLower() == "hist")
                {
                    History_Entry import_entry = String_To_History_Entry(line);
                    Database_Interface.Add_History(import_entry);
                }
                count++;
            }
        }
Exemplo n.º 2
0
        /*
         *   NAME
         *
         *        IO::String_To_History_Entry - Imports the data from a file
         *
         *   SYNOPSIS
         *
         *        History_Entry String_To_History_Entry(string line);
         *
         *             line      --> the line of text from an import file
         *
         *   DESCRIPTION
         *
         *        This function converts a line of text from a file to a history entry object and returns it.
         *
         *   RETURNS
         *
         *        History_Entry object containing the data from the file.
         */
        private static History_Entry String_To_History_Entry(string line)
        {
            try
            {
                History_Entry temp   = new History_Entry();
                string[]      values = line.Split(',');

                temp.id          = Convert.ToInt32(values[1]);
                temp.student_id  = Convert.ToInt32(values[2]);
                temp.date        = values[3];
                temp.current_lvl = Convert.ToChar(values[4]);

                return(temp);
            }
            catch (Exception e)
            {
                new Log(e, "IO.cs: String_To_History_Entry.", "Error loading history entry.");
            }

            return(null);
        }