Beispiel #1
0
        public async override void VerifyCell(VerifyParam p)
        {
            if (p.NewValue.Length == 0)
            {
                p.FormMain.FormError.RemoveError(p.Cell, this);
                return;
            }

            string error = await Task.Run <string>(() =>
            {
                try
                {
                    System.Net.Dns.GetHostEntry(p.NewValue);
                    return(null);
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            });

            if (null != error)
            {
                p.FormMain.FormError.AddError(p.Cell, this, ErrorLevel.Warn, error);
            }
            else
            {
                p.FormMain.FormError.RemoveError(p.Cell, this);
            }
        }
Beispiel #2
0
        public override void VerifyCell(VerifyParam p)
        {
            var msg = Tools.VerifyName(p.NewValue, CheckNameType.CheckOnly);

            if (null != msg)
            {
                p.FormMain.FormError.AddError(p.Cell, this, ErrorLevel.Error, "枚举名不符合要求: " + msg);
                return;
            }

            var varDefine  = p.ColumnTag.PathLast.Define;
            var enumDefine = varDefine.Parent.GetEnumDefine(varDefine.Name);

            if (null == enumDefine)
            {
                p.FormMain.FormError.AddError(p.Cell, this, ErrorLevel.Error, "枚举没有找到: " + varDefine.Name);
                return;
            }

            var valueDefine = enumDefine.GetValueDefine(p.NewValue);

            if (null == valueDefine)
            {
                p.FormMain.FormError.AddError(p.Cell, this, ErrorLevel.Error, "枚举常量没有定义。");
                return;
            }

            p.FormMain.FormError.RemoveError(p.Cell, this);
        }
Beispiel #3
0
 public override void VerifyCell(VerifyParam param)
 {
     if (double.TryParse(param.NewValue, out var _))
     {
         param.FormMain.FormError.RemoveError(param.Cell, this);
     }
     else
     {
         param.FormMain.FormError.AddError(param.Cell, this, ErrorLevel.Error, "It is not a int value.");
     }
 }
Beispiel #4
0
 private bool ExistData(VerifyParam param, VarDefine foreignVar)
 {
     foreach (var beanData in foreignVar.Parent.Document.Beans)
     {
         Bean.VarData varData = beanData.GetLocalVarData(foreignVar.Name);
         if (null != varData && param.NewValue.Equals(varData.Value))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #5
0
        public async override void VerifyCell(VerifyParam p)
        {
            if (p.NewValue.Length == 0)
            {
                p.FormMain.FormError.RemoveError(p.Cell, this);
                return;
            }

            string error = await Task.Run <string>(
                () =>
            {
                try
                {
                    WebRequest req = WebRequest.Create(p.NewValue);
                    using (WebResponse res = req.GetResponse())
                    {
                        if (res is HttpWebResponse httpres)
                        {
                            if (httpres.StatusCode == HttpStatusCode.OK || httpres.StatusCode == HttpStatusCode.PartialContent)
                            {
                                return(null);
                            }
                            return(httpres.StatusDescription);
                        }
                        else
                        {
                            // 不是 http,尝试读取一下。
                            byte[] buffer = new byte[256];
                            int rc        = res.GetResponseStream().Read(buffer, 0, buffer.Length);
                            if (rc >= 0)
                            {
                                return(null);
                            }
                            return("rc < 0?");
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            });

            if (null != error)
            {
                p.FormMain.FormError.AddError(p.Cell, this, ErrorLevel.Warn, error);
            }
            else
            {
                p.FormMain.FormError.RemoveError(p.Cell, this);
            }
        }
Beispiel #6
0
        public void Verify(Property.VerifyParam param)
        {
            var typeName = System.Enum.GetName(typeof(EType), Type).ToLower();

            if (param.FormMain.PropertyManager.BuildIns.TryGetValue(typeName, out var p))
            {
                p.VerifyCell(param);
            }
            if (param.FormMain.PropertyManager.BuildIns.TryGetValue(Property.ForengnVerify.PName, out var f))
            {
                f.VerifyCell(param);
            }
        }
Beispiel #7
0
        public override void VerifyCell(VerifyParam p)
        {
            if (false == p.ColumnTag.UniqueIndex.TryGetValue(p.NewValue, out var cells))
            {
                throw new Exception("数据都建了索引,找不到?哪里漏了吧。");
            }

            if (cells.Count > 1)
            {
                p.FormMain.FormError.AddError(cells, this, ErrorLevel.Error, Name + " 重复了");
            }
            else
            {
                p.FormMain.FormError.RemoveError(p.Cell, this);
            }
        }
Beispiel #8
0
        public void VerifyAll(bool RemoveError)
        {
            try
            {
                if (RemoveError) // 优化,如果外面上下文已经知道重建了 GridData,就需要再次清除了。
                {
                    FormMain.Instance.FormError.RemoveErrorByGrid(this);
                }

                for (int rowIndex = 0; rowIndex < RowCount; ++rowIndex)
                {
                    for (int colIndex = 0; colIndex < ColumnCount; ++colIndex)
                    {
                        ColumnTag tag = Columns[colIndex].ColumnTag;

                        if (tag.Tag != ColumnTag.ETag.Normal)
                        {
                            continue;
                        }

                        Cell cell  = GetCell(colIndex, rowIndex);
                        var  param = new Property.VerifyParam()
                        {
                            FormMain    = FormMain.Instance,
                            Grid        = this,
                            ColumnIndex = colIndex,
                            RowIndex    = rowIndex,
                            ColumnTag   = tag,
                            NewValue    = cell.Value,
                        };

                        foreach (var p in tag.PathLast.Define.PropertiesList)
                        {
                            p.VerifyCell(param);
                        }
                        tag.PathLast.Define.Verify(param);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #9
0
 public override void VerifyCell(VerifyParam param)
 {
     if (string.IsNullOrEmpty(param.FormMain.ConfigProject.ResourceDirectory))
     {
         param.FormMain.FormError.AddError(param.Cell, this, ErrorLevel.Warn, "资源路径没有配置。");
     }
     else
     {
         string path = System.IO.Path.Combine(param.FormMain.ConfigProject.ResourceDirectory, param.NewValue);
         if (false == System.IO.File.Exists(path))
         {
             param.FormMain.FormError.AddError(param.Cell, this, ErrorLevel.Warn, "文件不存在。");
         }
         else
         {
             param.FormMain.FormError.RemoveError(param.Cell, this);
         }
     }
 }
Beispiel #10
0
        public override void VerifyCell(VerifyParam param)
        {
            string result = param.ColumnTag.PathLast.Define.OpenForeign(out var foreignVar);

            if (null == result)
            {
                if (null == foreignVar || ExistData(param, foreignVar)) // no foreign is ok.
                {
                    param.FormMain.FormError.RemoveError(param.Cell, this);
                }
                else
                {
                    param.FormMain.FormError.AddError(param.Cell, this, ErrorLevel.Warn, "value not exist in foreign.");
                }
            }
            else
            {
                param.FormMain.FormError.AddError(param.Cell, this, ErrorLevel.Warn, result);
            }
        }
Beispiel #11
0
 public override void VerifyCell(VerifyParam param)
 {
 }
Beispiel #12
0
 public override void VerifyCell(VerifyParam param)
 {
     base.VerifyCell(param);
 }
Beispiel #13
0
 public abstract void VerifyCell(VerifyParam param);
Beispiel #14
0
        public override void VerifyCell(VerifyParam p)
        {
            int colListStart = GridData.FindColumnListStart(p.Grid, p.ColumnIndex);

            if (colListStart < 0)
            {
                return; // Not A List Item
            }
            int colListEnd = GridData.FindColumnListEnd(p.Grid, p.ColumnIndex);

            if (colListStart < 0)
            {
                return; // Not A List Item. FindColumnListStart 应该足够判断了,都判断一下吧。
            }
            // collect list item cell
            int colBeanBegin           = colListStart + 1;
            List <GridData.Cell> cells = new List <GridData.Cell>();

            while (colBeanBegin < colListEnd)
            {
                colBeanBegin = GridData.DoActionUntilBeanEnd(p.Grid, colBeanBegin, colListEnd, (int col) =>
                {
                    ColumnTag tag = (ColumnTag)p.Grid.GetColumn(col).ColumnTag;
                    if (tag.Tag != ColumnTag.ETag.Normal)
                    {
                        return;
                    }

                    if (tag.Path.Count == p.ColumnTag.Path.Count && // same level.
                        tag.PathLast.Define == p.ColumnTag.PathLast.Define)    // same var
                    {
                        cells.Add(p.Grid.GetRow(p.RowIndex).Cells[col]);
                    }
                });
            }
            ColumnTag tagListEnd  = p.Grid.GetColumn(colListEnd).ColumnTag;
            int       pathListVar = tagListEnd.Path.Count - 1;

            Bean.VarData varList = tagListEnd.PathLast.Define.Parent.Document.Beans[p.RowIndex]
                                   .GetVarData(0, tagListEnd, pathListVar);
            int varListCount = varList == null ? 0 : varList.Beans.Count;

            // count same oldValue
            HashSet <GridData.Cell> same = new HashSet <GridData.Cell>();

            if (p.OldValue != null)
            {
                // load时 varListCount 包含所有数据。
                // Validating 时,如果是新增的,varListCount少1。
                // 计数 oldValue 不需要判断新数据,这里不需要额外判断。
                for (int i = 0; i < varListCount; ++i)
                {
                    var c = cells[i];
                    if (c == p.Cell)
                    {
                        continue;
                    }

                    string str = c.Value;
                    if (p.OldValue.Equals(str))
                    {
                        same.Add(c);
                    }
                }
                if (same.Count == 1)
                {
                    p.FormMain.FormError.RemoveError(same.First(), this);
                }
                same.Clear();
            }

            // count same newValue
            // load时 varListCount 包含所有数据。
            // Validating 时,如果是新增的,varListCount少1。当前新增cell在后面Add。所以不需要特别处理。
            for (int i = 0; i < varListCount; ++i)
            {
                var c = cells[i];
                if (c == p.Cell)
                {
                    continue;
                }

                string str = c.Value;
                if (p.NewValue.Equals(str))
                {
                    same.Add(c);
                }
            }

            // report
            if (same.Count >= 1)
            {
                same.Add(p.Cell);
                p.FormMain.FormError.AddError(same, this, ErrorLevel.Error, Name + " 重复啦。");
            }
            else
            {
                p.FormMain.FormError.RemoveError(p.Cell, this);
            }
        }
Beispiel #15
0
        private void OnCellValuePushed(object sender, DataGridViewCellValueEventArgs e)
        {
            var grid = sender as DataGridView;
            DataGridViewColumn col = grid.Columns[e.ColumnIndex];
            ColumnTag          tag = (ColumnTag)col.Tag;

            if (ColumnTag.ETag.Normal != tag.Tag)
            {
                return; // 不可能。特殊列都是不可编辑的。
            }
            var doc = grid.Tag as Document;

            bool addRow = false;

            if (e.RowIndex == doc.GridData.RowCount)
            {
                doc.AddBean(new Bean(doc, ""));
                doc.GridData.InsertRow(e.RowIndex, false);
                grid.Rows.Add();
                addRow = true;
            }

            if (addRow)
            {
                doc.GridData.BuildUniqueIndexOnAddRow(e.RowIndex);
            }

            var cell     = doc.GridData.GetCell(e.ColumnIndex, e.RowIndex);
            var oldValue = cell.Value;

            cell.Value = e.Value as string;
            if (cell.Value == null)
            {
                cell.Value = "";
            }
            var newValue = cell.Value;

            // save data
            int colIndex    = e.ColumnIndex;
            var updateParam = new Bean.UpdateParam()
            {
                UpdateType = Bean.EUpdate.Data
            };

            doc.Beans[e.RowIndex].Update(doc.GridData, doc.GridData.GetRow(e.RowIndex), ref colIndex, 0, updateParam);

            // verify
            tag.UpdateUniqueIndex(oldValue, newValue, cell);
            var param = new Property.VerifyParam()
            {
                FormMain    = this,
                Grid        = doc.GridData,
                ColumnIndex = e.ColumnIndex,
                RowIndex    = e.RowIndex,
                ColumnTag   = tag,
                OldValue    = oldValue,
                NewValue    = newValue,
            };

            foreach (var p in tag.PathLast.Define.PropertiesList)
            {
                p.VerifyCell(param);
            }
            tag.PathLast.Define.Verify(param);
        }