Пример #1
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Add a drill to a student in Student XML.</summary>
        /// <param name="student">Student object to be modified</param>
        /// <param name="drillToAdd">Drill object to be added.</param>
        /// <param name="studentXMLPath">Student XML file path.</param>
        /// <returns>Boolean confirming success.</returns>
        public bool AddDrillToStudentXML(Student student, Drill drillToAdd, string studentXMLPath)
        {
            XDocument data = XDocument.Load(studentXMLPath);

            XElement studentElement = data.Descendants("stu").Where(s => s.Attribute("ID").Value.Equals(student.ID.ToString())).FirstOrDefault();
            bool isDrillAlreadyAssignedToStudent = isDrillAssigned(student, drillToAdd);
            if ((studentElement != null) && (!isDrillAlreadyAssignedToStudent))
            {
                XElement newStudentDrill = new XElement("drill", drillToAdd.ID);
                student.curDrillList.Add(drillToAdd);

                studentElement.Add(newStudentDrill);
                data.Save(studentXMLPath);
                return true;
            }
            return false;
        }
Пример #2
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/1/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Delete an drill from an XML file.</summary>
        /// <param name="drill">Drill object to be deleted.</param>
        /// <param name="fileName">XML file name.</param>
        public void Delete(Drill drill, string fileName)
        {
            XDocument data = XDocument.Load(fileName);

            XElement drillElement = data.Descendants("drill").Where(s => s.Attribute("ID").Value.Equals(drill.ID.ToString())).FirstOrDefault();
            if (drillElement != null)
            {
                drillElement.Remove();
                data.Save(fileName);
            }
        }
Пример #3
0
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/5/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Add a drill node to Drill XML.</summary>
 /// <param name="newDrill">Drill object to be added.</param>
 /// <returns>XElement</returns>
 public XElement CreateDrillNode(Drill newDrill)
 {
     XElement drill =
         new XElement("drill",
             new XElement("drillName", newDrill.DrillName),
             new XElement("questions", newDrill.Questions),
             new XElement("rangeStart", newDrill.RangeStart),
             new XElement("rangeEnd", newDrill.RangeEnd),
             new XElement("operand", newDrill.Operand),
             new XElement("wrong", newDrill.Wrong),
             new XElement("skipped", newDrill.Skipped),
             new XElement("percent", newDrill.Percent));
     return drill;
 }
Пример #4
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Adding a new drill to Drill XML. </summary>
        /// <param name="drill">Drill name.</param>
        /// <param name="drillList">List of drill objects.</param>
        /// <returns>Boolean confirmation.</returns>
        public bool AddNewDrill(Drill drill, List<Drill> drillList)
        {
            XDocument data = XDocument.Load(drillXMLPath);

            XElement DrillElement =
                data.Descendants("drill").Where(s => s.Element("drillName").Value == drill.DrillName).FirstOrDefault();
            if (DrillElement != null)
            {
                MessageBox.Show("A Drill with that name already exists! Please choose a different name", "Raptor Math", MessageBoxButtons.OK);
                return false;
            }
            else
            {
                XElement newDrill = CreateDrillNode(drill);

                newDrill.SetAttributeValue("ID", GetNextAvailableID(drillXMLPath, "drill"));
                drill.ID = Convert.ToInt32(newDrill.Attribute("ID").Value);

                data.Element("RaptorMathDrills").Add(newDrill);
                drillList.Add(drill);
                data.Save(drillXMLPath);
                return true;
            }
        }
Пример #5
0
        //------------------------------------------------------------------//
        // 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;
        }
Пример #6
0
        //------------------------------------------------------------------//
        // 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;
        }
Пример #7
0
 //----------------------------------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                                            //
 // Date: 4/3/14                                                                                 //
 //----------------------------------------------------------------------------------------------//
 /// <summary>Remove a drill from student's XML file.</summary>
 /// <param name="student">Student object to be modified.</param>
 /// <param name="drillToRemove">Drill object to be removed.</param>
 /// <returns>Boolean confirming removal success.</returns>
 public bool RemoveDrillFromStudent(Student student, Drill drillToRemove)
 {
     return XMLDriver.RemoveDrillFromStudentXML(student, drillToRemove);
 }
Пример #8
0
 //------------------------------------------------------------------//
 // 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;
 }
Пример #9
0
 //----------------------------------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                                            //
 // Date: 4/3/14                                                                                 //
 //----------------------------------------------------------------------------------------------//
 /// <summary>Add a drill to student's XML file.</summary>
 /// <param name="student">Student object to be modified.</param>
 /// <param name="drillToAdd">Drill object to be added.</param>
 /// <returns>Boolean confirming addition success.</returns>
 public bool AddDrillToStudent(Student student, Drill drillToAdd)
 {
     return XMLDriver.AddDrillToStudentXML(student, drillToAdd);
 }
Пример #10
0
        //----------------------------------------------------------------------------------------------//
        // 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;
        }
Пример #11
0
        //----------------------------------------------------------------------------------------------//
        // 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;
        }
