Exemple #1
0
    //*********************************************************************
    //
    public void ReadAssignmentData(ScheduleOfClasses scheduleOfClasses)
    {
        // We have to read a second file containing the teaching
        // assignments.

        StreamReader reader = null;

        try {
            // Open the file.
            reader = new StreamReader(new FileStream(AssignmentsFile, FileMode.Open));

            string line = reader.ReadLine();
            while (line != null)
            {
                // Once again we'll make use of the Split() method to split
                // the line into substrings using tabs as the delimiter

                string[] strings = line.Split('\t');

                // Now assign the value of the fields to the appropriate
                // substring

                string id = strings[0];

                // The full section number is a concatenation of the
                // course no. and section no., separated by a hyphen;
                // e.g., "ART101 - 1".

                string fullSectionNumber = strings[1];

                // Look these two objects up in the appropriate collections
                // using the ScheduleOfClasses reference that was passed to
                // this method.

                Professor p = FindProfessor(id);
                Section   s = scheduleOfClasses.FindSection(fullSectionNumber);
                if (p != null && s != null)
                {
                    p.AgreeToTeach(s);
                }

                line = reader.ReadLine();
            }
        } //  end of try block
        catch (FileNotFoundException f) {
            Console.WriteLine(f);
        }
        catch (IOException i) {
            Console.WriteLine(i);
        }
        finally {
            //  Close the input stream.
            if (reader != null)
            {
                reader.Close();
            }
        }

        return;
    }
Exemple #2
0
    //**************************************
    //
    public void Display()
    {
        Console.WriteLine("Transcript for:  " +
                          this.StudentOwner.ToString());

        if (TranscriptEntries.Count == 0)
        {
            Console.WriteLine("\t(no entries)");
        }
        else
        {
            foreach (TranscriptEntry te in TranscriptEntries)
            {
                Section           sec = te.Section;
                Course            c   = sec.RepresentedCourse;
                ScheduleOfClasses soc = sec.OfferedIn;

                Console.WriteLine("\tSemester:        " + soc.Semester);
                Console.WriteLine("\tCourse No.:      " + c.CourseNumber);
                Console.WriteLine("\tCredits:         " + c.Credits);
                Console.WriteLine("\tGrade Received:  " + te.Grade);
                Console.WriteLine("\t-----");
            }
        }
    }
Exemple #3
0
    //********************************************
    // Test scaffold.
    //
    static void Main()
    {
        // We need a CourseCatalog object to test the Faculty class

        CourseCatalog catalog = new CourseCatalog("CourseCatalog.dat", "Prerequisites.dat");

        catalog.ReadCourseCatalogData();
        catalog.ReadPrerequisitesData();

        // We also need a ScheduleOfClasses object.

        ScheduleOfClasses schedule = new ScheduleOfClasses("SoC_SP2009.dat", "SP2009");

        schedule.ReadScheduleData(catalog);

        //  Create a Faculty object.

        Faculty faculty = new Faculty("Faculty.dat", "TeachingAssignments.dat");

        //  Read Faculty data from input file.

        faculty.ReadFacultyData();
        faculty.ReadAssignmentData(schedule);

        // Display information about the faculty.

        faculty.Display();
    }
Exemple #4
0
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main()
        {
            //  Create CourseCatalog, ScheduleOfClasses, and Faculty objects.
            //  The order of creation is important because a ScheduleOfClasses
            //  needs a CourseCatalog object to properly initialize and a
            //  Faculty object needs a ScheduleOfClasses object.

            //  Create a CourseCatalog object and read data from input files. dfdgfddfg

            CourseCatalog catalog = new CourseCatalog("CourseCatalog.dat", "Prerequisites.dat");
            catalog.ReadCourseCatalogData();
            catalog.ReadPrerequisitesData();

            //  Create a ScheduleOfClasses object and read data from input file.

            ScheduleOfClasses schedule = new ScheduleOfClasses("SoC_SP2009.dat", "SP2009");
            schedule.ReadScheduleData(catalog);

            //  Create a Faculty object and read data from input files.

            Faculty faculty = new Faculty("Faculty.dat", "TeachingAssignments.dat");
            faculty.ReadFacultyData();
            faculty.ReadAssignmentData(schedule);

            // Create and display an instance of the main GUI window

            Application.Run(new MainForm(schedule));
        }
