Ejemplo n.º 1
0
        private void tvTablesColumns_ExpandTable(TreeNode tNode)
        {
            if (tNode.Parent == null)                   // Check for Tables or Views
            {
                return;
            }

            if (tNode.FirstNode.Text != "")             // Have we already filled it out?
            {
                return;
            }

            // Need to obtain the column information for the requested table/view
            // suppress redraw until tree view is complete
            tvTablesColumns.BeginUpdate();

            string           sql        = "SELECT * FROM " + DesignerUtility.NormalizeSqlName(tNode.Text);
            List <SqlColumn> tColumns   = DesignerUtility.GetSqlColumns(_Draw, _DataSource, sql);
            bool             bFirstTime = true;

            foreach (SqlColumn sc in tColumns)
            {
                if (bFirstTime)
                {
                    bFirstTime           = false;
                    tNode.FirstNode.Text = sc.Name;
                }
                else
                {
                    tNode.Nodes.Add(sc.Name);
                }
            }

            tvTablesColumns.EndUpdate();
        }
Ejemplo n.º 2
0
        private void bMove_Click(object sender, System.EventArgs e)
        {
            if (tvTablesColumns.SelectedNode == null ||
                tvTablesColumns.SelectedNode.Parent == null)
            {
                return;                         // this is the Tables/Views node
            }
            TreeNode node = tvTablesColumns.SelectedNode;
            string   t    = node.Text;

            if (tbSQL.Text == "")
            {
                if (node.Parent.Parent == null)
                {                                      // select table; generate full select for table
                    tvTablesColumns_ExpandTable(node); // make sure we've obtained the columns

                    StringBuilder sb   = new StringBuilder("SELECT ");
                    TreeNode      next = node.FirstNode;
                    while (true)
                    {
                        sb.Append(DesignerUtility.NormalizeSqlName(next.Text));
                        next = next.NextNode;
                        if (next == null)
                        {
                            break;
                        }
                        sb.Append(", ");
                    }
                    sb.Append(" FROM ");
                    sb.Append(DesignerUtility.NormalizeSqlName(node.Text));
                    t = sb.ToString();
                }
                else
                {                       // select column; generate select of that column
                    t = "SELECT " + DesignerUtility.NormalizeSqlName(node.Text) + " FROM " + DesignerUtility.NormalizeSqlName(node.Parent.Text);
                }
            }

            tbSQL.SelectedText = t;
        }