public decimal updateLiveOkoo()
        {
            DataTable dt = OkooHtml.GetTableOutHtml();
            using (DataClassesMatchDataContext match = new DataClassesMatchDataContext())
            {
                var ll = match.live_okoo.Where(e => e.live_okoo_id > 0);
                match.live_okoo.DeleteAllOnSubmit(ll);//更新后删除
                match.SubmitChanges();

                foreach (DataRow aa in dt.Rows)
                {
                    if (HtmlTextToStr(aa[15].ToString()) != null)
                    {
                        live_okoo lo = new live_okoo();
                        lo.value = HtmlValueToInt(aa[0].ToString());
                        lo.LeagueName = HtmlTextToStr(aa[1].ToString());
                        lo.match_time = HtmlTextToStr(aa[2].ToString());
                        lo.MatchOrder1_HomeName = TeamName(aa[3].ToString());
                        lo.MatchOrder1_HandicapNumber = HtmlTextToStr(aa[4].ToString());
                        lo.MatchOrder1_AwayName = TeamName(aa[5].ToString());
                        lo.ok_1_0 = HtmlTextToStr(aa[6].ToString());
                        lo.ok_1_1 = HtmlTextToStr(aa[7].ToString());
                        lo.ok_1_2 = HtmlTextToStr(aa[8].ToString());
                        lo.MatchInfo = HtmlTextToStr(aa[11].ToString());
                        lo.Match_1_Win = HtmlTextToStr(aa[12].ToString());
                        lo.Match_1_Drawn = HtmlTextToStr(aa[13].ToString());
                        lo.Match_1_Lost = HtmlTextToStr(aa[14].ToString());

                        match.live_okoo.InsertOnSubmit(lo);
                        match.SubmitChanges();
                    }
                }
                return match.live_okoo.Max(e => e.live_okoo_id);
            }
        }
 public void top20Algorithm()
 {
     using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn))
     {
         int i = 0;
         foreach (var id in idExc)
         {
             i++;
             ProgressBarDelegate.DoSendPMessage(i);
             Application.DoEvents();
             RowNumberLimit r = new RowNumberLimit(id);
             //match_analysis_result mar = new match_analysis_result();
             var mar = matches.Match_analysis_result.Where(e => e.Live_table_lib_id == id).First();//查找需要更新的数据
             mar.Live_table_lib_id = r.id;
             mar.Pre_algorithm = "top20";
             mar.Pre_match_count  = r.Top20Count;
             mar.Home_goals = r.HomeGoals;
             mar.Away_goals = r.AwayGoals;
             mar.Home_w = r.hWin;
             mar.Home_d = r.hDraw;
             mar.Home_l = r.hLose;
             mar.Fit_win_loss = r.CureFitWinLoss ;
             mar.Fit_goals = r.CureFitGoals ;
             mar.Fit_odd_even = r.CureFitOddEven ;//直接赋值,修改完成
             
         }
         matches.SubmitChanges();
     }
 }
        public decimal InsertLastHtmlTableToDB()
        {
            DataTable dt = SevenmResult.GetHtmlTable();

            DataClassesMatchDataContext match = new DataClassesMatchDataContext(Conn.conn);

            foreach (DataRow aa in dt.Rows)
            {
                if (HtmlTextToStr(aa[3].ToString()) != null)
                {
                    Result_tb rt = new Result_tb();
                    rt.Html_position = aa[0].ToString();
                    rt.Match_type = HtmlTextToStr(aa[1].ToString());
                    rt.S_time = HtmlTextToStr(aa[2].ToString());
                    rt.Home_team = HtmlTextToStr(aa[3].ToString());
                    rt.Full_time_score = HtmlTextToStr(aa[4].ToString());
                    rt.Away_team = HtmlTextToStr(aa[5].ToString());
                    rt.Half_time_score = HtmlTextToStr(aa[6].ToString());
                    rt.Odds = HtmlTextToStr(aa[7].ToString());
                    rt.Win_loss_big = HtmlTextToStr(aa[8].ToString());
                    rt.S_date = HtmlDateToStrResult(aa[2].ToString());
                    rt.Home_team_big = HtmlHrefToStr(aa[3].ToString());
                    rt.Away_team_big = HtmlHrefToStr(aa[5].ToString());

                    match.Result_tb.InsertOnSubmit(rt);
                    match.SubmitChanges();
                    
                }
            }
           
            return match.Result_tb.Select(e => e.Result_tb_id).Max();
        }
        public decimal updateLiveAibo()
        {
            DataTable dt = AiboHtml.GetTableOutHtml();
            using (DataClassesMatchDataContext match = new DataClassesMatchDataContext())
            {
                var ll = match.live_Aibo.Where(e => e.live_Aibo_id > 0);
                match.live_Aibo.DeleteAllOnSubmit(ll);//更新后删除
                match.SubmitChanges();

                foreach (DataRow aa in dt.Rows)
                {
                    if (HtmlTextToStr(aa[3].ToString()) != null) // && HtmlTextToStr(aa[11].ToString()) == null
                    {
                        live_Aibo lo = new live_Aibo();
                        lo.value = HtmlTextToStr(aa[1].ToString());
                        lo.LeagueName = HtmlTextToStr(aa[2].ToString());
                        lo.match_time = HtmlTextToStr(aa[3].ToString());
                        lo.MatchOrder1_HomeName = AiboTeamName(aa[5].ToString());
                        lo.MatchOrder1_HandicapNumber = HtmlTextToStr(aa[6].ToString());
                        lo.MatchOrder1_AwayName = AiboTeamName(aa[7].ToString());

                        match.live_Aibo.InsertOnSubmit(lo);
                       
                    }
                }
                match.SubmitChanges();
                return match.live_Aibo.Max(e => e.live_Aibo_id);
            }
        }
 public void top20Algorithm()
 {
     using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
     {
         int i = 0;
         foreach (var id in idExc)
         {
             i++;
             ProgressBarDelegate.DoSendPMessage(i);
             Application.DoEvents();
             RowNumberLimit r = new RowNumberLimit(id);
             match_analysis_result mar = new match_analysis_result();
             mar.live_table_lib_id = r.id;
             mar.pre_algorithm = "top20";
             mar.pre_match_count = r.Top20Count;
             mar.home_goals = r.HomeGoals;
             mar.away_goals = r.AwayGoals;
             mar.home_w = r.hWin;
             mar.home_d = r.hDraw;
             mar.home_l = r.hLose;
             mar.fit_win_loss = r.CureFitWinLoss ;
             mar.fit_goals = r.CureFitGoals ;
             mar.fit_odd_even = r.CureFitOddEven ;
             matches.match_analysis_result.InsertOnSubmit(mar);
            
         }
         matches.SubmitChanges();
     }
 }
 public ForecastAlgorithm()
 {
     using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
     {
         var idLive = matches.live_Table_lib.Select(e => e.live_table_lib_id);
         var idAnalysis = matches.match_analysis_result.Select(e => e.live_table_lib_id);
         idExc = idLive.Except(idAnalysis).ToList();   //except序列A有的元素序列B没有
     }
 }
 //private DateTime? todaytime;
 public AuditForecastAlgorithm(int daysDiff)
 {
     using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn))
     {
         //todaytime = DateTime.Now;
         var idLive = matches.Live_Table_lib
             .Where(e => e.Match_time.Value.Date >= DateTime.Now.AddDays(daysDiff).Date)
             .Select(e => e.Live_table_lib_id);
         idExc = idLive.ToList();
     }
 }
        public decimal InsertLiveHtmlTableToDB()
        {
            DataTable dt = SevenmLive.GetHtmlTable();

            DataClassesMatchDataContext match = new DataClassesMatchDataContext(Conn.conn);

            var result = match.Live_Table.Where(r => r.Live_table_id > 0);
            match.Live_Table.DeleteAllOnSubmit(result);
            match.SubmitChanges();

            string ddate = null;
            Queue<string> todayDate = new Queue<string>();

            foreach (DataRow aa in dt.Rows)
            {
                if (HtmlDateToStrLive(aa[1].ToString()) != null)
                {
                    if (HtmlDateToStrLive(aa[1].ToString()).IndexOf("最新賽果") == -1)
                    {
                        ddate = HtmlDateToStrLive(aa[1].ToString());
                        ddate = ddate.Replace("年", "-").Replace("月", "-").Replace("日", " ");
                        todayDate.Enqueue(ddate);
                    }
                    else
                    {
                        ddate = todayDate.Dequeue();
                    }
                }

                if (HtmlTextToStr(aa[3].ToString()) != null)
                {
                    Live_Table lt = new Live_Table();
                    lt.Html_position = aa[0].ToString();
                    lt.Match_type = HtmlTextToStr(aa[2].ToString());
                    lt.S_time = HtmlTextToStr(aa[3].ToString());
                    lt.Home_team = HtmlTextToStr(aa[5].ToString());
                    lt.Full_time_score = HtmlTextToStr(aa[6].ToString());
                    lt.Away_team = HtmlTextToStr(aa[7].ToString());
                    lt.Half_time_score = HtmlTextToStr(aa[8].ToString());
                    lt.S_date = ddate;
                    lt.Home_team_big = HtmlHrefToStr(aa[5].ToString());
                    lt.Away_team_big = HtmlHrefToStr(aa[7].ToString());

                    match.Live_Table.InsertOnSubmit(lt);
                    match.SubmitChanges();
                    
                }
            }
            
            return match.Live_Table.Select(e => e.Live_table_id).Max();
        }
        private void Form1_Load(object sender, EventArgs ee)
        {
            dataGridView5.Visible = false;
            toolStripStatusLabel2.Text = dateTimePicker2.Value.ToString("yyyy-MM-dd");//日历组建日期字符串格式化方法
            using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
            {
                toolStripStatusLabel3.Text = matches.result_tb_lib.Max(p => p.match_time).Value.ToString();
                var maxtime = matches.live_Table_lib.Max(p => p.match_time);
                toolStripStatusLabel4.Text = maxtime.HasValue ? maxtime.Value.ToString() : null;
            }
            treeView5.Nodes.Clear();
            loaddatatree.TreeViewMatch(treeView5, "type");
            dateTimePicker1.Value = DateTime.Parse(toolStripStatusLabel3.Text);

        }
 private void init_table_id_value()
 {
     using (DataClassesMatchDataContext match = new DataClassesMatchDataContext(Conn.conn))
     {
         var uri = match.Match_table_xpath.Where(e => e.Uri_host == uri_host).FirstOrDefault();
         if (uri.Max_table_id_value.Length > 1)
             table_id_value = uri.Max_table_id_value;
         else
         {
             if (uri.Second_table_id_value.Length > 1)
                 table_id_value = uri.Second_table_id_value;
             else
                 table_id_value = uri.Max_table_xpath;
         }
     }
 }
        public void initTreeNode(int daysDiff, List<string> matchlist, bool ismath)
        {
            //这个连接不能放到class中,不然取的还是缓存的数据???????????
            //对象和数据库之间会存在不能更新的问题???????????
            using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn))

            //using (SoccerScoreSqlite matches = new SoccerScoreSqlite(cnn))
            {
                if (ismath)
                    ltlAll = matches.Live_Table_lib
                        .Where(e => matchlist.Contains(e.Match_type))
                        .Where(m => m.Match_time.Value.Date >= DateTime.Now.AddDays(daysDiff).Date)
                        .OrderBy(m => m.Match_time).ToList();
                else
                    ltlAll = matches.Live_Table_lib
                        .Where(m => m.Match_time.Value.Date >= DateTime.Now.AddDays(daysDiff).Date)
                        .OrderBy(m => m.Match_time).ToList();
                rtlAll = matches.Result_tb_lib.Where(m => m.Match_time.Value.Date >= DateTime.Now.AddDays(daysDiff).Date).ToList();
                marAll = matches.Match_analysis_result.Where(e => e.Live_table_lib_id > 0).ToList();
                loAll = matches.Live_okoo.Where(e => e.Live_okoo_id > 0).ToList();
            }
        }
 private void toolStripButton2_Click(object sender, EventArgs ee)
 {
     MessageBox.Show(ViewMatchOverDays.ToString());
     AuditForecastAlgorithm f = new AuditForecastAlgorithm(ViewMatchOverDays);
     int pb = f.idExc.Count();
     MessageBox.Show(pb.ToString());
     if (pb != 0)
     {
         using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
         {
             dMatch.dHome = matches.result_tb_lib.ToLookup(e => e.home_team_big);
             dMatch.dAway = matches.result_tb_lib.ToLookup(e => e.away_team_big);
         }
         toolStripProgressBar1.Maximum = pb;
         f.top20Algorithm();
     }
     MessageBox.Show("OK");
 }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            string sql = @"
                            if exists (select 1
		                                from  sysobjects
	                                   where  id = object_id('match_analysis_result')
		                                and   type = 'U')
                               drop table match_analysis_result
                            ;

                            CREATE TABLE [dbo].[match_analysis_result](
                                [analysis_result_id] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
                                [live_table_lib_id] [decimal] NOT NULL,
                                [result_tb_lib_id] [decimal] NULL,
                                [pre_algorithm] [nvarchar](20) NULL,
                                [pre_match_count] [int] NULL,
                                [home_w] [int] NULL,
                                [home_d] [int] NULL,
                                [home_l] [int] NULL,
                                [home_goals] [float] NULL,
                                [away_goals] [float] NULL,
                                [fit_win_loss] [float] NULL,
                                [fit_goals] [float] NULL,
                                [fit_odd_even] [float] NULL,
[result_fit] [nvarchar](20) NULL,
[result_goals] [nvarchar](20) NULL,
[result_wdl] [nvarchar](20) NULL,
                             CONSTRAINT [PK_MATCH_ANALYSIS_RESULT] PRIMARY KEY NONCLUSTERED 
                            (
                                [analysis_result_id] ASC
                            )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,
                                 IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
                            ) ON [PRIMARY]";
            DataClassesMatchDataContext matches = new DataClassesMatchDataContext();
            DialogResult result; //Messagebox所属于的类
            result = MessageBox.Show(this, "YesOrNo", "你确定要删除分析库?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)//Messagebox返回的值
            {
                matches.ExecuteCommand(sql);
                MessageBox.Show("OK");
            }
        }
 private void toolStripButton_iniLast_Click(object sender, EventArgs e)
 {
     using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
     {
         int pb = matches.result_tb.Count();
         toolStripProgressBar1.Maximum = pb;
         MessageBox.Show(pb.ToString());
     }
     SevenmResultToSql sevenm = new SevenmResultToSql();
     sevenm.UpdateLastMatch();
 }
 //获取数据库的数据结构
 private void button6_Click(object sender, EventArgs e)
 {
     using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
     {
         dataGridView1.DataSource = matches.match_table_xpath;
     }
 }
 private void treeView5_AfterSelect(object sender, TreeViewEventArgs c)
 {
     if (c.Node.Level == 1)
     {
         dataGridView5.Visible = true;
         using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
         {
             var mar = from a in matches.match_analysis_result
                       join b in matches.live_Table_lib on a.live_table_lib_id equals b.live_table_lib_id
                       select new
                       {
                           a.result_wdl,
                           a.result_fit,
                           a.result_goals,
                           b.match_type
                       };
             var winrate = from p in mar
                           where p.match_type == c.Node.Text
                           group p by p.match_type into q
                           select new
                           {
                               q.Key,
                               fitW = q.Where(e => e.result_fit == "W").Count(),
                               fitL = q.Where(e => e.result_fit == "L").Count(),
                               goalsW = q.Where(e => e.result_goals == "W").Count(),
                               goalsL = q.Where(e => e.result_goals == "L").Count(),
                               wdlW = q.Where(e => e.result_wdl == "W").Count(),
                               wdlL = q.Where(e => e.result_wdl == "L").Count(),
                           };
             dataGridView5.DataSource = winrate;
             var maxwin = winrate.FirstOrDefault();
             int[] maxw = { maxwin.fitW, maxwin.fitL, maxwin.goalsW, maxwin.goalsL, maxwin.wdlW, maxwin.wdlL };
             label3.Text = maxw.Max().ToString();
         }
     }
     if (c.Node.Level != 2) { return; }
     dataGridView5.Visible = false;
     string selectMatch = c.Node.Text.ToString();
     string[] ar = selectMatch.Split(Convert.ToChar(','));
     int id = Int32.Parse(ar[0].ToString());
     label3.Text = LoadDataToChart.ForeCast(chart1, id, selectMatch);
     LoadDataToChart.LabelMatchDetail(chart1, PointLabelsList.GetItemText(PointLabelsList.SelectedItem));
 }
        public void UpdateTodayMatch()
        {
            DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn);
            var lt = matches.Live_Table.OrderBy(o => o.S_date).ThenBy(p => p.S_time);//用lambda表达式简洁

            foreach (var m in lt)
            {
                if (m.Home_team_big != null)
                {
                    //一一对应生成
                    Live_Table_lib ltl = new Live_Table_lib();
                    ltl.Html_position = Int32.Parse(m.Html_position);
                    ltl.Home_team_big = Int32.Parse(GetNumber(m.Home_team_big));
                    ltl.Away_team_big = Int32.Parse(GetNumber(m.Away_team_big));
                    ltl.Match_type = m.Match_type.Trim();
                    if (m.S_date.IndexOf("-") != -1)
                        temp_date = m.S_date.Substring(0, 10);
                    ltl.Match_time = DateTime.Parse(temp_date + " " + m.S_time);
                    ltl.Status = m.Full_time_score.Replace("&nbsp;", "").Trim();
                    ltl.Home_team = m.Home_team.Trim();
                    ltl.Away_team = m.Away_team.Trim();
                    ltl.Home_red_card = StringCount(m.Home_team, "&nbsp;", 0);
                    ltl.Away_red_card = StringCount(m.Away_team, "&nbsp;", 0);
                    ltl.Full_home_goals = null;
                    ltl.Full_away_goals = null;
                    if (m.Half_time_score.IndexOf("-") > 0)
                    {
                        ltl.Half_home_goals = Int32.Parse(m.Half_time_score.Substring(0, m.Half_time_score.IndexOf("-")));
                        ltl.Half_away_goals = Int32.Parse(m.Half_time_score.Substring(m.Half_time_score.IndexOf("-") + 1, m.Half_time_score.Length - m.Half_time_score.IndexOf("-") - 1));
                    }

                    var rtExist = matches.Live_Table_lib.Where(p => p.Home_team_big == ltl.Home_team_big && p.Away_team_big == ltl.Away_team_big);
                    //let关键字,匿名类型
                    var rtUpdateExist = from p in rtExist
                                        let timeDiff = ltl.Match_time.Value - p.Match_time.Value
                                        where timeDiff.Days <= 1
                                        where timeDiff.Days >= -1
                                        select p;

                    //存在记录的则做更新,必须确认是最新数据,即时间差不超过1天
                    if (rtUpdateExist.Any())
                    {
                        var rtUpate = rtUpdateExist.First();
                        rtUpate.Status = ltl.Status;
                        rtUpate.Home_team = ltl.Home_team;
                        rtUpate.Away_team = ltl.Away_team;
                        rtUpate.Home_red_card = ltl.Home_red_card;
                        rtUpate.Away_red_card = ltl.Away_red_card;
                        rtUpate.Half_home_goals = ltl.Half_home_goals;
                        rtUpate.Half_away_goals = ltl.Half_away_goals;
                        //matches.SubmitChanges();
                    }
                    //不存在记录的此处做插入
                    else
                    {
                        matches.Live_Table_lib.InsertOnSubmit(ltl);
                        matches.SubmitChanges();
                    }
                }
            }

            matches.Live_Table.DeleteAllOnSubmit(lt);//更新后删除
            matches.SubmitChanges();
            MessageBox.Show("OK");
            //dataGridView1.DataSource = matches.live_Table_lib;
        }
 private void button29_Click(object sender, EventArgs e)
 {
     using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
     {
         dataGridView1.DataSource = matches.live_Table_lib;
     }
 }
 private void button30_Click(object sender, EventArgs e)
 {
     DataClassesMatchDataContext matches = new DataClassesMatchDataContext();
     dataGridView1.DataSource = matches.result_tb_lib;
 }
        public  void UpdateLastMatch()
        {
            int i = 0;
            DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn .conn );
            var rt = matches.Result_tb.OrderBy(o => o.S_date).ThenBy(p => p.S_time);//用lambda表达式简洁

            //取临时变量监视
            DateTime lib_max_match_time = matches.Result_tb_lib.Select(p => p.Match_time).Max().Value.AddDays(-2);
            foreach (var m in rt)
            {
                i++;
                ProgressBarDelegate.DoSendPMessage(i);
                Application.DoEvents();
                if (m.Home_team_big != null)
                {
                    Result_tb_lib rtl = new Result_tb_lib();
                    rtl.Html_position = Int32.Parse(m.Html_position);
                    rtl.Home_team_big = Int32.Parse(GetNumber(m.Home_team_big));
                    rtl.Away_team_big = Int32.Parse(GetNumber(m.Away_team_big));
                    rtl.Match_type = m.Match_type.Trim();
                    last_line = m.S_time.LastIndexOf("\n");
                    temp_time=m.S_time.Substring(last_line,m.S_time.Length-last_line-1);
                    rtl.Match_time = DateTime.Parse(m.S_date.Substring(0, 10) + " " + temp_time);
                    rtl.Odds = m.Odds.Trim();
                    rtl.Win_loss_big = m.Win_loss_big.Trim();
                    rtl.Home_team = m.Home_team.Trim();
                    rtl.Away_team = m.Away_team.Trim();
                    rtl.Home_red_card = StringCount(m.Home_team, "&nbsp;", 0);
                    rtl.Away_red_card =StringCount(m.Away_team, "&nbsp;", 0);
                    string bf = m.Full_time_score.Replace("&nbsp;", "").Replace("&nbsp;", "");
                    if (m.Full_time_score.IndexOf("-") > 0)
                    {
                        rtl.Full_home_goals = Int32.Parse(bf.Substring(0, bf.IndexOf("-")));
                        rtl.Full_away_goals = Int32.Parse(bf.Substring(bf.IndexOf("-") + 1, bf.Length - bf.IndexOf("-") - 1));
                    }
                    if (m.Half_time_score.IndexOf("-") > 0)
                    {
                        rtl.Half_home_goals = Int32.Parse(m.Half_time_score.Substring(0, m.Half_time_score.IndexOf("-")));
                        rtl.Half_away_goals = Int32.Parse(m.Half_time_score.Substring(m.Half_time_score.IndexOf("-") + 1, m.Half_time_score.Length - m.Half_time_score.IndexOf("-") - 1));
                    }

                    //如果库中文件的日期太小,直接删除
                    if (rtl.Match_time > lib_max_match_time)
                    {
                        //数据分区,层次化查询
                        var rtExist = from p in matches.Result_tb_lib
                                      where p.Match_time == rtl.Match_time
                                      where p.Home_team_big == rtl.Home_team_big
                                      where p.Away_team_big == rtl.Away_team_big
                                      select p;

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

                    //更新后删除
                    matches.Result_tb.DeleteOnSubmit(m);
                    matches.SubmitChanges();
                    
                }
            }
            MessageBox.Show("OK");
            //dataGridView1.DataSource = matches.result_tb_lib;
        }
 private void button9_Click_1(object sender, EventArgs c)
 {
     Uri uri = new Uri(textBox3.Text);
     string host = uri.Host;
     using (DataClassesMatchDataContext match = new DataClassesMatchDataContext())
     {
         var eUri = match.match_table_xpath.Where(e => e.uri_host == host).FirstOrDefault();
         if (eUri == null)
         {
             match_table_xpath nUri = new match_table_xpath();
             nUri.uri_host = host.ToString();
             nUri.max_table_xpath = textBox4.Text;
             nUri.second_table_xpath = textBox6.Text;
             nUri.max_table_id_value = textBox7.Text;
             nUri.second_table_id_value = textBox8.Text;
             match.match_table_xpath.InsertOnSubmit(nUri);
         }
         else
         {
             eUri.uri_host = host.ToString();
             eUri.max_table_xpath = textBox4.Text;
             eUri.second_table_xpath = textBox6.Text;
             eUri.max_table_id_value = textBox7.Text;
             eUri.second_table_id_value = textBox8.Text;
             //match.match_table_xpath.InsertOnSubmit(eUri);
         }
         match.SubmitChanges();
     }
     MessageBox.Show("OK");
 }
        private void button3_Click(object sender, EventArgs c)
        {
            using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext())
            {
                var mar = from a in matches.match_analysis_result
                          join b in matches.live_Table_lib on a.live_table_lib_id equals b.live_table_lib_id
                          select new
                          {
                              a.result_wdl,
                              a.result_fit,
                              a.result_goals,
                              b.match_type
                          };
                var winrate = from p in mar
                              group p by p.match_type into q
                              select new
                              {
                                  q.Key,
                                  fitW = q.Where(e => e.match_type == q.Key).Where(e => e.result_fit == "W").Count(),
                                  fitL = q.Where(e => e.match_type == q.Key).Where(e => e.result_fit == "L").Count(),
                                  goalsW = q.Where(e => e.match_type == q.Key).Where(e => e.result_goals == "W").Count(),
                                  goalsL = q.Where(e => e.match_type == q.Key).Where(e => e.result_goals == "L").Count(),
                                  wdlW = q.Where(e => e.match_type == q.Key).Where(e => e.result_wdl == "W").Count(),
                                  wdlL = q.Where(e => e.match_type == q.Key).Where(e => e.result_wdl == "L").Count(),
                              };

                dataGridView1.DataSource = winrate;
            }
        }