开发者

adding a timer to implement reminders in application

I have a reminders table in my apps database

FieldName = 'id'
FieldName = 'title'
FieldName = 'description'
FieldName = 'start_date'
FieldName = 'start_time'
FieldName = 'end_date'
FieldName = 'end_time'
FieldName = 'repeat'  (true/false)
FieldName = 'occurs'  (Integer = 1-Daily, 2-Weekly, 3-Monthy, 4-Annually)
FieldName = 'completed" (true/False)

Is there a way to use a TTimer to display the title and description of the reminder whenever the event occurs? If so, please explain in code/seudo code, or text.

a reminder is either a onetime - or - re-occurring event

if one time (occurs = 1 daily) , the date and time is stored in the Start_Date & Start Time The reminder should display at that time. After displayed, table field "Completed" is set to true.

if re-occurring, the date and time is stored in the Start_Date & Start Time and the End Date and End Time is stored. The reminder should display at that day and time, each day (1), week (2), month(3), or year(4)

If daily, reminder should display at that time every day,开发者_StackOverflow until end date is reached

If weekly, reminder should display at that time, on that particular day (of each week), until end date is reached

If monthly, reminder should display at that time, on that particular day (of each month), until end date is reached

If Annually, reminder should display at that time, on that particular day (of each year), until end date is reached

when end date is reached, Completed is updated with True

thanks, i hope this is easily do-able with out any additional components or libraries


<ironic>

Your question: Is there a way to use a TTimer to display the title and description of the reminder whenever the event occurs?

My answer

Yes, is there a way to do it.

Requirement: If so, please explain in code.

Anwer to fillfull your requirement

pseudocode:

procedure TEventsManager.SetNextEventTimer;
begin
  if Assigned(NextOcurringEvent) then
  begin
    Timer1.Interval := MillisecondsBetween(Now, NextOcurringEvent.DateTime);
    Timer1.Enabled := True;
  end;
end;

procedure TEventsManager.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  DisplayReminder(nextOcurringEvent);
  SetNextEventTimer;
end;

</ironic>


I know you said without additional components, but I think you'll like this.

In JVCL, there's a component called TJvScheduledEvents which can do exactly what you need and you can use it with very little programming. Try it and if you have any questions about it, feel free to ask.


So, i couldn't figure out how to post all the code, but here is the main TTimer Event

Procedure TForm1.Timer1Time(Sender: TObject);
var
 CommandText: String;
begin
 try
  Timer1.Enabled:= False;
  if ADOQuery1.Active then 
   ADOQuery1.Active:= False;
  CommandText :=
  Format('SELECT * FROM REMINDERS WHERE (START_DATE <= %s) AND (COMPLETED = FALSE) AND (LASTCHECK < %s)',
    [FormatDateTime('mm/dd/yy', Date), FormatDateTime('mm/dd/yy', Date)]);
ADOQuery1.SQL.Text := CommandText;
try
  ADOQuery1.Active := True;
  if not ADOQuery1.IsEmpty then
  begin
    BuildReminderList(ADOQuery1);
  end;
except
  //
end;
finally
Timer1.Enabled := True;
  end; 
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