Beispiel #1
0
        public static void BindBsonData(this DataGridView grd, Chart chart, TaskData data, TextEditorControl text)
        {
            text.AppendLine($"{DateTime.Now}-准备数据..");
            grd.Clear();
            text.Clear();
            chart.Series.Clear();

            grd.DataSource = data.Result;
            DataTable dt = data.Result?.Copy().RemoveDataTableNullColumns();

            chart.DataSource = dt;
            text.AppendLine($"{DateTime.Now}-合成曲线图..");

            if (dt?.Columns.OfType <DataColumn>().Any(col => col.ColumnName == "ts") == true)
            {
                foreach (DataColumn col in dt.Columns)
                {
                    if (col.ColumnName != "ts")
                    {
                        if (col.DataType == typeof(long))
                        {
                            chart.AddSeries(col.ColumnName, ChartValueType.Int64);
                        }
                        else if (col.DataType == typeof(int))
                        {
                            chart.AddSeries(col.ColumnName, ChartValueType.Int32);
                        }
                        else if (col.DataType == typeof(float))
                        {
                            chart.AddSeries(col.ColumnName, ChartValueType.Single);
                        }
                        else if (col.DataType == typeof(double))
                        {
                            chart.AddSeries(col.ColumnName, ChartValueType.Double);
                        }
                    }
                }
                chart.DataBind();
            }
            if (data.LimitExceeded)
            {
                DataGridViewRow limitRow = new DataGridViewRow();
                limitRow.CreateCells(grd);
                limitRow.DefaultCellStyle.ForeColor = Color.OrangeRed;
                DataGridViewCell cell = limitRow.Cells[0];
                cell.Value    = Resources.LimitExceeded;
                cell.ReadOnly = true;
                grd.Rows.Add(limitRow);
            }

            for (int i = 0; i <= grd.Columns.Count - 1; i++)
            {
                int colw = grd.Columns[i].Width;
                grd.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                grd.Columns[i].Width        = Math.Min(colw, 400);
            }

            if (grd.Rows.Count == 0)
            {
                grd.Columns.Add("no-data", Resources.NoResult);
            }

            grd.ReadOnly = grd.Columns["_id"] == null;
            grd.Visible  = true;
            text.AppendLine($"{DateTime.Now}-完成..");
        }