private void StudentForm_Load(object sender, EventArgs e) { labelWelcome.Text = "Welcome, " + Program.users[Program.currentUser].fullName; foreach (Problem problem in Program.users[Program.currentUser].problemSet) { textBox1.AppendText(problem.printProblem() + "\r\n"); } currentProblem = getProblem(); displayProblem(); }
private Problem generateProblem() { Problem problem = new Problem(); problem.operand1 = rng.Next(min, max); problem.operand2 = rng.Next(min, max); problem.operation = isAddition; //True = addition selected (default), False = subtraction selected. if (problem.operation) problem.solution = problem.operand1 + problem.operand2; else problem.solution = problem.operand1 - problem.operand2; return problem; }
//Aurelio Arango and Stephanie Yao, 4-8-14 /* NOTE: Function component of load_ProblemSet(...)*/ public List<Problem> load_Problem(XElement setList) { List<Problem> problem_list = new List<Problem>(); int index = 0; foreach (XElement problem in setList.Descendants("Problem")) { //XElement user_student = user.Parent; //string userid = Parent.Name; string operation = problem.Element("Operator").Value; string operand1 = problem.Element("Operand1").Value; string operand2 = problem.Element("Operand2").Value; // string solved = problem.Element("IsSolved").Value; // string attempts = problem.Element("Attempts").Value; int op1 = Convert.ToInt32(operand1); int op2 = Convert.ToInt32(operand2); Problem newproblem = new Problem(op1, op2, operation); problem_list.Add(newproblem); // Debug.Write("OP1: " + problem_list[index].operand1 + " \n OP2: " + problem_list[index].operand2 + "\n"); index++; } return problem_list; }//end function
/* SHOWN EVENT, triggered when the form is shown (either initial creation, or when unhidden). * Builds the form to be specific to that student, and tries to get the first problem. * If the student has no problem file, it says that they have no problems, and disables inputs. * Kevin and Uriah */ private void StudentShown(object sender, EventArgs e) { //Aurelio Arango //Modified to get current date from current student //labelWelcome.Text = "Welcome, " + currentUser.fullName +"\n"+getDate(currentUser.userID); labelWelcome.Text = "Welcome, " + currentUser.fullName + "\n" + currentUser.lastLogin; labelWelcome.Left = (this.ClientSize.Width - labelWelcome.Width) / 2; loadTime(); //Obsolete code, replaced by following function call... //fileName = @"c:\users\public\MathDrills\ProblemSets\" + currentUser.userID + ".xml"; //if (File.Exists(fileName)) // StudentXMLFile = XElement.Load(fileName); setlist = Program.loadProblems(currentUser.group); //If they don't have any file, then they don't have any problems assigned. Say so, and disable inputs to avoid issues. //else if (setlist[0].group != currentUser.group ) { buttonSubmit.Enabled = inputAnswer.Enabled = false; labelQuestion.Text = "You have no problems assigned."; labelQuestion.Top -= 40; labelQuestion.Font = new Font("Microsoft Sans Serif", 13); CancelButton = buttonLogout; return; } //Find out how many problems in the current problem set they have. //problemSetSize = StudentXMLFile.Descendants("ProblemSet").ElementAt(setIndex).Descendants("Problem").Count(); problemSetSize = setlist[0].problems.Count(); max = problemSetSize * 2; //Get the first problem and display it. currentProblem = getProblem(); if (currentProblem != null ) displayProblem(); }
/* SUBMITANSWER, called after clicking the Submit button, checks if the input is valid, checks if it is correct, gives feedback, and finds the next problem * Kevin and Uriah */ public void submitAnswer() { int value; //Temporary, just used for int.TryParse, otherwise unneeded. //If they put in a non-number, or they put nothing in, this will (1) say so, (2) clear the value, and (3) re-select the input box. if ((inputAnswer.Text.Length == 0) || (!int.TryParse(inputAnswer.Text, out value))) { inputAnswer.Focus(); inputAnswer.Text = ""; labelFeedback.Text = "That was not a number"; return; } //checkAnswer() returns a boolean, true if they got the answer right, false if not. //If it was right, mark that problem as solved (so it will not reappear later) //Give the appropriate feedback either way. if (checkAnswer()) { inputAnswer.Text = ""; setlist[0].problems[problemIndex].isSolved = true; solved++; labelFeedback.Text = "Correct!"; } else { inputAnswer.Text = ""; labelFeedback.Text = "Incorrect"; } //Show the feedback for just a half-second by making the thread sleep Refresh(); System.Threading.Thread.Sleep(500); labelFeedback.Text = ""; //Whether they got the problem right or wrong, progress to the next one, display it, and focus on the input field. problemIndex++; problemIndex = (problemIndex % problemSetSize); //Make sure we loop through the problemset, not going out of bounds. currentProblem = getProblem(); //Get a new problem if (currentProblem != null) { displayProblem(); //Display it inputAnswer.Focus(); //Focus the textbox (so they can immediately type there) } else { } }
//Aurelio Arango & Stepahnie Yao //this method gets the the current problem from the Problem Set, public Problem getProblem() { Problem newproblem = new Problem(); // MARKER: WIP!!! if (solved != setlist[0].problems.Count) { //Debug.Write(setlist[0].problems[problemIndex]); newproblem = setlist[0].problems[problemIndex]; //problemIndex++; return newproblem; } else { labelFeedback.Text = "You've completed all problem sets assigned to you!"; buttonSubmit.Enabled = inputAnswer.Enabled = false; CancelButton = buttonLogout; return null; } }
/* SHOWN EVENT, triggered when the form is shown (either initial creation, or when unhidden). * Builds the form to be specific to that student, and tries to get the first problem. * If the student has no problem file, it says that they have no problems, and disables inputs. * Kevin and Uriah */ private void StudentShown(object sender, EventArgs e) { //Aurelio Arango //Modified to get current date from current student //labelWelcome.Text = "Welcome, " + currentUser.fullName +"\n"+getDate(currentUser.userID); labelWelcome.Text = "Welcome, " + currentUser.fullName + "\n" + currentUser.lastLogin; labelWelcome.Left = (this.ClientSize.Width - labelWelcome.Width) / 2; loadTime(); //Obsolete code, replaced by following function call... /* * Jorge & Aurelio & Kevin - Uncommenting code that was commented out in second cycle. Commenting this code is causing * for an unhandled exception to be thrown because it is trying to read a function */ fileName = @"c:\users\public\MathDrills\ProblemSets\setGroup" + currentUser.group + ".xml"; if (!File.Exists(fileName)) { Console.WriteLine("Dialogue Box: No problem sets found for current user. CLick ok."); goToLogin(); } else { StudentXMLFile = XElement.Load(fileName); setlist = Program.loadProblems(currentUser.group); //If they don't have any file, then they don't have any problems assigned. Say so, and disable inputs to avoid issues. //else if (setlist[0].group != currentUser.group ) { buttonSubmit.Enabled = inputAnswer.Enabled = false; labelQuestion.Text = "You have no problems assigned."; labelQuestion.Top -= 40; labelQuestion.Font = new Font("Microsoft Sans Serif", 13); CancelButton = buttonLogout; return; } //Find out how many problems in the current problem set they have. //problemSetSize = StudentXMLFile.Descendants("ProblemSet").ElementAt(setIndex).Descendants("Problem").Count(); problemSetSize = setlist[0].problems.Count(); max = problemSetSize * 2; //Get the first problem and display it. currentProblem = getProblem(); if (currentProblem != null ) displayProblem(); } }
/*Jorge Torres 4/29/2014 - Reworking the way this fucntion obtains the problem to display. * */ //Aurelio Arango & Stepahnie Yao /*this method gets the the current problem from the Problem Set, public Problem getProblem() { Problem newproblem = new Problem(); // MARKER: WIP!!! if (solved != setlist[0].problems.Count) { //Debug.Write(setlist[0].problems[problemIndex]); newproblem = setlist[0].problems[problemIndex]; //problemIndex++; return newproblem; } else { labelFeedback.Text = "You've completed all problem sets assigned to you!"; buttonSubmit.Enabled = inputAnswer.Enabled = false; CancelButton = buttonLogout; return null; } }*/ public Problem getProblem() { Problem newproblem = new Problem(); // MARKER: WIP!!! //Jorge Torres - lets verify that the date is correct for the attempt on the problem set DateTime now = DateTime.Now; String dueDateForProblemSet = null; Console.WriteLine(currentUser.getGroup); switch(currentUser.getGroup) { case "A": dueDateForProblemSet = (setlist[0].dueDate); break; case "B": dueDateForProblemSet = (setlist[1].dueDate); break; case "C": dueDateForProblemSet = (setlist[2].dueDate); break; } DateTime finalDueDate = DateTime.Parse(dueDateForProblemSet); if (now.Date <= finalDueDate.Date) { Console.WriteLine("we can still do this problem set!!!"); } else { Console.WriteLine("you ran our of time poop:" + finalDueDate + "&&" + now); } if (solved != setlist[0].problems.Count ) { //Debug.Write(setlist[0].problems[problemIndex]); newproblem = setlist[0].problems[problemIndex]; //problemIndex++; return newproblem; } else { labelFeedback.Text = "You've completed all problem sets assigned to you!"; buttonSubmit.Enabled = inputAnswer.Enabled = false; CancelButton = buttonLogout; return null; } }