public bool UpdateMO(string moId, out string errorText) { errorText = ""; string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { // send MO to SAP //Query MO SAPWSQueryMO.Z_GET_PRODORD_TO_IMES_WSClient sapQueryMOClient = new SAPWSQueryMO.Z_GET_PRODORD_TO_IMES_WSClient("SAPQueryMO"); sapQueryMOClient.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["SAPUserName"].ToString(); sapQueryMOClient.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["SAPUserPwd"].ToString(); SAPWSQueryMO.ZMO_IMES_H QueryHeader = new SAPWSQueryMO.ZMO_IMES_H(); QueryHeader.MONUMBER = moId; QueryHeader.SERIALNUMBER = string.Format("{0:yyyyMMddHHmmssfff}", DateTime.Now); SAPWSQueryMO.ZE1RESBL[] items = new SAPWSQueryMO.ZE1RESBL[0]; SAPWSQueryMO.ZE1AFKOL header = sapQueryMOClient.Z_GET_PRODORD_TO_IMES(QueryHeader, ref items); //regenerate WS moHeader WSMORelease MoRelease = new WSMORelease(); MoHeader moHeader = new MoHeader(); List<MoItemDetail> moItems =new List<MoItemDetail>(); #region map moHedaer moHeader.BasicFinishDate = header.BASICFINISHDATE; moHeader.BasicStartDate = header.BASICSTARTDATE; moHeader.BOMExplDate = header.BOMEXPLDATE; moHeader.BOMStatus = header.BOMSTATUS; moHeader.BuildOutMtl = header.BUILDOUTMTL; moHeader.CreateDate = header.CREATEDATE; moHeader.DeliveredQty = header.DELIVEREDQTY; moHeader.MaterialGroup = header.MATERIALGROUP; moHeader.MaterialType = header.MATERIALTYPE; moHeader.MoNumber = header.MONUMBER; moHeader.MoType = header.MOTYPE; moHeader.Plant = header.PLANT; moHeader.Priority = header.PRIORITY; moHeader.ProductionVer = header.PRODUCTIONVER; moHeader.Remark1 = header.REMARK1; moHeader.Remark2 = header.REMARK2; moHeader.Remark3 = header.REMARK3; moHeader.Remark4 = header.REMARK4; moHeader.Remark5 = header.REMARK5; moHeader.SalesOrder = header.SALESORDER; moHeader.SerialNumber = header.SERIALNUMBER; moHeader.SOItem = header.SOITEM; moHeader.Status = header.STATUS; moHeader.TCode = header.TCODE ; moHeader.TotalQty = header.TOTALQTY; moHeader.Unit = header.UNIT; #endregion #region map moItem foreach (SAPWSQueryMO.ZE1RESBL item in items) { MoItemDetail detail = new MoItemDetail(); detail.AltGroup = item.ALTGROUP; detail.Bulk = item.BULK_IND; detail.Component = item.COMPONENT; detail.Delete = item.DELETE_IND; detail.FinalIssue = item.FINAL_ISSUE; detail.MN = item.MN; detail.MoItem = item.MOITEM; detail.MoNumber = item.MONUMBER; detail.Pantom = item.PANTOM; detail.ParentMaterial = item.PARENT_MATERIAL; detail.ReqQty = item.REQQTY; detail.Reservation = item.RESERVATION; detail.ResvItem = item.RESVITEM; detail.SerialNumber =item.SERIALNUMBER; detail.SpecialStock = item.SPECIALSTOCK; detail.Unit =item.UNIT; detail.UnitReqQty = item.UNITREQQTY; detail.WithdrawQty = item.WITHDRAWQTY; moItems.Add(detail); } #endregion MoReleaseResponse moReleaseResp= MoRelease.MoRelease(moHeader, moItems.ToArray()); if (moReleaseResp.Result == "T") { errorText = ""; return true; } else { errorText = moReleaseResp.FailDescr; return false; } } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); errorText = e.Message; return false; } finally { BaseLog.LoggingEnd(logger, methodName); } }
//4.Build Response message structure public static MoReleaseResponse BuildResponseMsg(MoHeader moheader, bool isOK, string errMsg) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { MoReleaseResponse response = new MoReleaseResponse(); if (isOK) { response.FailDescr = ""; response.MoNumber = moheader.MoNumber; response.Result = "T"; } else { response.FailDescr = errMsg; response.MoNumber = moheader.MoNumber; response.Result = "F"; } BaseLog.LoggingInfo(logger,"ResponseMsg: \r\n{0}", ObjectTool.ObjectTostring(response)); //SQL.InsertTxnDataLog("Send", "MoReleaseResponse", moheader.MoNumber, moheader.BuildOutMtl, moheader.TxnId, "", errMsg, "Sending",""); 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 MoHeader(MoHeader header) { ObjectTool.CopyObject(header, this); }
public DBMoHeader(MoHeader header):base(header){ }
public MoReleaseResponse MoRelease(MoHeader moheader, MoItemDetail[] moitems) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); string msgName = "MORelease"; string responseMsg = "MOReleaseResponse"; if (string.IsNullOrEmpty(moheader.TCode) || moheader.TCode == "CO02" || moheader.TCode == "BADI") { msgName = "MOChange"; responseMsg = "MOChangeResponse"; } DBMoHeader dbheader = new DBMoHeader(moheader); try { WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, msgName, string.IsNullOrEmpty(moheader.MoNumber) ? "" : moheader.MoNumber, string.IsNullOrEmpty(moheader.Status) ? "" : moheader.Status, string.IsNullOrEmpty(moheader.SerialNumber) ? "" : moheader.SerialNumber, "", "", EnumMsgState.Received, ""); List<DBMoItemDetail> lstdbItemdetail = new List<DBMoItemDetail>(); foreach (MoItemDetail item in moitems) { lstdbItemdetail.Add(new DBMoItemDetail(item)); } //1.檢查必要的input parameter DBMoItemDetail[] dbitemsArr = lstdbItemdetail.ToArray(); Execute.ValidateParameter(dbheader, lstdbItemdetail.ToArray()); //2.檢查資料內容 Execute.CheckData(dbheader, dbitemsArr); //3.執行DB insert Execute.Process(dbheader, dbitemsArr); //4.Build Response Message MoReleaseResponse mrealease = Execute.BuildResponseMsg(moheader, true, ""); WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Send, responseMsg, string.IsNullOrEmpty(moheader.MoNumber) ? "" : moheader.MoNumber, string.IsNullOrEmpty(moheader.Status) ? "" : moheader.Status, string.IsNullOrEmpty(moheader.SerialNumber) ? "" : moheader.SerialNumber, "", "", EnumMsgState.Success, ""); return mrealease; } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); MoReleaseResponse mrealease = Execute.BuildResponseMsg(moheader, false, e.Message); WS.Common.SQL.InsertTxnDataLog(EnumMsgCategory.Receive, responseMsg, string.IsNullOrEmpty(moheader.MoNumber) ? "" : moheader.MoNumber, string.IsNullOrEmpty(moheader.Status) ? "" : moheader.Status, string.IsNullOrEmpty(moheader.SerialNumber) ? "" : moheader.SerialNumber, "", e.Message, EnumMsgState.Fail, ""); return mrealease; } finally { BaseLog.LoggingEnd(logger, methodName); } }