unit Vraag1_UXXXX;

  {PROPOSED SOLUTION}

interface

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

type
  TfrmVraagEen = class(TForm)
    qryEen: TADOQuery;
    dsrEen: TDataSource;
    grdEen: TDBGrid;
    Panel2: TPanel;
    btnB: TButton;
    btnE: TButton;
    btnA: TButton;
    btnD: TButton;
    btnF: TButton;
    bmbSluitAf: TBitBtn;
    btnC: TButton;
    btnG: TButton;

    procedure btnAClick(Sender: TObject);
    procedure btnBClick(Sender: TObject);
    procedure btnCClick(Sender: TObject);
    procedure btnDClick(Sender: TObject);
    procedure btnEClick(Sender: TObject);
    procedure btnFClick(Sender: TObject);
    procedure btnGClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmVraagEen: TfrmVraagEen;

implementation

{$R *.dfm}


procedure TfrmVraagEen.btnAClick(Sender: TObject);
begin
  qryEen.Active := False;
  qryEen.SQL.Text :=  'SELECT SkoolNaam, Kategorie, Balans, LaasteBetaling ' +
                       'FROM tblSkole ORDER BY Kategorie, LaasteBetaling';
  qryEen.Active := True;
end;

procedure TfrmVraagEen.btnBClick(Sender: TObject);
begin
  qryEen.Active := False;
  qryEen.SQL.Text :=  'SELECT SkoolNaam, Balans, LaasteBetaling FROM tblSkole ' +
                     'WHERE (Balans > 0) AND (#2011/11/25#-LaasteBetaling >60)';
//     'WHERE (Balans > 0) AND (DateDiff("d",[LaasteBetaling],"2011/11/25")>60)';
  qryEen.Active := True;
end;

procedure TfrmVraagEen.btnCClick(Sender: TObject);
begin
  qryEen.Active := False;
  qryEen.SQL.Text :=  'SELECT Beampte, Count(AantekenTyd) AS [Spitsure] ' +
                       'FROM tblOproepe ' +
                       'WHERE (HOUR(AantekenTyd) Between 15 and 24)  ' +
                       'GROUP BY Beampte';
  qryEen.Active := True;
end;

procedure TfrmVraagEen.btnDClick(Sender: TObject);
begin
  qryEen.Active := False;
  qryEen.SQL.Text :=  'SELECT SkoolNaam, Rede , ' +
                       'Count(AantekenDatum) AS [Getal besoeke] ' +
                       'FROM tblSkole, tblOproepe  ' +
                  'WHERE (tblSkole.SkoolNommer = tblOproepe.SkoolNommer) ' +
                       ' AND (Year(AantekenDatum) = 2011)   ' +
                       'Group by SkoolNaam, Rede ';
  qryEen.Active := True;
end;

procedure TfrmVraagEen.btnEClick(Sender: TObject);
begin
  qryEen.Active := False;
  qryEen.SQL.Text :=  'SELECT '+
                       'Format(SUM(Paaiemente),"Currency") AS [Totale bedrag],  ' +
                       'Format(AVG(Balans),"Currency") AS [Gemiddelde bedrag] ' +
                       'FROM tblSkole ' +
                       'WHERE (Kategorie = "S")';
 qryEen.Active := True;
 grdEen.Columns[0].Width := 100;
end;

procedure TfrmVraagEen.btnFClick(Sender: TObject);
begin
  qryEen.Active := False;
  qryEen.SQL.Text :=  'UPDATE tblSkole  ' +
                       'SET Balans = Balans - Paaiemente, LaasteBetaling = #25/11/2011# ' +
                       'WHERE Kategorie = "P" ';
  qryEen.ExecSQL;
  MessageDlg('Rekords Suksesvol Verwerk',mtInformation,[mbok],0);

end;

procedure TfrmVraagEen.btnGClick(Sender: TObject);
begin
  qryEen.Active := False;
  qryEen.SQL.Text :=  'DELETE FROM tblOproepe ' +
                       'WHERE Year(AantekenDatum) = 2010';
  qryEen.ExecSQL;
  MessageDlg('Rekords Suksesvol Verwerk',mtInformation,[mbok],0);

end;

end.
