Exemple #1
0
        public override DataRow ToDataRow(DataRow row)
        {
            //分组字段赋值
            IEnumerable <SemicolonSeparatedItem> fileFields = Data.FileFieldItems.Where(c => c.Key != null && c.IsGrouped == true);
            IEnumerable <string> groupNames = fileFields.Select(c => c.Key).Distinct();

            foreach (string groupName in groupNames)
            {
                string fieldValue = string.Join("", fileFields.Where(c => c.Key == groupName).OrderBy(c => c.Index).Select(c => c.Value).ToArray());
                SemicolonSeparatedItem.FillRowValueByValueAndName(ref row, groupName, fieldValue);
            }
            //未分组字段赋值
            fileFields = Data.FileFieldItems.Where(c => c.Key != null && c.IsGrouped == false);
            foreach (SemicolonSeparatedItem field in fileFields)
            {
                SemicolonSeparatedItem.FillRowValueByValueAndName(ref row, field.Key, field.Value);
            }
            //静态字段赋值
            foreach (var field in Data.StaticFieldItems)
            {
                SemicolonSeparatedItem.FillRowValueByValueAndName(ref row, field.Key, field.Value);
            }

            return(row);
        }
Exemple #2
0
        /// <summary>
        /// 获取数据对象列集合
        /// </summary>
        /// <returns></returns>
        public List <string> GetSemicolonSeparatedItemColumns()
        {
            List <string> columns = new List <string>();
            //分组字段添加
            IEnumerable <SemicolonSeparatedItem> fileFields = FileFieldItems.Where(c => c.Key != null && c.IsGrouped == true);
            IEnumerable <string> groupNames = fileFields.Select(c => c.Key).Distinct();

            if (groupNames.Count() > 0)
            {
                SemicolonSeparatedItem.AddColumnByFieldName(ref columns, groupNames);
            }
            //未分组字段添加
            fileFields = FileFieldItems.Where(c => c.Key != null && c.IsGrouped == false);
            if (fileFields.Count() > 0)
            {
                SemicolonSeparatedItem.AddColumnByFieldName(ref columns, fileFields.Select(c => c.Key));
            }
            //静态字段添加
            if (StaticFieldItems.Count() > 0)
            {
                SemicolonSeparatedItem.AddColumnByFieldName(ref columns, StaticFieldItems.Select(c => c.Key));
            }
            //检查重复
            if (columns.Count != columns.Distinct().Count())
            {
                List <string> columnCopy = new List <string>(columns);

                var distinctColumns = columns.Distinct();
                foreach (var distinctColumn in distinctColumns)
                {
                    columnCopy.Remove(distinctColumn);
                }
                throw new Exception(string.Format("下列字段出现重复:{0}", string.Join("|", columnCopy)));
            }
            return(columns.Distinct().ToList());
        }