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?
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.
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.
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?
Re: Having login rights follow user
Quote:
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.