//1.檢查必要的input parameter public static void ValidateParameter(MoConfirmChangeResult result) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { List<string> NotNullItemList = new List<string> {"MoNumber", "SerialNumber", "Result"}; logger.DebugFormat("MoConfirmChangeResult: \r\n{0}", ObjectTool.ObjectTostring(result)); ObjectTool.CheckNullData(NotNullItemList, result); //if (result.MoNumber == "") //{ // throw new Exception("This MoNumber :" + result.MoNumber + " is no data"); //} //if (result.SerialNumber == "") //{ // throw new Exception("This SerialNumber :" + result.SerialNumber + " is no data"); //} //if (result.ItemNumber == "") //{ // throw new Exception("This ItemNumber :" + result.ItemNumber + " is no data"); //} //if (result.Result == "") //{ // throw new Exception("This Result :" + result.Result + " is no data"); //} //log.DebugFormat("Header: {0}", moheader.ToString()); //log.DebugFormat("Header: \r\n{0}", ObjectTool.ObjectTostring(result)); } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }
public static string UpdateStatus(MoConfirmChangeResult CFCResult) { string Message = ""; string TxnId = CFCResult.SerialNumber; string MoNumber = CFCResult.MoNumber; string Result = CFCResult.Result; SqlParameter outResult = SQLHelper.CreateSqlParameter("@ReturnMessage", 255, "", ParameterDirection.Output); SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionString_CFG(), System.Data.CommandType.StoredProcedure, "SAP_MOConfirmResult", SQLHelper.CreateSqlParameter("@Function", 32, "MOConfirmChangeResult"), SQLHelper.CreateSqlParameter("@TxnId", 32, TxnId.Trim()), SQLHelper.CreateSqlParameter("@MoNumber", 20, MoNumber.Trim()), SQLHelper.CreateSqlParameter("@Result", 20, Result.Trim()), outResult); Message = outResult.Value.ToString(); return Message; }
//2.檢查資料內容 public static void CheckData(MoConfirmChangeResult CFCResult) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { if (Common.SQL.CheckSentData(CFCResult.SerialNumber, CFCResult.MoNumber) == "N") { { throw new Exception("SerialNumber :" + CFCResult.SerialNumber + " or " + " MoNumber : " + CFCResult.MoNumber + " is not exists in IMES SendData table"); } } } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }
public void MoConfirmChangeResult(MoConfirmChangeResult Result) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); string msgName="MOConfirmChangeResult"; try { if (Result == null) { IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, msgName, "" , "" , "", "", "", EnumMsgState.Received, ""); throw new Exception("Result is Null"); } else { IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, msgName, String.IsNullOrEmpty(Result.MoNumber) ? "" : Result.MoNumber, String.IsNullOrEmpty(Result.Result) ? "" : Result.Result, String.IsNullOrEmpty(Result.SerialNumber) ? "" : Result.SerialNumber, "", "", EnumMsgState.Received, ""); } //1.檢查必要的input parameter Execute.ValidateParameter(Result); //2.檢查資料內容 Execute.CheckData(Result); //3.執行DB insert Execute.Process(Result); //4.Build Response Message //MoReleaseResponse mrealease = Execute.BuildResponseMsg(moheader, true, ""); //return mrealease; IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, msgName, String.IsNullOrEmpty(Result.MoNumber) ? "" : Result.MoNumber, String.IsNullOrEmpty(Result.Result) ? "" : Result.Result, String.IsNullOrEmpty(Result.SerialNumber) ? "" : Result.SerialNumber, "", Result.Result == "T" ? "" : Result.ErrorMessage, Result.Result == "T" ? EnumMsgState.Success : EnumMsgState.Fail, ""); if (Result.Result != "T") { UTL.SendMail("ebook result of MOConfirmChange fail (MO: " + Result.MoNumber + ", Result: " +Result.ErrorMessage + ")", "MO: " + Result.MoNumber + ", Result: " +Result.ErrorMessage); } } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); if (Result == null) { IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, msgName, "" , "", "" , "", e.Message, EnumMsgState.Fail, ""); } else { IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, msgName, String.IsNullOrEmpty(Result.MoNumber) ? "" : Result.MoNumber, String.IsNullOrEmpty(Result.Result) ? "" : Result.Result, String.IsNullOrEmpty(Result.SerialNumber) ? "" : Result.SerialNumber, "", e.Message, EnumMsgState.Fail, ""); } UTL.SendMail(msgName + " fail", e.Message); //4.Build Response Error Message } finally { BaseLog.LoggingEnd(logger, methodName); } }
//3.執行DB insert public static void Process(MoConfirmChangeResult CFCResult) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { using (TransactionScope txn = UTL.CreateDbTxn()) { //1 UpdateStatus string Message = SQL.UpdateStatus(CFCResult); BaseLog.LoggingInfo(logger, Message); // 最後一行 txn.Complete(); } } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }