Printing scheduled appointments in a predefined timegrid

Hi,

In a database I store scheduled appointments. There are no overlapping appointments.
I want to print these appointments within a timegrid.

Database Appoitments:
START                  END                      DESCRIPTION
10-10-2006 09:45  10-10-2006 11:00  Appointment 1
10-10-2006 11:00  10-10-2006 12:00  Appointment 2

Printout on timegrid: Date 10-10-2006
09:00
09:15
09:30
09:45    09:45 - 11:00  Appointment 1
10:00
10:15
10:30
10:45
11:00    11:00 - 12:00  Appointment 2
11:15
etc. etc. etc.

I can't figure out how to do the following:
1. So the timegrid must be filled regardless of the number of appointments.
2. The appointments must be aligned within the grid based on the start date/time.

Additional problem: How to position a starttime that isn't matchable with a predefined time in the timegrid (f.e. 09:10).
09:00    09:10 - 09:45 Appointment 3

Thank you very much for your help in this.

Regards,
Stef
Stef MerlijnDeveloperAsked:
Who is Participating?
 
calinutzConnect With a Mentor Commented:
so build your timegrid something like this:

var
 i:integer  ;
 t:TTime;
begin
t:=StrToTime('09:00');

actio.Active:=false;
actio.SQL.Clear;
actio.SQL.Add('delete from test_time');
actio.ExecSQL;

repeat
actio.Active:=false;
actio.SQL.Clear;
actio.SQL.Add('insert into test_time (times) values ('+QuotedStr(TimeToStr(t))+')');
actio.ExecSQL;
t:=IncMinute(t,15)
until t>=StrToTime('17:00');

AdoTable1.Active:=false;
AdoTable1.Active:=true;
end;


// where column times is of tipe smalldatetime
// also must set the field property of ADOTabel1 to the following display format:     HH:MM

0
 
calinutzConnect With a Mentor Commented:
First you must decide if you want a DBGrid or a StringGrid. It makes a difference
  For DBGrid... all you have to do is use a temporary table where you will insert the timegrid, and then update with the appointments. After that, the DBGrid will simply show the result

For StringGrid... almost the same... generate the stringGrid manually instead of working with a datasource, you will have to insert the timegrid like :
StringGrid.Cells[0,1]:='09:00'
...
The same goes fro the appointments... you would have to parse the cells for the needed hour and place there the appointment text.
So I would go for the DBGrid version
0
 
calinutzCommented:
For better understanding I will paste the dfm down here:
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 554
  Height = 563
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 80
    Top = 68
    Width = 169
    Height = 25
    Caption = 'Generate timegrid'
    TabOrder = 0
    OnClick = Button1Click
  end
  object DBGrid1: TDBGrid
    Left = 80
    Top = 96
    Width = 457
    Height = 397
    DataSource = DataSource1
    TabOrder = 1
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
  end
  object ADOConnection1: TADOConnection
    Connected = True
    ConnectionString =
      'Provider=SQLOLEDB.1;Password=yourpassword;Persist Security Info=' +
      'True;User ID=sa;Initial Catalog=yourDB;Data Source=SERVER'
    LoginPrompt = False
    Provider = 'SQLOLEDB.1'
    Left = 12
    Top = 12
  end
  object ADOTable1: TADOTable
    Active = True
    Connection = ADOConnection1
    CursorType = ctStatic
    TableName = 'test_time'
    Left = 92
    Top = 12
    object ADOTable1times: TDateTimeField
      FieldName = 'times'
      DisplayFormat = 'HH:MM'
    end
    object ADOTable1tesxt: TWideStringField
      FieldName = 'tesxt'
      Size = 50
    end
  end
  object DataSource1: TDataSource
    DataSet = ADOTable1
    Left = 132
    Top = 12
  end
  object actio: TADOQuery
    Connection = ADOConnection1
    Parameters = <>
    Left = 16
    Top = 64
  end
end
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
calinutzConnect With a Mentor Commented:
Of course you must enter your info about user name, password and host of the server.
Naturaly you can do the same different database approach, other DB Engine, TCustomDataset, Access DB, or whatever.
I just gave you an example on how it can be made.


And about adding an hour that starts at another point that does not exist in the timegrid... just do the insert of the respective appointment in the table, and then sort the table by the times field... create an index on that field and all will be alright. the appointment will appear in the grid between the times that are smaller and bigger than it.


regards
0
 
Stef MerlijnDeveloperAuthor Commented:
Thank you Calinutz,

But an important part of my question isn't answered yet:
*************
2. The appointments must be aligned within the grid based on the start date/time.

Additional problem: How to position a starttime that isn't matchable with a predefined time in the timegrid (f.e. 09:10).
09:00    09:10 - 09:45 Appointment 3
*************
0
 
Stef MerlijnDeveloperAuthor Commented:
When I would just insert the appointments into the table there will be duplicate starttimes in the table.

Like:
09:45
09:45    09:45 - 11:00  Appointment 1

0
 
calinutzConnect With a Mentor Commented:
You probabely missunderstood  what I sayd.
After you generate the timegrid by inserting in the table the standard hours: 09:00, 09:15, 09:30... etc
if you have an apointment at a predefined date like the standard ones... you will do an update on the table... (so not an insert),
and

- if you have an appointment that cannot be found in the timegrid (so it's not standard 09:15, 09:30 etc) suppose it's 09:23,
in this case you just do an insert in the table.

Any Query like:
select * from test_time order by times
will order your appointments in order of the time... so what's the problem?
0
 
Stef MerlijnDeveloperAuthor Commented:
I understand now what you mean.
Thank you for your help.

Regards,
Stef
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.