123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using CB.Cache;
- using CB.Entity;
- namespace CB.Data
- {
- //TCQXC
- public partial class Caches
- {
- /// <summary>
- /// 七星彩所有开奖信息
- /// </summary>
- /// <returns></returns>
- public static IList<TCQXCInfo> GetTCQXCList()
- {
- var cache = CBCache.GetCacheService();
- IList<TCQXCInfo> list = cache.GetObject(CacheKeys.TCQXCList) as IList<TCQXCInfo>;
- if (null == list)
- {
- list = TCQXCService.ToList();
- cache.AddObject(CacheKeys.TCQXCList, list);
- }
- return list;
- }
- /// <summary>
- /// 七星彩所有开奖信息
- /// </summary>
- /// <param name="topSize">top行(没有值默认传0)</param>
- /// <param name="term">期数(没有值默认传0)</param>
- /// <param name="year">年份(没有值默认传0)</param>
- /// <returns></returns>
- public static List<TCQXCInfo> GetTCQXCList(int topSize, int term, int year)
- {
- var list = GetTCQXCList();
- if (null == list || 0 >= list.Count)
- return null;
- List<TCQXCInfo> result = new List<TCQXCInfo>();
- if (topSize > 0)
- {
- int n = topSize > list.Count ? 0 : list.Count - topSize;
- for (int i = list.Count - 1; i >= n; i--)
- {
- if (0 <= list[i].OpenCode1)
- result.Add(list[i]);
- //如果没有正确开奖号的情况就忽略该行数据,并多循环一次到topSize行
- else if (n > 0) n--;
- }
- }
- else if (term > 0)
- {
- TCQXCInfo info = list.FirstOrDefault(x => x.Term == term && 0 <= x.OpenCode1);
- if (info != null) result.Add(info);
- }
- else if (year > 0)
- result = list.ToList().FindAll(x => x.Term >= year * 1000 + 1 && x.Term < (year + 1) * 1000 && 0 <= x.OpenCode1);
- return result;
- }
- /// <summary>
- /// 返回七星彩近topSize条开机号、试机号、开奖号列表
- /// </summary>
- /// <param name="topSize">查询记录数</param>
- /// <param name="openCodeType">号码类型</param>
- /// <returns></returns>
- public static IList<TCQXCInfo> GetTCQXCList(int topSize, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
- {
- if (0 >= topSize)
- return null;
- var list = GetTCQXCList();
- if (null == list || 0 >= list.Count)
- return null;
- IList<TCQXCInfo> r = new List<TCQXCInfo>();
- int n = topSize > list.Count ? list.Count : topSize;
- for (int i = list.Count - 1; i >= 0; i--)
- {
- if (0 == n) { break; }
- if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1"))
- { r.Add(list[i]); n--; continue; }
- if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1"))
- { r.Add(list[i]); n--; continue; }
- if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1)
- { r.Add(list[i]); n--; continue; }
- }
- return r;
- }
- /// <summary>
- /// 根据期数获取七星彩开奖详细
- /// term=0时,读取最新一期开奖明细;
- /// term=0时并不一定包含开奖号数据,有可能只有开机号数据或试机号数据
- /// </summary>
- /// <param name="term">查询期数</param>
- /// <param name="openCodeType">查询开奖数据类型;term=0时,此参数有效</param>
- /// <returns>开奖数据</returns>
- public static TCQXCInfo GetTCQXCInfo(long term, OpenCodeType openCodeType = OpenCodeType.Normal)
- {
- var list = GetTCQXCList();
- if (null == list || 0 >= list.Count)
- return null;
- TCQXCInfo entity = null;
- if (0 == term)
- {
- entity = list[list.Count - 1];
- if (openCodeType == OpenCodeType.Normal)
- return entity;
- if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1"))
- return entity;
- if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1"))
- return entity;
- if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= entity.OpenCode1)
- return entity;
- for (int i = list.Count - 2; i >= 0; i--)
- {
- entity = list[i];
- if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1"))
- return entity;
- if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1"))
- return entity;
- if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= entity.OpenCode1)
- return entity;
- }
- return null;
- }
- foreach (var item in list)
- {
- if (term == item.Term)
- {
- entity = item; break;
- }
- }
- return entity;
- }
- }
- }
|