/// <summary> /// Read all the note from the given Worksheet object, create the Daynotes objects and add them to this CoursePlan object. /// </summary> /// <param name="noteBoard">A excel worksheet object represents the note board. </param> /// <param name="dates">An array of DateTime objects contains all the start time of this course </param> /// <param name="isRegular">An array of string represents this course appears every week or every two weeks. /// "" represents regular, "g" represents only on even weeks and "u" only on odd weeks. /// The order of this array should be the same as the order of the array "dates". </param> public void ReadNoteBoard(Excel.Worksheet noteBoard, DateTime[] dates, string[] isRegular) { DateTimeCalcUtils.SortDate(ref dates, ref isRegular); //Initialize the counter int k = 0; //Traverse the note board for (int i = 3; i < noteBoard.UsedRange.Rows.Count - 1; i++) { //Jump the title lines if (((Excel.Range)noteBoard.Cells[i, 2]).Text == "Anfang d. 2. Abschnitts") { //Jump the holiday for (int n = 0; n < dates.Length; n++) { dates[n] = dates[n].AddDays(14); } //To the next row of the note board continue; } //Jump the title lines else if (((Excel.Range)noteBoard.Cells[i, 2]).Text == "Ende des Schuljahres" || ((Excel.Range)noteBoard.Cells[i, 2]).Text == "") { continue; } DateTime lineDate = ((Excel.Range)noteBoard.Cells[i, 2]).Value; //If the date fits if (DateTime.Compare(lineDate, dates[k]) == 0) { //If this weekday is regular, or it fits to the rule if (string.IsNullOrEmpty(isRegular[k]) || (DateTimeCalcUtils.IsEvenWeek(lineDate) && isRegular[k] == "g") || (!DateTimeCalcUtils.IsEvenWeek(lineDate) && isRegular[k] == "u")) { Daynote currentDaynotes = new Daynote(lineDate); //Go through the three notes on the same row for (int j = 3; j < 8; j += 2) { string currentNote = ((Excel.Range)noteBoard.Cells[i, j]).Value; string currentLineGrade = ((Excel.Range)noteBoard.Cells[i, j + 1]).Value; //When the note is not empty if (currentNote != null) { //If the grade fits to the current course if (currentLineGrade == this._className || currentLineGrade == this.GetGrade() || currentLineGrade == null) { currentDaynotes.AddNote(currentNote); } } } //Add the daynote to the plan this.AddLine(currentDaynotes); } dates[k] = dates[k].AddDays(7); //Move the counter of the DatesA array if (k < dates.Length - 1) { k++; } else { k = 0; } } } }
/// <summary> /// Read all the note from the given Worksheet object, create the Daynotes objects and add them to this CoursePlan object. /// </summary> /// <param name="noteBoard">A excel worksheet object represents the note board. </param> /// <param name="dates">An array of DateTime objects contains all the start time of this course </param> /// <param name="isRegular">An array of string represents this course appears every week or every two weeks. /// "" represents regular, "g" represents only on even weeks and "u" only on odd weeks. /// The order of this array should be the same as the order of the array "dates". </param> public void ReadNoteBoard(Excel.Worksheet noteBoard, DateTime[] dates, string[] isRegular, DateTime[,] holidays) { DateTimeCalcUtils.SortDate(ref dates, ref isRegular); //Initialize the counter int k = 0; //Get the end of the term var dateCell = noteBoard.Cells[1, 9] as Excel.Range; DateTime endDate = DateTime.Parse((dateCell.Text as string).Split('~').Last(), new CultureInfo("de-DE"), DateTimeStyles.NoCurrentDateDefault); //Traverse the note board for (int i = 3; i < noteBoard.UsedRange.Rows.Count; i++) { //Jump the title lines if (((Excel.Range)noteBoard.Cells[i, 2]).Text == "Anfang d. 2. Abschnitts" || ((Excel.Range)noteBoard.Cells[i, 2]).Text == "") { continue; } else if (((Excel.Range)noteBoard.Cells[i, 2]).Text == "Ende des Schuljahres") { break; } else if (DateTime.Compare(dates[k], endDate) > 0) { break; } // If the dates is in holiday, jump it // Also add a daynote that says holiday until // Use date of the holiday begin bool inFirstHoliday = DateTime.Compare(dates[k], holidays[0, 0]) >= 0 && DateTime.Compare(dates[k], holidays[0, 1]) <= 0; bool inSecondHoliday = DateTime.Compare(dates[k], holidays[1, 0]) >= 0 && DateTime.Compare(dates[k], holidays[1, 1]) <= 0; if (inFirstHoliday || inSecondHoliday) { // Jump the holidays // Not use +14 days because not every holiday has 14 days for (int j = 0; j < dates.Length; j++) { bool nowInFirstHoliday = DateTime.Compare(dates[j], holidays[0, 0]) >= 0 && DateTime.Compare(dates[j], holidays[0, 1]) <= 0; bool nowInSecondHoliday = DateTime.Compare(dates[j], holidays[1, 0]) >= 0 && DateTime.Compare(dates[j], holidays[1, 1]) <= 0; while (nowInFirstHoliday || nowInSecondHoliday) { dates[j] = dates[j].AddDays(7); nowInFirstHoliday = DateTime.Compare(dates[j], holidays[0, 0]) >= 0 && DateTime.Compare(dates[j], holidays[0, 1]) <= 0; nowInSecondHoliday = DateTime.Compare(dates[j], holidays[1, 0]) >= 0 && DateTime.Compare(dates[j], holidays[1, 1]) <= 0; } } // Check the k index, if not correct, change it for (int j = 0; j < dates.Length; j++) { if (DateTime.Compare(dates[k], dates[j]) > 0) { k = j; j = 0; } } // Add note about the holiday if (inFirstHoliday) { Daynote holidayUntil = new Daynote(holidays[0, 0]); holidayUntil.AddNote($"bis {holidays[0, 1]:dd.MM.yyyy} {DateTimeCalcUtils.GetHolidayType(holidays[0, 0])}"); this.AddLine(holidayUntil); } else if (inSecondHoliday) { Daynote holidayUntil = new Daynote(holidays[1, 0]); holidayUntil.AddNote($"bis {holidays[1, 1]:dd.MM.yyyy} {DateTimeCalcUtils.GetHolidayType(holidays[1, 0])}"); this.AddLine(holidayUntil); } } // Get the date of the current line of the note board DateTime lineDate = ((Excel.Range)noteBoard.Cells[i, 2]).Value; //If the date fits if (DateTime.Compare(lineDate, dates[k]) == 0) { //If this weekday is regular, or it fits to the rule if (string.IsNullOrEmpty(isRegular[k]) || (DateTimeCalcUtils.IsEvenWeek(lineDate) && isRegular[k] == "g") || (!DateTimeCalcUtils.IsEvenWeek(lineDate) && isRegular[k] == "u")) { Daynote currentDaynotes = new Daynote(lineDate); //Go through the three notes on the same row for (int j = 3; j < 8; j += 2) { string currentNote = ((Excel.Range)noteBoard.Cells[i, j]).Value; string currentLineGrade = ((Excel.Range)noteBoard.Cells[i, j + 1]).Value; //When the note is not empty if (currentNote != null) { //If the grade fits to the current course if (currentLineGrade == this._className || currentLineGrade == this.GetGrade() || string.IsNullOrEmpty(currentLineGrade)) { currentDaynotes.AddNote(currentNote); } } } //Add the daynote to the plan this.AddLine(currentDaynotes); } dates[k] = dates[k].AddDays(7); //Move the counter of the DatesA array if (k < dates.Length - 1) { k++; } else { k = 0; } } } // string secondHoliday = $"bis {holidays[1, 1]:dd.MM.yyyy} {DateTimeCalcUtils.GetHolidayType(holidays[1, 0])}"; // if (!_lines.Last().GetNotes().Contains(secondHoliday)) // _lines.Last().AddNote(secondHoliday); }