public bool InsertScore(csScore s) { try { int o; parameters.Clear(); parameters.Add("@pAwayRot", Convert.ToInt32(s.awayRot.Trim())); parameters.Add("@pHomeRot", Convert.ToInt32(s.homeRot.Trim())); parameters.Add("@pAwayScore", (s.awayScore == "x" || !int.TryParse(s.awayScore, out o)) ? null : s.awayScore.Trim()); parameters.Add("@pHomeScore", (s.homeScore == "x" || !int.TryParse(s.homeScore, out o)) ? null : s.homeScore.Trim()); parameters.Add("@pPeriod", s.period); parameters.Add("@pDescription1", (String.IsNullOrWhiteSpace(s.description1) && (s.awayScore == "x")) ? "X" : s.description1); parameters.Add("@pSportId", Convert.ToInt32(s.sportId.Trim())); parameters.Add("@pDate", s.date); parameters.Add("@pDescription2", (String.IsNullOrWhiteSpace(s.description2) && (s.homeScore == "x")) ? "X" : s.description2); csDonBest.ExecutePAConfimation("[dbo].[web_insertScore]", parameters); } catch (Exception ex) { return(false); } finally { parameters.Clear(); } return(true); }
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(" ", "").Trim().Replace(" ", "").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(" ", "").Replace("\n", "").Trim(); score.description2 = i.Values[j + 1].Val2.Replace(" ", "").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() + ""; } }