Esempio n. 1
0
		private void ProceedDividedCell(CQ Cell, List<Subject> targetList, int day, int hour)
		{
			string fullName = WebUtility.HtmlDecode(Cell[".r_predm_in2"][0]["title"]);
			string shortName = WebUtility.HtmlDecode(Cell[".r_predm_in2"][0].InnerText);

			string longTeacher = WebUtility.HtmlDecode(Cell[".r_ucit_in2"][0]["title"]);
			string shortTeacher = WebUtility.HtmlDecode(Cell[".r_ucit_in2"][0].InnerText);

			string shortRoom = WebUtility.HtmlDecode(Cell[".r_mist_in2 > div.r_dole"][0]["title"]);

			var selectAciveQ = from q in targetList
							   where q.Info.LongName == fullName
							   select q;

			SubjectInfo cellInfo = new SubjectInfo
			{
				LongName = fullName,
				ShortName = shortName,
				LongTeacher = longTeacher,
				ShortTeacher = shortTeacher
			};

			SheduleTime thisTime = new SheduleTime
			{
				Info = cellInfo,
				Week = ((shortName.Contains("L: ")) ? SheduleTime.EEvenOdd.Odd : SheduleTime.EEvenOdd.Even),
				ShedulePosition = new ShedulePosition
				{
					Day = day,
					Hour = hour
				}
			};
			thisTime.Info.ShortName = thisTime.Info.ShortName.Replace("L: ", "").Replace("S: ", "");

			if (!selectAciveQ.Any())//add new subject
			{
				Subject newSubject = new Subject(thisTime)
				{
					Info = cellInfo,
					Id = targetList.Count
				};

				targetList.Add(newSubject);
			}
			else//assign to an existing subject
			{
				selectAciveQ.ElementAt(0).When.Add(thisTime);
			}
		}
Esempio n. 2
0
		private List<Subject> ParseSubjects(string html)
		{
			CQ DOM = html;
			List<Subject> innerSubs = new List<Subject>();

			IDomObject[] mainLines = DOM[".r_roztable > tbody > tr"].ToArray();
			for (int y = 1; y < 6; y++)
			{
				IDomObject[] dayLines = ((CQ)mainLines[y].OuterHTML)["tr > td"].ToArray();

				for (int x = 1; x < 16; x++)
				{
					IDomObject hourCell = dayLines[x];
					if (hourCell.HasClass("r_rr"))//no subject there
					{
						//Debug.WriteLine("empty cell [d,h]: [" + (y - 1) + "," + (x - 1) + "]");
					}
					else if (hourCell.HasClass("r_rrw"))//something there
					{
						if ((((CQ)hourCell.InnerHTML)[".r_bunka_2"][0]) == null)
						{
							IDomObject subName = ((CQ)hourCell.InnerHTML)[".r_predm"][0];

							string fullName = WebUtility.HtmlDecode(subName["title"]);
							var checkQuery = from q in innerSubs
											  where q.Info.LongName == fullName
											  select q;

							string shortName = WebUtility.HtmlDecode(subName.InnerText);
							IDomObject teacher = (((CQ)hourCell.InnerHTML)[".r_ucit"][0]);
							string longTeacher = WebUtility.HtmlDecode(teacher["title"]);
							string shortTeacher = WebUtility.HtmlDecode(teacher.InnerText);

							SubjectInfo cellInfo = new SubjectInfo
							{
								LongName = fullName,
								LongTeacher = longTeacher,
								ShortTeacher = shortTeacher,
								ShortName = shortName
							};

							SheduleTime thisTime = ParseScheduleTime(hourCell, (y - 1), (x - 1));//this cell
							thisTime.Info = cellInfo;

							if (!checkQuery.Any())//new subj
							{
								if (shortName.Contains("S: ") || shortName.Contains("L: "))//detect even/odd
								{
									thisTime.Week = shortName.Contains("S: ") ? SheduleTime.EEvenOdd.Even : SheduleTime.EEvenOdd.Odd;
								}

								Subject newSubject = new Subject(thisTime)
								{
									Info = cellInfo,
									Id = innerSubs.Count
								};

								newSubject.Info.ShortName = newSubject.Info.ShortName.Replace("S: ", "").Replace("L: ", "");

								innerSubs.Add(newSubject);
							}
							else//we already know this subject, add new sheduleTime
							{
								Subject oldSubject = checkQuery.First();
								oldSubject.When.Add(thisTime);
							}
						}
						else
						{
							CQ divCell = ((CQ)hourCell.InnerHTML)[".r_bunka_2"][0].InnerHTML;

							ProceedDividedCell(divCell[".r_bunka_in2"][0].InnerHTML, innerSubs, y - 1, x - 1);
							ProceedDividedCell(divCell[".r_bunka_in2last"][0].InnerHTML, innerSubs, y - 1, x - 1);
						}
					}
				}
			}

			return innerSubs;
		}