Is an Enum or a 2d Array the solution im looking for?  
Author Message
dynamicdon





PostPosted: Fri Jan 19 05:41:16 CST 2007 Top

Visual C#.Net >> Is an Enum or a 2d Array the solution im looking for?

I have a status text on my status bar which simply lists the logged in
user name.

the code that puts text into this is:

stUserName.Text = "Currently logged in user: " +
System.Environment.UserName;

However our login names here are firstname, surname initial, like so: -


freds

I'd like to write the status strip as:

Currently logged in user: Firstname Surname (logged in user)

e.g.

Currently logged in user: Fred Smith (freds)

So i need to way of linking a list which I can populate myself of names
with user names.

I looked at enums but it would seem they only allow you to assign names
to numbers.
Whereas i need to assign full names to user names.

I could use lots of 'if's' but id rather have one collection that
simply has Fullname, and associated username if possible.

Whats the best way to do this?

Thanks,

Gary.

DotNet50  
 
 
Daniel





PostPosted: Fri Jan 19 05:41:16 CST 2007 Top

Visual C#.Net >> Is an Enum or a 2d Array the solution im looking for? Hi

Yes you dont want an enum for this.

Don't you have a database that they are logging into and it checks their
details when they log in surely? And that contains the full name, surname
etc and you can retrieve the details from there?

If you dont have that, a little worrying, then i suppose a struct like:

struct Names
{
string loginname;
string FirstName;
string LastName;
}

and then a:

List<Names> NameList = new List();

and do tis to populate for each

public void AddName(string loginName, string firstName, string LastName)
{
Names n;
n.LoginName = loginName;
n.FirstName = firstName;
n.LastName = lastName;

NameList.Add(n);
}

And then once you have that list you can check the user against that by
iterating through and comparing the loginName part.






>I have a status text on my status bar which simply lists the logged in
> user name.
>
> the code that puts text into this is:
>
> stUserName.Text = "Currently logged in user: " +
> System.Environment.UserName;
>
> However our login names here are firstname, surname initial, like so: -
>
>
> freds
>
> I'd like to write the status strip as:
>
> Currently logged in user: Firstname Surname (logged in user)
>
> e.g.
>
> Currently logged in user: Fred Smith (freds)
>
> So i need to way of linking a list which I can populate myself of names
> with user names.
>
> I looked at enums but it would seem they only allow you to assign names
> to numbers.
> Whereas i need to assign full names to user names.
>
> I could use lots of 'if's' but id rather have one collection that
> simply has Fullname, and associated username if possible.
>
> Whats the best way to do this?
>
> Thanks,
>
> Gary.
>


 
 
Bobbo





PostPosted: Fri Jan 19 06:01:45 CST 2007 Top

Visual C#.Net >> Is an Enum or a 2d Array the solution im looking for?


> Don't you have a database that they are logging into and it checks their
> details when they log in surely? And that contains the full name, surname
> etc and you can retrieve the details from there?

Gary,

Daniel's comments regarding your login procedure are seriously worth
noting, although if you must proceed with maintaining a list of users,
you could probably [unless anyone else knows of any limitations] extend
the List<> suggestion to use Dictionary<>. This allows the object to
be stored against a key, in your case the 'freds' string.

This assumes .net 2.0 by the way.

e.g. You might have a simple class to store the user details,
pre-empting the requirement to store extra information in future.

class Employee
{
string _forename;
string _surname;

public Employee(string forename, string surname)
{
Forename = forename;
Surname = surname;
}

public string Forename
{
get { return _forename; }
private set { _forename = value; }
}

public string Surname
{
get { return _surname; }
private set { _surname = value; }
}
}


Then at the point where you obtain your list of employees, you'd add
them to the dictionary list thus:

Dictionary<string, Employee> employeeList = new
Dictionary<string, Employee>();

// Loop through list of employees from database here
employeeList.Add("freds", new Employee("Fred", "Smith"));


And finally when you need to retrieve the employee:

string userId = "freds";
Employee thisUser = employeeList[userId];
string loggedInUser = string.Format("{0} {1} ({2})",
thisUser.Forename, thisUser.Surname, userId);

 
 
Daniel





PostPosted: Fri Jan 19 06:17:45 CST 2007 Top

Visual C#.Net >> Is an Enum or a 2d Array the solution im looking for? ...and in case your debating the 2 methods and no database option, Bobbo's
is more of a complete solution. Go for that.




>

>
>> Don't you have a database that they are logging into and it checks their
>> details when they log in surely? And that contains the full name, surname
>> etc and you can retrieve the details from there?
>
> Gary,
>
> Daniel's comments regarding your login procedure are seriously worth
> noting, although if you must proceed with maintaining a list of users,
> you could probably [unless anyone else knows of any limitations] extend
> the List<> suggestion to use Dictionary<>. This allows the object to
> be stored against a key, in your case the 'freds' string.
>
> This assumes .net 2.0 by the way.
>
> e.g. You might have a simple class to store the user details,
> pre-empting the requirement to store extra information in future.
>
> class Employee
> {
> string _forename;
> string _surname;
>
> public Employee(string forename, string surname)
> {
> Forename = forename;
> Surname = surname;
> }
>
> public string Forename
> {
> get { return _forename; }
> private set { _forename = value; }
> }
>
> public string Surname
> {
> get { return _surname; }
> private set { _surname = value; }
> }
> }
>
>
> Then at the point where you obtain your list of employees, you'd add
> them to the dictionary list thus:
>
> Dictionary<string, Employee> employeeList = new
> Dictionary<string, Employee>();
>
> // Loop through list of employees from database here
> employeeList.Add("freds", new Employee("Fred", "Smith"));
>
>
> And finally when you need to retrieve the employee:
>
> string userId = "freds";
> Employee thisUser = employeeList[userId];
> string loggedInUser = string.Format("{0} {1} ({2})",
> thisUser.Forename, thisUser.Surname, userId);
>


 
 
Gary





PostPosted: Fri Jan 19 08:54:16 CST 2007 Top

Visual C#.Net >> Is an Enum or a 2d Array the solution im looking for? Hi thanks,

no database solution, this is a simple app and there are less than 20
users here.

thanks for your suggestions, i'll try to implement them!

Gary



> ...and in case your debating the 2 methods and no database option, Bobbo's
> is more of a complete solution. Go for that.
>
>


> >

> >
> >> Don't you have a database that they are logging into and it checks their
> >> details when they log in surely? And that contains the full name, surname
> >> etc and you can retrieve the details from there?
> >
> > Gary,
> >
> > Daniel's comments regarding your login procedure are seriously worth
> > noting, although if you must proceed with maintaining a list of users,
> > you could probably [unless anyone else knows of any limitations] extend
> > the List<> suggestion to use Dictionary<>. This allows the object to
> > be stored against a key, in your case the 'freds' string.
> >
> > This assumes .net 2.0 by the way.
> >
> > e.g. You might have a simple class to store the user details,
> > pre-empting the requirement to store extra information in future.
> >
> > class Employee
> > {
> > string _forename;
> > string _surname;
> >
> > public Employee(string forename, string surname)
> > {
> > Forename = forename;
> > Surname = surname;
> > }
> >
> > public string Forename
> > {
> > get { return _forename; }
> > private set { _forename = value; }
> > }
> >
> > public string Surname
> > {
> > get { return _surname; }
> > private set { _surname = value; }
> > }
> > }
> >
> >
> > Then at the point where you obtain your list of employees, you'd add
> > them to the dictionary list thus:
> >
> > Dictionary<string, Employee> employeeList = new
> > Dictionary<string, Employee>();
> >
> > // Loop through list of employees from database here
> > employeeList.Add("freds", new Employee("Fred", "Smith"));
> >
> >
> > And finally when you need to retrieve the employee:
> >
> > string userId = "freds";
> > Employee thisUser = employeeList[userId];
> > string loggedInUser = string.Format("{0} {1} ({2})",
> > thisUser.Forename, thisUser.Surname, userId);
> >