Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to force users to shutdown their VFP application. 3

Status
Not open for further replies.

ramani

Programmer
Mar 15, 2001
4,336
AE
Hi,

1. In your Main.PRG ..
Before the main event is started..
Add code...

***************************************************
PUBLIC pnShutSeconds, ptShutTime
pnShutSeconds = 0
ptShutTime = {}
***************************************************
** To avoid new users from starting application **
IF FILE("DoShut.txt")
=MESSAGEBOX("Try after some time",0+16+ ;
"System maintenance in progress")
QUIT
ENDIF
***************************************************

2. Add a timer class to your application.
In the Timer event of the Timer class.. add the code..
******************************************************
IF m.pnShutSeconds = 0
IF FILE("DoShut.txt")
m.pnShutSeconds = VAL(FILETOSTR("DoShut.txt"))
m.ptShutTime = DATETIME()+VAL(FILETOSTR("DoShut.txt"))
ENDIF
ENDIF
IF m.pnShutSeconds > 0
WAIT WINDOW "Maintenance shutdown called by " + ;
"System Administrator" + CHR(13)+ ;
"Please Close down your application before " + ;
"the forced shutdown."+ CHR(13)+ CHR(13)+;
"ShutDown Time "+TTOC(m.ptShutTime) + CHR(13)+ ;
"Current Time is "+TTOC(DATETIME()) NOWAIT NOCLEAR
IF DATETIME() > m.ptShutTime
** Instead of ThisForm.Release,
** you may have to call a shutdown routine.
WAIT CLEAR
ThisForm.Release()
ENDIF
ENDIF
******************************************************

3. Set the timer interval as 1000 (1 second) or even (10000=10 seconds) so that the resources are not drained by the timer call.

4. Drop this timer class in your base application form
or drop it in all forms of your application.

5. Steps you have to take.. to make this call..
a. When you need to make a shutdown call..
b. Start VFP.. change to the default application
directory in the server place..
c. Decide the shutdown time you want to allow
This shall be in seconds.. say 300 for 5 minutes
d. In the command window..
STRTOFILE("300","Doshut.txt")
e. In 5 + probable lag due timer firing interval
i.e. say 5 minutes 10 seconds
All will be forced shutdown by the timer call.
f. DO YOUR MAINTENANCE
g. DELETE file DoShut.txt
or else no one will be able to get on.

While the description is more.. actual code is very less.

I will be adding this as an FAQ soon :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Ramani,
This is similar (although completly diffrerent :) ) to what I use, it's just that it doesn't handle a couple of potential problems. The first is when someone isn't at their w4orkstation when this message comes up. The next is report Previews - they can hang this sort of shutdown - especially when the first problem is true. The next is transaction processing or even just buffered data, you have to decide whether to save the data or discard it before doing the form release(). (You kind of hint at this in your comment "you may have to call a shutdown routine", but depending on the form, this can be complicated.)

Rick
 
Rick,

It wouldn't be too hard to make the 'shutdown routine' check for open print preview windows, although I think I'm right in saying ramani doesn't use them himself - he prefers to run acrobat (which is better at handling the output).

What do you think?

Regards

Griff
Keep [Smile]ing
 
Hi Rick

Thanks for your review..

1. This is similar (although completly diffrerent ) to what I use, .. If it is not asking for too much, you can explain more and show another way. VFP is having more ways of doing a job than any other STUDIO product can do. And often one method could be better from another given the circumstances. SO you could be right.


2. it's just that it doesn't handle a couple of potential problems. The first is when someone isn't at their workstation when this message comes up.
This message is posted as a wait window without clearing the message. SO timer event surely fire the codes to completeness. I do not see any problem in this. The main purpose is to take care of these situation and fire out the application to auto close for maintenance.

3. The next is report Previews - they can hang this sort of shutdown - especially when the first problem is true. I will specificaly try this out (_screen matters).. right now no comments.. since my method of handling reports could be different. I have a detailed way of handling reports by my own class, which handles.. export to PDF, export to word, display on screen on my own defined window which in fact is another form, print to selected printer etc., What I need to check is handling _screen that you are talking.

