Ejemplo n.º 1
0
Archivo: Bean.cs Proyecto: e2wugui/zeze
        public VarData GetVarData(int pathCurrentIndex, ColumnTag tag, int pathEndIndex)
        {
            if (pathCurrentIndex > pathEndIndex)
            {
                return(null);
            }

            ColumnTag.VarInfo varInfo = tag.Path[pathCurrentIndex];
            if (false == VariableMap.TryGetValue(varInfo.Define.Name, out var varData))
            {
                return(null);
            }

            if (pathCurrentIndex == pathEndIndex)
            {
                return(varData);
            }

            if (varInfo.Define.Type == VarDefine.EType.List)
            {
                if (varInfo.ListIndex >= varData.Beans.Count)
                {
                    return(null);
                }
                Bean bean = varData.Beans[varInfo.ListIndex];
                if (null == bean)
                {
                    return(null);
                }
                return(bean.GetVarData(pathCurrentIndex + 1, tag, pathEndIndex));
            }
            throw new Exception("pathCurrentIndex != pathEndIndex And VarData Is Not A List");
        }
Ejemplo n.º 2
0
Archivo: Bean.cs Proyecto: e2wugui/zeze
        public bool Update(GridData grid, GridData.Row row, ref int colIndex, int pathIndex, UpdateParam param)
        {
            // ColumnCount maybe change in loop
            for (; colIndex < grid.ColumnCount; ++colIndex)
            {
                ColumnTag tag = grid.GetColumn(colIndex).ColumnTag;
                switch (tag.Tag)
                {
                case ColumnTag.ETag.AddVariable:
                    // end of bean.
                    // 删除Define变化时没有同步的数据。
                    HashSet <string> removed = new HashSet <string>();
                    foreach (var k in VariableMap.Keys)
                    {
                        if (tag.PathLast.Define.Parent.GetVariable(k) == null)
                        {
                            removed.Add(k);
                        }
                    }
                    foreach (var k in removed)
                    {
                        DeleteVarData(k);
                    }
                    return(false);
                }
                ColumnTag.VarInfo varInfo = tag.Path[pathIndex];
                if (false == VariableMap.TryGetValue(varInfo.Define.Name, out var varData))
                {
                    switch (param.UpdateType)
                    {
                    case EUpdate.Data:
                        break;     // will new data

                    case EUpdate.CallAction:
                    case EUpdate.Grid:
                        if (varInfo.Define.Type == VarDefine.EType.List)
                        {
                            if (tag.Tag == ColumnTag.ETag.ListStart)
                            {
                                ++colIndex;
                            }
                            colIndex = GridData.FindColumnListEnd(grid, colIndex);
                        }
                        continue;     // data not found. continue load.

                    case EUpdate.DeleteData:
                        return(true);    // data not found. nothing need to delete.

                    default:
                        throw new Exception("unknown update type");
                    }
                    varData = new VarData(this, varInfo.Define.Name);
                    VariableMap.Add(varInfo.Define.Name, varData);
                }
                else if (param.UpdateType == EUpdate.CallAction)
                {
                    param.UpdateAction(grid, colIndex, varInfo, varData);
                }

                if (varInfo.Define.Type == VarDefine.EType.List)
                {
                    if (param.UpdateType == EUpdate.DeleteData)
                    {
                        if (pathIndex + 1 < tag.Path.Count)
                        {
                            if (varInfo.ListIndex < varData.Beans.Count)
                            {
                                Bean bean1 = varData.Beans[varInfo.ListIndex];
                                if (null != bean1)
                                {
                                    bean1.Update(grid, row, ref colIndex, pathIndex + 1, param);
                                }
                                // always return true;
                            }
                        }
                        else
                        {
                            if (ColumnTag.ETag.ListStart != tag.Tag)
                            {
                                throw new Exception("应该仅在Tag为ListStart时移除数据. see FormMain.deleteVariable...");
                            }
                            DeleteVarData(varInfo.Define.Name);
                        }
                        return(true);
                    }
                    if (ColumnTag.ETag.ListStart == tag.Tag)
                    {
                        continue; // 此时没有进入下一级Bean,就在当前Bean再次判断,因为这里没有ListIndex。
                    }
                    if (tag.Tag == ColumnTag.ETag.ListEnd)
                    {
                        int curListCount = -varInfo.ListIndex;
                        int add          = 0;
                        for (int i = curListCount; i < varData.Beans.Count; ++i)
                        {
                            ColumnTag tagSeed = tag.Copy(ColumnTag.ETag.Normal);
                            tagSeed.PathLast.ListIndex = i;
                            add += tag.PathLast.Define.Reference.BuildGridColumns(grid, colIndex + add, tagSeed, -1);
                        }
                        if (curListCount < varData.Beans.Count) // curListCount 至少为1.
                        {
                            varInfo.ListIndex = -varData.Beans.Count;
                        }
                        if (add > 0)
                        {
                            --colIndex; // 新增加了列,回退一列,继续装载数据。
                        }
                        continue;
                    }

                    if (varInfo.ListIndex >= varData.Beans.Count)
                    {
                        if (EUpdate.Data == param.UpdateType)
                        {
                            for (int i = varData.Beans.Count; i < varInfo.ListIndex; ++i)
                            {
                                varData.AddBean(new Bean(Document, varInfo.Define.Value));
                            }
                            Bean create = new Bean(Document, varInfo.Define.Value);
                            varData.AddBean(create);
                            if (create.Update(grid, row, ref colIndex, pathIndex + 1, param))
                            {
                                return(true);
                            }
                        }
                        // 忽略剩下的没有数据的item直到ListEnd。
                        colIndex = GridData.FindColumnListEnd(grid, colIndex);
                        continue;
                    }

                    Bean bean = varData.Beans[varInfo.ListIndex];
                    if (null != bean)
                    {
                        if (bean.Update(grid, row, ref colIndex, pathIndex + 1, param))
                        {
                            return(true);
                        }
                        continue;
                    }
                    if (EUpdate.Data == param.UpdateType)
                    {
                        Bean create = new Bean(Document, varInfo.Define.Value);
                        varData.SetBeanAt(varInfo.ListIndex, create);
                        if (create.Update(grid, row, ref colIndex, pathIndex + 1, param))
                        {
                            return(true);
                        }
                    }
                    continue;
                }

                if (pathIndex + 1 != tag.Path.Count)
                {
                    throw new Exception("Remain Path, But Is Not A List");
                }

                switch (param.UpdateType)
                {
                case EUpdate.Data:
                    // OnGridCellEndEdit update data
                    varData.Value = row.Cells[colIndex].Value;
                    return(true);

                case EUpdate.CallAction:
                    // 上面已经做完了。
                    break;

                case EUpdate.Grid:
                    row.Cells[colIndex].Value = varData.Value; // upate to grid
                    break;                                     // Update Grid 等到 ColumnTag.ETag.AddVariable 才返回。在这个函数开头。

                case EUpdate.DeleteData:
                    DeleteVarData(varInfo.Define.Name);
                    return(true);

                default:
                    throw new Exception("unkown update type. end.");
                }
            }
            return(true);
        }