Home arrow Delphi-Kylix arrow Page 3 - Server Code for an Internet Access Control Application
DELPHI-KYLIX

Server Code for an Internet Access Control Application


In the preceding article we dealt with the functional requirements of the server application as well as with the components that make up the server interface. In this article we will continue to build on the concepts that we discussed there and at the same time explore the code that runs the server application.

Author Info:
By: David Web
Rating: 5 stars5 stars5 stars5 stars5 stars / 9
September 08, 2008
TABLE OF CONTENTS:
  1. · Server Code for an Internet Access Control Application
  2. · Custom Procedures and Functions
  3. · Timing Procedure
  4. · Final Part of the Procedure

print this article
SEARCH DEVARTICLES

Server Code for an Internet Access Control Application - Timing Procedure
(Page 3 of 4 )

The timing procedure is perhaps the most important code of the three custom procedures in the application. It is responsible for updating the server and keeping staff members updated on the status of various workstations. More importantly, it activates workstations when staff members allocate sessions for users, by sending the "activate" command in the manner that we discussed before. Let's look in detail at the functional logic for the timing procedure:


procedure TForm1.timing(theStation,charge,thetime:string);

var

List: TList;

I:integer;

Context: TMyContext;

currtime,end_time:tdatetime;

li:tlistitem;

begin

currtime:=now;

longTimeFormat:='hh:nn:ss';

end_time:=IncMinute(currtime,strtoint(alloctime));

form1.endtime:=end_time;


// tAll:=alloctime;

//Search for workstation name in lv list

//if the name is there, then just add the allocated time and charge etc.

li:=lv.FindCaption(0,theStation,true,true,true);

if li <> nil then begin

memo1.lines.add(theStation+'...found...');

form1.li.ImageIndex:=8;

li.SubItems.Strings[0]:=formatdatetime('hh:mm:ss',currtime);

li.SubItems.Strings[1]:=timetostr(end_time);

li.SubItems.Strings[2]:=alloctime + ' minutes';

li.SubItems.Strings[3]:='$'+charge;

li.SubItems.Strings[4]:='Busy';


end

else begin

//the computer name is not on the listview, so add it!

memo1.lines.add('Timing...Caption does not exists.');

//update the lview

form1.li:=form1.lv.Items.Add;

form1.li.ImageIndex:=8;

form1.li.Caption:=theStation;

form1.li.SubItems.Add(formatdatetime('hh:mm:ss',currtime));

form1.li.SubItems.Add(timetostr(end_time));

form1.li.SubItems.Add(alloctime + ' minutes');

form1.li.SubItems.Add('N$'+charge);

form1.li.SubItems.Add('Busy');

end;


List := form1.ts.Contexts.LockList;

try

for I := 0 to List.Count-1 do

begin

Context :=TMyContext(List[I]);

if Context.compname = theStation then

begin

try

Context.Connection.IOHandler.WriteLn('activate:'+theStation+'@'+alloctime);

except

end;

Exit;

end;

end;

finally

form1.ts.Contexts.UnlockList;

end;

form1.memo1.Lines.add('error.');

end;


One of the primary aims of this procedure is to keep staff members updated on the status of an Internet session. It does this by automatically calculating the length of time that a user will be on the Internet using the actual time that a staff member allocates to that user. For example if a user is allocated thirty minutes at exactly one 'o clock then the procedure will automatically calculate and visually indicate that the user's session should end at half past one.

I hard coded the time units, which are fifteen, thirty and sixty minutes. This is of course not good practice, but in this case it is okay, because any time a user wants more time, a staff member will simply re-allocate the required time unit.

In addition to time keeping, this procedure also shows the total cost of any allocated time unit; for example, a fifteen minute session will cost around five dollars, a thirty minute session will cost ten dollars, and so on. The code starts by setting up the different variables that it will use to keep time. The variable names should give you an idea of their function. For example, the "currtime" variable stores the current time, and so on:


currtime:=now;

longTimeFormat:='hh:nn:ss';

end_time:=IncMinute(currtime,strtoint(alloctime));

form1.endtime:=end_time;


The "alloctime" variable will contain a time unit that is used to add to the current time. This is programmatically achieved by using the "IncMinute()" function as shown above, which then gives us the time that the session should end. The main control on the form that shows us the status of the connected workstations is the list view control; I choose it because it is highly customizable and is perfect for real time updates. It also therefore occupies a lot of time in this procedure.

The next section of the procedure does two things: first, it checks to see if the name of the workstation that the staff member allocates a session to is actually shown on the list view; if so, it adds the required information such as the allocated time and cost of the session. The workstation name search is done using the list view's search function called "FindCaption()":


//if the name is there, then just add the allocated time and charge etc.

li:=lv.FindCaption(0,theStation,true,true,true);

if li <> nil then begin

memo1.lines.add(theStation+'...found...');

form1.li.ImageIndex:=8;

li.SubItems.Strings[0]:=formatdatetime('hh:mm:ss',currtime);

li.SubItems.Strings[1]:=timetostr(end_time);

li.SubItems.Strings[2]:=alloctime + ' minutes';

li.SubItems.Strings[3]:='$'+charge;

li.SubItems.Strings[4]:='Busy';


Second, it checks if the name of the workstation is on the list. If not, it adds the workstation name and all related session information:


end

else begin

//the computer name is not on the listview, so add it!

memo1.lines.add('Timing...Caption does not exists.');

//update the lview

form1.li:=form1.lv.Items.Add;

form1.li.ImageIndex:=8;

form1.li.Caption:=theStation;

form1.li.SubItems.Add(formatdatetime('hh:mm:ss',et));

form1.li.SubItems.Add(timetostr(et));

form1.li.SubItems.Add(thetime + ' minutes');

form1.li.SubItems.Add('N$'+charge);

form1.li.SubItems.Add('Busy');

end;


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials