public Enrollment(Activity activity, Student student, string cell) { if (cell == null) { throw new ArgumentNullException(); } if (cell.Length > 2) { throw new ArgumentException("Cell data too long"); } if (!(cell[0] == 'P' || (cell[0] >= '0' && cell[0] <= '9'))) { throw new ArgumentException("Priority not valid"); } if (cell.Length > 1 && cell[1] != 'A') { throw new ArgumentException("Status not valid"); } activity.Quota[student.Class].AddEnroll(this); // do this first, so we may throw KeyNotFoundException student.Quota.AddEnroll(this); Activity = activity; Student = student; Id = _globalIdCount++; PriorityI = (cell[0] == 'P') ? -1 : (cell[0] - '0'); bool status = cell.Length > 1 && cell[1] == 'A'; if (core.EnrollStatus == null) core.EnrollStatus = new State(); core.EnrollStatus = core.EnrollStatus.Set(Id, status); }
internal void LoadActivities() { var wsAct = (Worksheet)Book.Sheets["0.班別名額"]; Range usedRange = wsAct.UsedRange; // actArr is an one-based array var actArr = (object[,])usedRange.Value; int numCols = actArr.GetLength(1); var className = new List<string>(numCols); for (int i = 3; i <= numCols; i++) { if (actArr[1, i] == null) { break; } className.Add(actArr[1, i].ToString().Trim()); } int numRows = actArr.GetLength(0); ActList = new List<Activity>(numRows); for (int i = 2; i <= numRows; i++) { GC.Collect(); try { var a = new Activity(i - 2, actArr[i, 1].ToString(), actArr[i, 2].ToString()); Debug.Print("Loaded -> " + i + ":" + a); Constraint con = null; for (int j = 0; j < className.Count; j++) { object o = actArr[i, 3 + j]; if (o == null) { continue; } if (o is string) { if ("<".Equals(((string)o).Trim())) { a.Quota[className[j]] = con; Debug.Print(" < " + className[j] + " " + con); } else { Debug.Print(" ? " + className[j] + " " + o); } } else if (o is double) { con = new Constraint((int)(double)o); a.Quota[className[j]] = con; Debug.Print(" - " + className[j] + " " + con); } else { throw new ApplicationException("Illegal data type '" + o.GetType() + "' at (" + i + ",3)"); } } ActList.Add(a); } catch (NullReferenceException) { } catch (IndexOutOfRangeException) { } catch (ArgumentException) { } } }