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 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
| unit Essai;
interface
uses
{ Composant TXStringGrid :
Authors: Michael Dürig (md)
http://www.vclcomponents.com/Delphi/Grids/XStringrid-info.html}
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
XStringGrid, Grids,extctrls, StdCtrls;
type
TForm1 = class(TForm)
Planning: TXStringGrid; //Authors: Michael Dürig (md)
ComboCellEditor1: TComboCellEditor; //Authors: Michael Dürig (md)
procedure PlanningDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure ScrollGrille(Grid:TStringGrid);
procedure PlanningTopLeftChanged(Sender: TObject);
procedure EffacerFirstCol(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
Scroll,NbreLigne,FirstLigne,NbreRect:Integer;
end;
var
Form1: TForm1;
Madate:tDatetime;
implementation
uses MergedForumDevelopper;
{$R *.DFM}
procedure TForm1.PlanningTopLeftChanged(Sender: TObject);
begin
Scroll:=(Sender as TStringGrid).topRow-2;
ScrollGrille(planning);
end;
procedure TForm1.ScrollGrille(Grid:TStringGrid);
var
rect,Rect1 : trect;
OldBrushColor:Tcolor;
OldPenColor:Tcolor;
OldFontSize:Integer;
OldFontName:String;
NumRect,ValScroll:integer;
begin
//Initialisations diverses
Rect := Bounds(0,0,0,0);
OldBrushColor:=Grid.Canvas.Brush.color;
OldPenColor:=Grid.Canvas.pen.color;
OldFontName:=Grid.Canvas.Font.name;
OldFontSize:=Grid.Canvas.font.Size;
EffacerFirstCol(self);
for NumRect:=0 to NbreRect-1 do
begin
// Premier rectangle pas de scroll
if NumRect=0 then
ValScroll:=0
else
ValScroll:=Scroll;
// si Premiere ligne du rectangle appartient au titre de la colonne 0
if Grid.topRow>NbreLigne*Numrect+2 then
Rect1.Top := 2*Grid.defaultRowHeight+2-
Grid.defaultRowHeight+Grid.RowHeights[0]-
Grid.defaultRowHeight+grid.RowHeights[1]
else
Rect1.Top := Grid.CellRect(0,Grid.TopRow+NbreLigne*NumRect-
ValScroll).top;
//
Rect1.Left := 0;
Rect1.Right := Grid.CellRect(0,(NumRect+1)*NbreLigne+1).Right;
Rect1.Bottom := Grid.CellRect(0,(NumRect+1)*NbreLigne+1).Bottom;
//
Grid.canvas.FillRect(Rect1);
Grid.canvas.brush.Color:=$0080FFFF;
Canvas.Pen.Color := clSilver;
Grid.canvas.FillRect(Rect1);
if (Rect1.bottom-Grid.defaultRowHeight)<0 then
begin
// Le bloc qui suit pour imiter le "look" par défaut
if Grid.GridLineWidth = 1 then
begin
Canvas.brush.Color:=clwindow;
Grid.canvas.Pen.Color := clblack;
Grid.canvas.Pen.Width := 1;
Grid.canvas.Rectangle(Rect1.Left-1,Rect1.Top-1,Rect1.Right,
Rect1.Bottom+1);
end;
end;
Frame3D(Grid.Canvas, Rect1, clBtnHighlight, clBtnShadow, 1);
InflateRect(Rect1,-2,-2);
Grid.Canvas.font.Color:=clblack;
DrawText(Grid.Canvas.Handle, PChar(Grid.Cells[0,(NumRect*NbreLigne+
2)]),-1, Rect1 ,DT_CENTER or DT_NOPREFIX or DT_VCENTER or
DT_SINGLELINE );
end;
Planning.Canvas.Pen.Color:=clBlack;
//
Rect:=Planning.CellRect(0,Planning.topRow);
Planning.Canvas.MoveTo(rect.left,rect.top-1);
Planning.Canvas.LineTo(Planning.FixedCols*
(Rect.left+Planning.defaultColWidth+1),(rect.top-1));
Grid.Canvas.Brush.color:=OldBrushColor;
Grid.Canvas.pen.color:=OldpenColor;
Grid.Canvas.Font.name:=OldFontName;
Grid.Canvas.font.Size:=OldFontSize;
//
end;
procedure TForm1.PlanningDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
Grid:TXStringGrid;
Cell3D:Boolean;
OldFontSize:Integer;
OldFontName:String;
OldBrushColor:Tcolor;
begin
Grid:=(sender as TXstringGrid);
OldBrushColor:=grid.Canvas.Brush.color;
OldFontSize:=Grid.canvas.font.size;
OldFontName:= Grid.canvas.font.name;
begin
if (
(not MergedCells(Grid,Acol,Arow,0,0,0,1,State,clBtnFace,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE,Cell3D=True)) and // EQUIPE
(not MergedCells(Grid,Acol,Arow,1,0,2,1,State,clBtnFace,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE,Cell3D=True)) and // Agent
(not mergedCells(Grid,Acol,Arow,3,0,5,0,State,clBtnFace,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE,Cell3D=True)) and // compteurs
(not mergedCells(Grid,Acol,Arow,3,1,3,1,State,clBtnFace,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE,Cell3D=True)) and
(not mergedCells(Grid,Acol,Arow,4,1,4,1,State,clBtnFace,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE,Cell3D=True)) and
(not mergedCells(Grid,Acol,Arow,5,1,5,1,State,clBtnFace,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE,Cell3D=True))
) then
begin
If (acol<Grid.Fixedcols) then
begin
Grid.Canvas.brush.Color:=clwindow;
Grid.Canvas.Pen.Color := clSilver;
Grid.Canvas.Pen.Width := 1;
Grid.Canvas.Rectangle(Rect.Left-1,Rect.Top-1,Rect.Right+1,
Rect.Bottom+1);
DrawText(Grid.canvas.Handle, PChar(grid.Cells[ACol,ARow]),-1,
Rect ,DT_CENTER or DT_NOPREFIX or DT_VCENTER or
DT_SINGLELINE );
end
else
if (arow in [0..1]) and (acol in [6..Grid.colCount-1]) then
drawtext(Grid.canvas.Handle,pchar(grid.cells[aCol,aRow]),-1,rect,DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE )
else
// Formatage donnée saisie dans la grille
if (arow in [2..Grid.RowCount-1]) and (acol in [6..Grid.colCount-1]) then
begin
Grid.canvas.font.Name:='Microsoft Sans Serif';
grid.canvas.font.size:=8;
Grid.Canvas.font.Color:=clred;
drawtext(Grid.canvas.Handle,pchar(grid.cells[aCol,aRow]),-1,rect,DT_CENTER or DT_WORDBREAK);
end;
end;
end;
grid.Canvas.Brush.Color:=OldBrushColor;
Grid.canvas.font.name:=OldFontName;
Grid.canvas.font.size:=OldFontSize;
ScrollGrille(Planning);
end;
procedure TForm1.EffacerFirstCol(Sender: TObject);
var
x:integer;
rect:trect;
begin
for x:=2 to planning.RowCount-1 do
begin
Rect.Left :=Planning.CellRect(0,x).Left;
Rect.Top := Planning.CellRect(0,x).top;
Rect.Right := Planning.CellRect(0,x).Right;
Rect.Bottom := Planning.CellRect(0,x).Bottom;
Planning.canvas.FillRect(Rect);
if Planning.GridLineWidth = 1 then
begin
Planning.Canvas.brush.Color:=ClWindow;
Planning.canvas.Pen.Color := ClSilver;
Planning.canvas.Pen.Width := 1;
Planning.canvas.Rectangle(Rect.Left-1,Rect.Top-1,Rect.Right,Rect.Bottom+1);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
x,y:integer;
begin
MaDate:=now;
planning.RowHeights[0]:=15;
planning.RowHeights[1]:=20;
Planning.Cells[0,0]:='EQUIPE';
Planning.Cells[1,0]:='AGENTS' ;
Planning.Cells[3,0]:='Compteurs';
Planning.Cells[3,1]:='C';
Planning.Cells[4,1]:='RP';
Planning.Cells[5,1]:='RQ';
planning.cells[0,2]:='VAC 1';
planning.cells[0,6]:='VAC 2';
planning.cells[0,10]:='VAC 3';
planning.cells[0,14]:='VAC 4';
for x:=0 to 30 do
if (x mod 2)=0 then
planning.cells[2,x+2]:='TOTO '+inttostr(x);
for x:=0 to planning.colCount-1 do
begin
planning.Cells[x+Planning.FixedCols,0]:=UpperCase((FormatDateTime('ddd',maDate+x)));
planning.Cells[x+Planning.FixedCols,1]:=UpperCase(FormatDateTime('dd',maDate+x));
end;
// remplacant / Titulaires
for y:=1 to 25 do
if (y mod 2)=0 then
planning.cells[1,y]:='T'
else
planning.cells[1,y]:='R' ;
// hauteur des cellule fusionnées première colonne
NbreLigne:=4;
// nombre de boite à afficher
NbreRect:=3;//
Scroll:=0;// init du scroll
end;
end. |
Partager