private void GetMatchResult(int matchid,int spportid)
 {
     CrawlAllMarkets crawl=new CrawlAllMarkets();
     DataTable dt = new DataTable();
     dt = crawl.GetMatchResult(matchid,spportid);
     dataGridView1.DataSource = dt;
 }
        private void LoadChampionsLeague()
        {
            DataTable dt = new DataTable();
            CrawlAllMarkets crawl = new CrawlAllMarkets();
            // 358==Leagueid of Champions League
            dt = crawl.GetMatchesByCoupon();

            TreeNode tn_group = new TreeNode("Match Result");
            string matchdate = "";
            foreach (DataRow row in dt.Rows)
            {

                if (matchdate != row["MatchDate"].ToString())
                {
                    matchdate = row["MatchDate"].ToString();
                    TreeNode tn_date = new TreeNode(matchdate);
                    string sql1 = "(matchdate='" + matchdate + "')";
                    tn_group.Nodes.Add(tn_date);
                    foreach (DataRow dr1 in dt.Select(sql1))
                    {
                        TreeNode tn_match = new TreeNode(dr1["Home"].ToString() + " V " + dr1["Away"].ToString() + ":" + dr1["id"].ToString());
                        tn_date.Nodes.Add(tn_match);
                    }
                }
            }
            if (InvokeRequired)
            {
                Action a = () =>
                {
                    treeView1.Nodes.Add(tn_group);

                }; BeginInvoke(a);
            }
        }
 private void loadData()
 {
     string url = "http://www.oddschecker.com/football-betting";
     //string html = Helper.GetWebSiteContent("http://www.oddschecker.com/gaelic-games/gaelic-football/"); //(ConfigurationSettings.AppSettings["URL"]);
     CrawlAllMarkets crawl = new CrawlAllMarkets();
     CrawlFirstPage crawlpage = new CrawlFirstPage();
     CrawlEachMarket crawlmarket = new CrawlEachMarket();
     //string msg = crawlpage.DeleteFirstPageRecords();
     //Task taskA = Task.Factory.StartNew(() =>
     //{
     //    string msg1 = crawlpage.CrawlEachSport();
     //}, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness);
     string msg2 = crawl.CrawlBettingLinks();
     //crawlpage.CrawlWorldMarkets();
     //crawlpage.CrawlLeagues(url);
 }
        private void callback()
        {
            TraceService("Timer Started");

            CrawlAllMarkets crawl = new CrawlAllMarkets();
            CrawlFirstPage crawlpage = new CrawlFirstPage();
            ////CrawlEachMarket crawlmarket = new CrawlEachMarket();
            //string msg = crawlpage.DeleteFirstPageRecords();
            string msg1 = "", msg2 = "", msg3 = "";
            try
            {
                msg1 = DateTime.Now + ":" + crawlpage.CrawlEachSport();
            }
            catch (Exception ex)
            {
            }
            finally { TraceService("Reply from CrawlEachSport at " + msg1 + "\n"); }

            try
            {
                msg2 = DateTime.Now + ":" + crawl.CrawlBettingLinks();
            }
            catch (Exception ex) { }
            finally { TraceService("Reply from CrawlEachSport at " + msg2 + "\n"); }
            try
            {
                msg3 = DateTime.Now + ":" + crawlpage.CrawlAllGolf();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                TraceService(" Reply from CrawlEachMatchResult at " + msg3 + "\n");
            }
            try
            {
                msg3 = DateTime.Now + ":" + crawlpage.CrawlEachMatchResult();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                TraceService(" Reply from CrawlEachMatchResult at " + msg3 + "\n");
            }
        }
 private void LoadTreeViewForGaelic(string sport)
 {
     int id = Convert.ToInt32(sport.Substring(1));
     CrawlAllMarkets crawl = new CrawlAllMarkets();
     DataSet ds = crawl.GetMatchesAndMarkets(id);
     ds.Relations.Add("Sport_Match", ds.Tables[0].Columns["sportid"], ds.Tables[1].Columns["sportid"]);
     ds.Relations.Add("Match_Mkt", ds.Tables[2].Columns["id"], ds.Tables[3].Columns["matchid"]);
     //ds.Relations.Add("Match_Date", ds.Tables[1].Columns["MatchDate"], ds.Tables[2].Columns["MatchDate"]);
     //TreeNode tn_group = new TreeNode("GAA Football");
     foreach (DataRow drSport in ds.Tables[0].Rows)
     {
         TreeNode tn_group = new TreeNode(drSport["SportName"].ToString());
         foreach (DataRow dr in drSport.GetChildRows("Sport_Match"))
         {
             string matchdate = dr["MatchDate"].ToString();
             string sportid = dr["sportid"].ToString();
             TreeNode tn_date = new TreeNode(matchdate);
             tn_group.Nodes.Add(tn_date);
             string sql1 = "(matchdate='" + matchdate + "') AND (sportid='" + sportid + "')";
             foreach (DataRow dr1 in ds.Tables[2].Select(sql1))
             //foreach (DataRow dr1 in dr.GetChildRows("Match_Date"))
             {
                 TreeNode tn_match = new TreeNode(dr1["Home"].ToString() + " V " + dr1["Away"].ToString());
                 tn_date.Nodes.Add(tn_match);
                 foreach (DataRow drChild in dr1.GetChildRows("Match_Mkt"))
                 {
                     TreeNode tn_market = new TreeNode(drChild["bettingmarket"].ToString());
                     tn_market.Name = drChild["id"].ToString() + "," + drChild["matchid"].ToString() + "," + drChild["bettinglink"].ToString() + "," + Convert.ToString(drSport["sportid"]);
                     tn_match.Nodes.Add(tn_market);
                 }
             }
         }
         if (InvokeRequired)
         {
             Action a = () =>
             {
                 treeView1.Nodes.Add(tn_group);
             }; BeginInvoke(a);
         }
     }
     //treeView1.Nodes.Add(tn_group);
 }
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {

            string html = Helper.GetWebSiteContent("http://www.oddschecker.com/gaelic-games/gaelic-football/"); //(ConfigurationSettings.AppSettings["URL"]);
            CrawlAllMarkets crawl = new CrawlAllMarkets();
            CrawlFirstPage crawlpage = new CrawlFirstPage();
            ////CrawlEachMarket crawlmarket = new CrawlEachMarket();
            string msg = crawlpage.DeleteFirstPageRecords();
            string msg1 = crawlpage.CrawlMyPage(html);
            string msg2 = crawl.CrawlBettingLinks();
            //TraceService("Reply from DeleteFirstPageRecords at " + DateTime.Now + ":" + msg + "\n Reply from CrawlMyPage at " + DateTime.Now + ":" + msg1 + "\n Reply from CrawlBettingLinks at " + DateTime.Now + ":" + msg2 + "\n");
            //string html = Helper.GetWebSiteContent(ConfigurationSettings.AppSettings["URL"]);
            //CrawlAllMarkets crawl = new CrawlAllMarkets();
            //CrawlFirstPage crawlpage = new CrawlFirstPage();
            //CrawlEachMarket crawlmarket = new CrawlEachMarket();
            
            //crawlpage.CrawlMyPage(html);
            //crawl.CrawlBettingLinks();
            //crawlmarket.CrawlMarketLinks();
        }
        protected void BindGrid(long matchid)
        {
            BindingSource bindingSource1 = new BindingSource();
            dataGridMarkets.AutoGenerateColumns = false;
            dataGridMarkets.ColumnCount = 4;

            dataGridMarkets.Columns[0].Name = "ID";
            dataGridMarkets.Columns[0].DataPropertyName = "id";
            dataGridMarkets.Columns[0].Visible = false;
            dataGridMarkets.Columns[1].Name = "MatchID";
            dataGridMarkets.Columns[1].DataPropertyName = "matchid";
            dataGridMarkets.Columns[1].Visible = false;
            dataGridMarkets.Columns[2].Name = "Markets";
            dataGridMarkets.Columns[2].DataPropertyName = "bettingmarket";
            dataGridMarkets.Columns[3].Name = "BettingLink";
            dataGridMarkets.Columns[3].DataPropertyName = "bettinglink";
            dataGridMarkets.Columns[3].Visible = false;
            var buttonCol = new DataGridViewButtonColumn();
            buttonCol.UseColumnTextForButtonValue = true;
            buttonCol.Name = "Odds";
            buttonCol.Text = "View Odds";

            dataGridMarkets.Columns.Add(buttonCol);
            CrawlAllMarkets crawl = new CrawlAllMarkets();
            dataGridMarkets.DataSource = crawl.GetBettingMarkets(matchid);

            //foreach (DataGridViewColumn column in dataGridMarkets.Columns)
            //    column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

            //this.Width = dataGridMarkets.Width + 100;

            //int totalRowHeight = dataGridMarkets.ColumnHeadersHeight;

            //foreach (DataGridViewRow row in dataGridMarkets.Rows)
            //    totalRowHeight += row.Height;

            //dataGridMarkets.Height = totalRowHeight+10;
            //this.Height = dataGridMarkets.Height + 100;
        }
        private void LoadTreeViewForSoccer()
        {
            CrawlAllMarkets crawl = new CrawlAllMarkets();
            DataSet ds = crawl.GetMatchesAndMarketsFoSoccer();
            ds.Relations.Add("Sport_Match", ds.Tables[0].Columns["sportid"], ds.Tables[1].Columns["sportid"]);
            ds.Relations.Add("Date_Section", ds.Tables[1].Columns["matchdate"], ds.Tables[2].Columns["matchdate"]);
            // ds.Relations.Add("League_Match", ds.Tables[3].Columns["leagueid"], ds.Tables[4].Columns["leagueid"]);
            ds.Relations.Add("Match_Mkt", ds.Tables[4].Columns["id"], ds.Tables[5].Columns["matchid"]);

            //TreeNode tn_group = new TreeNode("GAA Football");
            foreach (DataRow drSport in ds.Tables[0].Rows)
            {
                TreeNode tn_group = new TreeNode(drSport["SportName"].ToString());

                //treeView1.Nodes.Add(tn_group);

                foreach (DataRow dr in drSport.GetChildRows("Sport_Match"))
                {
                    TreeNode tn_date = new TreeNode(dr["MatchDate"].ToString());
                    tn_group.Nodes.Add(tn_date);
                    TreeNode worldsec = new TreeNode("World");
                    tn_date.Nodes.Add(worldsec);
                    foreach (DataRow dr1 in dr.GetChildRows("Date_Section"))
                    {
                        string matchdate = Convert.ToString(dr1["matchdate"]);
                        string section = Convert.ToString(dr1["section"]);

                        TreeNode tn_section = new TreeNode(section);
                        if (section.Equals("English") || section.Equals("Scottish") || section.Equals("European") || section.Equals("Champions League") || section.Equals("Europa League"))
                            tn_date.Nodes.Add(tn_section);
                        else
                        {
                            worldsec.Nodes.Add(tn_section);
                        }
                        string sql = "(matchdate='" + matchdate + "') AND (section='" + section + "')";
                        foreach (DataRow drChild in ds.Tables[3].Select(sql))
                        {
                            string leagueid = drChild["leagueid"].ToString();
                            TreeNode tn_league = new TreeNode(drChild["league"].ToString());
                            tn_section.Nodes.Add(tn_league);
                            string sql1 = "(matchdate='" + matchdate + "') AND (leagueid='" + leagueid + "')";
                            foreach (DataRow drchildrow in ds.Tables[4].Select(sql1))
                            {

                                TreeNode tn_match = new TreeNode(drchildrow["Home"].ToString() + " V " + drchildrow["Away"].ToString());
                                tn_league.Nodes.Add(tn_match);
                                foreach (DataRow drmarket in drchildrow.GetChildRows("Match_Mkt"))
                                {
                                    TreeNode tn_market = new TreeNode(drmarket["bettingmarket"].ToString());
                                    tn_market.Name = drmarket["id"].ToString() + "," + drmarket["matchid"].ToString() + "," + drmarket["bettinglink"].ToString() + "," + Convert.ToString(drSport["sportid"]);

                                    tn_match.Nodes.Add(tn_market);
                                }
                            }
                        }

                    }
                }

                if (InvokeRequired)
                {
                    Action a = () =>
                    {
                        treeView1.Nodes.Add(tn_group);
                    }; BeginInvoke(a);
                }
            }
            //treeView1.Nodes.Add(tn_group);
        }
 private void BindMasterMarket(int sportid)
 {
     CrawlAllMarkets crawl = new CrawlAllMarkets();
     cmbMasterMarketName.DataSource = crawl.GetMasterMarketName(sportid);
     cmbMasterMarketName.DisplayMember = "ResultName";
     cmbMasterMarketName.ValueMember = "ResultLink";
 }
 private void notarchivedToolStripMenuItem_Click(object sender, EventArgs e)
 {
     CrawlAllMarkets crawl = new CrawlAllMarkets();
     crawl.CrawlBettingLinksByCoupon(false);
 }
        private void crawlerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Start Crawling.
            //  time = new System.Threading.Timer(startcrawling());
            //BackCrawler.GetCrawler d = new GetCrawler();
            //d.startCrawling();

            //      foreach (ToolStripMenuItem item in startCrawlingToolStripMenuItem.DropDown.Items)
            //   {
            // item.Text = (sender as ToolStripMenuItem).Text;
            if (IsCrawlProcessRunning == true)
            {
                SetProgress(false);
                IsCrawlProcessRunning = false;
            }
            SetProgress(true);
            IsCrawlProcessRunning = true;
            CrawlFirstPage crawldata = new CrawlFirstPage();

            if ((sender as ToolStripMenuItem).Text == "League")
            {
                DataTable dt = crawldata.GetSports("2");
                string link = dt.Rows[0]["link"].ToString();
                int sportid = Convert.ToInt32(dt.Rows[0]["sportid"].ToString());
                if (sportid == 2)
                    crawldata.CrawlLeagues(link);
            }
            else if ((sender as ToolStripMenuItem).Text == "WorldMarket")
            {
                DataTable dt = crawldata.GetSports("2");
                string link = dt.Rows[0]["link"].ToString();
                int sportid = Convert.ToInt32(dt.Rows[0]["sportid"].ToString());
                if (sportid == 2)
                    crawldata.CrawlWorldMarkets();
            }
            else if ((sender as ToolStripMenuItem).Text == "Soccer")
            {
                DataTable dt = crawldata.GetSports((sender as ToolStripMenuItem).Name.ToString());
                string link = dt.Rows[0]["link"].ToString();
                int sportid = Convert.ToInt32(dt.Rows[0]["sportid"].ToString());
                // soocer
                //   crawldata.CrawlLeagues(link);
                //   crawldata.CrawlWorldMarkets();
                DataSet ds = crawldata.GetLeague();
                for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                {
                    string matchlink = Convert.ToString(ds.Tables[0].Rows[j]["link"]);
                    int sport_id = Convert.ToInt32(ds.Tables[0].Rows[j]["sportid"]);
                    long leagueid = Convert.ToInt32(ds.Tables[0].Rows[j]["leagueid"]);
                    ThreadParameters t = new ThreadParameters();
                    t.URL = matchlink;
                    t.SportID = sport_id;
                    t.LeagueID = leagueid;
                    crawldata.CrawlMyPage(t);
                }
            }
            else if ((sender as ToolStripMenuItem).Text == "GaaFootball")
            {
                DataTable dt = crawldata.GetSports((sender as ToolStripMenuItem).Name.ToString());
                string link = dt.Rows[0]["link"].ToString();
                int sportid = Convert.ToInt32(dt.Rows[0]["sportid"].ToString());
                // GAA Football
                ThreadParameters tp = new ThreadParameters();
                tp.URL = link;
                tp.SportID = sportid;
                if (sportid == 12)
                {
                    crawldata.CrawlMyPage(tp);
                }
            }
            else if ((sender as ToolStripMenuItem).Text == "GaaHurling")
            {
                DataTable dt = crawldata.GetSports((sender as ToolStripMenuItem).Name.ToString());
                string link = dt.Rows[0]["link"].ToString();
                int sportid = Convert.ToInt32(dt.Rows[0]["sportid"].ToString());
                ThreadParameters tp = new ThreadParameters();
                tp.URL = link;
                tp.SportID = sportid;
                // GAA Hurling.
                if (sportid == 28)
                {
                    crawldata.CrawlMyPage(tp);
                }
            }
            else if ((sender as ToolStripMenuItem).Text == "Golf")
            {
                DataTable dt = crawldata.GetSports((sender as ToolStripMenuItem).Name.ToString());
                string link = dt.Rows[0]["link"].ToString();
                int sportid = Convert.ToInt32(dt.Rows[0]["sportid"].ToString());
                // Golf
                if (sportid == 29)
                {
                    crawldata.CrawlGolfTurnament(link, sportid.ToString());
                }
            }
            else if ((sender as ToolStripMenuItem).Text == "GolfMarketName")
            {
                crawldata.CrawlGolfBettingMarketName();
            }
            else if ((sender as ToolStripMenuItem).Text == "GolfMarkets")
            {
                crawldata.CrawlGolfBettingMarket();
            }
            else if ((sender as ToolStripMenuItem).Text == "BettingMarket")
            {
                CrawlAllMarkets crawl = new CrawlAllMarkets();
                crawl.CrawlBettingLinks();
            }
            else if ((sender as ToolStripMenuItem).Text == "MarketResult")
            {
                crawldata.CrawlEachMatchResult();
            }
            //  Thread d = new Thread();
            SetProgress(false);
            IsCrawlProcessRunning = false;
            //   }
        }
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {

            try
            {
                TreeNode parentnode = e.Node;
                while (parentnode.Parent != null)
                {
                    parentnode = parentnode.Parent;
                }

                if (parentnode.Text.Equals("Match Result"))
                //if (e.Node.Level == 3 || e.Node.Level == 5)
                {
                    OddsCheckerCrawler parent = this.MdiParent as OddsCheckerCrawler;
                    if (!parent.IsProcessRunning)
                    {
                        //if (!string.IsNullOrEmpty(parent.SelectedBookies()))
                        //{

                        //parent.SetProgress(true);
                        //parent.IsProcessRunning = true;
                        string info = e.Node.Text;
                        string[] info1 = info.Split(':');
                        CrawlAllMarkets crawl = new CrawlAllMarkets();
                        string[] match = crawl.GetChampionMatchInfo(Convert.ToInt32(info1[1].ToString()));
                        //match[0]=link;match[1]=time;
                        if (match[0] != null)
                        {
                            parent.IsProcessRunning = true;
                            parent.SetProgress(true);
                            flowLayoutPanel1.Controls.Clear();

                            //    lblsportid.Text = info1[3];
                            countthread = 0;

                            Task taskA = Task.Factory.StartNew(() =>
                            {
                                FillMatchInfo(info1[1], match[0], match[1],1);

                            }, TaskCreationOptions.LongRunning);
                        }
                        //}
                        //else
                        //{
                        //    MessageBox.Show("Please select atleast one bookie from Select Bookies menu");
                        //}
                    }
                    else
                    {
                        MessageBox.Show("A process is already running");
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An internal error occured while processing the request");
            }
        }
 private void btnsave_Click(object sender, EventArgs e)
 {
     CrawlAllMarkets c = new CrawlAllMarkets();
     
   //  c.CrawlBettingMarkets("http://www.oddschecker.com//football/world/morocco/gnf-1/ocs-olympique-de-safi-v-fus-rabat/betting-markets", 7624);
     CrawlFirstPage crawl = new CrawlFirstPage();
     Console.WriteLine("Crawling Started EachSport");
     crawl.GetMatchListByTime();
  //   crawl.CrawlChampionLeauge("3866", "file:///E:/OddsCompiler/z-rowdata/Results/Barcelona%20v%20Atletico%20Madrid/Barcelona%20v%20Atletico%20Madrid%20Winner%20Betting%20Odds%20%20%20Football%20Betting%20%20%20Oddschecker.htm", "34pm");
 }
        private void MatchResult(string[] result, string matchid)
        {
            CrawlEachMarketData crawl = new CrawlEachMarketData();
            int sportid = crawl.GetSportID(Convert.ToInt32(matchid));
             CrawlAllMarkets crawls=new CrawlAllMarkets();
            DataTable dt = new DataTable();
            dt = crawls.GetMatchResult(Convert.ToInt32(matchid),sportid);
            Dictionary<string, string> data = new Dictionary<string, string>();
            if (dt.Rows.Count > 0)
            {
                for(int i=0;i<dt.Rows.Count;i++)
                {
                    DataRow row=dt.Rows[i];
                    if (row[0].ToString() == "Winner")
                    {
                        string[] score = result[1].Split('-');
                        if (Convert.ToInt32(score[0]) > Convert.ToInt32(score[1]))
                            dt.Rows[i][1] = "Home";

                        else if (Convert.ToInt32(score[0]) < Convert.ToInt32(score[1]))
                            dt.Rows[i][1] = "Away";
                        else dt.Rows[i][1] = "Draw";
                    }
                    else if (row[0].ToString() == "HalfTime")
                        dt.Rows[i][1] =((result[2].Substring(result[2].IndexOf('-') - 1, 1)) + "-" + (result[2].Substring(result[2].IndexOf('-') + 1, 1)));
                    else if (row[0].ToString() == "BothTeamToScore")
                    {
                        string[] scorefull = result[1].Split('-'); string full;
                        if (Convert.ToInt32(scorefull[0]) > 0 & Convert.ToInt32(scorefull[1]) > 0)
                            dt.Rows[i][1] = "YES";
                        else dt.Rows[i][1] = "NO";
                    }
                    else if (row[0].ToString() == "HalfTimeFullTimeWinner")
                    {
                        string[] scorefull = result[1].Split('-'); string full;
                        string[] scorehalf = ((result[2].Substring(result[2].IndexOf('-') - 1, 1)) + "-" + (result[2].Substring(result[2].IndexOf('-') + 1, 1))).Split('-'); string half = "";
                        if (Convert.ToInt32(scorehalf[0]) > Convert.ToInt32(scorehalf[1]))
                            half = "Home";
                        else if (Convert.ToInt32(scorehalf[0]) < Convert.ToInt32(scorehalf[1]))
                            half = "Away";
                        else half = "Draw";

                        if (Convert.ToInt32(scorefull[0]) > Convert.ToInt32(scorefull[1]))
                            full = "Home";
                        else if (Convert.ToInt32(scorefull[0]) < Convert.ToInt32(scorefull[1]))
                            full = "Away";
                        else full = "Draw";
                       
                        dt.Rows[i][1]= half + "/" + full;
                    }
                    else if (row[0].ToString() == "CorrectScore")
                    {
                      dt.Rows[i][1]=   result[2].Substring(0, result[2].IndexOf('-') - 1) + " " + result[1] + " " + result[2].Substring(result[2].IndexOf('-') + 2, result[2].Length - result[2].Substring(0, result[2].IndexOf('-') + 1).Length);
                    }
                    else if (row[0].ToString() == "HalfTimeScore")
                    {
                        dt.Rows[i][1] =((result[2].Substring(result[2].IndexOf('-') - 1, 1)) + "-" + (result[2].Substring(result[2].IndexOf('-') + 1, 1)));
                    }
                    else if (row[0].ToString() == "Handicaps")
                    {
                        dt.Rows[i][1] = "";
                    }
                    else if (row[0].ToString() == "AlternativeHandicaps")
                    {
                        dt.Rows[i][1] = "";
                    }
                    else if (row[0].ToString() == "MatchResultAndBoth")
                    {
                        string[] scorefull = result[1].Split('-'); string full;
                        if (Convert.ToInt32(scorefull[0]) > 0 & Convert.ToInt32(scorefull[1]) > 0)
                            dt.Rows[i][1] = "YES" +" "+result[1];
                        else dt.Rows[i][1] = "NO" + " " + result[1];
                    }
                    else if (row[0].ToString() == "DoubleChanceWinner")
                    {
                        string[] scorefull = result[1].Split('-'); string full;
                        if (Convert.ToInt32(scorefull[0]) ==Convert.ToInt32(scorefull[1]))
                            dt.Rows[i][1] = "Home or Draw, Away or Draw";
                        else if(Convert.ToInt32(scorefull[0]) >Convert.ToInt32(scorefull[1]))
                            dt.Rows[i][1] = "Home or Away, Home or Draw";
                        else if (Convert.ToInt32(scorefull[0]) < Convert.ToInt32(scorefull[1]))
                            dt.Rows[i][1] = "Home or Away , Away or Draw";
                    }
                    else if (row[0].ToString() == "DoubleChanceBeaten")
                    {
                        string[] scorefull = result[1].Split('-'); string full;
                        if (Convert.ToInt32(scorefull[0]) == Convert.ToInt32(scorefull[1]))
                            dt.Rows[i][1] = "Home or Away";
                        else if (Convert.ToInt32(scorefull[0]) > Convert.ToInt32(scorefull[1]))
                            dt.Rows[i][1] = "Away or Draw";
                        else if (Convert.ToInt32(scorefull[0]) < Convert.ToInt32(scorefull[1]))
                            dt.Rows[i][1] = "Home or Draw";
                    }
                    else if (row[0].ToString() == "TeamToScoreFirst")
                    {
                        string hgt = result[8].Substring(result[8].IndexOf("mins") - 3, 2) + "";
                        string agt = result[10].Substring(result[10].IndexOf("mins") - 3, 2) + "";
                        if (Convert.ToInt32(hgt) < Convert.ToInt32(agt))
                            dt.Rows[i][1] = "Home";
                        else if (Convert.ToInt32(hgt) < Convert.ToInt32(agt))
                            dt.Rows[i][1] = "Away";
                        else dt.Rows[i][1] = "Both";
                    }
                    else if (row[0].ToString() == "ToWinBothHalves")
                    {
                        string[] hscore =((result[2].Substring(result[2].IndexOf('-') - 1, 1)) + "-" + (result[2].Substring(result[2].IndexOf('-') + 1, 1))).Split('-');
                        string[] score = result[1].Split('-');
                        if (Convert.ToInt32(score[0]) > Convert.ToInt32(score[1]) && Convert.ToInt32(hscore[0]) > Convert.ToInt32(hscore[1]))
                            dt.Rows[i][1] = "Home";
                        else if (Convert.ToInt32(score[0]) < Convert.ToInt32(score[1]) && Convert.ToInt32(hscore[0]) < Convert.ToInt32(hscore[1]))
                            dt.Rows[i][1] = "Away";
                        else dt.Rows[i][1] = "Nither";
                    }
                    else if (row[0].ToString() == "ToWinEitherHalf")
                    {
                        string[] hscore =((result[2].Substring(result[2].IndexOf('-') - 1, 1)) + "-" + (result[2].Substring(result[2].IndexOf('-') + 1, 1))).Split('-');
                        string[] score = result[1].Split('-');
                        if (Convert.ToInt32(hscore[0]) > Convert.ToInt32(hscore[1]))
                            dt.Rows[i][1] = "Home";
                        else if (Convert.ToInt32(hscore[0]) > Convert.ToInt32(hscore[1])) dt.Rows[i][1] = "Away";
                        else dt.Rows[i][1] = "Draw";

                         if (Convert.ToInt32(score[0]) > Convert.ToInt32(score[1]))
                            dt.Rows[i][1] += "Home";
                         else if (Convert.ToInt32(score[0]) < Convert.ToInt32(score[1])) dt.Rows[i][1] += "Away";
                        else dt.Rows[i][1] += "Draw";
                    }
                    else if (row[0].ToString() == "ToWinFormBehind")
                    {
                        string[] hscore =((result[2].Substring(result[2].IndexOf('-') - 1, 1)) + "-" + (result[2].Substring(result[2].IndexOf('-') + 1, 1))).Split('-');
                        string[] score = result[1].Split('-');
                        if (Convert.ToInt32(hscore[0]) < Convert.ToInt32(hscore[1]) && Convert.ToInt32(score[0]) > Convert.ToInt32(score[1]))
                            dt.Rows[i][1] = "Home";
                        else if(Convert.ToInt32(hscore[0]) > Convert.ToInt32(hscore[1]) && Convert.ToInt32(score[0]) < Convert.ToInt32(score[1]))
                            dt.Rows[i][1] = "Away";
                        else dt.Rows[i][1] = "Nither";
                    }
                    else if (row[0].ToString() == "TimeOfFirstGoal")
                    {
                        dt.Rows[i][1] = result[6];
                    }
                    else if (row[0].ToString() == "TimeofLastGoal")
                    {
                        dt.Rows[i][1] = result[7];
                    }
                    else if (row[0].ToString() == "ExactTotalGoal")
                    {
                        dt.Rows[i][1] = "";
                    }
                    else if (row[0].ToString() == "ToScoreFirstAndNotWin")
                    {
                        string[] score = result[1].Split('-');
                        string hgt = result[8].Substring(result[8].IndexOf("mins") - 3, 2) + "";
                        string agt = result[10].Substring(result[10].IndexOf("mins") - 3, 2) + "";
                        if (Convert.ToInt32(hgt) < Convert.ToInt32(agt))
                        {
                            if(Convert.ToInt32(score[0])<Convert.ToInt32(score[1]))
                            dt.Rows[i][1] = "Home";
                        }
                        else if (Convert.ToInt32(hgt) < Convert.ToInt32(agt))
                        {
                            if (Convert.ToInt32(score[0]) > Convert.ToInt32(score[1]))
                            dt.Rows[i][1] = "Away";
                        }
                        if (dt.Rows[i][1].ToString() == "") dt.Rows[i][1] = "No One";
                    }
                    else if (row[0].ToString() == "FirstGoalScorer")
                    {
                        dt.Rows[i][1] = result[3];
                    }
                    else if (row[0].ToString() == "LastGoalScorer")
                    {
                        dt.Rows[i][1] = result[4];
                    }
                    else if (row[0].ToString() == "AnyTimeGoalScorer")
                    {
                        dt.Rows[i][1] = ""; 
                    }
                    else if (row[0].ToString() == "ToScoreToOrMoreGoales")
                    {
                        dt.Rows[i][1] = "";
                    }
                    else if (row[0].ToString() == "ToScoreHatTrick")
                    {
                        dt.Rows[i][1] = "";
                    }
                    else if (row[0].ToString() == "TotalScore")
                    {
                        dt.Rows[i][1] = result[1];
                    }
                    else if (row[0].ToString() == "OverUnder0.5")
                    {
                        string[] score = result[1].ToString().Trim(' ').Split('-');
                        int total = Convert.ToInt32(score[0]) + Convert.ToInt32(score[1]);
                        if (total >= 1)
                            dt.Rows[i][1] = "Winner";
                        else dt.Rows[i][1] = "Beaten";
                    }
                    else if (row[0].ToString() == "OverUnder1.5")
                    {
                        string[] score = result[1].Trim(' ').Split('-');
                        int total = Convert.ToInt32(score[0]) + Convert.ToInt32(score[1]);
                        if (total >= 2)
                            dt.Rows[i][1] = "Winner";
                        else dt.Rows[i][1] = "Beaten";
                    }
                    else if (row[0].ToString() == "OverUnder2.5")
                    {
                        string[] score = result[1].Trim(' ').Split('-');
                        int total = Convert.ToInt32(score[0]) + Convert.ToInt32(score[1]);
                        if (total >= 3)
                            dt.Rows[i][1] = "Winner";
                        else dt.Rows[i][1] = "Beaten";
                    }
                    else if (row[0].ToString() == "OverUnder3.5")
                    {
                        string[] score = result[1].Trim(' ').Split('-');
                        int total = Convert.ToInt32(score[0]) + Convert.ToInt32(score[1]);
                        if (total >= 4)
                            dt.Rows[i][1] = "Winner";
                        else dt.Rows[i][1] = "Beaten";
                    }
                    else if (row[0].ToString() == "OverUnder4.5")
                    {
                        string[] score = result[1].Trim(' ').Split('-');
                        int total = Convert.ToInt32(score[0]) + Convert.ToInt32(score[1]);
                        if (total >= 5)
                            dt.Rows[i][1] = "Winner";
                        else dt.Rows[i][1] = "Beaten";
                    }
                    else if (row[0].ToString() == "")
                    {
                    }
                }

                // Update to database
                CrawlAllMarketsData marketdata = new CrawlAllMarketsData();
                marketdata.UpdateMarketResults(dt,Convert.ToInt32(matchid), sportid);
            }
        }
        private void LoadTreeView(int sportid)
        {
            CrawlAllMarkets crawl = new CrawlAllMarkets();
            DataSet ds = crawl.GetMatchByDate(sportid);
            ds.Relations.Add("Date_Section1", ds.Tables[0].Columns["matchdate"], ds.Tables[1].Columns["matchdate"]);
                TreeNode tn_group = new TreeNode(lblSportName.Text);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    TreeNode tn_date = new TreeNode(dr["MatchDate"].ToString());
                    string matchdate = Convert.ToString(dr["matchdate"]);

                    string sql1 = "(matchdate='" + matchdate + "')";

                    foreach (DataRow dr1 in ds.Tables[1].Select(sql1))
                    {
                        TreeNode tn_match = new TreeNode(dr1["Home"].ToString() + " V " + dr1["Away"].ToString() + ":" + dr1["id"].ToString());
                        tn_date.Nodes.Add(tn_match);
                    }
                    tn_group.Nodes.Add(tn_date);
                }
                if (InvokeRequired)
                {
                    Action a = () =>
                    {
                        treeView1.Nodes.Add(tn_group);
                    }; BeginInvoke(a);
                }
        }