private void button_Click(object sender, RoutedEventArgs e) { choice = (Course)(this.comboBox.SelectedItem); /************************************************************************************************** * * // TO DO - Create code to validate user selection (the choice object) * // and to display an error or a registation confirmation message accordinlgy * // Also update the total credit hours textbox if registration is confirmed for a selected course * * COMPLETED 12/13/2019 - RH ***************************************************************************************************/ /*******************************RH CODE ADDED FOR PROJECT IN THIS FUNCTION BELOW*******************/ if (this.listBox.Items.Contains(choice) && choice.IsRegisteredAlready()) { this.textBlock1.Text = "You have already registered for this " + choice.ToString() + " course"; // Add string to custom text block and print it to window. } else if (creditHours < 9) // Total credit hours cannot exceed 9 credit hours { this.listBox.Items.Add(choice); // Add each select to the output box of course. choice.SetToRegistered(); creditHours += 3; // Each course has 3 credit hours each and is updated. this.textBox.Text = Convert.ToString(creditHours); // TextBox is the credit hour text box displayed. this.textBlock1.Text = "Registration confirmed for course " + choice.ToString(); // Print string when each eligible course is added. } else { this.textBlock1.Text = "You cannot register for more than 9 credit hours."; } }
private void button_Click(object sender, RoutedEventArgs e) { choice = (Course)(this.comboBox.SelectedItem); string courseName = choice.ToString(); switch (validateUserSelection(choice)) { case 0: //Display error confirmation: Already registered label3.Content = "You have already registered for this course " + courseName; break; case 1: //Display error confirmation: Too many credit hours label3.Content = "You cannot register for more than 9 credit hours."; break; case 2: choice.SetToRegistered(); //Sets registration bool to true (See ValidateUserSelection function) listBox.Items.Add(choice); // Display a registration confirmation message label3.Content = "Registration confirmed for course " + courseName; TotalCreditHours += 3; // update the total credit hours textbox if registration is confirmed for a selected course textBox.Text = TotalCreditHours.ToString(); break; } }
private void button_Click(object sender, RoutedEventArgs e) { //Placed the code in a try statement block try { choice = (Course)(this.comboBox.SelectedItem); //Message if student clicks button before selection if (null == choice) { label3.Content = "Please make a selection"; return; } //Makes sure the student cant register for more than 9 credit hours if (totalCredit >= 9) { label3.Content = "You can not register for more than 9 credit hours"; return; } //else statement contains the process of student registering, detecting repeated entries //and confirming the registration for the selected course else { var isarepeat = false; foreach (var item in this.listBox.Items) { var courseItem = item as Course; if (null != courseItem) { if (courseItem.ToString() == choice.ToString()) { isarepeat = true; } } } if (isarepeat) { label3.Content = "You are Already Registered for Course " + choice; } else { this.listBox.Items.Add(choice); totalCredit = totalCredit + 3; textBox.Text = totalCredit.ToString(); label3.Content = "Registration Confirmed for Course " + choice; } } } //End of Try Block //Catches All Exceptions catch (Exception exception) { label3.Content = exception.Message; } }
private void button_Click(object sender, RoutedEventArgs e) { choice = (Course)(this.comboBox.SelectedItem); int creditHours = 0; String message = ""; // Validate user selection if (choice.IsRegisteredAlready()) { message = "Already registered for course: " + choice.ToString(); } else { if (this.textBox.Text != "") // First selection has "" for the Text value. { creditHours = int.Parse(this.textBox.Text); } if (creditHours >= 9) { message = "You cannot register for more than 9 credit hours."; } else { message = "Registration confirmed for course " + choice.ToString() + "."; choice.SetToRegistered(); // Update credit hours creditHours += 3; this.listBox.Items.Add(choice.ToString()); this.textBox.Text = creditHours.ToString(); } } // Display error or confirmation this.label3.Content = message; }
private void button_Click(object sender, RoutedEventArgs e) { /*int numericalCourseIdentifier = 0; * * choice = (Course)(this.comboBox.SelectedItem); * string chosenCourseName = choice.ToString(); //Retrieves string of course name * * numericalCourseIdentifier = IdentifyCourse(chosenCourseName, numericalCourseIdentifier); //Takes the course name and converts it to an integer representative * * switch (ValidateUserSelection(numericalCourseIdentifier, firstChoice, secondChoice, thirdChoice, TotalCredits)) //Updates the label3 text based on selection * { * case -1: * label3.Content = chosenCourseName + " is not a recognized course."; //Not really necessary, but I included it just in case * break; * case -2: * label3.Content = "You have already registered for this " + chosenCourseName + " course."; * break; * case -3: * label3.Content = "You cannot register for more than 9 credit hours."; * break; * case -4: * label3.Content = "Registration confirmed for course " + chosenCourseName; //Updates label to confirm registration * * TotalCredits += 3; * textBox.Text = TotalCredits.ToString(); * * if (firstChoice == 0) * firstChoice = numericalCourseIdentifier; * else if (secondChoice == 0) * secondChoice = numericalCourseIdentifier; * else if (thirdChoice == 0) * thirdChoice = numericalCourseIdentifier; * * listBox.Items.Add(choice); //Update the listBox with each registration * * break; * } * choice = (Course)(this.comboBox.SelectedItem); * string chosenCourseName = choice.ToString(); //Retrieves string of course name * * switch (validateSelection(choice)) * { * case 1: * label3.Content = "You have already registered for this " + chosenCourseName + " course."; * break; * case 2: * label3.Content = "You cannot register for more than 9 credit hours."; * break; * case 0: * label3.Content = "Registration confirmed for course " + chosenCourseName; //Updates label to confirm registration * choice.SetToRegistered(); * TotalCredits += 3; * textBox.Text = TotalCredits.ToString(); * listBox.Items.Add(choice); //Update the listBox with each registration * break; * } * } * * int ValidateUserSelection (int choice, int firstChoice, int secondChoice, int thirdChoice, int totalCredit) * { * if (choice < 1 || choice > 7) * return -1; * else if (choice == firstChoice || choice == secondChoice || choice == thirdChoice) * return -2; * else if (totalCredit > 8) * return -3; * return -4; */ choice = (Course)(this.comboBox.SelectedItem); string chosenCourseName = choice.ToString(); //Retrieves string of course name switch (ValidateUserSelection(choice)) { case 1: label3.Content = "You have already registered for this " + chosenCourseName + " course."; break; case 2: label3.Content = "You cannot register for more than 9 credit hours."; break; case 0: label3.Content = "Registration confirmed for course " + chosenCourseName; //Updates label to confirm registration choice.SetToRegistered(); TotalCredits += 3; textBox.Text = TotalCredits.ToString(); listBox.Items.Add(choice); //Update the listBox with each registration break; } }