public SqlDataSourceDataConnectionChooserPanel(SqlDataSourceDesigner sqlDataSourceDesigner, IDataEnvironment dataEnvironment) : base(sqlDataSourceDesigner)
        {
            this._sqlDataSourceDesigner = sqlDataSourceDesigner;
            this._sqlDataSource         = (SqlDataSource)this._sqlDataSourceDesigner.Component;
            this._dataEnvironment       = dataEnvironment;
            this.InitializeComponent();
            this.InitializeUI();
            DesignerDataConnection conn    = new DesignerDataConnection(System.Design.SR.GetString("SqlDataSourceDataConnectionChooserPanel_CustomConnectionName"), this._sqlDataSource.ProviderName, this._sqlDataSource.ConnectionString);
            ExpressionBinding      binding = this._sqlDataSource.Expressions["ConnectionString"];

            if ((binding != null) && string.Equals(binding.ExpressionPrefix, "ConnectionStrings", StringComparison.OrdinalIgnoreCase))
            {
                string expression = binding.Expression;
                string str2       = "." + "ConnectionString".ToLowerInvariant();
                if (expression.ToLowerInvariant().EndsWith(str2, StringComparison.Ordinal))
                {
                    expression = expression.Substring(0, expression.Length - str2.Length);
                }
                ICollection connections = this._dataEnvironment.Connections;
                if (connections != null)
                {
                    foreach (DesignerDataConnection connection2 in connections)
                    {
                        if (connection2.IsConfigured && string.Equals(connection2.Name, expression, StringComparison.OrdinalIgnoreCase))
                        {
                            conn = connection2;
                            break;
                        }
                    }
                }
            }
            this.SetConnectionSettings(conn);
        }
 private void SaveSchema(DesignerDataConnection connection, string selectCommand, DataTable schemaTable)
 {
     base.DesignerState["DataSourceSchema"] = schemaTable;
     base.DesignerState["DataSourceSchemaConnectionStringHash"] = connection.ConnectionString.GetHashCode();
     base.DesignerState["DataSourceSchemaProviderName"]         = connection.ProviderName;
     base.DesignerState["DataSourceSchemaSelectMethod"]         = selectCommand;
 }
 private bool SelectConnection(DesignerDataConnection conn)
 {
     if (conn.IsConfigured)
     {
         foreach (DataConnectionItem item in this._connectionsComboBox.Items)
         {
             DesignerDataConnection designerDataConnection = item.DesignerDataConnection;
             if (designerDataConnection.IsConfigured && (designerDataConnection.Name == conn.Name))
             {
                 this._connectionsComboBox.SelectedItem = item;
                 return(true);
             }
         }
     }
     else
     {
         foreach (DataConnectionItem item2 in this._connectionsComboBox.Items)
         {
             DesignerDataConnection connection2 = item2.DesignerDataConnection;
             if (!connection2.IsConfigured && SqlDataSourceDesigner.ConnectionsEqual(connection2, conn))
             {
                 this._connectionsComboBox.SelectedItem = item2;
                 return(true);
             }
         }
     }
     return(false);
 }
        public override bool OnNext()
        {
            if (!base.CheckValidProvider())
            {
                return(false);
            }
            DesignerDataConnection dataConnection = this.DataConnection;

            if (!dataConnection.IsConfigured)
            {
                this._needsToPersistConnectionInfo = false;
                SqlDataSourceSaveConfiguredConnectionPanel nextPanel = base.NextPanel as SqlDataSourceSaveConfiguredConnectionPanel;
                if (nextPanel == null)
                {
                    nextPanel      = ((SqlDataSourceWizardForm)base.ParentWizard).GetSaveConfiguredConnectionPanel();
                    base.NextPanel = nextPanel;
                }
                if (!SqlDataSourceDesigner.ConnectionsEqual(dataConnection, nextPanel.CurrentConnection))
                {
                    nextPanel.SetConnectionInfo(dataConnection);
                }
                return(true);
            }
            this._needsToPersistConnectionInfo = true;
            return(base.OnNext());
        }
 public SqlDataSourceOrderClause(DesignerDataConnection designerDataConnection, DesignerDataTableBase designerDataTable, System.ComponentModel.Design.Data.DesignerDataColumn designerDataColumn, bool isDescending)
 {
     this._designerDataConnection = designerDataConnection;
     this._designerDataTable      = designerDataTable;
     this._designerDataColumn     = designerDataColumn;
     this._isDescending           = isDescending;
 }
