// create a new database connection: //ajouter voiture public bool ajouterVoiture(Voiture v) { try { sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); string req = "Insert Into Automobile(Annee, Immatriculation, Coulour, Marque, TypeV, AutoMoto) Values (" + v.Annee + ", '" + v.Immatriculation + "', '" + v.Coulour + "', '" + v.Marque + "', '" + v.TypeV + "', 'True');"; // Lets insert something into our new table: sqlite_cmd.CommandText = req; sqlite_cmd.ExecuteNonQuery(); sqlite_conn.Close(); return true; } catch (Exception) { return false; } }
private void btn_ajouter_Click(object sender, EventArgs e) { if (combo_categorie.SelectedIndex == 0) { Moto m = new Moto(); m.Annee=Int32.Parse(txt_annee.Text); m.Immatriculation=txt_immatriculation.Text; m.Cylindre = Int32.Parse(txt_cylindre.Text); m.VitesseMax = Int32.Parse(txt_vitesse.Text); txt_annee.Text = ""; txt_immatriculation.Text = ""; txt_cylindre.Text = ""; txt_vitesse.Text = ""; if (garage.ajouterMoto(m)) { MessageBox.Show("Inssertion réussi"); } } if (combo_categorie.SelectedIndex == 1) { Voiture v = new Voiture(); v.Annee = Int32.Parse(txt_annee.Text); v.Immatriculation = txt_immatriculation.Text; v.Coulour = txt_coulour.Text; v.Marque = txt_marque.Text; v.TypeV = txt_typeV.Text; txt_annee.Text = ""; txt_immatriculation.Text = ""; txt_coulour.Text = ""; txt_marque.Text = ""; txt_typeV.Text = ""; if (garage.ajouterVoiture(v)) { MessageBox.Show("Inssertion réussi"); } } }
private void combo_categorie_SelectedIndexChanged(object sender, EventArgs e) { if (combo_categorie.SelectedIndex == 0) { lbl_colour.Visible = false; lbl_marque.Visible = false; lbl_typeV.Visible = false; lbl_annee_voiture.Visible = false; txt_coulour.Visible = false; txt_marque.Visible = false; txt_typeV.Visible = false; txt_annee_voiture.Visible = false; lbl_cylindre.Visible = true; lbl_vitesse.Visible = true; lbl_annee_moto.Visible = true; txt_cylindre.Visible = true; txt_vitesse.Visible = true; txt_annee_moto.Visible = true; m = garage.getUnMoto(txt_immatriculation.Text); txt_immatriculation.Text = m.Immatriculation; txt_annee_moto.Text = m.Annee.ToString(); txt_cylindre.Text = m.Cylindre.ToString(); txt_vitesse.Text = m.VitesseMax.ToString(); } if (combo_categorie.SelectedIndex == 1) { lbl_colour.Visible = true; lbl_marque.Visible = true; lbl_typeV.Visible = true; lbl_annee_voiture.Visible = true; txt_coulour.Visible = true; txt_marque.Visible = true; txt_typeV.Visible = true; txt_annee_voiture.Visible = true; lbl_cylindre.Visible = false; lbl_vitesse.Visible = false; lbl_annee_moto.Visible = false; txt_cylindre.Visible = false; txt_vitesse.Visible = false; txt_annee_moto.Visible = false; vo = garage.getUneVoiture(txt_immatriculation.Text); txt_immatriculation.Text = vo.Immatriculation; txt_annee_voiture.Text = (vo.Annee).ToString(); txt_typeV.Text = vo.TypeV; txt_coulour.Text = vo.Coulour; txt_marque.Text = vo.Marque; } }
// afficher tout les voiture public List<Voiture> getLseVoitures() { sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); List<Voiture> voitures = new List<Voiture>(); string req = "select * from Automobile where AutoMoto='True';"; // Lets insert something into our new table: sqlite_cmd.CommandText = req; sqlite_datareader = sqlite_cmd.ExecuteReader(); while (sqlite_datareader.Read()) { Voiture v = new Voiture(); v.Annee = Int32.Parse(sqlite_datareader["Annee"].ToString()); v.Immatriculation = sqlite_datareader["Immatriculation"].ToString(); v.Coulour = sqlite_datareader["Coulour"].ToString(); v.Marque = sqlite_datareader["Marque"].ToString(); v.TypeV = sqlite_datareader["TypeV"].ToString(); voitures.Add(v); } sqlite_conn.Close(); return voitures; }
public bool modifierVoiture(string immatriculation, Voiture v) { try { sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); string req = "update Automobile set Annee=" + v.Annee + ", Coulour='" + v.Coulour + "', Marque='" + v.Marque + "', TypeV='" + v.TypeV + "' where Immatriculation='"+immatriculation+"' and AutoMoto='True';"; sqlite_cmd.CommandText = req; sqlite_cmd.ExecuteNonQuery(); sqlite_conn.Close(); return false; } catch (Exception) { return false; } }
public Voiture getUneVoiture(string immatriculation) { Voiture v = new Voiture(); try { sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); string req = "select * from Automobile where Immatriculation='" + immatriculation + "' and AutoMoto='True';"; sqlite_cmd.CommandText = req; sqlite_datareader = sqlite_cmd.ExecuteReader(); while (sqlite_datareader.Read()) { v.Annee = Int32.Parse(sqlite_datareader["Annee"].ToString()); v.Immatriculation = sqlite_datareader["Immatriculation"].ToString(); v.Coulour = sqlite_datareader["Coulour"].ToString(); v.Marque = sqlite_datareader["Marque"].ToString(); v.TypeV = sqlite_datareader["TypeV"].ToString(); } sqlite_conn.Close(); } catch (Exception) { Console.WriteLine("Erreur dans la requette"); } return v; }