unit Unit6;
{Alarm Details}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Mask, ExtCtrls, ComCtrls;
type
TAlarm =
class
private
Handled: Boolean;
public
MsgText:
string;
DateTime: TDateTime;
PlaySound: Boolean;
Recurring: Integer;
function GetAlarmStr:
string;
procedure CheckTime;
end;
type
TForm6 =
class(TForm)
CloseBitBtn: TBitBtn;
OkBitBtn: TBitBtn;
Bevel1: TBevel;
MessageEdit: TEdit;
TimeMaskEdit: TMaskEdit;
MessageLabel: TLabel;
TimeLabel: TLabel;
PlaySoundCheckBox: TCheckBox;
RecurringGroupBox: TGroupBox;
EverydayRadioButton: TRadioButton;
WeeklyonRadioButton: TRadioButton;
DateRadioButton: TRadioButton;
WeeklyComboBox: TComboBox;
DateTimePicker1: TDateTimePicker;
procedure CloseBitBtnClick(Sender: TObject);
procedure RecurringRadioButtonClick(Sender: TObject);
procedure MessageEditChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
procedure GetData(Alarm: TAlarm);
procedure SetData(Alarm: TAlarm);
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
function TAlarm.GetAlarmStr:
string;
begin
Result := FormatDateTime('
hh:mm ', DateTime) + MsgText;
end;
procedure TAlarm.CheckTime;
var
Hour1, Min1, Sec1, MSec1: Word;
Hour2, Min2, Sec2, MSec2: Word;
Match: Boolean;
begin
// ???????????? ??????? ?????
DecodeTime(Time, Hour1, Min1, Sec1, MSec1);
// ????????????? ??????? ????? ??????????
DecodeTime(DateTime, Hour2, Min2, Sec2, MSec2);
// ?????????, ??? ??????? ????? ????????? ? ???????? ??????????
case Recurring
of
0:
// ??? ?????????? ?????????????
Match := (Hour1 = Hour2)
and (Min1 = Min2);
1..7:
// ??? ???????????? ?????????????
Match := (Hour1 = Hour2)
and (Min1 = Min2)
and
(Recurring = DayOfWeek(Date));
8:
// ??? ?????????? ????
Match := (Hour1 = Hour2)
and (Min1 = Min2)
and
(Int(DateTime) = Date);
else
Match := False;
end;
// ?????? ?????? ? ?????? ??????? ???????????
if Match
then
begin
if not Handled
then // ??????!
begin
Handled := True;
// ????????????? ????????? ????????????
if PlaySound
then Beep;
MessageDlg(GetAlarmStr, mtWarning, [mbOk], 0);
end;
end
else
Handled := False;
// ?????????? ??????? ????????????
end;
procedure TForm6.GetData(Alarm: TAlarm);
begin
with Alarm
do
begin
// ???????? ?? ??????? ????? ????????? ??????????
MsgText := MessageEdit.Text;
// ???????? ?? ??????? ????? ???????????? ??????????
DateTime := StrToTime(TimeMaskEdit.Text);
// ???????? ?? ??????? ????????? ????????????? ?????
PlaySound := PlaySoundCheckBox.Checked;
// ???????? ?? ??????? ????????????? ???????????? ??????????
if EverydayRadioButton.Checked
then
Recurring := 0
else if WeeklyonRadioButton.Checked
then
Recurring := WeeklyComboBox.ItemIndex + 1
else { DateRadioButton.Checked }
begin
Recurring := 8;
DateTime := DateTimePicker1.Date + DateTime;
end;
end;
end;
procedure TForm6.SetData(Alarm: TAlarm);
begin
with Alarm
do
begin
// ?????????? ? ???? ??????? ????? ????????? ??????????
MessageEdit.Text := MsgText;
// ?????????? ? ???? ??????? ????? ??????????
TimeMaskEdit.Text := FormatDateTime('
hh:mm', DateTime);
// ?????????? ? ???? ??????? ????????? ????????????? ?????
PlaySoundCheckBox.Checked := PlaySound;
// ?????????? ? ???? ??????? ????????????? ??????????
case Recurring
of
0:
// ?????????
EverydayRadioButton.Checked := True;
1..7:
// ???????????
begin
WeeklyonRadioButton.Checked := True;
WeeklyComboBox.ItemIndex := Recurring - 1;
end;
8:
// ? ?????????? ????
begin
DateRadioButton.Checked := True;
DateTimePicker1.Date := Int(DateTime);
end;
end;
end;
end;
procedure TForm6.CloseBitBtnClick(Sender: TObject);
begin
Close;
end;
procedure TForm6.RecurringRadioButtonClick(Sender: TObject);
begin
WeeklyComboBox.Enabled := Sender = WeeklyonRadioButton;
DateTimePicker1.Enabled := Sender = DateRadioButton;
end;
procedure TForm6.MessageEditChange(Sender: TObject);
begin
OkBitBtn.Enabled := Length(MessageEdit.Text) <> 0;
end;
procedure TForm6.FormCreate(Sender: TObject);
begin
TimeMaskEdit.Text := FormatDateTime('
hh:mm', Time);
WeeklyComboBox.ItemIndex := DayOfWeek(DateTimePicker1.Date) - 1;
DateTimePicker1.Date := Now;
end;
end.