Пример #12
0
 //----------------------------------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                                            //
 // Date: 4/3/14                                                                                 //
 //----------------------------------------------------------------------------------------------//
 /// <summary>Validation of drill data input.</summary>
 /// <param name="drillToValidate">Drill object to validate.</param>
 /// <returns>Boolean confirming validity.</returns>
 public bool isDrillInfoValid(Drill drillToValidate)
 {
     if (!(drillToValidate.DrillName.Equals(string.Empty))
         && (drillToValidate.Questions.All(char.IsDigit))
         && (drillToValidate.RangeStart.All(char.IsDigit) && (Convert.ToInt32(drillToValidate.RangeStart) > 0))
         && (drillToValidate.RangeEnd.All(char.IsDigit) && (Convert.ToInt32(drillToValidate.RangeEnd) > 0))
         && (drillToValidate.Operand.Equals("subtraction") || (drillToValidate.Operand.Equals("addition"))))
     {
         return true;
     }
     return false;
 }
Пример #13
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Remove a drill from a student in Student XML.</summary>
        /// <param name="student">Student object to be modified</param>
        /// <param name="DrillToRemove">Drill object to be removed.</param>
        /// <param name="studentXMLPath">Student XML file path.</param>
        /// <returns>Boolean confirming success.</returns>
        public bool RemoveDrillFromStudentXML(Student student, Drill DrillToRemove, string studentXMLPath)
        {
            XDocument data = XDocument.Load(studentXMLPath);

            XElement studentElement = data.Descendants("stu").Where(s => s.Attribute("ID").Value.Equals(student.ID.ToString())).FirstOrDefault();
            bool isDrillAlreadyAssignedToStudent = isDrillAssigned(student, DrillToRemove);
            if ((studentElement != null) && (isDrillAlreadyAssignedToStudent))
            {
                XElement newStudentDrill = new XElement("drill", DrillToRemove.ID);
                if (studentElement.Elements("drill") != null)
                {
                    foreach (XElement drill in studentElement.Elements("drill"))
                    {
                        if (DrillToRemove == student.curDrillList.Where(dri => dri.ID.Equals(Convert.ToInt32(drill.Value))).FirstOrDefault())
                        {
                            drill.Remove();
                            student.curDrillList.Remove(DrillToRemove);
                            data.Save(studentXMLPath);
                            return true;
                        }
                    }
                }
            }
            return false;
        }
Пример #14
0
        //------------------------------------------------------------------//
        // Authors: Joshua Boone and Justine Dinh                           //
        // Date: 4/28/14                                                    //
        //------------------------------------------------------------------//
        /// <summary>Deletes a drill from the xml.</summary>
        /// <param name="drill">The drill to remove.</param>
        /// <param name="fileName">XML file name.</param>
        public void DeleteDrill(Drill drill, string fileName)
        {
            XDocument drillXML = XDocument.Load(fileName);

            XElement drillElement = drillXML.Descendants("drill").Where(s => s.Attribute("ID").Value.Equals(drill.ID.ToString())).FirstOrDefault();
            Debug.WriteLine(drill.DrillName);
            Debug.WriteLine(drillElement);
            if (drillElement != null)
            {
                drillElement.Remove();
                drillXML.Save(fileName);
            }
        }
Пример #15
0
 //------------------------------------------------------------------//
 // Authors: Joshua Boone and Justine Dinh                           //
 // Date: 4/28/14                                                    //
 //------------------------------------------------------------------//
 /// <summary>Removes the passed in drill from the manger's drill list.</summary>
 public void RemoveDrillFromSystem(Drill drill)
 {
     mainDrillList.Remove(drill);
 }
Пример #16
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/5/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Default creation of Drill XML file.</summary>
        /// <param name="DrillXMLPath">Drill XML file path.</param>
        /// <returns>Boolean confirmation.</returns>
        public bool InitialCreateDrillXML(string DrillXMLPath)
        {
            Drill DrillOne = new Drill("10AddProb1to25", "10", "1", "25", "addition");
            DrillOne.ID = 1;
            XElement defaultDrillOne = CreateDrillNode(DrillOne);
            defaultDrillOne.SetAttributeValue("ID", DrillOne.ID);

            Drill DrillTwo = new Drill("10SubProb1to25", "10", "1", "25", "subtract");
            DrillTwo.ID = 2;
            XElement defaultDrillTwo = CreateDrillNode(DrillTwo);
            defaultDrillTwo.SetAttributeValue("ID", DrillTwo.ID);

            XDocument newDrillsDoc =
                new XDocument(
                    new XElement("RaptorMathDrills", defaultDrillOne, defaultDrillTwo));
            newDrillsDoc.Save(DrillXMLPath);
            return true;
        }
