Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

=+ What would it look like? Who should deliver it?

Answered: 1 week ago