public async Task <ActionResult> Load(GridSettings gridSettings, Constants.KndLine kneadingCommandLine = Constants.KndLine.Conventional) { try { // Request parameters to server are invalid. if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(FindValidationErrors(ModelState))); } var loadKneadingCommandResult = await _kneadingLineNoDomain.LoadKneadingCommands(gridSettings, kneadingCommandLine); return(Json(loadKneadingCommandResult.Data)); } catch (Exception exception) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } }
public ActionResult Retrieval(string containerType, Constants.KndLine kneadingLine, string colorClass) { var terminalNo = _identityDomain.FindTerminalNo(HttpContext.User.Identity); var deviceCode = _configurationService.PreProductDeviceCode; var isCheckedConveyor = _commonDomain.CheckStatusAndNumberRecordOfConveyor(terminalNo); if (!isCheckedConveyor) { return(Json(new { Success = false, Message = PreProductManagementResources.MSG13 })); } var checkedDeviceStatus = _commonDomain.CheckStatusOfDeviceRecordForProductManagement(deviceCode); if (!checkedDeviceStatus) { return(Json(new { Success = false, Message = PreProductManagementResources.MSG14 })); } var result = _preProductManagementDomain.Retrieval(containerType, terminalNo, kneadingLine, colorClass); if (result == null) { return(Json(new { Success = false, Message = PreProductManagementResources.MSG21 })); } return(Json(new { Success = true, result })); }
/// <summary> /// This function is for start kneading commands. /// </summary> /// <param name="terminalNo"></param> /// <param name="kneadingCommandResults"></param> /// <param name="kneadingLine"></param> public async Task StartKneadingCommand(string terminalNo, IList <FindKneadingCommandItem> kneadingCommandResults, Constants.KndLine kneadingLine) { // Refine terminal number by using specific rule defined in document. terminalNo = RefineTerminalNo(terminalNo); // Check whether the first record matches with the condition found or not. var bConditionMet = false; foreach (var kneadingCommandResult in kneadingCommandResults) { // Whether condition statisfied or not. var isConditionSatisfied = false; // If Kneading Status is “Kneading” AND Product Status is “Terminating”, check if the selected record is the first record in data window or not. if (kneadingCommandResult.KneadingStatus.Trim().Equals(Constants.F42_Status.TX42_Sts_Knd) && kneadingCommandResult.ProductStatus.Trim() .Equals(Constants.F39_Status.Terminating.ToString("D"))) { if (!bConditionMet) { //If yes, update [f39_status] in “tx39_pdtpln” table to “Kneading”, where [f39_preproductcode] //is equal to Pre-product Code, //[f39_kndeptbgndate] is equal to Production Date and [f39_updatedate] is equal to Updated Date 1 var productPlans = _unitOfWork.PdtPlnRepository.GetAll(); productPlans = productPlans.Where( x => x.F39_PreProductCode.Trim() .Equals(kneadingCommandResult.F42_PreProductCode.Trim()) && x.F39_KndEptBgnDate.Equals(kneadingCommandResult.ProductionDate) && x.F39_UpdateDate.Equals(kneadingCommandResult.UpdatedDate1)); foreach (var productPlan in productPlans) { productPlan.F39_Status = Constants.F39_Status.Kneading.ToString("D"); } isConditionSatisfied = true; } } // If Kneading Status is “Not Kneaded” AND (Product Status is “Commanded” OR “Terminating” OR “Termination”) //if (kneadingCommandResult.KneadingStatus.Equals(Constants..ToString("D")) // && (kneadingCommandResult.ProductStatus.Equals(Constants.F39_Status.Terminating.ToString("D") || )) // If Kneading Status is “Not Kneaded” AND (Product Status is “Commanded” OR “Terminating” OR “Termination”), then: if (kneadingCommandResult.KneadingStatus.Trim().Equals(Constants.F42_Status.TX42_Sts_NotKnd) && (kneadingCommandResult.ProductStatus.Trim().Equals(Constants.F39_Status.Commanded.ToString("D")) || kneadingCommandResult.ProductStatus.Trim() .Equals(Constants.F39_Status.Terminating.ToString("D")) || kneadingCommandResult.ProductStatus.Trim().Equals(Constants.F39_Status.Termination.ToString("D")))) { // Find the current system time. var systemTime = DateTime.Now; var tx55Kndcmdmsrsnds = _unitOfWork.KndCmdMsrSndRepository.GetAll(); tx55Kndcmdmsrsnds = tx55Kndcmdmsrsnds.Where( x => x.F55_KndCmdNo.Trim().Equals(kneadingCommandResult.F42_KndCmdNo.Trim()) && x.F55_PrePdtLotNo.Trim().Equals(kneadingCommandResult.LotNo.Trim())); var tx55Kndcmdmsrsnd = await tx55Kndcmdmsrsnds.FirstOrDefaultAsync(); //var isInsert = false; if (tx55Kndcmdmsrsnd == null) { tx55Kndcmdmsrsnd = new TX55_KndCmdMsrSnd(); tx55Kndcmdmsrsnd.F55_KndCmdNo = kneadingCommandResult.F42_KndCmdNo; tx55Kndcmdmsrsnd.F55_PrePdtLotNo = kneadingCommandResult.LotNo; tx55Kndcmdmsrsnd.F55_PrePdtCode = kneadingCommandResult.F42_PreProductCode; tx55Kndcmdmsrsnd.F55_Status = Constants.F55_Status.SentFromAToC.ToString("D"); tx55Kndcmdmsrsnd.F55_Priority = "0"; tx55Kndcmdmsrsnd.F55_MsrSndCls = kneadingLine.ToString("D"); tx55Kndcmdmsrsnd.F55_TerminalNo = terminalNo; tx55Kndcmdmsrsnd.F55_PictureNo = Constants.PictureNo.TCPS041F; tx55Kndcmdmsrsnd.F55_AbnormalCode = ""; tx55Kndcmdmsrsnd.F55_AddDate = systemTime; tx55Kndcmdmsrsnd.F55_UpdateDate = systemTime; _unitOfWork.KndCmdMsrSndRepository.Add(tx55Kndcmdmsrsnd); //isInsert = true; } //if (isInsert) // _unitOfWork.KndCmdMsrSndRepository.Add(tx55Kndcmdmsrsnd); /* * o Check if the selected record is the first record in data window. * If yes, update [f39_status] in “tx39_pdtpln” table to “Kneading”, * where [f39_preproductcode] is equal to Pre-product Code, [f39_kndeptbgndate] is equal to Production Date and [f39_updatedate] is equal to Updated Date 1. */ if (!bConditionMet) { var result = kneadingCommandResult; var productPlans = _unitOfWork.PdtPlnRepository.GetAll(); productPlans = productPlans.Where( x => x.F39_PreProductCode.Trim().Equals(result.F42_PreProductCode.Trim()) && (x.F39_KndEptBgnDate == result.ProductionDate) && (x.F39_UpdateDate == result.UpdatedDate1)); //var tx39Pdtpln = // _unitOfWork.PdtPlnRepository.Get( // x => // x.F39_PreProductCode.Trim().Equals(result.F42_PreProductCode) && // (x.F39_KndEptBgnDate == result.ProductionDate) && // (x.F39_UpdateDate == result.UpdatedDate1)); //if (tx39Pdtpln != null) // tx39Pdtpln.F39_Status = Constants.F39_Status.Kneading.ToString("D"); var productPlan = await productPlans.FirstOrDefaultAsync(); if (productPlan != null) { productPlan.F39_Status = Constants.F39_Status.Kneading.ToString("D"); _unitOfWork.PdtPlnRepository.Update(productPlan); } isConditionSatisfied = true; } } if (isConditionSatisfied) { bConditionMet = true; } } //System sends message to C4/C5 .... var lsSndMsg = "1002" + terminalNo + "Tcps041f" + "0020"; if (lsSndMsg.Length != 20) { throw new Exception("MSG 9"); } _notificationService.SendMessageToC4(lsSndMsg); // Save changes to database. var records = await _unitOfWork.CommitAsync(); }
/// <summary> /// Load kneading commands from database. /// </summary> /// <param name="gridSettings"></param> /// <param name="kneadingCommandline"></param> /// <returns></returns> public async Task <ResponseResult <GridResponse <object> > > LoadKneadingCommands(GridSettings gridSettings, Constants.KndLine kneadingCommandline) { var kneadingLineMegabit = Constants.KndLine.Megabit.ToString("D"); // Find all kneading commands (TX42_KndCmd) var kneadingCommands = _unitOfWork.KneadingCommandRepository.GetAll(); // Find all Preproducts (TM03_PreProduct) var preProducts = _unitOfWork.PreProductRepository.GetAll(); // Find all product plans. var productPlans = _unitOfWork.PdtPlnRepository.GetAll(); var outsidePreProduct = Constants.F42_OutSideClass.PreProduct.ToString("D"); // Please refer document 3.2.1 UC 6: View Kneading command due to the complex query. if (kneadingCommandline == Constants.KndLine.Conventional) { kneadingCommands = kneadingCommands.Where(x => x.F42_KndCmdNo.Trim().StartsWith("A")); } else { kneadingCommands = kneadingCommands.Where(x => x.F42_KndCmdNo.Trim().StartsWith("B")); } kneadingCommands = kneadingCommands.Where(x => x.F42_OutSideClass.Equals(outsidePreProduct)); // Maximum value of [f42_kndcmdbookno] in TX42_KNDCMD. var maximumKneadingCommandBookNo = await kneadingCommands.MaxAsync(x => (int?)x.F42_KndCmdBookNo) ?? 0; kneadingCommands = kneadingCommands.Where(x => x.F42_KndCmdBookNo == maximumKneadingCommandBookNo); // Find kneading commands from repositories. var loadKneadingCommandsResult = from kneadingCommand in kneadingCommands from preproduct in preProducts from productPlan in productPlans where preproduct.F03_PreProductCode.Trim().Equals(kneadingCommand.F42_PreProductCode.Trim()) && preproduct.F03_PreProductCode.Trim().Equals(productPlan.F39_PreProductCode.Trim()) && kneadingCommand.F42_KndEptBgnDate.Equals(productPlan.F39_KndEptBgnDate) select new FindKneadingCommandItem { F42_KndCmdNo = kneadingCommand.F42_KndCmdNo, F42_PreProductCode = kneadingCommand.F42_PreProductCode, F03_PreProductName = preproduct.F03_PreProductName, ProductStatus = productPlan.F39_Status, LotNo = kneadingCommand.F42_PrePdtLotNo, F39_ColorClass = kneadingCommandline == Constants.KndLine.Megabit ? null : preproduct.F03_ColorClass.Trim(), KneadingStatus = kneadingCommand.F42_Status, UpdatedDate1 = productPlan.F39_UpdateDate, UpdateDate2 = kneadingCommand.F42_UpdateDate, ProductionDate = kneadingCommand.F42_KndEptBgnDate, F42_CommandSeqNo = kneadingCommand.F42_CommandSeqNo, F42_LotSeqNo = kneadingCommand.F42_LotSeqNo }; //Ascending order by: [f42_commandseqno], then [f42_lotseqno] loadKneadingCommandsResult = loadKneadingCommandsResult.OrderBy(x => x.F42_KndCmdNo).ThenBy(x => x.LotNo); // Count the total record which matches with the conditions. var totalRecords = await loadKneadingCommandsResult.CountAsync(); var realPageIndex = gridSettings.PageIndex - 1; // Do pagination. loadKneadingCommandsResult = loadKneadingCommandsResult.Skip(realPageIndex * gridSettings.PageSize) .Take(gridSettings.PageSize); // Build a grid and respond to client. var resultModel = new GridResponse <object>(loadKneadingCommandsResult, totalRecords); return(new ResponseResult <GridResponse <object> >(resultModel, true)); }
/// <summary> /// Load kneading commands from database. /// </summary> /// <param name="gridSettings"></param> /// <param name="kneadingCommandline"></param> /// <returns></returns> public async Task <ResponseResult <GridResponse <object> > > LoadKneadingCommands(GridSettings gridSettings, Constants.KndLine kneadingCommandline) { var kneadingLineMegabit = Constants.KndLine.Megabit.ToString("D"); // Find all kneading commands (TX42_KndCmd) var kneadingCommands = _unitOfWork.PdtPlnRepository.GetAll(); // Find all Preproducts (TM03_PreProduct) var preProducts = _unitOfWork.PreProductRepository.GetAll(); if (kneadingCommandline == Constants.KndLine.Conventional) { kneadingCommands = kneadingCommands.Where(x => x.F39_KneadingLine.Trim().Equals("1")); } else { kneadingCommands = kneadingCommands.Where(x => x.F39_KneadingLine.Trim().Equals("0")); } kneadingCommands = kneadingCommands.Where(x => x.F39_Status.Trim() != "0"); var loadKneadingCommandsResult = from kneadingCommand in kneadingCommands join preproduct in preProducts on kneadingCommand.F39_PreProductCode.Trim() equals preproduct.F03_PreProductCode.Trim() select new PdtPlnItem1 { F39_KndCmdNo = kneadingCommand.F39_KndCmdNo, F39_PreProductCode = kneadingCommand.F39_PreProductCode, F03_PreProductName = preproduct.F03_PreProductName, LotNo = kneadingCommand.F39_StartLotNo, MaterialAmount = kneadingCommand.F39_PrePdtLotAmt, F39_Status = kneadingCommand.F39_Status == "0" ? "Yet" : kneadingCommand.F39_Status == "1"? "Command": kneadingCommand.F39_Status == "2" ? "Produce" : kneadingCommand.F39_Status == "3" ? "End" : kneadingCommand.F39_Status == "4" ? "F End" : kneadingCommand.F39_Status == "5" ? "Stopped" : kneadingCommand.F39_Status == "6" ? "Stopping" : "" }; //Ascending order by: [F39_commandseqno], then [F39_lotseqno] loadKneadingCommandsResult = loadKneadingCommandsResult.OrderBy(x => new { x.F39_KndCmdNo }); // Count the total record which matches with the conditions. var totalRecords = await loadKneadingCommandsResult.CountAsync(); var realPageIndex = gridSettings.PageIndex - 1; // Do pagination. loadKneadingCommandsResult = loadKneadingCommandsResult.Skip(realPageIndex * gridSettings.PageSize) .Take(gridSettings.PageSize); // Build a grid and respond to client. var resultModel = new GridResponse <object>(loadKneadingCommandsResult, totalRecords); return(new ResponseResult <GridResponse <object> >(resultModel, true)); }