I'm designing a view that shows the location of some boxes in an inventory, I'll put it in an image here
In each box the first data is the part number, the second is the amount of things you have and the third is the priority in which they have to leave and that method is the one that I want to fix since it is not automatic and I can not find a way to do it that is done by a method, this is the way I am doing it.
foreach (var p in cajas.OrderBy(c => c.fecha))
{
if (p.partNumber == "10-sag")
{
p.fifo = i;
i++;
}
if (p.partNumber == "10-qt")
{
p.fifo = j;
j++;
}
}
I want you to do the same thing, keep a count of the order in which the box must be removed but this count is independent according to the partNumber, what I do not want is that if for example a new part is entered and the partNumber is not none of the two that are there in the if have to go to add it.
I leave the object's constructor too
class Caja
{
public string partNumber;
public int fifo;
public DateTime fecha;
public int quantity;
public int position;
public int orderColumn;
public int boxnum;
public Caja(string partNumber, int fifo, int quantity, int position, DateTime fecha, int orderColumn, int boxnum)
{
this.partNumber = partNumber;
this.fifo = fifo;
this.quantity = quantity;
this.position = position;
this.fecha = fecha;
this.orderColumn = orderColumn;
this.boxnum = boxnum;
}
}
and with this method return the color of the oldest box is red
class CajaCollection : List<Caja>
{
public Color ObtenerColorCaja(Caja caja)
{
return ObtenerColorCaja(IndexOf(caja));
}
public Color ObtenerColorCaja(int index)
{
// Localiza la primera caja ordenando por fecha y con el mismo partNumber
var primeraCaja = this.OrderBy(c => c.fecha)
.First(c => c.partNumber == this[index].partNumber);
// Si el índice coincide es la primera a salir (rojo), si no verde
return index == IndexOf(primeraCaja) ? Color.Red : Color.Green;
}
}