Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using NSDBConnect;
- using System.Collections.ObjectModel;
- using MySql.Data.MySqlClient;
- using HtmlAgilityPack;
- namespace WpfApp2
- {
- /// <summary>
- /// Logique d'interaction pour MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public ObservableCollection<Person> test { get; set; }
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {/*
- DBConnect db1 = new DBConnect();
- Console.WriteLine("Initializing");
- db1.Select();
- */
- Console.ReadLine();
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- List<Person> persons = new List<Person>();
- persons.Add(new Person("Misha", "Kozlov"));
- persons.Add(new Person("Joe", "Black"));
- MyGrid.ItemsSource = persons;
- }
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- string connectionString = "server=localhost;user id=root;port=3306;Pwd=;database=csharp";
- MySqlConnection connection = new MySqlConnection(connectionString);
- MySqlCommand cmd = new MySqlCommand();
- MySqlDataReader reader;
- cmd.CommandText = "PS_Admin_ListeUser";
- cmd.CommandType = System.Data.CommandType.StoredProcedure;
- cmd.Connection = connection;
- connection.Open();
- reader = cmd.ExecuteReader();
- List<Person> persons = new List<Person>();
- while (reader.Read())
- {
- string UnNom = reader.GetString("Nom");
- string UnPrenom = reader.GetString("Prenom");
- int UnID = reader.GetInt32("IDUser");
- persons.Add(new Person(UnID, UnNom, UnPrenom));
- }
- MyGrid.ItemsSource = persons;
- reader.Close();
- connection.Close();
- }
- private void Button_Click_3(object sender, RoutedEventArgs e)
- {
- string connectionString = "server=SRV-WAKANDA.cloudapp.net;user id=root;port=13306;Pwd=KCX96mtkhm!;database=parking";
- MySqlConnection connection = new MySqlConnection(connectionString);
- MySqlCommand cmd = new MySqlCommand();
- cmd.CommandText = "PS_User_Delete";
- cmd.CommandType = System.Data.CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@aIDUser", int.Parse(TB_ID.Text));
- cmd.Connection = connection;
- connection.Open();
- cmd.ExecuteNonQuery();
- connection.Close();
- }
- private void MyGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- try
- {
- if (MyGrid.SelectedItem != null)
- {
- if (MyGrid.SelectedItem is Person)
- {
- var Ligne = (Person)MyGrid.SelectedItem;
- if (Ligne != null)
- {
- TB_ID.Text = Ligne.ID.ToString();
- }
- }
- }
- }
- catch (Exception)
- {
- }
- }
- private void Button_Click_4(object sender, RoutedEventArgs e)
- {
- try
- {
- if (MyGrid.SelectedItem != null)
- {
- if (MyGrid.SelectedItem is Person)
- {
- var Ligne = (Person)MyGrid.SelectedItem;
- if (Ligne != null)
- {
- Form1 FormDetail = new Form1(Ligne);
- FormDetail.Show();
- }
- }
- }
- }
- catch (Exception)
- {
- }
- }
- private void Button_Click_5(object sender, RoutedEventArgs e)
- {
- string url = "https://www.pagesjaunes.fr/annuaire/paris-75/natixis";
- HtmlWeb web = new HtmlWeb();
- HtmlDocument doc = web.Load(url);
- /*var titleElement =
- doc.DocumentNode
- .Element("html")
- .Element("head")
- .Element("title");
- if (titleElement != null)
- {
- string title = titleElement.InnerText;
- Console.WriteLine("Titre: {0}", title);
- }
- else
- {
- Console.WriteLine("Pas de titre");
- }*/
- /*
- var body =
- doc.DocumentNode
- .Element("html")
- .Element("body");
- var titles = body.Elements("h2");
- foreach (var title in titles)
- {
- Console.WriteLine(title.InnerHtml);
- }
- */
- //var links = doc.DocumentNode.Descendants("a");
- var links = doc.DocumentNode.SelectNodes("//*[@class=\"cross-links\"]//li");
- foreach (var link in links)
- {
- try
- {
- String value = link.InnerText;
- Char delimiter = ',';
- String[] substrings = value.Split(delimiter);
- /* foreach (var substring in substrings)
- Console.WriteLine(substring);*/
- //This is my connection string i have assigned the database file address path
- string MyConnection2 = "datasource=personne;port=3307;username=root;password=";
- //This is my insert query in which i am taking input from the user through windows forms
- string Query = "insert into personne(nom,adresse,code) values('" + substrings[0] + "','" + substrings[1] + "','" + substrings[2] + "');";
- //This is MySqlConnection here i have created the object and pass my connection string.
- MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
- //This is command class which will handle the query and connection object.
- MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
- MySqlDataReader MyReader2;
- MyConn2.Open();
- MyReader2 = MyCommand2.ExecuteReader(); // Here our query will be executed and data saved into the database.
- MessageBox.Show("Save Data");
- while (MyReader2.Read())
- {
- }
- MyConn2.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- Console.WriteLine("ok"+link.InnerText);
- }
- /*
- var table = doc.GetElementbyId("listResults");
- var rows = table.Element("tbody").Elements("tr");
- var contacts =
- from r in rows
- let values = r.Elements("td").Select(c => c.InnerText).ToArray()
- select new Person(int.Parse(values[2]),values[0], values[1]);
- MyGrid.Columns[2].Header = "Age";
- MyGrid.ItemsSource = contacts;*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement