Пример #1
0
        public DataTable ExecuteDataTable(EnumColumnList enumColumns, CodeNamePairColumnList codeNamePairColunms)
        {
            DataTable table = ExecuteDataTable();

            ConvertColumn(table, enumColumns, codeNamePairColunms);
            return(table);
        }
Пример #2
0
        public DataTable ExecuteDataTable(EnumColumnList enumColumns)
        {
            DataTable table = ExecuteDataTable();

            ConvertEnumColumn(table, enumColumns);
            return(table);
        }
Пример #3
0
        private void ConvertColumnFromRow(DataRow row, EnumColumnList enumColumns, CodeNamePairColumnList codeNamePairColunms)
        {
            if (enumColumns != null && enumColumns.Count > 0)
            {
                foreach (var entry in enumColumns)
                {
                    Type enumType = entry.EnumType;
                    if (!enumType.IsEnum)
                    {
                        throw new ArgumentException("The type '" + enumType.AssemblyQualifiedName + "' is not enum.", "enumColumns");
                    }
                    int columnIndex = entry.ColumnIndex.HasValue ? entry.ColumnIndex.Value : row.Table.Columns.IndexOf(entry.ColumnName + "_ECCentral_Auto_Removed_820319");
                    if (columnIndex < 0)
                    {
                        continue;
                    }
                    if (row[columnIndex] == null || row[columnIndex] == DBNull.Value)
                    {
                        row[entry.NewColumnIndex] = DBNull.Value;
                        continue;
                    }
                    object orignalData = row[columnIndex];
                    object tmp;
                    if (orignalData == null || orignalData == DBNull.Value || orignalData.ToString().Trim().Length <= 0)
                    {
                        row[entry.NewColumnIndex] = DBNull.Value;
                    }
                    else if (EnumCodeMapper.TryGetEnum(orignalData, enumType, out tmp))
                    {
                        row[entry.NewColumnIndex] = tmp;
                    }
                    else
                    {
                        row[entry.NewColumnIndex] = Enum.Parse(enumType, orignalData.ToString(), true);
                    }
                }
            }

            if (codeNamePairColunms != null && codeNamePairColunms.Count > 0)
            {
                foreach (var entry in codeNamePairColunms)
                {
                    int columnIndex = entry.ColumnIndex.HasValue ? entry.ColumnIndex.Value : row.Table.Columns.IndexOf(entry.ColumnName + "_ECCentral_Auto_Removed_820319");
                    if (row[columnIndex] == null || row[columnIndex] == DBNull.Value)
                    {
                        row[entry.NewColumnIndex] = DBNull.Value;
                        continue;
                    }
                    List <CodeNamePair> list = CodeNamePairManager.GetList(entry.DomainName, entry.Key);
                    string       code        = row[columnIndex].ToString();
                    CodeNamePair option      = list.Find(x => x.Code == code);
                    if (option.Code != null)
                    {
                        row[entry.NewColumnIndex] = option.Name;
                    }
                }
            }
        }
Пример #4
0
        public void ConvertColumn(DataTable table, EnumColumnList enumColumns, CodeNamePairColumnList codeNamePairColunms)
        {
            if (table == null || table.Rows == null || table.Rows.Count <= 0)
            {
                return;
            }
            if (enumColumns != null && enumColumns.Count > 0)
            {
                foreach (var entry in enumColumns)
                {
                    Type enumType = entry.EnumType;
                    if (!enumType.IsEnum)
                    {
                        throw new ArgumentException("The type '" + enumType.AssemblyQualifiedName + "' is not enum.", "enumColumns");
                    }
                    string columnName = entry.ColumnIndex.HasValue ? table.Columns[entry.ColumnIndex.Value].ColumnName : entry.ColumnName;
                    int    index      = table.Columns.IndexOf(columnName);
                    if (index >= 0)
                    {
                        table.Columns[index].ColumnName = (entry.NewColumnNameForOriginalValue != null && entry.NewColumnNameForOriginalValue.Trim().Length > 0) ?
                                                          entry.NewColumnNameForOriginalValue : (columnName + "_ECCentral_Auto_Removed_820319");
                        table.Columns.Add(columnName, enumType);
                        entry.ColumnIndex    = index;
                        entry.NewColumnIndex = table.Columns.Count - 1;
                    }
                }
            }
            if (codeNamePairColunms != null && codeNamePairColunms.Count > 0)
            {
                foreach (var entry in codeNamePairColunms)
                {
                    string columnName = entry.ColumnIndex.HasValue ? table.Columns[entry.ColumnIndex.Value].ColumnName : entry.ColumnName;
                    int    index      = table.Columns.IndexOf(columnName);
                    if (index >= 0)
                    {
                        table.Columns[index].ColumnName = (entry.NewColumnNameForOriginalValue != null && entry.NewColumnNameForOriginalValue.Trim().Length > 0) ?
                                                          entry.NewColumnNameForOriginalValue : (columnName + "_ECCentral_Auto_Removed_820319");
                        table.Columns.Add(columnName, typeof(string));
                        entry.ColumnIndex    = index;
                        entry.NewColumnIndex = table.Columns.Count - 1;
                    }
                }
            }

            foreach (DataRow row in table.Rows)
            {
                ConvertColumnFromRow(row, enumColumns, codeNamePairColunms);
            }
        }
Пример #5
0
 public void ConvertEnumColumn(DataTable table, EnumColumnList enumColumns)
 {
     ConvertColumn(table, enumColumns, null);
 }