home *** CD-ROM | disk | FTP | other *** search
- /*===========================================================================
- File: CalendarGenerator.CPP
-
- Summary: This is one of the derived classes for the CrossLang sample.
- This class generates calendars in HTML format.
-
- ----------------------------------------------------------------------------
- This file is part of the Microsoft NGWS Samples.
-
- Copyright (C) 1998-2000 Microsoft Corporation. All rights reserved.
- ===========================================================================*/
-
- #using <mscorlib.dll>
- #using "TableGen.dll"
- using namespace System;
-
- [assembly::System::Runtime::CompilerServices::AssemblyKeyFileAttribute("CalendarGen.key")];
-
- __gc public class CalendarGenerator : public TableGen::TableGenerator
- {
- protected:
- int startcell;
- int month;
- int year;
-
- public:
-
- /******************************************************************************
- Function : SetParameter(String param)
-
- Abstract: This implementation of SetParameter() determines what month
- to generate a calelendar for.
-
- Input Parameters: String param = The String that represents the month/year.
-
- Returns: void.
- ******************************************************************************/
- void SetParameter(String *param)
- {
- // Take string, parse, get month and year.
- int delimeter = param->IndexOf(L'/');
- month = Convert::ToInt32(param->Substring(0, delimeter));
- year = Convert::ToInt32(param->Substring(delimeter+1, 4));
-
- // Do simple bounds check on month
- if(month > 12)
- month = 12;
- if(month < 1)
- month = 1;
-
- // Create a Date Object based on the first of the specified month and year
- DateTime d(year, month, 1, 0, 0, 0);
-
- // Use the DateTime class to get the day of the week for the 1st of the month.
- startcell = d.DayOfWeek;
- }
-
- /******************************************************************************
- Function : int GetColumnCount()
-
- Abstract: This implementation of GetColumnCount() returns the number of days
- in the week.
-
- Input Parameters: None
-
- Returns: int: The number of columns.
- ******************************************************************************/
- int GetColumnCount()
- {
- // Always 7 days in a week.
- return 7;
- }
-
- /******************************************************************************
- Function : int GetRowCount()
-
- Abstract: This implementation of GetRowCount() returns the number of
- weeks in the specified month.
-
- Input Parameters: None
-
- Returns: int: The number of rows.
- ******************************************************************************/
- int GetRowCount()
- {
- // Get the number of days in the month
- int numdays = DateTime::DaysInMonth(year, month);
-
- // Get the total days in the month plus the offset from the beginning
- // of the first week.
- int daysplusoffset = numdays + startcell;
-
- // Find out how many whole weeks are in the month + offset.
- int weeksinmonth = daysplusoffset / 7;
-
- // If there is a remainder, add an additional week.
- if(daysplusoffset%7)
- weeksinmonth++;
-
- return weeksinmonth;
- }
-
- /******************************************************************************
- Function : String *GetHeader()
-
- Abstract: This method returns any default header for this table. Since this
- is a calendar, we return the names of each day of the week.
-
- Input Parameters: None
-
- Returns: String: HTML header for the top of the table.
- ******************************************************************************/
- String *GetHeader()
- {
- // Return default header with the days of the week.
- return L"<THEAD><TH>Sun</TH><TH>Mon</TH><TH>Tue</TH><TH>Wed</TH><TH>Thu</TH><TH>Fri</TH><TH>Sat</TH></THEAD>";
- }
-
- /******************************************************************************
- Function : String* GetFooter()
-
- Abstract: This method returns any empty footer for this table.
-
- Input Parameters: None
-
- Returns: String*: HTML footer for the bottom of the table.
- ******************************************************************************/
- String *GetFooter()
- {
- return L"";
- }
-
- /******************************************************************************
- Function : String* GetCell(int column, int row)
-
- Abstract: This implementation of GetCell() returns the HTML string
- representation for this cell in the table.
-
- Input Parameters: int column: The column to get, int row: The row to get
-
- Returns: String*: HTML for the specific cell.
- ******************************************************************************/
- String *GetCell(int column, int row)
- {
- // Determine the date from the row and cell number.
- int date = ((row *7)+(column - startcell))+1;
-
- // Get the number of days in the month specified by client.
- int numdays = DateTime::DaysInMonth(year, month);
-
- // Return a String representation of the date
- if(date > 0 && date <= numdays)
- return Convert::ToString((int)date);
- else
- return L"";
- }
-
- };
-