/// <summary> /// Web background job - Create Siebel Opportunity /// </summary> /// <param name="active"></param> /// <param name="errorMsg"></param> /// <returns></returns> public static bool BatchCreateSiebelOpportunity(SiebelActive active) { string row_id = string.Empty; string wsparas = string.Empty; string wserrmsg = string.Empty; try { //先把狀態更新成Processing以免任何失敗造成job一直執行這筆指令 active.UpdateActiveProcessing(SiebelActiveUpdatedUser.System); row_id = SiebelDAL.CreateSiebelOptyV2(active, ref wsparas, ref wserrmsg); if (!string.IsNullOrEmpty(wserrmsg)) { active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Create Siebel Opportunity through Siebel web service failed: " + wserrmsg, wsparas); return(false); } if (string.IsNullOrEmpty(row_id)) { active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Opportunity Row id Siebel WS returned is string.isNullOrEmpty", wsparas); return(false); } if (row_id.Equals("NULL", StringComparison.InvariantCultureIgnoreCase)) { active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Opportunity Row id Siebel WS returned is Null string!", wsparas); return(false); } } catch (Exception e) { active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Create Siebel Opportunity failed: " + e.Message, wsparas); return(false); } try { /* * 檢查SiebelActive裡面,是否有別的數據(同quoteID), * 預防同一批次作業中,還要再Create Quote或Update Opty的情況 * Case 1: Create Opty後 還要Create Quote * Case 2: Create Opty後 還要Update Opty * Case 3: Create Opty後 先Update Opty 再Create Quote */ List <SiebelActive> list = SiebelDAL.GetSiebelActiveByQuoteID(active.QuoteID, active.ID); //必須排除自己這筆紀錄 if (list != null) { foreach (SiebelActive sa in list) { //sa.OptyID = row_id; //sa.Update(); SiebelDAL.updateOptyID(sa.ID, row_id); } } //2015/4/27 Also have to check and update [MyAdvantechGlobal].[CARTMASTERV2].[optyID] after creating Opportunity successfully MyAdvantechDAL.UpdateOptyID(active.QuoteID, row_id); /* * end */ //建立Siebel opty成功 active.UpdateActiveSuccess(SiebelActiveUpdatedUser.System, wsparas); active.UpdateOptyIDtoOptyQuote(active.QuoteID, row_id); ////檢查optyQuote table 把optyId跟相關的數據一併更新過去 //if (active.SiebelOpty == null) //{ // optyQuote opty = new optyQuote(); // opty.quoteId = active.QuoteID; // opty.optyId = active.OptyID; // opty.optyStage = active.OptyStage; // opty.Opty_Owner_Email = active.OptyOwnerEmail; // opty.Add(); //} //else //{ // active.SiebelOpty.optyId = active.OptyID; // active.SiebelOpty.optyName = active.OptyName; // active.SiebelOpty.optyStage = active.OptyStage; // active.SiebelOpty.Opty_Owner_Email = active.OptyOwnerEmail; // active.SiebelOpty.Update(); //} return(true); } catch (Exception ex) { active.UpdateActiveFailed(SiebelActiveUpdatedUser.System, "Create Siebel Opportunity failed: " + ex.ToString(), wsparas); return(false); } }