예제 #1
0
        private static void SetData(string realHtml, List<SuperLottoModel> list)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(realHtml);

            XmlNodeList nodeList = xmlDoc.SelectNodes("/table/tbody/tr");

            foreach (XmlNode item in nodeList)
            {
                SuperLottoModel sl = new SuperLottoModel();

                XmlNodeList itemNodeList = item.ChildNodes;
                XmlNode firstNode = itemNodeList[0];
                sl.Phase = firstNode.ChildNodes[0].InnerText;

                XmlNode SecondNode = itemNodeList[1];
                int weekStart = SecondNode.InnerText.IndexOf("(");
                int weekEnd = SecondNode.InnerText.IndexOf(")");
                string str = SecondNode.InnerText.Substring(0, weekStart);
                sl.LotteryDate = Convert.ToDateTime(str);
                sl.Week = SecondNode.InnerText.Substring(weekStart, weekEnd - weekStart + 1);

                XmlNodeList redBalls = itemNodeList[2].ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes;
                sl.FirstRedBall = Convert.ToInt32(redBalls[0].InnerText);
                sl.SecondRedBall = Convert.ToInt32(redBalls[1].InnerText);
                sl.ThirdRedBall = Convert.ToInt32(redBalls[2].InnerText);
                sl.FourthRedBall = Convert.ToInt32(redBalls[3].InnerText);
                sl.FifthRedBall = Convert.ToInt32(redBalls[4].InnerText);
                XmlNodeList blueBalls = itemNodeList[2].ChildNodes[0].ChildNodes[0].ChildNodes[1].ChildNodes;
                sl.FirstBlueBall = Convert.ToInt32(blueBalls[0].InnerText);
                sl.SecondBlueBall = Convert.ToInt32(blueBalls[1].InnerText);
                list.Add(sl);
            }
        }
예제 #2
0
        public void Add(SuperLottoModel model)
        {
            var TempModel = db.SuperLotto.Where(i => i.Phase == model.Phase).FirstOrDefault();
            if (TempModel != null)
            {
                return;
            }
            SuperLotto lottoModel = new SuperLotto()
            {
                Phase = model.Phase,
                LotteryDate = model.LotteryDate,
                Week = model.Week,
                CreateTime = DateTime.Now,
                LotteryType = 1
            };
            SuperLottoClass lottoClass = new SuperLottoClass() {
                Phase=model.Phase,
                LotteryDate=model.LotteryDate,
                Week=model.Week,
                FirstRedBall =model.FirstRedBall,
                SecondRedBall = model.SecondRedBall,
                ThirdRedBall=model.ThirdRedBall,
                FourthRedBall=model.FourthRedBall,
                FifthRedBall=model.FifthRedBall,
                FirstBlueBall=model.FirstBlueBall,
                SecondBlueBall=model.SecondBlueBall
            };

            lottoModel = db.SuperLotto.Add(lottoModel);
            db.SaveChanges();
            db.SuperLottoClass.Add(lottoClass);
            Ball firstRedBall = new Ball()
            {
                SuperLottoId = lottoModel.Id,
                BallValue = model.FirstRedBall,
                BallType = 1,
                Sort = 1
            };
            db.Ball.Add(firstRedBall);
            Ball SecondRedBall = new Ball()
            {
                SuperLottoId = lottoModel.Id,
                BallValue = model.SecondRedBall,
                BallType = 1,
                Sort = 2
            };
            db.Ball.Add(SecondRedBall);
            Ball ThirdRedBall = new Ball()
            {
                SuperLottoId = lottoModel.Id,
                BallValue = model.ThirdRedBall,
                BallType = 1,
                Sort = 3
            };
            db.Ball.Add(ThirdRedBall);
            Ball FourthRedBall = new Ball()
            {
                SuperLottoId = lottoModel.Id,
                BallValue = model.FourthRedBall,
                BallType = 1,
                Sort = 4
            };
            db.Ball.Add(FourthRedBall);
            Ball FifthRedBall = new Ball()
            {
                SuperLottoId = lottoModel.Id,
                BallValue = model.FifthRedBall,
                BallType = 1,
                Sort = 5
            };
            db.Ball.Add(FifthRedBall);
            Ball FirstBlueBall = new Ball()
            {
                SuperLottoId = lottoModel.Id,
                BallValue = model.FirstBlueBall,
                BallType = 2,
                Sort = 1
            };
            db.Ball.Add(FirstBlueBall);
            Ball SecondBlueBall = new Ball()
            {
                SuperLottoId = lottoModel.Id,
                BallValue = model.SecondBlueBall,
                BallType = 2,
                Sort = 1
            };
            db.Ball.Add(SecondBlueBall);
        }