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
| private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
SqlConnection maConnexionSQLsrv;
SqlCommand myCommand;
string maRequeteVW;
SqlDataReader myReaderVW;
dtVW = new DataTable();
//Récupération de la chaine de connexion au serveur de base de données
maConnexionSQLsrv = new SqlConnection("server=xxxx;");
maRequeteVW = "SELECT ....
AND PPTimeStamp >= '2010-" + mois + "-01 00:00:00' and PPTimeStamp < '2010-" + moisSuivant + "-01 00:00:00'" ;
//Création de la commande SQL
myCommand = new SqlCommand(maRequeteVW, maConnexionSQLsrv);
try
{
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myReaderVW = myCommand.ExecuteReader();
dataGridView1.DataSource = myReaderVW;
dtVW.Load(myReaderVW);
int OK, AllOK, NbrCollones;
double total = 1;
double[] Pourcentage = new double[10];
NbrCollones = dtVW.Rows.Count;
for (int i = 0; i < NbrCollones; i++)
{
OK = (int)dtVW.Rows[i].ItemArray[1];
AllOK = (int)dtVW.Rows[i].ItemArray[2];
Pourcentage[i] = (double)OK / AllOK;
Pourcentage[i] = Math.Round(Pourcentage[i], 4); // limite le nombre de chiffre aprés la virgule
total = Pourcentage[i] * total;
}
total = Math.Round(total, 4); // limite le nombre de chiffre aprés la virgule
total = total * 100; // pour avoir la valeur en pourcentage
textBox1.Text = total.ToString();
myCommand.Connection.Close();
}
catch (SqlException ex)
{
Console.Write(ex.Message);
}
} |
Partager