Beispiel #1
0
        /// <summary>
        ///     This function is for preventing kneading command from executing.
        /// </summary>
        /// <param name="terminalNo"></param>
        /// <param name="kneadingCommandResult"></param>
        public async Task StopKneadingCommand(string terminalNo, FindKneadingCommandItem kneadingCommandResult)
        {
            var sentFromAtoC = Constants.F55_Status.SentFromAToC.ToString("D");

            //	Get Updated Date 3 from [f55_updatedate] in “tx55_kndcmdmsrsnd” table
            //where [f55_kndcmdno] is equal to CmdNo, [f55_prepdtlotno] is equal to LotNo above AND [f55_status] is “Sent from A to C” (or “0”)
            var kndcmdmsrsnds = _unitOfWork.KndCmdMsrSndRepository.GetAll();

            kndcmdmsrsnds = kndcmdmsrsnds.Where(x => x.F55_KndCmdNo.Trim()
                                                .Equals(kneadingCommandResult.F42_KndCmdNo.Trim()));
            kndcmdmsrsnds =
                kndcmdmsrsnds.Where(x => x.F55_PrePdtLotNo.Trim().Equals(kneadingCommandResult.LotNo.Trim()));
            kndcmdmsrsnds = kndcmdmsrsnds.Where(x => x.F55_Status.Trim().Equals(sentFromAtoC));
            var kndcmdmsrsnd = kndcmdmsrsnds.FirstOrDefault();

            if (kndcmdmsrsnd != null)
            {
                //•	Delete that record from “tx55_kndcmdmsrsnd” table where [f55_kndcmdno] is equal to CmdNo,
                //[f55_prepdtlotno] is equal to LotNo, [f55_updatedate] is equal to Updated Date 3 above AND [f55_status] is “Sent from A to C” (or “0”).
                try
                {
                    _unitOfWork.KndCmdMsrSndRepository.Delete(kndcmdmsrsnd);
                    _unitOfWork.Commit();
                }
                catch (Exception ex)
                {
                    throw new Exception("MSG12");
                }
                ////If the query runs well but no record is affected from the above query, system shows message MSG 12
                //var affectedItem =
                //    _unitOfWork.KndCmdMsrSndRepository.Get(
                //        x => x.F55_KndCmdNo.Trim().Equals(kneadingCommandResult.F42_KndCmdNo.Trim())
                //             && x.F55_PrePdtLotNo.Trim().Equals(kneadingCommandResult.LotNo.Trim())
                //             && x.F55_Status.Trim().Equals(sentFromAtoC)
                //             && (x.F55_UpdateDate == kndcmdmsrsnd.F55_UpdateDate));

                ////If the query runs well but no record is affected from the above query, system shows message MSG 12
                //if (affectedItem == null)
                //    throw new Exception("MSG12");
            }

            //•	Update [f42_status] in “tx42_kndcmd” table of that record to “Forced Completed”,
            //where [f42_kndcmdno] is equal to CmdNo, [f42_prepdtlotno] is equal to LotNo and [f42_updatedate] is equal to Updated Date 2 above
            var tx42Records = _unitOfWork.KneadingCommandRepository.GetAll();

            tx42Records =
                tx42Records.Where(x => x.F42_KndCmdNo.Trim().Equals(kneadingCommandResult.F42_KndCmdNo.Trim()));
            tx42Records = tx42Records.Where(x => x.F42_PrePdtLotNo.Trim().Equals(kneadingCommandResult.LotNo.Trim()));
            tx42Records = tx42Records.Where(x => x.F42_UpdateDate.Equals(kneadingCommandResult.UpdateDate2));

            foreach (var tx42Record in tx42Records)
            {
                tx42Record.F42_Status = Constants.F42_Status.TX42_Sts_FrcCmp;
            }

            //•	Suppose Lot Amount, Lot End Amount and Updated Date 4 are retrieved from [f39_prepdtlotamt], [f39_endlotamont] and [f39_updatedate]
            //of “tx39_pdtpln” table where [f39_preproductcode] is equal to Pre-product Code and [f39_kndeptbgndate] is equal to Production Date above
            var f39Records = _unitOfWork.PdtPlnRepository.GetAll();

            f39Records =
                f39Records.Where(x => x.F39_PreProductCode.Trim()
                                 .Equals(kneadingCommandResult.F42_PreProductCode.Trim()));
            f39Records = f39Records.Where(x => x.F39_KndEptBgnDate.Equals(kneadingCommandResult.ProductionDate));
            var f39Record = f39Records.FirstOrDefault();

            if (f39Record == null)
            {
                throw new Exception();
            }

            //•	System re-checks whether the kneading command is stopped or not by checking if there is
            //any existing record from “tx55_kndcmdmsrsnd” table where [f55_kndcmdno] is equal to CmdNo and [f55_status] is “Sent from A to C” (or “0”)

            var kndcmdmsrsndItem =
                _unitOfWork.KndCmdMsrSndRepository.Get(
                    i =>
                    i.F55_KndCmdNo.Trim().Equals(kneadingCommandResult.F42_KndCmdNo.Trim()) &&
                    i.F55_Status.Equals(sentFromAtoC));

            //	If there is no record found, means the kneading command is over.
            if (kndcmdmsrsndItem == null)
            {
                //System will double check if Lot Amount is equal to Lot End Amount plus 1.
                ////If it is correct, then Kneading is truly over
                if (f39Record.F39_PrePdtLotAmt == f39Record.F39_EndLotAmont + 1)
                {
                    //Once the Kneading is over, system will update [f39_status] of that record in “tx39_pdtpln”
                    //table to “Completed” and increment [f39_endlotamont] by 1, where [f39_kndeptbgndate] is equal to Production Date and [f39_updatedate] is equal to Updated Date 4
                    var tx39PdtplnRecords = _unitOfWork.PdtPlnRepository.GetAll();
                    tx39PdtplnRecords =
                        tx39PdtplnRecords.Where(x => x.F39_KndEptBgnDate == kneadingCommandResult.ProductionDate);
                    tx39PdtplnRecords = tx39PdtplnRecords.Where(x => x.F39_UpdateDate == f39Record.F39_UpdateDate);

                    foreach (var tx39PdtplnRecord in tx39PdtplnRecords)
                    {
                        tx39PdtplnRecord.F39_Status = Constants.F39_Status.Completed.ToString("D");
                        tx39PdtplnRecord.F39_EndLotAmont++;
                        _unitOfWork.PdtPlnRepository.Update(tx39PdtplnRecord);
                    }
                }
            }
            else
            {
                //	If there is existing record found, which means the kneading is not over yet.
                //Then system updates [f39_endlotamont] of that record in “tx39_pdtpln” table by increment itself by 1,
                //where [f39_kndeptbgndate] is equal to Production Date and [f39_updatedate] is equal to Updated Date 4.
                var tx39PdtplnRecords = _unitOfWork.PdtPlnRepository.GetAll();
                tx39PdtplnRecords =
                    tx39PdtplnRecords.Where(x => x.F39_KndEptBgnDate == kneadingCommandResult.ProductionDate);
                tx39PdtplnRecords = tx39PdtplnRecords.Where(x => x.F39_UpdateDate == f39Record.F39_UpdateDate);

                foreach (var tx39PdtplnRecord in tx39PdtplnRecords)
                {
                    tx39PdtplnRecord.F39_EndLotAmont++;
                    tx39PdtplnRecord.F39_KndEptBgnDate = kneadingCommandResult.ProductionDate;
                    tx39PdtplnRecord.F39_UpdateDate    = f39Record.F39_UpdateDate;

                    _unitOfWork.PdtPlnRepository.Update(tx39PdtplnRecord);
                }
            }

            // Save changes.
            _unitOfWork.Commit();
        }
