Example #1
0
        /// <summary>
        /// 读取北京下期期号
        /// </summary>
        /// <returns></returns>
        public CollectResultEntity GetBeijingNextPeriodNum()
        {
            CollectResultEntity result = new CollectResultEntity();

            string sql = @"SELECT TOP 1 [PeriodNum],[RetTime] FROM [Helpmate].[dbo].[SourceData_28_Beijing] ORDER BY [PeriodNum] DESC";
            DBHelper db = new DBHelper();
            try
            {
                DataTable dt = db.ExeSqlDataAdapter(CommandType.Text, sql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    result.PeriodNum = long.Parse(dt.Rows[0]["PeriodNum"].ToString()) + 1;
                    result.RetTime = DateTime.Parse(dt.Rows[0]["RetTime"].ToString());
                    //到23:55当天开奖就结束了,下一期在第二天9:05
                    if (result.RetTime.Hour == 23 && result.RetTime.Minute == 55)
                        result.RetTime = DateTime.Parse(string.Format("{0} 9:05", result.RetTime.ToShortDateString())).AddDays(1);
                    else
                        result.RetTime = result.RetTime.AddMinutes(5);
                }
                else
                {
                    result.PeriodNum = 0;
                }
            }
            catch (Exception ex)
            {
                WriteLog.Write(string.Format("GetBeijingNextPeriodNum读取SQL Server数据库期号失败,sql:{0},错误信息:{1}", sql, ex.ToString()));
            }
            finally
            {
                db.Dispose();
            }

            return result;
        }
