public static void writeLogSystem(TdErreur erreur) { using (EventLog eventLog = new EventLog("Application")) { eventLog.Source = "WinBoutique"; eventLog.WriteEntry(string.Format("date: {0}, libelle: {1}, description: {2}", erreur.dateErreur, erreur.Libelle, erreur.Description)); } }
public static bool setErreur(TdErreur erreur) { bdBoutiqueContext db1 = new bdBoutiqueContext(); bool rep = false; try { db1.tdErreurs.Add(erreur); db1.SaveChanges(); rep = true; }catch (Exception ex) { WriteError(erreur); } return(rep); }
public bool updateProduit(Produit produit) { bool rep = false; try { db.Entry(produit).State = EntityState.Modified; db.SaveChanges(); rep = true; } catch (Exception ex) { TdErreur erreur = new TdErreur(); erreur.Libelle = "Modification de produit"; erreur.Description = ex.ToString(); //setErreur(erreur); WriteError(erreur); } return(rep); }
public bool deleteProduit(int id) { bool rep = false; try { Produit produit = db.produits.Find(id); db.produits.Remove(produit); db.SaveChanges(); rep = true; } catch (Exception ex) { TdErreur erreur = new TdErreur(); erreur.Libelle = "Suppression de produit"; erreur.Description = ex.ToString(); //setErreur(erreur); WriteError(erreur); } return(rep); }
public bool addProduit(Produit produit) { bool rep = false; try { db.produits.Add(produit); db.SaveChanges(); rep = true; } catch (Exception ex) { TdErreur erreur = new TdErreur(); erreur.Libelle = "Ajout de produit"; erreur.Description = ex.ToString(); //setErreur(erreur); //WriteError(erreur); writeLogSystem(erreur); } return(rep); }
public static void WriteError(TdErreur erreur) { try { string path = System.Web.HttpContext.Current.Server.MapPath("~/Error/fileError.txt"); System.IO.TextWriter writeFile = new StreamWriter(path, true); writeFile.WriteLine("" + erreur.dateErreur); writeFile.WriteLine("---------------------------------------------------------------------------------------"); writeFile.WriteLine(erreur.Libelle); writeFile.WriteLine("---------------------------------------------------------------------------------------"); writeFile.WriteLine(erreur.Description); writeFile.WriteLine("---------------------------------------------------------------------------------------"); writeFile.Flush(); writeFile.Close(); writeFile = null; } catch (IOException e) { // WriteError(e.ToString()); writeLogSystem(erreur); } }