List<> duplicate object problem

May 17 2010 4:22 PM

i have class called Artikl
it has few propertyes.. and one of them my be different for same artikl.. i don't how to explain this.. 
i have another class called Smetka (account) would be the english name.. that class holds list of objects of my first class
something like this

public class Smetka //(account) the english name for smetka..
{//... some code
List<Artikl> arts = new List<Artikl>();
// .. some code
}

public class Artikl
{

public string Name{get;set}
public int key{get;set}
public double amount{get;set}
public double stock{get;set}

}

i have dataBase where my Atril's are storred.. 
property called amount is not writen in the database.. and its value IS NOT set when I create the object.. i set the value later in the code..  now when i store some artikl.. i retreive the artikl from the database, i set it's amount property, than i check if amount is smaller then stock, then stock -=amount.. and finaly update chenges in the database..

hope you understand the purpose of my application.. now my problem is when i add Artikl in the art property of my smetka class, and if that Artikl already exist in the list, the amound property for all equals artik's changes, and it get equals the last artikl's property amount.. that's problem.. because you may first sell the first artikl, with amount of 3 peaces, than maybe on same account sell the 1 artikl with amount of 1 peacess.. , the program automatickli will change the amount property of all artikl's in the list..

how can i prevent this? how can i prevent amount property from all same objects from changes.. 

I hope you understand my problem, and i hope you will help me solve this.., sorry for my english.. 

Answers (8)