private void OKButton_Click(object sender, EventArgs e)
        {
            Course course = new Course();
            course.CourseCode = Cause.Text;
            course.CourseName = Cause.Text;
            course.ExamTime = "no exam";
            Index index = new Index();
            index.IndexNumber = "-1";
            index.Group = "FOREVER ALONE";
            IndexRow indexRow = new IndexRow();
            indexRow.Day = (WeekDays)Convert.ToInt32(Day.Text);
            indexRow.StartTime = StartTime.Text;
            indexRow.EndTime = EndTime.Text;
            for (int i = 0; i < 13; i++)
            {
                indexRow.IsScheduledInWeek[i] = true;
            }

            course.addIndex(index);
            index.addIndexRow(indexRow);
            CoursePlanningController.CourseList.Add(course);

            source.Refresh();
            this.Close();
        }
 public void AddCourse(Course course)
 {
     if (course != null)
     {
         CoursePlanningController.CourseList.Add(course);
     }
 }
        public Course ParseCourseInformationFromHtmlString(string HtmlString)
        {
            Course courseToReturn = new Course();
            Index currentIndex = null;
            IndexRow currentIndexRow;
            string FinalTable;
            try
            {
                // process coursename
                string courseNameStartTag = "<TD WIDTH=\"100\"><B><FONT COLOR=#0000FF>";
                int courseNameStart = HtmlString.IndexOf(courseNameStartTag) + courseNameStartTag.Length;
                string courseNameStopTag = "</FONT>";
                string tempString = HtmlString.Substring(courseNameStart);
                int courseNameStop = tempString.IndexOf(courseNameStopTag);
                courseToReturn.CourseCode = tempString.Substring(0, courseNameStop);

                // process course title
                string courseTitleStartTag = "<TD WIDTH=\"500\"><B><FONT COLOR=#0000FF>";
                int courseTitleStart = HtmlString.IndexOf(courseTitleStartTag) + courseTitleStartTag.Length;
                string courseTitleStopTag = "</FONT>";
                tempString = HtmlString.Substring(courseTitleStart);
                int courseTitleStop = tempString.IndexOf(courseTitleStopTag);
                courseToReturn.CourseName = tempString.Substring(0, courseTitleStop);

                // process table information start
                // firstly extract tables
                string tableStartTag = "<TABLE  border>";
                int tableStart = HtmlString.IndexOf(tableStartTag) + tableStartTag.Length;
                string tableStopTag = "</TABLE>";
                tempString = HtmlString.Substring(tableStart);
                int tableStop = tempString.LastIndexOf(tableStopTag);
                FinalTable = tempString.Substring(0, tableStop);
            }
            catch
            {
                return null;
            }
            // deal with line break
            FinalTable = Regex.Replace(FinalTable, @"[\n\r]", "");

            HtmlParser hp1 = new HtmlParser();
            foreach (string row in hp1.GetTableRows(FinalTable))
            {
                HtmlParser hp2 = new HtmlParser();
                currentIndexRow = new IndexRow();
                int cellCount = 0;
                foreach (string cell in hp2.GetTableCells(row))
                {
                    // if this is a new index, add a new index
                    if (cellCount == 0 && !String.IsNullOrEmpty(cell))
                    {
                        currentIndex = new Index();
                        currentIndex.IndexNumber = String.Copy(cell);
                        courseToReturn.addIndex(currentIndex);
                    }
                    else
                    {
                        switch (cellCount)
                        {
                            case 1: // type information
                                currentIndexRow.Type = cell;
                                break;
                            case 2: //group information
                                currentIndex.Group = cell;
                                break;
                            case 3: // day information
                                currentIndexRow.Day = (WeekDays)Enum.Parse(typeof(WeekDays), cell);
                                break;
                            case 4: // time information
                                string[] temp = cell.Split('-');
                                currentIndexRow.StartTime = temp[0];
                                currentIndexRow.EndTime = temp[1];
                                break;
                            case 5: // venue information
                                currentIndexRow.Venue = cell;
                                break;
                            case 6: // week information
                                parseWeekInfo(currentIndexRow.IsScheduledInWeek, cell);
                                break;
                        }
                    }
                    cellCount++;
                }
                // finished one row, add the row into index
                if (currentIndex != null)
                    currentIndex.addIndexRow(currentIndexRow);
            }
            return courseToReturn;
        }