unit Unit1; interface uses Windows,SysUtils, Variants, Classes, Forms,WinSock, Dialogs, DB, ADODB,StdCtrls,Messages, ExtCtrls; type TForm1 = class(TForm) boston: TADOConnection; qryinsert: TADOQuery; timer: TTimer; procedure FormCreate(Sender: TObject); procedure timerTimer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} // 0.0.4 // 27-02-2014 function GetCurrentUserName: string; const cnMaxUserNameLen = 254; var sUserName: string; dwUserNameLen: DWORD; begin dwUserNameLen := cnMaxUserNameLen - 1; SetLength(sUserName, cnMaxUserNameLen); GetUserName(PChar(sUserName), dwUserNameLen); SetLength(sUserName, dwUserNameLen); Result := string(sUserName); end; function GetCurrentComputerName: string; const cnMaxComputerNameLen = 254; var sComputerName: string; dwComputerNameLen: DWORD; begin dwComputerNameLen := cnMaxComputerNameLen - 1; SetLength(sComputerName, cnMaxComputerNameLen); GetComputerName(PChar(sComputerName), dwComputerNameLen); SetLength(sComputerName, dwComputerNameLen); Result := string(sComputerName); end; function GetLocalIP: String; const WSVer = $101; var wsaData: TWSAData; P: PHostEnt; Buf: array [0..127] of Char; begin Result := ''; if WSAStartup(WSVer, wsaData) = 0 then begin if GetHostName(@Buf, 128) = 0 then begin P := GetHostByName(@Buf); if P <> nil then Result := iNet_ntoa(PInAddr(p^.h_addr_list^)^); end; WSACleanup; end; end; procedure TForm1.FormCreate(Sender: TObject); begin try qryinsert.SQL.Text := 'begin TRANSACTION insertdata' +#13#10 + 'insert into [supervisor].[user].[info_host](host,login,last_ip) values (:host,:login,:ip)'+#13#10 + 'COMMIT TRANSACTION insertdata'; qryinsert.Parameters.ParamByname('login').Value:= GetCurrentUserName ; qryinsert.Parameters.ParamByname('host').Value:= GetCurrentComputerName ; qryinsert.Parameters.ParamByname('ip').Value:= GetLocalIP ; qryinsert.ExecSQL; timer.Enabled:=True; form1.timer.Interval:=1500; except Application.Terminate; end end; procedure TForm1.timerTimer(Sender: TObject); begin ExitProcess(0); end; end.
/* , ----------------------------------------------------------- host - login - last_ip - ip createdate - createdate_unix - unix , ------------------------------------------------------------ */ CREATE TABLE [user].[info_host]( [id] [int] IDENTITY(1,1) NOT NULL, [host] [nvarchar](128) NULL, [login] [nvarchar](128) NULL, [createdate] [datetime] NOT NULL, [createdate_unix] [int] NOT NULL, [last_ip] [nvarchar](20) NULL ) ON [supervisor] GO ALTER TABLE [user].[info_host] ADD DEFAULT (getdate()) FOR [createdate] GO ALTER TABLE [user].[info_host] ADD DEFAULT (datediff(second,'1970-01-01 00:00:00',getutcdate())) FOR [createdate_unix]
/* , . ------------------------------------------------------------ login - displayName - displayname createdate - createdate_unix - unix , ------------------------------------------------------------ */ CREATE TABLE [user].[info_login_card]( [id] [int] IDENTITY(1,1) NOT NULL, [login] [nvarchar](128) NULL, [createdate] [datetime] NOT NULL, [createdate_unix] [int] NOT NULL, [displayName] [nvarchar](256) NULL ) ON [supervisor] GO ALTER TABLE [user].[info_login_card] ADD DEFAULT (getdate()) FOR [createdate] GO ALTER TABLE [user].[info_login_card] ADD DEFAULT (datediff(second,'1970-01-01 00:00:00',getutcdate())) FOR [createdate_unix] GO
set rowcount $limit SELECT a.[id] ,a.[host] ,a.[login] ,a.[createdate] ,a.[createdate_unix] ,a.[last_ip] ,b.[displayName] FROM [user].[info_host] a left join [user].[info_login_card] b on a.login = b.login where b.displayName like ('$ihostlogin') order by a.[createdate_unix] desc set rowcount 0
set rowcount $limit SELECT a.[id] ,a.[host] ,a.[login] ,a.[createdate] ,a.[createdate_unix] ,a.[last_ip] ,b.[displayName] FROM [user].[info_host] a left join [user].[info_login_card] b on a.login = b.login where a.host like ('$hostlogin') order by a.[createdate_unix] desc set rowcount 0
set rowcount $limit SELECT a.[id] ,a.[host] ,a.[login] ,a.[createdate] ,a.[createdate_unix] ,a.[last_ip] ,b.[displayName] FROM [user].[info_host] a left join [user].[info_login_card] b on a.login = b.login where a.login like ('$hostlogin') order by a.[createdate_unix] desc set rowcount 0
Source: https://habr.com/ru/post/240635/
All Articles