Click here to Skip to main content
15,914,322 members
Home / Discussions / C#
   

C#

 
GeneralRe: converting variable into the a string Pin
Guffa9-Jul-05 17:02
Guffa9-Jul-05 17:02 
GeneralRe: converting variable into the a string Pin
amitmohanty9-Jul-05 18:05
amitmohanty9-Jul-05 18:05 
GeneralRe: converting variable into the a string Pin
afinnell9-Jul-05 22:36
afinnell9-Jul-05 22:36 
GeneralRe: converting variable into the a string Pin
Guffa9-Jul-05 23:41
Guffa9-Jul-05 23:41 
GeneralRe: converting variable into the a string Pin
Denevers10-Jul-05 3:08
Denevers10-Jul-05 3:08 
GeneralMove data between forms Pin
sea#9-Jul-05 12:40
sea#9-Jul-05 12:40 
GeneralRe: Move data between forms Pin
Snowblind379-Jul-05 13:26
Snowblind379-Jul-05 13:26 
GeneralRe: Move data between forms Pin
Luis Alonso Ramos9-Jul-05 14:40
Luis Alonso Ramos9-Jul-05 14:40 
It depends, are you writing a Windows Forms or an ASP.NET application? I will assume Windows Forms.

What I do is create a User class that has properties like name, database ID, and anything else you would like to know about a user. It also has a Current static property, which is initializes by a static method taking user name and password. Something like this:
class User
{
    // Private fields, and properties to access user information.
    // The properties could also have setters if you have a Save method
    // that will persist the changes to the database.
    private int id;
    private string name;
 
    public int Id
    {
        get { id; }
    }
 
    public string Name
    {
        get { return name; }
    }
 
    // Constructor that gets the info for one customer
    public User(int id)
    {
        // Load id and name from database
        ....
    }
 
    // Static methods and properties for current logged in user
    static private User current;
 
    // Static property to return currently-logged in user. Since the field
    // is private, it can't be created from the outside.
    public static User Current
    {
        get { return current; }
    }
 
    // Call this method to try to login a user.
    public static bool LogIn(string userName, string password)
    {
        // Try to find a record in the database with the specific user name and
        // password

        if(found)
        {
            current = new User(foundId);
            return true;  // User logged in
        }
 
        return false;  // No user logged in
    }

    public static void Logout()
    {
        current =  null;
    }
}
Then I always have a global object with info about the current user, so I can do things like this:
if(User.Current != null)
    sbpUserName.Text = User.Current.Name;  // Display in status bar
else
    sbpUserName.Text = "(please log in)";
I hope this helps! Good luck!

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralGraphics - removing a line Pin
quilkin9-Jul-05 12:30
quilkin9-Jul-05 12:30 
GeneralRe: Graphics - removing a line Pin
DavidNohejl9-Jul-05 13:16
DavidNohejl9-Jul-05 13:16 
GeneralRe: Graphics - removing a line Pin
quilkin9-Jul-05 20:57
quilkin9-Jul-05 20:57 
GeneralRe: Graphics - removing a line Pin
DavidNohejl10-Jul-05 1:26
DavidNohejl10-Jul-05 1:26 
GeneralRe: Graphics - removing a line Pin
quilkin10-Jul-05 8:05
quilkin10-Jul-05 8:05 
GeneralRe: Graphics - removing a line Pin
Mathew Hall9-Jul-05 23:00
Mathew Hall9-Jul-05 23:00 
Generalrtsp protocol Pin
Member 16897569-Jul-05 12:11
Member 16897569-Jul-05 12:11 
GeneralRe: rtsp protocol Pin
leppie9-Jul-05 14:14
leppie9-Jul-05 14:14 
GeneralRich Edit TextBox Pin
Akrynite9-Jul-05 9:28
Akrynite9-Jul-05 9:28 
GeneralRe: Rich Edit TextBox Pin
Judah Gabriel Himango9-Jul-05 10:58
sponsorJudah Gabriel Himango9-Jul-05 10:58 
GeneralRe: Rich Edit TextBox Pin
Anonymous9-Jul-05 11:04
Anonymous9-Jul-05 11:04 
GeneralRe: Rich Edit TextBox Pin
Anonymous9-Jul-05 12:14
Anonymous9-Jul-05 12:14 
GeneralAccessing the parallel port Pin
asif amjad9-Jul-05 9:22
asif amjad9-Jul-05 9:22 
GeneralRe: Accessing the parallel port Pin
Anonymous9-Jul-05 11:38
Anonymous9-Jul-05 11:38 
GeneralRemoving selected text from a string Pin
Member 20300389-Jul-05 8:19
Member 20300389-Jul-05 8:19 
GeneralRe: Removing selected text from a string Pin
Snowblind379-Jul-05 8:29
Snowblind379-Jul-05 8:29 
GeneralRe: Removing selected text from a string Pin
User 66589-Jul-05 8:34
User 66589-Jul-05 8:34 

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.