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
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace pfffff
{
class WACCS: List<WACC>
{
SqlConnection mySqlConnection = new SqlConnection("Data Source = .\\SQLEXPRESS; Initial Catalog=AxisBase; Trusted_Connection=Yes");
SqlCommand mySqlCommand = new SqlCommand();
// le datasource doit être un tableau ou une liste ou un autre "ienumerable"
public List<WACC> FillWACCS()
{
decimal[] TauxImpot = Select("Tauximpot", "DO", null);
decimal[] FondsPropre = Select("FondsPropres", "DO", null);
decimal[] VEs = new decimal [5];
var s = new WACCS();
for (int i = 0; i < 5; i++)
{ s.Add(new WACC(i,TauxImpot,FondsPropre,VEs));
}
return s;
}
public decimal[] Select(string commande, string table, string where)
{
try
{
mySqlCommand = mySqlConnection.CreateCommand();
if (where == null)
mySqlCommand.CommandText = "SELECT " + commande + " FROM " + table;
else
mySqlCommand.CommandText = "SELECT " + commande + " FROM " + table + " WHERE " + where;
mySqlConnection.Open();
SqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader(); //je lance la commande
var liste = new List<decimal>();
while (mySqlDataReader.Read())
{
liste.Add(mySqlDataReader.GetValue(0).GetHashCode());
}
mySqlConnection.Close();
mySqlDataReader.Close();
return liste.ToArray();
}
catch (Exception eSelect)
{
throw new Exception("Select exception : " + eSelect.Message);
}
}
}
class WACC
{ // définit les variables d'un élément de la liste (qui donneront les colonnes du DataGridView)
decimal[] VE { get; set; }
decimal[] Tauximpot { get; set; }
decimal[] FondsPropres { get; set; }
public WACC(int i, decimal[] Tauximpot, decimal[] FondsPropres, decimal[] VE)
{
this.Tauximpot = Tauximpot;
this.VE = VE;
this.FondsPropres = FondsPropres;
VE[i] = Tauximpot[i] + FondsPropres[i];
//this.VE = VE;
}
}
} |
Partager