1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private List<customer> clients = null;
private customer clientEnCours = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
clients = new List<customer>();
clients.Add(new customer(1,"Pascal"));
clients.Add(new customer(2,"Claude"));
clients.Add(new customer(3,"Michel"));
clients.Add(new customer(4,"Frédérique"));
clientEnCours = clients.First();
labelId.Text = clientEnCours.Id.ToString();
labelNom.Text = clientEnCours.Nom;
buttonPrecedent.Enabled = false;
}
private void buttonPrecedent_Click(object sender, EventArgs e)
{
var resultat = clients.Where(c => c.Id == clientEnCours.Id - 1).Select(c => c);
if (resultat.Count() != 0)
{
clientEnCours = resultat.First();
buttonSuivant.Enabled = true;
labelId.Text = clientEnCours.Id.ToString();
labelNom.Text = clientEnCours.Nom;
}
else
{
buttonPrecedent.Enabled = false;
}
}
private void buttonSuivant_Click(object sender, EventArgs e)
{
var resultat = clients.Where(c => c.Id == clientEnCours.Id + 1).Select(c => c);
if (resultat.Count() !=0)
{
clientEnCours = resultat.First();
buttonPrecedent.Enabled = true;
labelId.Text = clientEnCours.Id.ToString();
labelNom.Text = clientEnCours.Nom;
}
else
{
buttonSuivant.Enabled = false;
}
}
}
public class customer
{
private int _id;
private string _nom;
public int Id
{
get { return _id; }
set { _id = value; }
}
public string Nom
{
get { return _nom; }
set { _nom = value; }
}
public customer(int id, string nom)
{
Id = id;
Nom = nom;
}
}
} |
Partager