Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Xml;
  11. using System.Net;
  12. using System.ServiceModel.Syndication;
  13. using MySql.Data.MySqlClient;
  14.  
  15. namespace WindowsFormsApp1
  16. {
  17. public partial class Form1 : Form
  18. {
  19. public Form1()
  20. {
  21. InitializeComponent();
  22. }
  23.  
  24. private void richTextBox1_TextChanged(object sender, EventArgs e)
  25. {
  26. }
  27.  
  28. private void richTextBox2_TextChanged(object sender, EventArgs e)
  29. {
  30. }
  31.  
  32. private void button1_Click(object sender, EventArgs e)
  33. {
  34. richTextBox1.Clear();
  35. string URL = textBox1.Text;
  36. XmlReader reader = XmlReader.Create(URL);
  37. SyndicationFeed feed = SyndicationFeed.Load(reader);
  38. reader.Close();
  39. int id = 1;
  40. foreach (SyndicationItem item in feed.Items)
  41. {
  42. richTextBox1.SelectionColor = Color.Red;
  43. richTextBox1.AppendText(id + ". " + item.Title.Text + "\r\n");
  44. richTextBox1.SelectionColor = Color.Black;
  45. richTextBox1.AppendText(item.Summary.Text + "\r\n");
  46. richTextBox1.SelectionColor = Color.Gray;
  47. richTextBox1.AppendText(item.PublishDate + "\r\n");
  48. richTextBox1.AppendText(item.Links[0].GetAbsoluteUri() + "\r\n");
  49. richTextBox1.SelectionColor = Color.Black;
  50. richTextBox1.AppendText("_____________________________________________________________________\r\n");
  51. id += 1;
  52. }
  53. }
  54.  
  55. private void button2_Click(object sender, EventArgs e)
  56. {
  57. int id = 1;
  58. string delete = "DELETE FROM news_rss";
  59. string ConnStr = "server=localhost;user=root;database=database;password=;";
  60. MySqlConnection conn = new MySqlConnection(ConnStr);
  61. conn.Open();
  62.  
  63. string URL = textBox1.Text;
  64. XmlReader reader = XmlReader.Create(URL);
  65. SyndicationFeed feed = SyndicationFeed.Load(reader);
  66. reader.Close();
  67.  
  68. MySqlCommand command_delete = new MySqlCommand(delete, conn);
  69. command_delete.ExecuteNonQuery();
  70. foreach (SyndicationItem item in feed.Items)
  71. {
  72. string add_text = "INSERT INTO news_rss SET id='" + id + "', name='"
  73. + item.Title.Text + "', description='" + item.Summary.Text + "', data='"
  74. + item.PublishDate + "', link='" + item.Links[0].GetAbsoluteUri() + "'";
  75. MySqlCommand command_add = new MySqlCommand(add_text, conn);
  76. id += 1;
  77. command_add.ExecuteNonQuery();
  78. }
  79. conn.Close();
  80.  
  81. }
  82.  
  83. private void button3_Click(object sender, EventArgs e)
  84. {
  85. richTextBox2.Clear();
  86. string ConnStr = "server=localhost;user=root;database=database;password=;";
  87. MySqlConnection conn = new MySqlConnection(ConnStr);
  88. conn.Open();
  89. string sql = "SELECT id, name, description, data, link FROM news_rss";
  90. MySqlCommand command = new MySqlCommand(sql, conn);
  91. MySqlDataReader reader = command.ExecuteReader();
  92. while (reader.Read())
  93. {
  94. richTextBox2.SelectionColor = Color.Red;
  95. richTextBox2.AppendText(reader[0].ToString() + ". " + reader[1].ToString() + "\r\n");
  96. richTextBox2.SelectionColor = Color.Black;
  97. richTextBox2.AppendText(reader[2] + "\r\n");
  98. richTextBox2.SelectionColor = Color.Gray;
  99. richTextBox2.AppendText(reader[3] + "\r\n");
  100. richTextBox2.SelectionColor = Color.Black;
  101. richTextBox2.AppendText(reader[4] + "\r\n");
  102. richTextBox2.AppendText("_____________________________________________________________________\r\n");
  103. }
  104. reader.Close();
  105. conn.Close();
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement