Exemplo n.º 1
0
    protected int defaultOpenTimes    = 179;        //每人销售的期数
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string   GameName = ub.GetSub("GameName", xmlPath);
            DateTime GameBeginTime, GameEndTime, CurrentTime;
            int      GameOpenTimes, SaleTimes, OpenTimes, ValidDays;
            int      StopSec  = defaultStopSec;
            bool     AutoCalc = false;
            #region 读取配置项,并初始化变量
            try
            {
                int.TryParse(ub.GetSub("StopSaleSec", xmlPath), out StopSec);
                if (StopSec <= defaultStopSecMin)
                {
                    StopSec = defaultStopSec;
                }
                //
                string ct1 = ub.GetSub("GameBeginTime", xmlPath);
                string ct2 = ub.GetSub("GameEndTime", xmlPath);
                GameBeginTime = Convert.ToDateTime(ct1);
                GameEndTime   = Convert.ToDateTime(ct2);
                CurrentTime   = DateTime.Now;
                GameOpenTimes = int.Parse(ub.GetSub("GameOpenTimes", xmlPath)); //游戏每天开奖期数
                SaleTimes     = int.Parse(ub.GetSub("SaleTimes", xmlPath));     //每期游戏开售分钟数
                OpenTimes     = int.Parse(ub.GetSub("OpenTimes", xmlPath));     //每期游戏开奖分钟数(在上期停售后N秒后开奖)
                ValidDays     = int.Parse(ub.GetSub("ValidDays", xmlPath));     //当期的兑奖有效日期天数
                myOpenTimes   = OpenTimes;
                mySaleTimes   = SaleTimes;
                myValidDays   = ValidDays;
                int autocalc = int.Parse(ub.GetSub("AutoCalc", xmlPath));
                if (autocalc == 1)
                {
                    AutoCalc = true;
                }
            }
            catch (Exception ex)
            {
                Response.Write("error1“读取配置项并初始化变量”出错!!!" + "</br>");
                Response.Write(ex.Message.Replace("\n", "</br>"));
                return;
            }
            #endregion
            Response.Write("PK10每天的销售时间为" + GameBeginTime.ToShortTimeString() + "至" + GameEndTime.ToShortTimeString() + ",每" + SaleTimes.ToString() + "分钟一期,每天" + GameOpenTimes.ToString().Trim() + "期" + "<br/>");
            //
            PK10_Base _base = new PK10().GetSaleBase();
            #region 判断是否已有初始化(tb_PK10_Base表添加一行ID=0的记录)
            if (_base == null)
            {
                Response.Write("ok1 没有初始化游戏数据" + "<br/>");
                return;
            }
            #endregion

            if (_base.CurrentSaleDate < DateTime.Parse(CurrentTime.ToShortDateString()))
            {
                int newNo = new PK10().GetTodayFistCreateNo();
                if (newNo > 0)
                {
                    #region 初始化新的一天数据
                    //新的一天,从网页抓取正在开售的期
                    Response.Write("初始化新的一天数据...." + "<br/>");
                    string    html = new PK10().GetHtmlByURL();
                    PK10_List list = new PK10().GetCurrentSaleDataByHtml(html);
                    if (list != null)
                    {
                        //初始化当天销售数据(生成将要开售的期号)
                        string cInitFlag = new PK10().InitSaleData(GameBeginTime, newNo, mySaleTimes, myValidDays, GameOpenTimes, StopSec);
                        if (cInitFlag == "")
                        {
                            GetLatestOpenDatas(html, "0");//获取当天已经开奖的数据(补填当天的销售记录)(从百度彩票抓,可以抓到整日的数据)
                        }
                        else
                        {
                            Response.Write("error1 :初始化当天销售数据失败!" + "<br/>");
                        }
                    }
                    else
                    {
                        Response.Write("error1 :抓取网页数据失败!" + "<br/>");
                    }
                    #endregion
                }
                else
                {
                    Response.Write("error1“数据隔了1天以上没抓取过,请先设置今天的开始期号!”" + "</br>");
                    //向上一天插入一跳最后一期的记录,例如:insert into tb_PK10_List(No,date) values('584063','2016-10-30'),不用设置begintime,endtime等。
                }
                return;
            }
            else
            {
                Response.Write("<a href =\"" + Utils.getPage("PK10Get.aspx" + "?act=getall") + "\">" + "手动抓取最近所有开奖数据" + "</a><br/>");
                Response.Write("<a href =\"" + Utils.getPage("PK10Get.aspx") + "\">" + "自动抓取开奖数据" + "</a><br/>");
                Response.Write("<br/>");
                string act = Utils.GetRequest("act", "get", 1, "", "");
                if (act == "getall")
                {
                    Response.Write("【手动抓取最近所有开奖数据...】" + " <br/>");
                    string html = new PK10().GetHtmlByURL();
                    RefreshLatestOpenData(html);
                    GetLatestOpenDatas(html, "0"); //(从百度彩票抓,可以抓到整日的数据)
                }
                else
                {
                    Response.Write("【自动抓取第" + _base.GetOpenDataNo.ToString() + "期】" + "<br/>");
                    #region 读取开奖记录
                    if (CurrentTime < _base.GetOpenDataBeginTime) //未到公布开奖时间
                    {
                        Response.Write("等待开奖公布..." + "<br/>");
                    }
                    else
                    {
                        if (CurrentTime <= _base.GetOpenDataEndTime) //处于本期公布开奖时间,读取开奖记录,并重置下次读取的时间段
                        {
                            string html = new PK10().GetHtmlByURL2();
                            RefreshLatestOpenData(html);
                        }
                        else //超过指定的开奖公布时间,读取最新开奖记录,并重置下次读取的时间段;然后读取已开奖的记录更新开奖(刷新机可能停止运作了一段长的时间)
                        {
                            string html = new PK10().GetHtmlByURL2();
                            RefreshLatestOpenData(html);
                            html = new PK10().GetHtmlByURL();
                            GetLatestOpenDatas(html, _base.GetOpenDataNo); //(从百度彩票抓,可以抓到整日的数据)
                        }
                    }
                    #endregion
                }
            }
            if (AutoCalc)
            {
                CalcOpenData(); //派奖计算
            }
            Response.Write("ok1");
        }
        catch (Exception ex)
        {
            Response.Write("error1" + "<br/>" + ex.Message);
            return;
        }
    }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            _logic = new PK10();
            string   GameName = ub.GetSub("GameName", xmlPath);
            DateTime GameBeginTime, GameEndTime, CurrentTime;
            int      GameOpenTimes, SaleTimes, OpenTimes, isRobot;
            string   Robots;
            #region 读取配置项,并初始化变量
            try
            {
                #region 游戏状态判断
                string GameStatus = ub.GetSub("GameStatus", xmlPath);
                switch (GameStatus)
                {
                case "1":     //维护
                    Utils.Safe(GameName);
                    break;

                case "2":    //内测(PK币)
                case "3":    //公测(PK币)
                    myIsTest = 1;
                    break;

                case "4":    //内测(酷币)
                    myIsTest = 0;
                    break;

                default:      //正常
                    myIsTest = 0;
                    break;
                }
                #endregion
                string ct1 = ub.GetSub("GameBeginTime", xmlPath);
                string ct2 = ub.GetSub("GameEndTime", xmlPath);
                GameBeginTime = Convert.ToDateTime(ct1);
                GameEndTime   = Convert.ToDateTime(ct2);
                CurrentTime   = DateTime.Now;
                GameOpenTimes = int.Parse(ub.GetSub("GameOpenTimes", xmlPath)); //游戏每天开奖期数
                SaleTimes     = int.Parse(ub.GetSub("SaleTimes", xmlPath));     //每期游戏开售分钟数
                OpenTimes     = int.Parse(ub.GetSub("OpenTimes", xmlPath));     //每期游戏开奖分钟数(在上期停售后N分钟后开奖)
                isRobot       = int.Parse(ub.GetSub("isRobot", xmlPath));       //是否启用机器人的标志
                Robots        = ub.GetSub("Robots", xmlPath);                   //机器人列表
                myIsRobot     = (isRobot == 1) ? true : false;
                myRobots      = Robots;
                myMinPayPrice = int.Parse(ub.GetSub("MinPayPrice", xmlPath)); //游戏最小下注单价
                myMaxPayPrice = int.Parse(ub.GetSub("MaxPayPrice", xmlPath)); //游戏最大下注单价
            }
            catch (Exception ex)
            {
                Response.Write("eror1:“读取配置项并初始化变量”出错!!!" + "</br>");
                Response.Write(ex.Message.Replace("\n", "</br>"));
                return;
            }
            #endregion
            Response.Write("PK10每天的销售时间为" + GameBeginTime.ToShortTimeString() + "至" + GameEndTime.ToShortTimeString() + ",每" + SaleTimes.ToString() + "分钟一期,每天" + GameOpenTimes.ToString().Trim() + "期" + "<br/>");
            if (!myIsRobot)
            {
                Response.Write("close1:" + "没设置开启机器人!");
                return;
            }
            #region 排除非销售时间
            //if (CurrentTime < GameBeginTime || CurrentTime > GameEndTime.AddMinutes(SaleTimes))
            //{
            //    Response.Write("ok1:" + "非销售时间!");
            //    return;
            //}
            #endregion
            #region 机器人下注、兑奖
            try
            {
                Response.Write("机器人...下注!" + "</br>");
                OpenRobot();
                Response.Write("ok1");
            }
            catch (Exception ex)
            {
                Response.Write("error1:“机器人下注、兑奖”出错!!!" + "</br>");
                Response.Write(ex.Message.Replace("\n", "</br>"));
                return;
            }
            #endregion
        }
        catch
        {
            Response.Write("error1");
        }
    }