Exemplo n.º 1
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public override object Clone()
        {
            RelationCondition condition = base.Clone() as RelationCondition;

            condition.item1       = (this.item1 != null) ? (this.item1.Clone() as ConditionBase) : null;
            condition.item2       = (this.item2 != null) ? (this.item2.Clone() as ConditionBase) : null;
            condition.compareType = this.compareType;
            return(condition);
        }
Exemplo n.º 2
0
 static string GetExpectedFormula(CellValueRule cellValueRule, int index)
 {
     if ((cellValueRule != null) && (cellValueRule.Condition != null))
     {
         if (cellValueRule.Condition is RelationCondition)
         {
             RelationCondition condition = cellValueRule.Condition as RelationCondition;
             if (((index != 10) && (index != 11)) || ((condition.Item1 == null) || !(condition.Item1 is RelationCondition)))
             {
                 if (((index != 20) && (index != 0x15)) || ((condition.Item2 == null) || !(condition.Item2 is RelationCondition)))
                 {
                     if (((index == 0) && (condition.Item1 != null)) && (condition.Item1.ExpectedFormula != null))
                     {
                         return("=" + condition.Item1.ExpectedFormula);
                     }
                     if (((index == 1) && (condition.Item2 != null)) && (condition.Item2.ExpectedFormula != null))
                     {
                         return("=" + condition.Item2.ExpectedFormula);
                     }
                 }
                 else
                 {
                     condition = condition.Item2 as RelationCondition;
                     if (((index == 20) && (condition.Item1 != null)) && (condition.Item1.ExpectedFormula != null))
                     {
                         return("=" + condition.Item1.ExpectedFormula);
                     }
                     if (((index == 0x15) && (condition.Item2 != null)) && (condition.Item2.ExpectedFormula != null))
                     {
                         return("=" + condition.Item2.ExpectedFormula);
                     }
                 }
             }
             else
             {
                 condition = condition.Item1 as RelationCondition;
                 if (((index == 10) && (condition.Item1 != null)) && (condition.Item1.ExpectedFormula != null))
                 {
                     return("=" + condition.Item1.ExpectedFormula);
                 }
                 if (((index == 11) && (condition.Item2 != null)) && (condition.Item2.ExpectedFormula != null))
                 {
                     return("=" + condition.Item2.ExpectedFormula);
                 }
             }
         }
         else if (((index == 0) && (cellValueRule.Condition != null)) && (cellValueRule.Condition.ExpectedFormula != null))
         {
             return("=" + cellValueRule.Condition.ExpectedFormula);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 void RemoveCondition(CellRange[] ranges, ConditionBase condition)
 {
     if ((condition != null) && (ranges != null))
     {
         RelationCondition condition2 = condition as RelationCondition;
         if (condition2 != null)
         {
             this.RemoveCondition(ranges, condition2.Item1);
             this.RemoveCondition(ranges, condition2.Item2);
         }
         else
         {
             this.RemoveConditionsByRange(ranges, new IConditionalFormula[] { condition });
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates conditions for the rule.
        /// </summary>
        /// <returns>
        /// The  condition.
        /// </returns>
        protected override ConditionBase CreateCondition()
        {
            GeneralCompareType equalsTo;
            CellValueCondition condition;
            string             formula = IsFormula(this.value1) ? (this.value1 as string).TrimStart(new char[] { '=' }) : null;

            IsFormula(this.value1);
            string str2 = IsFormula(this.value2) ? (this.value2 as string).TrimStart(new char[] { '=' }) : null;

            IsFormula(this.value2);
            switch (this.op)
            {
            case ComparisonOperator.Between:
            {
                CellValueCondition condition4 = new CellValueCondition(GeneralCompareType.GreaterThanOrEqualsTo, this.value1, formula)
                {
                    TreatNullValueAsZero = true
                };
                ConditionBase      base2      = condition4;
                CellValueCondition condition5 = new CellValueCondition(GeneralCompareType.LessThanOrEqualsTo, this.value2, str2)
                {
                    TreatNullValueAsZero = true
                };
                ConditionBase      base3      = condition5;
                CellValueCondition condition6 = new CellValueCondition(GeneralCompareType.LessThanOrEqualsTo, this.value1, formula)
                {
                    TreatNullValueAsZero = true
                };
                ConditionBase      base4      = condition6;
                CellValueCondition condition7 = new CellValueCondition(GeneralCompareType.GreaterThanOrEqualsTo, this.value2, str2)
                {
                    TreatNullValueAsZero = true
                };
                ConditionBase     base5      = condition7;
                RelationCondition condition2 = new RelationCondition(RelationCompareType.And, base2, base3);
                return(new RelationCondition(RelationCompareType.Or, condition2, new RelationCondition(RelationCompareType.And, base4, base5)));
            }

            case ComparisonOperator.NotBetween:
            {
                CellValueCondition condition10 = new CellValueCondition(GeneralCompareType.LessThan, this.value1, formula)
                {
                    TreatNullValueAsZero = true
                };
                ConditionBase      base6       = condition10;
                CellValueCondition condition11 = new CellValueCondition(GeneralCompareType.GreaterThan, this.value2, str2)
                {
                    TreatNullValueAsZero = true
                };
                ConditionBase      base7       = condition11;
                CellValueCondition condition12 = new CellValueCondition(GeneralCompareType.GreaterThan, this.value1, formula)
                {
                    TreatNullValueAsZero = true
                };
                ConditionBase      base8       = condition12;
                CellValueCondition condition13 = new CellValueCondition(GeneralCompareType.LessThan, this.value2, str2)
                {
                    TreatNullValueAsZero = true
                };
                ConditionBase     base9      = condition13;
                RelationCondition condition8 = new RelationCondition(RelationCompareType.Or, base6, base7);
                return(new RelationCondition(RelationCompareType.And, condition8, new RelationCondition(RelationCompareType.Or, base8, base9)));
            }

            case ComparisonOperator.EqualTo:
            case ComparisonOperator.NotEqualTo:
            case ComparisonOperator.GreaterThan:
            case ComparisonOperator.LessThan:
            case ComparisonOperator.GreaterThanOrEqualTo:
            case ComparisonOperator.LessThanOrEqualTo:
                equalsTo = GeneralCompareType.EqualsTo;
                switch (this.op)
                {
                case ComparisonOperator.EqualTo:
                    equalsTo = GeneralCompareType.EqualsTo;
                    goto Label_00F3;

                case ComparisonOperator.NotEqualTo:
                    equalsTo = GeneralCompareType.NotEqualsTo;
                    goto Label_00F3;

                case ComparisonOperator.GreaterThan:
                    equalsTo = GeneralCompareType.GreaterThan;
                    goto Label_00F3;

                case ComparisonOperator.LessThan:
                    equalsTo = GeneralCompareType.LessThan;
                    goto Label_00F3;

                case ComparisonOperator.GreaterThanOrEqualTo:
                    equalsTo = GeneralCompareType.GreaterThanOrEqualsTo;
                    goto Label_00F3;

                case ComparisonOperator.LessThanOrEqualTo:
                    equalsTo = GeneralCompareType.LessThanOrEqualsTo;
                    goto Label_00F3;
                }
                break;

            default:
                return(null);
            }
Label_00F3:
            condition = new CellValueCondition(equalsTo, this.value1, formula);
            condition.TreatNullValueAsZero = true;
            return(condition);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a validator based on numbers.
        /// </summary>
        /// <param name="typeOperator">
        /// The type of <see cref="P:Dt.Cells.Data.DataValidator.ComparisonOperator" /> compare operator.
        /// </param>
        /// <param name="v1">The first object.</param>
        /// <param name="v2">The second object.</param>
        /// <param name="isIntegerValue">
        /// <c>true</c> if the validator is set to a number; otherwise, <c>false</c>.
        /// </param>
        /// <returns>Returns a new validator.</returns>
        public static DataValidator CreateNumberValidator(Dt.Cells.Data.ComparisonOperator typeOperator, object v1, object v2, bool isIntegerValue)
        {
            string        formula  = IsFormula(v1) ? (v1 as string).TrimStart(new char[] { '=' }) : null;
            object        expected = IsFormula(v1) ? null : v1;
            string        str2     = IsFormula(v2) ? (v2 as string).TrimStart(new char[] { '=' }) : null;
            object        obj3     = IsFormula(v2) ? null : v2;
            ConditionBase base2    = null;

            switch (typeOperator)
            {
            case Dt.Cells.Data.ComparisonOperator.Between:
            {
                NumberCondition condition = new NumberCondition(GeneralCompareType.GreaterThanOrEqualsTo, expected, formula)
                {
                    IntegerValue = isIntegerValue
                };
                NumberCondition condition2 = new NumberCondition(GeneralCompareType.LessThanOrEqualsTo, obj3, str2)
                {
                    IntegerValue = isIntegerValue
                };
                base2 = new RelationCondition(RelationCompareType.And, condition, condition2);
                break;
            }

            case Dt.Cells.Data.ComparisonOperator.NotBetween:
            {
                NumberCondition condition3 = new NumberCondition(GeneralCompareType.LessThan, expected, formula)
                {
                    IntegerValue = isIntegerValue
                };
                NumberCondition condition4 = new NumberCondition(GeneralCompareType.GreaterThan, obj3, str2)
                {
                    IntegerValue = isIntegerValue
                };
                base2 = new RelationCondition(RelationCompareType.Or, condition3, condition4);
                break;
            }

            case Dt.Cells.Data.ComparisonOperator.EqualTo:
            {
                NumberCondition condition5 = new NumberCondition(GeneralCompareType.EqualsTo, expected, formula)
                {
                    IntegerValue = isIntegerValue
                };
                base2 = condition5;
                break;
            }

            case Dt.Cells.Data.ComparisonOperator.NotEqualTo:
            {
                NumberCondition condition6 = new NumberCondition(GeneralCompareType.NotEqualsTo, expected, formula)
                {
                    IntegerValue = isIntegerValue
                };
                base2 = condition6;
                break;
            }

            case Dt.Cells.Data.ComparisonOperator.GreaterThan:
            {
                NumberCondition condition7 = new NumberCondition(GeneralCompareType.GreaterThan, expected, formula)
                {
                    IntegerValue = isIntegerValue
                };
                base2 = condition7;
                break;
            }

            case Dt.Cells.Data.ComparisonOperator.LessThan:
            {
                NumberCondition condition9 = new NumberCondition(GeneralCompareType.LessThan, expected, formula)
                {
                    IntegerValue = isIntegerValue
                };
                base2 = condition9;
                break;
            }

            case Dt.Cells.Data.ComparisonOperator.GreaterThanOrEqualTo:
            {
                NumberCondition condition8 = new NumberCondition(GeneralCompareType.GreaterThanOrEqualsTo, expected, formula)
                {
                    IntegerValue = isIntegerValue
                };
                base2 = condition8;
                break;
            }

            case Dt.Cells.Data.ComparisonOperator.LessThanOrEqualTo:
            {
                NumberCondition condition10 = new NumberCondition(GeneralCompareType.LessThanOrEqualsTo, expected, formula)
                {
                    IntegerValue = isIntegerValue
                };
                base2 = condition10;
                break;
            }
            }
            return(new DataValidator(base2)
            {
                type = isIntegerValue ? CriteriaType.WholeNumber : CriteriaType.DecimalValues, ComparisonOperator = typeOperator
            });
        }
Exemplo n.º 6
0
        bool CheckCondition(int expected, IActualValue actualValue)
        {
            if (this.IgnoreBlank && (actualValue.GetValue() == null))
            {
                return(true);
            }
            object obj2 = actualValue.GetValue(NumberFormatType.DateTime);

            if (obj2 is DateTime)
            {
                if (this.expectTypeId != 0)
                {
                    if (this.expectTypeId == 1)
                    {
                        int?nullable3 = base.GetExpectedInt(null, 0, 0);
                        if (nullable3.HasValue)
                        {
                            return(this.IsEqualsYear(nullable3.Value, (DateTime)obj2));
                        }
                    }
                    else if (this.expectTypeId == 2)
                    {
                        int?nullable4 = base.GetExpectedInt(null, 0, 0);
                        if (nullable4.HasValue)
                        {
                            return(this.IsEqualsQuarter(nullable4.Value, (DateTime)obj2));
                        }
                    }
                    else if (this.expectTypeId == 3)
                    {
                        int?nullable5 = base.GetExpectedInt(null, 0, 0);
                        if (nullable5.HasValue)
                        {
                            return(this.IsEqualsMonth(nullable5.Value, (DateTime)obj2));
                        }
                    }
                    else if (this.expectTypeId == 4)
                    {
                        int?nullable6 = base.GetExpectedInt(null, 0, 0);
                        if (nullable6.HasValue)
                        {
                            return(this.IsEqualsWeek(nullable6.Value, (DateTime)obj2));
                        }
                    }
                    else if (this.expectTypeId == 5)
                    {
                        int?nullable7 = base.GetExpectedInt(null, 0, 0);
                        if (nullable7.HasValue)
                        {
                            return(this.IsEqualsDay(nullable7.Value, (DateTime)obj2));
                        }
                    }
                }
                else
                {
                    DateTime?nullable  = null;
                    DateTime?nullable2 = null;
                    switch (((DateOccurringType)expected))
                    {
                    case DateOccurringType.Today:
                    {
                        DateTime time4 = DateTime.Now;
                        nullable  = new DateTime(time4.Year, time4.Month, time4.Day, 0, 0, 0);
                        nullable2 = new DateTime(time4.Year, time4.Month, time4.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.Yesterday:
                    {
                        DateTime time3 = DateTime.Now;
                        TimeSpan span2 = new TimeSpan(1, 0, 0, 0);
                        time3    -= span2;
                        nullable  = new DateTime(time3.Year, time3.Month, time3.Day, 0, 0, 0);
                        nullable2 = new DateTime(time3.Year, time3.Month, time3.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.Tomorrow:
                    {
                        DateTime time5 = DateTime.Now;
                        TimeSpan span3 = new TimeSpan(1, 0, 0, 0);
                        time5    += span3;
                        nullable  = new DateTime(time5.Year, time5.Month, time5.Day, 0, 0, 0);
                        nullable2 = new DateTime(time5.Year, time5.Month, time5.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.Last7Days:
                    {
                        DateTime time  = DateTime.Now;
                        TimeSpan span  = new TimeSpan(6, 0, 0, 0);
                        DateTime time2 = time - span;
                        nullable  = new DateTime(time2.Year, time2.Month, time2.Day, 0, 0, 0);
                        nullable2 = new DateTime(time.Year, time.Month, time.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.ThisMonth:
                    {
                        DateTime time21 = DateTime.Now;
                        TimeSpan span8  = new TimeSpan(time21.Day - 1, 0, 0, 0);
                        DateTime time22 = time21 - span8;
                        DateTime time24 = time22.AddMonths(1).AddDays(-1.0);
                        nullable  = new DateTime(time22.Year, time22.Month, time22.Day, 0, 0, 0);
                        nullable2 = new DateTime(time24.Year, time24.Month, time24.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.LastMonth:
                    {
                        DateTime time17 = DateTime.Now;
                        TimeSpan span7  = new TimeSpan(time17.Day - 1, 0, 0, 0);
                        DateTime time18 = time17 - span7;
                        DateTime time19 = time18.AddMonths(-1);
                        DateTime time20 = time18.AddDays(-1.0);
                        nullable  = new DateTime(time19.Year, time19.Month, time19.Day, 0, 0, 0);
                        nullable2 = new DateTime(time20.Year, time20.Month, time20.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.NextMonth:
                    {
                        DateTime time25 = DateTime.Now;
                        TimeSpan span9  = new TimeSpan(time25.Day - 1, 0, 0, 0);
                        DateTime time27 = (time25 - span9).AddMonths(1);
                        DateTime time29 = time27.AddMonths(1).AddDays(-1.0);
                        nullable  = new DateTime(time27.Year, time27.Month, time27.Day, 0, 0, 0);
                        nullable2 = new DateTime(time29.Year, time29.Month, time29.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.ThisWeek:
                    {
                        DateTime time10 = DateTime.Now;
                        TimeSpan span5  = new TimeSpan((int)time10.DayOfWeek, 0, 0, 0);
                        DateTime time11 = time10 - span5;
                        DateTime time12 = time11 + new TimeSpan(6, 0, 0, 0);
                        nullable  = new DateTime(time11.Year, time11.Month, time11.Day, 0, 0, 0);
                        nullable2 = new DateTime(time12.Year, time12.Month, time12.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.LastWeek:
                    {
                        DateTime time6 = DateTime.Now;
                        TimeSpan span4 = new TimeSpan((int)time6.DayOfWeek, 0, 0, 0);
                        DateTime time7 = time6 - span4;
                        DateTime time8 = time7 - new TimeSpan(7, 0, 0, 0);
                        DateTime time9 = time8 + new TimeSpan(6, 0, 0, 0);
                        nullable  = new DateTime(time8.Year, time8.Month, time8.Day, 0, 0, 0);
                        nullable2 = new DateTime(time9.Year, time9.Month, time9.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }

                    case DateOccurringType.NextWeek:
                    {
                        DateTime time13 = DateTime.Now;
                        TimeSpan span6  = new TimeSpan((int)time13.DayOfWeek, 0, 0, 0);
                        DateTime time14 = time13 - span6;
                        DateTime time15 = time14 + new TimeSpan(7, 0, 0, 0);
                        DateTime time16 = time15 + new TimeSpan(6, 0, 0, 0);
                        nullable  = new DateTime(time15.Year, time15.Month, time15.Day, 0, 0, 0);
                        nullable2 = new DateTime(time16.Year, time16.Month, time16.Day, 0x17, 0x3b, 0x3b);
                        break;
                    }
                    }
                    if (nullable.HasValue && nullable2.HasValue)
                    {
                        DateCondition     condition  = new DateCondition(DateCompareType.AfterEqualsTo, nullable.Value, null);
                        DateCondition     condition2 = new DateCondition(DateCompareType.BeforeEqualsTo, nullable2.Value, null);
                        RelationCondition condition3 = new RelationCondition(RelationCompareType.And, condition, condition2);
                        return(condition3.Evaluate(null, 0, 0, actualValue));
                    }
                }
            }
            return(false);
        }