Exemple #5
0
    static void Main()
    {
        //  Create CourseCatalog, ScheduleOfClasses, and Faculty objects.
        //  The order of creation is important because a ScheduleOfClasses
        //  needs a CourseCatalog object to properly initialize and a
        //  Faculty object needs a ScheduleOfClasses object.

        //  Create a CourseCatalog object and read data from input files.

        CourseCatalog catalog = new CourseCatalog("CourseCatalog.dat", "Prerequisites.dat");

        catalog.ReadCourseCatalogData();
        catalog.ReadPrerequisitesData();

        //  Create a ScheduleOfClasses object and read data from input file.

        ScheduleOfClasses schedule = new ScheduleOfClasses("SoC_SP2009.dat", "SP2009");

        schedule.ReadScheduleData(catalog);

        //  Create a Faculty object and read data from input files.

        Faculty faculty = new Faculty("Faculty.dat", "TeachingAssignments.dat");

        faculty.ReadFacultyData();
        faculty.ReadAssignmentData(schedule);

        // Create and display an instance of the main GUI window

        Application.Run(new MainForm(schedule));
    }
    //******************************************
    // Test scaffold.
    //
    static void Main()
    {
        // We need a CourseCatalog object to test the ScheduleOfClasses
        CourseCatalog catalog = new CourseCatalog("CourseCatalog.dat", "Prerequisites.dat");

        catalog.ReadCourseCatalogData();
        catalog.ReadPrerequisitesData();

        // Create a ScheduleOfClasses object ...
        ScheduleOfClasses schedule = new ScheduleOfClasses("SoC_SP2009.dat", "SP2009");

        //  Read data from the input file ...
        schedule.ReadScheduleData(catalog);

        // ... and use its Display() method to list the ScheduleOfClasses
        // results!

        schedule.Display();
    }
