Beispiel #1
0
        protected override void OnRefresh(object sender, EventArgs args)
        {
            try
            {
                return;

                this._dataTableSet.Children.Clear();

                DataSet ds =
                    SqlHelper.ExecuteDataset(this.ConnectionString, CommandType.Text, this.Content);
                List <DBModelNode>   modelNodeList     = new List <DBModelNode>();
                List <ColumnSetNode> columnSetNodeList = new List <ColumnSetNode>();

                #region [构造ColumnSetNode ModelNode]
                foreach (DataTable dataTable in ds.Tables)
                {
                    ColumnSetType columnSet     = new ColumnSetType();
                    ColumnSetNode columnSetNode = new ColumnSetNode();
                    columnSetNode.Name = dataTable.TableName;
                    columnSetNodeList.Add(columnSetNode);

                    DBModelNode modelNode = new DBModelNode();
                    modelNode.Name          = dataTable.TableName;
                    modelNode.ColumnSetName = dataTable.TableName;
                    modelNodeList.Add(modelNode);

                    foreach (DataColumn dataColumn in dataTable.Columns)
                    {
                        ColumnNode columnNode = NodeFactory.CreateNode <ColumnNode>();// new ColumnNode();
                        columnNode.AllowDBNull = dataColumn.AllowDBNull;
                        columnNode.DbType      = SchemaUtility.GetDbType(DBGlobalService.DbType, dataColumn.DataType.Name).ToString();
                        columnNode.Description = "";
                        columnNode.IsPK        = false;
                        columnNode.Name        = dataColumn.ColumnName;
                        columnNode.Precision   = 0;
                        columnNode.Scale       = 0;
                        columnNode.Size        = 0;
                        columnNode.SystemType  = dataColumn.DataType;
                        columnNode.Parent      = columnSetNode;

                        FieldNode fieldNode = NodeFactory.CreateNode <FieldNode>();// new FieldNode();
                        fieldNode.Description = "";
                        fieldNode.Name        = dataColumn.ColumnName;
                        fieldNode.ColumnName  = dataColumn.ColumnName;
                        fieldNode.NullAble    = dataColumn.AllowDBNull;
                        fieldNode.SystemType  = dataColumn.DataType;
                        fieldNode.Parent      = modelNode;
                    }
                    columnSetNode.Parent = this._dataTableSet;
                }
                #endregion

                var hasModel = from n in this._modelSet.Children
                               join m in modelNodeList on
                                   ((DBModelNode)n).ColumnSetName equals m.ColumnSetName
                                   where n is DBModelNode
                               select n;

                #region 更新存在的模型
                foreach (DBModelNode modelNode in hasModel)
                {
                    var columnSet = from colset in columnSetNodeList
                                    where colset.Name == modelNode.ColumnSetName
                                    select colset;
                    ColumnSetNode csNode = columnSet.First();

                    foreach (BaseNode node in modelNode.Children)
                    {
                        FieldNode fieldNode = node as FieldNode;
                        if (fieldNode == null)
                        {
                            continue;
                        }

                        if (string.IsNullOrWhiteSpace(fieldNode.ColumnName))
                        {
                            continue;
                        }

                        var column = from col in csNode.Children
                                     where col.Name == fieldNode.Name
                                     select col;

                        bool       needModify = true;
                        ColumnNode colNode    = (ColumnNode)column.FirstOrDefault();
                        if (colNode != null && colNode.Name.Equals(fieldNode.ColumnName) &&
                            colNode.SystemType.Equals(fieldNode.SystemType) &&
                            colNode.AllowDBNull.Equals(fieldNode.NullAble))
                        {
                            needModify = false;
                        }
                        fieldNode.OnColumnModify(needModify);
                    }
                    //添加不存在的字段
                    DBModelNode newModelNode = modelNodeList.Find((m) => { return(m.ColumnSetName.Equals(modelNode.ColumnSetName)); });
                    for (int i = 0; i < newModelNode.Children.Count; i++)
                    {
                        if (newModelNode.Children[i] is FieldNode)
                        {
                            FieldNode fNode     = (FieldNode)newModelNode.Children[i];
                            var       exsitNode = modelNode.Children.FirstOrDefault((n) =>
                                                                                    (n is FieldNode) &&
                                                                                    n.Name.Equals(fNode.Name)
                                                                                    );
                            if (exsitNode == null)
                            {
                                fNode.Parent = null;
                                modelNode.Children.Add(fNode);
                                i--;
                            }
                        }
                    }
                }

                #endregion

                #region 插入不存在的模型
                var hasModelNameList = from n in hasModel
                                       select((DBModelNode)n).ColumnSetName;

                foreach (DBModelNode m in modelNodeList)
                {
                    if (!hasModelNameList.Contains(m.ColumnSetName))
                    {
                        m.Parent = this._modelSet;
                    }
                }

                #endregion
                base.OnRefresh(sender, args);
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误:" + ex.Message);
            }
        }
