Esempio n. 1
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));
    }
Esempio n. 2
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));
        }
Esempio n. 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();
    }
Esempio n. 4
0
        /// <summary>
        /// อัพเดทหรือเพิ่มข้อมูล course catalog
        /// </summary>
        /// <param name="data">ข้อมูลที่ต้องการดำเนินการ</param>
        public async Task UpsertCourseCatalog(CourseCatalog data)
        {
            var update = Builders <CourseCatalog> .Update
                         .Set(it => it.GroupName, data.GroupName)
                         .Set(it => it.Advertisements, data.Advertisements)
                         .Set(it => it.Grade, data.Grade)
                         .Set(it => it.SideName, data.SideName)
                         .Set(it => it.PriceUSD, data.PriceUSD)
                         .Set(it => it.Series, data.Series)
                         .Set(it => it.Title, data.Title)
                         .Set(it => it.FullDescription, data.FullDescription)
                         .Set(it => it.DescriptionImageUrl, data.DescriptionImageUrl)
                         .Set(it => it.CreatedDate, data.CreatedDate)
                         .Set(it => it.DeletedDate, data.DeletedDate)
                         .Set(it => it.Semesters, data.Semesters)
                         .Set(it => it.IsFree, data.IsFree)
                         .Set(it => it.TotalWeeks, data.TotalWeeks);

            var updateOption = new UpdateOptions {
                IsUpsert = true
            };
            await MongoAccess.MongoUtil.Instance
            .GetCollection <CourseCatalog>(AppConfigOptions.CourseCatalogTableName)
            .UpdateOneAsync(it => it.id == data.id, update, updateOption);
        }
Esempio n. 5
0
        /// <summary>
        /// Upadtes the category filters for a given course catalog
        /// </summary>
        /// <param name="cat">Course catalog</param>
        /// <param name="allCourses">List of existing courses</param>
        /// <param name="db">Database context</param>
        /// <returns></returns>
        private async Task UpdateCategoryFiltersForCatalog(CourseCatalog cat, List <Course> allCourses, DatabaseContext db)
        {
            var doc = await SendGetRequest(_categoryUrl);

            var navi  = doc.GetElementbyId("pageTopNavi");
            var links = navi.Descendants().Where((d) => d.Name == "a" && d.Attributes.Any(a => a.Name == "class" && a.Value.Contains("depth_2")));
            var modifiedCatalogText = cat.ShortTitle.Replace("WS", "Winter").Replace("SS", "Sommer");

            if (links.Any(l => l.InnerText == modifiedCatalogText))
            {
                var url = links.First(l => l.InnerText == modifiedCatalogText).Attributes["href"].Value;
                doc = await SendGetRequest(BaseUrl + WebUtility.HtmlDecode(url));

                var nodes            = GetNodesForCategories(doc);
                var parentCategories = await UpdateCategoriesInDatabase(db, null, nodes, doc, true, cat, allCourses);

                do
                {
                    foreach (var category in parentCategories.Select(e => e.Value))
                    {
                        PaulRepository.AddLog($"Currently at filter {category.Title}", FatalityLevel.Verbose, "");
                    }
                    var tasks = parentCategories.Keys.Select(node => UpdateCategoryForHtmlNode(db, node, parentCategories[node], cat, allCourses)).ToList();
                    parentCategories = (await Task.WhenAll(tasks)).SelectMany(r => r).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                    await db.SaveChangesAsync();
                } while (parentCategories.Keys.Any());
            }
        }
 public CourseCatalogDTO(CourseCatalog cource)
 {
     CourseId        = cource.CourseId;
     Name            = cource.Name;
     Description     = cource.Description;
     CreatedByUserId = cource.CreatedByUserID;
 }
