////------------------------------------------------------------------// //// Authors: Cody Jordan, Cian Carota // //// Date: 4/5/14 // ////------------------------------------------------------------------// ///// <summary>Edit data in Student XML.</summary> ///// <param name="newFName">Student's first name.</param> ///// <param name="newLName">Student's last name.</param> ///// <param name="selectedStudent">Student object to be modified</param> ///// <param name="group">Group object associated with student.</param> ///// <param name="studentList">List of student objects.</param> ///// <returns>bool, bool</returns> //public Tuple<bool, bool> editStudent(string newFName, string newLName, Student selectedStudent, Group group, List<Student> studentList) //{ // return XMLStudentDriver.editStudent(newFName, newLName, selectedStudent, group, studentList, studentXMLPath, groupXMLPath, dataDirectory); //} //----------------------------------------------------------------------------------------------// // Authors: Joshua Boone and Justine Dinh // // Date: 4/12/14 // //----------------------------------------------------------------------------------------------// //------------------------------------------------------------------// /// <summary>Edit a student's group placement.</summary> /// <param name="selectedStudent">Student object to be modified</param> /// <param name="group">Group object associated with student.</param> public void EditGroup(Student selectedStudent, Group group) { selectedStudent.GroupID = group.ID; XMLStudentDriver.EditGroup(selectedStudent, studentXMLPath, groupXMLPath, dataDirectory); }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/5/14 // //------------------------------------------------------------------// /// <summary>Check if drill is already associated with a group. /// </summary> /// <param name="group">Group object to check against.</param> /// <param name="drill">Drill object to check for.</param> /// <returns>Boolean confirmation.</returns> public bool isDrillAssignedToGroup(Group group, Drill drill) { foreach (Drill groupDrill in group.groupDrillList) { if (groupDrill.ID == drill.ID) { return true; } } return false; }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/1/14 // //------------------------------------------------------------------// /// <summary>Delete an group from an XML file.</summary> /// <param name="group">Group object to be deleted.</param> /// <param name="fileName">XML file name.</param> public void Delete(Group group, string fileName) { XDocument data = XDocument.Load(fileName); XElement groupElement = data.Descendants("group").Where(s => s.Attribute("ID").Value.Equals(group.ID.ToString())).FirstOrDefault(); if (groupElement != null) { groupElement.Remove(); data.Save(fileName); } }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/5/14 // //------------------------------------------------------------------// /// <summary>Edit group data.</summary> /// <param name="newName">New group name.</param> /// <param name="currentName">Current group name.</param> /// <param name="groupList">List of group objects.</param> /// <returns>Boolean success confirmation.</returns> public bool editGroup(string newName, string currentName, List<Group> groupList) { Group modifiedGroup = new Group(); foreach (Group group in groupList) { if(group.Name == currentName) { modifiedGroup.ID = group.ID; modifiedGroup.Name = newName; UpdateGroup(group, modifiedGroup); return true; } } return false; }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/3/14 // //------------------------------------------------------------------// /// <summary>Clears content of 'Select Drill' combo box and /// repopulates with drills that can be unassigned from the selected /// group.</summary> /// <param name="group">The group to be modified</param> private void RefreshSelectUnassignedDrillCmbo(Group group) { MngDrills_SelectDrillCmbo.Items.Clear(); if (group != null) { MngDrills_StudentOrGroupCmbo.ForeColor = Color.Green; foreach (Drill drill in localManager.mainDrillList) { Drill studentDrill = group.groupDrillList.Where(dri => dri.ID.ToString().Equals(drill.ID.ToString())).FirstOrDefault(); if (studentDrill == null) MngDrills_SelectDrillCmbo.Items.Add(drill.DrillName); } } else { MngDrills_StudentOrGroupCmbo.ForeColor = Color.Red; } }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/1/14 // //------------------------------------------------------------------// /// <summary>Adding a new group to Group XML. </summary> /// <param name="groupName">Group name.</param> /// <param name="groupList">List of group objects.</param> /// <returns>Boolean confirmation.</returns> public bool AddNewGroup(string groupName, List<Group> groupList) { Group group = new Group(); group.Name = groupName; XDocument data = XDocument.Load(groupXMLPath); XElement GroupElement = data.Descendants("group").Where(s => s.Element("groupName").Value == group.Name).FirstOrDefault(); if (GroupElement != null) { return false; } else { XElement newGroup = new XElement("group", new XElement("groupName", group.Name)); newGroup.SetAttributeValue("ID", GetNextAvailableID(groupXMLPath, "group")); group.ID = Convert.ToInt32(newGroup.Attribute("ID").Value); data.Element("RaptorMathGroups").Add(newGroup); groupList.Add(group); data.Save(groupXMLPath); return true; } }
//----------------------------------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/3/14 // //----------------------------------------------------------------------------------------------// /// <summary>Remove all group's drills from student's XML file.</summary> /// <param name="group">Group object acting as source.</param> /// <param name="student">Student object to be modified.</param> public void RemoveGroupDrillsFromStudent(Group group, Student student) { if ((group != null) && (student != null)) { foreach (Drill drill in group.groupDrillList) { RemoveDrillFromStudent(student, drill); } } }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/5/14 // //------------------------------------------------------------------// /// <summary>Add a drill to a group XML.</summary> /// <param name="group">Group oject to be modified.</param> /// <param name="drillToAdd">Drill object to be added.</param> /// <returns>Boolean success confirmation.</returns> public bool AddDrillToGroupXML(Group group, Drill drillToAdd) { XDocument data = XDocument.Load(groupXMLPath); XElement groupElement = data.Descendants("group").Where(grp => grp.Attribute("ID").Value.Equals(group.ID.ToString())).FirstOrDefault(); bool isDrillAlreadyAssignedToGroup = isDrillAssignedToGroup(group, drillToAdd); if ((groupElement != null) && (!isDrillAlreadyAssignedToGroup)) { XElement newStudentDrill = new XElement("drill", drillToAdd.ID); group.groupDrillList.Add(drillToAdd); groupElement.Add(newStudentDrill); data.Save(groupXMLPath); return true; } return false; }
//----------------------------------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/3/14 // //----------------------------------------------------------------------------------------------// /// <summary>Remove a drill from group's XML file.</summary> /// <param name="group">Group object to be modified.</param> /// <param name="drillToRemove">Drill object to be removed.</param> /// <returns>Boolean confirming removal success.</returns> public bool RemoveDrillFromGroup(Group group, Drill drillToRemove) { bool isDrillRemovedFromGroup = XMLDriver.RemoveDrillFromGroupXML(group, drillToRemove); List<Student> StudentList = FindStudentsByGroupID(group.ID); if (isDrillRemovedFromGroup) { foreach (Student student in StudentList) { RemoveDrillFromStudent(student, drillToRemove); } } return isDrillRemovedFromGroup; }
//----------------------------------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/3/14 // //----------------------------------------------------------------------------------------------// /// <summary>Add all group's drills to student's XML file.</summary> /// <param name="group">Group object acting as source.</param> /// <param name="student">Student object to be modified.</param> public void AddGroupDrillsToStudent(Group group, Student student) { if ((group != null) && (student != null)) { foreach(Drill drill in group.groupDrillList) { AddDrillToStudent(student, drill); } } }
//------------------------------------------------------------------// // Authors: Joshua Boone and Justine Dinh // // Date: 4/12/14 // //------------------------------------------------------------------// /// <summary>Returns if there are group reocords in a picked date range</summary> /// <param name="first">Start date</param> /// <param name="second">End date</param> /// <param name="group">Group to generate report</param> /// <returns>Whether there are records for this group in the given date range</returns> public bool IsRecordInRangeGroup(DateTime first, DateTime second, Group group) { string date; bool recordsExist = false; List<Record> recordList = new List<Record>(); List<Student> listOfStudentsInGroup = new List<Student>(); foreach (Student student in studentList) { if (student.GroupID == group.ID) { listOfStudentsInGroup.Add(student); } } foreach (Student studentInGroup in listOfStudentsInGroup) { foreach (Record record in studentInGroup.curRecordList) { date = record.DateTaken; if ((DateTime.Parse(date) >= first) && (DateTime.Parse(date) <= second)) { recordsExist = true; break; } } } return recordsExist; }
//----------------------------------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/3/14 // //----------------------------------------------------------------------------------------------// /// <summary>Add a drill to group's XML file.</summary> /// <param name="group">Group object to be modified.</param> /// <param name="drillToAdd">Drill object to be added.</param> /// <returns>Boolean confirming addition success.</returns> public bool AddDrillToGroup(Group group, Drill drillToAdd) { bool isDrillAddedToGroup = XMLDriver.AddDrillToGroupXML(group, drillToAdd); List<Student> StudentList = FindStudentsByGroupID(group.ID); if(isDrillAddedToGroup) { foreach(Student student in StudentList) { AddDrillToStudent(student, drillToAdd); } } return isDrillAddedToGroup; }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/3/14 // //------------------------------------------------------------------// /// <summary>Will refresh 'Stu/Grp' and 'Select /// Drill' combo boxes relative to intent to unassign a drill to a /// group.</summary> /// <param name="group">The group to be modified</param> private void RefreshUnassignedGroupCmboBoxes(Group group) { RefreshGroupCmboBox(); RefreshSelectUnassignedDrillCmbo(group); }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/5/14 // //------------------------------------------------------------------// /// <summary>Load a list of groups from XML to local.</summary> /// <param name="groupList">List of group objects to be populated. /// </param> /// <param name="mainDrillList">List of drill objects</param> /// <param name="fileName">XML file name.</param> public void LoadGroupXML(List<Group> groupList, List<Drill> mainDrillList, string fileName) { XDocument groupXML = XDocument.Load(fileName); foreach (XElement group in groupXML.Root.Nodes()) { Group Group = new Group(); Group.ID = Convert.ToInt32(group.Attribute("ID").Value); Group.Name = group.Element("groupName").Value; if(group.Elements("drill") != null) { foreach(XElement drill in group.Elements("drill")) { Drill newDrill = mainDrillList.Where(dri => dri.ID.Equals(Convert.ToInt32(drill.Value))).FirstOrDefault(); Group.groupDrillList.Add(newDrill); } } groupList.Add(Group); } }
//------------------------------------------------------------------// // Cody Jordan, Cian Carota // // Date: 4/8/14 // //------------------------------------------------------------------// /// <summary>Generate average percent, average wrong, average skipper</summary> /// <param name="first">Start date</param> /// <param name="second">End date</param> /// <param name="group">Group to generate report</param> /// <returns>Tuple that contains the group name, avg percent, avg skipped, numberOfSets</returns> public Tuple<string, float, float, float, int> GenerateRecordForGroup(DateTime first, DateTime second, Group group) { string date; List<Record> recordList = new List<Record>(); List<Student> listOfStudentsInGroup = new List<Student>(); foreach (Student student in studentList) { if (student.GroupID == group.ID) listOfStudentsInGroup.Add(student); } int numberOfSets = 0; float totalPercent = 0.0f; int totalWrong = 0; int totalSkipped = 0; int numberOfStudents = listOfStudentsInGroup.Count; foreach(Student studentInGroup in listOfStudentsInGroup) { foreach (Record record in studentInGroup.curRecordList) { date = record.DateTaken; if ((DateTime.Parse(date) >= first) && (DateTime.Parse(date) <= second)) { numberOfSets += 1; totalPercent += float.Parse(record.Percent); totalWrong += Convert.ToInt32(record.Wrong); totalSkipped += Convert.ToInt32(record.Skipped); } } } if (numberOfStudents > 0) { float avgPercent = (totalPercent / numberOfSets) / numberOfStudents; float avgWrong = totalWrong / numberOfStudents; float avgSkipped = totalSkipped / numberOfStudents; return Tuple.Create(group.Name, avgPercent, avgWrong, avgSkipped, numberOfSets); } else return Tuple.Create(group.Name, 0f, 0f, 0f, 0); //return recordList; }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/5/14 // //------------------------------------------------------------------// /// <summary>Remove a drill from Group XML.</summary> /// <param name="group">Group object to be modified.</param> /// <param name="DrillToRemove">Drill object to be removed.</param> /// <returns>Boolean confirmation.</returns> public bool RemoveDrillFromGroupXML(Group group, Drill DrillToRemove) { XDocument data = XDocument.Load(groupXMLPath); XElement groupElement = data.Descendants("group").Where(s => s.Attribute("ID").Value.Equals(group.ID.ToString())).FirstOrDefault(); bool isDrillAlreadyAssignedToStudent = isDrillAssignedToGroup(group, DrillToRemove); if ((groupElement != null) && (isDrillAlreadyAssignedToStudent)) { XElement newStudentDrill = new XElement("drill", DrillToRemove.ID); if (groupElement.Elements("drill") != null) { foreach (XElement drill in groupElement.Elements("drill")) { if (DrillToRemove == group.groupDrillList.Where(dri => dri.ID.Equals(Convert.ToInt32(drill.Value))).FirstOrDefault()) { drill.Remove(); group.groupDrillList.Remove(DrillToRemove); data.Save(groupXMLPath); return true; } } } } return false; }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/1/14 // //------------------------------------------------------------------// /// <summary>Edit data in Group XML.</summary> /// <param name="group">Group object to be replaced.</param> /// <param name="modifiedGroup">Group object to be inserted.</param> private void UpdateGroup(Group group, Group modifiedGroup) { XDocument data = XDocument.Load(groupXMLPath); XElement groupIDElement = data.Descendants("group").Where(grp => grp.Attribute("ID").Value.Equals(modifiedGroup.ID.ToString())).FirstOrDefault(); XElement groupNameElement = data.Descendants("group").Where(grp => grp.Element("groupName").Value.Equals(modifiedGroup.Name)).FirstOrDefault(); if ((groupIDElement != null) && (groupNameElement == null)) { groupIDElement.SetElementValue("groupName", modifiedGroup.Name); group.ID = modifiedGroup.ID; group.Name = modifiedGroup.Name; data.Save(groupXMLPath); } }
//------------------------------------------------------------------// // Authors: Joshua Boone and Justine Dinh // // Date: 4/28/14 // //------------------------------------------------------------------// /// <summary>Function to actually fill the data grid with the available drills.</summary> private void FillAvailableDrillsGroupDataGrid(Group group) { foreach (Drill drill in localManager.mainDrillList) { Drill Drill = group.groupDrillList.Where(dri => dri.ID.ToString().Equals(drill.ID.ToString())).FirstOrDefault(); if (Drill == null) { DataGridViewRow newRow = (DataGridViewRow)AvailableDrillDataDisplay.Rows[0].Clone(); newRow.Cells[0].Value = drill.DrillName; AvailableDrillDataDisplay.Rows.Add(newRow); } } }
//------------------------------------------------------------------// // Authors: Cody Jordan, Cian Carota // // Date: 4/3/14 // //------------------------------------------------------------------// /// <summary>Clears content of 'Select Drill' combo box and /// repopulates with drills that can be assigned to the selected /// group.</summary> /// <param name="group">The group to be modified</param> private void RefreshSelectAssignedDrillCmbo(Group group) { MngDrills_SelectDrillCmbo.Items.Clear(); if (group != null) { MngDrills_StudentOrGroupCmbo.ForeColor = Color.Green; foreach (Drill drill in group.groupDrillList) { MngDrills_SelectDrillCmbo.Items.Add(drill.DrillName); } } else { MngDrills_StudentOrGroupCmbo.ForeColor = Color.Red; } }