private TreeViewNode CreateTableNode(DBTableInfo sqlTableInfo, TreeViewNode parent) { string tableDisplayName = sqlTableInfo.Schema == "dbo" ? sqlTableInfo.TableName : sqlTableInfo.Schema + "." + sqlTableInfo.TableName; TreeViewNode tblNode = new TreeViewNode(tableDisplayName, parent); tblNode.Tag = sqlTableInfo; TreeViewNode insertSp = new TreeViewNode(Constants.insertTreeNodeText, tblNode); AddColumnNodes(insertSp, sqlTableInfo.Columns.Where(x => !x.Exclude), true); tblNode.Children.Add(insertSp); TreeViewNode deleteSp = new TreeViewNode(Constants.deleteTreeNodeText, tblNode); TreeViewNode whereDelCondition = new TreeViewNode(Constants.whereConditionTreeNodeText, deleteSp); deleteSp.Children.Add(whereDelCondition); tblNode.Children.Add(deleteSp); AddColumnNodes(whereDelCondition, sqlTableInfo.Columns.Where(x => x.IsPrimaryKey).ToList(), true); var updateCols = sqlTableInfo.Columns.Where(x => !x.Exclude).ToArray(); var updateWhereCols = sqlTableInfo.Columns.Where(x => x.IsPrimaryKey).ToArray(); if (updateCols.Any() && updateCols.All(x => !updateWhereCols.Contains(x))) { TreeViewNode updateSp = new TreeViewNode(Constants.updateTreeNodeText, tblNode); AddColumnNodes(updateSp, updateCols, true); tblNode.Children.Add(updateSp); TreeViewNode whereUpdateCondition = new TreeViewNode(Constants.whereConditionTreeNodeText, updateSp); updateSp.Children.Add(whereUpdateCondition); AddColumnNodes(whereUpdateCondition, updateWhereCols, true); } AddColumnNodes(deleteSp, new List<DBTableColumnInfo>(), true); var selectColumns = new DBTableColumnInfo[sqlTableInfo.Columns.Count]; TreeViewNode selectSp = new TreeViewNode(Constants.selectTreeNodeText, tblNode); sqlTableInfo.Columns.CopyTo(selectColumns, 0); Array.ForEach(selectColumns, x => { x.Exclude = false; }); AddColumnNodes(selectSp, selectColumns, true); tblNode.Children.Add(selectSp); var selectOneColumns = new DBTableColumnInfo[sqlTableInfo.Columns.Count]; var selectOneWhereCols = sqlTableInfo.Columns.Where(x => x.IsPrimaryKey).ToArray(); sqlTableInfo.Columns.CopyTo(selectOneColumns, 0); Array.ForEach(selectColumns, x => { x.Exclude = false; }); if (selectOneColumns.Any() && selectOneWhereCols.All(x => selectOneColumns.Any(y => x.ColumnName != y.ColumnName))) { TreeViewNode selectOneSp = new TreeViewNode(Constants.selectOneTreeNodeText, tblNode); AddColumnNodes(selectOneSp, selectOneColumns, true); tblNode.Children.Add(selectOneSp); TreeViewNode whereSelectOneCondition = new TreeViewNode(Constants.whereConditionTreeNodeText, selectOneSp); selectOneSp.Children.Add(whereSelectOneCondition); AddColumnNodes(whereSelectOneCondition, selectOneWhereCols, true); } return tblNode; }