Esempio n. 7
0
        /// <summary>
        /// Updates all courses in the database for a given course catalog
        /// </summary>
        /// <param name="catalog">Catalog for which the courses should be updated</param>
        /// <param name="allCourses">List of courses that have already been parsed (from database)</param>
        /// <param name="db">Database context</param>
        public async Task UpdateCoursesInCourseCatalog(CourseCatalog catalog, List <Course> allCourses, DatabaseContext db)
        {
            var counter = 1;

            try
            {
                PaulRepository.AddLog($"Update for {catalog.ShortTitle} started!", FatalityLevel.Normal, "");

                var courseList = allCourses.Where(co => co.Catalogue.InternalID == catalog.InternalID && !co.IsTutorial).ToList();
                //ensure that every course has the right instance of the course catalog so that we don't get a tracking exception
                courseList.ForEach(course => course.Catalogue = catalog);

                var messages = await Task.WhenAll(new[] { "1", "2" }.Select(useLogo => SendPostRequest(catalog.InternalID, "", useLogo)));

                foreach (var message in messages)
                {
                    var document = new HtmlDocument();
                    document.Load(await message.Content.ReadAsStreamAsync());
                    var pageResult = GetPageSearchResult(document, counter);
                    if (pageResult.HasCourses)
                    {
                        await GetCourseList(db, document, catalog, courseList, updateUrls : true);
                    }


                    while (pageResult.LinksToNextPages.Count > 0)
                    {
                        var docs = await Task.WhenAll(pageResult.LinksToNextPages.Select(s => SendGetRequest(BaseUrl + s)));

                        //Getting course list for at most 3 pages
                        var courses = await Task.WhenAll(docs.Select(d => GetCourseList(db, d, catalog, courseList, updateUrls: true)));

                        counter   += pageResult.LinksToNextPages.Count;
                        pageResult = GetPageSearchResult(docs.Last(), counter);
                    }
                }

                await UpdateCoursesInDatabase(db, courseList, catalog);

                PaulRepository.AddLog($"Update for {catalog.ShortTitle} completed!", FatalityLevel.Normal, "");
            }
            catch (DbUpdateConcurrencyException e)
            {
                //db.ChangeTracker.Entries().First(entry => entry.Equals(e)).State == EntityState.Detached;
                var str = new StringBuilder();
                foreach (var entry in e.Entries)
                {
                    str.AppendLine("Entry involved: " + entry.Entity + " Type: " + entry.Entity.GetType().Name);
                }

                PaulRepository.AddLog($"DbUpdateConcurrency failure: {e} in {catalog.Title} at round {counter}", FatalityLevel.Critical, "Nightly Update");
                PaulRepository.AddLog($"DbUpdateConcurrency failure: {str} in {catalog.Title}", FatalityLevel.Critical, "Nightly Update");
            }
            catch (Exception e)
            {
                PaulRepository.AddLog("Update failure: " + e + " in " + catalog.Title, FatalityLevel.Critical, "Nightly Update");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Assumes mutually-exclusive access to _seenCourseIdsByCatalog. Returns true
        /// iff the ID was not seen before for this catalog.
        /// </summary>
        /// <param name="catalog"></param>
        /// <param name="courseId"></param>
        /// <returns></returns>
        private bool AddSeenCourseId(CourseCatalog catalog, string courseId)
        {
            if (!_seenCourseIdsByCatalog.ContainsKey(catalog))
            {
                _seenCourseIdsByCatalog[catalog] = new HashSet <string>();
            }

            return(_seenCourseIdsByCatalog[catalog].Add(courseId));
        }
Esempio n. 9
0
        //Creater nye objekter i systemet
        public CourseMDVM()
        {
            _courseCatalog = new CourseCatalog();
            _courseCatalog.Load();

            _deletionCommand = new RelayCommand(DeleteCourse, () => _selectedCourse != null);
            _updateCommand   = new RelayCommand(UpdateCourse, () => _selectedCourse != null);
            _createCommand   = new RelayCommand(CreateCourse, () => true);
        }
Esempio n. 10
0
        private static async Task RemoveCourseCatalogAsync(DatabaseContext db, CourseCatalog catalog)
        {
            db.ChangeTracker.AutoDetectChangesEnabled = false;
            db.ChangeTracker.QueryTrackingBehavior    = QueryTrackingBehavior.NoTracking;
            var schedules = db.Schedules.IncludeAll().Where(s => s.CourseCatalogue.InternalID == catalog.InternalID);

            foreach (var s in schedules)
            {
                await db.Database.ExecuteSqlCommandAsync($"DELETE FROM SelectedCourseUser WHERE SelectedCourseId IN ({String.Join(",", s.SelectedCourses.Select(selectedCourse => selectedCourse.Id))}) ");

                await db.Database.ExecuteSqlCommandAsync($"DELETE FROM SelectedCourse Where ScheduleId = @p0", parameters : s.Id);

                await db.Database.ExecuteSqlCommandAsync($"DELETE FROM User Where ScheduleId = @p0", parameters : s.Id);

                db.Entry(s).State = EntityState.Deleted;
            }
            await db.SaveChangesAsync();

            //Delete Dates
            await db.Database.ExecuteSqlCommandAsync($"DELETE FROM DATE WHERE CourseId IN(SELECT Id FROM Course WHERE Course.CatalogueInternalID = {catalog.InternalID})");

            await db.SaveChangesAsync();

            //Delete ExamDates
            await db.Database.ExecuteSqlCommandAsync($"DELETE FROM ExamDate WHERE CourseId IN(SELECT Id FROM Course WHERE Course.CatalogueInternalID = {catalog.InternalID})");

            await db.SaveChangesAsync();

            //Delete Connected Courses
            await db.Database.ExecuteSqlCommandAsync($"DELETE FROM ConnectedCourse WHERE CourseId IN(SELECT Id FROM Course WHERE Course.CatalogueInternalID = {catalog.InternalID}) OR CourseId2 IN(SELECT Id FROM Course WHERE Course.CatalogueInternalID = {catalog.InternalID})");

            //Delete category courses
            await db.Database.ExecuteSqlCommandAsync($"DELETE FROM CategoryCourse WHERE CourseId IN(SELECT Id FROM Course WHERE Course.CatalogueInternalID = {catalog.InternalID})");

            //Delete category filters (workaround since EF can't perform the normal SQL delete)
            var categoryFilters = db.CategoryFilters.IncludeAll().Where(c => c.CourseCatalog.InternalID.Equals(catalog.InternalID)).ToList();

            while (categoryFilters.Any())
            {
                using (var readOnlyContext = new DatabaseContext(_filename, _basePath))
                {
                    var toDeleteCategoryFilters = categoryFilters.Where(c => !c.Subcategories.Any() || (!c.Subcategories.Any() && !categoryFilters.Any(c2 => c2.Subcategories.Contains(c))));
                    await db.Database.ExecuteSqlCommandAsync($"DELETE FROM CategoryFilter WHERE ID IN({String.Join(",", toDeleteCategoryFilters.Select(c => c.ID))})");

                    categoryFilters = db.CategoryFilters.IncludeAll().Where(c => c.CourseCatalog.InternalID.Equals(catalog.InternalID)).ToList();
                }
            }

            //Workaround for ForeignKey constraint failed
            await db.Database.ExecuteSqlCommandAsync($"DELETE FROM Course WHERE CatalogueInternalID = {catalog.InternalID} AND IsTutorial=1");

            await db.Database.ExecuteSqlCommandAsync($"DELETE FROM Course WHERE CatalogueInternalID = {catalog.InternalID}");

            db.Catalogues.Remove(catalog);
            await db.SaveChangesAsync();
        }
        public CourseCatalog CourseCatalogFind(string CatalogID)
        {
            String stmtId = "CourseCatalog_Find";

            Hashtable ht = new Hashtable();

            ht.Add("CatalogID", CatalogID);
            CourseCatalog result = ExecuteQueryForObject <CourseCatalog>(stmtId, ht);

            return(result);
        }
Esempio n. 12
0
        public static List <Course> SearchCourses(string name, CourseCatalog catalog)
        {
            var courses = Courses.Where(c =>
                                        !c.IsTutorial &&
                                        c.Catalogue.Equals(catalog) &&
                                        (!c.IsConnectedCourse || c.ConnectedCourses.All(course => course.IsConnectedCourse)));

            var search = new PrioritySearch <Course>(new Func <Course, string>[] { c => c.InternalCourseID, c => c.ShortName, c => c.Name, c => c.Docent });

            return(search.Search(courses, name));
        }
Esempio n. 13
0
        private static string GetCourseCatalogOrder(CourseCatalog catalog)
        {
            var match = Regex.Match(catalog.ShortTitle, @"(WS|SS)\s*([0-9]+)");

            if (match.Success && match.Groups.Count >= 3)
            {
                return(match.Groups[2].Value + match.Groups[1].Value);
            }
            else
            {
                return(catalog.ShortTitle);
            }
        }
        // GET: CourseCatalogs/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CourseCatalog courseCatalog = await db.CourseCatalogs.FindAsync(id);

            if (courseCatalog == null)
            {
                return(HttpNotFound());
            }
            return(View(courseCatalog));
        }
    //******************************************
    // Test scaffold.
    static void Main()
    {
        // We create a CourseCatalog object ...

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

        //  Read data from input files
        catalog.ReadCourseCatalogData();
        catalog.ReadPrerequisitesData();

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

        catalog.Display();
    }
        public async Task <ActionResult> Create([Bind(Include = "Id,GroupName,Grade,SideName,PriceUSD,Series,Title,FullDescription,TotalWeeks,DescriptionImageUrl,IsFree,RecLog")] CourseCatalog courseCatalog, IEnumerable <string> Advertisements)
        {
            if (ModelState.IsValid)
            {
                var advetisements = Advertisements ?? Enumerable.Empty <string>();
                courseCatalog.Advertisements     = string.Join("#;", advetisements);
                courseCatalog.RecLog.CreatedDate = DateTime.Now;
                db.CourseCatalogs.Add(courseCatalog);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(courseCatalog));
        }
Esempio n. 17
0
 public void DataBind(CourseCatalog data = null)
 {
     if (data == null)
     {
         courseCatalog = new CourseCatalog();
         state         = FormState.Add;
     }
     else
     {
         state = FormState.Modify;
         txtCatalogName.Text = data.CatalogName;
         txtCatalogSort.Text = data.CatalogSort.ToString();
         o = data.CourseID;
     }
 }
        public void CourseCatalogInsert(CourseCatalog data)
        {
            //String stmtId = "CourseCatalog_Insert";
            //ExecuteInsert(stmtId, courseCatalog);
            aers_sys_seedSqlMapDao dal = new aers_sys_seedSqlMapDao();

            data.CourseID = dal.GetMaxID("CourseCatalog");
            String    stmtId = "CourseCatalog_Insert";
            Hashtable ht     = new Hashtable();

            ht.Add("CatalogID", data.CatalogID);
            ht.Add("CourseID", data.CourseID);
            ht.Add("CatalogName", data.CatalogName);
            ht.Add("CatalogSort", data.CatalogSort);

            ExecuteInsert(stmtId, data);
        }
Esempio n. 19
0
    //******************************************
    // 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();
    }
