home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 February / Chip_2004-02_cd1.bin / program / delphi / navody / d56 / ec1vr2.exe / #setuppath# / CB5 / CalendarMaker / Main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-12-09  |  7.4 KB  |  221 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Main.h"
  6. #include "About.h"
  7. #include "FileCtrl.hpp"
  8. //---------------------------------------------------------------------------
  9. #pragma link "VReport"
  10. #pragma link "vrpage"
  11. #pragma link "Vrctrl"
  12. #pragma link "Vrctrlr"
  13. #pragma link "Vrlabel"
  14. #pragma link "Vrgrid"
  15. #pragma link "Vrprev"
  16. #pragma link "Vrprogr"
  17. #pragma resource "*.dfm"
  18.  
  19. #define MONTHS 4
  20. #define ROWS 3
  21.  
  22. TMainForm *MainForm;
  23. //---------------------------------------------------------------------------
  24. __fastcall TMainForm::TMainForm(TComponent* Owner)
  25.     : TForm(Owner)
  26. {
  27.   HolidaysTable->Active = true;
  28.  
  29.   Year = StrToInt (YearEdit->Text);
  30. }
  31. //----------------------------------------------------------------------------
  32. void __fastcall TMainForm::ExitActionExecute(TObject *Sender)
  33. {
  34.   Close();
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TMainForm::AboutActionExecute(TObject *Sender)
  38. {
  39.   AboutBox->ShowModal ();
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TMainForm::PrintSetupActionExecute(TObject *Sender)
  43. {
  44.   Report->PrinterSetup ();
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TMainForm::PrintActionExecute(TObject *Sender)
  48. {
  49.   if (Report->PrintSetup ())
  50.   {
  51.     Report->Print ();
  52.   }
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TMainForm::PrintPreviewActionExecute(TObject *Sender)
  56. {
  57.   Report->PrintPreview (PrintPreview);
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TMainForm::LoadActionExecute(TObject *Sender)
  61. {
  62.   if (LoadDialog->Execute ())
  63.   {
  64.     ((TAbsPicture *)PictureLabel->Data)->Picture->LoadFromFile (LoadDialog->FileName);
  65.   }
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TMainForm::HolidaysTableDateGetText(TField *Sender,
  69.       AnsiString &Text, bool DisplayText)
  70. {
  71.   if (DisplayText) Text = Sender->AsDateTime.FormatString ("d mmmm");
  72.   else
  73.   {
  74.     Word Year, Month, Day;
  75.     DecodeDate (Sender->AsDateTime,Year,Month,Day);
  76.     Text = IntToStr (Day) + "." + IntToStr (Month);
  77.   }
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TMainForm::HolidaysTableDateSetText(TField *Sender,
  81.       const AnsiString Text)
  82. {
  83.   int Month, Day;
  84.   int Pos;
  85.  
  86.   if ((Pos=Text.Pos (".")) != 0)
  87.   {
  88.     Day = atoi (Text.SubString (1,Pos-1).c_str ());
  89.     Month = atoi (Text.SubString (Pos+1,Text.Length ()-Pos).c_str ());
  90.     Sender->AsDateTime = TDateTime (2000,Month,Day);
  91.   }
  92.   else throw EConvertError ("Invalid date string");
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TMainForm::Zoom25ActionExecute(TObject *Sender)
  96. {
  97.   VRPage1->Zoom = 25;
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TMainForm::Zoom50ActionExecute(TObject *Sender)
  101. {
  102.   VRPage1->Zoom = 50;
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TMainForm::Zoom100ActionExecute(TObject *Sender)
  106. {
  107.   VRPage1->Zoom = 100;
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TMainForm::Zoom200ActionExecute(TObject *Sender)
  111. {
  112.   VRPage1->Zoom = 200;
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TMainForm::Zoom400ActionExecute(TObject *Sender)
  116. {
  117.   VRPage1->Zoom = 400;
  118. }
  119. //---------------------------------------------------------------------------
  120. void __fastcall TMainForm::YearEditExit(TObject *Sender)
  121. {
  122.   Year = StrToInt (YearEdit->Text);
  123.  
  124.   VRPage1->Invalidate();
  125. }
  126. //---------------------------------------------------------------------------
  127. void __fastcall TMainForm::HolidaysTableAfterPost(TDataSet *DataSet)
  128. {
  129.   VRPage1->Invalidate();
  130. }
  131. //---------------------------------------------------------------------------
  132. void __fastcall TMainForm::YearEditKeyPress(TObject *Sender, char &Key)
  133. {
  134.   if (Key == VK_RETURN) YearEditExit(Sender);
  135. }
  136. //---------------------------------------------------------------------------
  137. void __fastcall TMainForm::YearLabelCalcValue(TObject *Sender)
  138. {
  139.   ((TAbsString *)YearLabel->Data)->Value = Year;
  140. }
  141. //---------------------------------------------------------------------------
  142. void __fastcall TMainForm::TextEditChange(TObject *Sender)
  143. {
  144.   ((TAbsPlainText *)TextLabel->Data)->StringList->Text = TextEdit->Lines->Text;
  145. }
  146. //---------------------------------------------------------------------------
  147. void __fastcall TMainForm::ShadowLabelCalcValue(TObject *Sender)
  148. {
  149.   ((TAbsString *)ShadowLabel->Data)->Value = Year;
  150. }
  151. //---------------------------------------------------------------------------
  152. void __fastcall TMainForm::MonthsGridColumns0EndPrint(TObject *Sender,
  153.       TAfterAction &ARepeat)
  154. {
  155.   MonthsCol++;
  156.  
  157.   if (MonthsCol < MONTHS) ARepeat = aaRepeat;
  158.   else MonthsCol = 0;
  159. }
  160. //---------------------------------------------------------------------------
  161. void __fastcall TMainForm::MonthsGridRows0EndPrint(TObject *Sender,
  162.       TAfterAction &ARepeat)
  163. {
  164.   Row ++;
  165.  
  166.   if (Row < ROWS) ARepeat = aaRepeat;
  167.   else Row = 0;
  168. }
  169. //---------------------------------------------------------------------------
  170. void __fastcall TMainForm::MonthsGridColumns0SubItems0EndPrint(
  171.       TObject *Sender, TAfterAction &ARepeat)
  172. {
  173.   WeekDay ++;
  174.  
  175.   if (WeekDay < 7) ARepeat = aaRepeat;
  176.   else WeekDay = 0;
  177. }
  178. //---------------------------------------------------------------------------
  179. void __fastcall TMainForm::MonthsGridColumns0SubItems1BeginPrint(
  180.       TObject *Sender, TBeforeAction &APrint)
  181. {
  182.   if (MonthsCol == MONTHS - 1) APrint = baNoPrint;
  183. }
  184. //---------------------------------------------------------------------------
  185. void __fastcall TMainForm::MonthsGridRows0SubItems2EndPrint(
  186.       TObject *Sender, TAfterAction &ARepeat)
  187. {
  188.   Week ++;
  189.  
  190.   if (Week < 6) ARepeat = aaRepeat;
  191.   else Week = 0;
  192. }
  193. //---------------------------------------------------------------------------
  194. void __fastcall TMainForm::MonthsGridCells0CalcValue(TObject *Sender)
  195. {
  196.   ((TAbsString *)Sender)->Value = AnsiString (LongMonthNames[MonthsCol + (Row*MONTHS)]).LowerCase ();
  197. }
  198. //---------------------------------------------------------------------------
  199. void __fastcall TMainForm::MonthsGridCells1CalcValue(TObject *Sender)
  200. {
  201.   int Index = (WeekDay == 6)?0:WeekDay+1;
  202.  
  203.   ((TAbsString *)Sender)->Value = AnsiString (ShortDayNames[Index]).UpperCase ();
  204.   ((TAbsString *)Sender)->Font->Color = (WeekDay > 4)?clRed:clGray;
  205. }
  206. //---------------------------------------------------------------------------
  207. void __fastcall TMainForm::MonthsGridCells2CalcValue(TObject *Sender)
  208. {
  209.   TDateTime FirstDayDate = TDateTime (Year,MonthsCol + (Row*MONTHS) + 1,1);
  210.   int Day = max ((Week*7) + WeekDay - (FirstDayDate.DayOfWeek()+5)%7 + 1,0);
  211.  
  212.   if (Day > (int)(IncMonth (FirstDayDate,1) - FirstDayDate)) Day = 0;
  213.  
  214.   ((TAbsInt *)Sender)->Value = Day;
  215.   ((TAbsInt *)Sender)->Font->Color = (WeekDay > 4 ||
  216.     (Day != 0 && !HolidaysTable->Lookup ("Date",TDateTime (2000,MonthsCol + (Row*MONTHS) + 1,Day),"Date").IsNull ()))?
  217.     clRed:clBlack;
  218. }
  219. //---------------------------------------------------------------------------
  220.  
  221.