home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / CrossLang / CalendarGenerator.cpp next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  5.0 KB  |  159 lines

  1. /*===========================================================================
  2.   File:      CalendarGenerator.CPP
  3.  
  4.   Summary:   This is one of the derived classes for the CrossLang sample.
  5.              This class generates calendars in HTML format.
  6.  
  7. ----------------------------------------------------------------------------
  8.   This file is part of the Microsoft NGWS Samples.
  9.  
  10.   Copyright (C) 1998-2000 Microsoft Corporation.  All rights reserved.
  11. ===========================================================================*/
  12.  
  13. #using <mscorlib.dll>
  14. #using "TableGen.dll"
  15. using namespace System;
  16.  
  17. [assembly::System::Runtime::CompilerServices::AssemblyKeyFileAttribute("CalendarGen.key")];
  18.  
  19. __gc public class CalendarGenerator : public TableGen::TableGenerator
  20. {
  21. protected:
  22.     int startcell;
  23.     int month;
  24.     int year;
  25.     
  26. public:
  27.  
  28.     /******************************************************************************
  29.     Function : SetParameter(String param)
  30.     
  31.     Abstract: This implementation of SetParameter() determines what month
  32.               to generate a calelendar for.
  33.     
  34.     Input Parameters: String param = The String that represents the month/year.
  35.     
  36.     Returns: void.
  37.     ******************************************************************************/
  38.     void SetParameter(String *param)
  39.     {
  40.         // Take string, parse, get month and year.
  41.         int delimeter = param->IndexOf(L'/');
  42.         month = Convert::ToInt32(param->Substring(0, delimeter));
  43.         year = Convert::ToInt32(param->Substring(delimeter+1, 4));
  44.  
  45.         // Do simple bounds check on month
  46.         if(month > 12)
  47.             month = 12;
  48.         if(month < 1)
  49.             month = 1;
  50.  
  51.         // Create a Date Object based on the first of the specified month and year
  52.         DateTime d(year, month, 1, 0, 0, 0);
  53.         
  54.         // Use the DateTime class to get the day of the week for the 1st of the month.
  55.         startcell = d.DayOfWeek; 
  56.     }
  57.     
  58.         /******************************************************************************
  59.     Function : int GetColumnCount()
  60.     
  61.     Abstract: This implementation of GetColumnCount() returns the number of days
  62.           in the week.
  63.     
  64.     Input Parameters: None
  65.     
  66.     Returns: int: The number of columns.
  67.     ******************************************************************************/
  68.     int GetColumnCount()
  69.     {
  70.         // Always 7 days in a week.
  71.         return 7;
  72.     }
  73.     
  74.         /******************************************************************************
  75.     Function : int GetRowCount()
  76.     
  77.     Abstract: This implementation of GetRowCount() returns the number of
  78.           weeks in the specified month.
  79.     
  80.     Input Parameters: None
  81.     
  82.     Returns: int: The number of rows.
  83.     ******************************************************************************/
  84.     int GetRowCount()
  85.     {
  86.         // Get the number of days in the month
  87.         int numdays = DateTime::DaysInMonth(year, month);
  88.         
  89.         // Get the total days in the month plus the offset from the beginning
  90.         // of the first week.
  91.         int daysplusoffset = numdays + startcell;
  92.         
  93.         // Find out how many whole weeks are in the month + offset.
  94.         int weeksinmonth = daysplusoffset / 7;
  95.         
  96.         // If there is a remainder, add an additional week.
  97.         if(daysplusoffset%7)
  98.             weeksinmonth++;
  99.          
  100.         return weeksinmonth;
  101.     }
  102.  
  103.         /******************************************************************************
  104.     Function : String *GetHeader()
  105.     
  106.     Abstract: This method returns any default header for this table.  Since this
  107.               is a calendar, we return the names of each day of the week.
  108.     
  109.     Input Parameters: None
  110.     
  111.     Returns: String: HTML header for the top of the table.
  112.     ******************************************************************************/
  113.     String *GetHeader()
  114.     {
  115.         // Return default header with the days of the week.
  116.         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>";
  117.     }
  118.     
  119.     /******************************************************************************
  120.     Function : String* GetFooter()
  121.     
  122.     Abstract: This method returns any empty footer for this table.
  123.     
  124.     Input Parameters: None
  125.     
  126.     Returns: String*: HTML footer for the bottom of the table.
  127.     ******************************************************************************/
  128.     String *GetFooter()
  129.     {
  130.         return L"";
  131.     }
  132.     
  133.         /******************************************************************************
  134.     Function : String* GetCell(int column, int row)
  135.     
  136.     Abstract: This implementation of GetCell() returns the HTML string 
  137.           representation for this cell in the table.
  138.     
  139.     Input Parameters: int column: The column to get, int row: The row to get
  140.     
  141.     Returns: String*: HTML for the specific cell.
  142.     ******************************************************************************/
  143.     String *GetCell(int column, int row)
  144.     {
  145.         // Determine the date from the row and cell number.
  146.         int date = ((row *7)+(column - startcell))+1;
  147.         
  148.         // Get the number of days in the month specified by client.
  149.         int numdays = DateTime::DaysInMonth(year, month);
  150.         
  151.         // Return a String representation of the date
  152.         if(date > 0 && date <= numdays)
  153.             return Convert::ToString((int)date);
  154.         else
  155.             return L"";
  156.     }
  157.  
  158. };
  159.