Ejemplo n.º 1
0
        static void ChangeDefaultSemester(string semester)
        {
            using (var dbContext = new RoomScheduleContext())
            {
                try
                {
                    List <string> availableSemesters = dbContext.Semester.Select(row => row.Name).ToList();

                    if (availableSemesters.Contains(semester))
                    {
                        dbContext.Semester.UpdateRange(dbContext.Semester);
                        foreach (Semester sem in dbContext.Semester)
                        {
                            sem.Default = false;
                        }
                        dbContext.Semester.FirstOrDefault(row => row.Name == semester).Default = true;

                        dbContext.SaveChanges();
                    }

                    Semester defaultSemester = dbContext.Semester.Where(sem => sem.Default == true).FirstOrDefault();

                    if (defaultSemester != null)
                    {
                        Console.WriteLine($"The default semester is {defaultSemester.Name}");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Operation failed: {e.Message}");
                }
            }
        }
Ejemplo n.º 2
0
            public void AddAlsoMeets(Class theClass, List <string> notes)
            {
                using (var dbContext = new RoomScheduleContext())
                {
                    string extraClass;
                    for (int i = 0; i < notes.Count; i++)
                    {
                        Class newClass = Class.Clone(theClass);

                        try
                        {
                            extraClass = notes.ElementAt(i);
                            List <string> temp = extraClass.Split(new char[] { ' ', '-', }).ToList();
                            temp.RemoveAll(s => s.Length == 0);
                            string[] parts = temp.ToArray();

                            if (parts.Length >= 8)
                            {
                                string type     = parts[0].Trim(':');
                                string building = parts[1];
                                string room     = parts[2];
                                string days     = parts[3];

                                string beginString    = parts[5];
                                string beginTimeOfDay = parts.Length == 9 ? parts[6] : "";
                                string endString      = parts[parts.Length - 2];
                                string endTimeOfDay   = parts[parts.Length - 1];

                                TimeSpan begin = beginString.Contains(":") ? TimeSpan.Parse(beginString) : TimeSpan.FromHours(int.Parse(beginString));
                                TimeSpan end   = endString.Contains(":") ? TimeSpan.Parse(endString) : TimeSpan.FromHours(int.Parse(endString));

                                begin = begin.Add(beginTimeOfDay == "" && endTimeOfDay.ToLower() == "pm" && !beginString.StartsWith("12")? TimeSpan.FromHours(12) : TimeSpan.FromTicks(0));
                                end   = end.Add(endTimeOfDay.ToLower() == "pm" && !(endString.StartsWith("12")) ? TimeSpan.FromHours(12) : TimeSpan.FromTicks(0));

                                // Change class parameters and add to database
                                newClass.Syn      = i == 0 ? -theClass.Syn : i == 1 ? -(int.MaxValue - theClass.Syn) : i == 2 ? (int.MaxValue - theClass.Syn) : throw new Exception("Too many also meets!");
                                newClass.Title    = theClass.Title + ' ' + type;
                                newClass.Building = building;
                                newClass.Room     = room;
                                newClass.Days     = days;
                                newClass.Begin    = begin;
                                newClass.End      = end;

                                dbContext.Class.Add(newClass);
                                dbContext.SaveChanges();
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine($"Unable to add extra class for {theClass.Syn}, {theClass.Title} because of exception: {e.Message}");
                            Console.WriteLine($"Inner exception: {e.InnerException.Message}");
                        }
                    }
                }
            }
Ejemplo n.º 3
0
 static void SemesterStatus()
 {
     using (var dbContext = new RoomScheduleContext())
     {
         Console.WriteLine("Semester table status:");
         foreach (Semester semester in dbContext.Semester)
         {
             Console.WriteLine($"Semester Name: {semester.Name}, Display: {semester.Display}, Default: {semester.Default}");
         }
     }
 }
Ejemplo n.º 4
0
 static void RemoveSemester(string semester)
 {
     using (var dbContext = new RoomScheduleContext())
     {
         try
         {
             dbContext.Semester.Remove(dbContext.Semester.Where(row => row.Name == semester).FirstOrDefault());
             dbContext.SaveChanges();
             SemesterStatus();
         }
         catch (Exception e)
         {
             Console.WriteLine($"Operation failed: {e.Message}");
         }
     }
 }
Ejemplo n.º 5
0
        static void AddSemester(string semester)
        {
            using (var dbContext = new RoomScheduleContext())
            {
                try
                {
                    dbContext.Semester.Add(new Semester {
                        Name = semester, Default = false, Display = true
                    });
                    dbContext.SaveChanges();
                    SemesterStatus();
                }

                catch (Exception e)
                {
                    Console.WriteLine($"Operation failed: {e.Message}");
                }
            }
        }
Ejemplo n.º 6
0
        static void RemoveAllClasses()
        {
            using (var dbContext = new RoomScheduleContext())
            {
                try
                {
                    Console.WriteLine("Attempting to remove all classes");

                    dbContext.Class.RemoveRange(dbContext.Class);
                    int classesRemoved = dbContext.SaveChanges();

                    Console.WriteLine($"{classesRemoved} classes removed");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Operation failed: {e.Message}");
                }
            }
        }
Ejemplo n.º 7
0
 public void Test()
 {
     using (var db = new RoomScheduleContext())
     {
         db.Class.Add(new Class()
         {
             Begin     = new TimeSpan(9, 0, 0),
             End       = new TimeSpan(9, 50, 0),
             Days      = "MWF",
             Building  = "HSC",
             Room      = "3113",
             Professor = "Richard Halterman",
             Section   = "A",
             Semester  = "F14",
             Title     = "CPTR124 Intro to Programming",
             Syn       = 1234,
         });
         var count = db.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 static void HideSemester(string semester)
 {
     using (var dbContext = new RoomScheduleContext())
     {
         try
         {
             Semester sem = dbContext.Semester.Where(row => row.Name == semester).FirstOrDefault();
             if (sem != null)
             {
                 dbContext.Semester.Update(sem);
                 sem.Display = false;
                 dbContext.SaveChanges();
             }
             SemesterStatus();
         }
         catch (Exception e)
         {
             Console.WriteLine($"Operation failed: {e.Message}");
         }
     }
 }
Ejemplo n.º 9
0
        static string GetSemester(string type, bool showOptions)
        {
            string semester;

            Console.WriteLine($"Enter semester to {type}");

            if (showOptions)
            {
                Console.WriteLine("Options:");
                using (var dbContext = new RoomScheduleContext())
                {
                    foreach (string sem in dbContext.Semester.Select(row => row.Name).ToList())
                    {
                        Console.WriteLine(sem);
                    }
                }
            }
            semester = Console.ReadLine();

            return(semester);
        }
Ejemplo n.º 10
0
        static void AddAllClasses()
        {
            try
            {
                int totalCount = 0;
                using (var dbcontext = new RoomScheduleContext())
                {
                    Parser parser = new Parser();
                    foreach (string semester in dbcontext.Semester.Select(semester => semester.Name))
                    {
                        parser.Semester = semester;
                        int count = parser.DoTheWork();
                        totalCount += count;
                        Console.WriteLine($"{count} classes added for the {semester} term");
                    }
                }

                Console.WriteLine($"Finished. Added {totalCount} classes for all semesters");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Operation failed: {e.Message}");
            }
        }
Ejemplo n.º 11
0
            public void parsePageForClasses(string url)
            {
                HtmlWeb      webClient = new HtmlWeb();
                HtmlDocument doc       = webClient.Load(url);

                var classesTable = doc.DocumentNode.Descendants("table").ElementAt(0);

                using (var dbcontext = new RoomScheduleContext())
                {
                    TimeSpan begin;
                    TimeSpan end;
                    string   days;
                    string   building;
                    string   room;
                    string   professor;
                    string   section;
                    string   title;
                    int      syn;

                    List <string> alsoMeetsNotes = new List <string>();

                    int rows      = 0;
                    int validRows = 0;
                    foreach (var tableRow in classesTable.ChildNodes)
                    {
                        rows++;
                        bool alsoMeets = false;
                        if (tableRow.ChildNodes.Count == 13 && tableRow.ChildNodes.ElementAt(1).Name != "th")
                        {
                            validRows++;
                            HtmlNode[] tableCells = tableRow.ChildNodes.ToArray();

                            string tempSyn = tableCells[1].Descendants("span").FirstOrDefault().InnerText;
                            int.TryParse(tempSyn, out syn);

                            section = tableCells[2].Descendants("div").FirstOrDefault().InnerText;

                            title = tableCells[3].Descendants("a").FirstOrDefault().InnerText;

                            if (tableCells[3].Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("note")).ToList().Count > 0)
                            {
                                alsoMeetsNotes = tableCells[3].Descendants("div").Where(d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("note")).FirstOrDefault().Descendants("span").FirstOrDefault().InnerText.Split(new char[] { '\n', '\r' }).ToList();
                                alsoMeetsNotes = alsoMeetsNotes.Where(note => note.ToLower().StartsWith("lecture") || note.ToLower().StartsWith("laboratory")).ToList();
                                alsoMeets      = alsoMeetsNotes.Count > 0 ? true : false;
                            }

                            professor = tableCells[5].Descendants("span").FirstOrDefault().InnerText;

                            string   place           = tableCells[6].Descendants("span").FirstOrDefault().InnerText;
                            string[] buildingAndRoom = GetBuildingAndRoom(place);
                            building = buildingAndRoom[0];
                            room     = buildingAndRoom.Length > 1 ? buildingAndRoom[1] : "";

                            days = tableCells[7].InnerText.Trim();

                            string beginTemp = tableCells[8].InnerText.Trim();
                            begin = beginTemp == "" ? new TimeSpan(0) : DateTime.Parse(beginTemp).TimeOfDay;

                            string endTemp = tableCells[9].InnerText.Trim();
                            end = endTemp == "" ? new TimeSpan(0) : DateTime.Parse(endTemp).TimeOfDay;

                            Class newClass = new Class()
                            {
                                Syn       = syn,
                                Section   = section,
                                Title     = title,
                                Professor = professor,
                                Building  = building,
                                Room      = room,
                                Begin     = begin,
                                End       = end,
                                Days      = days,
                                Semester  = m_semester
                            };
                            dbcontext.Class.Add(newClass);

                            if (alsoMeets)
                            {
                                AddAlsoMeets(Class.Clone(newClass), alsoMeetsNotes);
                            }
                        }
                    }
                    try
                    {
                        m_totalCount += dbcontext.SaveChanges();
                    }

                    catch (Exception e)
                    {
                        Console.WriteLine("Error saving page of classes to database: " + e.Message);
                    }
                }
            }