Click here to Skip to main content
15,900,461 members
Home / Discussions / C#
   

C#

 
GeneralGDI+ Pin
bouli2-Feb-04 5:00
bouli2-Feb-04 5:00 
GeneralRe: GDI+ Pin
Mazdak2-Feb-04 5:17
Mazdak2-Feb-04 5:17 
GeneralRe: GDI+ Pin
bouli2-Feb-04 5:18
bouli2-Feb-04 5:18 
GeneralRe: GDI+ Pin
Mazdak2-Feb-04 5:27
Mazdak2-Feb-04 5:27 
GeneralRe: GDI+ Pin
bouli2-Feb-04 5:30
bouli2-Feb-04 5:30 
Generalpassword checking Pin
ASGill2-Feb-04 2:33
ASGill2-Feb-04 2:33 
GeneralRe: password checking Pin
Rhys__6662-Feb-04 3:04
Rhys__6662-Feb-04 3:04 
GeneralRe: password checking Pin
Heath Stewart2-Feb-04 3:15
protectorHeath Stewart2-Feb-04 3:15 
Before showing the dialog, set a property you'd add to the Form that dictates which button was clicked, like an enumeration for example (provides easy value checking to make sure an invalid enumeration wasn't passed in - see Enum.IsDefined).

You could also use a generic prompt Form that has a username and password property that gets the text from their respective TextBox controls in the Form and, if ShowDialog returned DialogResult.OK handle the code in each one of the Click event handlers for the departmental Buttons. If you put this in a terminating loop (for which you can always use break to break out of it if the credentials were authenticated successfully), the dialog could be shown multiple times - even using the same instance. Just don't forget to call Dispose when you're finally done with the Form to free system resources, which is necessary for modal dialogs (i.e., when calling Form.ShowDialog, which has to do with the underlying native resources used by the Form).

There's many other ways you can do this. Personally, I would've invoked the call on some sort of broker since your code to check the database is most likely the same except for, perhaps, the connection string and the query string. If you passed an instance of an object configured with the write departmental connection and query strings, the prompt could simply call a single method and know whether or not the credentials are valid without even knowing which department is authenticating the credentials. After all, it's just a generic prompt dialog - why should it care about how to authenticate credentials. Just use the power of polymorphism. For instance, if you have an interface like so:
public interface IAuthenticator
{
  bool Authenticate(string username, string password);
}
...and had a property that takes an instance of this interface (by declaring a property of Type IAuthenticator), then when the user tries clicks OK (or Login, or whatever) you make sure this property isn't null and call Authenticate on the instance. Any code that wants to authenticate credentials merely implements this interface and provides a specific implementation of Authenticate. This is a good abstract design.

 

Microsoft MVP, Visual C#
My Articles
GeneralC# Standard Template Library Pin
TeamWild2-Feb-04 1:11
TeamWild2-Feb-04 1:11 
GeneralRe: C# Standard Template Library Pin
Colin Angus Mackay2-Feb-04 1:36
Colin Angus Mackay2-Feb-04 1:36 
GeneralRe: C# Standard Template Library Pin
TeamWild2-Feb-04 2:00
TeamWild2-Feb-04 2:00 
GeneralRe: C# Standard Template Library Pin
Colin Angus Mackay2-Feb-04 2:35
Colin Angus Mackay2-Feb-04 2:35 
GeneralRe: C# Standard Template Library Pin
Judah Gabriel Himango2-Feb-04 8:25
sponsorJudah Gabriel Himango2-Feb-04 8:25 
GeneralRe: C# Standard Template Library Pin
Nemanja Trifunovic2-Feb-04 12:07
Nemanja Trifunovic2-Feb-04 12:07 
GeneralRe: C# Standard Template Library Pin
Heath Stewart2-Feb-04 3:04
protectorHeath Stewart2-Feb-04 3:04 
GeneralRe: C# Standard Template Library Pin
boogs2-Feb-04 9:01
boogs2-Feb-04 9:01 
GeneralClickety Pin
Colin Angus Mackay2-Feb-04 11:57
Colin Angus Mackay2-Feb-04 11:57 
GeneralButtons in DataGrid Pin
Lyubomir Naydenov2-Feb-04 0:39
Lyubomir Naydenov2-Feb-04 0:39 
GeneralRe: Buttons in DataGrid Pin
Mazdak2-Feb-04 0:50
Mazdak2-Feb-04 0:50 
GeneralRe: Buttons in DataGrid Pin
Heath Stewart2-Feb-04 3:20
protectorHeath Stewart2-Feb-04 3:20 
GeneralRe: Buttons in DataGrid Pin
Lyubomir Naydenov2-Feb-04 9:42
Lyubomir Naydenov2-Feb-04 9:42 
QuestionEasy URL Query parsing? Pin
3ddA2-Feb-04 0:08
3ddA2-Feb-04 0:08 
AnswerRe: Easy URL Query parsing? Pin
Heath Stewart2-Feb-04 3:27
protectorHeath Stewart2-Feb-04 3:27 
GeneralRe: Easy URL Query parsing? Pin
3ddA2-Feb-04 6:55
3ddA2-Feb-04 6:55 
GeneralLaunching mail client, open new message and add attachments Pin
jewlin1-Feb-04 23:29
jewlin1-Feb-04 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.