public bool InsertDataMLB(csTeamStat stat) { try { parameters.Clear(); parameters.Add("@pName", stat.Name); parameters.Add("@pAB", stat.AB); parameters.Add("@pPA", stat.PA); parameters.Add("@pH", stat.H); parameters.Add("@pB1", stat.B1); parameters.Add("@pB2", stat.B2); parameters.Add("@pB3", stat.B3); parameters.Add("@pHR", stat.HR); parameters.Add("@pR", stat.R); parameters.Add("@pRBI", stat.RBI); parameters.Add("@pBB", stat.BB); parameters.Add("@pK", stat.K); parameters.Add("@pSF", stat.SF); parameters.Add("@pGDP", stat.GDP); parameters.Add("@pSB", stat.SB); parameters.Add("@pAVG", stat.AVG); parameters.Add("@pOBP", stat.OBP); parameters.Add("@pSLG", stat.SLG); parameters.Add("@pOPS", stat.OPS); return(csConnectionMLB.ExecutePAConfirmation("[dbo].[web_insertMLBstat]", parameters)); } catch (Exception) { return(false); } finally { parameters.Clear(); } }
public ObservableCollection <csTeamStat> ScrapMLB_Stats(string url) { ObservableCollection <csTeamStat> data = new ObservableCollection <csTeamStat>(); csTeamStat t = null; try { string result = string.Empty; HtmlAgilityPack.HtmlWeb web = new HtmlWeb(); HtmlAgilityPack.HtmlDocument doc = web.Load(url); // Get all tables in the document HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table"); //String stringContent = ""; // Iterate all rows in the first table if (tables != null) { for (int k = 0; k < tables.Count; k++) { HtmlNodeCollection rows = tables[k].SelectNodes(".//tr"); if (rows != null) { for (int i = 1; i < rows.Count; ++i) { t = new csTeamStat(); HtmlNodeCollection cols = rows[i].SelectNodes(".//td"); //string stringCellText = ""; if (cols != null) { for (int j = 0; j < cols.Count; ++j) { string txt = cols[j].InnerText.Replace("\r\n", "").Trim().Replace("\t\t (R)", "").Trim().Replace("\t\t (L)", "").Trim(); if (!String.IsNullOrWhiteSpace(txt)) { if (j == 0) { t.Name = txt; } else if (j == 1) { t.AB = Convert.ToInt32(txt); } else if (j == 2) { t.PA = Convert.ToInt32(txt); } else if (j == 3) { t.H = Convert.ToInt32(txt); } else if (j == 4) { t.B1 = Convert.ToInt32(txt); } else if (j == 5) { t.B2 = Convert.ToInt32(txt); } else if (j == 6) { t.B3 = Convert.ToInt32(txt); } else if (j == 7) { t.HR = Convert.ToInt32(txt); } else if (j == 8) { t.R = Convert.ToInt32(txt); } else if (j == 9) { t.RBI = Convert.ToInt32(txt); } else if (j == 10) { t.BB = Convert.ToInt32(txt); } else if (j == 11) { t.K = Convert.ToInt32(txt); } else if (j == 12) { t.SF = Convert.ToInt32(txt); } else if (j == 13) { t.GDP = Convert.ToInt32(txt); } else if (j == 14) { t.SB = Convert.ToInt32(txt); } else if (j == 15) { t.AVG = Convert.ToDouble(txt); } else if (j == 16) { t.OBP = Convert.ToDouble(txt); } else if (j == 17) { t.SLG = Convert.ToDouble(txt); } else if (j == 18) { t.OPS = Convert.ToDouble(txt); } } } data.Add(t); } } } //stringContent = stringContent.Replace("</script>", ""); } } } catch (Exception ex) { throw new Exception(ex.Message); } return(data); }