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.
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:
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:
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.