internal static IDictionary <string, object> ToEscapedParameterKeys(this ParameterCollection parameters, HttpContext context, Control control)
 {
     if (parameters != null)
     {
         return(parameters.GetValues(context, control).ToEscapedParameterKeys(control));
     }
     return(null);
 }
예제 #2
0
        void InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary values, IDictionary oldValues, bool parametersMayMatchOldValues)
        {
            IOrderedDictionary parameterValues = parameters.GetValues(context, owner);

            foreach (string parameterName in parameterValues.Keys)
            {
                Parameter p         = parameters [parameterName];
                object    value     = FindValueByName(parameterName, values, false);
                string    valueName = parameterName;
                if (value == null)
                {
                    value = FindValueByName(parameterName, oldValues, true);
                }

                if (value == null && parametersMayMatchOldValues)
                {
                    value     = FindValueByName(parameterName, oldValues, false);
                    valueName = FormatOldParameter(parameterName);
                }

                if (value != null)
                {
                    object      dbValue      = p.ConvertValue(value);
                    DbParameter newParameter = CreateDbParameter(valueName, dbValue, p.Direction, p.Size);
                    if (!command.Parameters.Contains(newParameter.ParameterName))
                    {
                        command.Parameters.Add(newParameter);
                    }
                }
                else
                {
                    command.Parameters.Add(CreateDbParameter(p.Name, parameterValues [parameterName], p.Direction, p.Size));
                }
            }

            if (values != null)
            {
                foreach (DictionaryEntry de in values)
                {
                    if (!command.Parameters.Contains(ParameterPrefix + (string)de.Key))
                    {
                        command.Parameters.Add(CreateDbParameter((string)de.Key, de.Value));
                    }
                }
            }

            if (oldValues != null)
            {
                foreach (DictionaryEntry de in oldValues)
                {
                    if (!command.Parameters.Contains(ParameterPrefix + FormatOldParameter((string)de.Key)))
                    {
                        command.Parameters.Add(CreateDbParameter(FormatOldParameter((string)de.Key), de.Value));
                    }
                }
            }
        }
        private void InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList)
        {
            string      parameterPrefix = this.ParameterPrefix;
            IDictionary dictionary      = null;

            if (exclusionList != null)
            {
                dictionary = new ListDictionary(StringComparer.OrdinalIgnoreCase);
                foreach (DictionaryEntry entry in exclusionList)
                {
                    dictionary.Add(entry.Key, entry.Value);
                }
            }
            IOrderedDictionary values = parameters.GetValues(this._context, this._owner);

            for (int i = 0; i < parameters.Count; i++)
            {
                Parameter parameter = parameters[i];
                if ((dictionary != null) && dictionary.Contains(parameter.Name))
                {
                    continue;
                }
                DbParameter parameter2 = this._owner.CreateParameter(parameterPrefix + parameter.Name, values[i]);
                parameter2.Direction = parameter.Direction;
                parameter2.Size      = parameter.Size;
                if ((parameter.DbType != DbType.Object) || ((parameter.Type != TypeCode.Empty) && (parameter.Type != TypeCode.DBNull)))
                {
                    SqlParameter parameter3 = parameter2 as SqlParameter;
                    if (parameter3 == null)
                    {
                        parameter2.DbType = parameter.GetDatabaseType();
                    }
                    else
                    {
                        DbType databaseType = parameter.GetDatabaseType();
                        if (databaseType != DbType.Date)
                        {
                            if (databaseType != DbType.Time)
                            {
                                goto Label_0143;
                            }
                            parameter3.SqlDbType = SqlDbType.Time;
                        }
                        else
                        {
                            parameter3.SqlDbType = SqlDbType.Date;
                        }
                    }
                }
                goto Label_0151;
Label_0143:
                parameter2.DbType = parameter.GetDatabaseType();
Label_0151:
                command.Parameters.Add(parameter2);
            }
        }
