473,474 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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.

Jan 19 '07 #1
4 1713
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.


"Gary" <ga********@myway.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
>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.

Jan 19 '07 #2

Daniel wrote:
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, EmployeeemployeeList = 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);

Jan 19 '07 #3
....and in case your debating the 2 methods and no database option, Bobbo's
is more of a complete solution. Go for that.
"Bobbo" <ro************@choicequote.co.ukwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...
>
Daniel wrote:
>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, EmployeeemployeeList = 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);

Jan 19 '07 #4
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

Daniel wrote:
...and in case your debating the 2 methods and no database option, Bobbo's
is more of a complete solution. Go for that.
"Bobbo" <ro************@choicequote.co.ukwrote in message
news:11**********************@s34g2000cwa.googlegr oups.com...

Daniel wrote:
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, EmployeeemployeeList = 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);
Jan 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pjotr Wedersteers | last post by:
Hi I am not even sure if it is at all possible, and I can't find the stuff I am looking for, probably using the wrong search keys. WAMP machine (XP, 2.50.2, 4.1.5, 5.0.2) I have a field in...
10
by: Russell Shaw | last post by:
Hi, gcc-3.4 complains about non-integers in: enum {IDENTIFIER = "<identifier>", WIDGETDEF = "widgetdef"}; even if i cast the strings to integers.
3
by: Richard | last post by:
Okay gang, This should be simple but apparently it's not... I want to use the System.DayOfWeek enum to create and access an array of objects with one object for each day of the week. I'd like...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
6
by: Steven Woody | last post by:
is there any way in C leting me iterate all integer constants in a enum type ? their values might not be continue. thanks. - woody
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
12
by: Cmtk Software | last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI managed c++ and from C#. I defined the following enum in a VS dll project set to be compiled with the /clr switch: ...
1
by: toton | last post by:
Hi, I have an enum as enum DitectionType{ X,Y,XD,YD } ; Now I want to wrap it with a class which returns orthogonal direction for it. i.e X -Y , Y-X, XD-YD, YD->XD mapping should be there. I...
13
by: Rohit | last post by:
Is there any way by which I can find number of elements in an enum list? Generally I use one last element at the end to find out total number of elements. e.g. typedef enum{ SUN, MON, TUE,...
3
by: theBNich | last post by:
Hi, I currently have an enumeration in class Lexer: enum lexType { /* token keywords */ lexIF, lexTHEN, lexWHILE, lexDO, lexBEGIN, lexEND, lexELSE, lexPROGRAM, ... /*...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.