public static BOBet GetByExternalID(long id) { SqlConnection con = new SqlConnection(BOBase.GetConnectionString()); BOBet bet = null; con.Open(); try { SqlCommand cmd = new SqlCommand("P_Bet_GetByExternalID", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ExternalID", SqlDbType.BigInt).Value = id; SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow); try { while (rdr.Read()) { bet = new BOBet(rdr); } } finally { rdr.Close(); } } finally { con.Close(); } return bet; }
public BOBetComparer(BOBet.Columns column, BOBet.SortDirections direction) { _column = column; _direction = direction; }
public static void SpiderCurrentBets() { // This code needs to be moved WebClient Client = new WebClient(); string HTML = Client.DownloadString("http://dota2lounge.com/"); HtmlDocument document = new HtmlDocument(); document.LoadHtml(HTML); var bets = document.DocumentNode.Descendants().Where(d => d.Name.Contains("article")).ToArray()[1].SelectNodes("div"); foreach (HtmlNode node in bets) { HtmlNode nodeT = node.SelectSingleNode("div"); HtmlNode atag = node.SelectSingleNode("div//div//a"); string matchNumber = Regex.Match(atag.Attributes[0].Value, "\\d+").Value; long externalID = 0; long.TryParse(matchNumber, out externalID); if (nodeT.InnerText.ToLower().Contains("wrong match")) { // Node should be deleted and or skipped BOBet b = BOBet.GetByExternalID(externalID); if(b != null) { b.Delete(); } } else { // Get the data from html string tournament = nodeT.SelectNodes("div")[1].InnerText.Trim(); string timeFromNow = nodeT.SelectNodes("div")[0].InnerText.Trim(); string dFromNow = Regex.Match(timeFromNow.ToLower(), "\\d+ days from now").Value.Replace(" days from now", ""); string hFromNow = Regex.Match(timeFromNow.ToLower(), "\\d+ hours from now").Value.Replace(" hours from now", ""); string mFromNow = Regex.Match(timeFromNow.ToLower(), "\\d+ minutes from now").Value.Replace(" minutes from now", ""); string dAgo = Regex.Match(timeFromNow.ToLower(), "\\d+ days ago").Value.Replace(" days ago", ""); string hAgo = Regex.Match(timeFromNow.ToLower(), "\\d+ hours ago").Value.Replace(" hours ago", ""); string mAgo = Regex.Match(timeFromNow.ToLower(), "\\d+ minutes ago").Value.Replace(" minutes ago", ""); HtmlNode nodeM = node.SelectNodes("div")[1]; HtmlNode nodeT1 = nodeM.SelectNodes("div//div//div")[1]; string t1Name = nodeT1.SelectSingleNode("b").InnerText.Trim(); string t1Odds = "." + nodeT1.SelectSingleNode("i").InnerText.Replace("%","").Trim(); HtmlNode nodeT2 = nodeM.SelectNodes("div//div//div")[3]; string t2Name = nodeT2.SelectSingleNode("b").InnerText.Trim(); string t2Odds = "." + nodeT2.SelectSingleNode("i").InnerText.Replace("%", "").Trim(); // Parse the data into values instead of strings // Get the date time from time from now int dfn = 0; int hfn = 0; int mfn = 0; int da = 0; int ha = 0; int ma = 0; int.TryParse(dFromNow, out dfn); int.TryParse(hFromNow, out hfn); int.TryParse(mFromNow, out mfn); int.TryParse(dAgo, out da); int.TryParse(hAgo, out ha); int.TryParse(mAgo, out ma); DateTime date = DateTime.Now.AddDays(dfn - da).AddHours(hfn - ha).AddMinutes(mfn - ma); decimal odds = 0; decimal.TryParse(t1Odds, out odds); // Start populating the business objects and saving them BOBet bet = BOBet.GetByExternalID(externalID); if (bet == null) bet = new BOBet(); BOBetTeam t1 = BOBetTeam.GetByName(t1Name); BOBetTeam t2 = BOBetTeam.GetByName(t2Name); if(t1 == null) { t1 = new BOBetTeam(); t1.Name = t1Name; t1.Save(); } if (t2 == null) { t2 = new BOBetTeam(); t2.Name = t2Name; t2.Save(); } bet.BETTeam1BetTeam = t1; bet.BETTeam2BetTeam = t2; bet.Odds = odds; bet.Date = date; bet.ExternalID = externalID; bet.Save(); } } }