예제 #4
0
        private void GenerateOrderByClause(TypeUsage tu, out string orderByClause, out ObjectParameter[] orderByObjectParameters, bool applySortExpression)
        {
            var orderByClauseBuilder = new StringBuilder();

            if (applySortExpression)
            {
                // This sets the orderBy clause based on a clicked column header in the databound control.
                AppendOrderByKey(orderByClauseBuilder, _argsSortExpression, Strings.EntityDataSourceView_ColumnHeader, tu);
            }

            // AutoGenerateOrderByClause is mutually exclusive with OrderBy.
            // Only one of the following two if statements will execute.
            if (_autoGenerateOrderByClause)
            {
                Debug.Assert(String.IsNullOrEmpty(_orderBy), "If AutoGenerateOrderByClause is true, then OrderBy cannot be set. This should have been caught by a runtime error check");
                IOrderedDictionary paramValues = _orderByParameters.GetValues(_owner.HttpContext, _owner);
                foreach (DictionaryEntry de in paramValues)
                {
                    // Skip AutoGenerateOrderBy on expressions that have a null value.
                    if (!string.IsNullOrEmpty((string)(de.Value)))
                    {
                        if (0 < orderByClauseBuilder.Length)
                        {
                            orderByClauseBuilder.Append(", ");
                        }
                        AppendOrderByKey(orderByClauseBuilder, (string)(de.Value), Strings.EntityDataSourceView_AutoGenerateOrderByParameters, tu);
                    }
                }
            }

            // Append the OrderBy expression, if it's nonzero length.
            if (!String.IsNullOrEmpty(_orderBy))
            {
                orderByObjectParameters = _owner.GetOrderByParameters();
                Debug.Assert(!_autoGenerateOrderByClause, "If OrderBy is set, AutoGenerateOrderBy must be false. This should have been caught by a runtime error check");
                if (0 < orderByClauseBuilder.Length)
                {
                    orderByClauseBuilder.Append(", ");
                }
                orderByClauseBuilder.Append(_orderBy);
            }
            else
            {
                orderByObjectParameters = new ObjectParameter[] { };
            }

            if (orderByClauseBuilder.Length == 0 && _generateDefaultOrderByClause)
            {
                // This only occurs if there's no EntitySet, which means entities are not wrapped.
                orderByClauseBuilder.Append(GenerateDefaultOrderByFromTypeUsage(tu));
            }

            orderByClause = orderByClauseBuilder.ToString();
        }
예제 #5
0
 /// <summary>
 /// Validates that the keys in the update parameters all match property names on the entityWrapper.
 /// </summary>
 /// <param name="entityWrapper"></param>
 /// <param name="parameters"></param>
 internal static void ValidateWebControlParameterNames(EntityDataSourceWrapper entityWrapper,
                                                       ParameterCollection parameters,
                                                       EntityDataSource owner)
 {
     Debug.Assert(null != entityWrapper, "entityWrapper should not be null");
     if (null != parameters)
     {
         PropertyDescriptorCollection entityProperties = entityWrapper.GetProperties();
         System.Collections.Specialized.IOrderedDictionary parmVals = parameters.GetValues(owner.HttpContext, owner);
         foreach (DictionaryEntry de in parmVals)
         {
             string key = de.Key as string;
             if (null == key || null == entityProperties.Find(key, false))
             {
                 throw new InvalidOperationException(Strings.EntityDataSourceUtil_InsertUpdateParametersDontMatchPropertyNameOnEntity(key, entityWrapper.WrappedEntity.GetType().ToString()));
             }
         }
     }
 }
예제 #6
0
        /// <summary>
        /// Returns the value set onto the Parameter named by propertyName.
        /// If the Paramter does not have a value, it returns null.
        /// </summary>
        /// <param name="propertyName"></param>
        /// <param name="parameterCollection"></param>
        /// <param name="entityDataSource"></param>
        /// <returns></returns>
        internal static object GetParameterValue(string propertyName, ParameterCollection parameterCollection,
                                                 EntityDataSource entityDataSource)
        {
            if (null == parameterCollection) // ParameterCollection undefined
            {
                return(null);
            }

            System.Collections.Specialized.IOrderedDictionary values =
                parameterCollection.GetValues(entityDataSource.HttpContext, entityDataSource);

            foreach (object key in values.Keys)
            {
                string parameterName = key as string;
                if (null != parameterName && String.Equals(propertyName, parameterName, StringComparison.Ordinal))
                {
                    return(values[parameterName]);
                }
            }

            return(null);
        }
