/* * 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++; } }
/* * NAME * * Conference_Form::Add_Note_Click - event that triggers when the user clicks the Add Note button. * * SYNOPSIS * * void Add_Note_Click(object sender, EventArgs e); * * sender --> the object sending the event. * e --> the event arguments. * * DESCRIPTION * * This function triggers when the user clicks the Add Note button. * The function first verifies that a student has been selected. * Then, the function creates a new note and sends it to the database. */ private void Add_Note_Click(object sender, EventArgs e) { if (!(Student_Select.SelectedIndex > -1)) { MessageBox.Show("Please select a student.", "Error"); return; } using (New_Note_Form new_note = new New_Note_Form()) { if (new_note.ShowDialog() == DialogResult.OK) { string category = new Conference_Types(new_note.Category).Type; Database_Interface.Add_Note(current_student_id, new_note.Note, category); } } Refresh_Notes(); }