unit uStart;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, mysql56conn, sqldb, FileUtil, Forms, Controls, Graphics,
Dialogs, StdCtrls, LazLogger, IniFiles, LCLTranslator, uZadavani, uKnihovna;
//LazLoggerDummy //zaměnit pro zákaz logování
type
{ TFormPrihlaseni }
TFormPrihlaseni = class(TForm)
btnKonec: TButton;
EditKod: TEdit;
Label1: TLabel;
MySQLConnection1: TMySQL56Connection;
Query: TSQLQuery;
SQLTransaction1: TSQLTransaction;
procedure btnKonecClick(Sender: TObject);
procedure EditKodEditingDone(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
const
C_DB_SECTION = 'DB-INFO';
var
FormPrihlaseni: TFormPrihlaseni;
jmeno, kod: string;
priorita: integer;
stationID: string;
mySqlQuery:String;
INI: TINIFile;
DBpassword, DBlocation, DBname,DBuser: string;
implementation
{$R *.lfm}
{ TFormPrihlaseni }
procedure TFormPrihlaseni.EditKodEditingDone(Sender: TObject);
begin
MySQLConnection1.Open;
if MySQLConnection1.Connected then
begin
Query.Database := MySQLConnection1;
SQLTransaction1.Database := MySQLConnection1;
Debugln('Connected to server: ' + MySQLConnection1.HostName);
Query.Close;
//Prepared statement:
Query.SQL.Text := 'Select * from Operator where kod = (:KOD)';
Query.Params.ParamByName('KOD').AsString := EditKod.Text;
Query.Open;
while not Query.EOF do
begin
(* DbgOut(Query.Fields[0].AsString);
DbgOut(Query.Fields[1].AsString);
DbgOut(Query.Fields[2].AsString);
DbgOut(Query.Fields[3].AsString);
DbgOut(Query.Fields[4].AsString);
Debugln(Query.Fields[5].AsString);
*)
Debugln('ID: ', Query.FieldByName('ID').AsString,
' Operator: ' + Query.FieldByName('Operator').AsString,
' Kod: ' + Query.FieldByName('Kod').AsString, ' Skupina: ' +
Query.FieldByName('Skupina').AsString);
kod := Query.FieldByName('Kod').AsString;
jmeno := Query.FieldByName('Operator').AsString;
priorita := Query.FieldByName('Priorita').AsInteger;
Query.Next;
Debugln('Konec dat uživatele');
end;
Query.Close;
end;
if kod = EditKod.Text then
begin
EditKod.Text :='';
EditKod.SetFocus;
//ShowMessage('Uživatel ověřen.');
FormZadavani := TFormZadavani.Create(nil);
FormZadavani.ShowModal;
FormZadavani.Free;
end
else
begin
//ShowMessage('Uživatel neověřen.');
Query.Close;
Close;
end;
end;
procedure TFormPrihlaseni.btnKonecClick(Sender: TObject);
begin
close;
end;
procedure TFormPrihlaseni.FormActivate(Sender: TObject);
begin
SetDefaultLang('cs');
//ShowMessage(GetDefaultLang);
stationID := GetEnvironmentVariable('COMPUTERNAME') + ' ' +
GetEnvironmentVariable('USERNAME');
Debugln('*** Start programu: ' + stationID);
// Create the object, specifying the the ini file that contains the settings
INI := TINIFile.Create('DMySQL.ini');
// Put reading the INI file inside a try/finally block to prevent memory leaks
try
// reading values from the INI file.
DBuser := INI.ReadString(C_DB_SECTION, 'DBuser', '');
DBpassword := INI.ReadString(C_DB_SECTION, 'DBpassword', '');
DBlocation := INI.ReadString(C_DB_SECTION, 'DBlocation', '');
DBname := INI.ReadString(C_DB_SECTION, 'DBname', '');
finally
// After the ini file was used it must be freed to prevent memory leaks.
INI.Free;
end;
Debugln(DBuser + ' ' + DBpassword + ' ' + DBlocation+' ' + DBname);
DBpassword := Chrtran(DBpassword, '90m7n8o4pqr1stefgh0ijklu23vwx6yzab5cd',
'6ab903d1efg8h2ijklm7nop4qrstu5v0wxyz');
ShowMessage(DBuser + ' ' + DBpassword + ' ' + DBlocation+' ' + DBname);
MySQLConnection1.HostName := DBlocation;
MySQLConnection1.UserName := DBuser;
MySQLConnection1.Password := DBpassword;
MySQLConnection1.DatabaseName := DBname;
MySQLConnection1.Transaction := SQLTransaction1;
Debugln('*** Přihlášení ' + RRRRMMDD(now));
MySQLConnection1.Open;
if MySQLConnection1.Connected then
begin
Query.Database := MySQLConnection1;
SQLTransaction1.Database := MySQLConnection1;
Query.Close;
//Prepared statement:
Query.SQL.Text := 'Select * from bezi where jmenopoc = (:JMENOPOC)';
Query.Params.ParamByName('JMENOPOC').AsString := stationID;
Query.Open;
while not Query.EOF do
begin
Query.Next;
end;
if stationID = Query.FieldByName('JMENOPOC').AsString then
begin
mySQLQuery := 'update bezi set ZACATEK=''' + RRRRMMDD(Now) + ''', BEZI = "A" WHERE JMENOPOC = '''+ stationID +'''';
//SQLTransaction1.StartTransaction;
MySQLConnection1.ExecuteDirect(mySQLQuery);
SQLTransaction1.Commit;
end
else
begin
mySQLQuery :=
'insert into bezi (ID,JMENOPOC,ZACATEK,BEZI)' +
' values(0,''' + stationID +''' , ''' + RRRRMMDD(Now) + ''' , "A" )' ;
MySQLConnection1.ExecuteDirect(mySQLQuery);
SQLTransaction1.Commit;
end;
Query.Close;
end;
end;
procedure TFormPrihlaseni.FormDestroy(Sender: TObject);
begin
Query.Close;
//Prepared statement:
Query.SQL.Text := 'Select * from bezi where jmenopoc = (:JMENOPOC)';
Query.Params.ParamByName('JMENOPOC').AsString := stationID;
Query.Open;
while not Query.EOF do
begin
Query.Next;
end;
if stationID = Query.FieldByName('JMENOPOC').AsString then
begin
mySQLQuery := 'update bezi set ZACATEK=''' + RRRRMMDD(Now) + ''', BEZI = "N" WHERE JMENOPOC = '''+ stationID +'''';
//SQLTransaction1.StartTransaction;
MySQLConnection1.ExecuteDirect(mySQLQuery);
SQLTransaction1.Commit;
end;
Query.Close;
end;
end.