Stock data is transferred the next day to LINQ

Closing on the last day should be the starting value on the next day.

I tried this

var k = INV_STOCKs.Select(x => new DemoItemV1 { AreaId = x.STOCK_DATE, CategoryTitle = x.STOCK_QTY }) .AsEnumerable() .Select((x, i) => { x.ID = i + 1; return x }) .ToList(); 

Table structure

ID, STOCK_DATE, STOCK_QTY

Please anyone can help solve this problem.

I need to print like this

  Date Opening Stock Closing Stock 01/01/13 0 5 01/02/13 5 10 01/03/13 10 15 01/04/13 15 22 01/05/13 22 30 

Thanks in advance.

+8
c # linq
source share
2 answers

"I need to type" Date "," Opening "," close "in it"

 INV_STOCKs.GroupBy(x=>x.STOCK_DATE).ForEach(group=> { var g = group.OrderBy(x.ID); Print(g.First().STOCK_DATE); //Date Print(g.First().STOCK_QTY); //Opening stock Print(g.Last().STOCK_QTY); //Closing stock }); 

Printing is some way of printing this value, of course, you can use one method with three parameters or any other :)

EDIT: to save it to the list:

 class StockStore { public int OpeningStock; public int ClosingStock; public DateTime Date; } var list = new List<StockStore>(); INV_STOCKs.GroupBy(x=>x.STOCK_DATE).ForEach(group=> { var g = group.OrderBy(x.ID); list.Add(new StockStore { OpeningStock = g.First().STOCK_QTY, ClosingStock = g.Last().STOCK_QTY, Date = g.First().STOCK_DATE }); }); 
+3
source share

Something like that.

  var lastStockItem = INV_Stocks .OrderByDescending(x=>x.StOCK_Date) .FirstorDefault(); 

This will give you the last element of the day of the day.

0
source share

All Articles