Beispiel #6
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 SqlDataSourceFilterClause(DesignerDataConnection designerDataConnection, DesignerDataTableBase designerDataTable, System.ComponentModel.Design.Data.DesignerDataColumn designerDataColumn, string operatorFormat, bool isBinary, string value, System.Web.UI.WebControls.Parameter parameter)
 {
     this._designerDataConnection = designerDataConnection;
     this._designerDataTable      = designerDataTable;
     this._designerDataColumn     = designerDataColumn;
     this._isBinary       = isBinary;
     this._operatorFormat = operatorFormat;
     this._value          = value;
     this._parameter      = parameter;
 }
        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 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);
 }
        internal bool RefreshSchema(DesignerDataConnection connection, string commandText, SqlDataSourceCommandType commandType, ParameterCollection parameters, bool preferSilent)
        {
            IServiceProvider site    = this.SqlDataSource.Site;
            DbCommand        command = null;

            try
            {
                DbProviderFactory dbProviderFactory    = GetDbProviderFactory(connection.ProviderName);
                DbConnection      designTimeConnection = GetDesignTimeConnection(base.Component.Site, connection);
                if (designTimeConnection == null)
                {
                    if (!preferSilent)
                    {
                        UIServiceHelper.ShowError(this.SqlDataSource.Site, System.Design.SR.GetString("SqlDataSourceDesigner_CouldNotCreateConnection"));
                    }
                    return(false);
                }
                command = this.BuildSelectCommand(dbProviderFactory, designTimeConnection, commandText, parameters, commandType);
                DbDataAdapter adapter = CreateDataAdapter(dbProviderFactory, command);
                adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                DataSet dataSet = new DataSet();
                adapter.FillSchema(dataSet, SchemaType.Source, "DefaultView");
                DataTable schemaTable = dataSet.Tables["DefaultView"];
                if (schemaTable == null)
                {
                    if (!preferSilent)
                    {
                        UIServiceHelper.ShowError(site, System.Design.SR.GetString("SqlDataSourceDesigner_CannotGetSchema"));
                    }
                    return(false);
                }
                this.SaveSchema(connection, commandText, schemaTable);
                return(true);
            }
            catch (Exception exception)
            {
                if (!preferSilent)
                {
                    UIServiceHelper.ShowError(site, exception, System.Design.SR.GetString("SqlDataSourceDesigner_CannotGetSchema"));
                }
            }
            finally
            {
                if ((command != null) && (command.Connection.State == ConnectionState.Open))
                {
                    command.Connection.Close();
                }
            }
            return(false);
        }
        internal static bool ConnectionsEqual(DesignerDataConnection connection1, DesignerDataConnection connection2)
        {
            if ((connection1 == null) || (connection2 == null))
            {
                return(false);
            }
            if (connection1.ConnectionString != connection2.ConnectionString)
            {
                return(false);
            }
            string str  = (connection1.ProviderName.Trim().Length == 0) ? "System.Data.SqlClient" : connection1.ProviderName;
            string str2 = (connection2.ProviderName.Trim().Length == 0) ? "System.Data.SqlClient" : connection2.ProviderName;

            return(str == str2);
        }
        protected bool CheckValidProvider()
        {
            DesignerDataConnection dataConnection = this.DataConnection;

            try
            {
                SqlDataSourceDesigner.GetDbProviderFactory(dataConnection.ProviderName);
                return(true);
            }
            catch (Exception exception)
            {
                UIServiceHelper.ShowError(base.ServiceProvider, exception, System.Design.SR.GetString("SqlDataSourceConnectionPanel_ProviderNotFound", new object[] { dataConnection.ProviderName }));
                return(false);
            }
        }
 internal static DbConnection GetDesignTimeConnection(IServiceProvider serviceProvider, DesignerDataConnection connection)
 {
     if (serviceProvider != null)
     {
         IDataEnvironment service = (IDataEnvironment)serviceProvider.GetService(typeof(IDataEnvironment));
         if (service != null)
         {
             if (string.IsNullOrEmpty(connection.ProviderName))
             {
                 connection = new DesignerDataConnection(connection.Name, "System.Data.SqlClient", connection.ConnectionString);
             }
             return(service.GetDesignTimeConnection(connection));
         }
     }
     return(null);
 }
        private void SetConnectionSettings(DesignerDataConnection conn)
        {
            bool   flag             = this.SelectConnection(conn);
            string providerName     = conn.ProviderName;
            string connectionString = conn.ConnectionString;

            if (!flag && ((providerName.Length > 0) || (connectionString.Length > 0)))
            {
                if (providerName.Length == 0)
                {
                    providerName = "System.Data.SqlClient";
                }
                this._connectionsComboBox.Items.Insert(0, new DataConnectionItem(new DesignerDataConnection(conn.Name, providerName, connectionString)));
                this._connectionsComboBox.SelectedIndex = 0;
                this._connectionsComboBox.InvalidateDropDownWidth();
            }
            this._connectionStringTextBox.Text = connectionString;
        }
            public static string GetConnectionName(DesignerDataConnection connection)
            {
                DbConnectionStringBuilder connectionStringBuilder = SqlDataSourceDesigner.GetDbProviderFactory(connection.ProviderName).CreateConnectionStringBuilder();

                if (connectionStringBuilder == null)
                {
                    connectionStringBuilder = new DbConnectionStringBuilder();
                }
                string str = null;

                try
                {
                    object obj2;
                    connectionStringBuilder.ConnectionString = connection.ConnectionString;
                    if (IsLocalDbFileConnectionString(connection.ProviderName, connectionStringBuilder))
                    {
                        string filePathKey = GetFilePathKey(connection.ProviderName, connectionStringBuilder);
                        if (!string.IsNullOrEmpty(filePathKey))
                        {
                            string str3 = connectionStringBuilder[filePathKey] as string;
                            if (!string.IsNullOrEmpty(str3))
                            {
                                str = Path.GetFileNameWithoutExtension(str3) + "ConnectionString";
                            }
                        }
                    }
                    if ((str == null) && connectionStringBuilder.TryGetValue("Database", out obj2))
                    {
                        string s = obj2 as string;
                        if (!StringIsEmpty(s))
                        {
                            str = s + "ConnectionString";
                        }
                    }
                }
                catch
                {
                }
                if (str == null)
                {
                    str = "ConnectionString";
                }
                return(str.Trim());
            }
        private void OnNewConnectionButtonClick(object sender, EventArgs e)
        {
            DesignerDataConnection conn = this._dataEnvironment.BuildConnection(this, null);

            if (conn != null)
            {
                if (string.Equals(conn.ProviderName, "Microsoft.SqlServerCe.Client.4.0", StringComparison.OrdinalIgnoreCase))
                {
                    conn = new DesignerDataConnection(conn.Name, "System.Data.SqlServerCe.4.0", conn.ConnectionString, conn.IsConfigured);
                }
                if (!this.SelectConnection(conn))
                {
                    DataConnectionItem item = new DataConnectionItem(conn);
                    this._connectionsComboBox.Items.Add(item);
                    this._connectionsComboBox.SelectedItem = item;
                    this._connectionsComboBox.InvalidateDropDownWidth();
                }
            }
        }
        protected override void SetProviderName(object instance, DesignerDataConnection connection)
        {
            SqlDataSource component = instance as SqlDataSource;

            if (component != null)
            {
                if (connection.IsConfigured)
                {
                    ExpressionEditor expressionEditor = ExpressionEditor.GetExpressionEditor(typeof(ConnectionStringsExpressionBuilder), component.Site);
                    if (expressionEditor != null)
                    {
                        string expressionPrefix = expressionEditor.ExpressionPrefix;
                        component.Expressions.Add(new ExpressionBinding("ProviderName", typeof(string), expressionPrefix, connection.Name + ".ProviderName"));
                    }
                }
                else
                {
                    TypeDescriptor.GetProperties(component)["ProviderName"].SetValue(component, connection.ProviderName);
                }
            }
        }
        protected internal override void OnComplete()
        {
            DesignerDataConnection dataConnection = this._dataConnection;

            if (this._saveCheckBox.Checked)
            {
                try
                {
                    dataConnection = this._dataEnvironment.ConfigureConnection(this, this._dataConnection, this._nameTextBox.Text.Trim());
                }
                catch (Exception exception)
                {
                    if (exception != CheckoutException.Canceled)
                    {
                        UIServiceHelper.ShowError(base.ServiceProvider, exception, System.Design.SR.GetString("SqlDataSourceSaveConfiguredConnectionPanel_CouldNotSaveConnection"));
                    }
                }
            }
            PersistConnectionSettings(this._sqlDataSource, this._sqlDataSourceDesigner, dataConnection);
            this._sqlDataSourceDesigner.SaveConfiguredConnectionState = dataConnection.IsConfigured;
        }
