public static void BindErrorMessage(this TextEditorControl txt, string sql, Exception ex) { StringBuilder sb = new StringBuilder(); if (!(ex is TaosException)) { sb.AppendLine(ex.Message); sb.AppendLine(); sb.AppendLine("==================================================="); sb.AppendLine(ex.StackTrace); } else { TaosException tex = ex as TaosException; sb.AppendLine($"Error code: {tex.ErrorCode}"); sb.AppendLine($"Error message:{tex.Message}"); if (tex.Data != null) { foreach (string item in tex.Data.Keys) { sb.AppendLine($"{item}:{tex.Data[item]}"); } } sb.AppendLine("==================================================="); sb.AppendLine(tex.StackTrace); } txt.Highlighting = null; txt.Clear(); txt.Text = sb.ToString(); }
public static void BindErrorMessage(this TextEditorControl txt, string sql, Exception ex) { var sb = new StringBuilder(); if (!(ex is LiteException)) { sb.AppendLine(ex.Message); sb.AppendLine(); sb.AppendLine("==================================================="); sb.AppendLine(ex.StackTrace); } else if (ex is LiteException lex) { sb.AppendLine(ex.Message); if (lex.ErrorCode == LiteException.UNEXPECTED_TOKEN && sql != null) { var p = (int)lex.Position; var start = Math.Max(p - 30, 1) - 1; var end = Math.Min(p + 15, sql.Length); var length = end - start; var str = sql.Substring(start, length).Replace('\n', ' ').Replace('\r', ' '); var t = length - (end - p); sb.AppendLine(); sb.AppendLine(str); sb.AppendLine("".PadLeft(t, '-') + "^"); } } txt.Highlighting = null; txt.Clear(); txt.Text = sb.ToString(); }
public static void BindParameter(this TextEditorControl txt, TaskData data) { txt.SuspendLayout(); txt.Clear(); txt.SetHighlighting("JSON"); var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { var w = new JsonWriter(writer) { Pretty = true, Indent = 2 }; w.Serialize(data.Parameters ?? BsonValue.Null); } txt.Text = sb.ToString(); txt.ResumeLayout(); }
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}-完成.."); }