Beispiel #1
0
        private List <string> currentLogins = new List <string>();    //maintains a list of currently logged in students
                                                                      //would be nice if this wasn't global



        /*
         * This function returns the listbox to a full sorted list of all students in the database
         * Much like the other options that take advantage of Valid class SQL queries the
         * performance of this will depend on the student database being maintained as students
         * graduate
         */
        private void OpenFill()
        {
            nameListBox.Items.Clear();
            Valid         openFill     = new Valid();
            List <string> studentNames = new List <string>(openFill.StudentSearch("%"));

            studentNames.Sort();
            if (studentNames.Count > 0)
            {
                for (int i = 0; i < studentNames.Count; i++)
                {
                    nameListBox.Items.Add(studentNames[i]);
                }
            }
        }
Beispiel #2
0
        /*
         * This OpenFill method is functionally similar to the other listbox filling methods throughout
         * the forms, the key difference being this also populates the listbox with StudentIDs for
         * clarity in the removal process
         */
        private void OpenFill()  //populates the student list with the full database of students
        {
            studentListBox.Items.Clear();
            Valid         openFill     = new Valid();
            List <string> studentNames = new List <string>(openFill.StudentSearch("%", true));

            if (studentNames.Count > 0)
            {
                for (int i = 0; i < studentNames.Count; i++)
                {
                    string[] student = studentNames[i].Split(',');
                    studentListBox.Items.Add(student[0].Trim() + ", " + student[1].Trim() + ", " + Utility.Decrypt(student[2], false).Trim());
                }
            }
        }
Beispiel #3
0
        /*
         * The following region is used to update the student name listbox for faster logins
         * It queries the database on text change to match users
         * The size of the DB could cause this function to run slowly if old users aren't pruned
         *
         * The first section is designed to escape apostrophes in user names to not interfere with
         * SQL queries
         * The try block uses a function of the Valid class to retrieve all student entries that
         * partial match the last name entered
         */
        #region ListBoxUpdater
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string name = textBox1.Text;

            if (name.Length == 0)
            {
                name = "%";
            }
            if (name.Length > 1)
            {
                if (name.Contains("'"))
                {
                    for (int i = 0; i < name.Length; i++)
                    {
                        if (name[i] == '\'')
                        {
                            name = name.Insert(i, "\'");
                            i++;
                        }
                    }
                }
            }
            else if (name.Length == 1 && name == "\'")
            {
                name += "'";
            }
            try
            {
                nameListBox.Items.Clear();
                Valid         students     = new Valid();
                List <string> studentNames = new List <string>(students.StudentSearch(name));
                studentNames.Sort();
                if (studentNames.Count > 0)
                {
                    for (int i = 0; i < studentNames.Count; i++)
                    {
                        nameListBox.Items.Add(studentNames[i]);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something is broken in the list fill.", ex.Message);
            }
            //nameListBox.BeginUpdate
        }
Beispiel #4
0
        /*
         * This event handler filters the student list in the same way as the StudentLogin form
         * It carries the same restriction of only filtering by last name
         */
        private void searchBox_TextChanged(object sender, EventArgs e)
        {
            string name = searchBox.Text;

            if (name.Length == 0)   //sends a wildcard to the database for a full list when the search box is empty
            {
                name = "%";
            }
            if (name.Length > 1)    //escape sequence for names with apostrophes
            {
                if (name.Contains("'"))
                {
                    for (int i = 0; i < name.Length; i++)
                    {
                        if (name[i] == '\'')
                        {
                            name = name.Insert(i, "\'");
                            i++;
                        }
                    }
                }
            }
            else if (name.Length == 1 && name == "\'")
            {
                name += "'";
            }
            try
            {
                studentListBox.Items.Clear();
                Valid         students     = new Valid();
                List <string> studentNames = new List <string>(students.StudentSearch(name, true));
                if (studentNames.Count > 0)
                {
                    for (int i = 0; i < studentNames.Count; i++)
                    {
                        string[] student = studentNames[i].Split(',');
                        studentListBox.Items.Add(student[0].Trim() + ", " + student[1].Trim() + ", " + Utility.Decrypt(student[2], false).Trim());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something is broken in the list fill.", ex.Message);
            }
        }
Beispiel #5
0
        /*
         * The following function is called from the Full Database Dump menu item, it retrieves the
         * entire student DB and creates a CSV file with it.  This module was created to aid in
         * determining which students need to be purged from the database.
         */
        private void createDatabaseDumpToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog saveFile = new SaveFileDialog();

                saveFile.Filter           = "txt files (*.txt)|*.txt|csv files (*.csv)|*.csv|xml files (*.xml)|*.xml";
                saveFile.FilterIndex      = 2;
                saveFile.RestoreDirectory = true;   //Should reset the directory when saving is finished.
                                                    //Maintaining the directory in other forms is still
                                                    //performed for reliability.
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    using (StreamWriter outputfile = new StreamWriter(saveFile.FileName))
                    {
                        //first line creates the header line for later importing the data
                        outputfile.WriteLine("Last Name, First Name, Student ID");

                        Valid         allStudents = new Valid();
                        List <string> fullDB      = new List <string>(allStudents.StudentSearch("%", true));

                        //cycle through the retrieved list and write each line as plain text
                        for (int i = 0; i < fullDB.Count; i++)
                        {
                            string[] logLine = fullDB[i].Split(',');
                            outputfile.WriteLine(logLine[0] + "," + logLine[1] + "," + Utility.Decrypt(logLine[2], false));          //writing each list item to file
                        }
                        allStudents = null;
                        fullDB      = null;
                        backedUp    = true;
                    }
                }
                saveFile = null;    //removes the save dialog from memory
            }
            catch
            {
                MessageBox.Show("Error exporting plain text log file.");
                backedUp = false;
            }
        }