Пример #1
0
        /// <summary>
        /// Adds a new filter condition to the data filter
        /// </summary>
        /// <param name="condition">The condition to add</param>
        /// <returns>Boolean; whether the addition was successful</returns>
        public bool AddFilterCondition(FilterCondition condition, ConditionJoinType joinType)
        {
            #region Input Validation
            if (condition == null || string.IsNullOrEmpty(condition.ColumnName))
            {
                throw new ApplicationException("Invalid filter condition. Cannot add condition to data filter.");
            }
            #endregion // Input Validation

            // check for duplicate conditions
            foreach (DataRow row in ConditionTable.Rows)
            {
                FilterCondition rCondition = (FilterCondition)row[COLUMN_FILTER];

                if (rCondition.FriendlyCondition.Equals(condition.FriendlyCondition))
                {
                    // cannot add a duplicate condition, so return false
                    return(false);
                }
            }

            // find the highest ID value of all the conditions presently in the table
            int maxInt = int.MinValue;

            foreach (DataRow row in ConditionTable.Rows)
            {
                int value = row.Field <int>(COLUMN_ID);
                maxInt = Math.Max(maxInt, value);
            }

            // get the string representation of the joinType enum
            string join = ConvertJoinType(joinType);

            if (this.Count == 0)
            {
                maxInt = 0;
                join   = string.Empty;
            }

            // assume group = 1
            ConditionTable.Rows.Add(maxInt + 1, join, condition, 1);

            // sort by ID
            this.conditionTable = ConditionTable.Select("", COLUMN_ID).CopyToDataTable().DefaultView.ToTable("FilterTable");

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Removes a filter condition
        /// </summary>
        /// <returns>Bool</returns>
        public bool RemoveFilterCondition(string friendlyCondition)
        {
            int     i;
            int     rowToRemove = -1;
            DataRow row         = null;

            for (i = 0; i < ConditionTable.Rows.Count; i++)
            {
                row = ConditionTable.Rows[i];
                string str = row[COLUMN_FILTER].ToString();

                if (str.Equals(friendlyCondition))
                {
                    rowToRemove = i;
                    break;
                }
            }

            if (rowToRemove >= 0)
            {
                ConditionTable.Rows.Remove(ConditionTable.Rows[rowToRemove]);

                if (ConditionTable.Rows.Count > 0)
                {
                    this.conditionTable = ConditionTable.Select("", COLUMN_ID).CopyToDataTable().DefaultView.ToTable("FilterTable");

                    if (rowToRemove == 0)
                    {
                        ConditionTable.Rows[0][COLUMN_JOIN] = string.Empty;
                    }
                }

                return(true);
            }
            return(false);
        }
Пример #3
0
 /// <summary>
 /// Gets an array of data rows from the ConditionTable, sorted by the column ID
 /// </summary>
 /// <returns>Array of data rows</returns>
 private DataRow[] GetSortedDataRows()
 {
     return(ConditionTable.Select(string.Empty, COLUMN_ID));
 }