public List<NotifyBsamModelResponse> NotifyBsamModel(NotifyBsamModel[] BsamModelItems) { string connectionDB_BK = "SD_DBServer"; string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); try { //1.檢查必要的input parameter Execute.ValidateParameter(connectionDB_BK, BsamModelItems); //3.執行DB insert Execute.Process(connectionDB_BK, BsamModelItems); //4.Build Response Message List<NotifyBsamModelResponse> pgiresponse = Execute.BuildResponseMsg(connectionDB_BK, BsamModelItems); return pgiresponse; } catch (Exception e) { logger.Error(MethodBase.GetCurrentMethod(), e); // UTL.SendMail("test", e.Message); //4.Build Response Error Message List<NotifyBsamModelResponse> ResponseList = new List<NotifyBsamModelResponse>(); foreach (NotifyBsamModel item in BsamModelItems) { NotifyBsamModelResponse response = new NotifyBsamModelResponse(); string SerialNumber = ""; string State = "F"; response.SerialNumber = SerialNumber; response.Result = State; ResponseList.Add(response); } return ResponseList; } finally { BaseLog.LoggingEnd(logger, methodName); } }
//4.Build Response message structure public static List<NotifyBsamModelResponse> BuildResponseMsg(string connectionDB, NotifyBsamModel[] results) { int dbIndex = 0; string methodName = MethodBase.GetCurrentMethod().Name; BaseLog.LoggingBegin(logger, methodName); List<NotifyBsamModelResponse> ResponseList = new List<NotifyBsamModelResponse>(); try { foreach (NotifyBsamModel item in results) { BaseLog.LoggingInfo(logger, "SerialNumber: \r\n{0}", ObjectTool.ObjectTostring(item.SerialNumber)); NotifyBsamModelResponse response = new NotifyBsamModelResponse(); string SerialNumber = item.SerialNumber; string State = SQL.GetBsamModelState(connectionDB, dbIndex, SerialNumber); if (State == "N") State = "F"; response.SerialNumber = item.SerialNumber; response.Result = State; ResponseList.Add(response); } return ResponseList; } catch (Exception e) { BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e); throw e; } finally { BaseLog.LoggingEnd(logger, methodName); } }