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
|
procedure remplirGrille(Annee,Mois: integer);
var F : TextFile;
Ligne : String;
datedebut,datefin,DateGrille : TDateTime;
i,c,,Col,lapstemps : Integer;
aa,mm,jj : word;
begin
// initialiser la Grille
// recupérer denier jour du Mois
DateFin:=EndOfAMonth(Annee,Mois);
DecodeDate(DateFin,aa,mm,jj);
// cerise sur le gateau on peut tailler le stringGrid en fonction du nombre de jours
stringGrid1.Colcount:=jj+1;
StringGrid1.RowCount:=1+20; Ligne jours + 20 chambres
StringGrid1.Cells[0,0]:=formatdateTime('mmmm',DateFin);
StringGrid1.FixedCols:=1;
StringGrid1.FixedRows:=1;
// on peut même définir les largeurs de colonnes
StrinGrid1.DefaultColWidth:=30;
StringGrid1.ColWidths[0]:=80;
// Chambres
for i :=1 to 20 do
begin
StringGrid1.Cells[0,i]:=Format('Chambre %2d',[i]);
end;
// Jours
for i:=1 to jj do
begin
StrinGrid1.Cells[i,0]:=Format('%2d',[i]);
end;
// ouvrir Fichier Texte
AssignFile(F,nomFichier); // voir le nom du fichier
Reset(F);
While not EOF(F) do
begin
// lire la ligne
readln(F,ligne);
// parser la Ligne, cela dépendra du format que tu utilises CSV,Taille Fixe, etc....
// pour la suite je considère que tu a parser la ligne dans la structure indiquée dans le post #6
// Traiter les dates
DateDebut:=EncodeDate(StrToInt(addresainfo[1]),StrToInt(addresainfo[2]),strtoint(addresainfo[3]);
// au cas ou c'est une période 'à cheval'
if StrToInt(addresainfo[2])<Mois then DateDebut:=StartOfAMonth(annee,mois);
// au cas ou c'est une période 'à cheval'
DateFin:=EncodeDate(StrToInt(addresainfo[4]),StrToInt(addresainfo[5]),strtoint(addresainfo[6]);
if StrToInt(addresainfo[5])>Mois then DateDebut:=EndOfAMonth(Annee,Mois);
lapsTemps:=dateDiff(datedebut,dateFin);
for i:=0 to lapstemps do
begin
DateGrille:=IncDay(DateDebut,i);
Col:=DecodeDate(DateGrille,aa,mm,jj);
// Chercher chambre
for c:=1 to 20 do
begin
if addresaroom[c] then StringGrid1.Cells[Col,c]:='1'; // à voir si plus d'état
end;
end;
// fermer fichier
CloseFile(F);
end; |
Partager