Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new rule to the set of dashboard rules
        /// </summary>
        /// <param name="rule">The rule to add</param>
        /// <returns>Boolean; whether the addition was successful</returns>
        public bool AddRule(IDashboardRule rule)
        {
            #region Input Validation
            if (rule == null || string.IsNullOrEmpty(rule.FriendlyRule))
            {
                throw new ArgumentNullException("rule");
            }
            #endregion // Input Validation

            // check for duplicate rules
            foreach (DataRow row in RuleTable.Rows)
            {
                IDashboardRule rRule = (IDashboardRule)row[COLUMN_RULE];

                if (rRule.FriendlyRule.Equals(rule.FriendlyRule))
                {
                    // cannot add a duplicate rule, so return false
                    return(false);
                }
            }

            // find the highest run order value of all the rules presently in the table
            int maxInt = int.MinValue;

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

            RuleTable.Rows.Add(maxInt + 1, rule);

            // sort by run order
            this.ruleTable = RuleTable.Select("", COLUMN_RUN_ORDER).CopyToDataTable().DefaultView.ToTable("RuleTable");

            if (rule is DataAssignmentRule)
            {
                DataAssignmentRule assignRule = rule as DataAssignmentRule;
                if (!dashboardHelper.TableColumnNames.ContainsKey(assignRule.DestinationColumnName))
                {
                    dashboardHelper.TableColumnNames.Add(assignRule.DestinationColumnName, assignRule.DestinationColumnType);
                }
            }

            return(true);
        }