|
-
Jul 16th, 2007, 09:18 AM
#1
Thread Starter
Fanatic Member
Having login rights follow user
I have a login form and I have 3 different types of users - Admin, Library, and Publications. They login on the form and the SQL server returns what type they are. What I want is when they open a form, it loads to show or not show buttons depending on their type. In VB, I would create a global variable and base it on that but in C# I am not sure what the best route is. Any ideas?
-
Jul 16th, 2007, 10:23 PM
#2
Re: Having login rights follow user
The C# equivalent of a VB module is a static class. Alternatively you could use instance members of a singleton class.
-
Jul 16th, 2007, 10:24 PM
#3
Lively Member
Re: Having login rights follow user
you could use the singleton pattern and set the initial variable with login credentials. then while logged in just call the variable.
you could also make a user object with certain properties to hold the user credentials and pass them in on constructors.
i hope this helps.
-
Jul 17th, 2007, 08:03 AM
#4
Thread Starter
Fanatic Member
Re: Having login rights follow user
Actually what I did and it seems to work is - My app is an MDI app and on my Main form I have this:
Code:
//public variable to hold login rights
public class Type
{
public static string strType;
}
Then whenever I need to use it from any form I just do this:
Code:
Main.Type.strType = "Library";
What I would like to know, is this good coding?
-
Jul 17th, 2007, 08:23 AM
#5
Re: Having login rights follow user
 Originally Posted by Beast777
What I would like to know, is this good coding?
Is that property logically a member of that type? If so then it's fine, otherwise it's dodgy. Like I said, static classes are the C# equivalent of VB modules. If you're declaring a class specifically to expose global members then you should declare the class itself static as well as its members. Then you can't create an instance of it, just as you can't with VB modules.
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
|