Beispiel #2
0
        protected override void OnRefresh(object sender, EventArgs args)
        {
            try
            {
                return;

                this._dataTableSet.Children.Clear();

                DataSet ds =
                    SqlHelper.ExecuteDataset(this.ConnectionString, CommandType.Text, this.Content);
                List<DBModelNode> modelNodeList = new List<DBModelNode>();
                List<ColumnSetNode> columnSetNodeList = new List<ColumnSetNode>();

                #region [构造ColumnSetNode ModelNode]
                foreach (DataTable dataTable in ds.Tables)
                {
                    ColumnSetType columnSet = new ColumnSetType();
                    ColumnSetNode columnSetNode = new ColumnSetNode();
                    columnSetNode.Name = dataTable.TableName;
                    columnSetNodeList.Add(columnSetNode);

                    DBModelNode modelNode = new DBModelNode();
                    modelNode.Name = dataTable.TableName;
                    modelNode.ColumnSetName = dataTable.TableName;
                    modelNodeList.Add(modelNode);

                    foreach (DataColumn dataColumn in dataTable.Columns)
                    {
                        ColumnNode columnNode = NodeFactory.CreateNode<ColumnNode>();// new ColumnNode();
                        columnNode.AllowDBNull = dataColumn.AllowDBNull;
                        columnNode.DbType = SchemaUtility.GetDbType(DBGlobalService.DbType,dataColumn.DataType.Name).ToString();
                        columnNode.Description = "";
                        columnNode.IsPK = false;
                        columnNode.Name = dataColumn.ColumnName;
                        columnNode.Precision = 0;
                        columnNode.Scale = 0;
                        columnNode.Size = 0;
                        columnNode.SystemType = dataColumn.DataType;
                        columnNode.Parent = columnSetNode;

                        FieldNode fieldNode = NodeFactory.CreateNode<FieldNode>();// new FieldNode();
                        fieldNode.Description = "";
                        fieldNode.Name = dataColumn.ColumnName;
                        fieldNode.ColumnName = dataColumn.ColumnName;
                        fieldNode.NullAble = dataColumn.AllowDBNull;
                        fieldNode.SystemType = dataColumn.DataType;
                        fieldNode.Parent = modelNode;
                    }
                    columnSetNode.Parent = this._dataTableSet;
                }
                #endregion

                var hasModel = from n in this._modelSet.Children
                               join m in modelNodeList on
                               ((DBModelNode)n).ColumnSetName equals m.ColumnSetName
                               where n is DBModelNode
                               select n;

                #region 更新存在的模型
                foreach (DBModelNode modelNode in hasModel)
                {
                    var columnSet = from colset in columnSetNodeList
                                    where colset.Name == modelNode.ColumnSetName
                                    select colset;
                    ColumnSetNode csNode = columnSet.First();

                    foreach (BaseNode  node in modelNode.Children)
                    {
                        FieldNode fieldNode = node as FieldNode;
                        if (fieldNode == null)
                            continue;

                        if (string.IsNullOrWhiteSpace(fieldNode.ColumnName))
                            continue;

                        var column = from col in csNode.Children
                                     where col.Name == fieldNode.Name
                                     select col;

                        bool needModify = true;
                        ColumnNode colNode = (ColumnNode)column.FirstOrDefault();
                        if (colNode != null && colNode.Name.Equals(fieldNode.ColumnName)
                            && colNode.SystemType.Equals(fieldNode.SystemType)
                            && colNode.AllowDBNull.Equals(fieldNode.NullAble))
                        {
                            needModify = false;
                        }
                        fieldNode.OnColumnModify(needModify);
                    }
                    //添加不存在的字段
                    DBModelNode newModelNode = modelNodeList.Find((m) => { return m.ColumnSetName.Equals(modelNode.ColumnSetName); });
                    for (int i = 0; i < newModelNode.Children.Count; i++)
                    {
                        if (newModelNode.Children[i] is FieldNode)
                        {
                            FieldNode fNode = (FieldNode)newModelNode.Children[i];
                            var exsitNode = modelNode.Children.FirstOrDefault((n) =>
                                (n is FieldNode) &&
                                n.Name.Equals(fNode.Name)
                                );
                            if (exsitNode == null)
                            {
                                fNode.Parent = null;
                                modelNode.Children.Add(fNode);
                                i--;
                            }
                        }
                    }
                }

                #endregion

                #region 插入不存在的模型
                var hasModelNameList = from n in hasModel
                                       select ((DBModelNode)n).ColumnSetName;

                foreach (DBModelNode m in modelNodeList)
                {
                    if (!hasModelNameList.Contains(m.ColumnSetName))
                    {
                        m.Parent = this._modelSet;
                    }
                }

                #endregion
                base.OnRefresh(sender, args);
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误:" + ex.Message);
            }
        }