Beispiel #2
0
        /// <summary>
        /// Stop kneading command process execution.
        /// </summary>
        /// <param name="kneadingCommand"></param>
        /// <returns></returns>
        public ActionResult Stop(FindKneadingCommandItem kneadingCommand)
        {
            try
            {
                if (kneadingCommand == null)
                {
                    kneadingCommand = new FindKneadingCommandItem();
                    TryValidateModel(kneadingCommand);
                }

                if (!ModelState.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(Json(FindValidationErrors(ModelState)));
                }

                // Trim everything.
                if (!string.IsNullOrEmpty(kneadingCommand.F03_PreProductName))
                {
                    kneadingCommand.F03_PreProductName = kneadingCommand.F03_PreProductName.Trim();
                }

                if (!string.IsNullOrEmpty(kneadingCommand.F39_ColorClass))
                {
                    kneadingCommand.F39_ColorClass = kneadingCommand.F39_ColorClass.Trim();
                }

                if (!string.IsNullOrEmpty(kneadingCommand.F42_KndCmdNo))
                {
                    kneadingCommand.F42_KndCmdNo = kneadingCommand.F42_KndCmdNo.Trim();
                }

                if (!string.IsNullOrEmpty(kneadingCommand.F42_PreProductCode))
                {
                    kneadingCommand.F42_PreProductCode = kneadingCommand.F42_PreProductCode.Trim();
                }

                if (!string.IsNullOrEmpty(kneadingCommand.KneadingStatus))
                {
                    kneadingCommand.KneadingStatus = kneadingCommand.KneadingStatus.Trim();
                }

                if (!string.IsNullOrEmpty(kneadingCommand.LotNo))
                {
                    kneadingCommand.LotNo = kneadingCommand.LotNo.Trim();
                }

                if (!string.IsNullOrEmpty(kneadingCommand.ProductStatus))
                {
                    kneadingCommand.ProductStatus = kneadingCommand.ProductStatus.Trim();
                }

                // Find terminal from request.
                var terminalNo = _identityService.FindTerminalNo(HttpContext.User.Identity);
                _kneadingStartEndControlDomain.StopKneadingCommand(terminalNo, kneadingCommand);
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            catch (Exception exception)
            {
                if (exception.Message.Equals("MSG12", StringComparison.InvariantCultureIgnoreCase))
                {
                    Response.Headers["x-process-error"] = MessageResource.MSG12;
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }