473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Help constructing a class !

Hello,

I develop in ASP.NET with VB.NET code.

I need some help constructing a class: Worker. I'm designing the
properties of this class.
The class is filled reading tables in database.

Properties of Class Worker:
- ID_Card
- Names of Person
- ID_Current_Company
- Name of Current Company
- Is Worker working at the company? (Yes, No)
- Projects that worker worked in
- Project 1 (ID and name)
- Project 2 (ID and name)
- Project 3 (ID and name)
- ...

My problem is with property Projects_Worked_In. A worker could have
been in many projects. I don't know how many projects a worker has
worked at. It could be only 1 project or 5 projects.

How would you desing this property Projects_Worked_In of class Worker?

I was thinking to:
- Define 50 properties like Project1, Project2, Project3,... Project50,
all of them initialized in NULL
- Define a property Number_Of_Projects and according to that I will
know if I have to display Project1, Project2, Project3, etc.

Problem is what happen if Number_Of_Projects 50

Thank you for your help !

Oct 12 '06 #1
6 1221
pass it in as a delimited string then parse it in the class.
"Big George" <jb*****@gmail.comwrote in message news:11**********************@b28g2000cwb.googlegr oups.com...
Hello,

I develop in ASP.NET with VB.NET code.

I need some help constructing a class: Worker. I'm designing the
properties of this class.
The class is filled reading tables in database.

Properties of Class Worker:
- ID_Card
- Names of Person
- ID_Current_Company
- Name of Current Company
- Is Worker working at the company? (Yes, No)
- Projects that worker worked in
- Project 1 (ID and name)
- Project 2 (ID and name)
- Project 3 (ID and name)
- ...

My problem is with property Projects_Worked_In. A worker could have
been in many projects. I don't know how many projects a worker has
worked at. It could be only 1 project or 5 projects.

How would you desing this property Projects_Worked_In of class Worker?

I was thinking to:
- Define 50 properties like Project1, Project2, Project3,... Project50,
all of them initialized in NULL
- Define a property Number_Of_Projects and according to that I will
know if I have to display Project1, Project2, Project3, etc.

Problem is what happen if Number_Of_Projects 50

Thank you for your help !

Oct 12 '06 #2
You use a collection instead. You could actually do this in several ways.
You could create a NameValueCollection (located in the
System.Collections.Specialized namespace). This way you could put an id and
name into the collection. In this case, most people would probably put the
ID number as the name, and the name of the project as the value. You create
the namevaluecollection just as you would any other field. Then, you can add
projects to it as needed.

for example:
// initialize the collection
private NameValueCollection col = new NameValueCollection

then you can add to it such as:
col.Add(Id1.ToString(),"ProjectName1");
That's assuming that Id1 is a number.

Now, what if you wanted to make that a property. You woud do it like so

public NameValueCollection Projects
{
get
{
return col;
}
set
{
col = value;
}
}
You cuold then access it like so:
Worker.Projects.Add("1","Project1");
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Big George" <jb*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hello,

I develop in ASP.NET with VB.NET code.

I need some help constructing a class: Worker. I'm designing the
properties of this class.
The class is filled reading tables in database.

Properties of Class Worker:
- ID_Card
- Names of Person
- ID_Current_Company
- Name of Current Company
- Is Worker working at the company? (Yes, No)
- Projects that worker worked in
- Project 1 (ID and name)
- Project 2 (ID and name)
- Project 3 (ID and name)
- ...

My problem is with property Projects_Worked_In. A worker could have
been in many projects. I don't know how many projects a worker has
worked at. It could be only 1 project or 5 projects.

How would you desing this property Projects_Worked_In of class Worker?

I was thinking to:
- Define 50 properties like Project1, Project2, Project3,... Project50,
all of them initialized in NULL
- Define a property Number_Of_Projects and according to that I will
know if I have to display Project1, Project2, Project3, etc.

Problem is what happen if Number_Of_Projects 50

Thank you for your help !

Oct 12 '06 #3
Properties of Class Worker:
- ID_Card
- Names of Person
- ID_Current_Company
- Name of Current Company
- Is Worker working at the company? (Yes, No)
- Projects that worker worked in
- Project 1 (ID and name)
- Project 2 (ID and name)
- Project 3 (ID and name)
- ...

My problem is with property Projects_Worked_In. A worker could have
been in many projects. I don't know how many projects a worker has
worked at. It could be only 1 project or 5 projects.

