Beispiel #1
0
 private void button5_Click(object sender, EventArgs e)
 {
     dataGridView1.AllowUserToAddRows = false;
     if (dataGridView1.Columns.Count != 0)
     {
         for (int i = 0; i < dataGridView1.Columns.Count; i++)
         {
             if (dataGridView1.Columns[i].Name == comboBox1.Text)
             {
                 double[] columnData = (from DataGridViewRow row in dataGridView1.Rows
                                        where row.Cells[i].FormattedValue.ToString() != string.Empty
                                        select Convert.ToDouble(row.Cells[i].FormattedValue)).ToArray();
                 string average            = columnData.Average().ToString();
                 string min                = columnData.Min().ToString();
                 string max                = columnData.Max().ToString();
                 double sum                = Convert.ToDouble(columnData.Sum(d => Math.Pow((d - Convert.ToDouble(average)), 2)));
                 string standard_Deviation = Convert.ToString(Math.Sqrt((sum) / (columnData.Count() - 1)));
                 string range              = Convert.ToString(Convert.ToDouble(max) - Convert.ToDouble(min));
                 // Median
                 string median; double[] tempArray = columnData;
                 int    count = tempArray.Length; Array.Sort(tempArray);
                 if (count % 2 == 0)
                 {
                     double middleElement1 = tempArray[(count / 2) - 1]; double middleElement2 = tempArray[(count / 2)];
                     median = Convert.ToString((middleElement1 + middleElement2) / 2);
                 }
                 else
                 {
                     median = Convert.ToString(columnData[(count / 2)]);
                 }
                 var mode = tempArray.GroupBy(n => n).
                            OrderByDescending(g => g.Count()).
                            Select(g => g.Key).FirstOrDefault();
                 // MOdd
                 string mod          = Convert.ToString(mode);
                 double sumOfSquares = 0.0;
                 foreach (int num in tempArray)
                 {
                     sumOfSquares += Math.Pow((num - Convert.ToDouble(average)), 2.0);
                 }
                 // Varience
                 string     varience = Convert.ToString(sumOfSquares / (double)(tempArray.Length - 1));
                 SecondPage open     = new SecondPage(average, min, max, varience, standard_Deviation, median, mod, range, columnData); open.Show(); Visible = false;
             }
         }
     }
     else
     {
         MessageBox.Show("Please First Choose any Excel File.");
     }
 }
 private void pictureBox3_Click(object sender, EventArgs e)
 {
     SecondPage backoption = new SecondPage(average, min, max, variance, standard, median, mode, range, colData); backoption.Show(); this.Visible = false;
 }