You are on page 1of 6

unit Unit1;

interface

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

type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Timer1: TTimer;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
BitBtn1: TBitBtn;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBEdit1: TDBEdit;
DBComboBox1: TDBComboBox;
DBComboBox2: TDBComboBox;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
DBNavigator1: TDBNavigator;
ADOQuery1: TADOQuery;
DataSource2: TDataSource;
Edit1: TEdit;
DBGrid2: TDBGrid;
Label11: TLabel;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Timer1Timer(Sender: TObject);
procedure DBEdit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Label1DblClick(Sender: TObject);
procedure TabSheet1Show(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormActivate(Sender: TObject);

private
{ Private declarations }
public
path:string;
{ Public declarations }

end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var i: word;
test:string;

begin
label5.Caption:=timetostr(time); {untuk menampakkan jam system}
{cek jika jam system SAMADENGAN dbedit2.text}
if label5.caption=dbedit2.Text then
begin
test:=dbedit3.text;
{ubah isidbedit3 ke Integer}
case strtoint(dbedit3.Text ) of
0: ExitWindowsEx (EWX_SHUTDOWN, 0); {untuk menSHUTDOWN komputer
win98 SE}
9: sndPlaySound('bel2.wav', SND_ASYNC or SND_FILENAME);
{membunyikan bel}
else
begin
for i:=1 to strtoint(dbedit3.Text) do
begin
{membunyikan bel sesuai looping}
sndPlaySound('bel1.wav', SND_ASYNC and snd_loop);
end;
sndPlaySound('',snd_async); {mematikan bel}
end;
end;
adoquery1.Next ; {menurunkan cursor data}
end;
end;

procedure TForm1.DBEdit1Change(Sender: TObject);
begin
if dbedit1.IsMasked = not true then
dbedit1.Field.EditMask :='99:99:99';
end;

procedure TForm1.FormCreate(Sender: TObject);
var
ADate: TDateTime;
days: array[1..7] of string;
begin {mengoneksikan database}
path:=ExtractFilePath (Application.ExeName);

adoconnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Dat
a Source='+path+'\Database\bel.mdb;Persist Security Info=False';
adoconnection1.Connected :=true;
adotable1.Active :=true;
form1.Height :=600;
form1.Width :=800;
pagecontrol1.ActivePage :=tabsheet1;

days[1] := 'Minggu'; {konversi hari}
days[2] := 'Senin';
days[3] := 'Selasa';
days[4] := 'Rabu';
days[5] := 'Kamis';
days[6] := 'Jumat';
days[7] := 'Sabtu';
ADate := date;

label6.Caption:=datetostr(date);
label7.Caption:=days[DayOfWeek(ADate)];
edit1.Text :=label7.Caption;

adoQuery1.Parameters.ParamByName('hari_apa').Value := Edit1.Text;
adoquery1.Active :=true;

end;
{untuk cek bel}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
test:string;
begin

test:=dbedit3.text;
case strtoint(dbedit3.Text ) of
0: begin
ExitWindowsEx (EWX_SHUTDOWN, 0);
showmessage(inttostr(GetLastError()));
end;
9: PlaySound('bel2.wav',0, SND_ASYNC or SND_FILENAME);
else
begin
for i:=1 to strtoint(dbedit3.Text) do
begin
PlaySound('bel1.wav',0,SND_ASYNC and snd_loop);
end;
PlaySound('',0,snd_async);
end;
end;
end;

procedure TForm1.Label1DblClick(Sender: TObject);
begin
if button1.Visible = false then
begin
button1.visible:= true;
button2.visible:= true;
end
else
begin
button1.visible:= false;
button2.visible:= false;
end;
end;

procedure TForm1.TabSheet1Show(Sender: TObject);
begin
adoquery1.Close; {refresh data query}
adoquery1.Open ;
form1.Activate;
end;

procedure TForm1.Button2Click(Sender: TObject);
var jam:string;
begin
jam:=label5.Caption;
adoquery1.First;
with adoquery1 do
while not eof do {menyesuaikan data bel dengan jam
sekarang}
begin
if jam > adoquery1.FieldByName('jam_ke').Value then
adoquery1.Next
else
exit;
end;
end;

procedure TForm1.FormActivate(Sender: TObject);
var jam:string;
begin
if jam='' then
label5.Caption:=timetostr(time); {menyesuaikan data bel
dengan jam
sekarang untuk pertama kali
running }

jam:=label5.Caption;
with adoquery1 do
while not eof do
begin
if jam > adoquery1.FieldByName('jam_ke').Value then
adoquery1.Next
else
exit;
end;

end;

end.