private void GenerateItem(int kanbanReqId, int partFGId, int lotNumber) { List <MsPartStructure> partStructs = DbContext.MsPartStructure.Where(a => a.PartFGId == partFGId).ToList(); foreach (MsPartStructure partStruct in partStructs) { KanbanReqItem item = new KanbanReqItem(); item.KanbanReqId = kanbanReqId; item.PartId = partStruct.PartId; double usage = partStruct.Usage; double partNum = lotNumber * usage; item.EstKanban = 0; item.ReqKanban = 0; MsPart part = DbContext.MsPart.Where(a => a.PartId == partStruct.PartId).FirstOrDefault(); if (part != null) { item.EstKanban = (int)Math.Ceiling(partNum / part.LotSize); StockWH stock = DbContext.StockWH.Where(a => a.PartNo == part.PartNo).FirstOrDefault(); if (stock != null) { item.ReqKanban = partNum < stock.StockQty ? item.EstKanban : (int)Math.Floor(stock.StockQty / part.LotSize); } } DbContext.KanbanReqItem.Add(item); DbContext.SaveChanges(); } }
private void SetViewBagItem(KanbanReqItem data) { MsPart part = DbContext.MsPart.Where(a => a.PartId == data.PartId).FirstOrDefault(); if (part != null) { ViewBag.PartName = part.PartName; ViewBag.PartNo = part.PartNo; ViewBag.Supplier = part.Supplier; } }
public void Initialize(string authorizationToken) { lock (locker) { List <KanbanRequest> reqList = DbContext.KanbanRequest.Where(a => a.StatusId == 3).ToList(); List <KanbanItem> reqItems = new List <KanbanItem>(); foreach (KanbanRequest request in reqList) { short lineNo = 0; string lineName = ""; MsPartFG fg = DbContext.MsPartFG.Where(a => a.PartFGId == request.PartFGId).FirstOrDefault(); if (fg != null) { MsLine line = DbContext.MsLine.Where(a => a.LineId == fg.LineId).FirstOrDefault(); if (line != null) { lineNo = line.LineNo; lineName = line.LineName; } } List <KanbanReqItem> items = DbContext.KanbanReqItem.Where(a => a.KanbanReqId == request.KanbanReqId).ToList(); foreach (KanbanReqItem item in items) { MsPart part = DbContext.MsPart.Where(a => a.PartId == item.PartId).FirstOrDefault(); if (part != null) { KanbanItem kanbanItem = new KanbanItem(); kanbanItem.ReqItemId = item.ReqItemId; kanbanItem.KanbanReqId = request.KanbanReqId; kanbanItem.RequestNo = request.TagRequestNo; kanbanItem.RequestDate = request.RequestDateTime.AddMilliseconds(-request.RequestDateTime.Millisecond); kanbanItem.ReqNo = request.TagRequestNo; kanbanItem.PartId = item.PartId; kanbanItem.PartNo = part.PartNo; kanbanItem.LotSize = part.LotSize; kanbanItem.Zone = part.Zone; kanbanItem.LineNo = lineNo; kanbanItem.LineName = lineName; kanbanItem.OrderQty = item.ReqKanban; reqItems.Add(kanbanItem); } } } ReqItems.Add(authorizationToken, Tuple.Create(DateTime.UtcNow.AddHours(1), reqItems)); } }