Example #1
0
        //1.檢查必要的input parameter
        public static void ValidateParameter(MoConfirmResult[] results)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            BaseLog.LoggingBegin(logger, methodName);
            try
            {
                List<string> NotNullItemList = new List<string> {"MoNumber",
                                                                                              "SerialNumber",
                                                                                               "Result"};

                foreach (MoConfirmResult item in results)
                {
                    logger.DebugFormat("MoConfirmResult: \r\n{0}", ObjectTool.ObjectTostring(item));
                }

                foreach (MoConfirmResult item in results)
                {
                    ObjectTool.CheckNullData(NotNullItemList, item);
                }

                //if (string.IsNullOrEmpty( result.MoNumber) )
                //{
                //    throw new Exception("This MoNumber is no data");
                //}

                //if (string.IsNullOrEmpty( result.SerialNumber))
                //{
                //    throw new Exception("This SerialNumber  is no data");
                //}

                //if (string.IsNullOrEmpty( result.Result))
                //{
                //    throw new Exception("This Result  is no data");
                //}


                        
            }
            catch (Exception e)
            {
                BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);
                throw e;
            }
            finally
            {
               BaseLog.LoggingEnd(logger, methodName);
            }                        
        }
Example #2
0
        public static string UpdateStatus(MoConfirmResult CFResult)
        {
            string Message = "";
            string TxnId = CFResult.SerialNumber;
            string MoNumber = CFResult.MoNumber;
            string Result = CFResult.Result;
            SqlParameter outResult = SQLHelper.CreateSqlParameter("@ReturnMessage", 255, "", ParameterDirection.Output);
            SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionString_CFG(),
                                    System.Data.CommandType.StoredProcedure,
                                    "SAP_MOConfirmResult",
                                    SQLHelper.CreateSqlParameter("@Function", 32, "MOConfirmResult"),
                                    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;

        }
Example #3
0
        //2.檢查資料內容
        public static void CheckData(MoConfirmResult[] CFResults)
        {            
            string methodName = MethodBase.GetCurrentMethod().Name;
            BaseLog.LoggingBegin(logger, methodName);
            try
            {

                if (Common.SQL.CheckSentData(CFResults[0].SerialNumber, CFResults[0].MoNumber) == "N")
                {
                    { throw new Exception("SerialNumber :" + CFResults[0].SerialNumber + " or " + " MoNumber : " + CFResults[0].MoNumber + "  is not exists in IMES SendData table"); }
                }             
            }
            catch (Exception e)
            {
                BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);
                throw e;
            }
            finally
            {
                BaseLog.LoggingEnd(logger, methodName);
            }
        }
Example #4
0
        //3.執行DB insert 
        public static void Process(MoConfirmResult[] CFResults)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            BaseLog.LoggingBegin(logger, methodName);
            try
            {
                MoConfirmResult CFResult = new MoConfirmResult();
                CFResult.MoNumber = CFResults[0].MoNumber;
                CFResult.SerialNumber= CFResults[0].SerialNumber;
                CFResult.ItemNumber = CFResults[0].ItemNumber;
                CFResult.Result = "T";

                foreach (MoConfirmResult item in CFResults)
                {
                    if (item.Result == "F")
                    {
                        CFResult.Result = "F";
                        break;
                    }
                }
 
                using (TransactionScope txn = UTL.CreateDbTxn())
                {
                    //0.Lock SystemSetting Name='ConfirmMOResultLock'
                    int timespan = IMES.WS.Common.SQL.ConCurrentLock("ConfirmMOResultLock");
                    BaseLog.LoggingInfo(logger, "ConfirmMOResult Lock time span:" + timespan.ToString());  
                    //1 UpdateStatus
                    string Message=SQL.UpdateStatus(CFResult);
                    BaseLog.LoggingInfo(logger,Message);
                    // 最後一行
                    txn.Complete();
                }                

            }
            catch (Exception e)
            {
                BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);
                throw e;
            }
            finally
            {
                BaseLog.LoggingEnd(logger, methodName);
            }          
        }
