public bool IsMatch(ExcelDatabaseRow row, ExcelDatabaseCriteria criteria)
        {
            var retVal = true;

            foreach (var c in criteria.Items)
            {
                var candidate = c.Key.FieldIndex.HasValue ? row[c.Key.FieldIndex.Value] : row[c.Key.FieldName];
                var crit      = c.Value;
                if (candidate.IsNumeric() && crit.IsNumeric())
                {
                    if (System.Math.Abs(ConvertUtil.GetValueDouble(candidate) - ConvertUtil.GetValueDouble(crit)) > double.Epsilon)
                    {
                        return(false);
                    }
                }
                else
                {
                    var criteriaString = crit.ToString();
                    if (!Evaluate(candidate, criteriaString))
                    {
                        return(false);
                    }
                }
            }
            return(retVal);
        }
Exemple #2
0
 public ExcelDatabaseRow Read()
 {
     var retVal = new ExcelDatabaseRow();
     _rowIndex++;
     foreach (var field in Fields)
     {
         var colIndex = _fromCol + field.ColIndex;
         var val = GetCellValue(_rowIndex, colIndex);
         retVal[field.FieldName] = val;
     }
     return retVal;
 }
        public ExcelDatabaseRow Read()
        {
            var retVal = new ExcelDatabaseRow();

            _rowIndex++;
            foreach (var field in Fields)
            {
                var colIndex = _fromCol + field.ColIndex;
                var val      = GetCellValue(_rowIndex, colIndex);
                retVal[field.FieldName] = val;
            }
            return(retVal);
        }
Exemple #4
0
        public void IsMatchShouldMatchStrings2()
        {
            var data = new ExcelDatabaseRow();
            data["Crit1"] = "2";
            data["Crit2"] = 2;
            data["Crit3"] = 3;

            var crit = new Dictionary<ExcelDatabaseCriteriaField, object>();
            crit[new ExcelDatabaseCriteriaField("Crit1")] = "1";
            crit[new ExcelDatabaseCriteriaField("Crit3")] = 3;

            var matcher = new RowMatcher();

            var criteria = GetCriteria(crit);

            Assert.IsFalse(matcher.IsMatch(data, criteria));
        }
Exemple #5
0
        public void IsMatchShouldReturnFalseIfCriteriasDoesNotMatch()
        {
            var data = new ExcelDatabaseRow();
            data["Crit1"] = 1;
            data["Crit2"] = 2;
            data["Crit3"] = 3;

            var crit = new Dictionary<ExcelDatabaseCriteriaField, object>();
            crit[new ExcelDatabaseCriteriaField("Crit1")] = 1;
            crit[new ExcelDatabaseCriteriaField("Crit3")] = 4;

            var matcher = new RowMatcher();

            var criteria = GetCriteria(crit);

            Assert.IsFalse(matcher.IsMatch(data, criteria));
        }
Exemple #6
0
 public bool IsMatch(ExcelDatabaseRow row, ExcelDatabaseCriteria criteria)
 {
     var retVal = true;
     foreach (var c in criteria.Items)
     {
         var candidate = c.Key.FieldIndex.HasValue ? row[c.Key.FieldIndex.Value] : row[c.Key.FieldName];
         var crit = c.Value;
         if (candidate.IsNumeric() && crit.IsNumeric())
         {
             if(System.Math.Abs(ConvertUtil.GetValueDouble(candidate) - ConvertUtil.GetValueDouble(crit)) > double.Epsilon) return false;
         }
         else
         {
             var criteriaString = crit.ToString();
             if (!Evaluate(candidate, criteriaString))
             {
                 return false;
             }
         }
     }
     return retVal;
 }
Exemple #7
0
        public void IsMatchShouldHandleFieldIndex()
        {
            var data = new ExcelDatabaseRow();
            data["Crit1"] = "test";
            data["Crit2"] = 2;
            data["Crit3"] = 3;

            var crit = new Dictionary<ExcelDatabaseCriteriaField, object>();
            crit[new ExcelDatabaseCriteriaField(2)] = "<3";
            crit[new ExcelDatabaseCriteriaField("Crit3")] = 3;

            var matcher = new RowMatcher();

            var criteria = GetCriteria(crit);

            Assert.IsTrue(matcher.IsMatch(data, criteria));
        }