Example #2
0
        /// <summary>
        /// 读取北京失败期列表
        /// </summary>
        /// <returns></returns>
        public List<CollectResultEntity> GetBeijingFailPeriodList()
        {
            List<CollectResultEntity> result = null;

            string sql = @"SELECT [PeriodNum],[RetTime] FROM [Helpmate].[dbo].[SourceData_28_Beijing] WHERE [Status] = -1";
            DBHelper db = new DBHelper();
            try
            {
                DataTable dt = db.ExeSqlDataAdapter(CommandType.Text, sql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    result = new List<CollectResultEntity>();
                    foreach (DataRow row in dt.Rows)
                    {
                        CollectResultEntity item = new CollectResultEntity();
                        item.PeriodNum = long.Parse(row["PeriodNum"].ToString());
                        item.RetTime = DateTime.Parse(row["RetTime"].ToString());
                        result.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.Write(string.Format("GetBeijingFailPeriodList读取SQL Server数据库失败期列表失败,sql:{0},错误信息:{1}", sql, ex.ToString()));
            }
            finally
            {
                db.Dispose();
            }

            return result;
        }
        /// <summary>
        /// 计算北京龙虎网站数据
        /// </summary>
        /// <param name="collectResult">采集结果</param>
        /// <returns></returns>
        public SourceDataEntity Calculate(CollectResultEntity collectResult)
        {
            SourceDataEntity result = new SourceDataEntity();

            result.PeriodNum = collectResult.PeriodNum;
            result.RetTime = collectResult.RetTime;
            result.SiteSysNo = (int)Site.LongHu;
            result.CollectRet = collectResult.Result;
            result.Status = 1;

            #region retMidNum
            int retMidNum1 = 0;
            int retMidNum2 = 0;
            int retMidNum3 = 0;
            //取2 5 8 11 14 17位数字之和
            int i = 1;
            while (i < 17)
            {
                retMidNum1 += collectResult.Group[i];
                i += 3;
            }
            //取3 6 9 12 15 18位数字之和
            int j = 2;
            while (j < 18)
            {
                retMidNum2 += collectResult.Group[j];
                j += 3;
            }
            //取4 7 10 13 16 19位数字之和
            int k = 3;
            while (k < 19)
            {
                retMidNum3 += collectResult.Group[k];
                k += 3;
            }
            #endregion

            #region RetNum
            int retNum = retMidNum1 % 10;
            retNum += retMidNum2 % 10;
            retNum += retMidNum3 % 10;
            #endregion

            #region RetOddNum
            int retOddNum = (retMidNum1 % 10) * 100 + (retMidNum2 % 10) * 10 + (retMidNum3 % 10);
            #endregion

            result.RetOddNum = retOddNum;
            result.RetNum = retNum;
            result.RetMidNum = string.Format("{0}|{1}|{2}", retMidNum1, retMidNum2, retMidNum3);

            return result;
        }
        /// <summary>
        /// 计算北京71豆网站数据
        /// </summary>
        /// <param name="collectResult">采集结果</param>
        /// <returns></returns>
        public SourceDataEntity Calculate(CollectResultEntity collectResult)
        {
            SourceDataEntity result = new SourceDataEntity();

            result.PeriodNum = collectResult.PeriodNum;
            result.RetTime = collectResult.RetTime;
            result.SiteSysNo = (int)Site.QiYiDou;
            result.CollectRet = collectResult.Result;
            result.Status = 1;

            #region retMidNum
            int retMidNum1 = 0;
            int retMidNum2 = 0;
            int retMidNum3 = 0;
            //取1-6位数字之和
            for (int i = 0; i < 6; i++)
                retMidNum1 += collectResult.Group[i];
            //取7-12位数字之和
            for (int i = 6; i < 12; i++)
                retMidNum2 += collectResult.Group[i];
            //取13-18位数字之和
            for (int i = 12; i < 18; i++)
                retMidNum3 += collectResult.Group[i];
            #endregion

            #region RetNum
            int retNum = retMidNum1 % 10;
            retNum += retMidNum2 % 10;
            retNum += retMidNum3 % 10;
            #endregion

            #region RetOddNum
            int retOddNum = (retMidNum1 % 10) * 100 + (retMidNum2 % 10) * 10 + (retMidNum3 % 10);
            #endregion

            result.RetOddNum = retOddNum;
            result.RetNum = retNum;
            result.RetMidNum = string.Format("{0}|{1}|{2}", retMidNum1, retMidNum2, retMidNum3);

            return result;
        }
 /// <summary>
 /// 采集北京数据
 /// </summary>
 /// <param name="periodNum">期号</param>
 /// <param name="dtTime">开奖时间</param>
 /// <returns></returns>
 public CollectResultEntity Collect(long periodNum, DateTime dtTime)
 {
     CollectResultEntity result = new CollectResultEntity();
     string urlType = GetConfig.GetXMLValue(ConfigSource.Beijing, "UrlType");
     switch (urlType)
     {
         //使用地址1
         case "1":
             result = CollectBeijingData.Instance().CollectUrl1(periodNum);
             break;
         //使用地址2
         case "2":
             result = CollectBeijingData.Instance().CollectUrl2(periodNum);
             break;
         //使用地址3
         case "3":
             result = CollectBeijingData.Instance().CollectUrl3(periodNum, dtTime);
             break;
         //3个地址都使用,先使用地址3,地址3失败使用地址2,地址2失败则使用地址1
         case "4":
             result = CollectBeijingData.Instance().CollectUrl3(periodNum, dtTime);
             if (result == null || result.Group == null || result.Group.Length != 20)
                 result = CollectBeijingData.Instance().CollectUrl2(periodNum);
             if (result == null || result.Group == null || result.Group.Length != 20)
                 result = CollectBeijingData.Instance().CollectUrl1(periodNum);
             break;
         //使用1,2两个地址,先使用地址2,地址2失败则使用地址1
         case "5":
             result = CollectBeijingData.Instance().CollectUrl2(periodNum);
             if (result == null || result.Group == null || result.Group.Length != 20)
                 result = CollectBeijingData.Instance().CollectUrl1(periodNum);
             break;
         default:
             result = new CollectResultEntity();
             break;
     }
     return result;
 }
Example #6
0
        /// <summary>
        /// 计算加拿大28数据
        /// </summary>
        /// <param name="collectResult">采集结果</param>
        /// <returns></returns>
        private List<SourceDataEntity> CalculateCanada28Data(CollectResultEntity collectResult)
        {
            List<SourceDataEntity> result = null;

            ICalculate28Data calculateData = null;

            #region 计算龙虎网站数据
            calculateData = CalculateLongHu28Data.Instance();
            SourceDataEntity itemLongHu = calculateData.CalculateCanada(collectResult);
            if (itemLongHu != null)
            {
                result = new List<SourceDataEntity>();
                result.Add(itemLongHu);
            }
            #endregion

            #region 计算71豆网站数据
            calculateData = CalculateQiYiDou28Data.Instance();
            SourceDataEntity itemQiYiDou = calculateData.CalculateCanada(collectResult);
            if (itemQiYiDou != null)
            {
                if (result == null)
                    result = new List<SourceDataEntity>();
                result.Add(itemQiYiDou);
            }
            #endregion

            #region 计算芝麻西西网站数据
            calculateData = CalculateZhiMaXiXi28Data.Instance();
            SourceDataEntity itemZhiMaXiXi = calculateData.CalculateCanada(collectResult);
            if (itemZhiMaXiXi != null)
            {
                if (result == null)
                    result = new List<SourceDataEntity>();
                result.Add(itemZhiMaXiXi);
            }
            #endregion

            return result;
        }
Example #7
0
        /// <summary>
        /// 读取下期期号
        /// </summary>
        /// <param name="source">采集计算源</param>
        /// <returns></returns>
        public CollectResultEntity GetNextPeriodNum(Source source)
        {
            CollectResultEntity result = new CollectResultEntity();

            switch (source)
            {
                case Source.Beijing:
                    result = SourceDataDA.Instance().GetBeijingNextPeriodNum();
                    break;
                case Source.Canadan:
                    result = SourceDataDA.Instance().GetCanadanNextPeriodNum();
                    break;
                default:
                    result.PeriodNum = -1;
                    break;
            }

            //如果期号为0,则需要从网站采集
            if (result.PeriodNum == 0)
            {
                switch (source)
                {
                    case Source.Beijing:
                        result = CollectBeijingData.Instance().CollectPeriodNum();
                        break;
                    case Source.Canadan:
                        result = CollectCanadanData.Instance().CollectPeriodNum();
                        break;
                    default:
                        result.PeriodNum = -1;
                        break;
                }
            }

            return result;
        }
Example #8
0
        /// <summary>
        /// 读取加拿大下期期号
        /// </summary>
        /// <returns></returns>
        public CollectResultEntity GetCanadanNextPeriodNum()
        {
            CollectResultEntity result = new CollectResultEntity();

            string sql = @"SELECT TOP 1 [PeriodNum],[RetTime] FROM [Helpmate].[dbo].[SourceData_28_Canada] ORDER BY [PeriodNum] DESC";
            DBHelper db = new DBHelper();
            try
            {
                DataTable dt = db.ExeSqlDataAdapter(CommandType.Text, sql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    result.PeriodNum = long.Parse(dt.Rows[0]["PeriodNum"].ToString()) + 1;
                    result.RetTime = DateTime.Parse(dt.Rows[0]["RetTime"].ToString());
                    result.RetTime = result.RetTime.AddMinutes(4);
                }
                else
                {
                    result.PeriodNum = 0;
                }
            }
            catch (Exception ex)
            {
                WriteLog.Write(string.Format("GetCanadanNextPeriodNum读取SQL Server数据库期号失败,sql:{0},错误信息:{1}", sql, ex.ToString()));
            }
            finally
            {
                db.Dispose();
            }

            return result;
        }
        /// <summary>
        /// 采集加拿大数据
        /// </summary>
        /// <param name="periodNum">期号</param>
        /// <param name="dtTime">开奖时间(北京时间)</param>
        /// <returns></returns>
        public List<CollectResultEntity> CollectData(long periodNum, DateTime dtTime)
        {
            List<CollectResultEntity> result = new List<CollectResultEntity>();

            try
            {
                string url = string.Empty;
                string resultData = string.Empty;

                url = GetConfig.GetXMLValue(ConfigSource.Canadan, "PeriodNumUrl");
                dtTime = (new GetTime()).ConvertBeijingToCanadan(dtTime);
                url = string.Format(url, (new GetTime()).FormatCanadanCollectDate(dtTime));
                resultData = HttpHelper.GetHttpData(url);
                if (string.IsNullOrEmpty(resultData) || !resultData.Contains(periodNum.ToString()))
                    return null;

                List<Draw> drawList = new List<Draw>();
                drawList = JsonHelper.JsonToObj<List<Draw>>(resultData);
                if (drawList != null && drawList.Count > 0)
                {
                    drawList = drawList.OrderByDescending(m => m.drawNbr).ToList();
                    long nowMaxPeriodNum = drawList[0].drawNbr;
                    while (true)
                    {
                        Draw item = drawList.Find(delegate(Draw d) { return d.drawNbr == periodNum; });
                        if (item == null || periodNum > nowMaxPeriodNum)
                            break;
                        CollectResultEntity itemResult = new CollectResultEntity();
                        itemResult.Group = item.drawNbrs;
                        if (itemResult.Group != null && itemResult.Group.Length == 20)
                        {
                            itemResult.PeriodNum = item.drawNbr;
                            DateTime retTime = DateTime.Parse(string.Format("{0} {1}", item.drawDate, item.drawTime));
                            itemResult.RetTime = (new GetTime()).ConvertCanadanToBeijing(retTime);
                            itemResult.Result = itemResult.Group[0].ToString();
                            for (int i = 1; i < itemResult.Group.Length; i++)
                            {
                                itemResult.Result += string.Format("|{0}", itemResult.Group[i]);
                            }
                            result.Add(itemResult);
                        }
                        periodNum++;
                    }
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                WriteLog.Write(ex.ToString());
            }

            return result;
        }
        /// <summary>
        /// 采集期号
        /// </summary>
        /// <returns></returns>
        public CollectResultEntity CollectPeriodNum()
        {
            CollectResultEntity result = new CollectResultEntity();

            int tryTimes = 10;
            while (tryTimes > 0)
            {
                try
                {
                    string url = string.Empty;
                    string resultData = string.Empty;

                    url = GetConfig.GetXMLValue(ConfigSource.Canadan, "GetNewPeriodNumUrl");
                    DateTime dtTime = (new GetTime()).ConvertBeijingToCanadan(DateTime.Now);
                    url = string.Format(url, (new GetTime()).FormatCanadanCollectDate(dtTime));
                    resultData = HttpHelper.GetHttpData(url);
                    if (string.IsNullOrEmpty(resultData))
                    {
                        tryTimes--;
                        Thread.Sleep(10000);
                        continue;
                    }

                    List<Draw> drawList = new List<Draw>();
                    drawList = JsonHelper.JsonToObj<List<Draw>>(resultData);
                    if (drawList != null && drawList.Count > 0)
                    {
                        drawList = drawList.OrderByDescending(m => m.drawNbr).ToList();
                        Draw draw = drawList[0];
                        DateTime retTime = DateTime.Parse(string.Format("{0} {1}", draw.drawDate, draw.drawTime));
                        result.RetTime = (new GetTime()).ConvertCanadanToBeijing(retTime);
                        result.PeriodNum = draw.drawNbr;
                        tryTimes = 0;
                    }
                    else
                    {
                        tryTimes--;
                        Thread.Sleep(10000);
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    result.PeriodNum = 0;
                    WriteLog.Write(ex.ToString());
                    tryTimes--;
                    Thread.Sleep(10000);
                }
            }

            return result;
        }
 /// <summary>
 /// 采集期号
 /// </summary>
 /// <returns></returns>
 public CollectResultEntity CollectPeriodNum()
 {
     CollectResultEntity result = new CollectResultEntity();
     string urlType = GetConfig.GetXMLValue(ConfigSource.Beijing, "UrlType");
     switch (urlType)
     {
         case "1":
             result = CollectBeijingData.Instance().CollectPeriodNum1();
             break;
         case "2":
             result = CollectBeijingData.Instance().CollectPeriodNum2();
             break;
         case "3":
             result = CollectBeijingData.Instance().CollectPeriodNum3();
             break;
         case "4":
             result = CollectBeijingData.Instance().CollectPeriodNum3();
             if (result == null || result.PeriodNum <= 0)
                 result = CollectBeijingData.Instance().CollectPeriodNum2();
             if (result == null || result.PeriodNum <= 0)
                 result = CollectBeijingData.Instance().CollectPeriodNum1();
             break;
         case "5":
             result = CollectBeijingData.Instance().CollectPeriodNum2();
             if (result == null || result.PeriodNum <= 0)
                 result = CollectBeijingData.Instance().CollectPeriodNum1();
             break;
         default:
             result.PeriodNum = 0;
             break;
     }
     return result;
 }
        /// <summary>
        /// 采集北京地址3数据
        /// </summary>
        /// <param name="periodNum">期号</param>
        /// <returns></returns>
        private CollectResultEntity CollectUrl3(long periodNum, DateTime dtTime)
        {
            CollectResultEntity result = new CollectResultEntity();

            int tryTimes = 3;
            while (tryTimes > 0)
            {
                try
                {
                    string url = string.Empty;
                    string resultData = string.Empty;

                    url = GetConfig.GetXMLValue(ConfigSource.Beijing, "PeriodNumUrl3");
                    url = string.Format(url, (new GetTime()).FormatBeijingCollectDate(dtTime));
                    resultData = HttpHelper.GetHttpDataUTF8(url);
                    if (string.IsNullOrEmpty(resultData))
                    {
                        tryTimes--;
                        Thread.Sleep(5000);
                        continue;
                    }
                    CQ cq = resultData;

                    int i = 1;
                    string periodNumExpression = "";
                    string dataExpression = "";
                    while (i <= 500)
                    {
                        periodNumExpression = string.Format("tr:eq({0})>td:eq(0)", i);
                        dataExpression = string.Format("tr:eq({0})>td:eq(1)", i);
                        if (cq[periodNumExpression].Text().Trim() == periodNum.ToString())
                        {
                            resultData = cq[dataExpression].Text().Trim();
                            break;
                        }
                        i++;
                    }
                    resultData = resultData.Replace('-', '|');

                    result.Result = resultData;
                    result.Group = Array.ConvertAll<string, int>(resultData.Split('|'), delegate(string s) { return int.Parse(s); });
                    tryTimes = 0;
                }
                catch (Exception ex)
                {
                    WriteLog.Write(ex.ToString());
                    tryTimes--;
                    Thread.Sleep(5000);
                }
            }

            return result;
        }
        /// <summary>
        /// 采集北京地址2数据
        /// </summary>
        /// <param name="periodNum">期号</param>
        /// <returns></returns>
        private CollectResultEntity CollectUrl2(long periodNum)
        {
            CollectResultEntity result = new CollectResultEntity();

            int tryTimes = 3;
            while (tryTimes > 0)
            {
                try
                {
                    string url = string.Empty;
                    string resultData = string.Empty;

                    url = GetConfig.GetXMLValue(ConfigSource.Beijing, "PeriodNumUrl2");
                    url = string.Format(url, periodNum);
                    resultData = HttpHelper.GetHttpDataUTF8(url);
                    if (string.IsNullOrEmpty(resultData))
                    {
                        tryTimes--;
                        Thread.Sleep(5000);
                        continue;
                    }
                    CQ cq = resultData;
                    resultData = cq["div #gameListItem-2"].Find("tr.dataBack1:eq(0)>td:eq(1)").Text().Trim();
                    resultData = resultData.Replace(',', '|');
                    result.Result = resultData;
                    result.Group = Array.ConvertAll<string, int>(resultData.Split('|'), delegate(string s) { return int.Parse(s); });
                    tryTimes = 0;
                }
                catch (Exception ex)
                {
                    WriteLog.Write(ex.ToString());
                    tryTimes--;
                    Thread.Sleep(5000);
                }
            }

            return result;
        }
        /// <summary>
        /// 采集北京地址1数据
        /// </summary>
        /// <param name="periodNum">期号</param>
        /// <returns></returns>
        private CollectResultEntity CollectUrl1(long periodNum)
        {
            CollectResultEntity result = new CollectResultEntity();

            int tryTimes = 3;
            while (tryTimes > 0)
            {
                try
                {
                    string url = string.Empty;
                    string resultData = string.Empty;

                    url = GetConfig.GetXMLValue(ConfigSource.Beijing, "PeriodNumUrl");
                    url = string.Format(url, periodNum);
                    resultData = HttpHelper.GetHttpDataUTF8(url);
                    if (string.IsNullOrEmpty(resultData))
                    {
                        tryTimes--;
                        Thread.Sleep(5000);
                        continue;
                    }
                    CQ cq = resultData;

                    CQ val = cq["li"];
                    resultData = "";
                    for (int i = 0; i < val.Length; i++)
                    {
                        if (i == val.Length - 1)
                            resultData += val[i].TextContent.Trim();
                        else
                            resultData += string.Format("{0}|", val[i].TextContent.Trim());
                    }
                    result.Result = resultData;
                    result.Group = Array.ConvertAll<string, int>(resultData.Split('|'), delegate(string s) { return int.Parse(s); });
                    tryTimes = 0;
                }
                catch (Exception ex)
                {
                    WriteLog.Write(ex.ToString());
                    tryTimes--;
                    Thread.Sleep(5000);
                }
            }

            return result;
        }
        /// <summary>
        /// 采集地址3期号
        /// </summary>
        /// <returns></returns>
        private CollectResultEntity CollectPeriodNum3()
        {
            CollectResultEntity result = new CollectResultEntity();

            int tryTimes = 10;
            while (tryTimes > 0)
            {
                try
                {
                    string url = string.Empty;
                    string resultData = string.Empty;

                    url = GetConfig.GetXMLValue(ConfigSource.Beijing, "GetNewPeriodNumUrl3");
                    url = string.Format(url, (new GetTime()).FormatBeijingCollectDate(DateTime.Now));
                    resultData = HttpHelper.GetHttpDataUTF8(url);
                    if (string.IsNullOrEmpty(resultData))
                    {
                        tryTimes--;
                        Thread.Sleep(10000);
                        continue;
                    }

                    CQ cq = resultData;
                    resultData = cq["tr:eq(1)>td:eq(0)"].Text().Trim();
                    long periondNum = 0;
                    long.TryParse(resultData, out periondNum);
                    if (periondNum <= 0)
                    {
                        tryTimes--;
                        Thread.Sleep(10000);
                        continue;
                    }
                    //期号
                    result.PeriodNum = periondNum;
                    //时间
                    DateTime dtRetTime = (new GetTime()).NowTime(ConfigSource.Beijing);
                    DateTime dtNow = (new GetTime()).NowTime(ConfigSource.Beijing);
                    int hour = dtNow.Hour;

                    if (hour >= 0 && hour < 9)
                    {
                        dtRetTime = DateTime.Parse(string.Format("{0} 23:55:00", dtNow.ToShortDateString()));
                    }
                    else
                    {
                        int minute = dtNow.Minute % 5;
                        int second = dtNow.Second;
                        dtRetTime = dtNow.AddMinutes(0 - minute).AddSeconds(0 - second);
                    }
                    result.RetTime = dtRetTime;
                    tryTimes = 0;
                }
                catch (Exception ex)
                {
                    result.PeriodNum = 0;
                    WriteLog.Write(ex.ToString());
                    tryTimes--;
                    Thread.Sleep(10000);
                }
            }

            return result;
        }