Esempio n. 20
0
        public ResultEntity deleteChapter(int?chapterID)
        {
            ResultEntity resultEntity = new ResultEntity();
            ChapterNode  temp         = courseService.getChapterByID(chapterID);

            if (temp != null)
            {
                CourseCatalog courseCatalog = new CourseCatalog();
                courseCatalog.setChapterNode(temp);
                courseService.deleteChapter(courseCatalog);
                resultEntity.setState(courseService.getChapterByID(chapterID) == null ? 1 : 0);
            }
            else
            {
                resultEntity.setState(0);
            }
            resultEntity.setMessage(resultEntity.getState() == 1 ? "删除成功!" : "删除失败,该章节不存在!");
            return(resultEntity);
        }
Esempio n. 21
0
        private void picdelete_Click(object sender, EventArgs e)
        {
            if (this.gridView1.FocusedRowHandle >= 0)
            {
                CourseCatalog data = this.gridView1.GetRow(this.gridView1.FocusedRowHandle) as CourseCatalog;

                if ((MessageBox.Show("确定要删除吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes))
                {
                    int i = dal.Delete(data.CatalogID);
                    if (i > 0)
                    {
                        DataBind();
                    }
                    else
                    {
                        MessageBox.Show("删除失败!");
                    }
                }
            }
        }
        // GET: CourseCatalogs/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CourseCatalog courseCatalog = await db.CourseCatalogs.FindAsync(id);

            if (courseCatalog == null)
            {
                return(HttpNotFound());
            }
            var semesters = db.Semesters.Include(s => s.CourseCatalog)
                            .Where(it => !it.RecLog.DeletedDate.HasValue)
                            .OrderBy(it => it.RecLog.CreatedDate);

            ViewBag.Semesters = await semesters.ToListAsync();

            return(View(courseCatalog));
        }
Esempio n. 23
0
        public static async Task <Schedule> CreateNewScheduleAsync(CourseCatalog catalog)
        {
            using (var db = new DatabaseContext(_filename, _basePath))
            {
                db.Attach(catalog);
                Schedule schedule = new Schedule();
                var      guid     = Guid.NewGuid().ToString();
                while (db.Schedules.Any(s => s.Id == guid))
                {
                    guid = Guid.NewGuid().ToString();
                }
                schedule.Id = guid;
                schedule.CourseCatalogue = catalog;
                schedule.Name            = $"Stundenplan {catalog.ShortTitle}";
                db.Schedules.Add(schedule);
                await db.SaveChangesAsync();

                return(schedule);
            }
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            CourseCatalog courseCatalog = await db.CourseCatalogs.FindAsync(id);

            var now = DateTime.Now;

            courseCatalog.RecLog.DeletedDate = now;
            var semesterQry = courseCatalog.Semesters;

            foreach (var item in semesterQry)
            {
                item.RecLog.DeletedDate = now;
            }
            var unitQry = semesterQry.SelectMany(it => it.Units);

            foreach (var item in unitQry)
            {
                item.RecLog.DeletedDate = now;
            }
            var lessonQry = unitQry.SelectMany(it => it.Lessons);

            foreach (var item in lessonQry)
            {
                item.RecLog.DeletedDate = now;
            }
            var adsQry = lessonQry.SelectMany(it => it.Advertisements);

            foreach (var item in adsQry)
            {
                item.RecLog.DeletedDate = now;
            }
            var totdQry = lessonQry.SelectMany(it => it.TopicOfTheDays);

            foreach (var item in totdQry)
            {
                item.RecLog.DeletedDate = now;
            }
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "Id,GroupName,Grade,SideName,PriceUSD,Series,Title,FullDescription,TotalWeeks,DescriptionImageUrl,IsFree,RecLog")] CourseCatalog courseCatalog, IEnumerable <string> Advertisements)
        {
            if (ModelState.IsValid)
            {
                var selectedCourseCatalog = await db.CourseCatalogs.FirstOrDefaultAsync(it => it.Id == courseCatalog.Id);

                if (selectedCourseCatalog == null)
                {
                    return(View("Error"));
                }

                var advetisements = Advertisements ?? Enumerable.Empty <string>();
                selectedCourseCatalog.Advertisements      = string.Join("#;", advetisements);
                selectedCourseCatalog.GroupName           = courseCatalog.GroupName;
                selectedCourseCatalog.Grade               = courseCatalog.Grade;
                selectedCourseCatalog.SideName            = courseCatalog.SideName;
                selectedCourseCatalog.PriceUSD            = courseCatalog.PriceUSD;
                selectedCourseCatalog.Series              = courseCatalog.Series;
                selectedCourseCatalog.Title               = courseCatalog.Title;
                selectedCourseCatalog.FullDescription     = courseCatalog.FullDescription;
                selectedCourseCatalog.TotalWeeks          = courseCatalog.TotalWeeks;
                selectedCourseCatalog.DescriptionImageUrl = courseCatalog.DescriptionImageUrl;
                selectedCourseCatalog.IsFree              = courseCatalog.IsFree;
                foreach (var cc in selectedCourseCatalog.Licenses)
                {
                    cc.Grade = courseCatalog.Grade.ToString();
                    foreach (var item in cc.TeacherKeys)
                    {
                        item.Grade = courseCatalog.Grade.ToString();
                    }
                }

                await db.SaveChangesAsync();

                return(RedirectToAction("Details", new { @id = selectedCourseCatalog.Id }));
            }
            return(View(courseCatalog));
        }
