Solved

clock in application

Posted on 2004-04-15
2
198 Views
Last Modified: 2010-08-05
Click in and Clock out application connecting to Access database with ODBC
storing the user name and the password in the database

thank you
0
Comment
Question by:zgeorge_2
2 Comments
 
LVL 7

Expert Comment

by:sftweng
Comment Utility
zgeorge_2, are you looking for ideas or for a "shrink-wrapped" solution published here?
0
 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
Comment Utility
Hi George,
this is Your code.

{-------------------------------------------------------------}
program ClockInOut1;

uses
  Forms,
  Main1 in 'Main1.pas' {Form1},
  Pswd in 'Pswd.pas' {FPswd},
  Clock in 'Clock.pas' {FClock},
  Data in 'Data.pas' {DM1: TDataModule};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TDM1, DM1);
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TFPswd, FPswd);
  Application.CreateForm(TFClock, FClock);
  Application.Run;
end.
{-------------------------------------------------------------}
unit Main1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    edID: TEdit;
    BitBtn2: TBitBtn;
    BitBtn1: TBitBtn;
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    BitBtn9: TBitBtn;
    BitBtn10: TBitBtn;
    BitBtn11: TBitBtn;
    BitBtn12: TBitBtn;
    BitBtn13: TBitBtn;
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure edIDKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Pswd, Data, Clock;

{$R *.dfm}

procedure TForm1.BitBtn4Click(Sender: TObject);
var
  str: string;
  ind: integer;
begin
  str := edID.Text;
  ind := edID.SelStart;
  if (Length(str) < edID.MaxLength) or (edID.MaxLength = 0) then
    begin
    Insert( Char(Ord('0')+(Sender as TBitBtn).Tag),
            str, edID.SelStart+1);
    edID.Text := str;
    ActiveControl := edID;
    edID.SelStart := ind+1;
    end
  else
    begin
    ActiveControl := edID;
    edID.SelStart := ind;
    end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var
  str: string;
  ind: integer;
begin
  str := edID.Text;
  ind := edID.SelStart;
  if ind > 0 then
    begin
    Delete(str, edID.SelStart,1);
    edID.Text := str;
    end;
  ActiveControl := edID;
  if ind > 0 then
    edID.SelStart := ind-1
  else
    edID.SelStart := 0;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  edID.Text := '';
  ActiveControl := edID;
end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
  DM1.ADOQuery1.Close;
  DM1.ADOQuery1.SQL.Text :=
    Format('SELECT * FROM Tab_usr WHERE usr_id=%d',[StrToIntDef(edID.Text,-1)]);
  DM1.ADOQuery1.Open;
  if not DM1.ADOQuery1.Eof then
    begin
    FPswd.edPswd.Text := '';
    FPswd.edID.Text := edID.Text;
    if FPswd.ShowModal = mrOK then
      begin
      DM1.ADOQuery2.Close;
      DM1.ADOQuery2.SQL.Text :=
        Format('SELECT TOP 1 * FROM tab_clk WHERE clk_usr_nr=%d ORDER BY clk_time DESC',
               [DM1.ADOQuery1.FieldByName('usr_nr').AsInteger]);
      DM1.ADOQuery2.Open;
      if DM1.ADOQuery2.Eof then
        begin
        FClock.Button1.Visible := True;
        FClock.Button2.Visible := True;
        end
      else if (DM1.ADOQuery2.FieldByName('clk_type').AsString = 'O') then
        begin
        FClock.Button1.Visible := True;
        FClock.Button2.Visible := False;
        end
      else
        begin
        FClock.Button1.Visible := False;
        FClock.Button2.Visible := True;
        end;
      FClock.ShowModal;
      end;
    edID.Text := '';
    end
  else
    begin
    Application.MessageBox('Inalid ID Entered !','Error',MB_OK+MB_ICONEXCLAMATION)
    end;
end;

procedure TForm1.edIDKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0'..'9',#8]) then
    Key := #0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DM1.ADOConnection1.Connected := True;
end;

end.

{-------------------------------------------------------------}
unit Clock;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TFClock = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    procedure InsertTime(t: Char);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FClock: TFClock;

implementation

uses Data;

{$R *.dfm}

procedure TFClock.FormActivate(Sender: TObject);
begin
  ActiveControl := nil;
  Timer1.Enabled := True;
end;

procedure TFClock.Timer1Timer(Sender: TObject);
var
  str: string;
begin
  str := DateTimeToStr(Now);
  if str <> Label1.Caption then
    Label1.Caption := str;
end;

procedure TFClock.Button1Click(Sender: TObject);
begin
  InsertTime('I');
  Close;
end;

procedure TFClock.InsertTime(t: Char);
var
  nr: integer;
begin
  nr := DM1.ADOQuery1.FieldByName('usr_nr').AsInteger;
  DM1.ADOCommand1.CommandText :=
      Format('INSERT INTO tab_clk (clk_usr_nr,clk_type,clk_time) VALUES (%d,''%s'',''%s'')',
                       [nr,t,Label1.Caption]);
  DM1.ADOCommand1.Execute;
end;

procedure TFClock.Button2Click(Sender: TObject);
begin
  InsertTime('O');
  Close;
end;

end.
{-------------------------------------------------------------}
unit Pswd;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TFPswd = class(TForm)
    edPswd: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    edID: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FPswd: TFPswd;

implementation

uses Main1, Clock, Data;

{$R *.dfm}

procedure TFPswd.FormCreate(Sender: TObject);
begin
  Left := Form1.Left + 150;
  Top := Form1.Top -30;
end;

procedure TFPswd.Button3Click(Sender: TObject);
begin
  DM1.ADOQuery1.Close;
  DM1.ADOQuery1.SQL.Text :=
    Format('SELECT * FROM Tab_usr WHERE usr_id=%d AND usr_pswd=''%s''',
          [StrToIntDef(edID.Text,-1),edPswd.Text]);
  DM1.ADOQuery1.Open;
  if not DM1.ADOQuery1.Eof then
    ModalResult := mrOK
  else
    Application.MessageBox('Inalid password entered !','Error',MB_OK+MB_ICONEXCLAMATION)
end;

procedure TFPswd.FormActivate(Sender: TObject);
begin
  ActiveControl := edPswd;
end;

end.
{-------------------------------------------------------------}
unit Data;

interface

uses
  SysUtils, Classes, DB, ADODB;

type
  TDM1 = class(TDataModule)
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    ADOCommand1: TADOCommand;
    ADOQuery2: TADOQuery;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  DM1: TDM1;

implementation

{$R *.dfm}

end.
{-------------------------------------------------------------}
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now