예제 #7
0
        private ObjectParameter[] CreateObjectParametersFromParameterCollection(ParameterCollection paramColl)
        {
            IOrderedDictionary paramValues = paramColl.GetValues(HttpContext, this);

            List <ObjectParameter> objectParameters = new List <ObjectParameter>();

            foreach (Parameter parameter in paramColl)
            {
                if (!string.IsNullOrEmpty(parameter.Name))
                {
                    WebControlParameterProxy wcParam = new WebControlParameterProxy(parameter, paramColl, this);

                    if (wcParam.Value != null)
                    {
                        objectParameters.Add(new ObjectParameter(wcParam.Name, wcParam.Value));
                    }
                    else
                    {
                        objectParameters.Add(new ObjectParameter(wcParam.Name, wcParam.ClrType));
                    }
                }
            }
            return(objectParameters.ToArray());
        }
        /// <devdoc>
        /// Initializes a DbCommand with parameters from a ParameterCollection.
        /// The exclusion list contains parameter names that should not be added
        /// to the command's parameter collection.
        /// </devdoc>
        private void InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) {
            Debug.Assert(command != null);
            Debug.Assert(parameters != null);

            string parameterPrefix = ParameterPrefix;

            IDictionary caseInsensitiveExclusionList = null;
            if (exclusionList != null) {
                caseInsensitiveExclusionList = new ListDictionary(StringComparer.OrdinalIgnoreCase);
                foreach (DictionaryEntry de in exclusionList) {
                    caseInsensitiveExclusionList.Add(de.Key, de.Value);
                }
            }

            IOrderedDictionary values = parameters.GetValues(_context, _owner);
            for (int i = 0; i < parameters.Count; i++) {
                Parameter parameter = parameters[i];
                if ((caseInsensitiveExclusionList == null) || (!caseInsensitiveExclusionList.Contains(parameter.Name))) {
                    DbParameter dbParameter = _owner.CreateParameter(parameterPrefix + parameter.Name, values[i]);
                    dbParameter.Direction = parameter.Direction;
                    dbParameter.Size = parameter.Size;
                    if (parameter.DbType != DbType.Object || (parameter.Type != TypeCode.Empty && parameter.Type != TypeCode.DBNull)) {
                        SqlParameter sqlParameter = dbParameter as SqlParameter;
                        if (sqlParameter == null) {
                            dbParameter.DbType = parameter.GetDatabaseType();
                        }
                        else {
                            // In Whidbey, the DbType Date and Time members mapped to SqlDbType.DateTime since there
                            // were no SqlDbType equivalents. SqlDbType has since been modified to include the new
                            // Katmai types, including Date and Time. For backwards compatability SqlParameter's DbType
                            // setter doesn't support Date and Time, so the SqlDbType property should be used instead.
                            // Other new SqlServer 2008 types (DateTime2, DateTimeOffset) can be set using DbType.
                            DbType dbType = parameter.GetDatabaseType();
                            switch (dbType) {
                                case DbType.Time:
                                    sqlParameter.SqlDbType = SqlDbType.Time;
                                    break;
                                case DbType.Date:
                                    sqlParameter.SqlDbType = SqlDbType.Date;
                                    break;
                                default:
                                    dbParameter.DbType = parameter.GetDatabaseType();
                                    break;
                            }
                        }
                    }
                    command.Parameters.Add(dbParameter);
                }
            }
        }
		/// <summary>
		/// Merge the current data item fields with view parameter default values
		/// </summary>
		/// <param name="viewParams">default parameters</param>
		/// <param name="values">new parameters for update and insert</param>
		/// <param name="oldValues">old parameters for update and delete</param>
		/// <param name="allwaysAddNewValues">true for insert, as current item is
		/// irrelevant for insert</param>
		/// <returns>merged values</returns>
		IOrderedDictionary MergeParameterValues (ParameterCollection viewParams, IDictionary values, IDictionary oldValues)
		{
			IOrderedDictionary parametersValues = viewParams.GetValues (context, owner);
			OrderedDictionary mergedValues = new OrderedDictionary (StringComparer.InvariantCultureIgnoreCase);
			foreach (string parameterName in parametersValues.Keys) {
				mergedValues [parameterName] = parametersValues [parameterName];
				if (oldValues != null) {
					object value = FindValueByName (parameterName, oldValues, true);
					if (value != null) {
						object dataValue = viewParams [parameterName].ConvertValue (value);
						mergedValues [parameterName] = dataValue;
					}
				}

				if (values != null) {
					object value = FindValueByName (parameterName, values, false);
					if (value != null) {
						object dataValue = viewParams [parameterName].ConvertValue (value);
						mergedValues [parameterName] = dataValue;
					}
				}
			}

			if (values != null) {
				foreach (DictionaryEntry de in values)
					if (FindValueByName ((string) de.Key, mergedValues, false) == null)
						mergedValues [de.Key] = de.Value;
			}

			if (oldValues != null) {
				foreach (DictionaryEntry de in oldValues) {
					string oldValueKey = FormatOldParameter ((string) de.Key);
					if (FindValueByName (oldValueKey, mergedValues, false) == null)
						mergedValues [oldValueKey] = de.Value;
				}
			}

			return mergedValues;
		}
 private void OnOkButtonClick(object sender, EventArgs e)
 {
     ParameterCollection parameters = new ParameterCollection();
     foreach (ParameterItem item in this._parameterItems)
     {
         if (item.Parameter.DbType == DbType.Object)
         {
             parameters.Add(new Parameter(item.Parameter.Name, item.Parameter.Type, item.Parameter.DefaultValue));
         }
         else
         {
             parameters.Add(new Parameter(item.Parameter.Name, item.Parameter.DbType, item.Parameter.DefaultValue));
         }
     }
     try
     {
         parameters.GetValues(null, null);
     }
     catch (Exception exception)
     {
         UIServiceHelper.ShowError(base.ServiceProvider, exception, System.Design.SR.GetString("SqlDataSourceParameterValueEditorForm_InvalidParameter"));
         return;
     }
     base.DialogResult = DialogResult.OK;
     base.Close();
 }
