public List<NotifyMAWBResponse> NotifyMAWB(NotifyMAWB[] MAWBItems) { string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { //切換 MAWB temp data string SwitchMAWBTempDataToCQ = string.IsNullOrEmpty(WebConfigurationManager.AppSettings["SwitchMAWBTempDataToCQ"]) ? "" : WebConfigurationManager.AppSettings["SwitchMAWBTempDataToCQ"]; string connectionDB_BK = ""; if (SwitchMAWBTempDataToCQ == "Y") { connectionDB_BK = "SD_DBServer_BK_CQ"; } else { connectionDB_BK = "SD_DBServer_BK"; } string BatchId = string.Format("{0:yyyyMMddHHmmssfff}", DateTime.Now); //1.檢查必要的input parameter Execute.ValidateParameter(connectionDB_BK, MAWBItems, BatchId); //3.執行DB insert Execute.Process(connectionDB_BK, MAWBItems, BatchId); //4.Build Response Message List<NotifyMAWBResponse> pgiresponse = Execute.BuildResponseMsg(connectionDB_BK, BatchId); return pgiresponse; } catch (Exception e) { logger.Error(MethodBase.GetCurrentMethod(), e); // UTL.SendMail("test", e.Message); //4.Build Response Error Message List<NotifyMAWBResponse> ResponseList = new List<NotifyMAWBResponse>(); foreach (NotifyMAWB item in MAWBItems) { string connectionDB = "SD_DBServer"; int dbIndex = 0; NotifyMAWBResponse response = new NotifyMAWBResponse(); string SerialNumber = item.SerialNumber; string MAWB = item.MAWB; string State = "F"; response.SerialNumber = SerialNumber; response.MAWB = MAWB; response.Result = State; response.ErrorText = e.ToString().Substring(0,255); ResponseList.Add(response); SQL.InsertTxnDataLog_DB(connectionDB, dbIndex, EnumMsgCategory.Response, "NotifyMAWBResponse", string.IsNullOrEmpty(item.MAWB) ? "" : item.MAWB, "", string.IsNullOrEmpty(item.SerialNumber) ? "" : item.SerialNumber, "", "", EnumMsgState.Fail, e.ToString().Substring(0, 255)); } return ResponseList; } finally { BaseLog.LoggingEnd(logger, methodName); } }
//4.Build Response message structure public static List<NotifyMAWBResponse> BuildResponseMsg(string connectionDB_BK, string BatchId) { string connectionDB = "SD_DBServer"; //string connectionDB_BK = "SD_DBServer_BK"; //string connectionDB_BK = "SD_DBServer_BK_CQ"; int dbIndex = 0; string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); List<NotifyMAWBResponse> ResponseList = new List<NotifyMAWBResponse>(); List<MAWBMaster> MAWBStatus = SQL.GetMawbMaster(connectionDB_BK, dbIndex, BatchId); try { foreach (MAWBMaster item in MAWBStatus) { BaseLog.LoggingInfo(logger, "SerialNumber: \r\n{0}", item.SerialNumber); NotifyMAWBResponse response = new NotifyMAWBResponse(); string SerialNumber = item.SerialNumber; string MAWB = item.MAWB; string Result = item.State; string ErrorText = item.ErrorDescr; response.SerialNumber = item.SerialNumber; response.MAWB = MAWB; response.Result = Result; response.ErrorText = ErrorText; ResponseList.Add(response); SQL.InsertTxnDataLog_DB(connectionDB, dbIndex, EnumMsgCategory.Response, "NotifyMAWBResponse", string.IsNullOrEmpty(item.MAWB) ? "" : item.MAWB, "", string.IsNullOrEmpty(item.SerialNumber) ? "" : item.SerialNumber, "", "", EnumMsgState.Success, ""); } return ResponseList; } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }