/// <summary> /// 根据提供的类型 获取Excel 表头信息 /// </summary> /// <param name="type">外界调用</param> /// <param name="pi">如果是泛型属性,则继续</param> /// <returns></returns> public List <SheetInfo> GetSheetInfo(Type type, PropertyInfo pi = null) { var sheets = new List <SheetInfo>(); var propertyInfos = ReflectionTool.GetPropertyInfosFromCache(type); var sheetName = type.FullName; sheets.Add(new SheetInfo { Name = sheetName, Type = type, PropertyInfo = pi }); var list = sheets[0].ColumnInfos; foreach (var propertyInfo in propertyInfos) { if (propertyInfo.PropertyType.IsGenericType && propertyInfo.PropertyType.GetGenericTypeDefinition() != typeof(Nullable <>)) { if (ReflectionTool.GetCustomAttributeEx <NotImportAttribute>(propertyInfo) == null) { var t = propertyInfo.PropertyType.GenericTypeArguments[0]; var dictTmp = GetSheetInfo(t, propertyInfo); sheets.AddRange(dictTmp); } } else { var notImport = (ReflectionTool.GetCustomAttributeEx <NotImportAttribute>(propertyInfo) != null); string columnName = propertyInfo.Name; /*添加列定义的字段类型*/ string columnTypename = GetColumnTypeName(propertyInfo, type); ////获取导入模板列中的备注内容 string columnComment = columnTypename; if (ReflectionTool.GetCustomAttributeEx <ImportCommentAttribute>(propertyInfo) != null) { columnComment += ("," + ReflectionTool.GetCustomAttributeEx <ImportCommentAttribute>(propertyInfo).Commont); } list.Add(new SheetColumnInfo() { NotImport = notImport, Name = columnName, Note = columnComment, ColProperty = propertyInfo, MustImport = ReflectionTool.GetCustomAttributeEx <RequiredAttribute>(propertyInfo) != null }); } } return(sheets); }
/// <summary> /// 分页查询 /// 如果T中有OraModel,并且查询总记录数,并且查询条件都隶属于OraModel,则使用单表查询 /// </summary> /// <param name="searchParameters">查询参数 <see cref="DynamicSearch.SearchParameters" /></param> /// <param name="sqlwhere">字符串的查询条件</param> /// <returns>一个待查询的结果集</returns> public IQueryable <T> GetByPage(SearchParameters searchParameters, string sqlwhere = "") { //处理EF查询时,查询null值问题 searchParameters.BuildEmptySearch(); if (searchParameters.PageInfo.IsGetTotalCount && searchParameters.PageInfo.PageSize <= 1) { var attr = ReflectionTool.GetCustomAttributeEx <ViewOraModelAttribute>(typeof(T)); if (attr != null) { var oraModelPropInfos = ReflectionTool.GetPropertyInfosFromCache(attr.OraModel); // 判断是否所有的查询条件都在单表内 var sqlWhereCondition = sqlwhere.Split( new[] { " And ", " Or ", " AND ", " OR ", " and ", " or " }, StringSplitOptions.RemoveEmptyEntries); sqlWhereCondition = GetPropNameBySqlWhere(sqlWhereCondition); if (searchParameters.QueryModel?.Items != null && searchParameters.QueryModel.Items.All(a => oraModelPropInfos.Any(b => b.Name == a.Field)) && sqlWhereCondition.All(a => oraModelPropInfos.Any(b => a.ToLower().Equals(b.Name.ToLower())))) { GetSingleTableQuickCount(searchParameters, sqlwhere, attr); return(new List <T>().AsQueryable()); } } } IQueryable <T> list = _dbSet.Where(searchParameters.QueryModel); if (!string.IsNullOrEmpty(sqlwhere)) { list = list.Where(sqlwhere); } var totalCount = 0; var result = GetByPage(list, searchParameters.PageInfo, out totalCount); searchParameters.PageInfo.TotalCount = totalCount; return(result); }