Example #5
0
        public void MoConfirmResult(MoConfirmResult[] Result)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            BaseLog.LoggingBegin(logger, methodName);
            string msgName="MOConfirmResult";
            try
            {
                string errorMsg = "";
                string returnMsg = "";
                foreach (MoConfirmResult item in Result)
                {
                    returnMsg = "";
                    if (item.Result == "T" && item.ErrorMessage.Trim() != "")
                    {
                        returnMsg = item.ErrorMessage.Trim().Substring(18, (item.ErrorMessage.Trim().Length - 18));
                    }
                    if (item.Result == "T" && returnMsg != "") 
                    {
                        errorMsg = errorMsg + item.ErrorMessage + "(Success)" + "\n";
                    }
                    else if (item.Result != "T")
                    {
                        errorMsg = errorMsg + item.ErrorMessage + "(Fail)" + "\n";
                    }

                }
                if (Result != null && Result.Length > 0)
                    IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive,
                                                        msgName,
                                                        String.IsNullOrEmpty(Result[0].MoNumber) ? "" : Result[0].MoNumber,
                                                        String.IsNullOrEmpty(Result[0].Result) ? "" : Result[0].Result,
                                                        String.IsNullOrEmpty(Result[0].SerialNumber) ? "" : Result[0].SerialNumber,
                                                        "",
                                                        //Result = "T" also has errorMsg!
                                                        //Result[0].Result == "T" ? Result[0].ErrorMessage.Trim().Substring(18, (Result[0].ErrorMessage.Trim().Length - 18)) : Result[0].ErrorMessage,
                                                        errorMsg,
                                                        EnumMsgState.Received,
                                                        "");
                else
                {
                    IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive,
                                                        msgName,
                                                         "",
                                                         "",
                                                       "",
                                                        "",
                                                        "",
                                                        EnumMsgState.Received,
                                                        "");
                    throw new Exception("MoConfirmResult[] lenght is 0");
                }
                //1.檢查必要的input parameter
                Execute.ValidateParameter(Result);

                //2.檢查資料內容
                Execute.CheckData(Result);

                lock (objLock)
                {
                    //3.執行DB insert 
                    Execute.Process(Result);

                    //4. Query SAP MO Status by SAP WebService
                    SAPClient.QuerySAPMOStatus(Result[0].MoNumber);
                }

                //4.Build Response Message
                //MoReleaseResponse mrealease = Execute.BuildResponseMsg(moheader, true, "");
                //return mrealease;
                
                IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, 
                                                   msgName,
                                                   String.IsNullOrEmpty( Result[0].MoNumber) ? "":Result[0].MoNumber, 
                                                   String.IsNullOrEmpty( Result[0].Result)?"":Result[0].Result, 
                                                   String.IsNullOrEmpty( Result[0].SerialNumber)?"":Result[0].SerialNumber,
                                                   "",
                                                   //Result = "T" also has errorMsg!
                                                   //Result[0].Result == "T" ? "" : errorMsg,
                                                   errorMsg,
                                                   Result[0].Result == "T" ? EnumMsgState.Success : EnumMsgState.Fail, 
                                                   "");
               try
               {
                   DataTable dt = IMES.WS.Common.SQL.GetConfirmMoData(String.IsNullOrEmpty(Result[0].SerialNumber) ? "" : Result[0].SerialNumber,
                                                       String.IsNullOrEmpty(Result[0].MoNumber) ? "" : Result[0].MoNumber);
                   if (dt.Rows.Count > 0)
                   {
                       int DeliveredQty = (int)dt.Rows[0]["DeliveredQty"];
                       string Model = (string)dt.Rows[0]["Model"];
                       //Result = "T" also has errorMsg, need to send mail #2012/07/02
                       if (errorMsg != "")
                       {
                           BaseLog.LoggingInfo(logger, "ebook result of MOConfirm (MO:{0}, Model:{1}, Confirm Qty:{2})", Result[0].MoNumber, Model, DeliveredQty);
                           BaseLog.LoggingInfo(logger, "ebook result of MOConfirm Content:\nMO:{0},\nModel:{1},\nConfirm Qty:{2},\nResult:\n{3}", Result[0].MoNumber, Model, DeliveredQty, errorMsg);

                           UTL.SendMail("ebook result of MOConfirm (MO:" + Result[0].MoNumber + ", Model:" + Model + ", Confirm Qty:" + DeliveredQty + ")",
                                        "MO:" + Result[0].MoNumber + ",\nModel:" + Model + ",\nConfirm Qty:" + DeliveredQty + ",\nResult:\n" + errorMsg);
                       }                     
                   }
               }
               catch (Exception e)
               {
                   BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);
               }
                finally
                {
                    BaseLog.LoggingEnd(logger, methodName);
                }
            }
            catch (Exception e)
            {
                if (Result != null && Result.Length > 0)
                    IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive,
                                                        msgName,
                                                        String.IsNullOrEmpty(Result[0].MoNumber) ? "" : Result[0].MoNumber,
                                                        String.IsNullOrEmpty(Result[0].Result) ? "" : Result[0].Result,
                                                        String.IsNullOrEmpty(Result[0].SerialNumber) ? "" : Result[0].SerialNumber,
                                                        "",
                                                       e.Message,
                                                        EnumMsgState.Fail,
                                                        "");
                else
                     IMES.WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive,
                                                        msgName,
                                                         "",
                                                         "",
                                                       "",
                                                        "",
                                                       e.Message,
                                                        EnumMsgState.Fail,
                                                        "");

               
                BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);

                UTL.SendMail(msgName + " fail", e.Message);
                //4.Build Response Error Message
            }
            finally
            {
                BaseLog.LoggingEnd(logger, methodName);
            }
         }