unit Question2TripleTTyresU;

interface

uses
  TTyreUnit, TConUnit,  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, Grids, DBGrids, ExtCtrls, Buttons,
  ComCtrls, DBCtrls, jpeg ;

type
  TfrmOOPQuestion = class(TForm)
    pnlMain: TPanel;
    dbgTyreStock: TDBGrid;
    Panel2: TPanel;
    DSADO_tblStock: TDataSource;
    BitBtn1: TBitBtn;
    Image1: TImage;
    DBNav: TDBNavigator;
    redOutput: TRichEdit;
    Label1: TLabel;
    btnHeavy: TButton;
    btnCountDunlop: TButton;
    ADOQuery1: TADOQuery;
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnHeavyClick(Sender: TObject);
    procedure btnCountDunlopClick(Sender: TObject);
    procedure DBNavClick(Sender: TObject; Button: TNavigateBtn);


  private
    { Private declarations }
    
  public
    { Public declarations }

    myConverterObj : TConverter;      // 1
    myTyreObj : TTyre;                // 1
  end;

var
  frmOOPQuestion: TfrmOOPQuestion;

implementation

{$R *.dfm}



procedure TfrmOOPQuestion.btnCountDunlopClick(Sender: TObject);
var
  iCount : Integer;     // 1
begin
{  ADOQuery1.Close;
  ADOQuery1.SQL.Text := 'select * from TyreStockDetails where brand = ''Dunlop''';
  ADOQuery1.Open;
  ShowMessage('There are ' + IntToStr(ADOQuery1.RecordCount) + ' different Dunlop tires');  // 1
}

  ADOQuery1.First;        // 1
  icount := 0;
  while not ADOQuery1.Eof do   // 1
    begin
      if (ADOQuery1.Fields.FieldByName('Brand').Text = 'Dunlop') then    // 1
        begin
            inc(iCount);   // 1
        end;
      ADOQuery1.Next;   // 1
    end;
   ShowMessage('There are ' + IntToStr(iCount) + ' different Dunlop tires');  // 1
end;

procedure TfrmOOPQuestion.btnHeavyClick(Sender: TObject);
begin
  ADOQuery1.Sort := 'weight DESC';   // 1
  ADOQuery1.First;
  ShowMessage('The heaviest Tyre is the ' +
               ADOQuery1.Fields.Fieldbyname('Brand').Text +
               '  ' +
               ADOQuery1.Fields.Fieldbyname('SizeCode').Text) ;     // 2


end;

procedure TfrmOOPQuestion.FormCreate(Sender: TObject);
begin
   myConverterObj := TConverter.create;   // 2
   myTyreObj := TTyre.create;             // 2

end;

procedure TfrmOOPQuestion.FormShow(Sender: TObject);
begin
   // Given Code
   DBNav.VisibleButtons := [nbFirst,nbPrior,nbNext,nbLast];
   dbgTyreStock.Columns[0].Width := 35;
   dbgTyreStock.Columns[1].Width := 80;
   dbgTyreStock.Columns[2].Width := 60;
   dbgTyreStock.Columns[4].Width := 60;
   dbgTyreStock.Columns[5].Width := 50;
   dbgTyreStock.Columns[6].Width := 40;
end;

procedure TfrmOOPQuestion.DBNavClick(Sender: TObject;
  Button: TNavigateBtn);
begin

// Given Code: Die kode wat hier volg plaas reeds die huidige rekord se info in
//die myTyreObj
  myTyreObj.setData( ADOQuery1.Fields.Fieldbyname('ID').text,
                     ADOQuery1.Fields.Fieldbyname('Brand').Text,
                     ADOQuery1.Fields.Fieldbyname('Model').Text,
                     ADOQuery1.Fields.Fieldbyname('SizeCode').Text,
                     ADOQuery1.Fields.Fieldbyname('Type').Text,
                     ADOQuery1.Fields.Fieldbyname('Diameter').AsFloat,
                     ADOQuery1.Fields.Fieldbyname('TW').AsFloat,
                     ADOQuery1.Fields.Fieldbyname('Weight').AsFloat,
                     ADOQuery1.Fields.Fieldbyname('WheelWidths').Text,
                     ADOQuery1.Fields.FieldByName('D').AsBoolean,
                     ADOQuery1.Fields.Fieldbyname('A').AsBoolean
                   );
// code after this line
// --------------------

redOutput.Lines.Clear;      // 1
redOutput.Lines.Add(myTyreObj.toStr);       // 1
redOutput.Lines.Add(myTyreObj.getTreadWearDesc);     // 1

redOutput.Lines.Add('Tire Width: (mm)  ' + FloatToStrF(myTyreObj.getTireWidth,ffFixed, 8,0));     // 2
redOutput.Lines.Add('Tire relative height: (mm)  ' + FloatToStrF(myTyreObj.getRelTireHeight, ffFixed, 8,0));  // 2

myConverterObj.setInchVal(ADOQuery1.Fields.Fieldbyname('Diameter').AsFloat);   // 2
redOutput.Lines.Add('Tire Rimsize: (cm)  ' + FloatToStrF(myConverterObj.getMillimetreVal/10,ffFixed, 8,0)); // 2

myConverterObj.setPoundsVal(ADOQuery1.Fields.Fieldbyname('Weight').AsFloat);   // 1
redOutput.Lines.Add('Tire Weight: (kg''s)  ' + FloatToStrF(myConverterObj.getKgVal,ffFixed, 8,1));  // 2

end;

end.


