/// <summary> /// Retrieve the Categorie by its num /// </summary> /// <param name="numCategorie"></param> /// <returns>Categorie</returns> public static Categorie Get(int numCategorie) { Categorie categorie = new Categorie(); using (SqlConnection db = DbConnexion.connect()) { string sql = "SELECT NumCategorie, LibelleCategorie, NumFamille FROM Categorie c WHERE c.NumCategorie = @NumCategorie"; using (SqlCommand req = new SqlCommand(sql, db)) { req.Parameters.Add(new SqlParameter("NumCategorie", numCategorie)); SqlDataReader row = req.ExecuteReader(); if (row.Read()) { categorie.Num = int.Parse(row.GetValue(0).ToString()); categorie.Libelle = row.GetValue(1).ToString(); categorie.Famille = FamilleDAO.Get(int.Parse(row.GetValue(2).ToString())); } } } return categorie; }
/// <summary> /// Retrieve all Categories of the Famille /// </summary> /// <param name="famille"></param> /// <returns>List of Categorie</returns> public static List<Categorie> GetByFamille(Famille famille) { List<Categorie> listTickets = new List<Categorie>(); using (SqlConnection db = DbConnexion.connect()) { string sql = "SELECT NumCategorie, LibelleCategorie, NumFamille FROM Categorie c WHERE c.NumFamille = @NumFamille"; using (SqlCommand req = new SqlCommand(sql, db)) { req.Parameters.Add(new SqlParameter("NumFamille", famille.Num)); SqlDataReader row = req.ExecuteReader(); while (row.Read()) { Categorie categorie = new Categorie(); categorie.Num = int.Parse(row.GetValue(0).ToString()); categorie.Libelle = row.GetValue(1).ToString(); categorie.Famille = famille; listTickets.Add(categorie); } } } return listTickets; }
/// <summary> /// Retrieve all the SousCategorie of the Categorie /// </summary> /// <param name="categorie"></param> /// <returns>List of SousCategorie</returns> public static List<SousCategorie> GetByCategorie(Categorie categorie) { List<SousCategorie> listSousCategories = new List<SousCategorie>(); using(SqlConnection db = DbConnexion.connect()) { string sql = "SELECT NumSousCategorie, LibelleSousCategorie, NumCategorie FROM SousCategorie sc WHERE sc.NumCategorie = @NumCategorie"; using (SqlCommand req = new SqlCommand(sql, db)) { req.Parameters.Add(new SqlParameter("NumCategorie", categorie.Num)); SqlDataReader row = req.ExecuteReader(); while (row.Read()) { SousCategorie sousCategorie = new SousCategorie(); sousCategorie.Num = int.Parse(row.GetValue(0).ToString()); sousCategorie.Libelle = row.GetValue(1).ToString(); sousCategorie.Categorie = categorie; listSousCategories.Add(sousCategorie); } } } return listSousCategories; }
public void SelectFamilleAction() { if (_view.SelectedFamille.Num > 0) { // Initialize the Categorie ComboBox depending on the Family selected List<Categorie> listCategories = CategorieDAO.GetByFamille(_view.SelectedFamille); Categorie blankRow = new Categorie(); blankRow.Libelle = ""; listCategories.Insert(0, blankRow); // Categorie ComboBox Data Source _view.Categories = listCategories; } else { // Remove the Categorie Data Source if none Famille is selected _view.Categories = null; } search(); }