Question: Graphical User Interfaces I am having the hardest time with getting this program to do two things. 1. Keep track of hom many credit hours

Graphical User Interfaces

I am having the hardest time with getting this program to do two things. 1. Keep track of hom many credit hours the person has and 2. write the courses registered for to a file. Everytime I try to get it to run it always comes back with an error either intentional or not. I have already transfered the source code of the courses over and just need help with the actual form. Any help would be greatly appreciated

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Capella.IT4747;

namespace u04a1_Registration_WinForm { public partial class Form1 : Form { private List courses = new List(); private bool display = false;

public Form1() { InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) { /* * When form loads, this code will read the course data from the file * and populate the combobox. */ try { // Using using statement makes sure file is closed when done using (StreamReader sr = new StreamReader(@"Data\course.data.txt")) { string line; while ((line = sr.ReadLine()) != null) { // Parse data and add Course objects to courses List as they are created string[] data = line.Split(','); // Need to convert credits and weeks to integers courses.Add(new Course(data[0], data[1], Convert.ToInt16(data[2]), Convert.ToInt16(data[3]))); } } // Map displayed value in courses combobox to CourseNumber courses.Sort((a, b) => a.CourseNumber.CompareTo(b.CourseNumber)); courseComboBox.DataSource = courses; courseComboBox.DisplayMember = "CourseNumber"; courseComboBox.ValueMember = "CourseNumber";

registeredCourseList.View = View.List; display = true; } catch(IOException ex) { statusMessageText.Text = "Error reading data: " + ex.Message; } catch(ArgumentOutOfRangeException ex) { statusMessageText.Text = "Error in input format: " + ex.Message; } } // Event handler for combobox selection private void courseComboBox_SelectedIndexChanged(object sender, EventArgs e) { if (display) { courses[courseComboBox.SelectedIndex].Selected = true; registeredCourseList.Items.Add(courses[courseComboBox.SelectedIndex].ToString()); }

}

private void completeRegistrationButton_Click(object sender, EventArgs e) { try { using (StreamWriter file = new StreamWriter(@"Data egisteredcourses.txt")) { foreach(Course c in courses) { if (c.IsRegisteredFor) { Console.WriteLine(c); file.WriteLine(c); } } } } catch (IOException ie) { Console.WriteLine("Error writing line in file."); Console.WriteLine(ie.Message); } } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!