private DateList fillMonth() { int month = today.Month; int year = today.Year; DateList first = new DateList(1, month, year); DateList current = first; DateList temp; switch (month) { // Thirty days hath September, April, June, and November case 4: case 6: case 9: case 11: for (int i = 2; i <= 30; i++) { temp = new DateList(i, month, year); current.setNext(temp); current = current.getNext(); } break; // Except February which has 28 (or 29) case 2: if (DateTime.IsLeapYear(year)) { for (int i = 2; i <= 29; i++) { temp = new DateList(i, month, year); current.setNext(temp); current = current.getNext(); } } else { for (int i = 2; i <= 28; i++) { temp = new DateList(i, month, year); current.setNext(temp); current = current.getNext(); } } break; // All the rest have 31 default: for (int i = 2; i <= 31; i++) { temp = new DateList(i, month, year); current.setNext(temp); current = current.getNext(); } break; } return(first); }
public void PrintCalendar() { DateList current = first; DateTime firstDay = new DateTime(first.getYear(), first.getMonth(), first.getDay()); DateTime currentDay; int date = (int)firstDay.DayOfWeek; PrintMonthYear(); for (int i = 0; i < 6; i++) { for (int j = 0; j < 7; j++) { if (i == 0 && j < date) { Console.Write(" "); } else { currentDay = new DateTime(current.getYear(), current.getMonth(), current.getDay()); if (current.getDay() < 10) { if (today == currentDay) { Console.Write(" "); Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Black; Console.Write(" {0} ", current.getDay()); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } else { Console.Write(" {0} ", current.getDay()); } } else { if (today == currentDay) { Console.BackgroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Black; Console.Write(" {0} ", current.getDay()); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; } else { Console.Write(" {0} ", current.getDay()); } } current = current.getNext(); } if (current == null) { break; } } Console.WriteLine(); if (current == null) { break; } Console.WriteLine(); } for (int i = 0; i < Console.WindowWidth; i++) { Console.Write("="); } }