Пример #1
0
 public DialogResult ShowDialog(Timetable timetable, Unavailability unavail, int earliest, int latest)
 {
     Timetable_ = timetable;
     Unavail_ = unavail;
     Earliest_ = earliest;
     Latest_ = latest;
     return base.ShowDialog();
 }
Пример #2
0
        public Solver(Timetable timetable)
        {
            Timetable_ = timetable;

            Comparer_ = new Solver.SolutionComparer();
            Filters_ = new List<Solver.Filter>();
            Default();
        }
Пример #3
0
 public static Timetable From(Stream stream)
 {
     Timetable t = new Timetable();
     t.SubjectList.Add(stream.Type.Subject);
     t.TypeList.Add(stream.Type);
     t.StreamList.Add(stream);
     t.ClassList.AddRange(stream.Classes);
     return t;
 }
Пример #4
0
 public static Timetable From(Type type)
 {
     Timetable t = new Timetable();
     t.SubjectList.Add(type.Subject);
     t.TypeList.Add(type);
     t.StreamList.AddRange(type.Streams);
     foreach (Stream stream in type.Streams)
     {
         t.ClassList.AddRange(stream.Classes);
     }
     return t;
 }
Пример #5
0
        public Solver(Timetable timetable, Solver other)
        {
            Timetable_ = timetable;

            this.Comparer_ = other.Comparer_.Clone();
            this.Filters_ = new List<Solver.Filter>(other.Filters_);

            this.Solutions_ = new List<Solution>(Solutions_);
            this.MaxResults_ = other.MaxResults_;

            // other variables are initiated during solving
        }
