public static List <AutorisationRessource> listAutorisationRessource(string query) { NpgsqlConnection con = Connexion.Connection(); try { NpgsqlCommand Lcmd = new NpgsqlCommand(query, con); NpgsqlDataReader lect = Lcmd.ExecuteReader(); List <AutorisationRessource> l = new List <AutorisationRessource>(); if (lect.HasRows) { while (lect.Read()) { AutorisationRessource y = oneAutorisationRessource((Int32)((lect["id"] != null) ? (!lect["id"].ToString().Trim().Equals("") ? lect["id"] : 0) : 0)); l.Add(y); } } return(l); } catch (NpgsqlException e) { Messages.Exception(e); return(null); } finally { Connexion.Deconnection(con); } }
private void dgv_ress_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { if (dgv_ress.Rows.Count > 0) { if (dgv_ress.CurrentRow.Cells["id_ress_"].Value != null) { Int32 id = (Int32)dgv_ress.CurrentRow.Cells["id_ress_"].Value; if (id > 0) { Ressources r = new Ressources(id); bool b = (bool)dgv_ress.CurrentRow.Cells[e.ColumnIndex].Value; AutorisationRessource a = AutorisationRessourceBLL.One(AutorisationRessourceBLL.Current(new AutorisationRessource(current, r, b))); if (a != null ? a.Id > 0 : false) { AutorisationRessourceBLL.Update(new AutorisationRessource(a.Id, current, r, b)); } else { AutorisationRessourceBLL.Save(new AutorisationRessource(current, r, b)); } } } } } catch (Exception ex) { Messages.Exception(ex); } }
public static AutorisationRessource oneAutorisationRessource(Int32 id) { NpgsqlConnection con = Connexion.Connection(); try { String search = "select * from autorisation_ressource where id = " + id; NpgsqlCommand Lcmd = new NpgsqlCommand(search, con); NpgsqlDataReader lect = Lcmd.ExecuteReader(); AutorisationRessource y = new AutorisationRessource(); if (lect.HasRows) { while (lect.Read()) { y.Id = id; y.Niveau = BLL.NiveauAccesBLL.One((Int32)((lect["niveau"] != null) ? (!lect["niveau"].ToString().Trim().Equals("") ? lect["niveau"] : 0) : 0)); y.Ressource = BLL.RessourcesBLL.One((Int32)((lect["ressource"] != null) ? (!lect["ressource"].ToString().Trim().Equals("") ? lect["ressource"] : 0) : 0)); y.Update = (Boolean)((lect["acces"] != null) ? (!lect["acces"].ToString().Trim().Equals("") ? lect["acces"] : false) : false); } } return(y); } catch (NpgsqlException e) { Messages.Exception(e); return(null); } finally { Connexion.Deconnection(con); } }
public static Int32 currentAutorisationRessource(AutorisationRessource f) { NpgsqlConnection con = Connexion.Connection(); try { String search = "select * from autorisation_ressource where niveau = " + f.Niveau.Id + " and ressource = " + f.Ressource.Id + ""; NpgsqlCommand Lcmd = new NpgsqlCommand(search, con); NpgsqlDataReader lect = Lcmd.ExecuteReader(); Int32 id = new Int32(); if (lect.HasRows) { while (lect.Read()) { id = (Int32)((lect["id"] != null) ? (!lect["id"].ToString().Trim().Equals("") ? lect["id"] : 0) : 0); } } return(id); } catch (NpgsqlException e) { Messages.Exception(e); return(0); } finally { Connexion.Deconnection(con); } }
public static bool Delete(AutorisationRessource y) { try { return(AutorisationRessourceDAO.deleteAutorisationRessource(y)); } catch (Exception ex) { throw new Exception("Suppression Impossible", ex); } }
public static bool Update(AutorisationRessource y) { try { return(AutorisationRessourceDAO.updateAutorisationRessource(y)); } catch (Exception ex) { throw new Exception("Modification Impossible", ex); } }
public static AutorisationRessource Save(AutorisationRessource y) { try { return(AutorisationRessourceDAO.saveAutorisationRessource(y)); } catch (Exception ex) { throw new Exception("Insertion Impossible", ex); } }
public static Int32 Current(AutorisationRessource y) { try { return(AutorisationRessourceDAO.currentAutorisationRessource(y)); } catch (Exception ex) { throw new Exception("Retour Impossible", ex); } }
private NiveauAcces SuperNiveau() { NiveauAcces n = new NiveauAcces(); string query = "select * from niveau_acces where super = true limit 1"; List <NiveauAcces> l = NiveauAccesBLL.List(query); if (l != null ? l.Count > 0 : false) { n = l[0]; } else { n.Super = true; n.Description = "Super Administrateur"; n.Designation = "Super Administrateur"; n = NiveauAccesBLL.Save(n); } query = "select * from formulaires"; List <Formulaires> lf = FormulairesBLL.List(query); foreach (Formulaires f in lf) { AutorisationFormulaire a = AutorisationFormulaireBLL.One(AutorisationFormulaireBLL.Current(new AutorisationFormulaire(n, f, true))); if (a != null ? a.Id < 1 : true) { AutorisationFormulaireBLL.Save(new AutorisationFormulaire(n, f, true)); } } query = "select * from ressources"; List <Ressources> lr = RessourcesBLL.List(query); foreach (Ressources r in lr) { AutorisationRessource a = AutorisationRessourceBLL.One(AutorisationRessourceBLL.Current(new AutorisationRessource(n, r, true))); if (a != null ? a.Id < 1 : true) { AutorisationRessourceBLL.Save(new AutorisationRessource(n, r, true)); } } return(n); }
public static bool deleteAutorisationRessource(AutorisationRessource f) { NpgsqlConnection con = Connexion.Connection(); try { string delete = "delete from autorisation_ressource where id = " + f.Id; NpgsqlCommand cmd = new NpgsqlCommand(delete, con); cmd.ExecuteNonQuery(); return(true); } catch (NpgsqlException e) { Messages.Exception(e); return(false); } finally { Connexion.Deconnection(con); } }
public static bool updateAutorisationRessource(AutorisationRessource f) { NpgsqlConnection con = Connexion.Connection(); try { string update = "update autorisation_ressource set acces ='" + f.Update + "' where id = " + f.Id; NpgsqlCommand cmd = new NpgsqlCommand(update, con); cmd.ExecuteNonQuery(); return(true); } catch (NpgsqlException e) { Messages.Exception(e); return(false); } finally { Connexion.Deconnection(con); } }
public static AutorisationRessource saveAutorisationRessource(AutorisationRessource f) { NpgsqlConnection con = Connexion.Connection(); try { string insert = "insert into autorisation_ressource (niveau, ressource, acces) values (" + f.Niveau.Id + "," + f.Ressource.Id + ",'" + f.Update + "')"; NpgsqlCommand cmd = new NpgsqlCommand(insert, con); cmd.ExecuteNonQuery(); f.Id = currentAutorisationRessource(f); return(f); } catch (NpgsqlException e) { Messages.Exception(e); return(null); } finally { Connexion.Deconnection(con); } }