HKHelper.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Web.Mvc.Html;
  6. using CP.Common;
  7. namespace CP.Kjh.Models
  8. {
  9. /// <summary>
  10. /// 香港彩帮助类
  11. /// </summary>
  12. public static class HkHelper
  13. {
  14. /// <summary>
  15. /// 获取香港彩开奖号特征
  16. /// </summary>
  17. /// <param name="openCode"></param>
  18. /// <returns></returns>
  19. public static IEnumerable<HkResult> GetHkResultList(List<string> openCode, int year)
  20. {
  21. year = year.ToString().Substring(0, 4).ToInt32();
  22. foreach (var code in openCode)
  23. {
  24. yield return new HkResult
  25. {
  26. OpenCode = code.ToInt32(),
  27. BsType = GetType(code.ToInt32(), year, BsType.Red,HkTypeEnum.Bs),
  28. Sx = AttributeHelper.GetAttributeText(GetType(code.ToInt32(), year, SxType.Shu, HkTypeEnum.Sx)),
  29. Wx = AttributeHelper.GetAttributeText(GetType(code.ToInt32(), year, WxType.Jin, HkTypeEnum.Wx))
  30. };
  31. }
  32. }
  33. /// <summary>
  34. /// 获取某个开奖号的波色、生肖、五行
  35. /// </summary>
  36. /// <param name="openCode"></param>
  37. /// <param name="year"></param>
  38. /// <returns></returns>
  39. private static T GetType<T>(int openCode, int year,T t, HkTypeEnum hkType)
  40. {
  41. var model = OtherHelper.HkList.FirstOrDefault(p =>
  42. p.Type == hkType.ToString() && (","+ p.Number + ",").Contains(","+ openCode.ToString() + ",") && p.Year == year);
  43. return model == null ? t : (T)Enum.Parse(typeof(T), model.Name);
  44. }
  45. }
  46. }