コード例 #1
0
ファイル: Controller.cs プロジェクト: sdeloach/Scheduler
        public void ConvertKSISFileToLocal()
        {
            Semester KSISsemester = new Semester(gui);
            var      ofd          = new OpenFileDialog();

            ofd.Title  = "Open KSIS file";
            ofd.Filter = "CSV Files|*.csv";

            try
            {
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {   // read KSIS file
                    KSISsemester.KSISread(ofd.FileName);
                    gui.SetKSISFile(ofd.FileName);
                    KSISFileName = ofd.FileName;
                    WriteFileNames();

                    // save to local file
                    var sfd = new SaveFileDialog();
                    sfd.Title  = "Save to new local file";
                    sfd.Filter = "CSV Files|*.csv";
                    sfd.ShowDialog();
                    if (sfd.FileName != "")
                    {
                        gui.SetLocalFile(sfd.FileName);
                        localFileName = sfd.FileName;
                        WriteFileNames();
                        KSISsemester.Save(sfd.FileName);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        public string Print(Semester s, bool printAllSections, bool printAllDates)
        {
            if (s.Size() <= 0)
            {
                gui.WriteLine("No file loaded for printing.");
                return("");
            }

            // initialize local variables
            string lastCatalogNbr = "";
            string lastTopicDescr = "";

            string standardMeetingStartDt = "";
            string standardMeetingEndDt   = "";

            // making dangerous assumption that "standard" semester start and end dates are identical to the first section
            if (!printAllDates)
            {
                standardMeetingStartDt = s.ElementAt(0).MeetingStartDt;
                standardMeetingEndDt   = s.ElementAt(0).MeetingEndDt;
            }

            // sort by catalog number
            Semester semester = s.SortByCatalogNbr();

            // construct the output filename
            string filename = s.FileName.Substring(0, s.FileName.Length - 4) + "_schedule.html";

            //open file
            try
            {
                using (System.IO.StreamWriter printer = new System.IO.StreamWriter(filename, false))
                {
                    // print HTML header
                    printer.WriteLine("<html>");
                    printer.WriteLine("<head>");
                    printer.WriteLine("<title>" + semester.Name + " Line Schedule</title>");
                    printer.WriteLine("</head>");
                    printer.WriteLine("<body style='font-family=\"courier\"'>");
                    printer.WriteLine("<h1>" + semester.Name + "</h1>");
                    printer.WriteLine("<i>printed " + DateTime.Today.ToString("MMM dd, yyyy") + " " + DateTime.Now.ToString("HH:mm") + "</i>");

                    for (int x = 0; x < semester.Size(); x++)
                    {
                        Section sec = semester.ElementAt(x);

                        // skip sections we are not interested in seeing if printAllSections if false

                        if (!printAllSections)
                        {
                            if (!sec.HasBeenDeleted) // print all sections that have been deleted regardless of number
                            {
                                if (!sec.Instructor.Any() ||
                                    sec.CatalogNbr.Equals("999") || sec.CatalogNbr.Equals("990") ||
                                    sec.CatalogNbr.Equals("899") || sec.CatalogNbr.Equals("897") ||
                                    sec.CatalogNbr.Equals("898") || sec.CatalogNbr.Equals("895") ||
                                    (sec.CatalogNbr.Equals("690") && sec.TopicDescr.Equals(" ")) ||
                                    (sec.CatalogNbr.Equals("798") && sec.TopicDescr.Equals("Top/Vary By Student")) ||
                                    (sec.CatalogNbr.Equals("890") && sec.TopicDescr.Equals("Top/Vary By Student")))
                                {
                                    continue; //skip all the 80s, 798s, etc.
                                }
                            }
                        }
                        // print out lines for sections of interest
                        if (!sec.CatalogNbr.Equals(lastCatalogNbr) || (sec.CatalogNbr.Equals(lastCatalogNbr) && !sec.TopicDescr.Equals(lastTopicDescr)))
                        {
                            printer.WriteLine("</p>");
                            printer.WriteLine();
                            printer.Write("<p style=\"font-family:monospace;\"><strong>");
                            lastCatalogNbr = sec.CatalogNbr;
                            lastTopicDescr = sec.TopicDescr;
                            printer.Write(sec.Subject + OneSpace + sec.CatalogNbr + TwoSpaces
                                          + (sec.IsHidden || sec.ClassDescrVer ? "" : StartMark) + sec.ClassDescr
                                          + (sec.IsHidden || sec.ClassDescrVer ? "" : EndMark)
                                          + (!sec.TopicDescr.Equals(" ") ? " - " + sec.TopicDescr : ""));
                            printer.WriteLine("</strong><br>");
                        }

                        // highlight sections that were removed from the current semester
                        if (sec.HasBeenDeleted)
                        {
                            printer.Write("<span style=\"text-decoration: line-through\">");
                        }

                        // highlight sections that are listed as "hidden" in the current semester
                        if (sec.IsHidden)
                        {
                            printer.Write("<span style=\"color:blue; font-style: italic\">");
                        }

                        // format section number
                        string section = Utility.PadRightWithString(sec.SectionName, 3);
                        section = sec.IsHidden || sec.SectionVer ? section : StartMark + section + EndMark;

                        //format enrollment cap
                        string enrlCap = Utility.PadFrontWithString(sec.EnrlCap, 3);
                        enrlCap = (sec.IsHidden || sec.EnrlCapVer ? enrlCap : StartMark + enrlCap + EndMark);

                        // format class association component
                        string component = Utility.PadFrontWithString(sec.ClassAssnComponent, 4);
                        component = sec.IsHidden || sec.ClassAssnComponentVer ? component : StartMark + component + EndMark;

                        // format credits
                        string credits = (sec.UnitsMin.Equals(sec.UnitsMax) ? sec.UnitsMin : sec.UnitsMin + "-" + sec.UnitsMax);
                        credits = Utility.PadRightWithString(credits, 5);
                        credits = sec.IsHidden || (sec.UnitsMinVer && sec.UnitsMaxVer) ? credits : StartMark + credits + EndMark;

                        // format days of the week
                        string days = (sec.Mon.Equals("Y")) ? "M" : OneSpace;
                        days += (sec.Tues.Equals("Y")) ? "T" : OneSpace;
                        days += (sec.Wed.Equals("Y")) ? "W" : OneSpace;
                        days += (sec.Thurs.Equals("Y")) ? "U" : OneSpace;
                        days += (sec.Fri.Equals("Y")) ? "F" : OneSpace;
                        days  = (sec.IsHidden || (sec.MonVer && sec.TuesVer && sec.WedVer && sec.ThursVer && sec.FriVer &&
                                                  sec.SatVer && sec.SunVer)) ? days : StartMark + days + EndMark;

                        // format times of classes
                        string times = (sec.IsHidden || sec.MeetingTimeStartVer ? "" : StartMark) + Utility.PadFrontWithString(sec.MeetingTimeStart, 8)
                                       + (sec.IsHidden || sec.MeetingTimeStartVer ? "" : EndMark) + "-" + (sec.IsHidden || sec.MeetingTimeEndVer ? "" : StartMark)
                                       + Utility.PadFrontWithString(sec.MeetingTimeEnd, 8) + (sec.IsHidden || sec.MeetingTimeEndVer ? "" : EndMark);

                        if (times.Equals(StartMark + "12:00 AM" + EndMark + "-" + StartMark + "12:00 AM" + EndMark))
                        {
                            times = Utility.PadRightWithString(StartMark + "By Appointment" + EndMark, 17);
                        }
                        if (times.Equals("12:00 AM-12:00 AM"))
                        {
                            times = Utility.PadRightWithString("By Appointment", 17);
                        }

                        // format faculty name
                        string faculty = sec.Instructor;
                        faculty = faculty.Substring(0, faculty.Length > 17 ? 17 : faculty.Length);
                        faculty = Utility.PadRightWithString(faculty, 18);
                        faculty = (sec.IsHidden || sec.InstructorVer ? faculty : StartMark + faculty + EndMark);

                        // format building and classroom number
                        string facility = (sec.IsHidden || sec.FacilityIdVer ? "" : StartMark) + Utility.PadRightWithString(sec.FacilityId, 8)
                                          + (sec.IsHidden || sec.FacilityIdVer ? "" : EndMark);

                        string nonStd = standardMeetingStartDt.Equals(sec.MeetingStartDt) && standardMeetingEndDt.Equals(sec.MeetingEndDt) &&
                                        sec.MeetingStartDtVer && sec.MeetingEndDtVer ?
                                        "" : (sec.IsHidden || (sec.MeetingStartDtVer && sec.MeetingEndDtVer) ? "   [" : TwoSpaces + StartMark + "[")
                                        + sec.MeetingStartDt + "-" + sec.MeetingEndDt
                                        + (sec.IsHidden || (sec.MeetingStartDtVer && sec.MeetingEndDtVer) ? "]" : "]" + EndMark);

                        // print first part of line
                        printer.Write(section + Tab + enrlCap + Tab + component + Tab + credits + Tab + days + Tab + times + Tab
                                      + facility + Tab + faculty + Tab + nonStd);

                        if (sec.HasBeenDeleted)
                        {
                            printer.Write("</span>");
                        }

                        if (sec.IsHidden)
                        {
                            printer.Write("</span>");
                        }

                        // print out notes if they are there
                        if (sec.MyNotes.Trim().Any())
                        {
                            printer.WriteLine("<br><em>" + Tab + Tab + StartNote + sec.MyNotes + EndNote + "</em><br>");
                        }
                        else
                        {
                            printer.WriteLine("<br>");
                        }
                    }
                    printer.WriteLine("</body>");
                    printer.WriteLine("</html>");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            return(filename);
        }
コード例 #3
0
ファイル: Semester.cs プロジェクト: sdeloach/Scheduler
        public void VerifyAgainst(Semester KSISsemester)
        {
            // compare against KSIS data to set verification flags in each section
            this.CompareToSemester(KSISsemester);

            // create a semester sorted by instructor, the other by room
            // since semesters hold sections by reference, they "share" the sections
            Semester semesterByInstructor = this.SortByInstructor();
            Semester semesterByFacility   = this.SortByFacilityId();

            //create interval list to check overlaps
            IntervalList list = new IntervalList(gui);

            try
            {
                for (int i = 0; i < semesterByInstructor.Size(); i++)
                {
                    Section  sec      = semesterByInstructor.ElementAt(i);
                    Interval interval = new Interval(sec.Instructor, sec.CatalogNbr, sec.SectionName,
                                                     ConvertTimeToInt(sec.MeetingTimeStart), ConvertTimeToInt(sec.MeetingTimeEnd), sec.MeetingStartDt,
                                                     sec.MeetingEndDt, sec.Mon, sec.Tues, sec.Wed, sec.Thurs, sec.Fri);

                    // ignore {0,0} and (2400,2400), sections added to denote deleted sections, and hidden files
                    if (interval.Start != interval.End && !sec.HasBeenDeleted && !sec.IsHidden)
                    {
                        list.Add(interval);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            // verify instructor schedules do not overlap
            list.CheckForOverlaps();

            //create interval list to check overlaps
            list = new IntervalList(gui);

            for (int i = 0; i < semesterByFacility.Size(); i++)
            {
                // create an interval for each section in the semester
                Section  sec      = semesterByFacility.ElementAt(i);
                Interval interval = new Interval(sec.FacilityId, sec.CatalogNbr, sec.SectionName,
                                                 ConvertTimeToInt(sec.MeetingTimeStart), ConvertTimeToInt(sec.MeetingTimeEnd), sec.MeetingStartDt,
                                                 sec.MeetingEndDt, sec.Mon, sec.Tues, sec.Wed, sec.Thurs, sec.Fri);

                // ignore sections with intervals of {0,0} and (2400,2400) as well as sections that are deleted, hidden, or not assigned to a room yet
                if (interval.Start != interval.End && !sec.HasBeenDeleted && interval.Entity.Any() &&
                    !interval.Entity.StartsWith("zz") && !sec.IsHidden)
                {
                    list.Add(interval);
                }
            }

            // verify room schedules do not overlap
            list.CheckForOverlaps();

            this.Verified = true;
        }
コード例 #4
0
ファイル: Semester.cs プロジェクト: sdeloach/Scheduler
        private void CompareToSemester(Semester comparisonSemester)
        {
            if (semesterList.Count() <= 0)
            {
                gui.WriteLine("No file loaded for comparison.");
                return;
            }

            // look for sections in s but not semester
            int j = 0;

            foreach (var comparisonSection in comparisonSemester.semesterList)
            {
                bool found = false;
                foreach (var section in semesterList)
                {
                    if (section.CatalogNbr.Equals(comparisonSection.CatalogNbr) && section.SectionName.Equals(comparisonSection.SectionName))
                    {
                        found = true;
                        break;
                    }
                }

                // add section to semester to denote problem
                if (!found)
                {
                    Section sec = new Section(comparisonSection.Subject, comparisonSection.CatalogNbr,
                                              comparisonSection.ClassDescr, comparisonSection.SectionName, comparisonSection.Instructor,
                                              comparisonSection.Consent, comparisonSection.EnrlCap, comparisonSection.TopicDescr,
                                              comparisonSection.MeetingStartDt, comparisonSection.MeetingEndDt,
                                              comparisonSection.FacilityId, comparisonSection.MeetingTimeStart,
                                              comparisonSection.MeetingTimeEnd, comparisonSection.Mon, comparisonSection.Tues,
                                              comparisonSection.Wed, comparisonSection.Thurs, comparisonSection.Fri,
                                              comparisonSection.Sat, comparisonSection.Sun, comparisonSection.UnitsMin,
                                              comparisonSection.UnitsMax, comparisonSection.ClassAssnComponent, "", "");
                    semesterList.Insert(0, sec);
                    //semesterList.Add(comparisonSection);
                    sec.HasBeenDeleted = true;
                }
                j++;
            }

            // look for sections in semester but not s

            foreach (var section in semesterList)
            {
                bool found = false;
                foreach (var comparisonSection in comparisonSemester.semesterList)
                {
                    if (section.CatalogNbr.Equals(comparisonSection.CatalogNbr) && section.SectionName.Equals(comparisonSection.SectionName))
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    section.FlagChangesFromSection(new Section());
                }
            }

            // reset verification flags against the correct section
            foreach (var section in semesterList)
            {
                foreach (var comparisonSection in comparisonSemester.semesterList)
                {
                    if (section.CatalogNbr.Equals(comparisonSection.CatalogNbr) && section.SectionName.Equals(comparisonSection.SectionName))
                    {
                        if (section.FlagChangesFromSection(comparisonSection))
                        {
                            break;
                        }
                    }
                }
            }
        }
コード例 #5
0
ファイル: CalendarPrinter.cs プロジェクト: sdeloach/Scheduler
        public string Print(Semester semester, bool printAllSections, bool printAllDates)
        {
            if (semester == null)
            {
                MessageBox.Show("No semester loaded.");
            }
            else
            {
                // open file for each room in roomList array defined above
                //open file
                try
                {
                    string lastCatalogNbr = "";
                    string lastSection    = "";

                    foreach (var room in roomList)
                    {
                        string filename = Configuration.ICSDIRECTORY + semester.Name + " - " + room + ".ics";
                        using (System.IO.StreamWriter printer = new System.IO.StreamWriter(filename, false))
                        {
                            // print header
                            printer.WriteLine("BEGIN:VCALENDAR");
                            printer.WriteLine("PRODID:-//Microsoft Corporation//Outlook 16.0 MIMEDIR//EN");
                            printer.WriteLine("VERSION:2.0");
                            printer.WriteLine("METHOD:PUBLISH");
                            printer.WriteLine("X-MS-OLK-FORCEINSPECTOROPEN:TRUE");
                            printer.WriteLine("BEGIN:VTIMEZONE");
                            printer.WriteLine("TZID:Central Standard Time");
                            printer.WriteLine("BEGIN:STANDARD");
                            printer.WriteLine("DTSTART:16011104T020000"); //
                            printer.WriteLine("RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11");
                            printer.WriteLine("TZOFFSETFROM:-0500");
                            printer.WriteLine("TZOFFSETTO:-0600");
                            printer.WriteLine("END:STANDARD");
                            printer.WriteLine("BEGIN:DAYLIGHT");
                            printer.WriteLine("DTSTART:16010311T020000");
                            printer.WriteLine("RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3");
                            printer.WriteLine("TZOFFSETFROM:-0600");
                            printer.WriteLine("TZOFFSETTO:-0500");
                            printer.WriteLine("END:DAYLIGHT");
                            printer.WriteLine("END:VTIMEZONE");

                            // start processing courses as calendar events
                            for (int x = 0; x < semester.Size(); x++)
                            {
                                Section sec       = semester.ElementAt(x);
                                string  catNumber = sec.CatalogNbr;

                                // don't add event for second/third instructors of same section
                                if (catNumber.Equals(lastCatalogNbr) && sec.SectionName.Equals(lastSection))
                                {
                                    continue;
                                }
                                else
                                {
                                    lastCatalogNbr = catNumber;
                                    lastSection    = sec.SectionName;
                                }

                                // combine courses with co-taught numbers into a single event, but only create event for lowest catalog number
                                CoTaughtCourses cotaught = new CoTaughtCourses(gui);
                                string          ctc      = cotaught.CoTaughtCourseOf(catNumber);
                                if (ctc.Any())
                                {
                                    int cNum   = int.Parse(catNumber);
                                    int ctcNum = int.Parse(ctc);
                                    if ((!room.Equals("graduate") && !room.Equals("undergraduate")) ||
                                        (room.Equals("graduate") && IsGraduateCourse(cNum) && IsGraduateCourse(ctcNum)) ||
                                        (room.Equals("undergraduate") && IsUnderGraduateCourse(cNum) && IsUnderGraduateCourse(ctcNum)))
                                    {
                                        if (cNum > ctcNum)
                                        {
                                            continue; // skip courses whose number is greater than their cotaught course
                                        }
                                        else
                                        {
                                            catNumber += "/" + ctc;
                                        }
                                    }
                                }

                                // skip sections we are not interested in scheduling
                                if (NonPrintedSection(sec, room))
                                {
                                    continue; // do not print these sections
                                }
                                else
                                {
                                    // format values for event

                                    string today = ICSToday();

                                    string startDate = ICSDate(sec.MeetingStartDt);
                                    string endDate   = ICSDate(AddDaysToDate(sec.MeetingEndDt, 1)); // add 1 day to last class date
                                    string startTime = ICSTime(sec.MeetingTimeStart);
                                    string endTime   = ICSTime(sec.MeetingTimeEnd);

                                    string daysOfWeek = ICSDaysOfWeek(sec);

                                    startDate = ICSDate(CalculateActualStartDate(sec.MeetingStartDt, daysOfWeek));

                                    // print out lines for sections of interest
                                    printer.WriteLine("BEGIN:VEVENT");
                                    printer.WriteLine("CATEGORIES:Student/Teaching");
                                    printer.WriteLine("CLASS:PUBLIC");
                                    printer.WriteLine("CREATED:" + today);
                                    printer.WriteLine("DESCRIPTION:" + sec.Subject + " " + catNumber + "  " + sec.ClassDescr
                                                      + (!sec.TopicDescr.Equals(" ") ? " - " + sec.TopicDescr : ""));
                                    printer.WriteLine("DTEND;TZID=\"Central Standard Time\":" + startDate + endTime + "00");
                                    printer.WriteLine("DTSTAMP:" + today);
                                    printer.WriteLine("DTSTART;TZID=\"Central Standard Time\":" + startDate + startTime + "00");
                                    printer.WriteLine("LAST-MODIFIED:" + today);
                                    printer.WriteLine("LOCATION:" + sec.FacilityId);
                                    printer.WriteLine("PRIORITY:5");
                                    printer.WriteLine("RRULE:FREQ=WEEKLY;UNTIL=" + endDate + "000000" + ";" + daysOfWeek);
                                    printer.WriteLine("SEQUENCE:0");
                                    printer.WriteLine("SUMMARY;LANGUAGE=en-us:" + sec.Subject + " " + catNumber + " - "
                                                      + sec.SectionName + " (" + sec.Instructor + ")");
                                    printer.WriteLine("TRANSP:OPAQUE");
                                    printer.WriteLine("UID:" + Guid.NewGuid());
                                    printer.WriteLine("X-ALT-DESC;");
                                    printer.WriteLine("X-MICROSOFT-CDO-BUSYSTATUS:BUSY");
                                    printer.WriteLine("X-MICROSOFT-CDO-IMPORTANCE:1");
                                    printer.WriteLine("X-MICROSOFT-DISALLOW-COUNTER:FALSE");
                                    printer.WriteLine("X-MS-OLK-AUTOFILLLOCATION:FALSE");
                                    printer.WriteLine("X-MS-OLK-AUTOSTARTCHECK:FALSE");
                                    printer.WriteLine("X-MS-OLK-CONFTYPE:0");
                                    printer.WriteLine("END:VEVENT");
                                }
                            }
                            printer.WriteLine("END:VCALENDAR");
                        }
                    }
                }
                catch (Exception e)
                {
                    gui.WriteLine(e.Message);
                }

                gui.WriteLine("Calendar events generated.");
            }
            return("");
        }