private void RefreshNode(TreeNode nd) { if (nd.Level == 0 && nd.Nodes.Count == 1 && nd.Nodes[0].Text == "<EMPTY>") { this.RefreshDbList(nd); } else if (nd.Nodes.Count == 1 && nd.Nodes[0].Text == "<EMPTY>") { SqlObjType objType = (SqlObjType)nd.Tag; if (objType == SqlObjType.TableGroup || objType == SqlObjType.ViewGroup) { this.RefreshTableList(nd); } else if (objType == SqlObjType.ColumnGroup) { this.RefreshColumnList(nd); } else { this.RefreshGroupList(nd); } } }
private void RefreshGroupList(TreeNode nd) { nd.Text += " (expanding...)"; Application.DoEvents(); this.BeginUpdate(); this.UseWaitCursor = true; rsDbSql dbConn = this.GetDbObject(nd); SqlObjType objType = (SqlObjType)nd.Tag; try { nd.Nodes.Clear(); string[] objCol = new string[0]; switch (objType) { case SqlObjType.StoredProcGroup: objCol = dbConn.GetStoredProceedureList(nd.Parent.Text); break; case SqlObjType.FunctionGroup: if (nd.Text.ToLower().StartsWith("table")) { objCol = dbConn.GetTableValueFunctionList(nd.Parent.Parent.Text); } else { objCol = dbConn.GetScalarFunctionList(nd.Parent.Parent.Text); } break; case SqlObjType.ConstraintGroup: objCol = dbConn.GetConstraintList(nd.Parent.Parent.Parent.Text, nd.Parent.Text); break; case SqlObjType.IndexGroup: objCol = dbConn.GetIndexList(nd.Parent.Parent.Parent.Text, nd.Parent.Text, (SqlObjType)nd.Parent.Parent.Tag == SqlObjType.ViewGroup); break; case SqlObjType.TriggerGroup: objCol = dbConn.GetTriggerList(nd.Parent.Parent.Parent.Text, nd.Parent.Text, (SqlObjType)nd.Parent.Parent.Tag == SqlObjType.ViewGroup); break; case SqlObjType.KeyGroup: objCol = dbConn.GetPrimaryKeyList(nd.Parent.Parent.Parent.Text, nd.Parent.Text); break; case SqlObjType.UserGroup: objCol = dbConn.GetUserList(nd.Parent.Text); break; } foreach (string obj in objCol) { TreeNode ndObj = new TreeNode(obj); SqlObjType ndType = (SqlObjType)Enum.Parse(typeof(SqlObjType), objType.ToString().Substring(0, objType.ToString().IndexOf("Group"))); ndObj.ImageKey = ndObj.SelectedImageKey = ndType.ToString(); ndObj.ContextMenuStrip = this.mnuNdObj; ndObj.Tag = ndType; nd.Nodes.Add(ndObj); } if (objType == SqlObjType.KeyGroup) { foreach (string obj in dbConn.GetForeignKeyList(nd.Parent.Parent.Parent.Text, nd.Parent.Text)) { TreeNode ndObj = new TreeNode(obj); ndObj.Tag = SqlObjType.Key; ndObj.ImageKey = ndObj.SelectedImageKey = "Key"; nd.Nodes.Add(ndObj); } } } catch (Exception ex) { MessageBox.Show(this, string.Format("Unable to retreive the list of columns from the SQL server:\n\n{0}\n\nApplication Version: {1}", ex.Message, Application.ProductVersion), "Error"); nd.Nodes.Clear(); nd.Nodes.Add("<EMPTY>"); nd.Collapse(false); } finally { nd.Text = nd.Text.Substring(0, nd.Text.LastIndexOf('(')).TrimEnd(); this.EndUpdate(); this.UseWaitCursor = false; } }