unit UStatsRepartEssais;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons, Grids;

type
  TStatsRepartEssaisDLGForm = class(TForm)
    Panel1: TPanel;
    BitBtn1: TBitBtn;
    StatsRepartEssaisALPHATimer: TTimer;
    StatStringGrid: TStringGrid;
    SpeedButton1: TSpeedButton;
    procedure StatsRepartEssaisALPHATimerTimer(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure StatStringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure FormResize(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
	private
		{ Déclarations privées }
	public
		{ Déclarations publiques }
		procedure refreshStat;
  end;

var
  StatsRepartEssaisDLGForm: TStatsRepartEssaisDLGForm;

implementation

uses UDocometre;

{$R *.dfm}

procedure TStatsRepartEssaisDLGForm.refreshStat;
var i,j,m,n : integer;
begin
  StatStringGrid.RowCount := 1;
  StatStringGrid.Cells[0,0] := 'Nom Séquence type';
	StatStringGrid.Cells[1,0] := 'Nombre d''occurences';
  StatStringGrid.DefaultColWidth := (StatStringGrid.Width div 2) - 2;
  n := DocoForm.OrgaFrame.SelectedSessionRow - 1 ;
	for i := 0 to DocDOCOMETRE.ST.Count - 1 do
  begin
    m := 0;
    for j := 0 to DocDOCOMETRE.SESSIONS[n].ESSAIS.Count - 1 do
		begin
      if DocDOCOMETRE.SESSIONS[n].ESSAIS[j].NOMST = DocDOCOMETRE.ST[i].NOM
      then inc(m);
		end;
    StatStringGrid.RowCount := StatStringGrid.RowCount + 1;
    StatStringGrid.Cells[0,StatStringGrid.RowCount - 1] := DocDOCOMETRE.ST[i].NOM;
		StatStringGrid.Cells[1,StatStringGrid.RowCount - 1] := inttostr(m);
  end;
end;

procedure TStatsRepartEssaisDLGForm.StatsRepartEssaisALPHATimerTimer(
  Sender: TObject);
begin
   if ALphaBlendValue < 240
  then ALphaBlendValue := ALphaBlendValue + 40
  else begin
    ALphaBlendValue := 255;
    StatsRepartEssaisALPHATimer.Enabled := false;
  end;
end;

procedure TStatsRepartEssaisDLGForm.FormShow(Sender: TObject);
begin
  ALphaBlendValue := 0;
	StatsRepartEssaisALPHATimer.Enabled := true;
	refreshStat;
end;

procedure TStatsRepartEssaisDLGForm.StatStringGridDrawCell(Sender: TObject;
  ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  with (Sender as TStringGrid) do
  begin
    Canvas.Brush.Color := clWhite;
    if ARow > 0 then
    begin
      if (ARow mod 2) = 0 then Canvas.Brush.Color := $DDEEFF;
    end else Canvas.Brush.Color := clBtnFace;
    Canvas.FillRect(Rect);
    DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
                DT_CENTER or DT_VCENTER or DT_SINGLELINE	 );
  end;
end;

procedure TStatsRepartEssaisDLGForm.FormResize(Sender: TObject);
begin
  StatStringGrid.DefaultColWidth := (StatStringGrid.Width div 2) - 5;
end;

procedure TStatsRepartEssaisDLGForm.SpeedButton1Click(Sender: TObject);
begin
  refreshStat;
end;

procedure TStatsRepartEssaisDLGForm.BitBtn1Click(Sender: TObject);
begin
  hide;
end;

end.
