How to log a user out/switch user


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
OK, I'm definitely getting it. I added an ExitApp method to my sealed static MyApplication class. I call it from the login form and will be calling it from any other place I need to shut down code (like the unhandled exception handler). I'm using BeforeSessionLock to handle any closing/saving/undoing of forms. AfterSessionLock to clear a flag that indicates that the session is locked BigGrin (unless this is already available somewhere and I missed it).

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Is using the "End" statement in vb enough?

This is the ultimate "SHUT DOWN NOW" command Smile  Calling this will shut down the message pumps and logically exit the process.  Application.Exit() will not work (properly anyway) because you are running through an SF application. 

We always create a shared ShutDown method that does everything we need it to.  This was we can access from more than one location if need be.

Wouldn't the BeforeSessionLock event be the place to handle special stuff related to locking/logging in?

If this meets your needs then sure.  The way I mentioned earlier would just give you the ability to shut down your application from anywhere if you needed to.

Am I really starting to get this!??!!?

I believe you are Wink

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
OK, I lied, I have another question (in addition to the one in the previous post).



Wouldn't the BeforeSessionLock event be the place to handle special stuff related to locking/logging in? I.e. I could set a flag in the MyApplication class (to continue with your example) to indicate that its session locking, I could save/undo changes to forms as needed etc (likely calling static methods in the MyApplication class). Then the login form would be cleaner and only have to deal with exiting. And would the best place to handle this event be in the MyApplication class? Am I really starting to get this!??!!? Wow
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
hehe...like I said, I was pretty sure I was missing something pretty obvious!



OK, I get it now BigGrin



One final question: is there anything special I should do when closing the app? Is using the "End" statement in vb enough? Do I need to do anything within the SF framework? Do I need to call Application.Exit()? *



* once again demonstrating my lack of .NET understanding Blink
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
You have already answered half of the problem yourself.  You know when you are in a locked session versus the initial login.  If you create a custom login form you can program any logic into that you would like....including calling some shared method within your application or your main MDI form to shutdown the forms and save changes.  Better yet, create a shared propety that has a direct object reference to the main form and expose a method to call.

Public NotInheritable Class MyApplication
    Private Shared _MainForm As System.Windows.Forms.Form

    Public Shared ReadOnly Property MainForm As System.Windows.Forms.Form
       Get
          Return _MainForm
       End Get
    End Property
End Class

Set this reference to the class when the main form loads or instantiates:

MyApplication.MainForm = Me

Next, create a method within the main form to shut down your children forms as shown in a previous post:

Public Sub ShutDownFormsAndApp()
    '-- Place code here to close forms

    '-- Terminate the app
    End
End Sub

Now, in the custom login form, you can access the shared property to close the forms and shutdown the app.  Just add a button to your login form if you would like and enable it only for a locked session.  In the click call the shared property and public method:

CType(MyApplication.MainForm, MyMainForm).ShutDownFormsAndApp()

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I sorry, I'm just not following this.



I have a custom login form. When the login form is shown initially, the Exit is shown and this returns a result of Cancel to the caller (within Login.ShowLoginAndAuthUser), which then returns false, with sets the e.ShowMainForm to false, which causes the app to exit (some where in SF code). I'm pretty sure this is right. The Login.ShowLoginAndAuthUser code must configure the login form to show the exit button using the AllowAppExit property.



When LockSession is called, it must do whatever it does to lock the session, set AllowAppExit to false, then open the login form. If I did show the exit button, LockSession would likely ignore the cancel result (I'm guessing).



The problem I'm having it that in both cases I don't interact with the login form directly at ALL. And the login form doesn't directly cause the application to exit in the first case. And when the session is locked, I'm assuming the form is opened in dialog mode (ShowDialog), so any code I put in place after locking the session won't be run until after the login form is gone. I must be missing something pretty obvious here, but, well, I'm missing it Ermm









Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
does LockSession close the app?

No.  If you create a custom login form you can prevent the Exit button be being disable.  Or...create a button of your own to close down the application.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
OK, I see that I can setup a form to save any/all BOs on the form with the BaseForm.Save method. And likewise I can undo any changes with the BaseForm.Undo method. Cool, that is handled.



Interacting with the login form is not obvious though. I see that there is a AllowAppExit property, which is tied to the Exit button's Visible property. And clicking the exit button simply sets a DialogResult of cancel. When I call LockSession, how would I enable AllowAppExit and also if the user cancels the form via a click to Exit, does LockSession close the app?



Here too Smile We got about 8-10 inches yesterday!


Nice! BigGrin I'm nursing some blisters from some new snow boots I used to go snow shoeing yesterday, but it was glorious!
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
There are a lot of different ways you can handle your forms being closed and saving changes.  It could depend on how you are launching your forms.  We have a menu system wihtin our medical application that launches all forms, reports, etc.  So since we have a single point of launching, it makes it easy to add handlers or fill a collection of some kind.

In any case, one option is to loop through the forms collection in your MDI form.

For Each loForm As Form In Me.MdiChildren
    Try
       
With CType
(loForm, MicroFour.StrataFrame.UI.Windows.Forms.BaseForm)
            .Save()
            .Close()
        
End
With
    
Catch ex As
Exception
   
End
Try
Next

How can I get to be shown when the session is locked?

Well, you can create a custom login form to do this.  But depending on your needs, this might not be the best place to close down your app.  Generally it is best to require the end-user to at least log back in first...but maybe not.  It just depends on your circumstances.

it's snowing here

Here too Smile  We got about 8-10 inches yesterday!

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Thanks for the info guys!



So, I'm understanding what is done better. There are two things I'd like to be able to do:



1. when a user logs off, loop through the forms and possibly save changes. Would I need to expose some of the BO functionality at the form level, like the EditingState and the Save method? Also, I'd probably need to do this in an event related to session locking. Would it be BeforeSessionLocks (or what ever it is called)? And where is a suggested good place (in code) to put this event handler?



2. Add the Exit button to the login form when a session gets locked, so the app can just be closed. I know the button is there, but it must be hidden when session locking occurs. How can I get to be shown when the session is locked?



Thanks again and have a good weekend...it's snowing here BigGrin
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search