private List <ContractInsuranceData> ConvretToList(DataTable dtBDW) { try { var list = new List <ContractInsuranceData>(); dtBDW.AsEnumerable().ToList().ForEach(p => { ContractInsuranceData data = new ContractInsuranceData() { ContractNo = p[eBDW.CONTRACT_NUMBER.ToString()].ToString().Trim(), PolicyYear = p[eBDW.POLICY_YEAR.ToString()].ToString().Trim(), PolicyNo = p[eBDW.POLICY_NO.ToString()].ToString().Trim(), PolicyType = p[eBDW.POLICY_TYPE.ToString()].ToString().Trim().ToUpper(), MainBy = p[eBDW.MAIN_BY.ToString()].ToString().Trim(), MainDate = p[eBDW.MAIN_DATE.ToString()].ToString().Trim(), MainTime = p[eBDW.MAIN_TIME.ToString()].ToString().Trim(), CreateBy = p[eBDW.CREATE_BY.ToString()].ToString().Trim(), CreateDate = p[eBDW.CREATE_DATE.ToString()].ToString().Trim(), CreateTime = p[eBDW.CREATE_TIME.ToString()].ToString().Trim(), DataSource = p[eBDW.DATA_SOURCE.ToString()].ToString().Trim() }; list.Add(data); }); return(list); } catch (Exception ex) { throw ex; } }
private void DoProcess(SLMDBEntities slmdb, kkslm_tr_renewinsurance reins, List <ContractInsuranceData> contractInsureList, List <InsuranceCompanyData> insurComList, List <CoverageTypeData> coverageList) { try { string errMessage = ""; bool doUpdatePolicy = false; bool doUpdateAct = false; DateTime createdDate = DateTime.Now; var lead = slmdb.kkslm_tr_lead.Where(p => p.slm_ticketId == reins.slm_TicketId).FirstOrDefault(); if (lead == null) { throw new Exception("ไม่พบข้อมูล Lead TicketId " + reins.slm_TicketId + " ในระบบ"); } int countPolicy = slmdb.kkslm_tr_renewinsurance_compare.Count(p => p.slm_RenewInsureId == reins.slm_RenewInsureId && p.slm_Selected == true); int countAct = slmdb.kkslm_tr_renewinsurance_compare_act.Count(p => p.slm_RenewInsureId == reins.slm_RenewInsureId && p.slm_ActPurchaseFlag == true); ContractInsuranceData data = null; if (countPolicy > 0) { if (string.IsNullOrWhiteSpace(reins.slm_ReceiveNo)) { InsertPolicyActPending(contractInsureList, reins.slm_ContractNo, slmdb, AppConstant.PendingType.ReceiveNoNotFound, ""); errMessage = string.Format("ContractNo : {0}, TicketId : {1}, GoToPending, Error : ไม่พบข้อมูลเลขที่รับแจ้ง", reins.slm_ContractNo, reins.slm_TicketId); Util.WriteLogFile(logfilename, BatchCode, errMessage); BizUtil.InsertLog(BatchMonitorId, lead.slm_ticketId, "", errMessage); //Console.WriteLine("ContractNo " + reins.slm_ContractNo + ": PENDING"); return; } data = contractInsureList.Where(p => p.PolicyType == "V").FirstOrDefault(); if (data != null) { if (string.IsNullOrWhiteSpace(reins.slm_PolicyNo)) { doUpdatePolicy = true; } else { if (reins.slm_PolicyNo.Trim().ToLower() != data.PolicyNo.ToLower()) { doUpdatePolicy = true; } } if (doUpdatePolicy) { reins.slm_PolicyNo = data.PolicyNo; UpdateStatusAndOwnerLogging(slmdb, lead, createdDate, "10", "30", AppConstant.LoggingType.EODUpdateCurrent); UpdatePending(slmdb, reins.slm_ContractNo, "V", createdDate); } } data = contractInsureList.Where(p => p.PolicyType == "C").FirstOrDefault(); if (data != null) { if (countAct > 0) { if (string.IsNullOrWhiteSpace(reins.slm_ActNo)) { doUpdateAct = true; } else { if (reins.slm_ActNo.Trim().ToLower() != data.PolicyNo.ToLower()) { doUpdateAct = true; } } if (doUpdateAct) { reins.slm_ActNo = data.PolicyNo; UpdatePending(slmdb, reins.slm_ContractNo, "C", createdDate); } } else { InsertPolicyActPending(contractInsureList, reins.slm_ContractNo, slmdb, AppConstant.PendingType.PurchaseDetailNotFound, "C"); errMessage = string.Format("ContractNo : {0}, TicketId : {1}, GoToPending, Error : ไม่พบข้อมูลการซื้อพรบ. แต่มีเลขพรบ.เข้าระบบ", reins.slm_ContractNo, reins.slm_TicketId); Util.WriteLogFile(logfilename, BatchCode, errMessage); BizUtil.InsertLog(BatchMonitorId, lead.slm_ticketId, "", errMessage); //Console.WriteLine("ContractNo " + reins.slm_ContractNo + ": PENDING"); } } } else if (countPolicy == 0 && countAct > 0) { data = contractInsureList.Where(p => p.PolicyType == "C").FirstOrDefault(); if (data != null) { if (string.IsNullOrWhiteSpace(reins.slm_ActNo)) { doUpdateAct = true; } else { if (reins.slm_ActNo.Trim().ToLower() != data.PolicyNo.ToLower()) { doUpdateAct = true; } } if (doUpdateAct) { reins.slm_ActNo = data.PolicyNo; UpdateStatusAndOwnerLogging(slmdb, lead, createdDate, "10", "31", AppConstant.LoggingType.EODUpdateCurrent); UpdatePending(slmdb, reins.slm_ContractNo, "C", createdDate); } } data = contractInsureList.Where(p => p.PolicyType == "V").FirstOrDefault(); if (data != null) { InsertPolicyActPending(contractInsureList, reins.slm_ContractNo, slmdb, AppConstant.PendingType.PurchaseDetailNotFound, "V"); errMessage = string.Format("ContractNo : {0}, TicketId : {1}, GoToPending, Error : ไม่พบข้อมูลการซื้อประกัน แต่มีเลขกรมธรรม์เข้าระบบ", reins.slm_ContractNo, reins.slm_TicketId); Util.WriteLogFile(logfilename, BatchCode, errMessage); BizUtil.InsertLog(BatchMonitorId, lead.slm_ticketId, "", errMessage); //Console.WriteLine("ContractNo " + reins.slm_ContractNo + ": PENDING"); } } else { InsertPolicyActPending(contractInsureList, reins.slm_ContractNo, slmdb, AppConstant.PendingType.PurchaseDetailNotFound, ""); Util.WriteLogFile(logfilename, BatchCode, string.Format("ContractNo : {0}, Error : ไม่พบข้อมูลการซื้อขายประกันและพรบ.", reins.slm_ContractNo)); BizUtil.InsertLog(BatchMonitorId, lead.slm_ticketId, "", string.Format("ContractNo : {0}, Error : ไม่พบข้อมูลการซื้อขายประกันและพรบ.", reins.slm_ContractNo)); //Console.WriteLine("ContractNo " + reins.slm_ContractNo + ": PENDING"); return; //ถ้าตก Pending ไม่มีการซื้อประกันและพรบ. ไม่ต้องลงบันทึกผลการติดต่อและไม่ส่ง CAR } if (doUpdatePolicy || doUpdateAct) { reins.slm_UpdatedBy = "SYSTEM"; reins.slm_UpdatedDate = createdDate; slmdb.SaveChanges(); var carData = AppUtil.GetDataForCARLogService(reins.slm_TicketId, slmdb); var phonecall = InsertPhonecallHistory(slmdb, reins.slm_TicketId, createdDate, carData); if (doUpdatePolicy && AppConstant.SendSMSPolicyNo) { InsertPrepareSMS(slmdb, lead, reins, insurComList, coverageList, createdDate); } CreateCASActivityLog(reins, slmdb, BatchCode, BatchMonitorId, phonecall.slm_PhoneCallId, carData); } } catch (Exception ex) { throw ex; } }