public GradeEmailForm(GAClass mainClass, Dictionary<int, Student> students, Assignment assignment, Dictionary<int,ResponseList> responseLists)
        {
            InitializeComponent();
            this.Text = "Email Grades - " + assignment.Name + " - " + mainClass.ClassName;
            this.AcceptButton = buttonSendEmails;
            this.CancelButton = buttonCancel;

            this.mainClass = mainClass;
            this.students = students;
            this.currentAssignment = assignment;
            this.responseLists = responseLists;
            this.Text = "Email Grades - " + currentAssignment.Name + " - " + mainClass.ClassName;

            studentScores = getStudentTotals();
            totalScore = 0;
            foreach (int i in studentScores.Values)
            {
                try
                {
                    totalScore += i;
                    if (i == 0)
                    {
                        numZeros++;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Crazy error!  Glad I'm not you, man (or woman).\nYeah, I've got nothing for you." +
                        ex.ToString(),
                        "Umm...");
                }
            }

            textBoxEmailAddress.Text = mainClass.FromAddress;
        }
 public EditClassForm()
 {
     InitializeComponent();
     this.CancelButton = buttonCancelClass;
     this.AcceptButton = buttonUpdateClass;
     FormStatus = -1;
     PublicClass = new GAClass();
 }
 public EditClassForm()
 {
     InitializeComponent();
     if (Text == "Add New Class")
     {
         buttonUpdateClass.Text = "Add";
     }
     FormStatus = -1;
     PublicClass = new GAClass();
 }
        public GradeEmailForm(GAClass mainClass, Dictionary<int, Student> students, Assignment assignment, Dictionary<int,ResponseList> responseLists)
        {
            InitializeComponent();
            this.Text = "Email Grades - " + assignment.Name + " - " + mainClass.ClassName;
            this.AcceptButton = buttonSendEmails;
            this.CancelButton = buttonCancel;

            this.mainClass = mainClass;
            this.students = students;
            this.currentAssignment = assignment;
            this.responseLists = responseLists;
            this.useHtml = mainClass.FormatAsHTML;
            textBoxSMTPServer.Text = mainClass.ServerName;
            this.smtpPort = mainClass.PortNumber;
            this.Text = "Email Grades - " + currentAssignment.Name + " - " + mainClass.ClassName;

            for (int i = 0; i < this.students.Values.Count; i++)
            {
                comboBoxStudentSelect.Items.Add(this.students.Values.ToList()[i]);
            }

            studentScores = getStudentTotals();
            totalScore = 0;
            foreach (int i in studentScores.Values)
            {
                try
                {
                    totalScore += i;
                    if (i == 0)
                    {
                        numZeros++;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        "Crazy error!  Glad I'm not you, man (or woman).\nYeah, here's some error stuff!\n\n" +
                        ex.ToString(),
                        "Umm...");
                }
            }

            textBoxEmailAddress.Text = mainClass.FromAddress;
        }
        //open Class, this opens an exisiting class
        //accessed through open folder icon/open class in the file menu
        private void OpenClass(object sender, EventArgs e)
        {
            //get the class to open
            OpenFileDialog openClass = new OpenFileDialog();
            openClass.Filter = "Graders Assistant DB Files (*.gadb)|*.gadb";
            openClass.Title = "Open Class File";
            openClass.Multiselect = false;
            openClass.AddExtension = true;
            openClass.ValidateNames = true;
            openClass.ShowDialog();

            //if a class was opened generate the database connection
            if (openClass.FileName != "")
            {
                // close the old class if necessary
                if (gaf != null)
                {
                    gaf.Close();
                    gaf.Dispose();
                    gaf = null;
                }
                dbConnention.ConnectDB(openClass.FileName);
                mainClass = dbConnention.GetClass();

                loadStudents(dbConnention);

                currentAssignmentID = 1;
                loadGradingForm(currentAssignmentID);

                classOpenEnableMenu();
            }
        }
        //edits the deatails of the current class
        private void EditClass(object sender, EventArgs e)
        {
            //TODO where does the class to be editied come from

            EditClassForm editClass = new EditClassForm();
            editClass.PublicClass = mainClass;
            editClass.populateClassForm();
            editClass.ShowDialog();

            //if the values on the form have been updated then commit the changes to the database
            if (editClass.FormStatus == 1)
            {
                //check to make sure a connection exisists
                if (dbConnention.IsConnected())
                {
                    //update the class table in the database
                    dbConnention.UpdateClass(editClass.PublicClass);
                    mainClass = editClass.PublicClass;
                }
                else
                {
                    MessageBox.Show("No connection exists, unable to save class data.");
                }
            }
        }
        //creates a new class
        //TODO still needs to acount for functionality to re populate the new main form once the class is created
        private void CreateNewClass(object sender, EventArgs e)
        {
            //open
            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.AddExtension = true;
            saveFile.Filter = "GradersAssistant DB Files (*.gadb)|*.gadb";
            saveFile.OverwritePrompt = true;
            saveFile.Title = "Create New Class File";
            saveFile.ValidateNames = true;
            saveFile.ShowDialog();

            if (saveFile.FileName != string.Empty)
            {
                try
                {
                    studentComboBox.Items.Clear();

                    Stream template = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("GradersAssistant.template.gat");
                    FileStream fileOut = new FileStream(saveFile.FileName, FileMode.OpenOrCreate, FileAccess.Write);
                    //FileStream fileOut = new FileStream(saveFile.FileName, FileMode.Create, FileAccess.Write);

                    // Now that we have the stream, we have to save it.

                    int len = 256;
                    Byte[] buffer = new Byte[len];
                    int bytesRead = template.Read(buffer, 0, len);
                    while (bytesRead > 0)
                    {
                        fileOut.Write(buffer, 0, bytesRead);
                        bytesRead = template.Read(buffer, 0, len);
                    }
                    template.Close();
                    fileOut.Close();

                    //open edit class form in add mode
                    EditClassForm addClass = new EditClassForm();
                    addClass.FormStatus = 0;
                    addClass.ShowDialog();

                    //if the values on the form have been updated then commit the changes to the database
                    if (addClass.FormStatus == 1)
                    {
                        //check to make sure a connection exisists
                        if (dbConnention.ConnectDB(saveFile.FileName))
                        {
                            //insert
                            if (dbConnention.AddClass(addClass.PublicClass))
                            {
                                mainClass = addClass.PublicClass;
                                classOpenEnableMenu();
                            }
                            else
                            {
                                MessageBox.Show("Class data failed to save to file!");
                            }
                        }
                        else
                        {
                            MessageBox.Show("No connection exists, unable to save class data.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    //if the template file does not exiist output an error message
                    MessageBox.Show("SYSTEM ERROR!!!!:\n This instilation of Graders Assistant\n appears to be corrupt.  Please\n restart the program and try again.\n If the problem continues please reinstall \n the program and try again.");
                }
            }
        }
        public bool UpdateClass(GAClass gaClass)
        {
            // We need to update the class values
                string query = String.Format("UPDATE {0} SET ", tables.GAClass.TableName);
                query += String.Format("{0} = @{0}, ", tables.GAClass.ClassName);
                query += String.Format("{0} = @{0}, ", tables.GAClass.GraderName);
                query += String.Format("{0} = @{0}, ", tables.GAClass.NumberOfSections);
                query += String.Format("{0} = @{0}, ", tables.GAClass.HostType);
                query += String.Format("{0} = @{0}, ", tables.GAClass.Username);
                query += String.Format("{0} = @{0}, ", tables.GAClass.FromAddress);
                query += String.Format("{0} = @{0}, ", tables.GAClass.ServerName);
                query += String.Format("{0} = @{0}, ", tables.GAClass.PortNumber);
                query += String.Format("{0} = @{0}, ", tables.GAClass.AlertOnLate);
                query += String.Format("{0} = @{0}, ", tables.GAClass.SetFullPoints);
                query += String.Format("{0} = @{0}, ", tables.GAClass.IncludeNames);
                query += String.Format("{0} = @{0}, ", tables.GAClass.IncludeSection);
                query += String.Format("{0} = @{0}, ", tables.GAClass.FormatAsHTML);
                query += String.Format("{0} = @{0}, ", tables.GAClass.EmailStudentsNoGrades);
                query += String.Format("{0} = @{0} ", tables.GAClass.DisplayClassStats);
                query += ";";
                OleDbCommand update = new OleDbCommand(query, dbConnection);
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.ClassName, OleDbType.VarChar)).Value = gaClass.ClassName;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.GraderName, OleDbType.VarChar)).Value = gaClass.GraderName;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.NumberOfSections, OleDbType.Integer)).Value = gaClass.NumberOfSections;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.HostType, OleDbType.Integer)).Value = gaClass.HostType;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.Username, OleDbType.VarChar)).Value = gaClass.UserName;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.FromAddress, OleDbType.VarChar)).Value = gaClass.FromAddress;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.ServerName, OleDbType.VarChar)).Value = gaClass.ServerName;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.PortNumber, OleDbType.Integer)).Value = gaClass.PortNumber;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.AlertOnLate, OleDbType.Boolean)).Value = gaClass.AlertOnLate;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.SetFullPoints, OleDbType.Boolean)).Value = gaClass.SetFullPoints;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.IncludeNames, OleDbType.Boolean)).Value = gaClass.IncludeNames;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.IncludeSection, OleDbType.Boolean)).Value = gaClass.IncludeSections;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.FormatAsHTML, OleDbType.Boolean)).Value = gaClass.FormatAsHTML;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.EmailStudentsNoGrades, OleDbType.Boolean)).Value = gaClass.EmailStudentsNoGrade;
                update.Parameters.Add(new OleDbParameter("@" + tables.GAClass.DisplayClassStats, OleDbType.Boolean)).Value = gaClass.DisplayClassStats;
                try
                {
                    update.ExecuteNonQuery();
                    return true;
                }
                catch(Exception ex)
                {

                    Debug.WriteLine("Could not update class values in the database.");
                    return false;
                }
        }