Exemple #7
0
        /// <summary>
        /// 此处为了省事,没有连接数据库,直接读文件
        /// </summary>
        /// <param name="semester"></param>
        /// <returns></returns>
        public ScheduleOfClasses GetScheduleOfClasses(string semester)
        {
            var          result = new ScheduleOfClasses(semester);
            StreamReader reader = null;

            try
            {
                var scheduleFile = HttpRuntime.AppDomainAppPath + @"data\Soc_SP2009.dat";
                // Open the file.
                reader = new StreamReader(new FileStream(scheduleFile, FileMode.Open));

                //  Read first line from input file.
                string line = reader.ReadLine();

                //  Keep reading lines until there aren't any more.
                while (line != null)
                {
                    // We'll use the Split() method of the String class to split
                    // the line we read from the file into substrings using tabs
                    // as the delimiter.

                    string[] strings = line.Split('\t');

                    // Now assign the value of the fields to the appropriate
                    // substring

                    string courseNumber  = strings[0];
                    string sectionValue  = strings[1];
                    string dayOfWeek     = strings[2];
                    string timeOfDay     = strings[3];
                    string room          = strings[4];
                    string capacityValue = strings[5];

                    // We need to convert the sectionNumber and capacityValue
                    // Strings to ints

                    int sectionNumber = Convert.ToInt32(sectionValue);
                    int capacity      = Convert.ToInt32(capacityValue);

                    // Look up the Course object in the Course Catalog.
                    var    courseDao = new CourseDAO();
                    Course c         = courseDao.GetCourse(courseNumber);
                    courseDao.GetPreRequisites(c);
                    // Schedule the Section and add it to the Dictionary.

                    Section s = c.ScheduleSection(sectionNumber, dayOfWeek,
                                                  timeOfDay, room, capacity);
                    result.AddSection(s);

                    line = reader.ReadLine();
                }
            }  //  End of try block
            catch (FileNotFoundException f)
            {
                Console.WriteLine(f);
            }
            catch (IOException i)
            {
                Console.WriteLine(i);
            }
            finally
            {
                //  Close the input stream.
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(result);
        }
Exemple #8
0
        /// <summary>
        /// 此处为了省事,没有连接数据库,直接读文件
        /// </summary>
        /// <param name="semester"></param>
        /// <returns></returns>
        public ScheduleOfClasses GetScheduleOfClasses(string semester)
        {
            var result = new ScheduleOfClasses(semester);
            StreamReader reader = null;
            try
            {
                var scheduleFile = HttpRuntime.AppDomainAppPath + @"data\Soc_SP2009.dat";
                // Open the file.
                reader = new StreamReader(new FileStream(scheduleFile, FileMode.Open));

                //  Read first line from input file.
                string line = reader.ReadLine();

                //  Keep reading lines until there aren't any more.
                while (line != null)
                {

                    // We'll use the Split() method of the String class to split
                    // the line we read from the file into substrings using tabs
                    // as the delimiter.

                    string[] strings = line.Split('\t');

                    // Now assign the value of the fields to the appropriate
                    // substring

                    string courseNumber = strings[0];
                    string sectionValue = strings[1];
                    string dayOfWeek = strings[2];
                    string timeOfDay = strings[3];
                    string room = strings[4];
                    string capacityValue = strings[5];

                    // We need to convert the sectionNumber and capacityValue
                    // Strings to ints

                    int sectionNumber = Convert.ToInt32(sectionValue);
                    int capacity = Convert.ToInt32(capacityValue);

                    // Look up the Course object in the Course Catalog.
                    var courseDao = new CourseDAO();
                    Course c = courseDao.GetCourse(courseNumber);
                    courseDao.GetPreRequisites(c);
                    // Schedule the Section and add it to the Dictionary.

                    Section s = c.ScheduleSection(sectionNumber, dayOfWeek,
                                          timeOfDay, room, capacity);
                    result.AddSection(s);

                    line = reader.ReadLine();
                }
            }  //  End of try block
            catch (FileNotFoundException f)
            {
                Console.WriteLine(f);
            }
            catch (IOException i)
            {
                Console.WriteLine(i);
            }
            finally
            {
                //  Close the input stream.
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return result;
        }
Exemple #9
0
    //**********************************************************
    //  Read Student data from an input file.
    //
    public void ReadStudentData(ScheduleOfClasses schedule)
    {
        // We're going to parse tab-delimited records into
        // four attributes -- id, name, major, and degree.

        StreamReader reader = null;

        try {
          // Open the file.
          reader = new StreamReader(new FileStream(StudentFile, FileMode.Open));

          //  Read first line from input file.

          string line = reader.ReadLine();

          // We'll use the Split() method of the String class to split
          // the line we read from the file into substrings using tabs
          // as the delimiter.

          string[] strings = line.Split('\t');

          // Now assign the value of the auto-implemented properties to the appropriate
          // substring

          Id = strings[0];
          Name = strings[1];
          Major = strings[2];
          Degree = strings[3];

          //  Read subsequent lines (if any) from input file.
          line = reader.ReadLine();

          //  Keep reading lines to get section info.
          while (line != null) {

        // The full section number is a concatenation of the
        // course no. and section no., separated by a hyphen;
        // e.g., "ART101 - 1".

        string fullSectionNumber = line.Trim();
        Section s = schedule.FindSection(fullSectionNumber);

        // Note that we are using the Section class's enroll()
        // method to ensure that bidirectionality is established
        // between the Student and the Section.
        s.Enroll(this);

        line = reader.ReadLine();
          }
        }  //  end of try block
        catch (FileNotFoundException f) {
          string message = "WARNING: "+f;
          //Console.WriteLine(f);
        }
        catch (IOException i) {
          string message = "WARNING: "+i;
          //Console.WriteLine(i);
        }
        finally {
          //  Close the input stream.
          if ( reader != null ) {
        reader.Close();
          }
        }

        return;
    }
    static void Main()
    {
        //  Create CourseCatalog, ScheduleOfClasses, and Faculty objects.
        //  The order of creation is important because a ScheduleOfClasses
        //  needs a CourseCatalog object to properly initialize and a
        //  Faculty object needs a ScheduleOfClasses object.

        //  Create a CourseCatalog object and read data from input files.

        CourseCatalog catalog = new CourseCatalog("CourseCatalog.dat", "Prerequisites.dat");

        catalog.ReadCourseCatalogData();
        catalog.ReadPrerequisitesData();

        //  Create a ScheduleOfClasses object and read data from input file.

        ScheduleOfClasses schedule = new ScheduleOfClasses("SoC_SP2009.dat", "SP2009");

        schedule.ReadScheduleData(catalog);

        //  Create a Faculty object and read data from input files.

        Faculty faculty = new Faculty("Faculty.dat", "TeachingAssignments.dat");

        faculty.ReadFacultyData();
        faculty.ReadAssignmentData(schedule);

        // We'll handle the students differently:  that is,
        // rather than loading them all in at application outset,
        // we'll pull in the data that we need just for one
        // Student when that Student logs on -- see the Student
        // class constructor for the details.

        // Let's temporarily create Students this way as a test,
        // to simulate Students logging on.  Note that only the
        // first Student has "preregistered" for courses based
        // on the content of his/her Student data file (see Student.cs
        // for details). Initial Student data is read from the
        // Student data files.

        Student s1 = new Student("111-11-1111.dat");

        s1.ReadStudentData(schedule);

        Student s2 = new Student("222-22-2222.dat");

        s2.ReadStudentData(schedule);

        Student s3 = new Student("333-33-3333.dat");

        s3.ReadStudentData(schedule);

        // Let's have one Student try enrolling in something, so
        // that we can simulate his/her logging off and persisting
        // the enrollment data in the ssn.dat file (see Student.cs
        // for details).

        Section sec = schedule.FindSection("ART101 - 1");

        sec.Enroll(s2);
        s2.WriteStudentData(); // Check contents of 222-22-2222.dat!

        // Let's see if everything got initialized properly
        // by calling various display methods!

        Console.WriteLine("====================");
        Console.WriteLine("Course Catalog:");
        Console.WriteLine("====================");
        Console.WriteLine("");
        catalog.Display();

        Console.WriteLine("====================");
        Console.WriteLine("Schedule of Classes:");
        Console.WriteLine("====================");
        Console.WriteLine("");
        schedule.Display();

        Console.WriteLine("======================");
        Console.WriteLine("Professor Information:");
        Console.WriteLine("======================");
        Console.WriteLine("");
        faculty.Display();

        Console.WriteLine("====================");
        Console.WriteLine("Student Information:");
        Console.WriteLine("====================");
        Console.WriteLine("");
        s1.Display();
        Console.WriteLine("");
        s2.Display();
        Console.WriteLine("");
        s3.Display();
    }
Exemple #11
0
    public MainForm(ScheduleOfClasses schedule)
    {
        currentUser   = null;
        this.schedule = schedule;

        // Create left-hand side labels
        int labelVertSpace = 40;
        int labelLeft      = 5;

        nameLabel           = new Label();
        nameLabel.Text      = "Student Name:";
        nameLabel.Font      = new Font(nameLabel.Font, FontStyle.Bold);
        nameLabel.AutoSize  = true;
        nameLabel.Top       = 5;
        nameLabel.Left      = labelLeft;
        nameLabel.TextAlign = ContentAlignment.MiddleCenter;

        idLabel           = new Label();
        idLabel.Text      = "ID Number:";
        idLabel.Font      = new Font(idLabel.Font, FontStyle.Bold);
        idLabel.AutoSize  = true;
        idLabel.Top       = nameLabel.Top + labelVertSpace;
        idLabel.Left      = labelLeft;
        idLabel.TextAlign = ContentAlignment.MiddleCenter;

        totalCourseLabel           = new Label();
        totalCourseLabel.Text      = "Total Courses:";
        totalCourseLabel.Font      = new Font(totalCourseLabel.Font, FontStyle.Bold);
        totalCourseLabel.AutoSize  = true;
        totalCourseLabel.Top       = idLabel.Top + labelVertSpace;
        totalCourseLabel.Left      = labelLeft;
        totalCourseLabel.TextAlign = ContentAlignment.MiddleCenter;

        registeredLabel          = new Label();
        registeredLabel.Text     = "Registered For:";
        registeredLabel.Font     = new Font(registeredLabel.Font, FontStyle.Bold);
        registeredLabel.AutoSize = true;
        registeredLabel.Top      = totalCourseLabel.Top + labelVertSpace;
        registeredLabel.Left     = labelLeft;

        // Create TextBox components
        nameTextBox           = new TextBox();
        nameTextBox.Width     = 140;
        nameTextBox.AutoSize  = true;
        nameTextBox.Top       = nameLabel.Top;
        nameTextBox.Left      = nameLabel.Right;
        nameTextBox.ReadOnly  = true;
        nameTextBox.BackColor = Color.White;

        idTextBox           = new TextBox();
        idTextBox.Width     = 140;
        idTextBox.AutoSize  = true;
        idTextBox.Top       = idLabel.Top;
        idTextBox.Left      = idLabel.Right;
        idTextBox.ReadOnly  = true;
        idTextBox.BackColor = Color.White;

        totalTextBox           = new TextBox();
        totalTextBox.Width     = 20;
        totalTextBox.AutoSize  = true;
        totalTextBox.Top       = totalCourseLabel.Top;
        totalTextBox.Left      = totalCourseLabel.Right;
        totalTextBox.ReadOnly  = true;
        totalTextBox.BackColor = Color.White;

        // Create right-hand side labels
        classScheduleLabel          = new Label();
        classScheduleLabel.Text     = "Schedule of Classes";
        classScheduleLabel.Font     = new Font(classScheduleLabel.Font, FontStyle.Bold);
        classScheduleLabel.AutoSize = true;
        classScheduleLabel.Top      = 5;
        classScheduleLabel.Left     = idTextBox.Right + 30;

        // Create "Schedule of Classes" ListBox Component
        scheduleListBox        = new ListBox();
        scheduleListBox.Font   = new Font(new FontFamily("Courier New"), 9.0f);
        scheduleListBox.Width  = 220;
        scheduleListBox.Height = 225;
        scheduleListBox.Top    = classScheduleLabel.Bottom + 5;
        scheduleListBox.Left   = idTextBox.Right + 30;

        // Display an alphabetically sorted course catalog list
        // in the scheduleListBox component.
        List <Section> sortedSections = schedule.GetSortedSections();

        foreach (Section section in sortedSections)
        {
            scheduleListBox.Items.Add(section);
        }

        // Create "Registered For" ListBox Component
        registeredListBox        = new ListBox();
        registeredListBox.Font   = new Font(new FontFamily("Courier New"), 9.0f);
        registeredListBox.Width  = 220;
        registeredListBox.Top    = registeredLabel.Bottom + 5;
        registeredListBox.Height = scheduleListBox.Bottom - registeredListBox.Top + 3;
        registeredListBox.Left   = labelLeft;

        // Add event handlers to the ListBox components
        scheduleListBox.SelectedIndexChanged   += ScheduleSelectionChanged;
        registeredListBox.SelectedIndexChanged += RegisteredSelectionChanged;

        // Create buttons
        int buttonHeight = 40;
        int buttonWidth  = 80;
        int buttonTop    = 275;

        logInButton        = new Button();
        logInButton.Text   = "Log In";
        logInButton.Height = buttonHeight;
        logInButton.Width  = buttonWidth;
        logInButton.Top    = buttonTop;
        logInButton.Left   = 10;

        dropButton        = new Button();
        dropButton.Text   = "Drop";
        dropButton.Height = buttonHeight;
        dropButton.Width  = buttonWidth;
        dropButton.Top    = buttonTop;
        dropButton.Left   = logInButton.Right + 15;

        saveButton        = new Button();
        saveButton.Text   = "Save My Schedule";
        saveButton.Height = buttonHeight;
        saveButton.Width  = buttonWidth;
        saveButton.Top    = buttonTop;
        saveButton.Left   = dropButton.Right + 15;

        addButton        = new Button();
        addButton.Text   = "Add";
        addButton.Height = buttonHeight;
        addButton.Width  = buttonWidth;
        addButton.Top    = buttonTop;
        addButton.Left   = saveButton.Right + 15;

        logOutButton        = new Button();
        logOutButton.Text   = "Log Out";
        logOutButton.Height = buttonHeight;
        logOutButton.Width  = buttonWidth;
        logOutButton.Top    = buttonTop;
        logOutButton.Left   = addButton.Right + 15;

        // Assign event handlers to the Buttons
        logInButton.Click  += LogInButtonClicked;
        addButton.Click    += AddButtonClicked;
        dropButton.Click   += DropButtonClicked;
        saveButton.Click   += SaveButtonClicked;
        logOutButton.Click += LogOutButtonClicked;

        // Initialize the buttons to their proper enabled/disabled
        // state.
        ResetButtons();

        // Add the GUI components to the form
        this.Controls.Add(logInButton);
        this.Controls.Add(dropButton);
        this.Controls.Add(saveButton);
        this.Controls.Add(addButton);
        this.Controls.Add(logOutButton);
        this.Controls.Add(classScheduleLabel);
        this.Controls.Add(idLabel);
        this.Controls.Add(idTextBox);
        this.Controls.Add(nameLabel);
        this.Controls.Add(nameTextBox);
        this.Controls.Add(totalCourseLabel);
        this.Controls.Add(totalTextBox);
        this.Controls.Add(registeredLabel);
        this.Controls.Add(scheduleListBox);
        this.Controls.Add(registeredListBox);

        // Set some appearance properties for the Form
        this.Text          = "Student Registration System";
        this.Height        = 370;
        this.Width         = 550;
        this.MinimumSize   = this.Size;
        this.StartPosition = FormStartPosition.CenterScreen;
    }
Exemple #12
0
    public MainForm(ScheduleOfClasses schedule)
    {
        currentUser = null;
        this.schedule = schedule;

        // Create left-hand side labels
        int labelVertSpace = 40;
        int labelLeft = 5;

        nameLabel = new Label();
        nameLabel.Text = "Student Name:";
        nameLabel.Font = new Font(nameLabel.Font, FontStyle.Bold);
        nameLabel.AutoSize = true;
        nameLabel.Top = 5;
        nameLabel.Left = labelLeft;
        nameLabel.TextAlign = ContentAlignment.MiddleCenter;

        idLabel = new Label();
        idLabel.Text = "ID Number:";
        idLabel.Font = new Font(idLabel.Font, FontStyle.Bold);
        idLabel.AutoSize = true;
        idLabel.Top = nameLabel.Top + labelVertSpace;
        idLabel.Left = labelLeft;
        idLabel.TextAlign = ContentAlignment.MiddleCenter;

        totalCourseLabel = new Label();
        totalCourseLabel.Text = "Total Courses:";
        totalCourseLabel.Font = new Font(totalCourseLabel.Font, FontStyle.Bold);
        totalCourseLabel.AutoSize = true;
        totalCourseLabel.Top = idLabel.Top + labelVertSpace;
        totalCourseLabel.Left = labelLeft;
        totalCourseLabel.TextAlign = ContentAlignment.MiddleCenter;

        registeredLabel = new Label();
        registeredLabel.Text = "Registered For:";
        registeredLabel.Font = new Font(registeredLabel.Font, FontStyle.Bold);
        registeredLabel.AutoSize = true;
        registeredLabel.Top = totalCourseLabel.Top + labelVertSpace;
        registeredLabel.Left = labelLeft;

        // Create TextBox components
        nameTextBox = new TextBox();
        nameTextBox.Width = 140;
        nameTextBox.AutoSize = true;
        nameTextBox.Top = nameLabel.Top;
        nameTextBox.Left = nameLabel.Right;
        nameTextBox.ReadOnly = true;
        nameTextBox.BackColor = Color.White;

        idTextBox = new TextBox();
        idTextBox.Width = 140;
        idTextBox.AutoSize = true;
        idTextBox.Top = idLabel.Top;
        idTextBox.Left = idLabel.Right;
        idTextBox.ReadOnly = true;
        idTextBox.BackColor = Color.White;

        totalTextBox = new TextBox();
        totalTextBox.Width = 20;
        totalTextBox.AutoSize = true;
        totalTextBox.Top = totalCourseLabel.Top;
        totalTextBox.Left = totalCourseLabel.Right;
        totalTextBox.ReadOnly = true;
        totalTextBox.BackColor = Color.White;

        // Create right-hand side labels
        classScheduleLabel = new Label();
        classScheduleLabel.Text = "Schedule of Classes";
        classScheduleLabel.Font = new Font(classScheduleLabel.Font, FontStyle.Bold);
        classScheduleLabel.AutoSize = true;
        classScheduleLabel.Top = 5;
        classScheduleLabel.Left = idTextBox.Right + 30;

        // Create "Schedule of Classes" ListBox Component
        scheduleListBox = new ListBox();
        scheduleListBox.Font = new Font(new FontFamily("Courier New"), 9.0f);
        scheduleListBox.Width = 220;
        scheduleListBox.Height = 225;
        scheduleListBox.Top = classScheduleLabel.Bottom + 5;
        scheduleListBox.Left = idTextBox.Right + 30;

        // Display an alphabetically sorted course catalog list
        // in the scheduleListBox component.
        List<Section> sortedSections = schedule.GetSortedSections();
        foreach( Section section in sortedSections) {
          scheduleListBox.Items.Add(section);
        }

        // Create "Registered For" ListBox Component
        registeredListBox = new ListBox();
        registeredListBox.Font = new Font(new FontFamily("Courier New"), 9.0f);
        registeredListBox.Width = 220;
        registeredListBox.Top = registeredLabel.Bottom + 5;
        registeredListBox.Height = scheduleListBox.Bottom - registeredListBox.Top + 3;
        registeredListBox.Left = labelLeft;

        // Add event handlers to the ListBox components
        scheduleListBox.SelectedIndexChanged += ScheduleSelectionChanged;
        registeredListBox.SelectedIndexChanged += RegisteredSelectionChanged;

        // Create buttons
        int buttonHeight = 40;
        int buttonWidth = 80;
        int buttonTop = 275;

        logInButton = new Button();
        logInButton.Text = "Log In";
        logInButton.Height = buttonHeight;
        logInButton.Width = buttonWidth;
        logInButton.Top = buttonTop;
        logInButton.Left = 10;

        dropButton = new Button();
        dropButton.Text = "Drop";
        dropButton.Height = buttonHeight;
        dropButton.Width = buttonWidth;
        dropButton.Top = buttonTop;
        dropButton.Left = logInButton.Right + 15;

        saveButton = new Button();
        saveButton.Text = "Save My Schedule";
        saveButton.Height = buttonHeight;
        saveButton.Width = buttonWidth;
        saveButton.Top = buttonTop;
        saveButton.Left = dropButton.Right + 15;

        addButton = new Button();
        addButton.Text = "Add";
        addButton.Height = buttonHeight;
        addButton.Width = buttonWidth;
        addButton.Top = buttonTop;
        addButton.Left = saveButton.Right + 15;

        logOutButton = new Button();
        logOutButton.Text = "Log Out";
        logOutButton.Height = buttonHeight;
        logOutButton.Width = buttonWidth;
        logOutButton.Top = buttonTop;
        logOutButton.Left = addButton.Right + 15;

        // Assign event handlers to the Buttons
        logInButton.Click += LogInButtonClicked;
        addButton.Click += AddButtonClicked;
        dropButton.Click += DropButtonClicked;
        saveButton.Click += SaveButtonClicked;
        logOutButton.Click += LogOutButtonClicked;

        // Initialize the buttons to their proper enabled/disabled
        // state.
        ResetButtons();

        // Add the GUI components to the form
        this.Controls.Add(logInButton);
        this.Controls.Add(dropButton);
        this.Controls.Add(saveButton);
        this.Controls.Add(addButton);
        this.Controls.Add(logOutButton);
        this.Controls.Add(classScheduleLabel);
        this.Controls.Add(idLabel);
        this.Controls.Add(idTextBox);
        this.Controls.Add(nameLabel);
        this.Controls.Add(nameTextBox);
        this.Controls.Add(totalCourseLabel);
        this.Controls.Add(totalTextBox);
        this.Controls.Add(registeredLabel);
        this.Controls.Add(scheduleListBox);
        this.Controls.Add(registeredListBox);

        // Set some appearance properties for the Form
        this.Text = "Student Registration System";
        this.Height = 370;
        this.Width = 550;
        this.MinimumSize = this.Size;
        this.StartPosition = FormStartPosition.CenterScreen;
    }
    //******************************************
    // Test scaffold.
    //
    static void Main()
    {
        // We need a CourseCatalog object to test the ScheduleOfClasses
        CourseCatalog catalog = new CourseCatalog("CourseCatalog.dat", "Prerequisites.dat");
        catalog.ReadCourseCatalogData();
        catalog.ReadPrerequisitesData();

        // Create a ScheduleOfClasses object ...
        ScheduleOfClasses schedule = new ScheduleOfClasses("SoC_SP2009.dat", "SP2009");

        //  Read data from the input file ...
        schedule.ReadScheduleData(catalog);

        // ... and use its Display() method to list the ScheduleOfClasses
        // results!

        schedule.Display();
    }
    //**********************************************************
    //  Read Student data from an input file.
    //
    public void ReadStudentData(ScheduleOfClasses schedule)
    {
        // We're going to parse tab-delimited records into
        // four attributes -- id, name, major, and degree.

        StreamReader reader = null;

        try {
            // Open the file.
            reader = new StreamReader(new FileStream(StudentFile, FileMode.Open));

            //  Read first line from input file.

            string line = reader.ReadLine();

            // We'll use the Split() method of the String class to split
            // the line we read from the file into substrings using tabs
            // as the delimiter.

            string[] strings = line.Split('\t');

            // Now assign the value of the auto-implemented properties to the appropriate
            // substring

            Id     = strings[0];
            Name   = strings[1];
            Major  = strings[2];
            Degree = strings[3];

            //  Read subsequent lines (if any) from input file.
            line = reader.ReadLine();

            //  Keep reading lines to get section info.
            while (line != null)
            {
                // The full section number is a concatenation of the
                // course no. and section no., separated by a hyphen;
                // e.g., "ART101 - 1".

                string  fullSectionNumber = line.Trim();
                Section s = schedule.FindSection(fullSectionNumber);

                // Note that we are using the Section class's enroll()
                // method to ensure that bidirectionality is established
                // between the Student and the Section.
                s.Enroll(this);

                line = reader.ReadLine();
            }
        } //  end of try block
        catch (FileNotFoundException f) {
            string message = "WARNING: " + f;
            //Console.WriteLine(f);
        }
        catch (IOException i) {
            string message = "WARNING: " + i;
            //Console.WriteLine(i);
        }
        finally {
            //  Close the input stream.
            if (reader != null)
            {
                reader.Close();
            }
        }

        return;
    }
Exemple #15
0
    //*********************************************************************
    //
    public void ReadAssignmentData(ScheduleOfClasses scheduleOfClasses)
    {
        // We have to read a second file containing the teaching
          // assignments.

        StreamReader reader = null;

        try {
          // Open the file.
          reader = new StreamReader(new FileStream(AssignmentsFile, FileMode.Open));

          string line = reader.ReadLine();
          while (line != null) {

        // Once again we'll make use of the Split() method to split
        // the line into substrings using tabs as the delimiter

        string[] strings = line.Split('\t');

        // Now assign the value of the fields to the appropriate
        // substring

        string id = strings[0];

        // The full section number is a concatenation of the
        // course no. and section no., separated by a hyphen;
        // e.g., "ART101 - 1".

        string fullSectionNumber = strings[1];

        // Look these two objects up in the appropriate collections
        // using the ScheduleOfClasses reference that was passed to
        // this method.

        Professor p = FindProfessor(id);
        Section s = scheduleOfClasses.FindSection(fullSectionNumber);
        if (p != null && s != null) {
          p.AgreeToTeach(s);
        }

        line = reader.ReadLine();
          }
        }  //  end of try block
        catch (FileNotFoundException f) {
          Console.WriteLine(f);
        }
        catch (IOException i) {
          Console.WriteLine(i);
        }
        finally {
          //  Close the input stream.
          if ( reader != null ) {
        reader.Close();
          }
        }

        return;
    }