unit Question2_U;

//Enter your exam number here

interface

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

type
  TfrmQuestion2 = class(TForm)
    pnlTables: TPanel;
    grpTblEmployees: TGroupBox;
    dbgPlayers: TDBGrid;
    grpTblPayments: TGroupBox;
    dbgGames: TDBGrid;
    pnlBtns: TPanel;
    bmbClose: TBitBtn;
    bmbRestoreDB: TBitBtn;
    pgcTabs: TPageControl;
    tbsQ2_1: TTabSheet;
    grpresults: TGroupBox;
    dbgSQL: TDBGrid;
    btnQ2_1_1: TButton;
    btnQ2_1_2: TButton;
    btnQ2_1_3: TButton;
    btnQ2_1_4: TButton;
    btnQ2_1_5: TButton;
    tbsQ2_2: TTabSheet;
    grpOutput: TGroupBox;
    redQ2: TRichEdit;
    btnQ2_2_1: TButton;
    btnQ2_2_2: TButton;
    spnQ2: TSpinEdit;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure bttExitClick(Sender: TObject);
       procedure btnStartClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure tbsDBResultsContextPopup(Sender: TObject; MousePos: TPoint;
      var Handled: Boolean);
    procedure btnQ2_1_1Click(Sender: TObject);
    procedure btnQ2_1_2Click(Sender: TObject);
    procedure btnQ2_1_5Click(Sender: TObject);
    procedure btnQ2_1_3Click(Sender: TObject);
    procedure btnQ2_1_4Click(Sender: TObject);
    procedure bmbRestoreDBClick(Sender: TObject);
    procedure btnQ2_2_2Click(Sender: TObject);
    procedure btnQ2_2_1Click(Sender: TObject);
  private
    { Private declarations }
    tblPlayers,tblTeamGames: TADOTable;
    dbConn: TConnection;
    sQlQry : string;

  public
    { Public declarations }
  end;

var
  frmQuestion2: TfrmQuestion2;

implementation

{$R *.dfm}


 { ===TABLE AND FIELDNAMES===
tblPlayers
              PlayerID,  FirstName,  LastName,  Country,  Team,  Age

tblTeamGames
                  GameID,  GameName,  Date,  WinnerID,  LoserID,  WinningTeamScore,  LosingTeamScore
 }

//--Question 2.1-----------------------------------------------------

procedure TfrmQuestion2.btnQ2_1_1Click(Sender: TObject);
begin

// Question 2.1.1

SQLQry := '';
  
// Don't change code below
dbConn.RunSQL(SQLQry ,dbgSQL);
end;

procedure TfrmQuestion2.btnQ2_1_2Click(Sender: TObject);
begin

// Question 2.1.2

SQLQry := '';

// Don't change code below
dbConn.RunSQL(SQLQry ,dbgSQL );
end;

procedure TfrmQuestion2.btnQ2_1_3Click(Sender: TObject);
var
 sTeam : string;
begin
//Provided code
sTeam := inputbox('Enter team','A or B or C ','A');

// Question 2.1.3

SQLQry :='';

// Don't change code below
dbConn.RunSQL(SQLQry ,dbgSQL);


end;

procedure TfrmQuestion2.btnQ2_1_4Click(Sender: TObject);
var
 Changed : boolean;
begin
// Question 2.1.4

SQLQry := '';

// Don't change code below
dbConn.ExecuteSQL(SQLQry,Changed);
if Changed then
   Messagedlg('File is updated',mtInformation,[mbok],0);
 dbconn.DisplayAll(dbgSQL);
end;

procedure TfrmQuestion2.btnQ2_1_5Click(Sender: TObject);
begin

// Question 2.1.5

SQLQry :=  '';
// Don't change code below
dbConn.RunSQL(SQLQry ,dbgSQL);
//dbconn.SetGridColumnWidths(dbgSQL);
//dbgSQL.Columns[5].Alignment := taRightJustify;
end;

//--Question 2.2-----------------------------------------------------
procedure TfrmQuestion2.btnQ2_2_1Click(Sender: TObject);
var ihelp : integer;
begin
//Question 2.2.1




end;

procedure TfrmQuestion2.btnQ2_2_2Click(Sender: TObject);
var
  sTeam : string;
  iteampoints : integer;
begin
//Provided code
tblPlayers.Sort := 'Team ASC';
redQ2.Clear;
sTeam := 'CyberSpartans';
iTeamPoints := 0;
 //================

//Question 2.2.2



//Provided code
redQ2.Lines.Add(' CyberSpartans points:  ' + inttostr(iTeamPoints))
end;



{$region 'Connection Region and Settings code - DO NOT CHANGE'}
procedure TfrmQuestion2.bmbRestoreDBClick(Sender: TObject);
begin
dbconn.RestoreDatabase;
  dbconn.SetGridColumnWidths(dbgPlayers );
  dbconn.SetGridColumnWidths(dbgGames );
  dbconn.DisplayAll(dbgSQL);
  dbconn.SetGridColumnWidths(dbgSQL );
end;

procedure TfrmQuestion2.btnStartClick(Sender: TObject);
begin
    pgcTabs.Visible := true;
end;

procedure TfrmQuestion2.bttExitClick(Sender: TObject);
begin
Close;
end;

procedure TfrmQuestion2.FormCreate(Sender: TObject);
begin
    pgcTabs.ActivePage := tbsQ2_1;
end;

procedure TfrmQuestion2.FormShow(Sender: TObject);
begin
  dbCONN := TConnection.Create;
  dbCONN.dbConnect;

  tblPlayers := dbCONN.tblOne;
  tblTeamGames := dbCONN.tblTwo;
  dbCONN.Gridsetup(dbgPlayers, dbgGames,dbgSQL);
  dbconn.SetGridColumnWidths(dbgPlayers );
  dbconn.SetGridColumnWidths(dbgGames );
  dbconn.DisplayAll(dbgSQL);
  dbconn.SetGridColumnWidths(dbgSQL );

  frmQuestion2.width := clientwidth;
  frmQuestion2.height := clientheight;
  frmQuestion2.WindowState := wsMaximized;

  pgcTabs.ActivePageIndex:= 0;
end;



procedure TfrmQuestion2.tbsDBResultsContextPopup(Sender: TObject;
  MousePos: TPoint; var Handled: Boolean);
begin

end;

{$endregion}
end.