4. The next is transaction processing or even just buffered data, you have to decide whether to save the data or discard it before doing the form release(). (You kind of hint at this in your comment "you may have to call a shutdown routine", but depending on the form, this can be complicated.) You are right to the extent that a method need to be adopted for handling half processed data. It is upto the situation.

But I still believe that if anyone is writing code in such a way that it goes beyond a few seconds in one set of TRANSACTIONS, I consider it as bad code. If any one leaves to user interaction between a loop of TRANSACTION PROCESSING again.. that is bad code.
Given this scenario,.. and if any user is venturing into not listening to the message and continue processing data, will have to loose one set of transaction they process at the time of code showing them the door. At the worst it will be the last set of one document they may be creating or editing. If any one leaves the application unattended.. they are fired out and there is no data loss again.. at the worst.. it is on the screen one.. which they have to reprocess. So under the circumstances, I do not feel this is an issue. I have not come across any heavy time consuming reports which could be in progress.. such as half an hour report generation in progress. If such report generations are in the common user routines, then such specific users need to be checked before issuing the system call. There can never be a conclusion as to this.

And this type of system call will be rare during working time and when required, and called, it is easy to take care that no one logs in by accident. That is the main advantage.. rather than telling and expecting that no one logs on when maintenance is on.

Besides these, if the application needs such a heavy waiting.. we can trap the reqirement in a different detailed way. But I have not put all these heavy application concepts in this thread. May be some other day !

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Ramani,
Don't take it so personally, Mike was only making a point - we all think your code is very useful.

Chill out man [smile]

Regards

Griff
Keep [Smile]ing
 
Sorry, that should have been Rick not Mike...
Regards

Griff
Keep [Smile]ing
 
Hi Griff..

Does my reply sounding bad.! My God. I only meant it as a deep drawn discussion and never meant anything hurting to any one. And I did not also feel anything bad. I am as cool as always! And also feel Rick is not feeling anythng bad.

Hi Rick,
My quoting you in bold letters is only because I value your comments very much. Not for hurting you. I did not also feel anything that way. My reply is to draw out more opinions and also say my opinion.

Every one is free to comment. And we are all here to do our things better. I do not want any one to feel hurt by my words at any point of time.

The only way I know to react when I dont agree and feel personal is to KEEP SILENT. Or specify that mildly.

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Ramani,
I take (took?) no offense at your response, just as I assume you didn't mind my critism. Certainly part of this forum is about sharing ideas that you may not think about when you are coding by yourself. I definitely don't have all the answers, which is why I read more messages that I respond to - it's how I learn.

Variants on coding themes is just one way that makes VFP so rich, there are many ways to do the same thing "right"!

Rick

P.S. One way to "kill" the Print Preview window that seems to work for me is:
Code:
** Kill the report preview window first.
IF WEXIST("Report Designer")
   Hide Window "Report Designer"
ENDIF
Note that this does assume the default preview window.

 
Thanks Rick for your confirmation. That is how I have felt you so far. And absolutely I have no fear or feelings for criticism. We all learn only with those.

Now I have to say.. Take it easy Griff.. No offence meant either :). And let us all leave it at that.

And coming to the subject..

IF WEXIST("Report Designer")
Hide Window "Report Designer"
ENDIF

Rick.. Dont we have to release it absolutely ?. I suggest
RELEASE WINDOW "Report Designer" instead. Any comments ?

And these are the codes I would put on the shutdown procedure.. of course.
:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Sorry, no offence meant!

TIC Regards

Griff
Keep [Smile]ing
 
Hey Griff,
No need for sorry. Just you gave me an opportunity to make myself clear to others. Thanks. :)
ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Ramani,
Actually Hiding that window seems to allow VFP to shut down. If it's showing, perhaps because it is application Modal, it won't allow VFP to close.

I could never get a RELEASE on that window to work - it may be one of those "secret" Windows VFP just keeps hidden until it needs it!

Rick


 
HI

There is an error in the above my code..

** To avoid new users from starting application **
IF FILE("DoShut.txt")
=MESSAGEBOX("Try after some time",0+16+ ;
"System maintenance in progress")
QUIT
ENDIF

***************************************************

should read as..



** To avoid new users from starting application **
IF FILE("DoShut.txt")
=MESSAGEBOX("Try after some time",0+16, ;
"System maintenance in progress")
QUIT
ENDIF
***************************************************

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top