unit referee_licentiesinfo;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
DbCtrls, sqldb, db;
type
{ TForm_Licentie_Info }
TForm_Licentie_Info = class(TForm)
BT_LicentieCancel: TButton;
BT_LicentieOk: TButton;
BT_LicentieUpdate: TButton;
DB_LicentieID: TDBEdit;
DB_Licentie: TDBEdit;
DB_LicentieUitleg: TDBEdit;
DS_Licenties: TDataSource;
GroupBox_Supervisor: TGroupBox;
GroupBox_SupervisorActie: TGroupBox;
lbl_Licentie: TLabel;
lbl_Discription: TLabel;
TQ_Licenties: TSQLQuery;
procedure BT_LicentieCancelClick(Sender: TObject);
procedure BT_LicentieOkClick(Sender: TObject);
procedure BT_LicentieUpdateClick(Sender: TObject);
procedure DS_LicentiesStateChange(Sender: TObject);
private
{ private declarations }
procedure UpdateLicentie;
public
{ public declarations }
procedure ShowLicentie(ID: integer);
end;
var
Form_Licentie_Info: TForm_Licentie_Info;
implementation
uses referee_funkties, referee_informatie, referee_meldingen, referee_types;
{$R *.lfm}
{ TForm_Licentie_Info }
procedure TForm_Licentie_Info.BT_LicentieCancelClick(Sender: TObject);
begin
Close;
end; // BT_LicentieCancelClick
procedure TForm_Licentie_Info.BT_LicentieOkClick(Sender: TObject);
begin
if (DB_Licentie.Text='') or (DB_LicentieUitleg.Text = '') then begin
Form_Message.MsgWindow(mStop, bOK, 'The field License and/or Discription is/are empty !!' + chr(13)+chr(10)+chr(13)+chr(10)+
'Please make sure that' + chr(13)+chr(10)+ 'this are filled !!', PrgNaam);
Exit;
end;
UpdateLicentie;
Close;
end; // BT_LicentieOkClick
procedure TForm_Licentie_Info.BT_LicentieUpdateClick(Sender: TObject);
begin
if (DB_Licentie.Text='') or (DB_LicentieUitleg.Text = '') then begin
Form_Message.MsgWindow(mStop, bOK, 'The field License and/or Discription is/are empty !!' + chr(13)+chr(10)+chr(13)+chr(10)+
'Please make sure that' + chr(13)+chr(10)+ 'this are filled !!', PrgNaam);
Exit;
end;
UpdateLicentie;
end; // BT_LicentieUpdateClick
procedure TForm_Licentie_Info.DS_LicentiesStateChange(Sender: TObject);
begin
// we veranderen de status van de knoppen om alleen opslaan mogelijk
// te maken bij insert of edit status
BT_LicentieUpdate.Enabled := DS_Licenties.State in [dsEdit, dsInsert];
BT_LicentieCancel.Enabled := True; // cancel mag altijd
// Toch altijd de OK-knop. Meer intiutief
BT_LicentieOk.Enabled := true;
BT_LicentieOk.Caption := 'Close';
if DS_Licenties.State in [dsEdit, dsInsert] then
BT_LicentieOk.Caption := 'OK + Close';
end; // DS_LicentiesStateChange
procedure TForm_Licentie_Info.ShowLicentie(ID: integer);
var cSQL: string;
MaxID: integer;
begin
TQ_Licenties.Active := false; // maar ze zouden al gesloten moeten zijn
// cSQL := 'SELECT * FROM tbl_Licenties_Keuze WHERE Licentie_ID = :Licentie_ID;';
cSQL := 'SELECT * FROM tbl_Licenties_Keuze WHERE Licentie_ID = ' + IntToStr(ID) + ';';
TQ_Licenties.DataBase := Form_Information.Connect_RefereeDB;
TQ_Licenties.SQL.Text := cSQL;
// TQ_Licenties.ParamByName('Licentie_ID').AsInteger := ID; // dit is mooier
//TQ_Licenties.Active:=True;
If ID <> 0 then
begin
TQ_Licenties.Open;
TQ_Licenties.Edit; // niet doen want hij staat reeds op AutoEdit, wel zo mooi
// toch even edit gedaan omdat die autoedit niet lekker werkt ????
end
else begin
TQ_Licenties.Open;
TQ_Licenties.Insert; // wel altijd direct een insert
MaxID := StrToIntDef(MLookup('MAX(Licentie_ID)','tbl_Licenties_Keuze','1=1'), 0);
MaxID := MaxID + 1;
TQ_Licenties.FieldByName('Licentie_ID').AsInteger := MaxID;
TQ_Licenties.FieldByName('Licentie').AsString := '';
TQ_Licenties.FieldByName('Licentie_Uitleg').AsString := '';
end; // if
ShowModal;
end; // ShowLicentie
//------------------------------------------------------------------------------
// Sla de gegevens van de supervisore divisie op.
//------------------------------------------------------------------------------
procedure TForm_Licentie_Info.UpdateLicentie;
begin
//Sla het op in de tabel
if TQ_Licenties.State in [dsEdit, dsInsert] then begin
TQ_Licenties.Post;
TQ_Licenties.ApplyUpdates; // <==-- ERROR !!!
if Form_Information.Trans_RefereeDB.Active then
Form_Information.Trans_RefereeDB.CommitRetaining;
end; // if
end; // UpdateLicentie
end.