Ejemplo n.º 1
0
 public void SetQueries(DesignerDataConnection dataConnection, SqlDataSourceQuery selectQuery, SqlDataSourceQuery insertQuery, SqlDataSourceQuery updateQuery, SqlDataSourceQuery deleteQuery)
 {
     this._dataConnection      = dataConnection;
     this._selectQuery         = selectQuery;
     this._insertQuery         = insertQuery;
     this._updateQuery         = updateQuery;
     this._deleteQuery         = deleteQuery;
     this._previewTextBox.Text = this._selectQuery.Command;
 }
        public void SetQueries(DesignerDataConnection dataConnection, SqlDataSourceQuery selectQuery, SqlDataSourceQuery insertQuery, SqlDataSourceQuery updateQuery, SqlDataSourceQuery deleteQuery)
        {
            DesignerDataConnection connection = dataConnection;

            if (!SqlDataSourceDesigner.ConnectionsEqual(this._dataConnection, connection))
            {
                this._dataConnection = connection;
                Cursor    current          = Cursor.Current;
                ArrayList storedProcedures = null;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    IDataEnvironment service = (IDataEnvironment)this._sqlDataSourceDesigner.Component.Site.GetService(typeof(IDataEnvironment));
                    if (service != null)
                    {
                        IDesignerDataSchema connectionSchema = service.GetConnectionSchema(this._dataConnection);
                        if ((connectionSchema != null) && connectionSchema.SupportsSchemaClass(DesignerDataSchemaClass.StoredProcedures))
                        {
                            ICollection schemaItems = connectionSchema.GetSchemaItems(DesignerDataSchemaClass.StoredProcedures);
                            if ((schemaItems != null) && (schemaItems.Count > 0))
                            {
                                storedProcedures = new ArrayList();
                                foreach (DesignerDataStoredProcedure procedure in schemaItems)
                                {
                                    if (!procedure.Name.ToLowerInvariant().StartsWith("AspNet_".ToLowerInvariant(), StringComparison.Ordinal))
                                    {
                                        storedProcedures.Add(procedure);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    UIServiceHelper.ShowError(base.ServiceProvider, exception, System.Design.SR.GetString("SqlDataSourceConnectionPanel_CouldNotGetConnectionSchema"));
                }
                finally
                {
                    Cursor.Current = current;
                }
                this._selectCommandEditor.SetConnection(this._dataConnection);
                this._selectCommandEditor.SetStoredProcedures(storedProcedures);
                this._insertCommandEditor.SetConnection(this._dataConnection);
                this._insertCommandEditor.SetStoredProcedures(storedProcedures);
                this._updateCommandEditor.SetConnection(this._dataConnection);
                this._updateCommandEditor.SetStoredProcedures(storedProcedures);
                this._deleteCommandEditor.SetConnection(this._dataConnection);
                this._deleteCommandEditor.SetStoredProcedures(storedProcedures);
                this._selectCommandEditor.SetQuery(selectQuery);
                this._insertCommandEditor.SetQuery(insertQuery);
                this._updateCommandEditor.SetQuery(updateQuery);
                this._deleteCommandEditor.SetQuery(deleteQuery);
            }
        }
        public override bool OnNext()
        {
            SqlDataSourceQuery        selectQuery = new SqlDataSourceQuery(this._selectQuery.Command, this._selectQuery.CommandType, this._parameterEditorUserControl.GetParameters());
            SqlDataSourceSummaryPanel nextPanel   = base.NextPanel as SqlDataSourceSummaryPanel;

            if (nextPanel == null)
            {
                nextPanel      = ((SqlDataSourceWizardForm)base.ParentWizard).GetSummaryPanel();
                base.NextPanel = nextPanel;
            }
            nextPanel.SetQueries(this._dataConnection, selectQuery, this._insertQuery, this._updateQuery, this._deleteQuery);
            return(true);
        }
        public override bool OnNext()
        {
            SqlDataSourceQuery selectQuery = this._selectCommandEditor.GetQuery();
            SqlDataSourceQuery query       = this._insertCommandEditor.GetQuery();
            SqlDataSourceQuery updateQuery = this._updateCommandEditor.GetQuery();
            SqlDataSourceQuery deleteQuery = this._deleteCommandEditor.GetQuery();

            if (((selectQuery == null) || (query == null)) || ((updateQuery == null) || (deleteQuery == null)))
            {
                return(false);
            }
            int num = 0;

            foreach (Parameter parameter in selectQuery.Parameters)
            {
                if ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput))
                {
                    num++;
                }
            }
            if (num == 0)
            {
                SqlDataSourceSummaryPanel summaryPanel = base.NextPanel as SqlDataSourceSummaryPanel;
                if (summaryPanel == null)
                {
                    summaryPanel   = ((SqlDataSourceWizardForm)base.ParentWizard).GetSummaryPanel();
                    base.NextPanel = summaryPanel;
                }
                summaryPanel.SetQueries(this._dataConnection, selectQuery, query, updateQuery, deleteQuery);
                return(true);
            }
            SqlDataSourceConfigureParametersPanel nextPanel = base.NextPanel as SqlDataSourceConfigureParametersPanel;

            if (nextPanel == null)
            {
                nextPanel      = ((SqlDataSourceWizardForm)base.ParentWizard).GetConfigureParametersPanel();
                base.NextPanel = nextPanel;
                SqlDataSource component        = (SqlDataSource)this._sqlDataSourceDesigner.Component;
                Parameter[]   selectParameters = new Parameter[component.SelectParameters.Count];
                for (int i = 0; i < component.SelectParameters.Count; i++)
                {
                    Parameter original = component.SelectParameters[i];
                    Parameter clone    = (Parameter)((ICloneable)original).Clone();
                    this._sqlDataSourceDesigner.RegisterClone(original, clone);
                    selectParameters[i] = clone;
                }
                nextPanel.InitializeParameters(selectParameters);
            }
            nextPanel.SetQueries(this._dataConnection, selectQuery, query, updateQuery, deleteQuery);
            return(true);
        }
 public void SetQueries(DesignerDataConnection dataConnection, SqlDataSourceQuery selectQuery, SqlDataSourceQuery insertQuery, SqlDataSourceQuery updateQuery, SqlDataSourceQuery deleteQuery)
 {
     this._dataConnection      = dataConnection;
     this._selectQuery         = selectQuery;
     this._insertQuery         = insertQuery;
     this._updateQuery         = updateQuery;
     this._deleteQuery         = deleteQuery;
     this._previewTextBox.Text = this._selectQuery.Command;
     Parameter[] array = new Parameter[this._selectQuery.Parameters.Count];
     this._selectQuery.Parameters.CopyTo(array, 0);
     Parameter[] parameters = MergeParameters(this._parameterEditorUserControl.GetParameters(), array);
     this._parameterEditorUserControl.ClearParameters();
     this._parameterEditorUserControl.AddParameters(parameters);
 }
        public SqlDataSourceQuery GetUpdateQuery(string oldValuesFormatString, bool includeOldValues)
        {
            if (!this.CanAutoGenerateQueries())
            {
                return(null);
            }
            StringBuilder builder = new StringBuilder("UPDATE ");

            builder.Append(this.GetTableName());
            builder.Append(" SET ");
            List <SqlDataSourceColumnData> effectiveColumns = this.GetEffectiveColumns();
            List <Parameter> parameters = new List <Parameter>();
            bool             flag       = true;

            foreach (SqlDataSourceColumnData data in effectiveColumns)
            {
                if (!data.Column.PrimaryKey)
                {
                    if (!flag)
                    {
                        builder.Append(", ");
                    }
                    builder.Append(data.EscapedName);
                    builder.Append(" = ");
                    builder.Append(data.ParameterPlaceholder);
                    flag = false;
                    DbProviderFactory dbProviderFactory = SqlDataSourceDesigner.GetDbProviderFactory(this.DesignerDataConnection.ProviderName);
                    parameters.Add(SqlDataSourceDesigner.CreateParameter(dbProviderFactory, data.WebParameterName, data.Column.DataType));
                }
            }
            if (flag)
            {
                return(null);
            }
            SqlDataSourceQuery whereClause = this.GetWhereClause(oldValuesFormatString, includeOldValues);

            if (whereClause == null)
            {
                return(null);
            }
            builder.Append(whereClause.Command);
            foreach (Parameter parameter in whereClause.Parameters)
            {
                parameters.Add(parameter);
            }
            return(new SqlDataSourceQuery(builder.ToString(), SqlDataSourceCommandType.Text, parameters));
        }
        public SqlDataSourceQuery GetDeleteQuery(string oldValuesFormatString, bool includeOldValues)
        {
            if (!this.CanAutoGenerateQueries())
            {
                return(null);
            }
            StringBuilder builder = new StringBuilder("DELETE FROM ");

            builder.Append(this.GetTableName());
            SqlDataSourceQuery whereClause = this.GetWhereClause(oldValuesFormatString, includeOldValues);

            if (whereClause == null)
            {
                return(null);
            }
            builder.Append(whereClause.Command);
            return(new SqlDataSourceQuery(builder.ToString(), SqlDataSourceCommandType.Text, whereClause.Parameters));
        }
 public void SetQuery(SqlDataSourceQuery query)
 {
     this._storedProcedureComboBox.SelectedIndex = -1;
     if (this._storedProcedures != null)
     {
         foreach (StoredProcedureItem item in this._storedProcedureComboBox.Items)
         {
             if (item.DesignerDataStoredProcedure.Name == query.Command)
             {
                 this._storedProcedureComboBox.SelectedItem = item;
                 break;
             }
         }
     }
     if (this._storedProcedureComboBox.SelectedIndex != -1)
     {
         this._sqlRadioButton.Checked             = false;
         this._storedProcedureRadioButton.Checked = true;
     }
     else
     {
         this._sqlRadioButton.Checked             = true;
         this._storedProcedureRadioButton.Checked = false;
         if (this._storedProcedureComboBox.Items.Count > 0)
         {
             this._storedProcedureComboBox.SelectedIndex = 0;
         }
     }
     if (!this._queryInitialized)
     {
         this._commandTextBox.Text = query.Command;
         this._originalCommand     = query.Command;
         this._commandType         = query.CommandType;
         this._parameters          = query.Parameters;
         this._queryInitialized    = true;
     }
     this.UpdateEnabledState();
 }
 public override bool OnNext()
 {
     if (this._tableRadioButton.Checked)
     {
         SqlDataSourceQuery insertQuery;
         SqlDataSourceQuery updateQuery;
         SqlDataSourceQuery deleteQuery;
         SqlDataSourceQuery selectQuery = this._tableQuery.GetSelectQuery();
         if (selectQuery == null)
         {
             selectQuery = new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
         }
         if (this._generateMode > 0)
         {
             SqlDataSource sqlDataSource = (SqlDataSource) this._sqlDataSourceDesigner.Component;
             bool adjustForOptimisticConcurrency = this._generateMode == 2;
             string oldValuesFormatString = GetOldValuesFormatString(sqlDataSource, adjustForOptimisticConcurrency);
             insertQuery = this._tableQuery.GetInsertQuery();
             if (insertQuery == null)
             {
                 insertQuery = new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
             }
             updateQuery = this._tableQuery.GetUpdateQuery(oldValuesFormatString, adjustForOptimisticConcurrency);
             if (updateQuery == null)
             {
                 updateQuery = new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
             }
             deleteQuery = this._tableQuery.GetDeleteQuery(oldValuesFormatString, adjustForOptimisticConcurrency);
             if (deleteQuery == null)
             {
                 deleteQuery = new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
             }
         }
         else
         {
             insertQuery = new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
             updateQuery = new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
             deleteQuery = new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
         }
         SqlDataSourceSummaryPanel summaryPanel = base.NextPanel as SqlDataSourceSummaryPanel;
         if (summaryPanel == null)
         {
             summaryPanel = ((SqlDataSourceWizardForm) base.ParentWizard).GetSummaryPanel();
             base.NextPanel = summaryPanel;
         }
         summaryPanel.SetQueries(this._dataConnection, selectQuery, insertQuery, updateQuery, deleteQuery);
         return true;
     }
     SqlDataSourceCustomCommandPanel nextPanel = base.NextPanel as SqlDataSourceCustomCommandPanel;
     if (nextPanel == null)
     {
         nextPanel = ((SqlDataSourceWizardForm) base.ParentWizard).GetCustomCommandPanel();
         base.NextPanel = nextPanel;
     }
     SqlDataSource component = (SqlDataSource) this._sqlDataSourceDesigner.Component;
     ArrayList dest = new ArrayList();
     ArrayList list2 = new ArrayList();
     ArrayList list3 = new ArrayList();
     ArrayList list4 = new ArrayList();
     this._sqlDataSourceDesigner.CopyList(component.SelectParameters, dest);
     this._sqlDataSourceDesigner.CopyList(component.InsertParameters, list2);
     this._sqlDataSourceDesigner.CopyList(component.UpdateParameters, list3);
     this._sqlDataSourceDesigner.CopyList(component.DeleteParameters, list4);
     nextPanel.SetQueries(this._dataConnection, new SqlDataSourceQuery(component.SelectCommand, component.SelectCommandType, dest), new SqlDataSourceQuery(component.InsertCommand, component.InsertCommandType, list2), new SqlDataSourceQuery(component.UpdateCommand, component.UpdateCommandType, list3), new SqlDataSourceQuery(component.DeleteCommand, component.DeleteCommandType, list4));
     return true;
 }
Ejemplo n.º 10
0
        private void UpdatePreview()
        {
            SqlDataSourceQuery selectQuery = this._tableQuery.GetSelectQuery();

            this._previewTextBox.Text = (selectQuery == null) ? string.Empty : selectQuery.Command;
        }
 public void SetQueries(DesignerDataConnection dataConnection, SqlDataSourceQuery selectQuery, SqlDataSourceQuery insertQuery, SqlDataSourceQuery updateQuery, SqlDataSourceQuery deleteQuery)
 {
     this._dataConnection = dataConnection;
     this._selectQuery = selectQuery;
     this._insertQuery = insertQuery;
     this._updateQuery = updateQuery;
     this._deleteQuery = deleteQuery;
     this._previewTextBox.Text = this._selectQuery.Command;
     Parameter[] array = new Parameter[this._selectQuery.Parameters.Count];
     this._selectQuery.Parameters.CopyTo(array, 0);
     Parameter[] parameters = MergeParameters(this._parameterEditorUserControl.GetParameters(), array);
     this._parameterEditorUserControl.ClearParameters();
     this._parameterEditorUserControl.AddParameters(parameters);
 }
 public override bool OnNext()
 {
     SqlDataSourceQuery selectQuery = new SqlDataSourceQuery(this._selectQuery.Command, this._selectQuery.CommandType, this._parameterEditorUserControl.GetParameters());
     SqlDataSourceSummaryPanel nextPanel = base.NextPanel as SqlDataSourceSummaryPanel;
     if (nextPanel == null)
     {
         nextPanel = ((SqlDataSourceWizardForm) base.ParentWizard).GetSummaryPanel();
         base.NextPanel = nextPanel;
     }
     nextPanel.SetQueries(this._dataConnection, selectQuery, this._insertQuery, this._updateQuery, this._deleteQuery);
     return true;
 }
 public SqlDataSourceQuery GetQuery()
 {
     SqlDataSourceQuery query;
     Cursor current = Cursor.Current;
     try
     {
         DbProviderFactory dbProviderFactory;
         Cursor.Current = Cursors.WaitCursor;
         if (this._sqlRadioButton.Checked)
         {
             SqlDataSourceCommandType text;
             ICollection is2;
             if (this._commandTextBox.Text.Trim().Length <= 0)
             {
                 return new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
             }
             if (string.Equals(this._commandTextBox.Text, this._originalCommand, StringComparison.OrdinalIgnoreCase))
             {
                 text = this._commandType;
             }
             else
             {
                 text = SqlDataSourceCommandType.Text;
             }
             dbProviderFactory = SqlDataSourceDesigner.GetDbProviderFactory(this._dataConnection.ProviderName);
             if ((this._editorMode == QueryBuilderMode.Select) || SqlDataSourceDesigner.SupportsNamedParameters(dbProviderFactory))
             {
                 Parameter[] c = this._sqlDataSourceDesigner.InferParameterNames(this._dataConnection, this._commandTextBox.Text, text);
                 if (c == null)
                 {
                     return null;
                 }
                 ArrayList list = new ArrayList(c);
                 is2 = this.MergeParameters(this._parameters, list, SqlDataSourceDesigner.SupportsNamedParameters(dbProviderFactory));
             }
             else
             {
                 is2 = this._parameters;
             }
             return new SqlDataSourceQuery(this._commandTextBox.Text, text, is2);
         }
         StoredProcedureItem selectedItem = this._storedProcedureComboBox.SelectedItem as StoredProcedureItem;
         if (selectedItem == null)
         {
             return new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]);
         }
         ArrayList newParameters = new ArrayList();
         ICollection is3 = null;
         try
         {
             is3 = selectedItem.DesignerDataStoredProcedure.Parameters;
         }
         catch (Exception exception)
         {
             UIServiceHelper.ShowError(this._sqlDataSourceDesigner.Component.Site, exception, System.Design.SR.GetString("SqlDataSourceCustomCommandEditor_CouldNotGetStoredProcedureSchema"));
             return null;
         }
         dbProviderFactory = SqlDataSourceDesigner.GetDbProviderFactory(this._dataConnection.ProviderName);
         if ((is3 != null) && (is3.Count > 0))
         {
             foreach (DesignerDataParameter parameter in is3)
             {
                 string name = SqlDataSourceDesigner.StripParameterPrefix(parameter.Name);
                 Parameter parameter2 = SqlDataSourceDesigner.CreateParameter(dbProviderFactory, name, parameter.DataType);
                 parameter2.Direction = parameter.Direction;
                 newParameters.Add(parameter2);
             }
         }
         ICollection parameters = this.MergeParameters(this._parameters, newParameters, SqlDataSourceDesigner.SupportsNamedParameters(dbProviderFactory));
         query = new SqlDataSourceQuery(selectedItem.DesignerDataStoredProcedure.Name, SqlDataSourceCommandType.StoredProcedure, parameters);
     }
     finally
     {
         Cursor.Current = current;
     }
     return query;
 }
 public void SetQuery(SqlDataSourceQuery query)
 {
     this._storedProcedureComboBox.SelectedIndex = -1;
     if (this._storedProcedures != null)
     {
         foreach (StoredProcedureItem item in this._storedProcedureComboBox.Items)
         {
             if (item.DesignerDataStoredProcedure.Name == query.Command)
             {
                 this._storedProcedureComboBox.SelectedItem = item;
                 break;
             }
         }
     }
     if (this._storedProcedureComboBox.SelectedIndex != -1)
     {
         this._sqlRadioButton.Checked = false;
         this._storedProcedureRadioButton.Checked = true;
     }
     else
     {
         this._sqlRadioButton.Checked = true;
         this._storedProcedureRadioButton.Checked = false;
         if (this._storedProcedureComboBox.Items.Count > 0)
         {
             this._storedProcedureComboBox.SelectedIndex = 0;
         }
     }
     if (!this._queryInitialized)
     {
         this._commandTextBox.Text = query.Command;
         this._originalCommand = query.Command;
         this._commandType = query.CommandType;
         this._parameters = query.Parameters;
         this._queryInitialized = true;
     }
     this.UpdateEnabledState();
 }
        public SqlDataSourceQuery GetQuery()
        {
            SqlDataSourceQuery query;
            Cursor             current = Cursor.Current;

            try
            {
                DbProviderFactory dbProviderFactory;
                Cursor.Current = Cursors.WaitCursor;
                if (this._sqlRadioButton.Checked)
                {
                    SqlDataSourceCommandType text;
                    ICollection is2;
                    if (this._commandTextBox.Text.Trim().Length <= 0)
                    {
                        return(new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]));
                    }
                    if (string.Equals(this._commandTextBox.Text, this._originalCommand, StringComparison.OrdinalIgnoreCase))
                    {
                        text = this._commandType;
                    }
                    else
                    {
                        text = SqlDataSourceCommandType.Text;
                    }
                    dbProviderFactory = SqlDataSourceDesigner.GetDbProviderFactory(this._dataConnection.ProviderName);
                    if ((this._editorMode == QueryBuilderMode.Select) || SqlDataSourceDesigner.SupportsNamedParameters(dbProviderFactory))
                    {
                        Parameter[] c = this._sqlDataSourceDesigner.InferParameterNames(this._dataConnection, this._commandTextBox.Text, text);
                        if (c == null)
                        {
                            return(null);
                        }
                        ArrayList list = new ArrayList(c);
                        is2 = this.MergeParameters(this._parameters, list, SqlDataSourceDesigner.SupportsNamedParameters(dbProviderFactory));
                    }
                    else
                    {
                        is2 = this._parameters;
                    }
                    return(new SqlDataSourceQuery(this._commandTextBox.Text, text, is2));
                }
                StoredProcedureItem selectedItem = this._storedProcedureComboBox.SelectedItem as StoredProcedureItem;
                if (selectedItem == null)
                {
                    return(new SqlDataSourceQuery(string.Empty, SqlDataSourceCommandType.Text, new Parameter[0]));
                }
                ArrayList   newParameters = new ArrayList();
                ICollection is3           = null;
                try
                {
                    is3 = selectedItem.DesignerDataStoredProcedure.Parameters;
                }
                catch (Exception exception)
                {
                    UIServiceHelper.ShowError(this._sqlDataSourceDesigner.Component.Site, exception, System.Design.SR.GetString("SqlDataSourceCustomCommandEditor_CouldNotGetStoredProcedureSchema"));
                    return(null);
                }
                dbProviderFactory = SqlDataSourceDesigner.GetDbProviderFactory(this._dataConnection.ProviderName);
                if ((is3 != null) && (is3.Count > 0))
                {
                    foreach (DesignerDataParameter parameter in is3)
                    {
                        string    name       = SqlDataSourceDesigner.StripParameterPrefix(parameter.Name);
                        Parameter parameter2 = SqlDataSourceDesigner.CreateParameter(dbProviderFactory, name, parameter.DataType);
                        parameter2.Direction = parameter.Direction;
                        newParameters.Add(parameter2);
                    }
                }
                ICollection parameters = this.MergeParameters(this._parameters, newParameters, SqlDataSourceDesigner.SupportsNamedParameters(dbProviderFactory));
                query = new SqlDataSourceQuery(selectedItem.DesignerDataStoredProcedure.Name, SqlDataSourceCommandType.StoredProcedure, parameters);
            }
            finally
            {
                Cursor.Current = current;
            }
            return(query);
        }
 public void SetQueries(DesignerDataConnection dataConnection, SqlDataSourceQuery selectQuery, SqlDataSourceQuery insertQuery, SqlDataSourceQuery updateQuery, SqlDataSourceQuery deleteQuery)
 {
     this._dataConnection = dataConnection;
     this._selectQuery = selectQuery;
     this._insertQuery = insertQuery;
     this._updateQuery = updateQuery;
     this._deleteQuery = deleteQuery;
     this._previewTextBox.Text = this._selectQuery.Command;
 }