Ejemplo 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++;
            }
        }
Ejemplo n.º 2
0
        /*
         * NAME
         *
         *       Class_Form::New_Student_Click - Verifies a student and sends him or her to the database.
         *
         * SYNOPSIS
         *
         *        void New_Student_Click(object sender, EventArgs e);
         *
         *          sender           --> the object sending the event.
         *          e                --> the event arguments.
         *
         * DESCRIPTION
         *
         *      Pulls the student data from the textboxes and verifies that the student is valid.
         *      Alerts user if student already exists, and asks for further action. If the student passes the checks,
         *      the function sends the student to the database.
         */
        private void New_Student_Click(object sender, EventArgs e)    //https://stackoverflow.com/questions/3036829/how-do-i-create-a-message-box-with-yes-no-choices-and-a-dialogresult
        {
            //Get all values from textbox
            Student new_student = Textboxes_To_Student();

            //if part of student is incorrect, do nothing! Let user edit and try again.
            if (new_student.FirstName == "" || new_student.LastName == "" || !Regex.IsMatch(new_student.StartLevel.ToString(), @"^[A-Z]+$") || !Regex.IsMatch(new_student.CurrentLevel.ToString(), @"^[A-Z]+$") || !Regex.IsMatch(new_student.GoalLevel.ToString(), @"^[A-Z]+$"))
            {
                return;
            }

            if (Database_Interface.Query_Student_Exist(new_student.FirstName, new_student.LastName))   //if student already exists...
            {
                DialogResult dialog = MessageBox.Show("Student already exists. Would you like to update their records?", "Student already exists", MessageBoxButtons.YesNo);
                if (dialog == DialogResult.Yes)
                {
                    Database_Interface.Update_Student(new_student);
                }
                else if (dialog == DialogResult.No)
                {
                    return;      //close dialog and do nothing
                }
            }
            else if (cf_id.Text != "")
            {
                Database_Interface.Update_Student(new_student);
            }
            else
            {
                Database_Interface.Add_Student(new_student);
            }

            Clear_TextBoxes();
            Refresh_Data_Grid_View();
        }