예제 #11
0
 private void ExtractCommandParametersToDataRow(ParameterCollection parameters, DataRow row)
 {
     IOrderedDictionary paramsValues = parameters.GetValues(context, owner);
     for (int i = 0; i < parameters.Count; i++)
     {
         if (paramsValues[i] != null)
         {
             row[parameters[i].Name] = paramsValues[i];
         }
     }
 }
 private void InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList)
 {
     string parameterPrefix = this.ParameterPrefix;
     IDictionary dictionary = null;
     if (exclusionList != null)
     {
         dictionary = new ListDictionary(StringComparer.OrdinalIgnoreCase);
         foreach (DictionaryEntry entry in exclusionList)
         {
             dictionary.Add(entry.Key, entry.Value);
         }
     }
     IOrderedDictionary values = parameters.GetValues(this._context, this._owner);
     for (int i = 0; i < parameters.Count; i++)
     {
         Parameter parameter = parameters[i];
         if ((dictionary != null) && dictionary.Contains(parameter.Name))
         {
             continue;
         }
         DbParameter parameter2 = this._owner.CreateParameter(parameterPrefix + parameter.Name, values[i]);
         parameter2.Direction = parameter.Direction;
         parameter2.Size = parameter.Size;
         if ((parameter.DbType != DbType.Object) || ((parameter.Type != TypeCode.Empty) && (parameter.Type != TypeCode.DBNull)))
         {
             SqlParameter parameter3 = parameter2 as SqlParameter;
             if (parameter3 == null)
             {
                 parameter2.DbType = parameter.GetDatabaseType();
             }
             else
             {
                 DbType databaseType = parameter.GetDatabaseType();
                 if (databaseType != DbType.Date)
                 {
                     if (databaseType != DbType.Time)
                     {
                         goto Label_0143;
                     }
                     parameter3.SqlDbType = SqlDbType.Time;
                 }
                 else
                 {
                     parameter3.SqlDbType = SqlDbType.Date;
                 }
             }
         }
         goto Label_0151;
     Label_0143:
         parameter2.DbType = parameter.GetDatabaseType();
     Label_0151:
         command.Parameters.Add(parameter2);
     }
 }
예제 #13
0
 public static IDictionary <string, object> ToDictionary(this ParameterCollection parameters, HttpContext context, Control control)
 {
     return(ToDictionary(parameters.GetValues(context, control)));
 }
