home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl\vcl.h>
- #pragma hdrstop
-
- #include "Main.h"
- #include "About.h"
- #include "FileCtrl.hpp"
- //---------------------------------------------------------------------------
- #pragma link "VReport"
- #pragma link "vrpage"
- #pragma link "Vrctrl"
- #pragma link "Vrctrlr"
- #pragma link "Vrlabel"
- #pragma link "Vrgrid"
- #pragma link "Vrprev"
- #pragma link "Vrprogr"
- #pragma resource "*.dfm"
-
- #define MONTHS 4
- #define ROWS 3
-
- TMainForm *MainForm;
- //---------------------------------------------------------------------------
- __fastcall TMainForm::TMainForm(TComponent* Owner)
- : TForm(Owner)
- {
- HolidaysTable->Active = true;
-
- Year = StrToInt (YearEdit->Text);
- }
- //----------------------------------------------------------------------------
- void __fastcall TMainForm::ExitActionExecute(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::AboutActionExecute(TObject *Sender)
- {
- AboutBox->ShowModal ();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::PrintSetupActionExecute(TObject *Sender)
- {
- Report->PrinterSetup ();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::PrintActionExecute(TObject *Sender)
- {
- if (Report->PrintSetup ())
- {
- Report->Print ();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::PrintPreviewActionExecute(TObject *Sender)
- {
- Report->PrintPreview (PrintPreview);
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::LoadActionExecute(TObject *Sender)
- {
- if (LoadDialog->Execute ())
- {
- ((TAbsPicture *)PictureLabel->Data)->Picture->LoadFromFile (LoadDialog->FileName);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::HolidaysTableDateGetText(TField *Sender,
- AnsiString &Text, bool DisplayText)
- {
- if (DisplayText) Text = Sender->AsDateTime.FormatString ("d mmmm");
- else
- {
- Word Year, Month, Day;
- DecodeDate (Sender->AsDateTime,Year,Month,Day);
- Text = IntToStr (Day) + "." + IntToStr (Month);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::HolidaysTableDateSetText(TField *Sender,
- const AnsiString Text)
- {
- int Month, Day;
- int Pos;
-
- if ((Pos=Text.Pos (".")) != 0)
- {
- Day = atoi (Text.SubString (1,Pos-1).c_str ());
- Month = atoi (Text.SubString (Pos+1,Text.Length ()-Pos).c_str ());
- Sender->AsDateTime = TDateTime (2000,Month,Day);
- }
- else throw EConvertError ("Invalid date string");
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::Zoom25ActionExecute(TObject *Sender)
- {
- VRPage1->Zoom = 25;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::Zoom50ActionExecute(TObject *Sender)
- {
- VRPage1->Zoom = 50;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::Zoom100ActionExecute(TObject *Sender)
- {
- VRPage1->Zoom = 100;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::Zoom200ActionExecute(TObject *Sender)
- {
- VRPage1->Zoom = 200;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::Zoom400ActionExecute(TObject *Sender)
- {
- VRPage1->Zoom = 400;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::YearEditExit(TObject *Sender)
- {
- Year = StrToInt (YearEdit->Text);
-
- VRPage1->Invalidate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::HolidaysTableAfterPost(TDataSet *DataSet)
- {
- VRPage1->Invalidate();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::YearEditKeyPress(TObject *Sender, char &Key)
- {
- if (Key == VK_RETURN) YearEditExit(Sender);
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::YearLabelCalcValue(TObject *Sender)
- {
- ((TAbsString *)YearLabel->Data)->Value = Year;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::TextEditChange(TObject *Sender)
- {
- ((TAbsPlainText *)TextLabel->Data)->StringList->Text = TextEdit->Lines->Text;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::ShadowLabelCalcValue(TObject *Sender)
- {
- ((TAbsString *)ShadowLabel->Data)->Value = Year;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::MonthsGridColumns0EndPrint(TObject *Sender,
- TAfterAction &ARepeat)
- {
- MonthsCol++;
-
- if (MonthsCol < MONTHS) ARepeat = aaRepeat;
- else MonthsCol = 0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::MonthsGridRows0EndPrint(TObject *Sender,
- TAfterAction &ARepeat)
- {
- Row ++;
-
- if (Row < ROWS) ARepeat = aaRepeat;
- else Row = 0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::MonthsGridColumns0SubItems0EndPrint(
- TObject *Sender, TAfterAction &ARepeat)
- {
- WeekDay ++;
-
- if (WeekDay < 7) ARepeat = aaRepeat;
- else WeekDay = 0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::MonthsGridColumns0SubItems1BeginPrint(
- TObject *Sender, TBeforeAction &APrint)
- {
- if (MonthsCol == MONTHS - 1) APrint = baNoPrint;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::MonthsGridRows0SubItems2EndPrint(
- TObject *Sender, TAfterAction &ARepeat)
- {
- Week ++;
-
- if (Week < 6) ARepeat = aaRepeat;
- else Week = 0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::MonthsGridCells0CalcValue(TObject *Sender)
- {
- ((TAbsString *)Sender)->Value = AnsiString (LongMonthNames[MonthsCol + (Row*MONTHS)]).LowerCase ();
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::MonthsGridCells1CalcValue(TObject *Sender)
- {
- int Index = (WeekDay == 6)?0:WeekDay+1;
-
- ((TAbsString *)Sender)->Value = AnsiString (ShortDayNames[Index]).UpperCase ();
- ((TAbsString *)Sender)->Font->Color = (WeekDay > 4)?clRed:clGray;
- }
- //---------------------------------------------------------------------------
- void __fastcall TMainForm::MonthsGridCells2CalcValue(TObject *Sender)
- {
- TDateTime FirstDayDate = TDateTime (Year,MonthsCol + (Row*MONTHS) + 1,1);
- int Day = max ((Week*7) + WeekDay - (FirstDayDate.DayOfWeek()+5)%7 + 1,0);
-
- if (Day > (int)(IncMonth (FirstDayDate,1) - FirstDayDate)) Day = 0;
-
- ((TAbsInt *)Sender)->Value = Day;
- ((TAbsInt *)Sender)->Font->Color = (WeekDay > 4 ||
- (Day != 0 && !HolidaysTable->Lookup ("Date",TDateTime (2000,MonthsCol + (Row*MONTHS) + 1,Day),"Date").IsNull ()))?
- clRed:clBlack;
- }
- //---------------------------------------------------------------------------
-
-