private void hudong_Thread_Timer_Method(object o) { long hudong_maxtime; MySqlConnection connection = new MySqlConnection("Database=zyg;Data Source=sirius0427.jios.org;User Id=cst;Password=q1w2e3r4t5Y^U&I*O(P);pooling=false;CharSet=utf8;port=3307"); connection.Open(); MySqlDataReader reader = new MySqlCommand("select max(collectiontime) as time from newsinfo where articletype='2'", connection).ExecuteReader(); reader.Read(); hudong_maxtime = reader["time"].ToLong(); reader.Close(); object[] objArray1 = new object[] { "select from_unixtime(collectiontime/1000) as time,title,digest,sourcename from newsinfo where articletype='2' and collectiontime >", hudong_lasttime, " and collectiontime <=", hudong_maxtime, " order by collectiontime" }; reader = new MySqlCommand(string.Concat(objArray1), connection).ExecuteReader(); try { int insertflag = 0; while (reader.Read()) { if (reader.HasRows) { int startIndex = 0; int num2 = 0; string str = ""; string str2 = ""; MyData data = new MyData { time = reader["time"].ToString() }; string str3 = reader["title"].ToString().Replace("\n", ""); if (reader["sourcename"].Equals("深证互动")) { startIndex = str3.IndexOf("问", 0) + 2; num2 = str3.IndexOf("):", 0) + 2; str = str3.Substring(startIndex, (num2 - startIndex) - 1); str2 = str3.Substring(num2, str3.Length - num2); } else if (reader["sourcename"].Equals(" 上证互动")) { startIndex = str3.IndexOf(":", 0) + 1; num2 = str3.IndexOf(")", 0) + 1; str = str3.Substring(startIndex, num2 - startIndex); str2 = str3.Substring(num2, str3.Length - num2); } str.Trim(); str2.Trim(); string[] textArray1 = new string[] { " 问:", str2, Environment.NewLine, " 答:", reader["digest"].ToString() }; data.title = string.Concat(textArray1); data.sourcename = str + "\n" + reader["time"].ToString(); string[] textArray2 = new string[] { str, "\t", reader["time"].ToString(), "\n问:", str2, Environment.NewLine, "\n答:", reader["digest"].ToString() }; string parameter = string.Concat(textArray2); //Thread thread1 = new Thread(new ParameterizedThreadStart(new StartMessageBox().CreateCounterWindowThread)); //thread1.SetApartmentState(ApartmentState.STA); //thread1.IsBackground = true; //thread1.Start(parameter); //base.Dispatcher.BeginInvoke((Action)delegate //{ // NotifyData data1 = new NotifyData(); // data1.Title = "抓妖股实时互动"; // data1.Content = parameter; // NotificationWindow dialog = new NotificationWindow();//new 一个通知 // dialog.Closed += Dialog_Closed; // dialog.TopFrom = GetTopFrom(); // _dialogs.Add(dialog); // dialog.DataContext = data1;//设置通知里要显示的数据 // dialog.Show(); //}, null); Dispatcher.BeginInvoke((Action) delegate { if (hudong_filter.IsChecked.Value) { insertflag = 0; foreach (string str1 in Regex.Split(hudong_filtertext.Text, ",", RegexOptions.IgnoreCase)) { if (data.title.IndexOf(str1) >= 0) { insertflag += 1; } else { insertflag += 0; } } } else { insertflag = 1; } if (insertflag >= 1) { dataset_hudong.Insert(0, data); new SoundPlayer("ring.wav").Play(); NotifyData data1 = new NotifyData(); data1.Title = "抓妖股实时互动" + insertflag.ToString(); data1.Content = parameter; NotificationWindow dialog = new NotificationWindow();//new 一个通知 dialog.Closed += Dialog_Closed; dialog.TopFrom = GetTopFrom(); _dialogs.Add(dialog); dialog.DataContext = data1;//设置通知里要显示的数据 dialog.Show(); } }, null); } } hudong_lasttime = hudong_maxtime; Dispatcher.BeginInvoke((Action) delegate() { ListView_hudong.ItemsSource = dataset_hudong; }, null); } catch (Exception) { MessageBox.Show("查询失败了!" + reader["title"].ToString().Replace("\n", "")); } finally { reader.Close(); connection.Close(); } }
private void search_hudong(object sender, RoutedEventArgs e) { //List<MyData> dataset_hudong = new List<MyData>(); dataset_hudong.Clear(); String mysqlStr = "Database=zyg;Data Source=sirius0427.jios.org;User Id=cst;Password=q1w2e3r4t5Y^U&I*O(P);pooling=false;CharSet=utf8;port=3307"; MySqlConnection mysql = new MySqlConnection(mysqlStr); mysql.Open(); String sqlSearch = "select max(collectiontime) as time from newsinfo where articletype='2'"; MySqlCommand mySqlCommand = new MySqlCommand(sqlSearch, mysql); MySqlDataReader reader = mySqlCommand.ExecuteReader(); reader.Read(); hudong_lasttime = reader["time"].ToLong(); reader.Close(); sqlSearch = "select from_unixtime(collectiontime/1000) as time,title,digest,sourcename from newsinfo where (title like '%" + KeyWord.Text + "%' or digest like '%" + KeyWord.Text + "%') and articletype='2' order by collectiontime desc limit 100"; mySqlCommand = new MySqlCommand(sqlSearch, mysql); reader = mySqlCommand.ExecuteReader(); try { while (reader.Read()) { if (reader.HasRows) { int startIndex = 0; int num2 = 0; string str = ""; string str2 = ""; MyData item = new MyData { time = reader["time"].ToString() }; string str3 = reader["title"].ToString().Replace("\n", ""); if (reader["sourcename"].Equals("深证互动")) { startIndex = str3.IndexOf("问", 0) + 2; num2 = str3.IndexOf("):", 0) + 2; str = str3.Substring(startIndex, (num2 - startIndex) - 1); str2 = str3.Substring(num2, str3.Length - num2); } else if (reader["sourcename"].Equals(" 上证互动")) { startIndex = str3.IndexOf(":", 0) + 1; num2 = str3.IndexOf(")", 0) + 1; str = str3.Substring(startIndex, num2 - startIndex); str2 = str3.Substring(num2, str3.Length - num2); } str.Trim(); str2.Trim(); string[] textArray1 = new string[] { " 问:", str2, Environment.NewLine, " 答:", reader["digest"].ToString() }; item.title = string.Concat(textArray1); item.sourcename = str + "\n" + reader["time"].ToString(); //int num3 = 0; //if (hudong_filter.IsChecked.Value) //{ // foreach (string str4 in Regex.Split(hudong_filtertext.Text, ",")) // { // if (item.title.IndexOf(str4) >= 0) // { // num3 = 1; // } // } //} //else //{ // num3 = 1; //} //if (num3 == 1) //{ dataset_hudong.Add(item); //} } } } catch (Exception) { MessageBox.Show("查询失败了!" + reader["title"].ToString().Replace("\n", "")); } finally { ListView_hudong.ItemsSource = null; ListView_hudong.ItemsSource = dataset_hudong; reader.Close(); mysql.Close(); } }