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"); } } }
//ajouter moto public bool ajouterMoto(Moto v) { try { sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); string req = "Insert Into Automobile(Annee, Immatriculation, Cylindre , VitesseMax, AutoMoto) Values (" + v.Annee + ", '" + v.Immatriculation + "', " + v.Cylindre + ", " + v.VitesseMax + ", 'False');"; // 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 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; } }
public bool modifierMoto(string immatriculation, Moto m) { try { sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); string req = "update Automobile set Annee=" + m.Annee + ", Cylindre=" + m.Cylindre + ", VitesseMax=" + m.VitesseMax + " where Immatriculation='" + immatriculation + "' and AutoMoto='False';"; sqlite_cmd.CommandText = req; sqlite_cmd.ExecuteNonQuery(); sqlite_conn.Close(); return false; } catch (Exception) { return false; } }
public Moto getUnMoto(string immatriculation) { Moto m = new Moto(); try { sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); string req = "select * from Automobile where Immatriculation='" + immatriculation + "' and AutoMoto='False';"; // Lets insert something into our new table: sqlite_cmd.CommandText = req; sqlite_datareader = sqlite_cmd.ExecuteReader(); while (sqlite_datareader.Read()) { m.Annee = Int32.Parse(sqlite_datareader["Annee"].ToString()); m.Immatriculation = sqlite_datareader["Immatriculation"].ToString(); m.Cylindre = Int32.Parse(sqlite_datareader["Cylindre"].ToString()); m.VitesseMax = Int32.Parse(sqlite_datareader["VitesseMax"].ToString()); } sqlite_conn.Close(); } catch (Exception) { Console.WriteLine("Erreur dans la requette"); } return m; }
//afficher les motos public List<Moto> getLesMotos() { List<Moto> motos = new List<Moto>(); sqlite_conn.Open(); sqlite_cmd = sqlite_conn.CreateCommand(); string req = "select * from Automobile where AutoMoto='False';"; // Lets insert something into our new table: sqlite_cmd.CommandText = req; sqlite_datareader = sqlite_cmd.ExecuteReader(); while (sqlite_datareader.Read()) { Moto v = new Moto(); v.Annee = Int32.Parse(sqlite_datareader["Annee"].ToString()); v.Immatriculation = sqlite_datareader["Immatriculation"].ToString(); v.Cylindre = Int32.Parse(sqlite_datareader["Cylindre"].ToString()); v.VitesseMax = Int32.Parse(sqlite_datareader["VitesseMax"].ToString()); motos.Add(v); } sqlite_conn.Close(); return motos; }