Vous êtes sur la page 1sur 3

1) Déclaration dans la classe Program de la collection d’employés:

public static List<Employe> col = new List<Employe>();


2) La procédure événementielle de chargement du formulaire:

private void Form1_Load(object sender, EventArgs e)


{
txt_salaire.Text = "0";
txt_categorie.Text = "0";
txt_mtle.Enabled = false;
list_employes.BorderStyle = BorderStyle.FixedSingle;
list_employes.View = View.Details;
list_employes.Columns.Add("Matricule");
list_employes.Columns.Add("Nom");
list_employes.Columns.Add("Date naissance");
list_employes.Columns.Add("Date Embauche");
list_employes.Columns.Add("Age à la retraite");
list_employes.Columns.Add("Salaire à payer");
}
3) La procédure événementielle des boutons radios rb_agent et rb_formateur :

private void rb_agent_CheckedChanged(object sender, EventArgs e)


{
if (rb_agent.Checked)
lbl_categorie.Text = "Prime:";
else
lbl_categorie.Text = "Heure sup:";
}

private void rb_formateur_CheckedChanged(object sender, EventArgs e)


{
rb_agent_CheckedChanged(sender, e);
}
4) La procédure événementielle du bouton btn_ajouter

private void btn_ajouter_Click(object sender, EventArgs e)


{
try
{
if (!Vides())
{
double salaire = double.Parse(txt_salaire.Text);
if (salaire >= 0)
{
if (rb_agent.Checked)
{
Program.col.Add(new
Agent(txt_nom.Text,dp_dNaissance.Value,dp_Embauche.Value,salaire,double.Parse(txt_c
ategorie.Text)));

}
else
{
Program.col.Add(new Formateur(txt_nom.Text,
dp_dNaissance.Value, dp_Embauche.Value, salaire, int.Parse(txt_categorie.Text)));

}
Employe ag=Program.col[Program.col.Count-1];
string[] detail = { ag.Matricule.ToString(), ag.Nom,
ag.DateNaissance.ToString("dd/MM/yyyy"), ag.DateEmbauche.ToString("dd/MM/yyyy"),
ag.DateRetraite(60).ToString("dd/MM/yyyy"), ag.SalaireAPayer().ToString() };
list_employes.Items.Add(new ListViewItem(detail));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public bool Vides()
{
return (txt_nom.Text == "") || (txt_salaire.Text == "") ||
(txt_categorie.Text == "");
}
5) La procédure événementielle du bouton btn_supprimer

private void btn_supprimer_Click(object sender, EventArgs e)


{
try
{
if (MessageBox.Show("Vous voulez supprimer cet employé?",
"Confirmer suppression:", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
int index = list_employes.SelectedIndices[0];
Program.col.RemoveAt(index);
list_employes.Items.RemoveAt(index);
}
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}
}
6) La procédure événementielle du bouton btn_exporter

private void btn_exporter_Click(object sender, EventArgs e)


{
try
{
FileStream f = new FileStream("Liste_employes.bin",
FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(f, Program.col);
f.Close();
MessageBox.Show("Enregistrement effectué avec succès!");
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}
}
7) La procédure événementielle associée au changement de ligne de list_employes

private void list_employes_SelectedIndexChanged(object sender, EventArgs e)


{
try
{
int index = list_employes.SelectedIndices[0];
if (Program.col[index] is Agent)
{
rb_agent.Checked = true;
Agent ag = (Agent)Program.col[index];
txt_mtle.Text = ag.Matricule.ToString();
txt_nom.Text = ag.Nom;
dp_dNaissance.Value = ag.DateNaissance;
dp_Embauche.Value = ag.DateEmbauche;
txt_salaire.Text = ag.SalaireBase.ToString();
txt_categorie.Text = ag.PrimeResponsabilite.ToString();
}
else
{
rb_formateur.Checked = true;
Formateur ag = (Formateur)Program.col[index];
txt_mtle.Text = ag.Matricule.ToString();
txt_nom.Text = ag.Nom;
dp_dNaissance.Value = ag.DateNaissance;
dp_Embauche.Value = ag.DateEmbauche;
txt_salaire.Text = ag.SalaireBase.ToString();
txt_categorie.Text = ag.HeureSup.ToString();
}
}
catch (ArgumentOutOfRangeException ex)
{
}
catch (Exception ex)
{

MessageBox.Show(ex.Message);
}
}
//Source : www.exelib.net

Vous aimerez peut-être aussi