// Suite de l'envoi de l'IP /* private System.Net.IPAddress adrIpLocale; * private IPAddress getAdrIpLocaleV4() * { * string hote = Dns.GetHostName(); * IPHostEntry ipLocales = Dns.GetHostEntry(hote); * foreach (IPAddress ip in ipLocales.AddressList) * { * if (ip.AddressFamily == AddressFamily.InterNetwork) * { * return ip; * } * } * return null; // aucune adresse IP V4 * }*/ private void btn_Envoyer_indice_Click(object sender, RoutedEventArgs e) { Indice indice = new Indice(); indice.Text = txtIndice.Text; Bdd bdd = new Bdd(); bdd.AddIndice(indice); /* string ipaddr = "192.168.1.0"; * * byte[] message; * Socket sock = new Socket(AddressFamily.InterNetwork, * SocketType.Dgram, ProtocolType.Udp); * System.Net.IPEndPoint epEmetteur = new IPEndPoint(adrIpLocale, 0); * sock.Bind(epEmetteur); * IPEndPoint epRecepteur = new IPEndPoint( * IPAddress.Parse(ipaddr), 33000); //IPAddress.Parse(tb_ipDestinataire.Text), 33000); * message = Encoding.Unicode.GetBytes(txtIndice.Text); * sock.SendTo(message, epRecepteur); * sock.Close();*/ string message = txtIndice.Text; //Sérialisation du message en tableau de bytes. byte[] msg = Encoding.Default.GetBytes(message); UdpClient udpClient = new UdpClient(); //La méthode Send envoie un message UDP. udpClient.Send(msg, msg.Length, "127.0.0.1", 5035); udpClient.Close(); }
// Méthode pour ajouter un indice : public void AddIndice(Indice indice) { try { // Ouverture de la connexion SQL this.connection.Open(); // Création d'une commande SQL en fonction de l'objet connection MySqlCommand cmd = this.connection.CreateCommand(); // Requête SQL cmd.CommandText = "INSERT INTO tbindice (id, text, date_dernier_envoi) VALUES (@id, @text, NOW())"; // Utilisation de l'objet contact passé en paramètre cmd.Parameters.AddWithValue("@id", indice.Id); cmd.Parameters.AddWithValue("@text", indice.Text); // Exécution de la commande SQL cmd.ExecuteNonQuery(); // Fermeture de la connexion this.connection.Close(); MessageBox.Show("Le nouvel indice a été correctement enregistré !"); } catch { MessageBox.Show("L'ajout du nouvel indice dans la base de données à échoué. " + "Veuillez vous assurer que le serveur MySQL (Base de données) est correctement lancé."); } }