/// <summary> /// GetRetByDept /// </summary> /// <param name="RetID">Retrieval ID</param> /// <returns></returns> public List<ReqAllocation> getRetByDept(string RetID) { int retID = Convert.ToInt32(RetID); List<ReqAllocation> reqAllocationList = new List<ReqAllocation>(); //hashmap-like to store itemID and collated qty Dictionary<string, int> itemQtyENGL = new Dictionary<string, int>(); Dictionary<string, int> itemQtyCPSC = new Dictionary<string, int>(); Dictionary<string, int> itemQtyCOMM = new Dictionary<string, int>(); Dictionary<string, int> itemQtyREGR = new Dictionary<string, int>(); Dictionary<string, int> itemQtyZOOL = new Dictionary<string, int>(); //obtain list of requisition with specified RetID List<Requisition> reqList = ctx.Requisition.Where(x => x.RetID == retID).ToList(); foreach(Requisition req in reqList) { //obtain list of requisition detail with ReqID List<RequisitionDetail> reqDetailList = ctx.RequisitionDetail.Where(x => x.ReqID == req.ReqID).ToList(); foreach(RequisitionDetail reqDetail in reqDetailList) { if (req.DeptID == "ENGL") { //if itemQty does not contain the item, add item to itemQty if (!itemQtyENGL.ContainsKey(reqDetail.ItemID)) { itemQtyENGL.Add(reqDetail.ItemID, (int)reqDetail.IssueQty); } //else if itemQty contains item, add the qty to existing qty else { itemQtyENGL["reqDetail.ItemID"] += (int)reqDetail.IssueQty; } } if (req.DeptID == "CPSC") { //if itemQty does not contain the item, add item to itemQty if (!itemQtyCPSC.ContainsKey(reqDetail.ItemID)) { itemQtyCPSC.Add(reqDetail.ItemID, (int)reqDetail.IssueQty); } //else if itemQty contains item, add the qty to existing qty else { itemQtyCPSC["reqDetail.ItemID"] += (int)reqDetail.IssueQty; } } if (req.DeptID == "COMM") { //if itemQty does not contain the item, add item to itemQty if (!itemQtyCOMM.ContainsKey(reqDetail.ItemID)) { itemQtyCOMM.Add(reqDetail.ItemID, (int)reqDetail.IssueQty); } //else if itemQty contains item, add the qty to existing qty else { itemQtyCOMM["reqDetail.ItemID"] += (int)reqDetail.IssueQty; } } if (req.DeptID == "REGR") { //if itemQty does not contain the item, add item to itemQty if (!itemQtyREGR.ContainsKey(reqDetail.ItemID)) { itemQtyREGR.Add(reqDetail.ItemID, (int)reqDetail.IssueQty); } //else if itemQty contains item, add the qty to existing qty else { itemQtyREGR["reqDetail.ItemID"] += (int)reqDetail.IssueQty; } } if (req.DeptID == "ZOOL") { //if itemQty does not contain the item, add item to itemQty if (!itemQtyZOOL.ContainsKey(reqDetail.ItemID)) { itemQtyZOOL.Add(reqDetail.ItemID, (int)reqDetail.IssueQty); } //else if itemQty contains item, add the qty to existing qty else { itemQtyZOOL["reqDetail.ItemID"] += (int)reqDetail.IssueQty; } } } } //extract all keys and values in itemQty string[] itemQtyENGLKeys = itemQtyENGL.Keys.ToArray(); int[] itemQtyENGLValues = itemQtyENGL.Values.ToArray(); string[] itemQtyCPSCKeys = itemQtyCPSC.Keys.ToArray(); int[] itemQtyCPSCValues = itemQtyCPSC.Values.ToArray(); string[] itemQtyCOMMKeys = itemQtyCOMM.Keys.ToArray(); int[] itemQtyCOMMValues = itemQtyCOMM.Values.ToArray(); string[] itemQtyREGRKeys = itemQtyREGR.Keys.ToArray(); int[] itemQtyREGRValues = itemQtyREGR.Values.ToArray(); string[] itemQtyZOOLKeys = itemQtyZOOL.Keys.ToArray(); int[] itemQtyZOOLValues = itemQtyZOOL.Values.ToArray(); //create and add ReqAllocation for ENGL Dept for (int i = 0; i < itemQtyENGL.Count; i++) { ReqAllocation reqAllocation = new ReqAllocation(); reqAllocation.ItemID = itemQtyENGLKeys[i]; reqAllocation.RequestQty = itemQtyENGLValues[i]; reqAllocation.Dept = "ENGL"; reqAllocationList.Add(reqAllocation); } //create and add ReqAllocation for CPSC Dept for (int i = 0; i < itemQtyCPSC.Count; i++) { //create and add new ReqAllocation ReqAllocation reqAllocation = new ReqAllocation(); reqAllocation.ItemID = itemQtyCPSCKeys[i]; reqAllocation.RequestQty = itemQtyCPSCValues[i]; reqAllocation.Dept = "CPSC"; reqAllocationList.Add(reqAllocation); } //create and add ReqAllocation for COMM Dept for (int i = 0; i < itemQtyCOMM.Count; i++) { //create and add new ReqAllocation ReqAllocation reqAllocation = new ReqAllocation(); reqAllocation.ItemID = itemQtyCOMMKeys[i]; reqAllocation.RequestQty = itemQtyCOMMValues[i]; reqAllocation.Dept = "COMM"; reqAllocationList.Add(reqAllocation); } //create and add ReqAllocation for REGR Dept for (int i = 0; i < itemQtyREGR.Count; i++) { //create and add new ReqAllocation ReqAllocation reqAllocation = new ReqAllocation(); reqAllocation.ItemID = itemQtyREGRKeys[i]; reqAllocation.RequestQty = itemQtyREGRValues[i]; reqAllocation.Dept = "REGR"; reqAllocationList.Add(reqAllocation); } //create and add ReqAllocation for ZOOL Dept for (int i = 0; i < itemQtyZOOL.Count; i++) { //create and add new ReqAllocation ReqAllocation reqAllocation = new ReqAllocation(); reqAllocation.ItemID = itemQtyZOOLKeys[i]; reqAllocation.RequestQty = itemQtyZOOLValues[i]; reqAllocation.Dept = "ZOOL"; reqAllocationList.Add(reqAllocation); } return reqAllocationList; }
/// <summary> /// GetReqAllocation /// </summary> /// <param name="RetID">Requisition ID</param> /// <returns></returns> public List<ReqAllocation> getReqAllocation(string RetID) { int retID = Convert.ToInt32(RetID); List<Requisition> reqList = ctx.Requisition.Where(x => x.RetID == retID).ToList(); List<ReqAllocation> reqAllocationList = new List<ReqAllocation>(); foreach(Requisition req in reqList) { List<RequisitionDetail> reqDetailList = ctx.RequisitionDetail.Where(x => x.ReqID == req.ReqID).ToList(); foreach (RequisitionDetail reqDetail in reqDetailList) { ReqAllocation reqAllocation = new ReqAllocation(); reqAllocation.ItemID = reqDetail.ItemID; reqAllocation.ReqID = req.ReqID; reqAllocation.Dept = req.DeptID; if(req.PriorityID == 1) reqAllocation.Priority = "HIGH"; else reqAllocation.Priority = "LOW"; reqAllocation.RequestQty = (int) reqDetail.RequestQty; if (reqDetail.IssueQty == null) { reqAllocation.IssueQty = 0; } else { reqAllocation.IssueQty = (int)reqDetail.IssueQty; } reqAllocationList.Add(reqAllocation); } } return reqAllocationList; }