Results 1 to 5 of 5

Thread: Having login rights follow user

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    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.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    683

    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?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width