private void DisplayNumericResults(NumericResults results)
 {
     if (results.Min.HasValue && !Double.IsNaN(results.Min.Value))
     {
         lblMin.Content  = "Min: " + Math.Round(results.Min.Value, 2).ToString();
         lblMax.Content  = "Max: " + Math.Round(results.Max.Value, 2).ToString();
         lblSum.Content  = "Sum: " + Math.Round(results.Sum.Value, 2).ToString();
         lblMean.Content = "Mean: " + Math.Round(results.Mean.Value, 2).ToString();
     }
 }
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkParameters parameters = (WorkParameters)(e.Argument);
            string         varName    = parameters.VariableName;
            string         dataType   = parameters.DataType;

            double count = 0;

            DataView dv = DashboardHelper.GenerateView();

            switch (dataType)
            {
            case "System.String":
                // do nothing
                break;

            case "System.Byte":
            case "System.Int16":
            case "System.Int32":
            case "System.Int64":
            case "System.Single":
            case "System.Double":
            case "System.Decimal":
                double min  = Double.NaN;
                double max  = Double.NaN;
                double mean = Double.NaN;
                double sum  = Double.NaN;
                count = 0;

                foreach (DataRowView rowView in dv)
                {
                    DataRow row = rowView.Row;

                    if (row[varName] != DBNull.Value)
                    {
                        double value = Convert.ToDouble(row[varName]);

                        if (value > max || Double.IsNaN(max))
                        {
                            max = value;
                        }

                        if (value < min || Double.IsNaN(min))
                        {
                            min = value;
                        }

                        if (Double.IsNaN(sum))
                        {
                            sum = value;
                        }
                        else
                        {
                            sum = sum + value;
                        }
                        count++;
                    }

                    if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                    {
                        e.Result = null;
                        return;
                    }
                }

                mean = sum / count;

                NumericResults numericResults = new NumericResults();
                numericResults.WorkParameters = parameters;
                numericResults.Max            = max;
                numericResults.Min            = min;
                numericResults.Sum            = sum;
                numericResults.Mean           = mean;

                if (worker.WorkerSupportsCancellation && !worker.CancellationPending)
                {
                    e.Result = numericResults;
                    return;
                }

                break;

            case "System.DateTime":
                DateTime?minDate = null;
                DateTime?maxDate = null;

                foreach (DataRowView rowView in dv)
                {
                    DataRow row = rowView.Row;

                    if (row[varName] != DBNull.Value)
                    {
                        DateTime value = (DateTime)row[varName];

                        if (!maxDate.HasValue || value > maxDate.Value)
                        {
                            maxDate = value;
                        }

                        if (!minDate.HasValue || value < minDate.Value)
                        {
                            minDate = value;
                        }
                    }

                    if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                    {
                        e.Result = null;
                        return;
                    }
                }

                DateResults dateResults = new DateResults();
                dateResults.WorkParameters = parameters;
                dateResults.Max            = maxDate;
                dateResults.Min            = minDate;

                if (worker.WorkerSupportsCancellation && !worker.CancellationPending)
                {
                    e.Result = dateResults;
                    return;
                }

                break;

            case "System.Boolean":
                int t = 0;
                int f = 0;

                count = 0;
                foreach (DataRowView rowView in dv)
                {
                    DataRow row = rowView.Row;

                    if (row[varName] != DBNull.Value)
                    {
                        bool value = Convert.ToBoolean(row[varName]);
                        if (value == true)
                        {
                            t = t + 1;
                        }
                        else if (value == false)
                        {
                            f = f + 1;
                        }
                    }

                    if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                    {
                        e.Result = null;
                        return;
                    }
                    count++;
                }

                BooleanResults booleanResults = new BooleanResults();
                booleanResults.WorkParameters = parameters;
                booleanResults.True           = t;
                booleanResults.False          = f;

                if (count > 0)
                {
                    if (booleanResults.True.HasValue)
                    {
                        booleanResults.TruePercent = booleanResults.True / count;
                    }
                    if (booleanResults.False.HasValue)
                    {
                        booleanResults.FalsePercent = booleanResults.False / count;
                    }
                }

                if (worker.WorkerSupportsCancellation && !worker.CancellationPending)
                {
                    e.Result = booleanResults;
                    return;
                }

                break;
            }
        }
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            WorkParameters parameters = (WorkParameters)(e.Argument);
            string varName = parameters.VariableName;
            string dataType = parameters.DataType;

            double count = 0;

            DataView dv = DashboardHelper.GenerateView();

            switch (dataType)
            {
                case "System.String":
                    // do nothing
                    break;
                case "System.Byte":
                case "System.Int16":
                case "System.Int32":
                case "System.Int64":
                case "System.Single":
                case "System.Double":
                case "System.Decimal":
                    double min = Double.NaN;
                    double max = Double.NaN;
                    double mean = Double.NaN;
                    double sum = Double.NaN;
                    count = 0;

                    foreach (DataRowView rowView in dv)
                    {
                        DataRow row = rowView.Row;

                        if (row[varName] != DBNull.Value)
                        {
                            double value = Convert.ToDouble(row[varName]);

                            if (value > max || Double.IsNaN(max))
                            {
                                max = value;
                            }

                            if (value < min || Double.IsNaN(min))
                            {
                                min = value;
                            }

                            if (Double.IsNaN(sum))
                            {
                                sum = value;
                            }
                            else
                            {
                                sum = sum + value;
                            }
                            count++;
                        }

                        if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                        {
                            e.Result = null;
                            return;
                        }
                    }

                    mean = sum / count;

                    NumericResults numericResults = new NumericResults();
                    numericResults.WorkParameters = parameters;
                    numericResults.Max = max;
                    numericResults.Min = min;
                    numericResults.Sum = sum;
                    numericResults.Mean = mean;

                    if (worker.WorkerSupportsCancellation && !worker.CancellationPending)
                    {
                        e.Result = numericResults;
                        return;
                    }

                    break;
                case "System.DateTime":
                    DateTime? minDate = null;
                    DateTime? maxDate = null;

                    foreach (DataRowView rowView in dv)
                    {
                        DataRow row = rowView.Row;

                        if (row[varName] != DBNull.Value)
                        {
                            DateTime value = (DateTime)row[varName];

                            if (!maxDate.HasValue || value > maxDate.Value)
                            {
                                maxDate = value;
                            }

                            if (!minDate.HasValue || value < minDate.Value)
                            {
                                minDate = value;
                            }
                        }

                        if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                        {
                            e.Result = null;
                            return;
                        }
                    }

                    DateResults dateResults = new DateResults();
                    dateResults.WorkParameters = parameters;
                    dateResults.Max = maxDate;
                    dateResults.Min = minDate;

                    if (worker.WorkerSupportsCancellation && !worker.CancellationPending)
                    {
                        e.Result = dateResults;
                        return;
                    }

                    break;
                case "System.Boolean":
                    int t = 0;
                    int f = 0;

                    count = 0;
                    foreach (DataRowView rowView in dv)
                    {
                        DataRow row = rowView.Row;

                        if (row[varName] != DBNull.Value)
                        {
                            bool value = Convert.ToBoolean(row[varName]);
                            if (value == true)
                            {
                                t = t + 1;
                            }
                            else if (value == false)
                            {
                                f = f + 1;
                            }
                        }

                        if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                        {
                            e.Result = null;
                            return;
                        }
                        count++;
                    }

                    BooleanResults booleanResults = new BooleanResults();
                    booleanResults.WorkParameters = parameters;
                    booleanResults.True = t;
                    booleanResults.False = f;

                    if (count > 0)
                    {
                        if (booleanResults.True.HasValue)
                        {
                            booleanResults.TruePercent = booleanResults.True / count;
                        }
                        if (booleanResults.False.HasValue)
                        {
                            booleanResults.FalsePercent = booleanResults.False / count;
                        }
                    }

                    if (worker.WorkerSupportsCancellation && !worker.CancellationPending)
                    {
                        e.Result = booleanResults;
                        return;
                    }

                    break;

            }
        }
 private void DisplayNumericResults(NumericResults results)
 {
     if (results.Min.HasValue && !Double.IsNaN(results.Min.Value))
     {
         lblMin.Content = "Min: " + Math.Round(results.Min.Value, 2).ToString();
         lblMax.Content = "Max: " + Math.Round(results.Max.Value, 2).ToString();
         lblSum.Content = "Sum: " + Math.Round(results.Sum.Value, 2).ToString();
         lblMean.Content = "Mean: " + Math.Round(results.Mean.Value, 2).ToString();
     }
 }