コード例 #1
0
        public Semester Read(string filename)
        {
            Semester semester = new Semester(gui);
            Section  section;

            if (!filename.ToLower().EndsWith(".csv"))
            {
                gui.WriteLine("Filename " + filename + " is not a valid .csv file.");
                return(semester);
            }

            StreamReader readFile;

            try
            {
                readFile = new StreamReader(filename);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Console.WriteLine(e.StackTrace);
                return(semester);
            }

            string line = readFile.ReadLine(); // skip first line

            while ((line = readFile.ReadLine()) != null)
            {
                List <string> data = Utility.ParseLine(line);

                // skip lines with blanck Monday Y/N schedule settings
                if (data.ElementAt(44).Equals(" ") || !data.ElementAt(44).Any())
                {
                    continue;
                }

                // Create a new section with current line
                section = new Section(data.ElementAt(00), data.ElementAt(01), data.ElementAt(02), data.ElementAt(03), data.ElementAt(04), data.ElementAt(05), data.ElementAt(06),
                                      data.ElementAt(07), data.ElementAt(8), data.ElementAt(9), data.ElementAt(10), data.ElementAt(11), data.ElementAt(12), data.ElementAt(13), data.ElementAt(14),
                                      data.ElementAt(15), data.ElementAt(16), data.ElementAt(17), data.ElementAt(18), data.ElementAt(19), data.ElementAt(20), data.ElementAt(21), data.ElementAt(22),
                                      data.ElementAt(23), data.ElementAt(24), data.ElementAt(25), data.ElementAt(26), data.ElementAt(27), data.ElementAt(28), data.ElementAt(29), data.ElementAt(30),
                                      data.ElementAt(31), data.ElementAt(32), data.ElementAt(33), data.ElementAt(34), data.ElementAt(35), data.ElementAt(36), data.ElementAt(37), data.ElementAt(38),
                                      data.ElementAt(39), data.ElementAt(40), data.ElementAt(41), data.ElementAt(42), data.ElementAt(43), data.ElementAt(44), data.ElementAt(45), data.ElementAt(46),
                                      data.ElementAt(47), data.ElementAt(48), data.ElementAt(49), data.ElementAt(50), data.ElementAt(51), data.ElementAt(52), data.ElementAt(53), data.ElementAt(54),
                                      data.ElementAt(55), data.ElementAt(56), data.ElementAt(57), data.ElementAt(58), data.ElementAt(59), data.ElementAt(60), data.ElementAt(61), data.ElementAt(62),
                                      data.ElementAt(63), data.ElementAt(64), data.ElementAt(65), data.ElementAt(66), data.ElementAt(67), data.ElementAt(68), data.ElementAt(69), data.ElementAt(70),
                                      data.ElementAt(71), data.ElementAt(72), data.ElementAt(73), data.ElementAt(74), data.ElementAt(75), data.ElementAt(76), data.ElementAt(77), data.ElementAt(78),
                                      data.ElementAt(79), data.ElementAt(80), data.ElementAt(81), data.ElementAt(82), data.ElementAt(83), data.ElementAt(84), data.ElementAt(85), data.ElementAt(86),
                                      data.ElementAt(87), data.ElementAt(88), data.ElementAt(89), data.ElementAt(90), data.ElementAt(91));

                // add section to semester
                semester.Add(section);
            }
            readFile.Close();

            // return semester sorted by CatalogNbr
            return(semester.SortByCatalogNbr());
        }
コード例 #2
0
ファイル: LocalCSVReader.cs プロジェクト: sdeloach/Scheduler
        public Semester Read(string filename)
        {
            Semester semester = new Semester(gui);
            Section  section;

            if (!filename.ToLower().EndsWith(".csv"))
            {
                MessageBox.Show("Filename " + filename + " is not a valid .csv file.");
                return(semester);
            }

            StreamReader readFile;

            try
            {
                readFile = new StreamReader(filename);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(semester);
            }

            List <string> data = Utility.ParseLine(readFile.ReadLine()); //get first line with semester name

            semester.Name = data.ElementAt(0);                           // save name of semester

            readFile.ReadLine();                                         // skip the next line - data headers

            string line;

            while ((line = readFile.ReadLine()) != null)
            {
                data = Utility.ParseLine(line);

                // create a new section with current line
                section = new Section(data.ElementAt(00), data.ElementAt(01), data.ElementAt(02), data.ElementAt(03), data.ElementAt(04),
                                      data.ElementAt(05), data.ElementAt(06), data.ElementAt(07), data.ElementAt(8), data.ElementAt(9), data.ElementAt(10),
                                      data.ElementAt(11), data.ElementAt(12), data.ElementAt(13), data.ElementAt(14), data.ElementAt(15), data.ElementAt(16),
                                      data.ElementAt(17), data.ElementAt(18), data.ElementAt(19), data.ElementAt(20), data.ElementAt(21), data.ElementAt(22),
                                      data.ElementAt(23), data.ElementAt(24));

                // add section to semester
                semester.Add(section);
            }
            readFile.Close();

            // return the semester sorted by catalog number

            semester.SortByCatalogNbr();
            return(semester);
        }
コード例 #3
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);
        }