J'appelle ma fonction depuis une autre de recherche qui est la suivante:
#region RECHECHER
private void Rechercher()
{
//on remet le DtSet a 0
DtSet.Clear();
if (this.txtCodeClasse.Text == "")
{
MessageBox.Show("Veuillez Choisir\nla Classe\ndans la liste déroulante svp \nA T T E N T I O N", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.cboClasse.Text = "---Select---";
this.cboClasse.Focus();
this.cboClasse.SelectAll();
}
else
{
if (this.txtCodeAnneeScolaire.Text == "")
{
MessageBox.Show("Veuillez Choisir\nl'Année Scolaire\ndans la liste déroulante svp\nA T T E N T I O N", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.cboAnneeScolaire.Text = "---Select---";
this.cboAnneeScolaire.Focus();
this.cboAnneeScolaire.SelectAll();
}
else
{
if (this.txtCodeTrimestre.Text == "")
{
MessageBox.Show("Veuillez Choisir \nle Trimestre\ndans la liste déroulante svp \nA T T E N T I O N", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.cboTrimestre.Text = "---Select---";
this.cboTrimestre.Focus();
this.cboTrimestre.SelectAll();
}
else
{
//On importe la fonction qui contient une partie de notre requete SQL
Critere_Recherche();
string sRechercherSQL = "SELECT Eleves.code_personnel AS code_eleve, Eleves.nom_personnel AS nom_eleve," + "\n" +
"Eleves.prenom_personnel AS prenom_eleve, Matieres.matiere, Classes.classe, Annees_Scolaires.annee," + "\n" +
"Enseignants.code_personnel as code_enseignant, Enseignants.nom_personnel as nom_enseignant, Civilites.mne_civilite," + "\n" +
"Count(*(Notations.note_obtenue)) AS nombre, Sum(Notations.note_obtenue) AS total," + "\n" +
"((Sum(Notations.note_obtenue))/(Count(*(Notations.note_obtenue)))) AS moyenne, Notations.coefficient," + "\n" +
"(((Sum(Notations.note_obtenue))/(Count(*(Notations.note_obtenue))))*(Notations.coefficient)) AS moyenne2, Trimestres.trimestre" + "\n" +
"FROM Classes, Annees_Scolaires, Matieres, Trimestres, Notations, Personnels AS Eleves, Personnels as Enseignants, Civilites" + "\n" +
"WHERE Classes.code_classe=Notations.code_classe AND Annees_Scolaires.code_annee=Notations.code_annee" + "\n" +
"AND Matieres.code_matiere=Notations.code_matiere AND Trimestres.code_trimestre=Notations.code_trimestre" + "\n" +
"AND Eleves.code_personnel=Notations.code_eleve AND Notations.code_enseignant=Enseignants.code_personnel and Civilites.code_civilite=Enseignants.code_civilite" + "\n" +
"AND Classes.classe '" + cboClasse.Text + "' AND Trimestres.trimestre '" + cboTrimestre.Text + "'" + "\n" +
"AND Annees_Scolaires.annee = '" + cboAnneeScolaire.Text + "'AND" + "\n" +
"((" + sLookup + ")= '" + txtRecherche.Text.Replace("'", "''") + "')" + "\n" +
"GROUP BY Eleves.code_personnel, Eleves.nom_personnel, Eleves.prenom_personnel, Matieres.matiere, Classes.classe," + "\n" +
"Annees_Scolaires.annee, Enseignants.code_personnel, Notations.coefficient, Trimestres.trimestre, Trimestres.trimestre, Enseignants.nom_personnel, Civilites.mne_civilite" + "\n" +
"ORDER BY Matieres.matiere, ((Sum(Notations.note_obtenue))/(Count(*(Notations.note_obtenue)))) DESC, Annees_Scolaires.annee DESC , Trimestres.trimestre DESC";
OleDbDataAdapter AdaptSearch = new OleDbDataAdapter(sRechercherSQL, strConex);
gbxRecherche.Text cboCritere.Text + " " + txtRecherche.Text;
//un ptit try catch pour les requete sans resultat
try
{
AdaptSearch.Fill(DtSet, "Notations");
// On definit le nombre de prospect correspondant a la recherche
iMax = DtSet.Tables[0].Rows.Count;
if (iMax == 0)
{
MessageBox.Show("Aucun Elève trouvé\nPour ce critère de Recherche", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
#region IMPRESSION BULLETIN INDIVIDUEL
if (this.cboCritere.Text != "Matricule")
{
this.iTotal = DtSet.Tables[0].Rows.Count;
if ((iTotal 0) || (iTotal 1))
{
this.lblTotal.Text = "Résultat pour ce Critère : " + iTotal.ToString();
}
else if (iTotal > 1)
{
this.lblTotal.Text = "Résultats pour ce Critère : " + iTotal.ToString();
}
// i est le premier element pour l'affichage
i = 1;
//On affiche le label
Label_Effectif();
Afficher();
this.lblPosition.Visible = true;
this.lblTotal.Visible = true;
this.btnPrecedent.Enabled = true;
this.btnSuivant.Enabled = true;
this.btnPremier.Enabled = true;
this.btnDernier.Enabled = true;
this.txtMotDePasse.Visible = false;
}
else if (this.cboCritere.Text == "Matricule")
{
this.iTotal = DtSet.Tables[0].Rows.Count;
this.lblTotal.Text = "Résultats pour ce Critère : " + iTotal.ToString();
// i est le premier element pour l'affichage
i = 1;
//On affiche le label
Label_Effectif();
Afficher();
Prof_Principal();
Effectif_Classe();
Educateur_Classe();
Redoublant_Classe();
Statistiques();
Justifiee();
this.lblPosition.Visible = true;
this.lblTotal.Visible = true;
this.btnPrecedent.Enabled = true;
this.btnSuivant.Enabled = true;
this.btnPremier.Enabled = true;
this.btnDernier.Enabled = true;
this.txtMotDePasse.Visible = false;
this.btnImprimer.Visible = true;
this.btnImprimer.BackColor = Color.Navy;
this.toolTip1.SetToolTip(this.btnImprimer, "Imprimer un Bulletin");
this.txtPrincipal.Visible = true;
this.txtPrincipal.BackColor = Color.Chartreuse;
this.txtPrincipal.ForeColor = Color.Red;
this.AcceptButton = this.btnImprimer;
}
#endregion
#region IMPRESSION FICHE PROFESSEUR PRINCIPAL
if (this.cboCritere.Text != "Classe")
{
this.iTotal = DtSet.Tables[0].Rows.Count;
if ((iTotal 0) || (iTotal 1))
{
this.lblTotal.Text = "Résultat pour ce Critère : " + iTotal.ToString();
}
else if (iTotal > 1)
{
this.lblTotal.Text = "Résultats pour ce Critère : " + iTotal.ToString();
}
// i est le premier element pour l'affichage
i = 1;
//On affiche le label
Label_Effectif();
Afficher();
this.lblPosition.Visible = true;
this.lblTotal.Visible = true;
this.btnPrecedent.Enabled = true;
this.btnSuivant.Enabled = true;
this.btnPremier.Enabled = true;
this.btnDernier.Enabled = true;
this.txtMotDePasse.Visible = false;
}
else if (this.cboCritere.Text == "Classe")
{
this.iTotal = DtSet.Tables[0].Rows.Count;
this.lblTotal.Text = "Résultats pour ce Critère : " + iTotal.ToString();
// i est le premier element pour l'affichage
i = 1;
//On affiche le label
Label_Effectif();
Afficher();
Prof_Principal();
Effectif_Classe();
Fiche_pp();
this.lblPosition.Visible = true;
this.lblTotal.Visible = true;
this.btnPrecedent.Enabled = true;
this.btnSuivant.Enabled = true;
this.btnPremier.Enabled = true;
this.btnDernier.Enabled = true;
this.txtMotDePasse.Visible = false;
this.btnImprimer.Visible = true;
this.btnImprimer.BackColor = Color.Green;
this.toolTip1.SetToolTip(this.btnImprimer, "Imprimer Fiche Professeur Principal");
this.txtPrincipal.Visible = true;
this.txtPrincipal.BackColor = Color.Chartreuse;
this.txtPrincipal.ForeColor = Color.Red;
this.AcceptButton = this.btnImprimer;
//StyledgvNotes();
}
#endregion
this.dgvEleves.Visible = true;
this.dgvNotes.Visible = false;
this.dgvEleves.Dock = System.Windows.Forms.DockStyle.Bottom;
//on affiche la liste dans le datagridview
this.dgvEleves.DataSource = this.DttGrid;
this.Conex.Close();
}
}
catch (FileNotFoundException ex)
{
MessageBox.Show(ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
iMax = 0;
i = 0;
Label_Effectif();
}
}
}
}
}
#endregion