public Client(string nom, string adresse, string telephone, int index_ville) { m_nom = nom; m_adresse = adresse; m_telephone = telephone; m_ville = DataBase.SqlDataProvider.trouverVille(index_ville); }
// TODO public static Client ClientExiste(string nom, Ville ville) { Client client = null; Agent agent; if (DBConnect()) { string requete = "SELECT NUM_C, NOM_C, ADRESSE_C, TEL_C, NUM_A, NUM_V FROM CLIENTS WHERE NOM_C=N'"+nom+"' AND NUM_V=N'"+ville.Index+"'"; OleDbCommand command = new OleDbCommand(requete, connect); OleDbDataReader reader = command.ExecuteReader(); // ajout des noms des clients dans la liste while (reader.Read()) { try { agent = SqlDataProvider.trouverAgent(reader.GetInt16(4)); } catch (Exception) { agent = null; } try { Ville villeC = SqlDataProvider.trouverVille(reader.GetInt16(5)); client = new Client(reader.GetInt16(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), agent, villeC); } catch (Exception) { client = null; } } // déconnexion reader.Close(); connect.Close(); } return client; }
private void boutonAjouter_Click(object sender, EventArgs e) { int codePostal; // si une des cases est vide if (textBoxCP.Text == "" || textBoxNom.Text == "") { MessageBox.Show("Formulaire mal rempli"); return; } // si code postal n'est pas un chiffre if (!int.TryParse(textBoxCP.Text, out codePostal)) { MessageBox.Show("Le code postal doit être un chiffre."); return; } Ville nouvelleVille = new Ville(codePostal, textBoxNom.Text); if (ajoutBdD(nouvelleVille)) { MessageBox.Show("Ajout OK"); this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Erreur d'ajout"); } }
public Bien(int prix, DateTime dateMiseEnVente, int surfaceHabitable, int surfaceJardin, Ville ville, Client client) { m_prix = prix; m_dateMiseEnVente = dateMiseEnVente; m_surfaceHabitable = surfaceHabitable; m_surfaceJardin = surfaceJardin; m_ville = ville; m_client = client; }
public Client(int index, string nom, string adresse, string telephone, Agent agent, Ville ville) { m_index = index; m_nom = nom; m_adresse = adresse; m_telephone = telephone; m_agent = agent; m_ville = ville; }
public Client(int index, string nom, string adresse, string telephone, int index_agent, int index_ville) { m_index = index; m_nom = nom; m_adresse = adresse; m_telephone = telephone; m_agent = SqlDataProvider.trouverAgent(index_agent); m_ville = SqlDataProvider.trouverVille(index_ville); }
private bool ajoutBdD(Ville ville) { // vérification si la ville est déjà en base (même CP et même nom) if (SqlDataProvider.VerificationPresenceVille(ville)) { MessageBox.Show("La ville est déjà dans la base de données","Avertissement"); return false; } // si ville n'existe pas déjà else { SqlDataProvider.AjouterVille(ville); return true; } }
private bool ajoutBdD(Ville ville) { // vérification si la ville est déjà en base (même CP et même nom) if (SqlDataProvider.VerificationPresenceVille(ville)) { MessageBox.Show("Ville déjà dans la BdD"); return false; } // si ville n'existe pas déjà else { SqlDataProvider.SaveVille(ville); return true; } }
/// <summary> /// Ajout d'une ville dans la base /// </summary> /// <param name="ville">Ville à ajouter</param> /// <returns>true si l'ajout a marché, false sinon</returns> public static bool AjouterVille(Ville ville) { bool ajout = false; if (DBConnect()) // si connexion { string requete = string.Format("INSERT INTO VILLES (NOM_V, CODE_POSTAL_V) VALUES (N'{0}',N'{1}')", ville.Nom.Replace("'", "''"), ville.CodePostal); OleDbCommand command = new OleDbCommand(requete, connect); int rowCount = command.ExecuteNonQuery(); if (rowCount == 1) ajout = true; // ajout effectué else ajout = false; // ajout non effectué // déconnexion connect.Close(); } return ajout; }
// Retrouver une ville à partir de son index public static Ville trouverVille(int index) { if (DBConnect()) { string requete = "SELECT CODE_POSTAL_V, NOM_V FROM VILLES WHERE NUM_V = " + index; OleDbCommand command = new OleDbCommand(requete, connect); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { int cp = reader.GetInt32(0); string nom = reader.GetString(1); Ville ville = new Ville(cp, nom, index); return ville; } reader.Close(); connect.Close(); } return null; }
private void boutonAjouter_Click(object sender, EventArgs e) { int codePostal; // si code postal n'est pas un chiffre if (!int.TryParse(textBoxCP.Text, out codePostal)) { MessageBox.Show("Le code postal doit être un chiffre.","Attention"); return; } Ville nouvelleVille = new Ville(codePostal, textBoxNom.Text); if (ajoutBdD(nouvelleVille)) { MessageBox.Show("La ville a bien été ajoutée dans la base de données.","Ajout réussit"); this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Aucune ville n'a été ajoutée.","Erreur"); } }
/// <summary> /// Vérification si la ville passée en paramètre est déjà dans la base /// </summary> /// <param name="villeRecherchee">Ville à vérifier</param> /// <returns>true si elle existe, false sinon</returns> public static bool VerificationPresenceVille(Ville villeRecherchee) { bool presente = false; List<Ville> listeVilles = GetListeVilles(); foreach (Ville ville in listeVilles) if (ville.Nom == villeRecherchee.Nom && ville.CodePostal == villeRecherchee.CodePostal) presente = true; return presente; }