|
-
Aug 18th, 2005, 12:01 AM
#1
Thread Starter
Addicted Member
[RESOLVED] End running class.
Hi all,
I've got a class called Startupforms as my startup project with the following code.
VB Code:
Public Class StartupForms
Shared Sub Main()
Dim SplashForm As New FrmSplash 'this is your first form
Dim LoginForm As New FrmLogin 'this is your second form
Dim MainForm As New FrmMAIN
SplashForm.ShowDialog() 'open first form
LoginForm.ShowDialog() 'open second form
MainForm.ShowDialog()
End Sub
End Class
Now on the second form which opens, there's a command button with code
if the user desires to exit the application. (This is a login form)
When the user clicks this button, it still opens the application, and flashes on the screen and returns errors and crap cause the user didn't logon and the connection wasnt made. Actually it's behaving worse than a baby.
How can I when the user clicks on the exit button on the second form, halt the class, and exit the application without executing the rest of the class?
Thanks
Rudi
-
Aug 18th, 2005, 12:29 AM
#2
Re: End running class.
You should provide an OK and a Cancel button on your login form. If the user presses OK then you should validate their credentials. If the login fails, inform the user and refresh the login form. You should make the Click event handler for the OK button look something like this:
VB Code:
Private Sub OK_Click(...) Handles okButton.Click
If Me.ValidateLogin() Then
Me.DialogResult = DialogResult.OK
Else
MessageBox.Show("Login failed. Please try again.")
End If
End Sub
where ValidateLogin is function that you write yourself that returns a Boolean indicating whether the login was successful. You would set the AcceptButton property of the form to the OK button and the CancelButton property to the Cancel button. You would also set the DialogResult property of the Cancel button to Cancel, although assigning the CancelButton property of the form should do this automatically. Your Main method would then look something like this:
VB Code:
Shared Sub Main()
Dim SplashForm As New FrmSplash 'this is your first form
Dim LoginForm As New FrmLogin 'this is your second form
SplashForm.ShowDialog() 'open first form
If LoginForm.ShowDialog() = DialogResult.OK Then
Application.Run(New FrmMain)
End If
End Sub
Also, I suggest you don't create a special class for this Main method. Either put it in a module or make it a Shared member of your main form. Then you simply set the module or form to be the startup object and the Main method will be used by default.
-
Aug 18th, 2005, 12:54 AM
#3
Thread Starter
Addicted Member
Re: End running class.
Hi JMCilhinney,
Thanks, I'm trying what you told me now. I assigned the the ok and cancel button properties to my "CmdLogin" and "CmdExit" buttons. When the user clicks exit, it now exits. Thanks, but when the user clicks Login... It still exits. hehe....
I think it's doing that cause I don't have the validate login stuff yet. Could you help me with that?
What I want to do is: Create a public connection string, that can be used anywhere in the application, while the application is open.
In my Login form, I've got a group box, with 2 radio buttons, "RdoNTAuth" & "RdoSQLAuth"
When the user clicks on RdoSQLAuth, then it shows text buttons and the user enters username and password.
So what I need is, a connection string needs to be created. or sql connection needs to be created publically. Regardless of the user using nt authentication or sql authentication. It at the end, creates the string for the login connection. (I think I explained that more difficult than it should sound)
What I would like is: I've got an module which name is: "JMSGlobals.vb"
With current code:
VB Code:
Module JMSGlobals
Public JMSColor = Color.FromArgb(149, 178, 198)
Public JMSConnection As New SqlClient.SqlConnection
End Module
Would it be possible to make the connection public in the JMSGlobals module, so that I can just refer to that connection whenever I need a connection to sql server? I just need to set the string for the duration of the lifetime of the open application (the user logs in all the time)
I hope I didn't make it sound too difficult, but I think you know what I mean. Can the validation be done in the module aswell?
Thanks
Rudi
-
Aug 18th, 2005, 01:16 AM
#4
Re: End running class.
You certainly can have a single connection for the whole app, and in fact it is a good idea. I like to actually create the connection in my first form, in your case the login form, so that I can configure it in the design window, like setting the connection string. I then have a public variable in a module, like you do but without the New keyword, which I assign my connection to in the Load event handler of the form it was added to.
Just one other thing, I don't think it is set by default but make sure the DialogResult property of your OK button has not been set to OK. It should be None, otherwise the form will close regardless of the result of your validation.
-
Aug 18th, 2005, 01:22 AM
#5
Thread Starter
Addicted Member
Re: End running class.
hmmm... ok I'm gonna try it and get back to you on this. Do you have any ideas on validation code. To check the login etc.
Thanks for all the help thusfar.
Rudi
-
Aug 18th, 2005, 04:50 AM
#6
Thread Starter
Addicted Member
Re: End running class.
JMCilHinney,
How Can I validate the sql server login, (get the error codes from sql server like invalid login, server not found etc)
When I do the login procedure, and it succeeds, then the application closes. It doesn't open the next form.
This is the code in my startup class:
VB Code:
Public Class StartupForms
Shared Sub Main()
Dim SplashForm As New FrmSplash 'this is your first form
Dim LoginForm As New FrmLogin 'this is your second form
Dim MainForm As New FrmMAIN
SplashForm.ShowDialog() 'open first form
If LoginForm.ShowDialog() = DialogResult.OK Then
Application.Run(MainForm)
'MainForm.ShowDialog()
End If
End Sub
End Class
And this is the code on my login button:
VB Code:
Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
If (RdoSQLAuth.Checked = True) Then
JMSGlobals.JMSConnection.ConnectionString = "Server=" & Me.txtJMSServer.Text & ";Database=MSTRIBOLOGY;User ID=" & Me.txtUsername.Text & ";Password=" & Me.txtPassword.Text & ";Trusted_Connection=False;workstation id=" & Environment.MachineName & ""
Me.Close()
ElseIf (RdoNTAuth.Checked = True) Then
JMSGlobals.JMSConnection.ConnectionString = "Data Source=" & Me.txtJMSServer.Text & ";Initial Catalog=MSTRIBOLOGY;Integrated Security=SSPI;workstation id=" & Environment.MachineName & ""
Me.Close()
End If
End Sub
What could be wrong?
Thanks
Rudi
-
Aug 18th, 2005, 04:58 AM
#7
Re: End running class.
DO NOT call Me.Close. This closes the form and certainly does not return DialogResult.OK to ShowDialog. I specifically wrote in the code I provided to set Me.DialogResult to OK. Doing that hides the form and returns the value you set to ShowDialog.
-
Aug 18th, 2005, 05:11 AM
#8
Thread Starter
Addicted Member
Re: End running class.
eek.... Sorry about that man... I got it now.
Any ideas on authentification validation?
Thanks again, sorry for not listening.
Rudi
-
Aug 18th, 2005, 05:25 AM
#9
Re: End running class.
 Originally Posted by Tjoppie
