Пример #1
0
        private void _RemoveErrorByGrid(GridData gridedit)
        {
            if (null == gridedit)
            {
                return;
            }

            // 现在只显示打开grid的文件错误。如果要显示所有文件的。
            // 就不能记住Cell的引用,应该使用文件名+(ColIndex, RowIndex)。
            // 但是由于文件会变化,(ColIndex, RowIndex)可能不再准确(看看怎么处理这种情况)。

            grid.SuspendLayout();
            Dictionary <GridData.Cell, int> removed
                = new Dictionary <GridData.Cell, int>(new IdentityEqualityComparer());

            for (int i = grid.RowCount - 1; i >= 0; --i)
            {
                GridData.Cell c = grid.Rows[i].Cells["Level"].Tag as GridData.Cell;
                if (c.Row.GridData == gridedit)
                {
                    removed[c]    = 1;
                    c.BackColor   = Color.White;
                    c.ToolTipText = null;
                    c.Invalidate();
                    grid.Rows.RemoveAt(i);
                }
            }
            grid.ResumeLayout();

            foreach (var c in removed.Keys)
            {
                Errors.Remove(c);
            }
        }
Пример #2
0
        private void _RemoveError(GridData.Cell cell, Property.IProperty p)
        {
            if (false == Errors.TryGetValue(cell, out var errors))
            {
                return;
            }

            if (false == errors.TryGetValue(p.Name, out var error))
            {
                return;
            }

            errors.Remove(p.Name);
            grid.Rows.Remove(error.Row);

            if (errors.Count == 0)
            {
                Errors.Remove(cell);
                cell.BackColor   = Color.White;
                cell.ToolTipText = null;
                cell.Invalidate();
            }
            else
            {
                UpdateErrorCell(cell, errors);
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
 public void AddUniqueIndex(string newValue, GridData.Cell cell)
 {
     if (false == UniqueIndex.TryGetValue(newValue, out var cells))
     {
         UniqueIndex.Add(newValue, cells = new HashSet <GridData.Cell>());
     }
     cells.Add(cell);
 }
Пример #5
0
        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();
        }
Пример #6
0
        public void RemoveError(GridData.Cell cell, Property.IProperty p)
        {
            if (IsDisposed) // 某些 verify 是异步的,可能在窗口关闭后返回。
            {
                return;
            }

            if (this.InvokeRequired)
            {
                DelegateInvoke d = delegate { _RemoveError(cell, p); };
                this.BeginInvoke(d);
            }
            else
            {
                _RemoveError(cell, p);
            }
        }
Пример #7
0
        public void UpdateUniqueIndex(string oldValue, string newValue, GridData.Cell cell)
        {
            if (null == oldValue)
            {
                oldValue = "";
            }

            if (oldValue.Equals(newValue))
            {
                return;
            }

            if (UniqueIndex.TryGetValue(oldValue, out var cells))
            {
                cells.Remove(cell);

                switch (cells.Count)
                {
                case 1:
                    // 关联的cell已经唯一了,特殊处理。
                    var formMain = FormMain.Instance;
                    if (formMain.PropertyManager.Properties.TryGetValue(Property.Unique.PName, out var puniq))
                    {
                        formMain.FormError.RemoveError(cells.First(), puniq);
                    }
                    if (formMain.PropertyManager.Properties.TryGetValue(Property.Id.PName, out var pid))
                    {
                        formMain.FormError.RemoveError(cells.First(), pid);
                    }
                    break;

                case 0:
                    UniqueIndex.Remove(oldValue);
                    break;
                }
            }
            AddUniqueIndex(newValue, cell);
        }
Пример #8
0
        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);
            }
        }