private void TreeNodeLoad(TreeNode tn)
 {
     foreach (var ltl in ltls)
     {
         double? fit = 0, goals = 0, wdl = 0;
         //加入live_table数据
         strNode = ltl.LiveTableLibID + "," + ltl.MatchType + "," + ltl.MatchTime + "::" + ltl.HomeTeam + "::" + ltl.AwayTeam + "::" + ltl.Status;
         mar = marAll.Where(o => o.LiveTableLibID == ltl.LiveTableLibID).OrderByDescending(o => o.AnalysisResultID).FirstOrDefault();
         if (mar != null)  //有运行过算法
         {
             //加入match_analysis数据
             strNode += "||" + mar.ResultFit + "::" + mar.ResultGoals + "::" + mar.ResultWDL + "::" + mar.FitWinLoss + "::" +
                             mar.HomeGoals + "::" + mar.AwayGoals + "::" + (mar.HomeGoals - mar.AwayGoals) + "::" +
                             mar.HomeW.ToString() + "::" + mar.HomeD.ToString() + "::" + mar.HomeL.ToString();
             if (mar.ResultTBLibID != null)  //有导入了结果
             {
                 //加入result_tb数据
                 rtl = rtlAll.Where(e => e.ResultTBLibID== mar.ResultTBLibID).FirstOrDefault();
                 strNode += "||" + rtl.MatchTime.Value.ToShortDateString() + "::" +
                                     rtl.FullHomeGoals.ToString() + "-" + rtl.FullAwayGoals.ToString() + "::" +
                                     rtl.Odds + "::" + rtl.WinLossBig + "::" + rtl.HomeTeam + "::" + rtl.AwayTeam;
             }
             fit = mar.FitWinLoss;
             goals = mar.HomeGoals - mar.AwayGoals;
             wdl = mar.HomeW - mar.HomeL;
         }
         //加入bj单场数据
         foreach (var lo in loAll)
             if (ltl.HomeTeam.Contains(lo.MatchOrder1hOmeName) || ltl.AwayTeam.Contains(lo.MatchOrder1aWayName))   //有匹配bj单场的数据
                 strNode += "********" + lo.Value + ">>" + lo.MatchOrder1hAndicapNumber;
         TreeNode child = new TreeNode(strNode);
         tn.Nodes.Add(child);
         //颜色处理
         if (fit < 0) child.ForeColor = Color.Blue;
         if (goals < 0) child.BackColor = Color.Orange;
         if (wdl < 0) child.NodeFont = new Font("Trebuchet MS", 10, FontStyle.Bold);
         if (strNode.Contains(">>")) child.Parent.ForeColor = Color.Red;
     }
 }
        public  void UpdateLastMatch()
        {
            int i = 0;
           // DataClassesMatchDataContext matches = new DataClassesMatchDataContext();
            SoccerScoreSqlite matches = new SoccerScoreSqlite(Conn.cnn);
            IEnumerable<ResultTB>  rt = matches.ResultTB.OrderBy(o => o.SDate).ThenBy(p => p.STime);//用lambda表达式简洁

            //取临时变量监视
            DateTime lib_max_match_time = matches.ResultTBLib.Select(p => p.MatchTime).Max().Value.AddDays(-2);
            foreach (var m in rt)
            {
                i++;
                ProgressBarDelegate.DoSendPMessage(i);
                Application.DoEvents();
                if (m.HomeTeamBig != null)
                {
                    ResultTBLib rtl = new ResultTBLib();
                     rtl.HTMLPosition = Int32.Parse(m.HTMLPosition);
                   
                    rtl.HomeTeamBig= Int32.Parse(GetNumber(m.HomeTeamBig));
                    
                      rtl.AwayTeamBig = Int32.Parse(GetNumber(m.AwayTeamBig));
                  
                   rtl.MatchType= m.MatchType.Trim();
                    
                    last_line = m.STime.LastIndexOf("\n");
                    temp_time=m.STime.Substring(last_line,m.STime.Length-last_line-1);
                     rtl.MatchTime = DateTime.Parse(m.SDate.Substring(0, 10) + " " + temp_time);
                   
                   rtl.Odds= m.Odds.Trim();
                    
                   rtl.WinLossBig = m.WinLossBig.Trim();
                    
                      rtl.HomeTeam = m.HomeTeam.Trim();
                
                 rtl.AwayTeam= m.AwayTeam.Trim();
                    
                   rtl.HomeRedCard= StringCount(m.HomeTeam, "&nbsp;", 0);

                   rtl.AwayRedCard = StringCount(m.AwayTeam, "&nbsp;", 0);
                   
                    string bf = m.FullTimeScore.Replace("&nbsp;", "").Replace("&nbsp;", "");
                    if (m.FullTimeScore.IndexOf("-") > 0)
                    {
                        rtl.FullHomeGoals= Int32.Parse(bf.Substring(0, bf.IndexOf("-")));
                        rtl.FullAwayGoals= Int32.Parse(bf.Substring(bf.IndexOf("-") + 1, bf.Length - bf.IndexOf("-") - 1));
                    }
                    if (m.HalfTimeScore.IndexOf("-") > 0)
                    {
                          rtl.HalfHomeGoals= Int32.Parse(m.HalfTimeScore.Substring(0, m.HalfTimeScore.IndexOf("-")));

                          rtl.HalfAwayGoals = Int32.Parse(m.HalfTimeScore.Substring(m.HalfTimeScore.IndexOf("-") + 1, m.HalfTimeScore.Length - m.HalfTimeScore.IndexOf("-") - 1));
                   
                    }

                    //如果库中文件的日期太小,直接删除
                    if (rtl.MatchTime > lib_max_match_time)
                    {
                        //数据分区,层次化查询
                        IEnumerable<ResultTBLib> rtExist = from p in matches.ResultTBLib
                                      where p.MatchTime== rtl.MatchTime
                                      where p.HomeTeamBig== rtl.HomeTeamBig
                                      where p.AwayTeamBig== rtl.AwayTeamBig
                                      select p;

                        //库中没有记录直接插入
                        if (!rtExist.Any())
                        {
                            matches.ResultTBLib.InsertOnSubmit(rtl);
                            matches.SubmitChanges();
                        }
                    }

                    //更新后删除
                    matches.ResultTB.DeleteOnSubmit(m);
                    matches.SubmitChanges();
                    
                }
            }
            MessageBox.Show("OK");
            //dataGridView1.DataSource = matches.result_tb_lib;
        }