1
I’m having trouble making a method to check two lists. This method will receive a list which is the list that has been added to the order and the Purchase Order Id to which that order has been associated. The method calls another method that returns from the database the list of items in the purchase request. So, at this point I have 2 lists: one received as a parameter with the items being added to the request, and the other I searched in the database with the items of the request.
I need to check if the items that are in the request are in the request, IE, check that the items in the list I received as parameter are in the items in the list that came from the bank. If so, I need to check if this item has already been purchased (I have a Boolean property for this), and if it has not been purchased I need to mark this property as true
and let this item pass to be registered.
I also need to check that these lists have no item that was not requested in the purchase request, IE, the buyer can not buy without a requisition for this item.
All items that should not be in the order, either because it was already purchased or because it was not requested, must be removed by the system. After registering the request, I have to display the list of items that were removed by the system.
I know it’s gotten really big because it’s a complex process but if anyone can help me with it, I’ve tried it all day today, but it’s always a loophole.
Code of the Method
public ControlePedidoRCM ControlePedidoRCM(int IdRCM, List<MaterialPedido> IdMaterial)
{
RCMDal rd = new RCMDal();
ControlePedidoRCM Controle = new ViewModel.ControlePedidoRCM();
List<int> Comprados = new List<int>();
List<int> Fora = new List<int>();
List<MaterialRCM> itens = rd.ListarItens(IdRCM).ToList();
foreach(var item in itens)
{
for(int i = 0; i < IdMaterial.Count; i++)
{
//se o material estiver na lista de RCM
if(item.MaterialID == IdMaterial[i].MaterialID)
{
if(item.Comprado == true)
{
//ja foi comprado
Comprados.Add(item.MaterialID);
}
}
else
{
//não está na RCM
Fora.Add(item.MaterialID);
}
}
}
Controle.Comprado = Comprados;
Controle.Fora = Fora;
return Controle;
}
A hint: your question is very difficult to understand, so I imagine you are having problems because you cannot divide the task into parts. Let go of the IDE for a few minutes and try writing - and in English, not in code - what the program should do. Write a sequence of steps. Then highlight the steps you can take and the ones you can’t. This makes you able to isolate the error easier and helps us to help you.
– Oralista de Sistemas
Another thing that might help: have you noticed that several programmers, even older ones, usually have dolls on their desks? Get a doll and try to explain your problem to him. I am serious. It may even be that with this you do not solve your problem, but at least you will have a clearer idea of the causes of your problem.
– Oralista de Sistemas
@Renan I use a rubber duck.
– Leonel Sanches da Silva
@Alanalmeida You can put examples of your code in the question?
– Leonel Sanches da Silva
Thanks for the tips, I’ll see if I can get some dolls put on my table rsrs.. as for the code I’ve touched him so much that now I think he’s already far from reaching the goal, I’m going to tidy him up to leave him the way he was when I got closer to doing what I need, then I update the question.
– Alan Almeida
Renan and Gypsy, I put the code.
– Alan Almeida
It’s gotten a lot better and it’s understandable now. Just two more things: First, we don’t know your client’s entire business rule, so we can only analyze the logical part of how the code works. Second, you were able to put together two lists - one for "in" products and one for "out" products. What, in no more than five words, is missing?
– Oralista de Sistemas
Look, difficult in less than five words, this is the first version of this method, the problem is, suppose I receive as parameter a list with 3 materials, Ids 1, 2, 3 and in the list that came from the bank the same thing, what happens that in Id one passes normal, but the other two he puts in the list of items that are out of the requisition, ie the other two fall into the LSE and are placed on the list as if they were out of the purchase request.
– Alan Almeida