/// <summary> /// 获取开奖号模板 /// </summary> /// <param name="type"></param> /// <param name="openCodeList">开奖号集合</param> /// <returns></returns> protected string GetOpenCodeTemplate(SCCLottery type, List <int> openCodeList) { StringBuilder res = new StringBuilder(); string blueTemplate = "<span class='ball-list blue'>{0}</span>"; string redTemplate = "<span class='ball-list red'>{0}</span>"; //快乐扑克3为特殊彩种 if (type == SCCLottery.ShanDongKLPK3) { return(GetKLPK3OpenCodeTemplate(openCodeList)); } #region 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0 //取出当前最大开奖号 //TODO 此做法欠妥,如果当前彩种开奖号取值在0-20之间,有可能某一期开奖号全部都小于10 int max = openCodeList.Max(); //是否需要添加0 bool hasAppendZero = (type != SCCLottery.ShanDongKLPK3 && max >= 10) || type == SCCLottery.GuangDongHC1; #endregion //其他彩 string typeCode = type.ToString(); if (LotteryBallTypeDict.ContainsKey(typeCode)) { int[] codeArr = LotteryBallTypeDict[typeCode]; //正常球个数 int normal = codeArr[0]; //蓝球个数 int blue = codeArr[1]; //生肖球个数 int zodiac = codeArr[2]; //季节球个数 int season = codeArr[3]; //方位球个数 int position = codeArr[4]; #region 正常球 if (normal > 0) { for (int i = 1; i <= normal; i++) { int openCode = openCodeList[i - 1].TryToInt32(); res.Append(string.Format(redTemplate, hasAppendZero ? openCode.RepairZero() : openCode.ToString())); } } #endregion #region 蓝球 if (blue > 0) { int index = normal; //for (int i = blue; i >= 1; i--) for (int i = 1; i <= blue; i++) { int openCode = openCodeList[index + i - 1].TryToInt32(); res.Append(string.Format(blueTemplate, hasAppendZero ? openCode.RepairZero() : openCode.ToString())); } } #endregion #region 生肖球 if (zodiac > 0) { int index = normal + blue; for (int i = zodiac; i >= 1; i--) { int openCode = openCodeList[index + i - 1].TryToInt32(); res.Append(string.Format(blueTemplate, LotteryUtils.GetZodiacByOpenCode(openCode))); } } #endregion #region 季节球 if (season > 0) { int index = normal + blue + zodiac; for (int i = season; i >= 1; i--) { int openCode = openCodeList[index + i - 1].TryToInt32(); res.Append(string.Format(blueTemplate, LotteryUtils.GetSeasonByOpenCode(openCode))); } } #endregion #region 方位球 if (position > 0) { int index = normal + blue + zodiac + season; for (int i = position; i >= 1; i--) { int openCode = openCodeList[index + i - 1].TryToInt32(); res.Append(string.Format(blueTemplate, LotteryUtils.GetPositionByOpenCode(openCode))); } } #endregion } else { //总共球个数 int total = type.GetEnumText().TryToInt32(); for (int i = 1; i <= total; i++) { int openCode = openCodeList[i - 1].TryToInt32(); res.Append(string.Format(redTemplate, hasAppendZero ? openCode.RepairZero() : openCode.ToString())); } } return(res.ToString()); }