/// <summary> /// 僅取得預審處理檔所需欄位資料 /// </summary> /// <param name="customerId">客戶ID</param> /// <returns></returns> public CustomerShortDO GetShortData(string customerId) { CustomerShortDO result = null; if (String.IsNullOrEmpty(customerId)) { throw new ArgumentNullException("customerId"); } string query = @" SELECT CHI_NAME,STMT_CYCLE_DESC,PAY_DEADLINE,MOBIL_TEL FROM [RG_ID] WHERE ACCT_ID =@CustomerId;"; using (SqlConnection connection = DbConnection(Connection.ICRS)) { SqlCommand command = new SqlCommand(query, connection); command.Parameters.Add(new SqlParameter("@CustomerId", SqlDbType.NVarChar) { Value = customerId }); connection.Open(); DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(command); adapter.Fill(dt); if (dt.Rows.Count == 1) { result = ConvertCustomerShortDO(dt.Rows[0]); } else { throw new InvalidOperationException("CustomerData not the only"); } adapter = null; dt = null; command = null; } return(result); }
/// <summary> /// 匯入預審名單 /// </summary> /// <param name="campaignId">行銷活動代號</param> /// <param name="userId">登入帳號</param> /// <param name="userName">登入姓名</param> /// <returns>處理結果</returns> public ImportPreAdjustResultDTO ImportPreAdjust(string campaignId, string userId, string userName) { ImportPreAdjustResultDTO result = null; if (String.IsNullOrEmpty(campaignId)) { throw new ArgumentNullException("campaignId"); } ValidatePreAdjustResultDTO validateResult = ValidatePreAdjust(campaignId); if (validateResult == null) { var e = new InvalidOperationException("ValidateResult not found"); e.Data["campaignId"] = campaignId; throw e; } else if (!String.IsNullOrEmpty(validateResult.ErrorMessage)) { result = new ImportPreAdjustResultDTO() { ValidateMessage = validateResult.ErrorMessage, }; return(result); } CampaignDO campaignInfo = CampaignService.GetCampaign(campaignId); if (campaignInfo == null) { var e = new InvalidOperationException("CampaignInfo not found"); e.Data["campaignId"] = campaignId; throw e; } IEnumerable <CampaignListDO> campaignList = CampaignService.GetCampaignList( campaignInfo.CampaignId, campaignInfo.ExecutionPathway); if ((campaignList == null) || (campaignList.Count() == 0)) { var e = new InvalidOperationException("CampaignList not found"); e.Data["CampaignId"] = campaignInfo.CampaignId; e.Data["ExecutionPathway"] = campaignInfo.ExecutionPathway; throw e; } DateTime currentTime = DateTime.Now; CampaignImportLogDO importLog = new CampaignImportLogDO() { CampaignId = campaignInfo.CampaignId, ExpectedStartDate = campaignInfo.ExpectedStartDateTime, ExpectedEndDate = campaignInfo.ExpectedEndDateTime, Count = campaignList.Count(), ImportUserId = userId, ImportUserName = userName, ImportDate = currentTime.ToString("yyyy/MM/dd"), }; List <PreAdjustDO> preAdjustList = new List <PreAdjustDO>(); PreAdjustDO preAdjust = null; foreach (CampaignListDO item in campaignList) { preAdjust = null; preAdjust = new PreAdjustDO() { CampaignId = campaignInfo.CampaignId, Id = item.CustomerId, ProjectName = item.Col1, ProjectAmount = Convert.ToDecimal(item.Col2), CloseDate = item.Col3, ImportDate = currentTime.ToString("yyyy/MM/dd"), Kind = item.Col4, Status = "待生效", }; preAdjustList.Add(preAdjust); } if (preAdjustList.Count == 0) { throw new InvalidOperationException("preAdjustList not found"); } CustomerDAO aboutDataDAO = new CustomerDAO(); CustomerShortDO aboutData = null; PreAdjustDO tempPreAdjust = null; foreach (CampaignListDO item in campaignList) { aboutData = aboutDataDAO.GetShortData(item.CustomerId); if (aboutData == null) { var e = new InvalidOperationException("AboutData not found"); e.Data["CustomerId"] = item.CustomerId; throw e; } tempPreAdjust = preAdjustList.FirstOrDefault(x => x.Id == item.CustomerId); if (tempPreAdjust == null) { var e = new InvalidOperationException("tempPreAdjust not found"); e.Data["CustomerId"] = item.CustomerId; throw e; } tempPreAdjust.ChineseName = aboutData.ChineseName; tempPreAdjust.ClosingDay = aboutData.ClosingDay; tempPreAdjust.PayDeadline = aboutData.PayDeadline; tempPreAdjust.MobileTel = aboutData.MobileTel; } SaveCampaignData(importLog, preAdjustList); result = new ImportPreAdjustResultDTO(); return(result); }