danny243
Messages postés74Date d'inscriptionvendredi 19 mars 2021StatutMembreDernière intervention16 octobre 2021
-
12 mai 2021 à 11:04
Utilisateur anonyme -
13 mai 2021 à 07:30
Bonjour, actuellement j'ai une base des données qui contient 3 tables et dans mes tables j'ai plusieurs dont le champ année et dans mon application Csharp je manipule cette table .
donc j'aimerai recuperer toutes les années dans mon champ année mais sans doublons et les mettre dans combobox j'essaie de faire de quoi mais je suis bloqué parce que j'avais un biding sauf qu'il m'affiche toutes les années de ma table moi je veux juste les années uniques pouvez vous m'aider
voici mon code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using BLL;
namespace UIL
{
/// <summary>
/// Logique d'interaction pour UCSommeVentesProv.xaml
/// </summary>
///
/// <summary>
/// Nom:Daniel Kabeya
/// Matricule:1812147
/// </summary>
public partial class UCSommeVentesProv : UserControl
{
List<int> listeAnnee = new List<int>();
public UCSommeVentesProv()
{
InitializeComponent();
//cboAnneeDeb.ItemsSource = Vente.vente;
}
private void cboAnneeDeb_Loaded(object sender, RoutedEventArgs e)
{
foreach (Vente v in Vente.vente)
{
}
cboAnneeDeb.ItemsSource = Vente.vente;
}
private void cboAnneeDeb_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Data;
using MySql.Data.MySqlClient;
using DAL;
namespace BLL
{
/// <summary>
/// Nom:Daniel Kabeya
/// Matricule:1812147
/// </summary>
public class Vente: INotifyPropertyChanged
{
public static ObservableCollection<Vente> vente = new ObservableCollection<Vente>();
/* public Vente(string province,string genre,int annee,double nbunites, double montantx1000)
{
this.province = province;
this.genre = genre;
this.annee = annee;
this.nbunites = nbunites;
this.montantx1000 = montantx1000;
}*/
/// <summary>
/// Methode qui est de type "void" qui me permet de récuperer les valeurs de chaque lignes de ma table et ensuite les affecter à mes propriétés à la
/// fin j'ajoute cela à ma liste
/// </summary>
public static void ChargerListeVente()
{
//Création de la collection observable
var listeVente = new ObservableCollection<Vente>();
//Appel de la fonction dans AccessDB pour la connection à la DB
DataTable dt = AccessDB.ConnecterBDVente();
for (int i = 0; i < dt.Rows.Count; i++)
{
var ven = new Vente
{
//Création d'un nouvel objet de type province
LaProvince = new Province(dt.Rows[i]["Province"].ToString()),
//Création d'un nouvel objet de type vehicule
LesGenres = new Vehicule(dt.Rows[i]["Genre"].ToString()),
Annee = Int32.Parse(dt.Rows[i]["Annee"].ToString()),
NbUnites = Int32.Parse(dt.Rows[i]["NbUnites"].ToString()),
Montantx1000 = Int32.Parse(dt.Rows[i]["Montantx1000"].ToString()),
};
listeVente.Add(ven);
}
vente = listeVente;
}
/* private string province;
public string Province
{
get
{
return province;
}
set
{
if (this.province != value)
{
this.province = value;
this.NotifyPropertyChanged("Province");
}
}
}*/
/// <summary>
/// je crée un attribut de type Province et je crée une propriété avec , qui est aussi de type Province
/// </summary>
private Province laProvince;
public Province LaProvince
{
get
{
return laProvince;
}
set
{
if (this.laProvince != value)
{
this.laProvince = value;
this.NotifyPropertyChanged("LaProvince");
}
}
}
/// <summary>
/// je crée un attribut de type Vehicule et je crée une propriété avec, qui est aussi de type Vehicule
/// </summary>
private Vehicule lesGenres;
public Vehicule LesGenres
{
get
{
return lesGenres;
}
set
{
if (this.lesGenres != value)
{
this.lesGenres = value;
this.NotifyPropertyChanged("LesGenres");
}
}
}
private int anneeUnique;
public int AnneeUnique
{
get
{
return anneeUnique;
}
set
{
if (this.anneeUnique != value)
{
this.anneeUnique = value;
this.NotifyPropertyChanged("AnneeUnique");
}
}
}
/// <summary>
/// je crée un attribut de type string et je crée une propriété avec, qui est aussi de type string
/// </summary>
private string genre;
public string Genre
{
get
{
return genre;
}
set
{
if (this.genre != value)
{
this.genre = value;
this.NotifyPropertyChanged("Genre");
}
}
}
/// <summary>
/// je crée un attribut de type int et je crée une propriété avec, qui est aussi de type int
/// </summary>
private int annee;
public int Annee
{
get
{
return annee;
}
set
{
if (this.annee != value)
{
this.annee = value;
this.NotifyPropertyChanged("Annee");
}
}
}
/// <summary>
/// je crée un attribut de type int et je crée une propriété avec, qui est aussi de type int
/// </summary>
private int nbunites;
public int NbUnites
{
get
{
return nbunites;
}
set
{
if (this.nbunites != value)
{
this.nbunites = value;
this.NotifyPropertyChanged("NbUnites");
}
}
}
/// <summary>
/// je crée un attribut de type int et je crée une propriété avec, qui est aussi de type int
/// </summary>
private int montantx1000;
public int Montantx1000
{
get
{
return montantx1000;
}
set
{
if (this.montantx1000 != value)
{
this.montantx1000 = value;
this.NotifyPropertyChanged("Montantx1000");
}
}
}
public void NotifyPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
12 mai 2021 à 20:34