예제 #1
0
        internal void LoadEnrollments(BackgroundWorker worker, int progressBase, int progressWidth)
        {
            var ws = (Worksheet)Book.Sheets["2.選班資料"];
            try
            {
                ws.Unprotect();
                Range r = ws.Range[
                    ws.Cells[RowOffset + 1, ColumnOffset + 1],
                    ws.Cells[RowOffset + StuList.Count, ColumnOffset + ActList.Count]
                    ];

                int curr = 0;
                int count = r.Count;
                EnrollList = new List<Enrollment>();
                foreach (Range c in r)
                {
                    if (c.Value2 != null && ((string)c.Text != ""))
                    {
                        try
                        {
                            Activity act = ActList[c.Column - ColumnOffset - 1];
                            Student stu = StuList[c.Row - RowOffset - 1];
                            var enroll = new Enrollment(
                                act,
                                stu,
                                (string)c.Text
                                );
                            EnrollList.Add(enroll);
                            c.Interior.Pattern = Constants.xlNone;
                        }
                        catch (KeyNotFoundException)
                        {
                            c.Interior.Color = XlRgbColor.rgbLightGrey;
                        }
                        catch (ArgumentException)
                        {
                            c.Interior.Color = XlRgbColor.rgbDarkGrey;
                        }
                    }
                    worker.ReportProgress(progressBase + progressWidth * ++curr / count);
                }
            }
            finally
            {
                ws.Protect(Contents: true, Scenarios: true);
            }

            EnrollList.Sort(EnrollPriorityComparator.FORWARD);
            foreach (Enrollment enroll in EnrollList)
            {
                Debug.Print(enroll.ToString());
            }
        }
        private void ForceEnroll(Enrollment e, Constraint[] restrict, int lvl, List<Enrollment> maybe)
        {
            if (lvl == restrict.Length)
            {
                Debug.Assert(e.GetRestricted() == null);
                e.Enrolled = true;

                var list = from eB in maybe.Distinct()
                           orderby eB.PriorityI
                           select eB;
                foreach (Enrollment eB in list)
                    if (!eB.Enrolled && eB.GetRestricted() == null)
                        eB.Enrolled = true;

                if (CheckVisit(EnrollStatus)) return;
                Queue(EnrollStatus);
            }
            else
            {
                State oldState = EnrollStatus;
                var rA = restrict[lvl].Accepted.OrderByDescending(eA => eA.PriorityI).Take(PROCESS_ROUND);
                foreach (var r in rA)
                {
                    EnrollStatus = oldState;
                    r.Enrolled = false;

                    var _maybe = (maybe == null ? new List<Enrollment>() : new List<Enrollment>(maybe));
                    _maybe.AddRange(r.ActivityQuota.Rejected);
                    _maybe.AddRange(r.StudentQuota.Rejected);
                    ForceEnroll(e, restrict, lvl + 1, _maybe);
                }
            }
        }