/// <summary> /// 初始化页面显示的三个借款标数据 /// </summary> private void IntialBorrowingTarget() { B_borrowing_target bllBorrowingTarget = new B_borrowing_target(); List <M_borrowing_target_ZhuoLu> listData = new List <M_borrowing_target_ZhuoLu>(); M_borrowing_target_ZhuoLu targetLifeSix = GetPartialTargetModel(6); if (targetLifeSix != null && targetLifeSix.targetid != 0) { listData.Add(targetLifeSix); } M_borrowing_target_ZhuoLu targetLifeThree = GetPartialTargetModel(3); if (targetLifeThree != null && targetLifeThree.targetid != 0) { listData.Add(targetLifeThree); } M_borrowing_target_ZhuoLu targetLifeOne = GetPartialTargetModel(1); if (targetLifeOne != null && targetLifeOne.targetid != 0) { listData.Add(targetLifeOne); } if (listData.Count < 3)//如果总共得到的标的数量小于3个,则补满三条数据,以使得页面显示不变形 { for (int i = 1; i <= 3 - listData.Count; i++) { listData.Add(listData[0]); } } StringBuilder targetLifeHtml = new StringBuilder(); int itemIndex = 1; foreach (M_borrowing_target_ZhuoLu item in listData) { string percent = (item.fundraising_amount / item.borrowing_balance * 100M).ToString("0"); targetLifeHtml.Append("<dl class=\"list-libao\">"); targetLifeHtml.AppendFormat("<a href=\"{0}\">", "/invest_borrow_" + item.targetid + ".html"); targetLifeHtml.AppendFormat("<dt class=\"libao{0}\">", itemIndex); targetLifeHtml.AppendFormat("<div class=\"libao{0}_jindu\">", itemIndex); targetLifeHtml.AppendFormat("<div><p style=\"width:{0}%;\"></p></div>", percent); targetLifeHtml.AppendFormat("<span>{0}%</span>", percent); targetLifeHtml.Append("</div>"); targetLifeHtml.Append("<div class=\"libao1_main\">"); targetLifeHtml.Append("<div class=\"libao1_main_1\">"); targetLifeHtml.AppendFormat("<p class=\"libao1_main_1_biaoti\">{0}</p>", item.borrowing_title); targetLifeHtml.Append("</div>"); targetLifeHtml.Append("<div class=\"libao1_main_2 libao1_diyi\">"); targetLifeHtml.AppendFormat("<h3>{0}</h3><small>%</small>", item.annual_interest_rate.ToString("0.00")); targetLifeHtml.Append("</div>"); targetLifeHtml.Append("<div class=\"libao1_main_3\">"); targetLifeHtml.AppendFormat("<p><span>{0}</span>个月</p>", item.life_of_loan); targetLifeHtml.Append("</div></div></dt></a></dl>"); itemIndex++; } ltrBorrowintTargets.Text = targetLifeHtml.ToString(); }
/// <summary> /// 根据条件得到一个对象实体 /// </summary> /// <param name="lifeOfLoan"></param> /// <returns></returns> public M_borrowing_target_ZhuoLu GetModelByLifeLoan(int lifeOfLoan) { string sql = @"select top 1 targetid,borrowing_title,annual_interest_rate,life_of_loan,fundraising_amount,borrowing_balance from [dbo].[hx_borrowing_target] where tender_state >= 2 and end_time >GETDATE() and unit_day = 1 and life_of_loan = @life_of_loan and borrowing_balance>0 order by tender_state asc,annual_interest_rate desc"; SqlParameter[] parameters = { new SqlParameter("@life_of_loan", SqlDbType.Int) }; parameters[0].Value = lifeOfLoan; DataSet ds = DbHelperSQL.Query(sql, parameters); if (ds != null && ds.Tables.Count > 0) { M_borrowing_target_ZhuoLu res = DataHelper.GetEntity <M_borrowing_target_ZhuoLu>(ds.Tables[0]); return(res); } else { return(null); } }
/// <summary> /// 根据期限获取借款标数据 /// </summary> /// <param name="month">借款期限(1,3,6)</param> /// <returns></returns> private M_borrowing_target_ZhuoLu GetPartialTargetModel(int month) { B_borrowing_target bllBorrowingTarget = new B_borrowing_target(); M_borrowing_target_ZhuoLu targetLife; M_borrowing_target target = bllBorrowingTarget.GetModel(Common.ConfigHelper.GetConfigInt("MonthTargetID_" + month)); if (target != null && target.targetid != 0 && target.tender_state == 2 && target.end_time > DateTime.Now && target.fundraising_amount < target.borrowing_balance)//如果指定的标不存在,则使用规则查找符合要求的标 { targetLife = new M_borrowing_target_ZhuoLu { targetid = target.targetid, annual_interest_rate = target.annual_interest_rate, borrowing_balance = target.borrowing_balance, borrowing_title = target.borrowing_title, fundraising_amount = target.fundraising_amount, life_of_loan = target.life_of_loan }; } else { targetLife = bllBorrowingTarget.GetModelByLifeLoan(month); } return(targetLife); }