Exemple #1
0
        private void updateIndices()
        {
            Queue data = _loader.getData();

            DataGridView.Rows.Clear();

            foreach (Queue row in data)
            {
                string name = (string)row.Dequeue();

                string[] cells = new string[row.Count];
                int      i     = row.Count - 1;
                foreach (string cell in row)
                {
                    cells[i--] = cell;
                }

                int index = DataGridView.Rows.Add(cells);
                DataGridView.Rows[index].HeaderCell.Value = name;
            }

            // раскрашиваем ячейки таблицы
            foreach (DataGridViewRow r in DataGridView.Rows)
            {
                bool alert_shown = false;

                for (int i = r.Cells.Count - 1; i >= 0; i--)
                {
                    DataGridViewCell cell = r.Cells[i];
                    if (cell.ColumnIndex == -1)
                    {
                        continue;
                    }

                    string value_string = (string)cell.Value;

                    if (value_string == null || value_string.Length == 0)
                    {
                        continue;
                    }

                    double value = Convert.ToDouble(value_string.Replace('.', ','));

                    value_string = String.Format("{0:F2}", value);

                    if (value > 0)
                    {
                        value_string = '+' + value_string;
                    }

                    value_string += '%';

                    cell.Value = value_string;

                    int red = 0, green = 0;
                    if (value < -0.01 || value > 0.01)
                    {
                        if (value > 0)
                        {
                            green = (int)(155 * value / 0.5) + 100;
                            if (green > 255)
                            {
                                green = 255;
                            }
                        }
                        else
                        {
                            red = (int)(-55 * value / 0.5) + 200;
                            if (red > 255)
                            {
                                red = 255;
                            }
                        }

                        cell.Style.BackColor = Color.FromArgb(0xFF, red, green, 0);
                    }

                    if (!alert_shown &&
                        _alert_limits.Contains(r.HeaderCell.Value))
                    {
                        double[] limits    = (double[])_alert_limits[r.HeaderCell.Value];
                        double   limit     = (double)limits[cell.ColumnIndex];
                        double   limit_neg = (1 - 100 / (100 + limit)) * 100;
                        if (limit != 0 &&
                            (value <= -limit_neg || value >= limit))
                        {
                            AlertForm alert_form = new AlertForm(this, "Индекс " + r.HeaderCell.Value
                                                                 + (value < 0 ? " упал на " : " вырос на ") + value_string
                                                                 + " за " + DataGridView.Columns[cell.ColumnIndex].Name, value < 0 ? Color.Red : Color.Green
                                                                 );

                            alert_form.Show();

                            alert_shown = true;
                        }
                    }
                }
            }

            DataGridView.ClearSelection();
            DataGridView.AutoResizeColumns();
        }
        private void updateIndices()
        {
            Queue data = _loader.getData();

            DataGridView.Rows.Clear();

            foreach (Queue row in data)
            {
                string name = (string)row.Dequeue();

                string[] cells = new string[row.Count];
                int i = row.Count - 1;
                foreach(string cell in row)
                {
                    cells[i--] = cell;
                }

                int index = DataGridView.Rows.Add(cells);
                DataGridView.Rows[index].HeaderCell.Value = name;
            }

            // раскрашиваем ячейки таблицы
            foreach (DataGridViewRow r in DataGridView.Rows)
            {
                bool alert_shown = false;

                for (int i = r.Cells.Count - 1; i >= 0; i--)
                {
                    DataGridViewCell cell = r.Cells[i];
                    if (cell.ColumnIndex == -1)
                        continue;

                    string value_string = (string)cell.Value;

                    if (value_string == null || value_string.Length == 0)
                        continue;

                    double value = Convert.ToDouble(value_string.Replace('.', ','));

                    value_string = String.Format("{0:F2}", value);

                    if (value > 0)
                    {
                        value_string = '+' + value_string;
                    }

                    value_string += '%';

                    cell.Value = value_string;

                    int red = 0, green = 0;
                    if (value < -0.01 || value > 0.01)
                    {
                        if (value > 0)
                        {
                            green = (int)(155 * value / 0.5) + 100;
                            if (green > 255)
                                green = 255;
                        }
                        else
                        {
                            red = (int)(-55 * value / 0.5) + 200;
                            if (red > 255)
                                red = 255;
                        }

                        cell.Style.BackColor = Color.FromArgb(0xFF, red, green, 0);
                    }

                    if (!alert_shown
                     && _alert_limits.Contains(r.HeaderCell.Value))
                    {
                        double[] limits = (double[])_alert_limits[r.HeaderCell.Value];
                        double limit = (double)limits[cell.ColumnIndex];
                        double limit_neg = (1 - 100 / (100 + limit)) * 100;
                        if (limit != 0
                         && (value <= -limit_neg || value >= limit))
                        {
                            AlertForm alert_form = new AlertForm(this, "Индекс " + r.HeaderCell.Value
                             + (value < 0 ? " упал на " : " вырос на ") + value_string
                             + " за " + DataGridView.Columns[cell.ColumnIndex].Name, value < 0 ? Color.Red : Color.Green
                            );

                            alert_form.Show();

                            alert_shown = true;
                        }
                    }
                }
            }

            DataGridView.ClearSelection();
            DataGridView.AutoResizeColumns();
        }