Ejemplo n.º 1
0
        public List <string> GetValusFromSource <T>(T data, int CelaMaxCount = 0)
        {
            List <string> result       = new List <String>();
            Type          t            = typeof(T);
            var           exportFields = t.GetProperties().Where(x => x.CustomAttributes.Select(p => p.AttributeType.Name).ToList().Contains("DisplayNameAttribute")).ToList();

            foreach (var p in exportFields)
            {
                Object value = p.GetValue(data, null);
                if (value == null)
                {
                    result.Add("");
                    continue;
                }
                if (value.GetType() == typeof(long) && p.Name == "ModifyDate")
                {
                    result.Add(LinqHelper.GetDateTime(value as long?).ToString("yyyy-MM-dd HH:mm:ss"));
                    continue;
                }
                if (typeof(T) == typeof(Order))
                {
                    string[] uploadFields = { "FileContents", "FileDetails", "BaiduActions" };
                    if (p.Name == "CelaExplains")
                    {
                        int i = 1;
                        (value as System.Collections.ObjectModel.ObservableCollection <CelaExplain>).ToList().ForEach(
                            item =>
                        {
                            result.Add(item.Item);
                            if (null == item.Strategy)
                            {
                                result.Add("");
                            }
                            else
                            {
                                result.Add(String.Join("\n", item.Strategy));
                            }
                            i++;
                        });
                        while (i <= CelaMaxCount)
                        {
                            result.Add("");
                            result.Add("");
                            i++;
                        }
                        continue;
                    }
                    else if (value.GetType() == typeof(List <string>))
                    {
                        value = String.Join("\n", (value as List <string>));
                    }
                    else if (uploadFields.Contains(p.Name))
                    {
                        var list = (value as System.Collections.ObjectModel.ObservableCollection <UploadImage>).ToList()
                                   .Select(x => String.Format("附件:{0}.{1}", x.Id, x.FileExtension)).ToList();
                        if (null != list && list.Count > 0)
                        {
                            value = String.Join("\n", list);
                        }
                        else
                        {
                            value = "";
                        }
                    }
                }
                else if (typeof(T) == typeof(PageQueryEntry))
                {
                    if (p.Name == "IsExpire")
                    {
                        var entity = new IsExpireToStingConverter();
                        value = entity.Convert(value, null, null, "");
                    }
                    else if (p.Name == "ValidDays")
                    {
                        value = Enum.GetName(typeof(ValidDays), value);
                    }
                    else if (value.GetType() == typeof(string[]))
                    {
                        value = String.Join("\n", (value as string[]));
                    }
                }
                result.Add(value.ToString());
            }
            return(result);
        }