示例#1
0
        public override void SearchValue(object sender, EventArgs e)
        {
            NodeContextInfo nodeCtx = new NodeContextInfo(NodeType.Column, this.Parent);

            string value = Utils.ShowDialog("Insert value to search:", string.Format("Search Value In Column {0}", nodeCtx.Column));

            if (!string.IsNullOrEmpty(value))
            {
                Utils.CreateNewBlankScript(QueryBuilder.GetColumnFullSearch(value, nodeCtx.Database, nodeCtx.Schema, nodeCtx.Table, nodeCtx.Column), true);
            }
        }
示例#2
0
        private void Duplicate(object sender, EventArgs e)
        {
            try
            {
                NodeContextInfo nodeCtx = new NodeContextInfo(NodeType.Table, this.Parent);
                Server          server  = new Server(nodeCtx.Server);
                Database        db      = server.Databases[nodeCtx.Database];

                // in case of there is already column that
                if (nodeCtx.Table.Contains("_Duplicate") ||
                    (db.Tables[nodeCtx.Table + "_Duplicate"]) != null)
                {
                    MessageBox.Show("There Is Already Table With The Same Name");
                    return;
                }

                DialogResult dialogResult = MessageBox.Show("Copy data also?", "Duplicate Table", MessageBoxButtons.YesNo);
                bool         copyData     = (dialogResult == DialogResult.Yes);

                Table            currentTable = db.Tables[nodeCtx.Table, nodeCtx.Schema];    // get current table
                ColumnCollection columns      = currentTable.Columns;                        // get columns of current table
                Table            newTable     = new Table(db, nodeCtx.Table + "_Duplicate"); // create new table to add it to current db

                foreach (Column col in columns)
                {
                    // create new column
                    Column c = new Column(newTable, col.Name);
                    c.DataType = col.DataType;
                    c.Nullable = true;
                    c.DataType.MaximumLength = col.DataType.MaximumLength;

                    // add the new column
                    newTable.Columns.Add(c);
                }

                db.Tables.Add(newTable);
                newTable.Create();

                if (copyData)
                {
                    string     sqlStatement = "INSERT INTO {0} SELECT * FROM [{1}].[{2}].[{3}]";
                    SqlCommand command      = new SqlCommand(string.Format(sqlStatement, newTable.Name, nodeCtx.Database, nodeCtx.Schema, nodeCtx.Table));
                    command.Connection = new SqlConnection(nodeCtx.ConnectionString);
                    command.Connection.Open();
                    command.ExecuteReader();
                    command.Connection.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#3
0
        private void Count(object sender, EventArgs e)
        {
            NodeContextInfo nodeCtx      = new NodeContextInfo(NodeType.Table, this.Parent);
            var             sqlStatement = string.Format(QueryBuilder.countQuery, nodeCtx.Database, nodeCtx.Schema, nodeCtx.Table);
            var             count        = QueryBuilder.GetCountOF(nodeCtx.ConnectionString, sqlStatement);
            StringBuilder   result       = new StringBuilder();

            result.AppendLine("-- Counting Rows In Table *" + nodeCtx.Table + "*");
            result.AppendLine("-- Result: " + count);
            result.AppendLine("-- Running Query: " + sqlStatement);
            Utils.CreateNewBlankScript(result);
        }
示例#4
0
        private void Duplicate(object sender, EventArgs e)
        {
            try
            {
                NodeContextInfo nodeCtx = new NodeContextInfo(NodeType.Column, this.Parent);
                Server          server  = new Server(nodeCtx.Server);
                Database        db      = server.Databases[nodeCtx.Database];
                // get current table
                Table currentTable = db.Tables[nodeCtx.Table, nodeCtx.Schema];
                // get columns of current table
                ColumnCollection col = currentTable.Columns;

                // in case of there is already column that
                if (nodeCtx.Column.Contains(DUPLICATE) ||
                    (col[nodeCtx.Column + DUPLICATE]) != null)
                {
                    MessageBox.Show("There Is Already Column With The Same Name");
                    return;
                }

                DialogResult dialogResult = MessageBox.Show("Copy Data Also?", "Duplicate Column", MessageBoxButtons.YesNo);
                bool         copyData     = (dialogResult == DialogResult.Yes);

                // get current column by name
                Column currentColumn = col[nodeCtx.Column];

                // create duplicated column
                Column duplicatedColumn = new Column(currentTable, nodeCtx.Column + "_Duplicate");
                duplicatedColumn.DataType = currentColumn.DataType;
                duplicatedColumn.Nullable = true;//currentColumn.Nullable;
                duplicatedColumn.DataType.MaximumLength = currentColumn.DataType.MaximumLength;

                // add the new column
                currentTable.Columns.Add(duplicatedColumn);
                duplicatedColumn.Create();

                // copy data
                if (copyData)
                {
                    string     sqlStatement = "UPDATE [{0}].[{1}].[{2}] SET {3} = {4}";
                    SqlCommand command      = new SqlCommand(string.Format(sqlStatement, nodeCtx.Database, nodeCtx.Schema, nodeCtx.Table, nodeCtx.Column + DUPLICATE, nodeCtx.Column));
                    command.Connection = new SqlConnection(nodeCtx.ConnectionString);
                    command.Connection.Open();
                    command.ExecuteReader();
                    command.Connection.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#5
0
        private void Test(object sender, EventArgs e)
        {
            NodeContextInfo nodeCtx = new NodeContextInfo(NodeType.Table, this.Parent);

            //Server server = new Server(nodeCtx.Server);
            //Database db = server.Databases[nodeCtx.Database];

            //db.ExecuteWithResults(string.Format("SELECT * FROM [{0}].[{1}].[{2}]", nodeCtx.Database, nodeCtx.Schema, nodeCtx.Table));
            try
            {
                //if (dte == null) { MessageBox.Show("nullllllllllllll"); }
                //Window window = dte.Windows.Item(Constants.vsWindowKindOutput);
                //OutputWindow outputWindow = (OutputWindow)window.Object;
                //OutputWindowPane owp;
                //owp = outputWindow.OutputWindowPanes.Add("new pane");
                //owp.OutputString("hello");
                MessageBox.Show(nodeCtx.ConnectionString);
            }
            catch (Exception er) { MessageBox.Show(er.ToString()); }
        }