How would you desing this property Projects_Worked_In of class Worker?

I was thinking to:
- Define 50 properties like Project1, Project2, Project3,... Project50,
all of them initialized in NULL
- Define a property Number_Of_Projects and according to that I will
know if I have to display Project1, Project2, Project3, etc.

Problem is what happen if Number_Of_Projects 50
Forget these ways to hell...

1) You have to make second class - Project (props ID and Name).
2) Add property Worker.Projects of type IList(Of Project), or other
collection-type.

....than, you can have any number of project that the worker worked on and
coding like this:
Worker.Project.Add(FirstProject)
Worker.Project.Add(SecondProject)
Worker.Project.Remove(FirstProject)
Worker.Project.Count

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
Oct 12 '06 #4
Thank you Robert !
>
Forget these ways to hell...

1) You have to make second class - Project (props ID and Name).
2) Add property Worker.Projects of type IList(Of Project), or other
collection-type.

...than, you can have any number of project that the worker worked on and
coding like this:
Worker.Project.Add(FirstProject)
Worker.Project.Add(SecondProject)
Worker.Project.Remove(FirstProject)
Worker.Project.Count

Robert Haken [MVP ASP/ASP.NET]
HAVIT, s.r.o., www.havit.cz
http://knowledge-base.havit.cz
Oct 12 '06 #5
Maybe you are stil on line:

How do you declare and instance these classes:

Private oWorker as Worker(myID_Card)

' Then how do you instance or call class "Project" ?
' Is enough to do:
oWorker.Project.Add(FirstProject)

But .NET doesn't allow this

Sorry about my ignorance

Oct 12 '06 #6
It depends on what type the "Project" field is.

Let's just say for the sake of argument that it's some type of
collection, Depending on the requirements of the class, you usually
instantiate it when you make a new instance of your Worker class:

public class Worker {

private List<Project_projects;
public List<ProjectProjects {
get { return _projects; }
set { _projects = value; }
}

public Worker() {
_projects = new List<Project>();
}
}

Then, whereever else in your code you can then add like so:

private oWorker = new Worker();
oWorker.Projects.Add(FirstProject);
oWorker.Projects.Add(SecondProject);
int projectCount = oWorker.Projects.Count;

you get the idea.

hope that helps!

Sean

Big George wrote:
Maybe you are stil on line:

How do you declare and instance these classes:

Private oWorker as Worker(myID_Card)

' Then how do you instance or call class "Project" ?
' Is enough to do:
oWorker.Project.Add(FirstProject)

But .NET doesn't allow this

Sorry about my ignorance
Oct 13 '06 #7

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

Similar topics

2
by: Simon Harvey | last post by:
Hi all, I am trying to get my win forms application to start, but I'm hitting a problem which I am certain is really simple. The start for my application is ApplicationManager.cs. This class...
8
by: Don | last post by:
I have a third party C++ DLL that I am trying to use from C#. The specific function I am trying to use is declared in C++ as follows: ladybugConvertToMultipleBGRU32( LadybugContext ...
4
by: perryschon | last post by:
Can someone please help me out with the Visual Basic source code needed that allows configuration and usage of comm ports in any PC? I am constructing an asynchronous serial communication RS-232...
6
by: JoshforRefugee | last post by:
heard that we can do automatic code generation using macros, but not sure how can I pursue this. Here is my problem. In my env, I have class A,B and C. All of them has constructors, and few...
11
by: davecph | last post by:
I'm constructing a website with a layout created with div-tags. They have a fixed width, float left, and display inline. When one of the div's contain a select-element the right-most div floats down...
1
by: nabil | last post by:
Hi I have probleam while while initilazing nested class ... I needs to create a object 'b' of B(nested class) in A(surrounding class). while constructing b I have to pass pointer of funtion...
3
by: hjast | last post by:
test has exited due to signal 10 (SIGBUS). This is the circle class #include <iostream.h> class Shape {
1
by: Brent White | last post by:
I can't figure out what I'm doing differently with this one drop-down list control from the other two that are working just fine. Background: I am constructing a page that will allow a user to...
24
by: Joe, G.I. | last post by:
Can anyone help me w/ a priority_queue. I'm generating MyEvent classes and I put them on a priority_queue, but I don't know how to get them in priority. The priority is the event w/ the smallest...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.