public GradingItemForm(Response r, Criteria criteria, Student student) { Cancelled = true; // fail closed rather than open GraderResponse = r; InitializeComponent(); studentNameLabel.Text = string.Format("{0}, {1}", student.LastName, student.FirstName); criteriaDescLabel.Text = criteria.Description; pointsReceivedNumericUpDown.Maximum = criteria.MaxPoints; pointsReceivedNumericUpDown.Minimum = 0; if (GraderResponse.PointsReceived < 0) { GraderResponse.PointsReceived = 0; } else if (GraderResponse.PointsReceived > criteria.MaxPoints) { GraderResponse.PointsReceived = criteria.MaxPoints; } pointsReceivedNumericUpDown.Value = GraderResponse.PointsReceived; maxPointsLabel.Text = string.Format("Pts out of {0} Pts", criteria.MaxPoints.ToString()); graderCommentTextBox.Text = GraderResponse.GraderComment; }
public EditStudentForm() { InitializeComponent(); NumOfSections = 1; this.CancelButton = buttonCancel; this.AcceptButton = buttonUpdate; PublicStudent = new Student(); }
public EditStudentForm() { InitializeComponent(); if (Text == "Add New Student") { buttonUpdate.Text = "Add"; } status = -1; PublicStudent = new Student(); }
public void LoadResponseList(Student student, ResponseList responseList) { if (currentAssignment == null || responseList.AssignmentID != currentAssignment.AssignmentID) { Debug.WriteLine("The assignment and response list IDs do not match!"); return; } currentStudent = student; currentResponseList = responseList; studentNameLabel.Text = string.Format("{0}, {1}", currentStudent.LastName, currentStudent.FirstName); studentIDLabel.Text = currentStudent.StudentSchoolID; foreach (KeyValuePair<int, RubricNode> rubricNode in currentAssignment.Rubric.Nodes) { TreeNode[] rubricTreeNodes = rubricTreeView.Nodes.Find(rubricNode.Value.Criteria.CriteriaID.ToString(),true); if (rubricTreeNodes.Length == 1) { Response response; if (currentResponseList.Responses.TryGetValue(rubricNode.Value.Criteria.CriteriaID, out response)) { // if we have already created a response for this criteria/student if (response.PointsReceived > 0) { rubricTreeNodes[0].Checked = true; } else { // no checkmark if they have received 0 pts rubricTreeNodes[0].Checked = false; } } else if(rubricNode.Value.Children.Count == 0) { // we need to create a response if none exists and this isn't a header response = currentResponseList.Responses[rubricNode.Value.Criteria.CriteriaID] = new Response(); rubricTreeNodes[0].Checked = true; response.PointsReceived = rubricNode.Value.Criteria.MaxPoints; } if (rubricNode.Value.Children.Count > 0) { rubricTreeNodes[0].Checked = true; rubricTreeNodes[0].Text = rubricNode.Value.Criteria.Description; } else { rubricTreeNodes[0].Text = string.Format("{0} ({1}): {2}", rubricNode.Value.Criteria.Description, rubricNode.Value.Criteria.MaxPoints.ToString(), response.PointsReceived.ToString()); } } else if (rubricTreeNodes.Length == 0) { Debug.WriteLine("The criteria in the rubric does not exist in the treeview."); } else { Debug.WriteLine("Multiple criteria share the same key."); } } rubricTreeView.ExpandAll(); updateAdjustmentListBox(); updatePoints(); }
/// <summary> /// This function actually does the email sending, using SMTP. /// </summary> /// <param name="useHTML">Boolean indicating whether or not to use send HTML or plain text.</param> /// <param name="text">The actual text of the email, with or without HTML formatting.</param> /// <param name="s">The student to whom the email should be sent.</param> /// <returns>Returns a boolean indicating whether or not the email went through, /// but an exception will be caught and thrown if the email does not work.</returns> private bool sendEmail(bool useHTML, string text, Student s) { try { if (!textBoxEmailAddress.Text.Contains('@')) { MessageBox.Show("Please enter a valid email address.", "Invalid Email!"); throw new Exception("Invalid sender email address."); } if (!s.EmailAddress.Contains('@')) { //MessageBox.Show("The recipient \"" + s.EmailAddress + "\" has an invalid email address."); throw new Exception("Invalid student email address."); } SmtpClient smtpClient = new SmtpClient(); NetworkCredential theCredential = new NetworkCredential(textBoxEmailAddress.Text, textBoxExchangePassword.Text); MailMessage message = new MailMessage(); MailAddress fromAddress = new MailAddress(textBoxEmailAddress.Text); try { smtpClient.Host = textBoxSMTPServer.Text; } catch (Exception ex) { //MessageBox.Show("Error: Please enter a valid SMTP server.", "No SMTP Server"); throw ex; } if (radioButtonProtocolExchange.Checked) { smtpClient.UseDefaultCredentials = false; smtpClient.Port = 587; smtpClient.EnableSsl = true; //smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; } smtpClient.Credentials = theCredential; message.From = fromAddress; message.Subject = textBoxSubject.Text; message.IsBodyHtml = useHTML; message.Body = text; message.To.Add(s.EmailAddress); try { smtpClient.Send(message); } catch (Exception ex) { //MessageBox.Show("Error sending email:\n" + ex.Message, ex.Message); throw ex; } return true; } catch (Exception ex) { throw ex; } }
/// <summary> /// This function returns the total score of one Student. /// Side effect: Also sets the maxScore object variable. Messy, I know. /// </summary> /// <param name="s">The Student whose score is to be gotten.</param> /// <returns>An integer indicating the Student's score.</returns> private int getOneTotal(Student s) { // this is ridiculous! -- Josh if (!responseLists.ContainsKey(s.StudentID)) { throw new Exception("Student " + s.FirstName + " " + s.LastName + " (" + s.StudentID + ") does not have any responses. Please check the grading guide."); } Dictionary<int, Response> responseDict = responseLists[s.StudentID].Responses; if (responseDict.Count == 0) { throw new Exception("Student " + s.FirstName + " " + s.LastName + " (" + s.StudentID + ") does not have any responses. Please check the grading guide."); } Rubric currentRubric = currentAssignment.Rubric; int theTotal = 0; maxScore = 0; foreach (int rootNodeID in currentRubric.RootNodes) { try { theTotal += getScoreFromNode(rootNodeID, currentRubric.Nodes, responseDict); } catch (Exception ex) { MessageBox.Show("Some responses missing for student " + s.FirstName + " " + s.LastName + ". Try regrading this student. " + "If that doesn't work, the database is probably corrupt.\n\n" + ex.ToString(), "Missing responses!"); } } return theTotal; }
/// <summary> /// This function is called recursively to navigate the criteria tree and get some of the /// text for a student's email, starting at a single node. /// </summary> /// <param name="s">The Student whose email text should be obtained.</param> /// <returns>Returns the string that should be sent to the sendEmail function.</returns> private string getEmailText(Student s) { if (!responseLists.ContainsKey(s.StudentID)) { throw new Exception("Student " + s.FirstName + " " + s.LastName + " (" + s.StudentID + ") does not have any responses. Please check the grading guide."); } Dictionary<int, Response> responseDict = responseLists[s.StudentID].Responses; // initialize text with header and blank line string theString = textBoxHeaderText.Text + "\n\n"; // add intro theString += "Grading Report for " + mainClass.ClassName + "\n" + "Assignment: " + currentAssignment.Name + "\n\n"; // class statistics theString += "Statistics:\n" + " Number of Students: " + students.Count + "\n" + " Numer of Students Graded: " + numGraded + "\n" + " Number of Zero Grades: " + numZeros + "\n" + " Average Grade: " + ((double)totalScore / (double)students.Count).ToString("F2") + "\n" + " Average (no zeros): " + ((double)totalScore / (double)studentScores.Count).ToString("F2") + "\n\n"; theString += "Your Score:\n\n"; //Dictionary<int, RubricNode> criterion = currentAssignment.Rubric.Nodes; Rubric currentRubric = currentAssignment.Rubric; foreach (int rootNodeID in currentRubric.RootNodes) { theString += getTextFromNode(rootNodeID, currentRubric.Nodes, responseDict, 0) + "\n"; } theString += "\n"; theString += "Total Score: " + studentScores[s.StudentID] + " out of " + maxScore + " -- " + (100*studentScores[s.StudentID]/maxScore).ToString("F2") + "%"; return theString; }
/// <summary> /// This function returns the HTML text for an HTML formatted email for one Student. Includes /// comments, grades, etc. Throws an exception if the Student has no responses. /// </summary> /// <param name="s">The Student whose email HTML should be obtained.</param> /// <returns>Returns the string that should be sent to the sendEmail function.</returns> private string getEmailHtml(Student s) { int tempInt; List<string> commentStrings = new List<string>(); if (!responseLists.ContainsKey(s.StudentID)) { throw new Exception("Student " + s.FirstName + " " + s.LastName + " (" + s.StudentID + ") does not have any responses. Please check the grading guide."); } Dictionary<int, Response> responseDict = responseLists[s.StudentID].Responses; // initialize html tags and add header text // NOTE: New lines are for minor source readability string theString = "<html><body>" + "<p>" + textBoxHeaderText.Text + "</p>"; // add intro theString += "<p>Grading Report for " + mainClass.ClassName + "<br />" + "Assignment: " + currentAssignment.Name + "</p>"; // class statistics theString += "<p>Statistics:" + " Number of Students: " + students.Count + "<br />" + " Numer of Students Graded: " + numGraded + "<br />" + " Number of Zero Grades: " + numZeros + "<br />" + " Average Grade: " + ((double)totalScore / (double)students.Count).ToString("F2") + "<br />" + " Average (no zeros): " + ((double)totalScore / (double)studentScores.Count).ToString("F2") + "</p>"; //Dictionary<int, RubricNode> criterion = currentAssignment.Rubric.Nodes; Rubric currentRubric = currentAssignment.Rubric; theString += "<p>Your Grades:<ul>"; tempInt = 0; foreach (int rootNodeID in currentRubric.RootNodes) { theString += getHtmlFromNode(rootNodeID, currentRubric.Nodes, responseDict, ref tempInt, ref commentStrings); } theString += "</ul>"; theString += "Total Score: " + studentScores[s.StudentID] + " out of " + maxScore + " -- " + (100 * studentScores[s.StudentID] / maxScore).ToString("F2") + "%</p><p>"; theString += "Comments:</p>"; foreach (string aComment in commentStrings) { theString += aComment; } theString += "</body></html>"; return theString; }
private void loadResponseList(int assignmentID, Student student) { ResponseList responseList = dbConnention.GetResponseList(assignmentID, student.StudentID); gaf.LoadResponseList(student, responseList); }
/// <summary> /// This function returns the HTML text for an HTML formatted email for one Student. Includes /// comments, grades, etc. Throws an exception if the Student has no responses. /// </summary> /// <param name="s">The Student whose email HTML should be obtained.</param> /// <returns>Returns the string that should be sent to the sendEmail function.</returns> private string getEmailHtml(Student s) { int tempInt; int adjustmentTotal = 0; List<string> commentStrings = new List<string>(); if (!responseLists.ContainsKey(s.StudentID)) { throw new Exception("Student " + s.FirstName + " " + s.LastName + " (" + s.StudentID + ") does not have any responses. Please check the grading guide."); } Dictionary<int, Response> responseDict = responseLists[s.StudentID].Responses; // initialize html tags and add header text // NOTE: New lines are for minor source readability string theString = "<html><body>" + "<p>" + textBoxHeaderText.Text + "</p>"; // add intro theString += "<h4>Grading Report for " + mainClass.ClassName + "</h4>" + "<h5>Assignment: " + currentAssignment.Name + "</h5>"; // class statistics theString += "<h5>Statistics:</h5><p>" + " Number of Students: " + students.Count + "<br />" + " Numer of Students Graded: " + numGraded + "<br />" + " Number of Zero Grades: " + numZeros + "<br />" + " Average Grade: " + ((double)totalScore / (double)students.Count).ToString("F2") + "<br />" + " Average (no zeros): " + ((double)totalScore / (double)studentScores.Count).ToString("F2") + "</p>"; //Dictionary<int, RubricNode> criterion = currentAssignment.Rubric.Nodes; Rubric currentRubric = currentAssignment.Rubric; theString += "<h5>Your Grades:</h5><ul>"; tempInt = 0; foreach (int rootNodeID in currentRubric.RootNodes) { theString += getHtmlFromNode(rootNodeID, currentRubric.Nodes, responseDict, ref tempInt, ref commentStrings); } theString += "</ul>"; // Now add adjustments... if there are any if (responseLists[s.StudentID].Adjustments.Count != 0) { theString += "<h5>Adjustments:</h5>"; theString += "<table width=\"100%\">"; foreach (Adjustment a in responseLists[s.StudentID].Adjustments) { theString += "<tr><td>" + a.Comment + "</td><td>" + a.PointAdjustment + "</td></tr>"; adjustmentTotal += a.PointAdjustment; } theString += "</table>"; } // Now do full summary theString += "<p>Subtotal: " + (studentScores[s.StudentID] - adjustmentTotal) + " out of " + maxScore + "<br />"; if (adjustmentTotal > 0) { theString += "Adjustments: +" + adjustmentTotal + "<br />"; } else { theString += "Adjustments: " + adjustmentTotal + "<br />"; } theString += "Total Score: " + studentScores[s.StudentID] + " out of " + maxScore + " -- " + (100 * (double)studentScores[s.StudentID] / (double)maxScore).ToString("F2") + "%</p>"; // Now comments... if there are any if (commentStrings.Count != 0) { theString += "<h5>Comments:</h5>"; foreach (string aComment in commentStrings) { theString += aComment; } } theString += "</body></html>"; return theString; }
public bool UpdateStudent(Student student) { if (student.HasID()) { // AAAAAAAAAGH ACCESS AND OLEDB SUCK. You can used named parameters BUT OleDb doesn't respect them and just relies on order. SUCKS. // We need to update because the student already has a key. string query = String.Format("UPDATE {0} SET ", tables.Student.TableName); query += String.Format("{0} = @{0}, ", tables.Student.FirstName); query += String.Format("{0} = @{0}, ", tables.Student.LastName); query += String.Format("{0} = @{0}, ", tables.Student.Username); query += String.Format("{0} = @{0}, ", tables.Student.EmailAddress); query += String.Format("{0} = @{0}, ", tables.Student.ClassSection); query += String.Format("{0} = @{0} ", tables.Student.StudentSchoolID); query += String.Format("WHERE {0} = @{0};", tables.Student.StudentID); OleDbCommand update = new OleDbCommand(query, dbConnection); update.Parameters.Add(new OleDbParameter("@" + tables.Student.FirstName, OleDbType.VarChar)).Value = student.FirstName;// student.FirstName; update.Parameters.Add(new OleDbParameter("@" + tables.Student.LastName, OleDbType.VarChar)).Value = student.LastName; update.Parameters.Add(new OleDbParameter("@" + tables.Student.Username, OleDbType.VarChar)).Value = student.Username; update.Parameters.Add(new OleDbParameter("@" + tables.Student.EmailAddress, OleDbType.VarChar)).Value = student.EmailAddress; update.Parameters.Add(new OleDbParameter("@" + tables.Student.ClassSection, OleDbType.Integer)).Value = student.ClassSection; update.Parameters.Add(new OleDbParameter("@" + tables.Student.StudentSchoolID, OleDbType.VarChar)).Value = student.StudentSchoolID; update.Parameters.Add(new OleDbParameter("@" + tables.Student.StudentID, OleDbType.Integer)).Value = student.StudentID; update.ExecuteNonQuery(); return true; } else { Debug.WriteLine("A student without an ID was found in a student dictionary. That's not good."); return false; } }
public bool DeleteStudent(Student student) { if (student.HasID()) { // We need to update because the student already has a key. string query = String.Format("DELETE FROM {0} ", tables.Student.TableName); query += String.Format("WHERE {0} = @{0};", tables.Student.StudentID); OleDbCommand update = new OleDbCommand(query, dbConnection); update.Parameters.Add(new OleDbParameter("@" + tables.Student.StudentID, OleDbType.Integer)).Value = student.StudentID; update.ExecuteNonQuery(); return true; } else { Debug.WriteLine("A student without an ID is trying to be deleted. That's not good."); return false; } }
public int AddStudent(Student student) { if (student.HasID()) { Debug.WriteLine("You should not add students if they already have an ID assigned."); return student.StudentID; } else { // We need to insert rather than update because the student has no key. string query = String.Format("INSERT INTO {0} (", tables.Student.TableName); query += String.Format("{0}, ", tables.Student.FirstName); query += String.Format("{0}, ", tables.Student.LastName); query += String.Format("{0}, ", tables.Student.Username); query += String.Format("{0}, ", tables.Student.EmailAddress); query += String.Format("{0}, ", tables.Student.ClassSection); query += String.Format("{0}", tables.Student.StudentSchoolID); query += ") VALUES ("; query += String.Format("@{0}, ", tables.Student.FirstName); query += String.Format("@{0}, ", tables.Student.LastName); query += String.Format("@{0}, ", tables.Student.Username); query += String.Format("@{0}, ", tables.Student.EmailAddress); query += String.Format("@{0}, ", tables.Student.ClassSection); query += String.Format("@{0}", tables.Student.StudentSchoolID); query += ");"; OleDbCommand insert = new OleDbCommand(query, dbConnection); insert.Parameters.Add(new OleDbParameter("@" + tables.Student.FirstName, OleDbType.VarChar)).Value = student.FirstName;// student.FirstName; insert.Parameters.Add(new OleDbParameter("@" + tables.Student.LastName, OleDbType.VarChar)).Value = student.LastName; insert.Parameters.Add(new OleDbParameter("@" + tables.Student.Username, OleDbType.VarChar)).Value = student.Username; insert.Parameters.Add(new OleDbParameter("@" + tables.Student.EmailAddress, OleDbType.VarChar)).Value = student.EmailAddress; insert.Parameters.Add(new OleDbParameter("@" + tables.Student.ClassSection, OleDbType.Integer)).Value = student.ClassSection; insert.Parameters.Add(new OleDbParameter("@" + tables.Student.StudentSchoolID, OleDbType.VarChar)).Value = student.StudentSchoolID; try { insert.ExecuteNonQuery(); } catch { Debug.WriteLine("Could not insert student."); } // Now that we inserted the student, we need to get its ID query = "SELECT @@IDENTITY;"; OleDbCommand getID = new OleDbCommand(query, dbConnection); int key = student.StudentID; try { key = (int)getID.ExecuteScalar(); } catch { Debug.WriteLine("Could not retrieve student ID."); } return key; } }