1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
//-------------------------------------------------------------------------
#include <vcl.h>
#include <vcl\printers.hpp>
#include <Printers.hpp>
#pragma hdrstop
#include "Tournoi.h"
#include "APropos.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//Variable de type entier pour prototypage
int Nb_Joueur;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
MasqueJoueur1->Lines->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ProgrammeClick(TObject *Sender)
{
//Variable d'itération boucle de comptage
int i, j, cpt;
int CptSolution = 1;
AnsiString Message4=("Non autorisé");
//Variable de type caractère MasqueJoueur1
AnsiString Cpti;
//Variable de type caractère MasqueJoueur2
AnsiString Cptj;
//Variable de type caractère séparateur données
AnsiString Separateur1="Joueur N°";
AnsiString Separateur2=" rencontre Joueur N°";
//Effacement zone d'affichage
MasqueJoueur1->Lines->Clear();
Nb_Solution->Caption=" ";
//Variable cpt et j initialisée à 1
cpt = 1;
j=1;
//Transtypage Chaîne caractère en Entier */
Nb_Joueur = StrToInt(Saisie->Text);
if(Saisie->Text=="")
{
ShowMessage(Message4);
}
else
{
try
{
for(i=1;i<=Nb_Joueur;i++)
{
if(i==cpt)
{
cpt=cpt+1;
}
for(j=cpt;j<=Nb_Joueur;j++)
{
Cpti = IntToStr(i);
Cptj = IntToStr(j);
MasqueJoueur1->Lines->Add(Separateur1+Cpti+Separateur2+Cptj);
MasqueJoueur1->Lines->SaveToFile("Tournoi.txt");
//Mise en place compteur de Nbr de solution avec son affichage
CptSolution = CptSolution + 1;
AnsiString Solution = IntToStr(CptSolution-1);
Nb_Solution->Caption = Solution;
}
}
}
catch(Exception& err)
{
ShowMessage(err.Message);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Configurationdelimpression1Click(TObject *Sender)
{
PrinterSetupDialog1->Execute();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Quitter1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Ouvrir1Click(TObject *Sender)
{
if(OpenDialog1->Execute())
{
if(MasqueJoueur1->Lines->Count>0) MasqueJoueur1->Clear();
MasqueJoueur1->Lines->LoadFromFile(OpenDialog1->FileName);
SaveDialog1->FileName = OpenDialog1->FileName;
OpenDialog1->Filter = "Fichiers texte (*.txt)";
OpenDialog1->FileName;
}
}
//----------------------------------------------------------------------------
void PrintFooter(TRect& rect, int lineHeight)
{
//Création du numéro de page. La méthode DrawText()
//requiert un paramètre char* (et non un objet String).
char buff[10];
wsprintf(buff, "Page %d", Printer()->PageNumber);
//Définition du pied de page
// Ajout de deux lignes.
rect.Top = Printer()->PageHeight -(lineHeight *2);
rect.bottom = rect.Top + lineHeight;
//Centrage du texte.
DrawText(Printer()->Handle, buff, -1, (RECT*)&rect, DT_CENTER);
//Traçage d'unr ligne au-dessus du numéro de page.
Printer()->Canvas->MoveTo(0,rect.top -2);
Printer()->Canvas->LineTo(rect.Right, rect.Top -2);
}
//-------------------------------------------------------------------------
void __fastcall TForm1::Imprimer1Click(TObject *Sender)
{
//Définition de la boite de dialogue Imprimer.
if(PrintDialog1->Execute())
{
Printer()->Title = " GESTION TOURNOI - " + OpenDialog1->FileName;
//Affectation de la police de l'objet à l'imprimante.
Printer()->Canvas->Font = MasqueJoueur1->Font;
//Calcul de la hauteur de ligne. On tient compte de la taille de la police
//et de la résolution de l'imprimante.
//Appel de la fonction abs(), le résultat pouvant être négatif.
//On augmente cette valeur de 40% pour l'en tête de page.
int lineHeight = abs(MulDiv(Printer()->Canvas->Font->Size,
GetDeviceCaps(Printer()->Handle, LOGPIXELSY), 72));
lineHeight *=1.4;
//Calcul du nombre de lignes par page.
//Trois lignes sont réservées au pied de page.
int linesPerPage = (Printer()->PageHeight/lineHeight) - 4;
//L'impression commence à la ligne 4, et non à la ligne 0
//ce qui permet de définir un en tête de page.
int lineCount = 4;
//Envoi de la commande d'impression à Windows.
Printer()->BeginDoc();
TRect rect;
rect.Top = lineHeight;
rect.left = 40;
rect.Right = Printer()->PageWidth;
rect.Bottom = lineHeight *2;
DrawText(Printer()->Handle, OpenDialog1->FileName.c_str(),1,
(RECT*)&rect,DT_CENTER);
//Traitement iétarif des lignes.
for(int i=0;i<MasqueJoueur1->Lines->Count;i++)
{
//Le pied de page est atteint, éjection de la page, impression
//d'une nouvelle page.
if(lineCount++==linesPerPage)
{
PrintFooter(rect, lineHeight);
lineCount =4;
Printer()->NewPage();
}
//Extraction de la chaîne suivante et impression à l'aide de TextOut()
String s = MasqueJoueur1->Lines->Strings[i];
Printer()->Canvas->TextOut(0, lineCount * lineHeight,s);
}
// Ce qui donne...
PrintFooter(rect, lineHeight);
Printer()->EndDoc();
}
}
//-------------------------------------------------------------------------
void __fastcall TForm1::QuitterClick(TObject *Sender)
{
Close();
}
//------------------------------------------------------------------------
void __fastcall TForm1::AproposClick(TObject *Sender)
{
AboutBox->Left = 264;
AboutBox->Top = 287;
AboutBox->ShowModal();
}
//-------------------------------------------------------------------------
void __fastcall TForm1::SaisieClick(TObject *Sender)
{
//Saisie->Text->Clear();
}
//------------------------------------------------------------------------- |
Partager