//Get la liste des etats de ristourne public List <TypeRistourne> GetListeTypeRistourne() { using (SqlConnection Conn = new SqlConnection(ClassVariableGlobal.SetConnexion())) try { Conn.Open(); List <TypeRistourne> _listeEtatRistourne = new List <TypeRistourne>(); if (Conn.State != System.Data.ConnectionState.Open) { Conn.Open(); } //string s = "SELECT nom AS [@nom], postnom AS [@postnom], matricule AS [@matricule]," + // " dateAbonnement AS [@dateAbonnement], nombreAmpere AS [@nombreAmpere]"+ // " FROM enregistrement"; string s = "SELECT * FROM tTypeRistourne"; //SELECT * FROM tClasse SqlCommand objCommand = new SqlCommand(s, Conn); SqlDataReader _Reader = objCommand.ExecuteReader(); while (_Reader.Read()) { TypeRistourne objCust = new TypeRistourne(); objCust.IdTypeRistourne = Convert.ToInt32(_Reader["IdTypeRistourne"]); objCust.DesignationTypeRistourne = _Reader["DesignationTypeRistourne"].ToString(); objCust.EtatRistourne = _Reader["EtatRistourne"].ToString(); _listeEtatRistourne.Add(objCust); } return(_listeEtatRistourne); } catch { throw; } finally { if (Conn != null) { if (Conn.State == ConnectionState.Open) { Conn.Close(); Conn.Dispose(); } } } }
// Enregistrement du type de ristourne public int InsertTypeRistourne(TypeRistourne typeRistourne) { using (SqlConnection connection = new SqlConnection(ClassVariableGlobal.SetConnexion())) { connection.Open(); string query = "INSERT INTO tTypeRistourne" + " (DesignationTypeRistourne, EtatRistourne)" + " VALUES(@DesignationTypeRistourne, @EtatRistourne)"; SqlCommand commande = new SqlCommand(query, connection); commande.Parameters.AddWithValue("@DesignationTypeRistourne", typeRistourne.DesignationTypeRistourne); commande.Parameters.AddWithValue("@EtatRistourne", typeRistourne.EtatRistourne); return(commande.ExecuteNonQuery()); } }