예제 #14
0
 protected virtual IDictionary TrimToParameters(ParameterCollection parameters, IDictionary values)
 {
     if (null == this._dataSource)
     {
         throw new InvalidOperationException("DataSource is null");
     }
     if (!(this._dataSource is Control))
     {
         throw new InvalidOperationException("DataSource is not a Control");
     }
     IDictionary result;
     if (null == values)
     {
         result = null;
     }
     else
     {
         Dictionary<string, object> prepared = new Dictionary<string, object>();
         IOrderedDictionary paramValues = parameters.GetValues(this.Context, this._dataSource as Control);
         if (null != parameters)
         {
             foreach (Parameter param in parameters)
             {
                 prepared.Add(param.Name, paramValues[param.Name]);
             }
         }
         if (null != values)
         {
             foreach (DictionaryEntry entry in values)
             {
                 if (prepared.ContainsKey(entry.Key.ToString()))
                 {
                     prepared[entry.Key.ToString()] = entry.Value;
                 }
             }
         }
         result = prepared;
     }
     return result;
 }
 internal DbCommand BuildSelectCommand(DbProviderFactory factory, DbConnection connection, string commandText, ParameterCollection parameters, SqlDataSourceCommandType commandType)
 {
     DbCommand command = CreateCommand(factory, commandText, connection);
     if ((parameters != null) && (parameters.Count > 0))
     {
         IOrderedDictionary values = parameters.GetValues(null, null);
         string parameterPrefix = GetParameterPrefix(factory);
         for (int i = 0; i < parameters.Count; i++)
         {
             Parameter parameter = parameters[i];
             DbParameter parameter2 = CreateParameter(factory);
             parameter2.ParameterName = parameterPrefix + parameter.Name;
             if (parameter.DbType != DbType.Object)
             {
                 SqlParameter parameter3 = parameter2 as SqlParameter;
                 if (parameter3 == null)
                 {
                     parameter2.DbType = parameter.DbType;
                 }
                 else if (parameter.DbType == DbType.Date)
                 {
                     parameter3.SqlDbType = SqlDbType.Date;
                 }
                 else if (parameter.DbType == DbType.Time)
                 {
                     parameter3.SqlDbType = SqlDbType.Time;
                 }
                 else
                 {
                     parameter2.DbType = parameter.DbType;
                 }
             }
             else
             {
                 if ((parameter.Type != TypeCode.Empty) && (parameter.Type != TypeCode.DBNull))
                 {
                     parameter2.DbType = parameter.GetDatabaseType();
                 }
                 if ((parameter.Type == TypeCode.Empty) && ProviderRequiresDbTypeSet(factory))
                 {
                     parameter2.DbType = DbType.Object;
                 }
             }
             parameter2.Value = values[i];
             if (parameter2.Value == null)
             {
                 parameter2.Value = DBNull.Value;
             }
             if (Parameter.ConvertDbTypeToTypeCode(parameter2.DbType) == TypeCode.String)
             {
                 if ((parameter2.Value is string) && (parameter2.Value != null))
                 {
                     parameter2.Size = ((string) parameter2.Value).Length;
                 }
                 else
                 {
                     parameter2.Size = 1;
                 }
             }
             command.Parameters.Add(parameter2);
         }
     }
     command.CommandType = GetCommandType(commandType);
     return command;
 }
		void InitializeParameters (DbCommand command, ParameterCollection parameters, IDictionary values, IDictionary oldValues, bool parametersMayMatchOldValues)
		{
			IOrderedDictionary parameterValues = parameters.GetValues (context, owner);

			foreach (string parameterName in parameterValues.Keys) {
				Parameter p = parameters [parameterName];
				object value = FindValueByName (parameterName, values, false);
				string valueName = parameterName;
				if (value == null)
					value = FindValueByName (parameterName, oldValues, true);

				if (value == null && parametersMayMatchOldValues) {
					value = FindValueByName (parameterName, oldValues, false);
					valueName = FormatOldParameter (parameterName);
				}

				if (value != null) {
					object dbValue = p.ConvertValue (value);
					DbParameter newParameter = CreateDbParameter (valueName, dbValue, p.Direction, p.Size);
					if (!command.Parameters.Contains (newParameter.ParameterName)) {
						command.Parameters.Add (newParameter);
					}
				}
				else {
					command.Parameters.Add (CreateDbParameter (p.Name, parameterValues [parameterName], p.Direction, p.Size));
				}
			}

			if (values != null) {
				foreach (DictionaryEntry de in values)
					if (!command.Parameters.Contains (ParameterPrefix + (string) de.Key))
						command.Parameters.Add (CreateDbParameter ((string) de.Key, de.Value));
			}

			if (oldValues != null) {
				foreach (DictionaryEntry de in oldValues)
					if (!command.Parameters.Contains (ParameterPrefix + FormatOldParameter ((string) de.Key)))
						command.Parameters.Add (CreateDbParameter (FormatOldParameter ((string) de.Key), de.Value));
			}
		}
예제 #17
0
        private ObjectParameter[] CreateObjectParametersFromParameterCollection(ParameterCollection paramColl)
        {
            IOrderedDictionary paramValues = paramColl.GetValues(HttpContext, this);

            List<ObjectParameter>  objectParameters = new List<ObjectParameter>();
            foreach (Parameter parameter in paramColl)
            {
                if (!string.IsNullOrEmpty(parameter.Name))
                {
                    WebControlParameterProxy wcParam = new WebControlParameterProxy(parameter, paramColl, this);

                    if (wcParam.Value != null)
                    {
                        objectParameters.Add(new ObjectParameter(wcParam.Name, wcParam.Value));
                    }
                    else
                    {
                        objectParameters.Add(new ObjectParameter(wcParam.Name, wcParam.ClrType));
                    }
                }
            }
            return objectParameters.ToArray();
        }