Example #1
0
        public void DeleteVariable(VarDefine var)
        {
            View?.SuspendLayout();
            var updateParam = new Bean.UpdateParam()
            {
                UpdateType = Bean.EUpdate.DeleteData
            };                                                                                 // never change

            for (int c = 0; c < ColumnCount; ++c)
            {
                ColumnTag tagref = Columns[c].ColumnTag;
                if (tagref.PathLast.Define == var)
                {
                    // delete data
                    for (int r = 0; r < RowCount; ++r)
                    {
                        var row    = Rows[r];
                        int colref = c;
                        Document.Beans[r].Update(this, row, ref colref, 0, updateParam);
                    }
                    // delete columns
                    switch (tagref.Tag)
                    {
                    case ColumnTag.ETag.Normal:
                        this.RemoveColumn(c);
                        --c;
                        break;

                    case ColumnTag.ETag.ListStart:
                        int colListEnd = GridData.FindCloseListEnd(this, c);
                        while (colListEnd >= c)
                        {
                            RemoveColumn(colListEnd);
                            --colListEnd;
                        }
                        --c;
                        break;

                    default:
                        MessageBox.Show("ListEnd?");
                        break;
                    }
                }
            }
            View?.ResumeLayout();
        }
Example #2
0
        private void UpdateData(Document doc, string newVarName)
        {
            GridData gridDataTmp = new GridData(doc);

            doc.BeanDefine.BuildGridColumns(gridDataTmp, 0, new ColumnTag(ColumnTag.ETag.Normal), -1);
            HashSet <Bean.VarData> varDatas = new HashSet <Bean.VarData>();
            var param = new Bean.UpdateParam()
            {
                UpdateType   = Bean.EUpdate.CallAction,
                UpdateAction = (GridData grid, int col, ColumnTag.VarInfo varInfo, Bean.VarData varData) =>
                {
                    if (varInfo.Define == this)
                    {
                        varDatas.Add(varData);
                    }
                },
            };

            foreach (var bean in doc.Beans)
            {
                int insertIndex = gridDataTmp.RowCount;
                gridDataTmp.InsertRow(insertIndex);
                int colIndex = 0;
                if (bean.Update(gridDataTmp, gridDataTmp.GetRow(insertIndex), ref colIndex, 0, param))
                {
                    break;
                }
            }
            foreach (var varData in varDatas)
            {
                varData.Parent.RenameVar(varData.Name, newVarName);
            }

            // 打开状态的文档需要重新装载。
            if (null != doc.GridData && null != doc.GridData.View)
            {
                FormMain.Instance.ReloadGridsAfterFormDefineClosed.Add(doc.GridData.View);
            }
        }
Example #3
0
        public void BuildGridData()
        {
            FormMain.Instance.FormError.RemoveErrorByGrid(GridData);
            GridData = new GridData(this);

            BeanDefine.BuildGridColumns(GridData, 0, new ColumnTag(ColumnTag.ETag.Normal), -1);

            var param = new Bean.UpdateParam()
            {
                UpdateType = Bean.EUpdate.Grid
            };

            foreach (var bean in _Beans)
            {
                int insertIndex = GridData.RowCount;
                GridData.InsertRow(insertIndex);

                int colIndex = 0;
                if (bean.Update(GridData, GridData.GetRow(insertIndex), ref colIndex, 0, param))
                {
                    break;
                }
            }

            for (int i = 0; i < GridData.ColumnCount; ++i)
            {
                ColumnTag tag = GridData.GetColumn(i).ColumnTag;
                switch (tag.Tag)
                {
                case ColumnTag.ETag.AddVariable:
                case ColumnTag.ETag.ListStart:
                case ColumnTag.ETag.ListEnd:
                    continue;
                }
                tag.BuildUniqueIndex(GridData, i);
            }
        }
Example #4
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);
        }