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
|
/// <summary>
/// Une instance de cette classe représente un compte
/// </summary>
public class Account
{
public int Account_ID { get; set; }
public String Account_Name { get; set; }
public int Account_Number { get; set; }
public int Account_Access { get; set; }
public Account(int account_id, String account_name, int account_number, int account_access)
{
this.Account_ID = account_id;
this.Account_Name = account_name;
this.Account_Number = account_number;
this.Account_Access = account_access;
}
}
public class BaseDeDonnees
{
public bool Open()
{
//TODO connexion
return true;
}
public void Close()
{
//TODO fermture
}
public IEnumerable<Account> GetAccounts()
{
List<Account> accounts = new List<Account>();//liste des comptes
//reader.Execute etc...
while (reader.Read())
{
String pseudo = Convert.ToString(reader.GetValue(1));
var account = new Account//un compte
(
Convert.ToInt32(reader.GetValue(0)),
Convert.ToString(reader.GetValue(1)),
Convert.ToInt32(reader.GetValue(2)),
Convert.ToInt32(reader.GetValue(4))
);
accounts.Add(account);//ajout dans la liste
}
Console.WriteLine(string.Format("{0} accounts in the list", accounts.Count));
return accounts;
}
}
//ton formulaire
public class Gui : Form
{
BaseDeDonnees db = new BaseDeDonnees();
public Gui()
{
if(!db.Open())
{
MessageBox.Show("Fail to open database", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button1_Click(object sender, EventArgs e)
{
var accounts = db.GetAccounts();
MessageBox.Show(string.Format("{0} accounts in the list", accounts.Count()), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
} |
Partager