public void IsSubstring_True()
        {
            var column = "D(1-3)";

            var actual = MappingTemplate.IsSubstring(column);

            Assert.True(actual);
        }
        public void GetColumn_Basic()
        {
            var column = "D";

            var actual = MappingTemplate.GetColumn(column);

            Assert.Equal(column, actual);
            Assert.False(MappingTemplate.IsSubstring(column));
            Assert.False(MappingTemplate.IsRegex(column));
        }
Esempio n. 3
0
        private bool HaveValidExcelColumnIdentifiers(string mappingTemplate)
        {
            foreach (var part in MappingTemplate.Parse(mappingTemplate))
            {
                try
                {
                    var column = MappingTemplate.GetColumn(part);

                    if (MappingTemplate.IsSubstring(part))
                    {
                        var subStringIndex = MappingTemplate.GetSubStringIndexes(part);

                        if (subStringIndex.Count != 0 && subStringIndex.Count != 2)
                        {
                            return(false);
                        }

                        if (subStringIndex.Count == 2)
                        {
                            if (subStringIndex[0] >= subStringIndex[1])
                            {
                                return(false);
                            }
                        }
                    }

                    if (!Utils.IsValidExcelColumn((column)) && column != CommissionTypes.GROUP_COMMISSION_TYPE)
                    {
                        return(false);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(true);
        }
        public static string GetCommissionTypeValue(IExcelDataReader reader, SheetConfig config, List <GroupValue> groupValues)
        {
            var parts = MappingTemplate.Parse(config.CommissionTypes.MappingTemplate);

            if (!parts.Any())
            {
                return(config.CommissionTypes.DefaultCommissionTypeCode);
            }

            var values = new List <string>();

            foreach (var part in parts)
            {
                string value = "";
                if (part == CommissionTypes.GROUP_COMMISSION_TYPE)
                {
                    value = GetGroupValue(groupValues, GroupFieldNames.CommissionType);
                }
                else
                {
                    var column = MappingTemplate.GetColumn(part);

                    var index = ExcelUtils.ColumnToIndex(column);
                    value = Utils.GetValue(reader, index);

                    //Update value is substring is defined
                    if (MappingTemplate.IsSubstring(part))
                    {
                        try
                        {
                            var subStringIndex = MappingTemplate.GetSubStringIndexes(part);

                            var startIndex = subStringIndex[0] - 1;
                            var length     = subStringIndex[1] - subStringIndex[0] + 1;
                            value = value.Substring(startIndex, length);
                        }
                        catch { }
                    }

                    //Update value is regex is defined
                    if (MappingTemplate.IsRegex(part))
                    {
                        try
                        {
                            var regex = MappingTemplate.GetRegex(part);

                            var match = Regex.Match(value, regex, RegexOptions.IgnoreCase);
                            if (match.Success)
                            {
                                value = match.Value;
                            }
                            else
                            {
                                value = "";
                            }
                        }
                        catch { }
                    }
                }

                values.Add(value);
            }

            return(MappingTemplate.Format(values));
        }