using CP.Common; using CP.Model; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Xml; using System.Configuration; using System.Reflection; using System.ComponentModel; using CP.Business; namespace CP.Kjh.Models { public static class OtherHelper { #region 配置(单例) private static readonly Lazy> czTypeEnumList = new Lazy>(() => GetCzTypeModel()); private static readonly Lazy> czList = new Lazy>(() => CzBll.GetAllList()); private static readonly Lazy> chartList = new Lazy>(() => ChartBll.GetList()); private static readonly Lazy> wfList = new Lazy>(() => new WFBLL().GetList()); private static readonly Lazy> whatList = new Lazy>(() => OtherHelper.ConvertXMLToObject(HttpContext.Current.Server.MapPath($@"{ConfigurationManager.AppSettings["WhatXml"]}"))); private static readonly Lazy> newsList = new Lazy>(() => OtherHelper.ConvertXMLToObject(HttpContext.Current.Server.MapPath($@"{ConfigurationManager.AppSettings["NewsXml"]}"))); private static readonly Lazy> hkList = new Lazy>(() => OtherHelper.ConvertXMLToObject(HttpContext.Current.Server.MapPath($@"{ConfigurationManager.AppSettings["HkXml"]}"))); /// /// 私有,,获取彩种配置的方法 /// /// private static IEnumerable GetCzTypeModel() { var list = new List(); foreach (FieldInfo field in typeof(CzTypeEnum).GetFields()) { if (!field.IsSpecialName) list.Add(new CzTypeModel { Name = ((DescriptionAttribute)Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute))).Description, Key = field.Name, Value = (int)field.GetRawConstantValue(), Parent = ((ParentAttribute)Attribute.GetCustomAttribute(field, typeof(ParentAttribute))).Parent, Img = ((ImgAttribute)Attribute.GetCustomAttribute(field, typeof(ImgAttribute))).Img, }); } return list; } /// /// CzTypeEnum类型配置数据 /// public static IEnumerable CzTypeEnumList { get { return czTypeEnumList.Value; } } /// /// 从数据库获取彩种信息 /// public static IEnumerable CzList { get { return czList.Value; } } /// /// 得到chat表的数据 /// public static IEnumerable ChartList { get { return chartList.Value.Where(p => p.state == 0); } } /// /// 从数据库获取玩法信息 /// public static IEnumerable WfList { get { return wfList.Value; } } /// /// 获取什么的配置数据(kjh和sjh) /// public static IEnumerable WhatList { get { return whatList.Value; } } /// /// 新闻配置 /// public static IEnumerable NewsList { get { return newsList.Value; } } /// /// 香港生肖配置 /// public static IEnumerable HkList { get { return hkList.Value; } } #endregion public static string KJXQImg(string value) { var dict = new Dictionary { { QGEnum.fcsd.ToString(),"fc3d"}, { DFEnum.gdhc1.ToString(),"hc1"}, { GPEnum.tcah11x5.ToString(),"ah11x5"}, }; if (dict.ContainsKey(value)) return dict[value]; return value; } /// /// 得到奇偶比 /// /// /// public static string GetJob(string code) { var list = code.Split('+')[0].Split(',').ToList(); if (code.IsEmpty()) return string.Empty; return list.Where(p => p.ToInt32() % 2 != 0).Count() + ":" + list.Where(p => p.ToInt32() % 2 == 0).Count(); } /// /// 得到和值 /// /// /// public static int GetHz(string code) { var list = code.Split('+')[0].Split(',').ToList(); if (code.IsEmpty()) return 0; return list.Sum(p => p.ToInt32()); } /// /// 得到大小比 /// /// /// public static string GetDxb(string code, int number) { var list = code.Split('+')[0].Split(',').ToList(); if (code.IsEmpty()) return string.Empty; return list.Where(p => p.ToInt32() >= number).Count() + ":" + list.Where(p => p.ToInt32() < number).Count(); } /// /// 全国彩获取旧版类型URL的扩展 /// /// /// public static string GetQGXQUrl(this QGEnum qgEnum) { return $"/xq_{RouteHelper.GetOldTypeName(qgEnum.ToString())}.aspx"; } /// /// 将XML内容转换成目标对象实体集合 /// /// 目标对象实体 /// 完整文件名(根目录下只需文件名称) /// /// public static List ConvertXMLToObject(string FileName, string WrapperNodeName = "UrlSetting") { XmlDocument doc = new XmlDocument(); doc.Load(FileName); List result = new List(); var TType = typeof(T); XmlNodeList nodeList = doc.ChildNodes; if (!string.IsNullOrEmpty(WrapperNodeName)) { foreach (XmlNode node in doc.ChildNodes) { if (node.Name == WrapperNodeName) { nodeList = node.ChildNodes; break; } } } object oneT = null; foreach (XmlNode node in nodeList) { if (node.NodeType == XmlNodeType.Comment || node.NodeType == XmlNodeType.XmlDeclaration) continue; oneT = TType.Assembly.CreateInstance(TType.FullName); foreach (XmlNode item in node.ChildNodes) { if (item.NodeType == XmlNodeType.Comment) continue; var property = TType.GetProperty(item.Name); if (property != null) property.SetValue(oneT, Convert.ChangeType(item.InnerText, property.PropertyType), null); } result.Add((T)oneT); } return result; } /// /// 通过新版类型枚举获取chart数据(用于ChartType) /// /// /// public static List GetChartList(string ename, ChartType tid = ChartType.走势) { return (from a in CzList join b in ChartList on a.cid equals b.cid orderby b.seq ascending where a.ename == ename && b.tid == tid && !b.url.IsEmpty() && !b.url.Contains("http") select b).ToList(); } } }