Esempio n. 26
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);

        // 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();
    }
        public void CourseCatalogUpdate(CourseCatalog courseCatalog)
        {
            String stmtId = "CourseCatalog_Update";

            ExecuteUpdate(stmtId, courseCatalog);
        }
Esempio n. 28
0
    //******************************************
    // 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();
    }
Esempio n. 29
0
    //**************************************************************
    //
    public void ReadScheduleData(CourseCatalog courseCatalog)
    {
        // We're going to parse tab-delimited records into
        // six fields - courseNumber, sectionNumber, dayOfWeek,
        // timeOfDay, room, and capacity.  We'll use courseNumber to
        // look up the appropriate Course object, and will then
        // call the ScheduleSection() method to fabricate a
        // new Section object.

        StreamReader reader = null;

        try {
            // 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.

                Course c = courseCatalog.FindCourse(courseNumber);

                // Schedule the Section and add it to the Dictionary.

                Section s = c.ScheduleSection(sectionNumber, dayOfWeek,
                                              timeOfDay, room, capacity);
                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;
    }
Esempio n. 30
0
        /// <summary>
        /// Updates the category filters in the database by comparing new filters with the existing filters
        /// </summary>
        /// <param name="db">Database context</param>
        /// <param name="currentFilter">Current category filter</param>
        /// <param name="nodes">New html nodes (basically new filters)</param>
        /// <param name="doc">Current Html document</param>
        /// <param name="isTopLevel">Determines if we are in the first run (so at the top level of the "tree")</param>
        /// <param name="cat">Course catalog</param>
        /// <param name="allCourses">List of existing courses</param>
        /// <returns></returns>
        private async Task <Dictionary <HtmlNode, CategoryFilter> > UpdateCategoriesInDatabase(DatabaseContext db, CategoryFilter currentFilter, IEnumerable <HtmlNode> nodes, HtmlDocument doc, bool isTopLevel, CourseCatalog cat, List <Course> allCourses)
        {
            var dict = new Dictionary <HtmlNode, CategoryFilter>();
            List <CategoryFilter> topLevelCategories = null;

            foreach (var node in nodes)
            {
                var title = node.InnerText.Trim();
                if (isTopLevel)
                {
                    if (topLevelCategories == null)
                    {
                        topLevelCategories = db.CategoryFilters.IncludeAll().ToList();
                    }
                    var category = topLevelCategories.FirstOrDefault(n => n.IsTopLevel && n.CourseCatalog.InternalID == cat.InternalID && n.Title == title);
                    if (category == null)
                    {
                        category = new CategoryFilter {
                            Title = title, CourseCatalog = cat, IsTopLevel = isTopLevel
                        };
                        db.Entry(category).State = EntityState.Added;
                    }

                    dict[node] = category;
                }
                else
                {
                    var filter = currentFilter.Subcategories.FirstOrDefault(c => c.Title == title);
                    if (filter == null)
                    {
                        //we found a new category
                        await _writeLock.WaitAsync();

                        filter = new CategoryFilter {
                            Title = title, IsTopLevel = isTopLevel, CourseCatalog = cat
                        };
                        currentFilter?.Subcategories.Add(filter);
                        var entry = db.ChangeTracker.Entries().FirstOrDefault(e => e.Entity == currentFilter);
                        if (entry?.State != EntityState.Added)
                        {
                            entry.State = EntityState.Modified;
                        }

                        db.Entry(filter).State = EntityState.Added;
                        _writeLock.Release();
                    }

                    dict[node] = filter;
                }
            }

            var courses = await GetCourseList(db, doc, cat, allCourses, allowMultipleIdPasses : true);

            if (courses.Any() && currentFilter != null)
            {
                foreach (var course in courses)
                {
                    await _writeLock.WaitAsync();

                    if (!currentFilter.ParsedCourses.Any(c => c.CourseId == course.Id))
                    {
                        var catCourse = new CategoryCourse {
                            Category = currentFilter, CourseId = course.Id
                        };
                        db.Entry(catCourse).State = EntityState.Added;
                        currentFilter.ParsedCourses.Add(catCourse);
                    }
                    _writeLock.Release();
                }
            }

            return(dict);
        }
 public CourseSearchViewModel(CourseCatalog catalog, Schedule schedule)
 {
     _catalog        = catalog;
     _schedule       = schedule;
     CategoryBrowser = new CategoryBrowsingViewModel(schedule);
 }
Esempio n. 32
0
    //**************************************************************
    //
    public void ReadScheduleData(CourseCatalog courseCatalog)
    {
        // We're going to parse tab-delimited records into
        // six fields - courseNumber, sectionNumber, dayOfWeek,
        // timeOfDay, room, and capacity.  We'll use courseNumber to
        // look up the appropriate Course object, and will then
        // call the ScheduleSection() method to fabricate a
        // new Section object.

        StreamReader reader = null;

        try {
          // 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.

        Course c =  courseCatalog.FindCourse(courseNumber);

        // Schedule the Section and add it to the Dictionary.

        Section s = c.ScheduleSection(sectionNumber, dayOfWeek,
                              timeOfDay, room, capacity);
        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;
    }
Esempio n. 33
0
 static void Run()
 {
     var catalog       = new Dictionary <Category, Dictionary <Author, List <Course> > >();
     var courseCatalog = new CourseCatalog();
 }