Any ideas on authentification validation?
Unfortunately not. I don't work with SQL Server much so I'll have to leave that to others I'm afraid.
-
Aug 18th, 2005, 05:42 AM
#10
Thread Starter
Addicted Member
Re: End running class.
Eish... Ok...
I'm having some trouble on setting that global sql connection.
Does the following connection strings look ok?
VB Code:
Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
If (RdoSQLAuth.Checked = True) Then
JMSGlobals.JMSConnection.ConnectionString = "Server=" & Me.txtJMSServer.Text & ";Database=MSTRIBOLOGY;User ID=" & Me.txtUsername.Text & ";Password=" & Me.txtPassword.Text & ";Trusted_Connection=False;workstation id=" & Environment.MachineName & ""
Me.DialogResult = DialogResult.OK
'Me.Close()
ElseIf (RdoNTAuth.Checked = True) Then
JMSGlobals.JMSConnection.ConnectionString = "Data Source=" & Me.txtJMSServer.Text & ";Initial Catalog=MSTRIBOLOGY;Integrated Security=SSPI;workstation id=" & Environment.MachineName & ""
Me.DialogResult = DialogResult.OK
'Me.Close()
End If
End Sub
-
Aug 18th, 2005, 05:47 AM
#11
Re: End running class.
Like I said, I haven't worked with SQL Server much, but you might like to look here if you haven't already. As to validating the logon, I've thought about it and I gues you would just try to open the connection and if it fails then check the exception, which may well differentiate between invalid credentials and other reasons.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|