Example #1
0
        public void SyncUp()
        {
            DateTime?dt      = GetLastUpdate();
            blScores scoreDB = new blScores();

            if (dt != null)
            {
                TimeSpan t    = DateTime.Now - Convert.ToDateTime(dt);
                DateTime date = Convert.ToDateTime(dt);
                int      days = Convert.ToInt32(t.TotalDays);

                for (int i = 0; i <= days; i++)
                {
                    SetInfo(date.Year + "-" + ((date.Month < 10) ? "0" + date.Month.ToString() : date.Month.ToString()) + "-" + ((date.Day < 10) ? "0" + date.Day.ToString() : date.Day.ToString()));
                    date = date.AddDays(1);
                }
            }

            // SetInfo("2018-08-02");
        }
Example #2
0
        private void SetInfo(string date)
        {
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://server1.donbest.com/scores/" + date + "/all.html?");

            myRequest.Method = "GET";
            try
            {
                WebResponse  myResponse = myRequest.GetResponse();
                StreamReader sr         = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
                string       result     = sr.ReadToEnd();
                var          doc        = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(result);

                foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table"))
                {
                    int  tableNumber = 0;
                    bool flag = false, first = false;

                    foreach (HtmlNode row in table.SelectNodes("tr"))
                    {
                        string f = row.InnerText;

                        if (f.ToUpper().Contains("SCORES"))
                        {
                            sport = CastIdSportDonBest2(f);
                        }

                        foreach (HtmlNode cell in row.SelectNodes("td"))
                        {
                            String c = cell.InnerText.ToString().Replace("&nbsp;", "").Trim().Replace("&nbsp", "").Trim();

                            if (DetectNumber(c))
                            {
                                first = flag = true;
                            }

                            if (flag)
                            {
                                if (tableNumber == 0) //save the headers
                                {
                                    if (first)
                                    {
                                        Headers.Add("rot");
                                        Headers.Add("team");
                                        first = false;
                                    }
                                    else
                                    {
                                        if (sport != "10" && sport != "8" && c.Trim() == "T")
                                        {
                                            Headers.Add(c);
                                            Headers.Add("status");
                                        }
                                        else if (sport == "8" && c.Trim() == "T")
                                        {
                                            Headers.Add("status");
                                        }
                                        else
                                        {
                                            Headers.Add(c);
                                        }
                                    }
                                }
                                else if (tableNumber == 1)//add values for the opponent 1
                                {
                                    Opp1.Add(c);
                                }
                                else if (tableNumber == 2)
                                {
                                    Opp2.Add(c);
                                }
                            }
                        }

                        if (flag)
                        {
                            tableNumber++;
                        }
                    }


                    int n1 = Headers.Count;
                    int n2 = Opp1.Count;
                    int n3 = Opp2.Count;

                    if (Headers.Count == Opp1.Count && Opp1.Count == Opp2.Count && Headers.Count > 0)
                    {
                        csScore score = new csScore();
                        for (int i = 0; i < Headers.Count; i++)
                        {
                            score.Values.Add(new csDictionary(Headers[i], Opp1[i], Opp2[i]));
                        }
                        score.sportId = sport;
                        ScoreList.Add(score);
                    }
                    else if (Headers.Count > 0)
                    {
                        int dssd = 0;
                    }
                    ClearValues();
                }

                blScores scoreDB = new blScores();
                if (ScoreList != null && ScoreList.Count > 0)
                {
                    foreach (var i in ScoreList)
                    {
                        csScore score = i;
                        score.awayRot = i.Values[0].Val1;
                        score.homeRot = i.Values[0].Val2;

                        for (int j = 2; j < i.Values.Count; j++)
                        {
                            if (i.Values[j].Header.ToUpper().Contains("OPEN"))
                            {
                                break;
                            }

                            score.period    = i.Values[j].Header;
                            score.awayScore = i.Values[j].Val1;
                            score.homeScore = i.Values[j].Val2;
                            score.sportId   = i.sportId;
                            score.date      = date;

                            if ((j + 1) < (ScoreList.Count - 1) && i.Values[j + 1].Header == "status")
                            {
                                score.description1 = i.Values[j + 1].Val1.Replace("&nbsp;", "").Replace("\n", "").Trim();
                                score.description2 = i.Values[j + 1].Val2.Replace("&nbsp;", "").Replace("\n", "").Trim();
                            }
                            else
                            {
                                score.description1 = "";
                                score.description2 = "";
                            }

                            if (i.Values[j].Header != "status")
                            {
                                scoreDB.InsertScore(score);
                            }
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                //lblNotFound.Text = "There is nothing to read. Error: " + ex.ToString() + "";
            }
        }