// Insert public int insert(string connectionString, AlertMailLog alertMailLog) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { int x = -9; conn.Open(); if (conn.State == System.Data.ConnectionState.Open) { SQLiteCommand command = new SQLiteCommand(@"INSERT INTO " + TABLE_NAME + " ('" + COLONNE_ID + "', '" + COLONNE_LOG + "') VALUES(" + alertMailLog.id + ",'" + alertMailLog.log + "')", conn); x = command.ExecuteNonQuery(); //Console.WriteLine("Table created"); } conn.Close(); return(x); } catch (Exception ex) { Console.WriteLine("AlertMailLog Insert 1 [ERROR]"); Console.WriteLine("Message : " + ex.Message); Console.WriteLine("\nStackTrace : " + ex.StackTrace); conn.Close(); return(-99); } } }
// Update public int update(string connectionString, AlertMailLog alertMailLog, StreamWriter writer) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { int x = -9; conn.Open(); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => update() | Creation d'une Instance"); if (conn.State == System.Data.ConnectionState.Open) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => update() | SQL => UPDATE " + TABLE_NAME + " SET " + COLONNE_LOG + " = '" + alertMailLog.log + "' WHERE " + COLONNE_ID + " = " + alertMailLog.id); SQLiteCommand command = new SQLiteCommand(@"UPDATE " + TABLE_NAME + " SET " + COLONNE_LOG + " = '" + alertMailLog.log + "' WHERE " + COLONNE_ID + " = " + alertMailLog.id, conn); x = command.ExecuteNonQuery(); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => update() | id : " + alertMailLog.id + " is Updated !"); } writer.Flush(); conn.Close(); return(x); } catch (Exception ex) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => update() | ##################################################"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => update() | [ERROR] update"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => update() | Message : " + ex.Message); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => update() | StackTrace : " + ex.StackTrace); writer.WriteLine(""); writer.Flush(); conn.Close(); return(-99); } } }
// Delete by ID public bool deleteById(string connectionString, AlertMailLog alertMailLog) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { conn.Open(); if (conn.State == System.Data.ConnectionState.Open) { using (IDbConnection db = conn) { SQLiteCommand command = new SQLiteCommand(@"DELETE FROM " + TABLE_NAME + " WHERE " + COLONNE_ID + " = " + alertMailLog.id, conn); command.ExecuteNonQuery(); Console.WriteLine(alertMailLog.id + " data have been deleted from " + TABLE_NAME + " !"); conn.Close(); return(true); } } conn.Close(); return(false); } catch (Exception ex) { Console.WriteLine("DELETE AlertMailLog [ERROR]"); Console.WriteLine(ex.Message); conn.Close(); return(false); } } }
// Update public int update(string connectionString, AlertMailLog alertMailLog) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { int x = -9; conn.Open(); if (conn.State == System.Data.ConnectionState.Open) { SQLiteCommand command = new SQLiteCommand(@"UPDATE " + TABLE_NAME + " SET " + COLONNE_LOG + " = '" + alertMailLog.log + "' WHERE " + COLONNE_ID + " = " + alertMailLog.id, conn); x = command.ExecuteNonQuery(); Console.WriteLine("ediFileID : " + alertMailLog.id + " is Updated !"); } conn.Close(); return(x); } catch (Exception ex) { Console.WriteLine("\n AlertMailLog Update [ERROR]"); Console.WriteLine(ex.Message); conn.Close(); return(-99); } } }
// Get by ID public AlertMailLog getById(string connectionString, int alertMailLogID, StreamWriter writer) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { AlertMailLog list = null; conn.Open(); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => getById(alertMailLogID: " + alertMailLogID + ") | Creation d'un Instance."); if (conn.State == System.Data.ConnectionState.Open) { using (IDbConnection db = conn) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => getById(alertMailLogID: " + alertMailLogID + ") | SQL => SELECT " + COLONNE_ID + ", " + COLONNE_LOG + " WHERE " + COLONNE_ID + " = " + alertMailLogID); var xxx = conn.Query <AlertMailLog>("SELECT " + COLONNE_ID + ", " + COLONNE_LOG + " FROM " + TABLE_NAME + " WHERE " + COLONNE_ID + " = " + alertMailLogID); if (xxx.ToList() == null || xxx.ToList().Count == 0) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => getById() | Aucun resulta."); writer.Flush(); conn.Close(); return(null); } list = xxx.ToList()[0]; writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => getById() | AlertMailLog obj recu"); } } writer.Flush(); //conn.Close(); return(list); } catch (Exception ex) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => getById() | ##################################################"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => getById() | [ERROR] getById"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => getById() | Message : " + ex.Message); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => getById() | StackTrace : " + ex.StackTrace); writer.WriteLine(""); writer.Flush(); //conn.Close(); return(null); } } }
// Delete by ID public bool deleteById(string connectionString, AlertMailLog alertMailLog, StreamWriter writer) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { conn.Open(); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => deleteById(alertMailLog.id: " + alertMailLog.id + ") | Creation d'une Instance"); if (conn.State == System.Data.ConnectionState.Open) { using (IDbConnection db = conn) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => deleteById() | SQL => DELETE FROM " + TABLE_NAME); SQLiteCommand command = new SQLiteCommand(@"DELETE FROM " + TABLE_NAME + " WHERE " + COLONNE_ID + " = " + alertMailLog.id, conn); command.ExecuteNonQuery(); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => deleteById() | Les donnees de la table " + TABLE_NAME + " sont supprime!"); writer.Flush(); conn.Close(); return(true); } } writer.Flush(); conn.Close(); return(false); } catch (Exception ex) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => deleteById() | ##################################################"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => deleteById() | [ERROR] deleteById (obj)"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => deleteById() | Message : " + ex.Message); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => deleteById() | StackTrace : " + ex.StackTrace); writer.WriteLine(""); writer.Flush(); conn.Close(); return(false); } } }
// Insert public int insert(string connectionString, AlertMailLog alertMailLog, StreamWriter writer) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { int x = -9; conn.Open(); writer.WriteLine(""); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => insert() | Creation d'une instance"); if (conn.State == System.Data.ConnectionState.Open) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => insert() | Creation d'une instance"); SQLiteCommand command = new SQLiteCommand(@"INSERT INTO " + TABLE_NAME + " ('" + COLONNE_ID + "', '" + COLONNE_LOG + "') VALUES(" + alertMailLog.id + ",'" + alertMailLog.log + "')", conn); x = command.ExecuteNonQuery(); //Console.WriteLine("Table created"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => insert() | Creation d'une instance"); } writer.Flush(); conn.Close(); return(x); } catch (Exception ex) { writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => insert() | ##################################################"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => insert() | Reproccess Insert [ERROR]"); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => insert() | Message : " + ex.Message); writer.WriteLine(DateTime.Now + " :: AlertMailLog.dll => insert() | StackTrace : " + ex.StackTrace); writer.WriteLine(""); writer.Flush(); conn.Close(); return(-99); } } }
// Get by ID public AlertMailLog getById(string connectionString, int id) { using (SQLiteConnection conn = new SQLiteConnection(connectionString)) { try { AlertMailLog list = null; conn.Open(); if (conn.State == System.Data.ConnectionState.Open) { using (IDbConnection db = conn) { var xxx = conn.Query <AlertMailLog>("SELECT " + COLONNE_ID + ", " + COLONNE_LOG + " FROM " + TABLE_NAME + " WHERE " + COLONNE_ID + " = " + id); if (xxx.ToList() == null || xxx.ToList().Count == 0) { conn.Close(); return(null); } list = xxx.ToList()[0]; Console.WriteLine("AlertMailLog list size : 1"); } } //conn.Close(); return(list); } catch (Exception ex) { Console.WriteLine("\nGET AlertMailLog [ERROR]"); Console.WriteLine(ex.Message); //conn.Close(); return(null); } } }