User Management for an Internet Access Control Application
(Page 1 of 4 )
In this part of the Internet access control application, we are going to discuss the last section of the server application that deals with user management. The term "user management" is somewhat misleading in the context of our application because it is not actually users of the Internet café that we are referring to, but rather the staff members. This section will deal with how staff members allocate Internet sessions to users and also how staff members with administration level access can add, remove and change new staff member details.
The first section deals with adding an Internet session for a user.
Adding an Internet session
This part of the server application is where most of the money making is taking place. Below is a screen shot of what the session allocating application looks like:
_html_151cbec4.png)
The above image shows the allocating screen detailing the following: the name of the workstation to which the session is being allocated; in this case the workstation is called “janedoe.” It also shows the length of time that is allocated; in this case it is sixty minutes. Finally, it shows the charge, which is twenty dollars.
The session time, charge and the name of the workstation will then be sent to the client application, which will use that information to start up an Internet session. The allocation form is activated when a staff member double clicks on the workstation name in the list view control. When a staff member double clicks on it, the name of the workstation is transferred to the allocation screen.
Below is a listing of the code that makes all of the above happen:
unit adduser;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm2 = class(TForm)
BitBtn1: TBitBtn;
StaticText1: TStaticText;
StaticText2: TStaticText;
edcharge: TEdit;
StaticText3: TStaticText;
StaticText4: TStaticText;
StaticText5: TStaticText;
cbtime: TComboBox;
Label1: TLabel;
procedure BitBtn1Click(Sender: TObject);
procedure cbtimeChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
uses server;
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
form1.WStation:='';
form1.mins:='';
form1.tcharge:='';
form1.WStation:=label1.caption;
form1.mins:=cbtime.Text;
form1.tcharge:=edcharge.Text;
//update mula table
with form1.ado1 do
begin
tablename:='mula';
active:=true;
Insert;
FieldByName('uid').AsInteger:= form1.uid;
FieldByName('total').AsCurrency:=strtofloat(edcharge.text);
post;
active:=false;
end;
form1.Timing(label1.Caption,edcharge.text,cbtime.text);
close;
end;
procedure TForm2.cbtimeChange(Sender: TObject);
begin
if cbtime.text = '15' then
begin
edcharge.text:='5.00';
end
else
if cbtime.text = '30' then
begin
edcharge.text:='10.00';
end
else
edcharge.text:='20.00';
end;
end.
The first procedure in the code deals with what happens when a staff member clicks on the “OK” button that is on the form. It is essentially responsible for updating the mula table and then sending the session information over to the workstation. The first part of the code initializes a couple of variables:
procedure TForm2.BitBtn1Click(Sender: TObject);
begin
form1.WStation:='';
form1.mins:='';
form1.tcharge:='';
The name of the workstation is added to the label control and other information, such as the time and charge, is added to the just-initialized variables from appropriate edit and combo box controls:
form1.WStation:=label1.caption;
form1.mins:=cbtime.Text;
form1.tcharge:=edcharge.Text;
Then the mula table is updated. Essentially, two pieces of information are sent to the database. The first piece is the user id of the currently logged-in staff member, which is captured at login, and the second piece is the total charge of the session that the staff member is allocating:
//update mula table
with form1.ado1 do
begin
tablename:='mula';
active:=true;
Insert;
FieldByName('uid').AsInteger:= form1.uid;
FieldByName('total').AsCurrency:=strtofloat(edcharge.text);
post;
active:=false;
end;
Finally, the information is sent to the workstation for processing. This is done by calling the timing() function which we discussed in the previous article. This function takes three arguments, which in this case are answered by adding the name of the workstation, the charge, and the time that is allocated for the Internet session:
form1.Timing(label1.Caption,edcharge.text,cbtime.text);
close;
end;
The remaining procedure in this form deals with the allocation of the time and charge. As I’ve stated previously, the time and charge for a session is hard coded (which is not good practice, as it will be difficult to change the values at a later stage), but you might be well advised to make the setting of these values more flexible:
procedure TForm2.cbtimeChange(Sender: TObject);
begin
if cbtime.text = '15' then
begin
edcharge.text:='5.00';
end
else
if cbtime.text = '30' then
begin
edcharge.text:='10.00';
end
else
edcharge.text:='20.00';
end;
end.
Next: User Management Module >>
More Delphi-Kylix Articles
More By David Web