Пример #17
0
        //----------------------------------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                                            //
        // Date: 4/3/14                                                                                 //
        //----------------------------------------------------------------------------------------------//
        /// <summary>Validate Drill info and then add the drill to the drill XML</summary>
        /// <param name="drillName">Drill's name.</param>
        /// <param name="numQuestions">Drill's number of problems.</param>
        /// <param name="minValue">Drill's min value.</param>
        /// <param name="maxValue">Drill's max value.</param>
        /// <param name="add">Drill's operator if addition.</param>
        /// <param name="subtract">Drill's operator if subtraction.</param>
        /// <returns>Boolean confirming creation success.</returns>
        public bool CreateDrill(string drillName, string numQuestions, string minValue, string maxValue, bool add, bool subtract)
        {
            bool isDrillAdded = false;
            string operand = SetOperand(add, subtract);

            Drill newDrill = new Drill(drillName, numQuestions, minValue, maxValue, operand);
            bool isDrillValid = isDrillInfoValid(newDrill);
            if (isDrillValid)
                isDrillAdded = XMLDriver.AddNewDrill(newDrill, mainDrillList);

            return isDrillAdded;
        }
Пример #18
0
        //------------------------------------------------------------------//
        // Authors: Cody Jordan, Cian Carota                                //
        // Date: 4/1/14                                                     //
        //------------------------------------------------------------------//
        /// <summary>Load a list of drills from XML to local.</summary>
        /// <param name="drillList">List of drill objects to be populated.
        /// </param>
        /// <param name="fileName">XML file name.</param>
        public void LoadDrillXML(List<Drill> drillList, string fileName)
        {
            XDocument drillXML = XDocument.Load(fileName);

            foreach (XElement drill in drillXML.Root.Nodes())
            {
                Drill Drill = new Drill();
                Drill.ID = Convert.ToInt32(drill.Attribute("ID").Value);
                Drill.DrillName = drill.Element("drillName").Value;
                Drill.Questions = drill.Element("questions").Value;
                Drill.RangeStart = drill.Element("rangeStart").Value;
                Drill.RangeEnd = drill.Element("rangeEnd").Value;
                Drill.Operand = drill.Element("operand").Value;
                Drill.Wrong = drill.Element("wrong").Value;
                Drill.Skipped = drill.Element("skipped").Value;
                Drill.Percent = drill.Element("percent").Value;
                drillList.Add(Drill);
            }
        }
Пример #19
0
        //------------------------------------------------------------------//
        // Authors: Joshua Boone and Justine Dinh                           //
        // Date: 4/28/14                                                    //
        //------------------------------------------------------------------//
        /// <summary>Tries to find and return the drill with the given name.</summary>
        public Drill FindDrill(string drillName)
        {
            Drill toReturn = new Drill();
            foreach (Drill drill in mainDrillList)
            {
                if (drill.DrillName == drillName)
                {
                    toReturn = drill;
                    break;
                }
            }

            return toReturn;
        }
Пример #20
0
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/5/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Remove a drill from Student XML.</summary>
 /// <param name="student">Student object to be modified.</param>
 /// <param name="DrillToRemove">Drill object to be removed.</param>
 /// <returns>Boolean confirmation.</returns>
 public bool RemoveDrillFromStudentXML(Student student, Drill DrillToRemove)
 {
     return XMLStudentDriver.RemoveDrillFromStudentXML(student, DrillToRemove, studentXMLPath);
 }
Пример #21
0
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/5/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Add a drill to Student XML.</summary>
 /// <param name="student">Student object to be modified.</param>
 /// <param name="drillToAdd">Drill object to be added.</param>
 /// <returns>Boolean confirmation.</returns>
 public bool AddDrillToStudentXML(Student student, Drill drillToAdd)
 {
     return XMLStudentDriver.AddDrillToStudentXML(student, drillToAdd, studentXMLPath);
 }
Пример #22
0
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/5/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Add data from active session to XML.</summary>
 /// <param name="currentStudent">Student object to be modified.</param>
 /// <param name="currentDrill">Drill object to be modified.</param>
 public void WriteCurrentSession(Student currentStudent, Drill currentDrill)
 {
     XMLStudentDriver.WriteCurrentSession(currentStudent, currentDrill);
     /*
     Record RecordToAdd = new Record(currentDrill.DrillName, DateTime.Now.ToString("M/d/yyyy"), currentDrill.Questions, currentDrill.RangeStart,
         currentDrill.RangeEnd, currentDrill.Operand, currentDrill.Wrong, currentDrill.Percent, currentDrill.Skipped);
     AddRecordToStudent(currentStudent, RecordToAdd);*/
 }
Пример #23
0
 //------------------------------------------------------------------//
 // Authors: Cody Jordan, Cian Carota                                //
 // Date: 4/5/14                                                     //
 //------------------------------------------------------------------//
 /// <summary>Check if drill already is assigned to a particular
 /// student.</summary>
 /// <param name="student"></param>
 /// <param name="drill"></param>
 /// <returns></returns>
 public bool isDrillAssigned(Student student, Drill drill)
 {
     foreach (Drill studentDrill in student.CurDrillList)
     {
         if (studentDrill.ID == drill.ID)
         {
             return true;
         }
     }
     return false;
 }