//1.檢查必要的input parameter public static void ValidateParameter(MoPullHeader header) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { logger.DebugFormat("Header: \r\n{0}", ObjectTool.ObjectTostring(header)); ObjectTool.CheckNullData(NotNullItemList, header); float data=0; if (!float.TryParse(header.IssuedQty, out data)) throw new Exception(" IssuedQty : " + header.IssuedQty + " is not number"); if (!float.TryParse(header.CurrentyIssueQty, out data)) throw new Exception(" CurrentyIssueQty : " + header.CurrentyIssueQty + " is not number"); } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }
//2.檢查資料內容 public static void CheckData(MoPullHeader moheader) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }
public MoPullReleaseResponse[] MoPullRelease(MoPullHeader[] moheaders) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); string msgName = "MOPullRelease"; string responseMsg = "MOPullReleaseResponse"; List<MoPullReleaseResponse> responseList = new List<MoPullReleaseResponse>(); foreach (MoPullHeader moheader in moheaders) { try { WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, msgName, string.IsNullOrEmpty(moheader.MoNumber) ? "" : moheader.MoNumber, string.IsNullOrEmpty(moheader.IssuedQty) ? "" : moheader.IssuedQty, string.IsNullOrEmpty(moheader.CurrentyIssueQty) ? "" : moheader.CurrentyIssueQty, "", "", EnumMsgState.Received, ""); //1.檢查必要的input parameter Execute.ValidateParameter(moheader); //2.檢查資料內容 //3.執行DB insert string ret = Execute.Process(moheader); //4.Build Response Message string errMsg = ""; MoPullReleaseResponse mrealease = Execute.BuildResponseMsg(moheader, ret, ref errMsg); WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Send, responseMsg, string.IsNullOrEmpty(moheader.MoNumber) ? "" : moheader.MoNumber, ret, string.IsNullOrEmpty(moheader.SerialNumber) ? "" : moheader.SerialNumber, "", "", EnumMsgState.Success, errMsg); responseList.Add(mrealease); } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); string errMsg = e.Message; MoPullReleaseResponse mrealease = Execute.BuildResponseMsg(moheader, "F", ref errMsg); WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Send, responseMsg, string.IsNullOrEmpty(moheader.MoNumber) ? "" : moheader.MoNumber, "F", string.IsNullOrEmpty(moheader.SerialNumber) ? "" : moheader.SerialNumber, "", e.Message, EnumMsgState.Fail, ""); responseList.Add(mrealease); } finally { BaseLog.LoggingEnd(logger, methodName); } } return responseList.ToArray(); }
public MoPullHeader(MoPullHeader header) { ObjectTool.CopyObject(header, this); }
//3.執行DB insert public static string Process(MoPullHeader header) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { string retvalue = ""; using (TransactionScope txn = UTL.CreateDbTxn()) { //1. update MO.Qty retvalue= SQL.UpdateMO(header); txn.Complete(); } if (retvalue == "F") { ISAPService SapService = ServiceAgent.getInstance().GetObjectByName<ISAPService>(WebConstant.ISAPService); string errorMsg=""; if (!SapService.UpdateMO(header.MoNumber, out errorMsg)) { BaseLog.LoggingError(logger, "call UpdateMO error Messag : {0}", errorMsg); } using (TransactionScope txn = UTL.CreateDbTxn()) { retvalue = SQL.UpdateMO(header); txn.Complete(); } } return retvalue; } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }
//4.Build Response message structure public static MoPullReleaseResponse BuildResponseMsg(MoPullHeader moheader, string ret, ref string errMsg) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { MoPullReleaseResponse response = new MoPullReleaseResponse(); response.MoNumber = moheader.MoNumber; response.SerialNumber = moheader.SerialNumber; response.Result = ret; if (ret != "T" && string.IsNullOrEmpty(errMsg) ) { errMsg = "Can not find MO [" + moheader.MoNumber + "]"; } response.ErrorMessage = errMsg; BaseLog.LoggingInfo(logger, "ResponseMsg: \r\n{0}", ObjectTool.ObjectTostring(response)); return response; } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); //SQL.InsertTxnDataLog("Send", "MoReleaseResponse", moheader.MoNumber, moheader.BuildOutMtl, moheader.TxnId, "",e.Message, "Fail",""); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }
public static string UpdateMO(MoPullHeader header) { string strSQL = @" IF Exists(select * from MO where MO=@MO) Begin UPDATE MO SET Qty=(case when @Qty>b.TotalQty then b.TotalQty else @Qty end), Status= (case when Status='R' then 'H' when Status='C' And Qty > Print_Qty then 'H' else Status end ), Udt=@Udt From MO a, MOData b WHERE a.MO = b.MO and a.MO=@MO IF Exists(select * from MOStatus where MO=@MO and Status='Close') Begin Update MOStatus Set Status='Release' where MO=@MO INSERT INTO MOStatusLog(MO, [Function], [Action], Station, PreStatus, Status, IsHold, HoldCode, TxnId, Comment, Editor, Cdt) Select @MO, 'WSMOPullRelease','UpdateMO', '','Close', Status,IsHold, HoldCode,@TxnId ,@Comment, @Editor, @Udt FROM MOStatus WHERE MO =@MO End Else Begin INSERT INTO MOStatusLog(MO, [Function], [Action], Station, PreStatus, Status, IsHold, HoldCode, TxnId, Comment, Editor, Cdt) Select @MO, 'WSMOPullRelease','UpdateMO', '',Status, Status,IsHold, HoldCode,@TxnId ,@Comment, @Editor, @Udt FROM MOStatus WHERE MO =@MO End set @Ret='T' End Else Begin set @Ret='F' End "; double totalqty = Math.Ceiling(float.Parse(header.IssuedQty)) + Math.Ceiling(float.Parse(header.CurrentyIssueQty)); string Comment = "IssuedQty:" + header.IssuedQty + " CurrentyIssueQty:" + header.CurrentyIssueQty; SqlParameter retPara = SQLHelper.CreateSqlParameter("@Ret", 8,"", ParameterDirection.Output); SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionString_CFG(), System.Data.CommandType.Text, strSQL, SQLHelper.CreateSqlParameter("@MO",20, header.MoNumber), SQLHelper.CreateSqlParameter("@Qty", (int) totalqty), SQLHelper.CreateSqlParameter("@TxnId", 16,header.SerialNumber), SQLHelper.CreateSqlParameter("@Comment", 255, Comment), SQLHelper.CreateSqlParameter("@Editor", 16,"SAP"), SQLHelper.CreateSqlParameter("@Udt", DateTime.Now), retPara); return retPara.Value.ToString(); }