static public int loadLastId() { db_management db = db_management.Instance; try { SQLiteConnection connection = db.openConnection(); String squery = "SELECT RefMarque, MAX(RefMarque) FROM Marques"; SQLiteCommand commande = new SQLiteCommand(squery, connection); SQLiteDataReader reader = commande.ExecuteReader(); if (reader.HasRows) { reader.Read(); int id; if (reader[0].GetType() != typeof(DBNull)) { id = (int)reader[0]; } else { id = 0; } reader.Close(); db.closeConnection(); idMarque = id; return(id); } else { reader.Close(); db.closeConnection(); return(0); } } catch (Exception e) { Console.WriteLine(e.Message + " | In Marques/loadLastId"); db.closeConnection(); return(0); } }
static public int getRefMarqueFromName(String name) { db_management db = db_management.Instance; try { SQLiteConnection connection = db.openConnection(); String squery = "SELECT RefMarque FROM Marques WHERE Nom = @Nom"; SQLiteCommand commande = new SQLiteCommand(squery, connection); commande.Parameters.Add(new SQLiteParameter("@Nom", name)); SQLiteDataReader reader = commande.ExecuteReader(); if (reader.HasRows) { reader.Read(); int reference; if (reader[0].GetType() != typeof(DBNull)) { reference = Convert.ToInt32(reader.GetInt64(0)); } else { reference = -1; } reader.Close(); db.closeConnection(); return(reference); } else { reader.Close(); db.closeConnection(); return(-1); } } catch (Exception e) { Console.WriteLine(e.Message + " | In Marques/getRefMarqueFromName"); db.closeConnection(); return(-1); } }
public static bool flushTable() { db_management db = db_management.Instance; try{ SQLiteConnection connection = db.openConnection(); SQLiteCommand commande; String squery = "DELETE FROM Articles"; commande = new SQLiteCommand(squery, connection); commande.ExecuteNonQuery(); db.closeConnection(); return(true); } catch (Exception e) { Console.WriteLine(e.Message + " | In Articles/flushTable"); db.closeConnection(); return(false); } }
public static int countRows() { db_management db = db_management.Instance; try { SQLiteConnection connection = db.openConnection(); String squery = "SELECT COUNT(RefMarque) FROM Marques"; SQLiteCommand commande = new SQLiteCommand(squery, connection); SQLiteDataReader reader = commande.ExecuteReader(); if (reader.HasRows) { reader.Read(); int count; if (reader[0].GetType() != typeof(DBNull)) { count = Convert.ToInt32(reader.GetInt64(0)); } else { count = -1; } reader.Close(); db.closeConnection(); return(count); } else { reader.Close(); db.closeConnection(); return(-1); } } catch (Exception e) { Console.WriteLine(e.Message + " | In Marques/countRows"); db.closeConnection(); return(-1); } }
public bool deleteFromDB() { db_management db = db_management.Instance; try { SQLiteConnection connection = db.openConnection(); SQLiteCommand commande; String squery; squery = "DELETE FROM Marques WHERE RefMarque = @RefMarque"; commande = new SQLiteCommand(squery, connection); commande.Parameters.Add(new SQLiteParameter("@RefMarque", refMarque)); commande.ExecuteNonQuery(); db.closeConnection(); return(true); } catch (Exception e) { Console.WriteLine(e.Message + " | In Marques/deleteFromDB"); db.closeConnection(); return(false); } }