protected virtual void OnFiltering(SqlDataSourceFilteringEventArgs e)
        {
            SqlDataSourceFilteringEventHandler handler = base.Events[EventFiltering] as SqlDataSourceFilteringEventHandler;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemplo n.º 2
0
        protected virtual void OnFiltering(SqlDataSourceFilteringEventArgs e)
        {
            if (!HasEvents())
            {
                return;
            }
            SqlDataSourceFilteringEventHandler h = Events [EventFiltering] as SqlDataSourceFilteringEventHandler;

            if (h != null)
            {
                h(this, e);
            }
        }
Exemplo n.º 3
0
 protected void CourseIndexDataSource_Filtering(object sender, SqlDataSourceFilteringEventArgs e)
 {
     if (e.ParameterValues[1] != null)
     {
         //防注入,替换四个关键key
         // e.ParameterValues[1].ToString().Replace("'", "''");
         e.ParameterValues[1] = e.ParameterValues[1].ToString().Replace("'", "''");
         e.ParameterValues[1] = e.ParameterValues[1].ToString().Replace("[", "[[]");
         e.ParameterValues[1] = e.ParameterValues[1].ToString().Replace("%", "[%]");
         e.ParameterValues[1] = e.ParameterValues[1].ToString().Replace("_", "[_]");
         /*
         AdminNewsListDataSource.FilterExpression.Replace("{1}", e.ParameterValues[1].ToString().Replace("[", "[[]"));
         AdminNewsListDataSource.FilterExpression.Replace("{1}", e.ParameterValues[1].ToString().Replace("%", "[%]"));
         AdminNewsListDataSource.FilterExpression.Replace("{1}", e.ParameterValues[1].ToString().Replace("_", "[_]"));
         */
     }
 }
Exemplo n.º 4
0
 protected void UserStatisticalDataSource_Filtering(object sender, SqlDataSourceFilteringEventArgs e)
 {
     if (e.ParameterValues[0].ToString().Equals("all"))
     {
         e.ParameterValues[0] = null;
         return;
     }
     if (e.ParameterValues[1] != null)
     {
         //防注入,替换四个关键key
         // e.ParameterValues[1].ToString().Replace("'", "''");
         e.ParameterValues[1] = e.ParameterValues[1].ToString().Replace("'", "''");
         e.ParameterValues[1] = e.ParameterValues[1].ToString().Replace("[", "[[]");
         e.ParameterValues[1] = e.ParameterValues[1].ToString().Replace("%", "[%]");
         e.ParameterValues[1] = e.ParameterValues[1].ToString().Replace("_", "[_]");
         /*
         AdminNewsListDataSource.FilterExpression.Replace("{1}", e.ParameterValues[1].ToString().Replace("[", "[[]"));
         AdminNewsListDataSource.FilterExpression.Replace("{1}", e.ParameterValues[1].ToString().Replace("%", "[%]"));
         AdminNewsListDataSource.FilterExpression.Replace("{1}", e.ParameterValues[1].ToString().Replace("_", "[_]"));
         */
     }
 }
 protected virtual new void OnFiltering(SqlDataSourceFilteringEventArgs e)
 {
 }
		protected virtual void OnFiltering (SqlDataSourceFilteringEventArgs e)
		{
			if (!HasEvents ()) return;
			SqlDataSourceFilteringEventHandler h = Events [EventFiltering] as SqlDataSourceFilteringEventHandler;
			if (h != null)
				h (this, e);
		}
		protected internal override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
		{
			if (SortParameterName.Length > 0 && SelectCommandType == SqlDataSourceCommandType.Text)
				throw new NotSupportedException ("The SortParameterName property is only supported with stored procedure commands in SqlDataSource");

			if (arguments.SortExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
				throw new NotSupportedException ("SqlDataSource cannot sort. Set DataSourceMode to DataSet to enable sorting.");

			if (arguments.StartRowIndex > 0 || arguments.MaximumRows > 0)
				throw new NotSupportedException ("SqlDataSource does not have paging enabled. Set the DataSourceMode to DataSet to enable paging.");

			if (FilterExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
				throw new NotSupportedException ("SqlDataSource only supports filtering when the data source's DataSourceMode is set to DataSet.");

			InitConnection ();

			DbCommand command = factory.CreateCommand ();
			command.CommandText = SelectCommand;
			command.Connection = connection;
			if (SelectCommandType == SqlDataSourceCommandType.Text)
				command.CommandType = CommandType.Text;
			else {
				command.CommandType = CommandType.StoredProcedure;
				if (SortParameterName.Length > 0 && arguments.SortExpression.Length > 0)
					command.Parameters.Add (CreateDbParameter (SortParameterName, arguments.SortExpression));
			}

			if (SelectParameters.Count > 0)
				InitializeParameters (command, SelectParameters, null, null, false);

			Exception exception = null;
			if (owner.DataSourceMode == SqlDataSourceMode.DataSet) {
				DataView dataView = null;

				if (owner.EnableCaching)
					dataView = (DataView) owner.Cache.GetCachedObject (SelectCommand, SelectParameters);

				if (dataView == null) {
					SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
					OnSelecting (selectingArgs);
					if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
						return null;
					}
					try {
						DbDataAdapter adapter = factory.CreateDataAdapter ();
						DataSet dataset = new DataSet ();

						adapter.SelectCommand = command;
						adapter.Fill (dataset, name);

						dataView = dataset.Tables [0].DefaultView;
						if (dataView == null)
							throw new InvalidOperationException ();
					}
					catch (Exception e) {
						exception = e;
					}
					int rowsAffected = (dataView == null) ? 0 : dataView.Count;
					SqlDataSourceStatusEventArgs selectedArgs = new SqlDataSourceStatusEventArgs (command, rowsAffected, exception);
					OnSelected (selectedArgs);

					if (exception != null && !selectedArgs.ExceptionHandled)
						throw exception;

					if (owner.EnableCaching)
						owner.Cache.SetCachedObject (SelectCommand, selectParameters, dataView);
				}

				if (SortParameterName.Length == 0 || SelectCommandType == SqlDataSourceCommandType.Text)
					dataView.Sort = arguments.SortExpression;

				if (FilterExpression.Length > 0) {
					IOrderedDictionary fparams = FilterParameters.GetValues (context, owner);
					SqlDataSourceFilteringEventArgs fargs = new SqlDataSourceFilteringEventArgs (fparams);
					OnFiltering (fargs);
					if (!fargs.Cancel) {
						object [] formatValues = new object [fparams.Count];
						for (int n = 0; n < formatValues.Length; n++) {
							formatValues [n] = fparams [n];
							if (formatValues [n] == null) return dataView;
						}
						dataView.RowFilter = string.Format (FilterExpression, formatValues);
					}
				}

				return dataView;
			}
			else {
				SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs (command, arguments);
				OnSelecting (selectingArgs);
				if (selectingArgs.Cancel || !PrepareNullParameters (command, CancelSelectOnNullParameter)) {
					return null;
				}

				DbDataReader reader = null;
				bool closed = connection.State == ConnectionState.Closed;

				if (closed)
					connection.Open ();
				try {
					reader = command.ExecuteReader (closed ? CommandBehavior.CloseConnection : CommandBehavior.Default);
				}
				catch (Exception e) {
					exception = e;
				}
				SqlDataSourceStatusEventArgs selectedArgs =
					new SqlDataSourceStatusEventArgs (command, reader.RecordsAffected, exception);
				OnSelected (selectedArgs);
				if (exception != null && !selectedArgs.ExceptionHandled)
					throw exception;

				return reader;
			}
		}
Exemplo n.º 8
0
        protected internal override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            if (SortParameterName.Length > 0 && SelectCommandType == SqlDataSourceCommandType.Text)
            {
                throw new NotSupportedException("The SortParameterName property is only supported with stored procedure commands in SqlDataSource");
            }

            if (arguments.SortExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
            {
                throw new NotSupportedException("SqlDataSource cannot sort. Set DataSourceMode to DataSet to enable sorting.");
            }

            if (arguments.StartRowIndex > 0 || arguments.MaximumRows > 0)
            {
                throw new NotSupportedException("SqlDataSource does not have paging enabled. Set the DataSourceMode to DataSet to enable paging.");
            }

            if (FilterExpression.Length > 0 && owner.DataSourceMode == SqlDataSourceMode.DataReader)
            {
                throw new NotSupportedException("SqlDataSource only supports filtering when the data source's DataSourceMode is set to DataSet.");
            }

            InitConnection();

            DbCommand command = factory.CreateCommand();

            command.CommandText = SelectCommand;
            command.Connection  = connection;
            if (SelectCommandType == SqlDataSourceCommandType.Text)
            {
                command.CommandType = CommandType.Text;
            }
            else
            {
                command.CommandType = CommandType.StoredProcedure;
                if (SortParameterName.Length > 0 && arguments.SortExpression.Length > 0)
                {
                    command.Parameters.Add(CreateDbParameter(SortParameterName, arguments.SortExpression));
                }
            }

            if (SelectParameters.Count > 0)
            {
                InitializeParameters(command, SelectParameters, null, null, false);
            }

            Exception exception = null;

            if (owner.DataSourceMode == SqlDataSourceMode.DataSet)
            {
                DataView dataView = null;

                if (owner.EnableCaching)
                {
                    dataView = (DataView)owner.Cache.GetCachedObject(SelectCommand, SelectParameters);
                }

                if (dataView == null)
                {
                    SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs(command, arguments);
                    OnSelecting(selectingArgs);
                    if (selectingArgs.Cancel || !PrepareNullParameters(command, CancelSelectOnNullParameter))
                    {
                        return(null);
                    }
                    try {
                        DbDataAdapter adapter = factory.CreateDataAdapter();
                        DataSet       dataset = new DataSet();

                        adapter.SelectCommand = command;
                        adapter.Fill(dataset, name);

                        dataView = dataset.Tables [0].DefaultView;
                        if (dataView == null)
                        {
                            throw new InvalidOperationException();
                        }
                    }
                    catch (Exception e) {
                        exception = e;
                    }
                    int rowsAffected = (dataView == null) ? 0 : dataView.Count;
                    SqlDataSourceStatusEventArgs selectedArgs = new SqlDataSourceStatusEventArgs(command, rowsAffected, exception);
                    OnSelected(selectedArgs);

                    if (exception != null && !selectedArgs.ExceptionHandled)
                    {
                        throw exception;
                    }

                    if (owner.EnableCaching)
                    {
                        owner.Cache.SetCachedObject(SelectCommand, selectParameters, dataView);
                    }
                }

                if (SortParameterName.Length == 0 || SelectCommandType == SqlDataSourceCommandType.Text)
                {
                    dataView.Sort = arguments.SortExpression;
                }

                if (FilterExpression.Length > 0)
                {
                    IOrderedDictionary fparams            = FilterParameters.GetValues(context, owner);
                    SqlDataSourceFilteringEventArgs fargs = new SqlDataSourceFilteringEventArgs(fparams);
                    OnFiltering(fargs);
                    if (!fargs.Cancel)
                    {
                        object [] formatValues = new object [fparams.Count];
                        for (int n = 0; n < formatValues.Length; n++)
                        {
                            formatValues [n] = fparams [n];
                            if (formatValues [n] == null)
                            {
                                return(dataView);
                            }
                        }
                        dataView.RowFilter = string.Format(FilterExpression, formatValues);
                    }
                }

                return(dataView);
            }
            else
            {
                SqlDataSourceSelectingEventArgs selectingArgs = new SqlDataSourceSelectingEventArgs(command, arguments);
                OnSelecting(selectingArgs);
                if (selectingArgs.Cancel || !PrepareNullParameters(command, CancelSelectOnNullParameter))
                {
                    return(null);
                }

                DbDataReader reader = null;
                bool         closed = connection.State == ConnectionState.Closed;

                if (closed)
                {
                    connection.Open();
                }
                try {
                    reader = command.ExecuteReader(closed ? CommandBehavior.CloseConnection : CommandBehavior.Default);
                }
                catch (Exception e) {
                    exception = e;
                }
                SqlDataSourceStatusEventArgs selectedArgs =
                    new SqlDataSourceStatusEventArgs(command, reader.RecordsAffected, exception);
                OnSelected(selectedArgs);
                if (exception != null && !selectedArgs.ExceptionHandled)
                {
                    throw exception;
                }

                return(reader);
            }
        }
        /// <devdoc>
        /// Returns all the rows of the datasource.
        /// Parameters are taken from the SqlDataSource.Parameters property collection.
        /// If DataSourceMode is set to DataSet then a DataView is returned.
        /// If DataSourceMode is set to DataReader then a DataReader is returned, and it must be closed when done.
        /// </devdoc>
        protected internal override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments) {
            if (SelectCommand.Length == 0) {
                return null;
            }

            DbConnection connection = _owner.CreateConnection(_owner.ConnectionString);

            if (connection == null) {
                throw new InvalidOperationException(SR.GetString(SR.SqlDataSourceView_CouldNotCreateConnection, _owner.ID));
            }

            DataSourceCache cache = _owner.Cache;
            bool cacheEnabled = (cache != null) && (cache.Enabled);
            //int startRowIndex = arguments.StartRowIndex;
            //int maximumRows = arguments.MaximumRows;
            string sortExpression = arguments.SortExpression;

            if (CanPage) {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }

            if (CanSort) {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }

            if (CanRetrieveTotalRowCount) {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }


            // If caching is enabled, load DataSet from cache
            if (cacheEnabled) {
                if (_owner.DataSourceMode != SqlDataSourceMode.DataSet) {
                    throw new NotSupportedException(SR.GetString(SR.SqlDataSourceView_CacheNotSupported, _owner.ID));
                }

                arguments.RaiseUnsupportedCapabilitiesError(this);

                DataSet dataSet = _owner.LoadDataFromCache(0, -1) as DataSet;

                if (dataSet != null) {
                    /*if (arguments.RetrieveTotalRowCount) {
                        int cachedTotalRowCount = _owner.LoadTotalRowCountFromCache();
                        if (cachedTotalRowCount >= 0) {
                            arguments.TotalRowCount = cachedTotalRowCount;
                        }
                        else {
                            // query for row count and then save it in cache
                            cachedTotalRowCount = QueryTotalRowCount(connection, arguments);
                            arguments.TotalRowCount = cachedTotalRowCount;
                            _owner.SaveTotalRowCountToCache(cachedTotalRowCount);
                        }
                    }*/
                    IOrderedDictionary parameterValues = FilterParameters.GetValues(_context, _owner);
                    if (FilterExpression.Length > 0) {
                        SqlDataSourceFilteringEventArgs filterArgs = new SqlDataSourceFilteringEventArgs(parameterValues);
                        OnFiltering(filterArgs);
                        if (filterArgs.Cancel) {
                            return null;
                        }
                    }
                    return FilteredDataSetHelper.CreateFilteredDataView(dataSet.Tables[0], sortExpression, FilterExpression, parameterValues);
                }
            }

            // Create command and add parameters
            DbCommand command = _owner.CreateCommand(SelectCommand, connection);
            InitializeParameters(command, SelectParameters, null);
            command.CommandType = GetCommandType(SelectCommandType);

            // Raise event to allow customization and cancellation
            SqlDataSourceSelectingEventArgs selectingEventArgs = new SqlDataSourceSelectingEventArgs(command, arguments);
            OnSelecting(selectingEventArgs);

            // If the operation was cancelled, exit immediately
            if (selectingEventArgs.Cancel) {
                return null;
            }

            // Add the sort parameter to allow for custom stored procedure sorting, if necessary
            string sortParameterName = SortParameterName;
            if (sortParameterName.Length > 0) {
                if (command.CommandType != CommandType.StoredProcedure) {
                    throw new NotSupportedException(SR.GetString(SR.SqlDataSourceView_SortParameterRequiresStoredProcedure, _owner.ID));
                }
                command.Parameters.Add(_owner.CreateParameter(ParameterPrefix + sortParameterName, sortExpression));

                // We reset the sort expression here so that we pretend as
                // though we're not really sorting (since the developer is
                // worrying about it instead of us).
                arguments.SortExpression = String.Empty;
            }

            arguments.RaiseUnsupportedCapabilitiesError(this);

            // reset these values, since they might have changed in the OnSelecting event
            sortExpression = arguments.SortExpression;
            //startRowIndex = arguments.StartRowIndex;
            //maximumRows = arguments.MaximumRows;

            // Perform null check if user wants to cancel on any null parameter value
            if (CancelSelectOnNullParameter) {
                int paramCount = command.Parameters.Count;
                for (int i = 0; i < paramCount; i++) {
                    DbParameter parameter = command.Parameters[i];
                    if ((parameter != null) &&
                        (parameter.Value == null) &&
                        ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput))) {
                        return null;
                    }
                }
            }

            // Replace null values in parameters with DBNull.Value
            ReplaceNullValues(command);

            /*if (arguments.RetrieveTotalRowCount && SelectCountCommand.Length > 0) {
                int cachedTotalRowCount = -1;
                if (cacheEnabled) {
                    cachedTotalRowCount = _owner.LoadTotalRowCountFromCache();
                    if (cachedTotalRowCount >= 0) {
                        arguments.TotalRowCount = cachedTotalRowCount;
                    }
                }
                if (cachedTotalRowCount < 0) {
                    cachedTotalRowCount = QueryTotalRowCount(connection, arguments);
                    arguments.TotalRowCount = cachedTotalRowCount;
                    if (cacheEnabled) {
                        _owner.SaveTotalRowCountToCache(cachedTotalRowCount);
                    }
                }
            }*/

            IEnumerable selectResult = null;

            switch (_owner.DataSourceMode) {
                case SqlDataSourceMode.DataSet:
                {
                    SqlCacheDependency cacheDependency = null;
                    if (cacheEnabled && cache is SqlDataSourceCache) {
                        SqlDataSourceCache sqlCache = (SqlDataSourceCache)cache;
                        if (String.Equals(sqlCache.SqlCacheDependency, SqlDataSourceCache.Sql9CacheDependencyDirective, StringComparison.OrdinalIgnoreCase)) {
                            if (!(command is System.Data.SqlClient.SqlCommand)) {
                                throw new InvalidOperationException(SR.GetString(SR.SqlDataSourceView_CommandNotificationNotSupported, _owner.ID));
                            }
                            cacheDependency = new SqlCacheDependency((System.Data.SqlClient.SqlCommand)command);
                        }
                    }

                    DbDataAdapter adapter = _owner.CreateDataAdapter(command);

                    DataSet dataSet = new DataSet();
                    int rowsAffected = 0;

                    bool eventRaised = false;
                    try {
                        rowsAffected = adapter.Fill(dataSet, Name);

                        // Raise the Selected event
                        eventRaised = true;
                        SqlDataSourceStatusEventArgs selectedEventArgs = new SqlDataSourceStatusEventArgs(command, rowsAffected, null);
                        OnSelected(selectedEventArgs);
                    }
                    catch (Exception ex) {
                        if (!eventRaised) {
                            // Raise the Selected event
                            SqlDataSourceStatusEventArgs selectedEventArgs = new SqlDataSourceStatusEventArgs(command, rowsAffected, ex);
                            OnSelected(selectedEventArgs);
                            if (!selectedEventArgs.ExceptionHandled) {
                                throw;
                            }
                        }
                        else {
                            bool isCustomException;
                            ex = BuildCustomException(ex, DataSourceOperation.Select, command, out isCustomException);
                            if (isCustomException) {
                                throw ex;
                            }
                            else {
                                throw;
                            }
                        }
                    }
                    finally {
                        if (connection.State == ConnectionState.Open) {
                            connection.Close();
                        }
                    }

                    // If caching is enabled, save DataSet to cache
                    DataTable dataTable = (dataSet.Tables.Count > 0 ? dataSet.Tables[0] : null);
                    if (cacheEnabled && dataTable != null) {
                        _owner.SaveDataToCache(0, -1, dataSet, cacheDependency);
                    }

                    if (dataTable != null) {
                        IOrderedDictionary parameterValues = FilterParameters.GetValues(_context, _owner);
                        if (FilterExpression.Length > 0) {
                            SqlDataSourceFilteringEventArgs filterArgs = new SqlDataSourceFilteringEventArgs(parameterValues);
                            OnFiltering(filterArgs);
                            if (filterArgs.Cancel) {
                                return null;
                            }
                        }
                        selectResult = FilteredDataSetHelper.CreateFilteredDataView(dataTable, sortExpression, FilterExpression, parameterValues);
                    }
                    break;
                }

                case SqlDataSourceMode.DataReader:
                {
                    if (FilterExpression.Length > 0) {
                        throw new NotSupportedException(SR.GetString(SR.SqlDataSourceView_FilterNotSupported, _owner.ID));
                    }

                    if (sortExpression.Length > 0) {
                        throw new NotSupportedException(SR.GetString(SR.SqlDataSourceView_SortNotSupported, _owner.ID));
                    }

                    bool eventRaised = false;
                    try {
                        if (connection.State != ConnectionState.Open) {
                            connection.Open();
                        }

                        selectResult = command.ExecuteReader(CommandBehavior.CloseConnection);

                        // Raise the Selected event
                        eventRaised = true;
                        SqlDataSourceStatusEventArgs selectedEventArgs = new SqlDataSourceStatusEventArgs(command, 0, null);
                        OnSelected(selectedEventArgs);
                    }
                    catch (Exception ex) {
                        if (!eventRaised) {
                            // Raise the Selected event
                            SqlDataSourceStatusEventArgs selectedEventArgs = new SqlDataSourceStatusEventArgs(command, 0, ex);
                            OnSelected(selectedEventArgs);
                            if (!selectedEventArgs.ExceptionHandled) {
                                throw;
                            }
                        }
                        else {
                            bool isCustomException;
                            ex = BuildCustomException(ex, DataSourceOperation.Select, command, out isCustomException);
                            if (isCustomException) {
                                throw ex;
                            }
                            else {
                                throw;
                            }
                        }
                    }
                    break;
                }
            }
            return selectResult;
        }
 protected virtual void OnFiltering(SqlDataSourceFilteringEventArgs e) {
     SqlDataSourceFilteringEventHandler handler = Events[EventFiltering] as SqlDataSourceFilteringEventHandler;
     if (handler != null) {
         handler(this, e);
     }
 }
        protected internal override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            SqlCacheDependency dependency;

            if (this.SelectCommand.Length == 0)
            {
                return(null);
            }
            DbConnection connection = this._owner.CreateConnection(this._owner.ConnectionString);

            if (connection == null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("SqlDataSourceView_CouldNotCreateConnection", new object[] { this._owner.ID }));
            }
            DataSourceCache cache          = this._owner.Cache;
            bool            flag           = (cache != null) && cache.Enabled;
            string          sortExpression = arguments.SortExpression;

            if (this.CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }
            if (this.CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }
            if (this.CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }
            if (flag)
            {
                if (this._owner.DataSourceMode != SqlDataSourceMode.DataSet)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_CacheNotSupported", new object[] { this._owner.ID }));
                }
                arguments.RaiseUnsupportedCapabilitiesError(this);
                DataSet set = this._owner.LoadDataFromCache(0, -1) as DataSet;
                if (set != null)
                {
                    IOrderedDictionary parameterValues = this.FilterParameters.GetValues(this._context, this._owner);
                    if (this.FilterExpression.Length > 0)
                    {
                        SqlDataSourceFilteringEventArgs args = new SqlDataSourceFilteringEventArgs(parameterValues);
                        this.OnFiltering(args);
                        if (args.Cancel)
                        {
                            return(null);
                        }
                    }
                    return(FilteredDataSetHelper.CreateFilteredDataView(set.Tables[0], sortExpression, this.FilterExpression, parameterValues));
                }
            }
            DbCommand command = this._owner.CreateCommand(this.SelectCommand, connection);

            this.InitializeParameters(command, this.SelectParameters, null);
            command.CommandType = GetCommandType(this.SelectCommandType);
            SqlDataSourceSelectingEventArgs e = new SqlDataSourceSelectingEventArgs(command, arguments);

            this.OnSelecting(e);
            if (e.Cancel)
            {
                return(null);
            }
            string sortParameterName = this.SortParameterName;

            if (sortParameterName.Length > 0)
            {
                if (command.CommandType != CommandType.StoredProcedure)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_SortParameterRequiresStoredProcedure", new object[] { this._owner.ID }));
                }
                command.Parameters.Add(this._owner.CreateParameter(this.ParameterPrefix + sortParameterName, sortExpression));
                arguments.SortExpression = string.Empty;
            }
            arguments.RaiseUnsupportedCapabilitiesError(this);
            sortExpression = arguments.SortExpression;
            if (this.CancelSelectOnNullParameter)
            {
                int count = command.Parameters.Count;
                for (int i = 0; i < count; i++)
                {
                    DbParameter parameter = command.Parameters[i];
                    if (((parameter != null) && (parameter.Value == null)) && ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput)))
                    {
                        return(null);
                    }
                }
            }
            this.ReplaceNullValues(command);
            IEnumerable enumerable = null;

            switch (this._owner.DataSourceMode)
            {
            case SqlDataSourceMode.DataReader:
            {
                if (this.FilterExpression.Length > 0)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_FilterNotSupported", new object[] { this._owner.ID }));
                }
                if (sortExpression.Length > 0)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_SortNotSupported", new object[] { this._owner.ID }));
                }
                bool flag4 = false;
                try
                {
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }
                    enumerable = command.ExecuteReader(CommandBehavior.CloseConnection);
                    flag4      = true;
                    SqlDataSourceStatusEventArgs args6 = new SqlDataSourceStatusEventArgs(command, 0, null);
                    this.OnSelected(args6);
                }
                catch (Exception exception2)
                {
                    bool flag5;
                    if (!flag4)
                    {
                        SqlDataSourceStatusEventArgs args7 = new SqlDataSourceStatusEventArgs(command, 0, exception2);
                        this.OnSelected(args7);
                        if (!args7.ExceptionHandled)
                        {
                            throw;
                        }
                        return(enumerable);
                    }
                    exception2 = this.BuildCustomException(exception2, DataSourceOperation.Select, command, out flag5);
                    if (flag5)
                    {
                        throw exception2;
                    }
                    throw;
                }
                return(enumerable);
            }

            case SqlDataSourceMode.DataSet:
                dependency = null;
                if (flag && (cache is SqlDataSourceCache))
                {
                    SqlDataSourceCache cache2 = (SqlDataSourceCache)cache;
                    if (string.Equals(cache2.SqlCacheDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase))
                    {
                        if (!(command is SqlCommand))
                        {
                            throw new InvalidOperationException(System.Web.SR.GetString("SqlDataSourceView_CommandNotificationNotSupported", new object[] { this._owner.ID }));
                        }
                        dependency = new SqlCacheDependency((SqlCommand)command);
                        break;
                    }
                }
                break;

            default:
                return(enumerable);
            }
            DbDataAdapter adapter      = this._owner.CreateDataAdapter(command);
            DataSet       dataSet      = new DataSet();
            int           affectedRows = 0;
            bool          flag2        = false;

            try
            {
                affectedRows = adapter.Fill(dataSet, base.Name);
                flag2        = true;
                SqlDataSourceStatusEventArgs args3 = new SqlDataSourceStatusEventArgs(command, affectedRows, null);
                this.OnSelected(args3);
            }
            catch (Exception exception)
            {
                if (flag2)
                {
                    bool flag3;
                    exception = this.BuildCustomException(exception, DataSourceOperation.Select, command, out flag3);
                    if (flag3)
                    {
                        throw exception;
                    }
                    throw;
                }
                SqlDataSourceStatusEventArgs args4 = new SqlDataSourceStatusEventArgs(command, affectedRows, exception);
                this.OnSelected(args4);
                if (!args4.ExceptionHandled)
                {
                    throw;
                }
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            DataTable table = (dataSet.Tables.Count > 0) ? dataSet.Tables[0] : null;

            if (flag && (table != null))
            {
                this._owner.SaveDataToCache(0, -1, dataSet, dependency);
            }
            if (table == null)
            {
                return(enumerable);
            }
            IOrderedDictionary values = this.FilterParameters.GetValues(this._context, this._owner);

            if (this.FilterExpression.Length > 0)
            {
                SqlDataSourceFilteringEventArgs args5 = new SqlDataSourceFilteringEventArgs(values);
                this.OnFiltering(args5);
                if (args5.Cancel)
                {
                    return(null);
                }
            }
            return(FilteredDataSetHelper.CreateFilteredDataView(table, sortExpression, this.FilterExpression, values));
        }
        protected internal override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            SqlCacheDependency dependency;
            if (this.SelectCommand.Length == 0)
            {
                return null;
            }
            DbConnection connection = this._owner.CreateConnection(this._owner.ConnectionString);
            if (connection == null)
            {
                throw new InvalidOperationException(System.Web.SR.GetString("SqlDataSourceView_CouldNotCreateConnection", new object[] { this._owner.ID }));
            }
            DataSourceCache cache = this._owner.Cache;
            bool flag = (cache != null) && cache.Enabled;
            string sortExpression = arguments.SortExpression;
            if (this.CanPage)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Page);
            }
            if (this.CanSort)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort);
            }
            if (this.CanRetrieveTotalRowCount)
            {
                arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);
            }
            if (flag)
            {
                if (this._owner.DataSourceMode != SqlDataSourceMode.DataSet)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_CacheNotSupported", new object[] { this._owner.ID }));
                }
                arguments.RaiseUnsupportedCapabilitiesError(this);
                DataSet set = this._owner.LoadDataFromCache(0, -1) as DataSet;
                if (set != null)
                {
                    IOrderedDictionary parameterValues = this.FilterParameters.GetValues(this._context, this._owner);
                    if (this.FilterExpression.Length > 0)
                    {
                        SqlDataSourceFilteringEventArgs args = new SqlDataSourceFilteringEventArgs(parameterValues);
                        this.OnFiltering(args);
                        if (args.Cancel)
                        {
                            return null;
                        }
                    }
                    return FilteredDataSetHelper.CreateFilteredDataView(set.Tables[0], sortExpression, this.FilterExpression, parameterValues);
                }
            }
            DbCommand command = this._owner.CreateCommand(this.SelectCommand, connection);
            this.InitializeParameters(command, this.SelectParameters, null);
            command.CommandType = GetCommandType(this.SelectCommandType);
            SqlDataSourceSelectingEventArgs e = new SqlDataSourceSelectingEventArgs(command, arguments);
            this.OnSelecting(e);
            if (e.Cancel)
            {
                return null;
            }
            string sortParameterName = this.SortParameterName;
            if (sortParameterName.Length > 0)
            {
                if (command.CommandType != CommandType.StoredProcedure)
                {
                    throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_SortParameterRequiresStoredProcedure", new object[] { this._owner.ID }));
                }
                command.Parameters.Add(this._owner.CreateParameter(this.ParameterPrefix + sortParameterName, sortExpression));
                arguments.SortExpression = string.Empty;
            }
            arguments.RaiseUnsupportedCapabilitiesError(this);
            sortExpression = arguments.SortExpression;
            if (this.CancelSelectOnNullParameter)
            {
                int count = command.Parameters.Count;
                for (int i = 0; i < count; i++)
                {
                    DbParameter parameter = command.Parameters[i];
                    if (((parameter != null) && (parameter.Value == null)) && ((parameter.Direction == ParameterDirection.Input) || (parameter.Direction == ParameterDirection.InputOutput)))
                    {
                        return null;
                    }
                }
            }
            this.ReplaceNullValues(command);
            IEnumerable enumerable = null;
            switch (this._owner.DataSourceMode)
            {
                case SqlDataSourceMode.DataReader:
                {
                    if (this.FilterExpression.Length > 0)
                    {
                        throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_FilterNotSupported", new object[] { this._owner.ID }));
                    }
                    if (sortExpression.Length > 0)
                    {
                        throw new NotSupportedException(System.Web.SR.GetString("SqlDataSourceView_SortNotSupported", new object[] { this._owner.ID }));
                    }
                    bool flag4 = false;
                    try
                    {
                        if (connection.State != ConnectionState.Open)
                        {
                            connection.Open();
                        }
                        enumerable = command.ExecuteReader(CommandBehavior.CloseConnection);
                        flag4 = true;
                        SqlDataSourceStatusEventArgs args6 = new SqlDataSourceStatusEventArgs(command, 0, null);
                        this.OnSelected(args6);
                    }
                    catch (Exception exception2)
                    {
                        bool flag5;
                        if (!flag4)
                        {
                            SqlDataSourceStatusEventArgs args7 = new SqlDataSourceStatusEventArgs(command, 0, exception2);
                            this.OnSelected(args7);
                            if (!args7.ExceptionHandled)
                            {
                                throw;
                            }
                            return enumerable;
                        }
                        exception2 = this.BuildCustomException(exception2, DataSourceOperation.Select, command, out flag5);
                        if (flag5)
                        {
                            throw exception2;
                        }
                        throw;
                    }
                    return enumerable;
                }
                case SqlDataSourceMode.DataSet:
                    dependency = null;
                    if (flag && (cache is SqlDataSourceCache))
                    {
                        SqlDataSourceCache cache2 = (SqlDataSourceCache) cache;
                        if (string.Equals(cache2.SqlCacheDependency, "CommandNotification", StringComparison.OrdinalIgnoreCase))
                        {
                            if (!(command is SqlCommand))
                            {
                                throw new InvalidOperationException(System.Web.SR.GetString("SqlDataSourceView_CommandNotificationNotSupported", new object[] { this._owner.ID }));
                            }
                            dependency = new SqlCacheDependency((SqlCommand) command);
                            break;
                        }
                    }
                    break;

                default:
                    return enumerable;
            }
            DbDataAdapter adapter = this._owner.CreateDataAdapter(command);
            DataSet dataSet = new DataSet();
            int affectedRows = 0;
            bool flag2 = false;
            try
            {
                affectedRows = adapter.Fill(dataSet, base.Name);
                flag2 = true;
                SqlDataSourceStatusEventArgs args3 = new SqlDataSourceStatusEventArgs(command, affectedRows, null);
                this.OnSelected(args3);
            }
            catch (Exception exception)
            {
                if (flag2)
                {
                    bool flag3;
                    exception = this.BuildCustomException(exception, DataSourceOperation.Select, command, out flag3);
                    if (flag3)
                    {
                        throw exception;
                    }
                    throw;
                }
                SqlDataSourceStatusEventArgs args4 = new SqlDataSourceStatusEventArgs(command, affectedRows, exception);
                this.OnSelected(args4);
                if (!args4.ExceptionHandled)
                {
                    throw;
                }
            }
            finally
            {
                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            DataTable table = (dataSet.Tables.Count > 0) ? dataSet.Tables[0] : null;
            if (flag && (table != null))
            {
                this._owner.SaveDataToCache(0, -1, dataSet, dependency);
            }
            if (table == null)
            {
                return enumerable;
            }
            IOrderedDictionary values = this.FilterParameters.GetValues(this._context, this._owner);
            if (this.FilterExpression.Length > 0)
            {
                SqlDataSourceFilteringEventArgs args5 = new SqlDataSourceFilteringEventArgs(values);
                this.OnFiltering(args5);
                if (args5.Cancel)
                {
                    return null;
                }
            }
            return FilteredDataSetHelper.CreateFilteredDataView(table, sortExpression, this.FilterExpression, values);
        }
 protected virtual new void OnFiltering(SqlDataSourceFilteringEventArgs e)
 {
 }