public void AddError(HashSet <GridData.Cell> cells, Property.IProperty p, Property.ErrorLevel level, string desc) { foreach (var cell in cells) { AddError(cell, p, level, desc); } }
private void _AddError(GridData.Cell cell, Property.IProperty p, Property.ErrorLevel level, string desc) { if (false == Errors.TryGetValue(cell, out var errors)) { Errors.Add(cell, errors = new SortedDictionary <string, Error>()); } if (errors.ContainsKey(p.Name)) // 同一个cell相同的prop只报告一次。 { return; } grid.Rows.Add(); DataGridViewRow row = grid.Rows[grid.RowCount - 1]; row.Cells["Level"].Value = System.Enum.GetName(typeof(Property.ErrorLevel), level); row.Cells["Level"].Tag = cell; row.Cells["Description"].Value = desc; row.Cells["File"].Value = cell.Row.GridData.Document.RelateName; errors.Add(p.Name, new Error() { Level = level, Description = desc, Row = row, }); UpdateErrorCell(cell, errors); }
private void UpdateErrorCell(GridData.Cell cell, SortedDictionary <string, Error> errors) { Property.ErrorLevel max = Property.ErrorLevel.Warn; StringBuilder sb = new StringBuilder(); foreach (var e in errors) { sb.Append(e.Key).Append(": ").Append(e.Value.Description).Append(Environment.NewLine); if (e.Value.Level > max) { max = e.Value.Level; } } cell.BackColor = max == Property.ErrorLevel.Error ? Color.Red : Color.Yellow; cell.ToolTipText = sb.ToString(); cell.Invalidate(); }
public void AddError(GridData.Cell cell, Property.IProperty p, Property.ErrorLevel level, string desc) { if (IsDisposed) // 某些 verify 是异步的,可能在窗口关闭后返回。 { return; } // 在调用线程中回调。 if (OnAddError != null) { OnAddError(cell, p, level, desc); } if (this.InvokeRequired) { DelegateInvoke d = delegate { _AddError(cell, p, level, desc); }; this.BeginInvoke(d); } else { _AddError(cell, p, level, desc); } }