Beispiel #19
0
        public SqlDataSourceQueryEditorForm(IServiceProvider serviceProvider, SqlDataSourceDesigner sqlDataSourceDesigner, string providerName, string connectionString, DataSourceOperation operation, SqlDataSourceCommandType commandType, string command, IList originalParameters) : base(serviceProvider)
        {
            this._sqlDataSourceDesigner = sqlDataSourceDesigner;
            this.InitializeComponent();
            this.InitializeUI();
            if (string.IsNullOrEmpty(providerName))
            {
                providerName = "System.Data.SqlClient";
            }
            this._dataConnection      = new DesignerDataConnection(string.Empty, providerName, connectionString);
            this._commandType         = commandType;
            this._commandTextBox.Text = command;
            this._originalParameters  = originalParameters;
            string str = Enum.GetName(typeof(DataSourceOperation), operation).ToUpperInvariant();

            this._commandLabel.Text = System.Design.SR.GetString("SqlDataSourceQueryEditorForm_CommandLabel", new object[] { str });
            ArrayList dest = new ArrayList(originalParameters.Count);

            sqlDataSourceDesigner.CopyList(originalParameters, dest);
            this._parameterEditorUserControl.AddParameters((Parameter[])dest.ToArray(typeof(Parameter)));
            this._commandTextBox.Select(0, 0);
            switch (operation)
            {
            case DataSourceOperation.Delete:
                this._queryBuilderMode = QueryBuilderMode.Delete;
                return;

            case DataSourceOperation.Insert:
                this._queryBuilderMode = QueryBuilderMode.Insert;
                return;

            case DataSourceOperation.Select:
                this._queryBuilderMode = QueryBuilderMode.Select;
                return;

            case DataSourceOperation.Update:
                this._queryBuilderMode = QueryBuilderMode.Update;
                return;
            }
        }
        internal static string EscapeObjectName(DesignerDataConnection connection, string objectName)
        {
            string str  = "[";
            string str2 = "]";

            try
            {
                DbProviderFactory dbProviderFactory = SqlDataSourceDesigner.GetDbProviderFactory(connection.ProviderName);
                DbCommandBuilder  builder           = dbProviderFactory.CreateCommandBuilder();
                if (dbProviderFactory == OracleClientFactory.Instance)
                {
                    str = str2 = "\"";
                }
                builder.QuotePrefix = str;
                builder.QuoteSuffix = str2;
                return(builder.QuoteIdentifier(objectName));
            }
            catch (Exception)
            {
                return(str + objectName + str2);
            }
        }
        public void SetConnectionInfo(DesignerDataConnection dataConnection)
        {
            this._dataConnection = dataConnection;
            this.ResetUI();
            bool saveConfiguredConnectionState = this._sqlDataSourceDesigner.SaveConfiguredConnectionState;
            DesignerDataConnection connection  = new DesignerDataConnection(string.Empty, this._sqlDataSourceDesigner.ProviderName, this._sqlDataSourceDesigner.ConnectionString);

            if (SqlDataSourceDesigner.ConnectionsEqual(dataConnection, connection))
            {
                if (!saveConfiguredConnectionState)
                {
                    this._saveCheckBox.Checked = false;
                }
                if (this._nameTextBox.Text.Length == 0)
                {
                    this._nameTextBox.Text = this.CreateDefaultConnectionName();
                }
            }
            else
            {
                this._nameTextBox.Text = this.CreateDefaultConnectionName();
            }
        }
        internal DataTable LoadSchema()
        {
            if (!this._forceSchemaRetrieval)
            {
                object obj2 = base.DesignerState["DataSourceSchemaConnectionStringHash"];
                string str  = base.DesignerState["DataSourceSchemaProviderName"] as string;
                string a    = base.DesignerState["DataSourceSchemaSelectMethod"] as string;
                if (string.IsNullOrEmpty(str))
                {
                    str = "System.Data.SqlClient";
                }
                if (string.IsNullOrEmpty(this.ConnectionString))
                {
                    return(null);
                }
                DesignerDataConnection connection = new DesignerDataConnection(string.Empty, this.ProviderName, this.ConnectionString);
                int    hashCode      = connection.ConnectionString.GetHashCode();
                string providerName  = connection.ProviderName;
                string selectCommand = this.SelectCommand;
                if (string.IsNullOrEmpty(providerName))
                {
                    providerName = "System.Data.SqlClient";
                }
                if (((obj2 == null) || (((int)obj2) != hashCode)) || (!string.Equals(str, providerName, StringComparison.OrdinalIgnoreCase) || !string.Equals(a, selectCommand, StringComparison.Ordinal)))
                {
                    return(null);
                }
            }
            DataTable table = base.DesignerState["DataSourceSchema"] as DataTable;

            if (table != null)
            {
                table.TableName = "DefaultView";
                return(table);
            }
            return(null);
        }
        private void OnQueryBuilderButtonClick(object sender, EventArgs e)
        {
            IServiceProvider site = this._sqlDataSourceDesigner.Component.Site;

            if ((this._dataConnection.ConnectionString != null) && (this._dataConnection.ConnectionString.Trim().Length == 0))
            {
                UIServiceHelper.ShowError(site, System.Design.SR.GetString("SqlDataSourceCustomCommandEditor_NoConnectionString"));
            }
            else
            {
                DesignerDataConnection connection = this._dataConnection;
                if (string.IsNullOrEmpty(this._dataConnection.ProviderName))
                {
                    connection = new DesignerDataConnection(this._dataConnection.Name, "System.Data.SqlClient", this._dataConnection.ConnectionString, this._dataConnection.IsConfigured);
                }
                string str = this._dataEnvironment.BuildQuery(this, connection, this._editorMode, this._commandTextBox.Text);
                if ((str != null) && (str.Length > 0))
                {
                    this._commandTextBox.Text = str;
                    this._commandTextBox.Focus();
                    this._commandTextBox.Select(0, 0);
                }
            }
        }
 internal static void PersistConnectionSettings(SqlDataSource sqlDataSource, SqlDataSourceDesigner sqlDataSourceDesigner, DesignerDataConnection dataConnection)
 {
     if (dataConnection.IsConfigured)
     {
         ExpressionBindingCollection expressions = sqlDataSource.Expressions;
         PropertyDescriptor          descriptor  = TypeDescriptor.GetProperties(sqlDataSource)["ProviderName"];
         descriptor.ResetValue(sqlDataSource);
         if (dataConnection.ProviderName != "System.Data.SqlClient")
         {
             expressions.Add(new ExpressionBinding(descriptor.Name, descriptor.PropertyType, "ConnectionStrings", dataConnection.Name + ".ProviderName"));
         }
         descriptor = TypeDescriptor.GetProperties(sqlDataSource)["ConnectionString"];
         descriptor.ResetValue(sqlDataSource);
         expressions.Add(new ExpressionBinding(descriptor.Name, descriptor.PropertyType, "ConnectionStrings", dataConnection.Name));
     }
     else
     {
         PropertyDescriptor descriptor2;
         if (sqlDataSource.ProviderName != dataConnection.ProviderName)
         {
             descriptor2 = TypeDescriptor.GetProperties(sqlDataSource)["ProviderName"];
             descriptor2.ResetValue(sqlDataSource);
             descriptor2.SetValue(sqlDataSource, dataConnection.ProviderName);
         }
         if (sqlDataSource.ConnectionString != dataConnection.ConnectionString)
         {
             descriptor2 = TypeDescriptor.GetProperties(sqlDataSource)["ConnectionString"];
             descriptor2.ResetValue(sqlDataSource);
             descriptor2.SetValue(sqlDataSource, dataConnection.ConnectionString);
         }
     }
 }
 protected virtual void SetProviderName(object instance, DesignerDataConnection connection)
 {
     throw new NotImplementedException();
 }
 public override void RefreshSchema(bool preferSilent)
 {
     try
     {
         this.SuppressDataSourceEvents();
         bool             flag = false;
         IServiceProvider site = this.SqlDataSource.Site;
         if (!this.CanRefreshSchema)
         {
             if (!preferSilent)
             {
                 UIServiceHelper.ShowError(site, System.Design.SR.GetString("SqlDataSourceDesigner_RefreshSchemaRequiresSettings"));
             }
         }
         else
         {
             IDataSourceViewSchema schema = this.GetView("DefaultView").Schema;
             bool flag2 = false;
             if (schema == null)
             {
                 this._forceSchemaRetrieval = true;
                 schema = this.GetView("DefaultView").Schema;
                 this._forceSchemaRetrieval = false;
                 flag2 = true;
             }
             DesignerDataConnection connection = new DesignerDataConnection(string.Empty, this.ProviderName, this.ConnectionString);
             if (preferSilent)
             {
                 flag = this.RefreshSchema(connection, this.SelectCommand, this.SqlDataSource.SelectCommandType, this.SqlDataSource.SelectParameters, true);
             }
             else
             {
                 Parameter[] parameterArray = this.InferParameterNames(connection, this.SelectCommand, this.SqlDataSource.SelectCommandType);
                 if (parameterArray == null)
                 {
                     return;
                 }
                 ParameterCollection parameters  = new ParameterCollection();
                 ParameterCollection parameters2 = new ParameterCollection();
                 foreach (ICloneable cloneable in this.SqlDataSource.SelectParameters)
                 {
                     parameters2.Add((Parameter)cloneable.Clone());
                 }
                 foreach (Parameter parameter in parameterArray)
                 {
                     if ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput))
                     {
                         Parameter parameter2 = parameters2[parameter.Name];
                         if (parameter2 != null)
                         {
                             parameter.DefaultValue = parameter2.DefaultValue;
                             if ((parameter.DbType == DbType.Object) && (parameter.Type == TypeCode.Empty))
                             {
                                 parameter.DbType = parameter2.DbType;
                                 parameter.Type   = parameter2.Type;
                             }
                             parameters2.Remove(parameter2);
                         }
                         parameters.Add(parameter);
                     }
                 }
                 if (parameters.Count > 0)
                 {
                     SqlDataSourceRefreshSchemaForm form = new SqlDataSourceRefreshSchemaForm(site, this, parameters);
                     flag = UIServiceHelper.ShowDialog(site, form) == DialogResult.OK;
                 }
                 else
                 {
                     flag = this.RefreshSchema(connection, this.SelectCommand, this.SqlDataSource.SelectCommandType, parameters, false);
                 }
             }
             if (flag)
             {
                 IDataSourceViewSchema schema2 = this.GetView("DefaultView").Schema;
                 if (flag2 && DataSourceDesigner.ViewSchemasEquivalent(schema, schema2))
                 {
                     this.OnDataSourceChanged(EventArgs.Empty);
                 }
                 else if (!DataSourceDesigner.ViewSchemasEquivalent(schema, schema2))
                 {
                     this.OnSchemaRefreshed(EventArgs.Empty);
                 }
             }
         }
     }
     finally
     {
         this.ResumeDataSourceEvents();
     }
 }
        protected internal virtual Parameter[] InferParameterNames(DesignerDataConnection connection, string commandText, SqlDataSourceCommandType commandType)
        {
            Parameter[] parameterArray2;
            Cursor      current = Cursor.Current;

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                if (commandText.Length == 0)
                {
                    UIServiceHelper.ShowError(this.SqlDataSource.Site, System.Design.SR.GetString("SqlDataSourceDesigner_NoCommand"));
                    return(null);
                }
                if (commandType == SqlDataSourceCommandType.Text)
                {
                    return(SqlDataSourceParameterParser.ParseCommandText(connection.ProviderName, commandText));
                }
                DbProviderFactory dbProviderFactory    = GetDbProviderFactory(connection.ProviderName);
                DbConnection      designTimeConnection = null;
                try
                {
                    designTimeConnection = GetDesignTimeConnection(base.Component.Site, connection);
                }
                catch (Exception exception)
                {
                    if (designTimeConnection == null)
                    {
                        UIServiceHelper.ShowError(this.SqlDataSource.Site, exception, System.Design.SR.GetString("SqlDataSourceDesigner_CouldNotCreateConnection"));
                        return(null);
                    }
                }
                if (designTimeConnection == null)
                {
                    UIServiceHelper.ShowError(this.SqlDataSource.Site, System.Design.SR.GetString("SqlDataSourceDesigner_CouldNotCreateConnection"));
                    return(null);
                }
                DbCommand command = this.BuildSelectCommand(dbProviderFactory, designTimeConnection, commandText, null, commandType);
                command.CommandType = CommandType.StoredProcedure;
                try
                {
                    this.DeriveParameters(connection.ProviderName, command);
                }
                catch (Exception exception2)
                {
                    UIServiceHelper.ShowError(this.SqlDataSource.Site, System.Design.SR.GetString("SqlDataSourceDesigner_InferStoredProcedureError", new object[] { exception2.Message }));
                    return(null);
                }
                finally
                {
                    if (command.Connection.State == ConnectionState.Open)
                    {
                        designTimeConnection.Close();
                    }
                }
                int         count          = command.Parameters.Count;
                Parameter[] parameterArray = new Parameter[count];
                for (int i = 0; i < count; i++)
                {
                    IDataParameter parameter = command.Parameters[i];
                    if (parameter != null)
                    {
                        string name = StripParameterPrefix(parameter.ParameterName);
                        parameterArray[i]           = CreateParameter(dbProviderFactory, name, parameter.DbType);
                        parameterArray[i].Direction = parameter.Direction;
                    }
                }
                parameterArray2 = parameterArray;
            }
            finally
            {
                Cursor.Current = current;
            }
            return(parameterArray2);
        }
 protected virtual void SetProviderName(object instance, DesignerDataConnection connection)
 {
 }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            System.Web.UI.Control instance = context.Instance as System.Web.UI.Control;
            if (provider != null)
            {
                IDataEnvironment environment = (IDataEnvironment)provider.GetService(typeof(IDataEnvironment));
                if (environment != null)
                {
                    IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                    if ((edSvc != null) && (context.Instance != null))
                    {
                        if (this._connectionStringPicker == null)
                        {
                            this._connectionStringPicker = new ConnectionStringPicker();
                        }
                        string           connectionString = (string)value;
                        ExpressionEditor expressionEditor = ExpressionEditor.GetExpressionEditor(typeof(ConnectionStringsExpressionBuilder), provider);
                        if (expressionEditor == null)
                        {
                            return(value);
                        }
                        string expressionPrefix = expressionEditor.ExpressionPrefix;
                        DesignerDataConnection currentConnection = GetCurrentConnection(instance, context.PropertyDescriptor.Name, connectionString, expressionPrefix);
                        this._connectionStringPicker.Start(edSvc, environment.Connections, currentConnection);
                        edSvc.DropDownControl(this._connectionStringPicker);
                        if (this._connectionStringPicker.SelectedItem != null)
                        {
                            DesignerDataConnection selectedConnection = this._connectionStringPicker.SelectedConnection;
                            if (selectedConnection == null)
                            {
                                selectedConnection = environment.BuildConnection(UIServiceHelper.GetDialogOwnerWindow(provider), null);
                            }
                            if (selectedConnection != null)
                            {
                                if (selectedConnection.IsConfigured)
                                {
                                    ((IExpressionsAccessor)instance).Expressions.Add(new ExpressionBinding(context.PropertyDescriptor.Name, context.PropertyDescriptor.PropertyType, expressionPrefix, selectedConnection.Name));
                                    this.SetProviderName(context.Instance, selectedConnection);
                                    IComponentChangeService service = (IComponentChangeService)provider.GetService(typeof(IComponentChangeService));
                                    if (service != null)
                                    {
                                        service.OnComponentChanged(instance, null, null, null);
                                    }
                                }
                                else
                                {
                                    value = selectedConnection.ConnectionString;
                                    this.SetProviderName(context.Instance, selectedConnection);
                                }
                            }
                        }
                        this._connectionStringPicker.End();
                    }
                    return(value);
                }
            }
            string providerName = this.GetProviderName(context.Instance);
            ConnectionStringEditorDialog form = new ConnectionStringEditorDialog(provider, providerName)
            {
                ConnectionString = (string)value
            };

            if (UIServiceHelper.ShowDialog(provider, form) == DialogResult.OK)
            {
                value = form.ConnectionString;
            }
            return(value);
        }
            public void Start(IWindowsFormsEditorService edSvc, ICollection connections, DesignerDataConnection currentConnection)
            {
                this._edSvc = edSvc;
                base.Items.Clear();
                object obj2 = null;

                foreach (DesignerDataConnection connection in connections)
                {
                    DataConnectionItem item = new DataConnectionItem(connection);
                    if ((connection.ConnectionString == currentConnection.ConnectionString) && (connection.IsConfigured == currentConnection.IsConfigured))
                    {
                        obj2 = item;
                    }
                    base.Items.Add(item);
                }
                base.Items.Add(new DataConnectionItem());
                base.SelectedItem = obj2;
            }