示例#1
0
 public bool IsValid()
 {
     foreach (DataGridViewRow row in _dgv.Rows)
     {
         foreach (DataGridViewCell cell in row.Cells)
         {
             IExamCell ic = cell.Tag as IExamCell;
             if (ic == null)
             {
                 continue;
             }
             if (!ic.IsValid())
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#2
0
        private void CellEdited(DataGridViewCell cell, IExamCell icell)
        {
            DataGridViewCellStyle style = cell.DataGridView.Rows[cell.RowIndex].Cells[0].Style;
            Color defaultBackColor      = style.BackColor;
            Color defaultForeColor      = style.ForeColor;

            cell.Style.BackColor = defaultBackColor;
            cell.Style.ForeColor = defaultForeColor;
            cell.ToolTipText     = "";

            string value = cell.Value == null ? "" : cell.Value.ToString().Trim();

            cell.Value = value;

            if (icell != null)
            {
                icell.SetValue(value);
                if (icell.IsValid())
                {
                    icell.Standard.Judge(cell);
                    if (icell.IsDirty)
                    {
                        cell.Style.BackColor = Color.Yellow;
                        cell.ToolTipText     = "此欄位值已變更,其原值為『" + icell.DefaultValue + "』";
                    }
                }
                else
                {
                    cell.Style.BackColor = Color.Red;
                    cell.Style.ForeColor = defaultForeColor;
                    cell.ToolTipText     = "錯誤!!此欄位必須為數字";
                }
            }

            if (DirtyChanged != null)
            {
                DirtyChanged.Invoke(this, new DirtyChangedEventArgs(IsDirty()));
            }
        }