Пример #6
0
        private void Open()
        {
            if (!AreYouSure("Open Timetable"))
                return;

            if (OpenDialogXML_.ShowDialog() != DialogResult.OK)
                return;

            XmlSerializer s = new XmlSerializer(typeof(Timetable));
            TextReader r;
            try
            {
                r = new StreamReader(OpenDialogXML_.FileName);
            }
            catch
            {
                MessageBox.Show("Could not open specified file!", "Open Timetable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Timetable t;
            try
            {
                t = (Timetable)s.Deserialize(r);
            }
            catch
            {
                MessageBox.Show("Failed to load saved data!", "Open Timetable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                r.Close();
                return;
            }
            r.Close();
            SaveDialogXML_.FileName = OpenDialogXML_.FileName;

            // build relationships and translate tree to lists
            foreach (Subject subject in t.SubjectList)
            {
                t.TypeList.AddRange(subject.Types);
                foreach (Type type in subject.Types)
                {
                    t.StreamList.AddRange(type.Streams);
                    type.Subject = subject;
                    foreach (Stream stream in type.Streams)
                    {
                        t.ClassList.AddRange(stream.Classes);
                        stream.Type = type;
                        foreach (Session session in stream.Classes)
                        {
                            session.Stream = stream;
                        }
                    }
                }
            }

            t.BuildEquivalency();
            t.BuildCompatibility();

            Timetable_ = t;
            timetableControl1.Timetable = Timetable_;
            timetableControl1.MatchBounds();
            ClearHistory();
            EnableButtons(true);
        }
Пример #7
0
 private void New()
 {
     if (!AreYouSure("Clear Timetable"))
         return;
     Timetable_ = null;
     timetableControl1.Timetable = Timetable_;
     SaveDialogXML_.FileName = null;
     EnableButtons(false);
     ClearHistory();
 }
Пример #8
0
        private void Next()
        {
            if (CurrentPage_ == 1)
            {
                // if there's no selected format, skip
                if (listBoxFormats.SelectedItem == null)
                    return;

                // load selected importer
                Importer_ = (Importer)listBoxFormats.SelectedItem;
                // clear importer files
                Importer_.File1Dialog.FileName = "";
                Importer_.File2Dialog.FileName = "";
                Importer_.File3Dialog.FileName = "";

                // bring up panel 2 (file import) information
                // file 1
                if (Importer_.File1Description != null)
                {
                    lblFile1.Text = Importer_.File1Description;
                    lblFile1.Visible = true;
                    btnBrowse1.Visible = true;
                    txtFile1.Visible = true;
                }
                else
                {
                    lblFile1.Visible = false;
                    btnBrowse1.Visible = false;
                    txtFile1.Visible = false;
                }
                // file 2
                if (Importer_.File2Description != null)
                {
                    lblFile2.Text = Importer_.File2Description;
                    lblFile2.Visible = true;
                    btnBrowse2.Visible = true;
                    txtFile2.Visible = true;
                }
                else
                {
                    lblFile2.Visible = false;
                    btnBrowse2.Visible = false;
                    txtFile2.Visible = false;
                }
                // file 3
                if (Importer_.File3Description != null)
                {
                    lblFile3.Text = Importer_.File3Description;
                    lblFile3.Visible = true;
                    btnBrowse3.Visible = true;
                    txtFile3.Visible = true;
                }
                else
                {
                    lblFile3.Visible = false;
                    btnBrowse3.Visible = false;
                    txtFile3.Visible = false;
                }
                // file instructions
                if (Importer_.FileInstructions != null)
                {
                    txtFileInstructions.Text = Importer_.FileInstructions;
                }
                else
                {
                    txtFileInstructions.Text = "No instructions provided for " + Importer_.FormatName + ".";
                }

                // bring up panel 2
                panel1.Visible = false;
                panel2.Visible = true;
                // enable back button
                btnBack.Enabled = true;
            }
            else if (CurrentPage_ == 2)
            {
                // try and parse files
                Timetable_ = Importer_.Import();

                // if it failed, alert the user and stay on the current page
                if (Timetable_ == null)
                {
                    MessageBox.Show("Failed to import timetable data.", "Import", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // build relational data
                Timetable_.BuildEquivalency();
                Timetable_.BuildCompatibility();
                //Timetable_.UpdateStates();

                // build tree
                Timetable_.BuildTreeView(treePreview);
                // and scroll back to the top
                treePreview.Nodes[0].EnsureVisible();
                // clear details box
                txtTreeDetails.Text = "";
                timetableControl1.Clear();

                // bring up panel 3
                panel2.Visible = false;
                panel3.Visible = true;
            }
            else if (CurrentPage_ == 3)
            {
                // clear ignored/required lists
                listViewIgnored.Items.Clear();
                listViewIgnored.Groups.Clear();
                listViewRequired.Items.Clear();
                listViewRequired.Groups.Clear();

                // populate ignored/required lists
                foreach (Subject subject in Timetable_.SubjectList)
                {
                    // create and add groups for the subjects
                    ListViewGroup ignoredSubjectGroup = new ListViewGroup(subject.Name);
                    ignoredSubjectGroup.Tag = subject;
                    listViewIgnored.Groups.Add(ignoredSubjectGroup);

                    ListViewGroup requiredSubjectGroup = new ListViewGroup(subject.Name);
                    requiredSubjectGroup.Tag = subject;
                    listViewRequired.Groups.Add(requiredSubjectGroup);

                    // add stream types to subject groups
                    foreach (Type type in subject.Types)
                    {
                        // create ListViewItem without group
                        ListViewItem item = new ListViewItem(new string[] { type.Code.ToString(), type.Name });
                        item.Tag = type;

                        // add it to the current group in the correct box
                        if (type.Required)
                        {
                            // set group and add to list
                            item.Group = requiredSubjectGroup;
                            listViewRequired.Items.Add(item);
                        }
                        else
                        {
                            // set group and add to list
                            item.Group = ignoredSubjectGroup;
                            listViewIgnored.Items.Add(item);
                        }
                    }
                }

                UpdateClashHighlight();

                btnRequire.Enabled = false;
                btnIgnore.Enabled = false;

                // bring up panel 4
                panel3.Visible = false;
                panel4.Visible = true;
                // swap next button for finish
                btnNext.Visible = false;
                btnFinish.Visible = true;

                // need to refresh to get red highlighter
                listViewIgnored.Refresh();
                listViewRequired.Refresh();
            }
            CurrentPage_++;
        }
Пример #9
0
 public DialogResult ShowDialog(Timetable timetable, Timeslot timeslot, int earliest, int latest)
 {
     return ShowDialog(timetable, new Unavailability("", timeslot), earliest, latest);
 }
Пример #10
0
 public Solver Clone(Timetable timetable)
 {
     return new Solver(timetable, this);
 }
Пример #11
0
        protected override Timetable Parse()
        {
            Timetable timetable = new Timetable();

            // get file name
            string fileName = File1Dialog_.FileName;
            // if it doesn't end with .xls
            string fileNameLower = fileName.ToLower();
            if (!(fileNameLower.EndsWith(".htm") || fileNameLower.EndsWith(".html")))
            {
                // pop up an error
                MessageBox.Show("Please select a HTML file.", "Import", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                // and return null - failed
                return null;
            }

            ParseOptional(timetable, fileName);

            return timetable;
        }
Пример #12
0
        private void Redo()
        {
            Timetable t = History_.Forward();
            if (t == null)
            {
                System.Media.SystemSounds.Beep.Play();
                return;
            }

            Changes_++;
            Timetable_ = t.DeepCopy();
            timetableControl1.Timetable = Timetable_;
            UpdateRemaining();
        }
Пример #13
0
        public void MergeWith(Timetable t)
        {
            SubjectList.AddRange(t.SubjectList);
            TypeList.AddRange(t.TypeList);
            StreamList.AddRange(t.StreamList);
            ClassList.AddRange(t.ClassList);
            UnavailableList.AddRange(t.UnavailableList);

            BuildEquivalency();
            BuildCompatibility();
            Update();
        }
Пример #14
0
 public void Clear()
 {
     Timetable = null;
 }
Пример #15
0
        public Timetable(Timetable other)
        {
            #region Clone subject/type/stream/class data

            // copy across all the subject data
            this.SubjectList = new List<Subject>();
            foreach (Subject subject in other.SubjectList)
                this.SubjectList.Add(subject.Clone());
            // copy all the type data
            this.TypeList = new List<Type>();
            foreach (Type type in other.TypeList)
                this.TypeList.Add(type.Clone());
            // copy all the stream data
            this.StreamList = new List<Stream>();
            foreach (Stream stream in other.StreamList)
                this.StreamList.Add(stream.Clone());
            // copy all the session data
            this.ClassList = new List<Session>();
            foreach (Session session in other.ClassList)
                this.ClassList.Add(session.Clone());

            // update reference to subjects
            for (int i = 0; i < this.SubjectList.Count; i++)
            {
                foreach (Type type in this.TypeList)
                {
                    if (type.Subject == other.SubjectList[i])
                        type.Subject = this.SubjectList[i];
                }
            }
            // update references to types
            for (int i = 0; i < this.TypeList.Count; i++)
            {
                // parent references
                foreach (Stream stream in this.StreamList)
                {
                    if (stream.Type == other.TypeList[i])
                        stream.Type = this.TypeList[i];
                }
                // child references
                for (int j = 0; j < this.TypeList[i].Subject.Types.Count; j++)
                {
                    if (this.TypeList[i].Subject.Types[j] == other.TypeList[i])
                    {
                        this.TypeList[i].Subject.Types[j] = this.TypeList[i];
                        break;
                    }
                }
                // unique streams
                for (int j = 0; j < this.TypeList[i].UniqueStreams.Count; j++)
                {
                    if (this.StreamList[i].Type.Streams[j] == other.StreamList[i])
                    {
                        this.StreamList[i].Type.Streams[j] = this.StreamList[i];
                        break;
                    }
                }
            }
            // update references to streams
            for (int i = 0; i < this.StreamList.Count; i++)
            {
                // parent references
                foreach (Session session in this.ClassList)
                {
                    if (session.Stream == other.StreamList[i])
                        session.Stream = this.StreamList[i];
                }
                // child references
                for (int j = 0; j < this.StreamList[i].Type.Streams.Count; j++)
                {
                    if (this.StreamList[i].Type.Streams[j] == other.StreamList[i])
                    {
                        this.StreamList[i].Type.Streams[j] = this.StreamList[i];
                        break;
                    }
                }
                // find all equivalent streams set to other.StreamList[i]
                for (int j = 0; j < this.StreamList.Count; j++)
                {
                    for (int k = 0; k < this.StreamList[j].Equivalent.Count; k++)
                    {
                        if (this.StreamList[j].Equivalent[k] == other.StreamList[i])
                        {
                            this.StreamList[j].Equivalent[k] = this.StreamList[i];
                            break;
                        }
                    }
                }
                // find all incompatible streams set to other.StreamList[i]
                for (int j = 0; j < this.StreamList.Count; j++)
                {
                    for (int k = 0; k < this.StreamList[j].Incompatible.Count; k++)
                    {
                        if (this.StreamList[j].Incompatible[k] == other.StreamList[i])
                        {
                            this.StreamList[j].Incompatible[k] = this.StreamList[i];
                            break;
                        }
                    }
                }
                // find all unique streams set to other.StreamList[i]
                foreach (Type type in this.TypeList)
                {
                    for (int j = 0; j < type.UniqueStreams.Count; j++)
                    {
                        if (type.UniqueStreams[j] == other.StreamList[i])
                        {
                            type.UniqueStreams[j] = this.StreamList[i];
                            break;
                        }
                    }
                }
            }
            // update references to the sessions
            for (int i = 0; i < this.ClassList.Count; i++)
            {
                // child references
                for (int j = 0; j < this.ClassList[i].Stream.Classes.Count; j++)
                {
                    if (this.ClassList[i].Stream.Classes[j] == other.ClassList[i])
                    {
                        this.ClassList[i].Stream.Classes[j] = this.ClassList[i];
                        break;
                    }
                }
            }

            #endregion

            // a shallow copy will do for boolean (value type)
            // TODO: copies both levels or just first level?
            this.StreamClashTable_ = (bool[][])other.StreamClashTable_.Clone();

            // clone unavailable data
            this.UnavailableList = new List<Unavailability>();
            foreach (Unavailability unavail in other.UnavailableList)
            {
                this.UnavailableList.Add(unavail.Clone());
            }

            // copy status of solution recomputation required
            this.RecomputeSolutions = other.RecomputeSolutions;
        }
Пример #16
0
 public DialogResult ShowDialog(Timetable timetable)
 {
     Timetable_ = timetable;
     return base.ShowDialog();
 }
Пример #17
0
        protected override Timetable Parse()
        {
            Timetable timetable = new Timetable();

            // Get file name.
            string fileName = File1Dialog_.FileName;
            if (!fileName.ToLower().EndsWith(".xls"))
            {
                // File doesn't end with .xls!
                MessageBox.Show("Please select a file with extension .xls.",
                                "File Type",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return null;
            }
            // Dump the input file into a string.
            StreamReader streamReader = new StreamReader(fileName);
            string timetable_html = streamReader.ReadToEnd();
            streamReader.Close();

            // Remove useless information.
            // Anything in the following list of regexes will be removed.
            string[] replacements = {
                @"\n",                      // we get rid of newlines so we don't have to bother with multiline regex
                @"<html.*?>",               // opening html
                @"<!--.*?-->",              // html comments
                @"=&quot;", @"&quot;",      // html-escaped quotes
                @"&nbsp;",                  // html-escaped spaces (these are useless anyway as the file contains normal spaces where needed)
                @"<meta.*?>",               // meta tags
                @"<tr><th>.*?</th></tr>",   // table headers
                @"</tr>",                   // remove close row tags (this will make sense for the cleanups)
                @"<table.*?>",              // table opening tag
                @"<body.*?>",               // body open tag
                @"</body></html>"           // end page tags
            };
            // Run the replacements.
            foreach (string replace_regex in replacements)
            {
                timetable_html = Regex.Replace(timetable_html, replace_regex, "");
            }

            // Build a dictionary of regex cleanups.
            // Probably should use a pair, but this requires less code and is probably more efficient
            Dictionary<string, string> cleanups = new Dictionary<string,string>();
            // Put the ampersands back in.
            cleanups.Add(@"&amp;", "&");
            // Assume that each <tr> actually means </tr><tr> in valid html.
            // Unfortunately this results in a </tr> at the start of the file.
            cleanups.Add(@"<tr>", "</tr><tr>");
            // Assume that the </table> tag actually represents a </tr>.
            cleanups.Add(@"</table>", "</tr>");
            // Run the cleanups
            foreach (string cleanup_regex in cleanups.Keys)
            {
                timetable_html = Regex.Replace(timetable_html,
                                               cleanup_regex,
                                               cleanups[cleanup_regex]);
            }
            // Get rid of the extra </tr> at the start of the file.
            Regex pattern = new Regex(@"</tr>");
            timetable_html = pattern.Replace(timetable_html, "", 1);

            // Build the regex to parse the file.
            Regex timetable_parser = new Regex(
                @"<tr>" +                                   // start row
                @"<td>(?<subject_code>.*?)</td>" +          // subject code (eg "BIOM2012")
                @"<td>(?<subject_desc>.*?)</td>" +          // subject description (eg "Machine Learning")
                @"<td>(?<session_type_name>.*?)</td>" +     // session time in long form (eg "Tutorial", "Lecture")
                @"<td>(?<stream_code>.*?)</td>" +           // stream (eg "T7", "L2", "P")
                @"<td>(?<start_time>.*?)</td>" +            // session start time (eg "11:00 AM")
                @"<td>(?<stop_time>.*?)</td>" +             // session stop time (eg "11:50 AM")
                @"<td>(?<clash>.*?)</td>" +                 // has a clash occured (pretty useless for our purposes)
                @"<td>(?<building_name>.*?)</td>" +         // full building name (eg "Forgan Smith Building")
                @"<td>(?<building_number>.*?)</td>" +       // building number (eg "01")
                @"<td>(?<room>.*?)</td>" +                  // room code (eg "205", "E105"
                @"<td>(?<running_dates>.*?)</td>" +         // time period over which the stream runs
                @"<td>(?<not_taught_on>.*?)</td>" +         // date the stream is not taught on
                @"<td>.*?</td>" +                           // unknown
                @"<td>.*?</td>" +                           // unknown
                @"<td>(?<session_type_name2>.*?)</td>" +    // not sure why this is here ?
                @"</tr>"                                    // close row
            );

            // Which day are the current sessions on?
            int current_day = -1;

            foreach (Match match in timetable_parser.Matches(timetable_html))
            {
                GroupCollection session_info = match.Groups;
                string subject_code = session_info["subject_code"].Value;
                if (subject_code.Contains("day"))
                {
                    // If we are talking about a day here.
                    switch (subject_code.Substring(0, 2))
                    {
                        case "Su":
                            current_day = 0;
                            break;
                        case "Mo":
                            current_day = 1;
                            break;
                        case "Tu":
                            current_day = 2;
                            break;
                        case "We":
                            current_day = 3;
                            break;
                        case "Th":
                            current_day = 4;
                            break;
                        case "Fr":
                            current_day = 5;
                            break;
                        case "Sa":
                            current_day = 6;
                            break;
                        default:
                            current_day = -1;
                            break;
                    }
                    continue;
                }

                // If we have a day selected already.
                if (current_day != -1)
                {
                    // Build a session object.
                    Session session = new Session();
                    session.Day = current_day;
                    // Do a sequential search for the subject.
                    Subject subject = null;
                    for (int i = 0; i < timetable.SubjectList.Count; i++)
                    {
                        if (timetable.SubjectList[i].Name == subject_code)
                        {
                            subject = timetable.SubjectList[i];
                            break;
                        }
                    }
                    // If it doesn't exist, create it.
                    if (subject == null)
                    {
                        subject = new Subject(subject_code);
                        timetable.SubjectList.Add(subject);
                    }

                    string session_code = session_info["stream_code"].Value;

                    // Build the regex to parse the session code.
                    Regex session_parser = new Regex(@"^(?<type>[a-zA-Z]+)(?<number>[0-9]*)\b");
                    Match session_match = session_parser.Match(session_code);

                    string type_code = session_match.Groups["type"].Value;
                    string stream_number_text = session_match.Groups["number"].Value;
                    // Convert the stream number (if any) to an integer.
                    int stream_number = 0;
                    if (stream_number_text.Length > 0)
                    {
                        stream_number = Convert.ToInt32(stream_number_text);
                    }

                    // Check if the session type exists.
                    Type type = null;
                    foreach (Type x in subject.Types)
                    {
                        if (x.Code == type_code)
                        {
                            // Matched on the first letter.
                            type = x;
                            break;
                        }
                    }
                    if (type == null)
                    {
                        // The session type doesn't exist, create it.
                        type = new Type(session_info["session_type_name"].Value,
                                        type_code,
                                        subject);
                        // Check if this session requires attendance.
                        type.Required = (type_code != "W" &&
                            type_code != "S" &&
                            type_code != "C");
                        timetable.TypeList.Add(type);
                    }

                    // Get a stream object.
                    // Grab the stream number.

                    // Search to see if the stream exists.
                    Stream stream = null;
                    foreach (Stream x in type.Streams)
                    {
                        if (x.Number == stream_number)
                        {
                            stream = x;
                            break;
                        }
                    }
                    // Otherwise build a new one.
                    if (stream == null)
                    {
                        stream = new Stream(stream_number);
                        // Tack it on to the stream list.
                        timetable.StreamList.Add(stream);
                    }

                    // Link the subject and type.
                    if (!subject.Types.Contains(type))
                    {
                        subject.Types.Add(type);
                        type.Subject = subject;
                    }
                    // Link the stream and type.
                    if (!type.Streams.Contains(stream))
                    {
                        type.Streams.Add(stream);
                        stream.Type = type;
                    }
                    // Link the stream and class together.
                    // Add it to our list of classes.
                    timetable.ClassList.Add(session);
                    stream.Classes.Add(session);
                    session.Stream = stream;

                    /****************************************************************************
                     * Calculate session start and stop times
                     ****************************************************************************/

                    string start_time = session_info["start_time"].Value;
                    int colon_index = start_time.IndexOf(":");

                    session.StartHour = Convert.ToInt32(start_time.Substring(0, colon_index)); // grab everything before the colon
                    session.StartMinute = Convert.ToInt32(start_time.Substring(colon_index + 1, 2)); // grab two characters after the colon
                    if (start_time.ToLower().Contains("p") && session.StartHour != 12) // if there is a PM in the time
                    {
                        session.StartHour += 12; // correct for it
                    }

                    string stop_time = session_info["stop_time"].Value;
                    colon_index = stop_time.IndexOf(":");
                    session.EndHour = Convert.ToInt32(stop_time.Substring(0, colon_index)); // grab everything before the colon
                    session.EndMinute = Convert.ToInt32(stop_time.Substring(colon_index + 1, 2)); // grab two characters after the colon
                    if (stop_time.ToLower().Contains("p") && session.EndHour != 12) // if there is a PM in the time
                    {
                        session.EndHour += 12; // correct for it
                    }
                    if (session.EndMinute >= 50)
                    {
                        session.EndHour++;
                        session.EndMinute = 0;
                    }

                    // Insert building location
                    if (session_info["building_number"].Value.Trim() == "")
                    {
                        session.Location = "";
                    }
                    else
                    {
                        session.Location = session_info["building_number"].Value;
                    }
                    if (session_info["room"].Value.Trim() != "")
                    {
                        session.Location += " - " + session_info["room"];
                    }
                }
            }

            return timetable;
        }
Пример #18
0
        private void ParseOptional(Timetable timetable, string fileName)
        {
            StreamReader inputStream = new StreamReader(fileName);
            string line, data;
            int pos, len;
            int rowLine = 0;

            Subject subject = null;
            Type type = null;
            Stream stream = null;
            List<Session> sessions = new List<Session>();

            bool newStream = true;
            int streamNumber = 0;

            // skip the rubbish
            while ((line = inputStream.ReadLine()) != null && !line.Contains("<form")) ;

            while ((line = inputStream.ReadLine()) != null && !line.Contains("</form"))
            {
                if (line.Contains("sectionSubHeading"))
                {
                    // extract the subject name
                    pos = line.IndexOf(">") + 1;
                    len = line.IndexOf("&nbsp;", pos) - pos;
                    data = line.Substring(pos, len);
                    // create subject and add to list
                    subject = new Subject(data);
                    timetable.SubjectList.Add(subject);
                }
                else if (line.Contains("paragraphHeading"))
                {
                    // extract the stream type
                    pos = line.IndexOf(">") + 1;
                    len = line.IndexOf("<", pos) - pos;
                    data = line.Substring(pos, len);
                    string dataUpper = data.ToUpper();
                    char typeCode = '?';
                    // search through all other types in the current subject to see
                    // if the stream type letter is already in use
                    bool foundUnique = false;
                    for (int i = 0; i < data.Length && !foundUnique; i++)
                    {
                        foundUnique = true;
                        for (int j = 0; j < subject.Types.Count && foundUnique; j++)
                        {
                            if (subject.Types[j].Code[0] == dataUpper[i])
                            {
                                foundUnique = false;
                            }
                        }
                        if (foundUnique)
                            typeCode = dataUpper[i];
                    }
                    // add new type
                    type = new Type(typeCode.ToString(), data, subject);
                    type.Required = true;
                    timetable.TypeList.Add(type);
                    // update parent subject
                    subject.Types.Add(type);
                    // reset stream number counter
                    streamNumber = 0;
                }
                else if (line.Contains("<tr"))
                {
                    rowLine = 0;
                }
                else if (line.Contains("</table>"))
                {
                    newStream = true;
                }
                else if (line.Contains("bsktData"))
                {
                    if (rowLine == 0)
                    {
                        // get the days
                        sessions.Clear();
                        len = 2;
                        for (pos = line.IndexOf(">") + 1; line[pos] != '<'; pos += 5)
                        {
                            int day;
                            data = line.Substring(pos, len);
                            switch (data)
                            {
                                case "Su":
                                    day = 0;
                                    break;
                                case "Mo":
                                    day = 1;
                                    break;
                                case "Tu":
                                    day = 2;
                                    break;
                                case "We":
                                    day = 3;
                                    break;
                                case "Th":
                                    day = 4;
                                    break;
                                case "Fr":
                                    day = 5;
                                    break;
                                case "Sa":
                                    day = 6;
                                    break;
                                default:
                                    day = -1;
                                    break;
                            }
                            // add new class
                            Session session = new Session();
                            session.Day = day;
                            timetable.ClassList.Add(session);
                            sessions.Add(session);
                        }

                        // create a new stream if necessary
                        if (newStream)
                        {
                            newStream = false;
                            // create the stream
                            stream = new Stream(++streamNumber, type);
                            timetable.StreamList.Add(stream);
                            // update the parent type
                            type.Streams.Add(stream);
                        }

                        foreach (Session session in sessions)
                        {
                            // set parent stream
                            session.Stream = stream;
                            // update the parent stream
                            stream.Classes.Add(session);
                        }
                    }

                    else if (rowLine == 1)
                    {
                        // get the start time
                        pos = line.IndexOf(">") + 1;
                        len = line.IndexOf(":", pos) - pos;
                        data = line.Substring(pos, len);
                        foreach (Session session in sessions)
                            session.StartHour = Convert.ToInt32(data);
                        // now get the minutes
                        pos += len + 1;
                        len = 2;
                        data = line.Substring(pos, len);
                        foreach (Session session in sessions)
                            session.StartMinute = Convert.ToInt32(data);
                        // now check am/pm
                        pos += 6 + 2;
                        len = 1;
                        data = line.Substring(pos, len);
                        if (data.ToLower() == "p" && sessions[0].StartHour != 12)
                        {
                            foreach (Session session in sessions)
                                session.StartHour += 12;
                        }
                    }

                    else if (rowLine == 2)
                    {
                        // get the end time
                        pos = line.IndexOf(">") + 1;
                        len = line.IndexOf(":", pos) - pos;
                        data = line.Substring(pos, len);
                        foreach (Session session in sessions)
                            session.EndHour = Convert.ToInt32(data);
                        // now get the minutes
                        pos += len + 1;
                        len = 2;
                        data = line.Substring(pos, len);
                        foreach (Session session in sessions)
                            session.EndMinute = Convert.ToInt32(data);
                        // now check am/pm
                        pos += 6 + 2;
                        len = 1;
                        data = line.Substring(pos, len);
                        if (data.ToLower() == "p" && sessions[0].EndHour != 12)
                        {
                            foreach (Session session in sessions)
                                session.EndHour += 12;
                        }
                    }
                    rowLine++;
                }
            }
            inputStream.Close();
        }
Пример #19
0
        private void Import()
        {
            if (!AreYouSure("Import Timetable"))
                return;

            // run the import wizard
            Timetable t = FormImport_.ShowDialog();
            if (t == null)
                return;

            Timetable_ = t;
            timetableControl1.Timetable = Timetable_;
            timetableControl1.MatchBounds();
            SaveDialogXML_.FileName = null;
            EnableButtons(true);
            ClearHistory();
        }
Пример #20
0
        private void Next()
        {
            if (CurrentPage_ == 1)
            {
                // if there's no selected format, skip
                if (listBoxFormats.SelectedItem == null)
                {
                    return;
                }

                // load selected importer
                Importer_ = (Importer)listBoxFormats.SelectedItem;
                // clear importer files
                Importer_.File1Dialog.FileName = "";
                Importer_.File2Dialog.FileName = "";
                Importer_.File3Dialog.FileName = "";

                // bring up panel 2 (file import) information
                // file 1
                if (Importer_.File1Description != null)
                {
                    lblFile1.Text      = Importer_.File1Description;
                    lblFile1.Visible   = true;
                    btnBrowse1.Visible = true;
                    txtFile1.Visible   = true;
                }
                else
                {
                    lblFile1.Visible   = false;
                    btnBrowse1.Visible = false;
                    txtFile1.Visible   = false;
                }
                // file 2
                if (Importer_.File2Description != null)
                {
                    lblFile2.Text      = Importer_.File2Description;
                    lblFile2.Visible   = true;
                    btnBrowse2.Visible = true;
                    txtFile2.Visible   = true;
                }
                else
                {
                    lblFile2.Visible   = false;
                    btnBrowse2.Visible = false;
                    txtFile2.Visible   = false;
                }
                // file 3
                if (Importer_.File3Description != null)
                {
                    lblFile3.Text      = Importer_.File3Description;
                    lblFile3.Visible   = true;
                    btnBrowse3.Visible = true;
                    txtFile3.Visible   = true;
                }
                else
                {
                    lblFile3.Visible   = false;
                    btnBrowse3.Visible = false;
                    txtFile3.Visible   = false;
                }
                // file instructions
                if (Importer_.FileInstructions != null)
                {
                    txtFileInstructions.Text = Importer_.FileInstructions;
                }
                else
                {
                    txtFileInstructions.Text = "No instructions provided for " + Importer_.FormatName + ".";
                }

                // bring up panel 2
                panel1.Visible = false;
                panel2.Visible = true;
                // enable back button
                btnBack.Enabled = true;
            }
            else if (CurrentPage_ == 2)
            {
                // try and parse files
                Timetable_ = Importer_.Import();

                // if it failed, alert the user and stay on the current page
                if (Timetable_ == null)
                {
                    MessageBox.Show("Failed to import timetable data.", "Import", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                // build relational data
                Timetable_.BuildEquivalency();
                Timetable_.BuildCompatibility();
                //Timetable_.UpdateStates();

                // build tree
                Timetable_.BuildTreeView(treePreview);
                // and scroll back to the top
                treePreview.Nodes[0].EnsureVisible();
                // clear details box
                txtTreeDetails.Text = "";
                timetableControl1.Clear();

                // bring up panel 3
                panel2.Visible = false;
                panel3.Visible = true;
            }
            else if (CurrentPage_ == 3)
            {
                // clear ignored/required lists
                listViewIgnored.Items.Clear();
                listViewIgnored.Groups.Clear();
                listViewRequired.Items.Clear();
                listViewRequired.Groups.Clear();

                // populate ignored/required lists
                foreach (Subject subject in Timetable_.SubjectList)
                {
                    // create and add groups for the subjects
                    ListViewGroup ignoredSubjectGroup = new ListViewGroup(subject.Name);
                    ignoredSubjectGroup.Tag = subject;
                    listViewIgnored.Groups.Add(ignoredSubjectGroup);

                    ListViewGroup requiredSubjectGroup = new ListViewGroup(subject.Name);
                    requiredSubjectGroup.Tag = subject;
                    listViewRequired.Groups.Add(requiredSubjectGroup);

                    // add stream types to subject groups
                    foreach (Type type in subject.Types)
                    {
                        // create ListViewItem without group
                        ListViewItem item = new ListViewItem(new string[] { type.Code.ToString(), type.Name });
                        item.Tag = type;

                        // add it to the current group in the correct box
                        if (type.Required)
                        {
                            // set group and add to list
                            item.Group = requiredSubjectGroup;
                            listViewRequired.Items.Add(item);
                        }
                        else
                        {
                            // set group and add to list
                            item.Group = ignoredSubjectGroup;
                            listViewIgnored.Items.Add(item);
                        }
                    }
                }

                UpdateClashHighlight();

                btnRequire.Enabled = false;
                btnIgnore.Enabled  = false;

                // bring up panel 4
                panel3.Visible = false;
                panel4.Visible = true;
                // swap next button for finish
                btnNext.Visible   = false;
                btnFinish.Visible = true;

                // need to refresh to get red highlighter
                listViewIgnored.Refresh();
                listViewRequired.Refresh();
            }
            CurrentPage_++;
        }
Пример #21
0
        private void Undo()
        {
            Timetable t = History_.Back();
            if (t == null)
            {
                System.Media.SystemSounds.Beep.Play();
                return;
            }

            Changes_--;
            Timetable_ = t.DeepCopy();
            timetableControl1.Timetable = Timetable_;
            Timetable_.RecomputeSolutions = true;
            UpdateRemaining();
        }
Пример #22
0
        /*public Timetable ShallowCopy()
        {
            Timetable t = new Timetable();
            t.SubjectList.AddRange(this.SubjectList);
            t.TypeList.AddRange(this.TypeList);
            t.StreamList.AddRange(this.StreamList);
            t.ClassList.AddRange(this.ClassList);
        }*/

        // construct a new timetable object with enough information to render a preview
        public Timetable PreviewSolution(Solver.Solution solution)
        {
            Timetable t = new Timetable();
            for (int i = 0; i < StreamList.Count; i++)
            {
                Stream stream = new Stream(StreamList[i]);
                if (solution.Streams.Contains(StreamList[i]))
                    stream.Selected = true;
                t.StreamList.Add(stream);

                stream.Classes.Clear();
                stream.Incompatible.Clear();
                stream.Equivalent.Clear();

                for (int j = 0; j < StreamList[i].Classes.Count; j++)
                {
                    Session session = new Session(StreamList[i].Classes[j]);
                    session.Stream = stream;
                    stream.Classes.Add(session);
                    t.ClassList.Add(session);
                }
            }
            t.UnavailableList = this.UnavailableList;

            return t;
        }
Пример #23
0
        public FormMain()
        {
            Timetable_ = null;
            Solver_ = new Solver(null);

            InitializeComponent();

            DefaultSize_ = Size;

            // do anchoring here to make form design easier
            tableLayoutPanel2.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            timetableControl1.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            tableLayoutPanel1.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            //tableLayoutPanel1.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;

            Export_.Width = 800;
            Export_.Height = 600;
            Export_.ShowAll = false;
            Export_.ShowDays = true;
            Export_.ShowGrayArea = false;
            Export_.ShowLocation = true;
            Export_.ShowText = true;
            Export_.ShowTimes = true;
            Export_.Grayscale = false;

            SaveDialogXML_.AddExtension = true;
            SaveDialogXML_.CheckFileExists = false;
            SaveDialogXML_.OverwritePrompt = true;
            SaveDialogXML_.Title = "Save Timetable";
            SaveDialogXML_.Filter = "XML File (*.xml)|*.xml";

            OpenDialogXML_.Multiselect = false;
            OpenDialogXML_.AddExtension = true;
            OpenDialogXML_.CheckFileExists = true;
            OpenDialogXML_.ShowReadOnly = false;
            OpenDialogXML_.Title = "Load Timetable";
            OpenDialogXML_.Filter = "XML File (*.xml)|*.xml";

            SaveDialogRaster_.AddExtension = true;
            SaveDialogRaster_.CheckFileExists = false;
            SaveDialogRaster_.OverwritePrompt = true;
            SaveDialogRaster_.Title = "Save Image";
            SaveDialogRaster_.Filter = "PNG Image (*.png)|*.png|JPEG Image (*.jpg, *.jpeg)|*.jpg;*.jpeg|GIF Image (*.gif)|*.gif";

            SaveDialogVector_.AddExtension = true;
            SaveDialogVector_.CheckFileExists = false;
            SaveDialogVector_.OverwritePrompt = true;
            SaveDialogVector_.Title = "Save Image";
            SaveDialogVector_.Filter = "Enhanced Metafile (*.emf)|*.emf";

            SaveDialogWallpaper_.AddExtension = true;
            SaveDialogWallpaper_.CheckFileExists = false;
            SaveDialogWallpaper_.OverwritePrompt = true;
            SaveDialogWallpaper_.Title = "Save Image";
            SaveDialogWallpaper_.Filter = "Bitmap Image (*.bmp)|*.bmp";
            SaveDialogWallpaper_.FileName = "wallpaper";

            //pageSetupDialog1.PageSettings = printDocument1.DefaultPageSettings;
            pageSetupDialog.PageSettings.Landscape = true;
            pageSetupDialog.PageSettings.Margins = new Margins(10 * 1000 / 254, 10 * 1000 / 254, 10 * 1000 / 254, 10 * 1000 / 254);

            FitToScreen();

            EnableButtons(false);

            UpdateSettings();
        }
Пример #24
0
 private void SetColors(Timetable timetable)
 {
     ColorScheme scheme = ColorScheme.Schemes[0];
     for (int i = 0; i < timetable.SubjectList.Count; i++)
     {
         timetable.SubjectList[i].Color = scheme.Colors[i % scheme.Colors.Count];
         /*switch (i % 6)
         {
             case 0:
                 timetable.SubjectList[i].Color = Color.Red;
                 break;
             case 1:
                 timetable.SubjectList[i].Color = Color.Blue;
                 break;
             case 2:
                 timetable.SubjectList[i].Color = Color.Green;
                 break;
             case 3:
                 timetable.SubjectList[i].Color = Color.Yellow;
                 break;
             case 4:
                 timetable.SubjectList[i].Color = Color.Purple;
                 break;
             case 5:
                 timetable.SubjectList[i].Color = Color.Orange;
                 break;
             default:
                 timetable.SubjectList[i].Color = Color.White;
                 break;
         }*/
     }
 }