示例#1
0
        private void CalculatePieChart(DataTable dt, DateTime start, DateTime stop)
        {
            Queries.sp_GetDataForLastXDaysDataTable castDT = (Queries.sp_GetDataForLastXDaysDataTable)dt;
            if (start.TimeOfDay < stop.TimeOfDay)
            {
                PercentLow = 100 * Convert.ToDouble(castDT.Where(i => i.Glucose <= Statics.LowThreshold &&
                                                                 i.TimeStamp.TimeOfDay >= start.TimeOfDay &&
                                                                 i.TimeStamp.TimeOfDay <= stop.TimeOfDay).Count()) / Convert.ToDouble(dt.Rows.Count);

                PercentHigh = 100 * Convert.ToDouble(castDT.Where(i => i.Glucose >= Statics.HighThreshold &&
                                                                  i.TimeStamp.TimeOfDay >= start.TimeOfDay &&
                                                                  i.TimeStamp.TimeOfDay <= stop.TimeOfDay).Count()) / Convert.ToDouble(dt.Rows.Count);

                PercentNormal = 100 * Convert.ToDouble(castDT.Where(i => i.Glucose > Statics.LowThreshold &&
                                                                    i.Glucose < Statics.HighThreshold &&
                                                                    i.TimeStamp.TimeOfDay >= start.TimeOfDay &&
                                                                    i.TimeStamp.TimeOfDay <= stop.TimeOfDay).Count()) / Convert.ToDouble(dt.Rows.Count);
            }
            else
            {
                PercentLow = 100 * Convert.ToDouble(castDT.Where(i => i.Glucose <= Statics.LowThreshold &&
                                                                 i.TimeStamp.TimeOfDay >= start.TimeOfDay ||
                                                                 i.TimeStamp.TimeOfDay <= stop.TimeOfDay).Count()) / Convert.ToDouble(dt.Rows.Count);

                PercentHigh = 100 * Convert.ToDouble(castDT.Where(i => i.Glucose >= Statics.HighThreshold &&
                                                                  i.TimeStamp.TimeOfDay >= start.TimeOfDay ||
                                                                  i.TimeStamp.TimeOfDay <= stop.TimeOfDay).Count()) / Convert.ToDouble(dt.Rows.Count);

                PercentNormal = 100 * Convert.ToDouble(castDT.Where(i => (i.Glucose > Statics.LowThreshold &&
                                                                          i.Glucose < Statics.HighThreshold) &&
                                                                    i.TimeStamp.TimeOfDay >= start.TimeOfDay ||
                                                                    i.TimeStamp.TimeOfDay <= stop.TimeOfDay).Count()) / Convert.ToDouble(dt.Rows.Count);
            }

            BindingSource = new DataTable("Pie");
            BindingSource.Columns.Add("Label");
            BindingSource.Columns.Add("Value");
            BindingSource.Rows.Add(new object[] { "", AllAreBlank() ? 1 : PercentLow });
            BindingSource.Rows.Add(new object[] { "", AllAreBlank() ? 98 : PercentNormal });
            BindingSource.Rows.Add(new object[] { "", AllAreBlank() ? 1 : PercentHigh });
        }