/// <summary> /// 设置 Cookie 数据 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="cookieName">Cookie 名称</param> /// <param name="data">实体数据</param> /// <param name="expires">过期时间</param> /// <param name="httpResponse">HttpResponseBase,如果未指定则取自 HttpContext.Current.Response</param> /// <param name="propertyMatchExpression">属性匹配,例:p=> new { ID = p.UserID }</param> /// <param name="propertyExpression">属性列表,如果指定则按指定属性列表设置 Cookie 数据,例:p=> new { p.UserID }</param> /// <param name="propertyContain">是否包含,true 属性包含,flase 属性排除</param> /// <param name="reflectionType">反射类型</param> public static void SetCookieT <T>(string cookieName, T data, DateTime expires, HttpResponseBase httpResponse = null, Expression <Func <T, object> > propertyMatchExpression = null, Expression <Func <T, object> > propertyExpression = null, bool propertyContain = true, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { Dictionary <string, object> propertyDict = CommonHelper.GetExpressionDict <T>(propertyMatchExpression); List <string> propertyNameList = CommonHelper.GetExpressionList <T>(propertyExpression); CookieHelper.ExecuteSetCookie <T>(httpResponse, cookieName, data, expires, propertyDict, propertyNameList, propertyContain, reflectionType); }
/// <summary> /// 返回 DataTable 数据 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="dataList">实体类型数据列表</param> /// <param name="propertyMatchExpression">属性匹配,例:p=> new { ID = p.UserID }</param> /// <param name="propertyExpression">属性列表,如果指定,则按指定属性列表 DataTable 数据,例:p=> new { p.UserID }</param> /// <param name="propertyContain">是否包含,true 属性包含,flase 属性排除</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static DataTable ToDataTable <T>(List <T> dataList, Expression <Func <T, object> > propertyMatchExpression, Expression <Func <T, object> > propertyExpression = null, bool propertyContain = true, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { Dictionary <string, object> propertyDict = CommonHelper.GetExpressionDict <T>(propertyMatchExpression); List <string> propertyNameList = CommonHelper.GetExpressionList <T>(propertyExpression); return(DataTableHelper.ExecuteToDataTable <T>(dataList, propertyDict, propertyNameList, propertyContain, reflectionType)); }
/// <summary> /// 根据实体数据列表创建 Excel /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="dataList">实体数据列表</param> /// <param name="excelPath">Excel 路径</param> /// <param name="sheetName">Sheet 表单名称</param> /// <param name="propertyMatchExpression">属性匹配,例:p=> new { ID = p.UserID }</param> /// <param name="propertyExpression">属性列表,如果指定,则按指定属性列表生成 Excel 数据,例:p=> new { p.UserID }</param> /// <param name="propertyContain">是否包含,true 属性包含,flase 属性排除</param> /// <param name="cellCallback">单元格写入之后调用</param> /// <param name="sheetCallback">表单数据写入之后调用</param> /// <param name="isHeader">是否创建表头</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static bool ToExcel <T>(List <T> dataList, string excelPath, string sheetName, Expression <Func <T, object> > propertyMatchExpression, Expression <Func <T, object> > propertyExpression = null, bool propertyContain = true, Action <ICell, object> cellCallback = null, Action <ISheet, List <string> > sheetCallback = null, bool isHeader = true, object columnValueFormat = null, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class, new() { bool result = ExcelHelper.ExecuteIWorkbookWrite(excelPath, (IWorkbook workbook) => { Dictionary <string, object> propertyDict = CommonHelper.GetExpressionDict <T>(propertyMatchExpression); Dictionary <string, object> valueFormatDict = CommonHelper.GetParameterDict(columnValueFormat); List <string> propertyNameList = CommonHelper.GetExpressionList <T>(propertyExpression); ExcelHelper.ToSheet(workbook, dataList, sheetName, cellCallback, sheetCallback, isHeader, propertyNameList, propertyContain, propertyDict, valueFormatDict, reflectionType); }); return(result); }
/// <summary> /// 设置索引 /// </summary> /// <typeparam name="T">实体类型</typeparam> /// <param name="dataList">实体数据列表</param> /// <param name="propertyExpression">属性筛选列表,例:p=> new { p.UserID }</param> /// <param name="primaryKey">主键,默认为空,表示添加索引,如果主键不为空,则表示按主键更新索引</param> /// <param name="maxBufferedDocs">最小合并文档数</param> /// <param name="maxMergeFactory">最小合并因子</param> /// <param name="reflectionType">反射类型</param> /// <returns></returns> public static bool Set <T>(List <T> dataList, Expression <Func <T, object> > propertyExpression, string primaryKey = "", int maxBufferedDocs = 1000, int maxMergeFactory = 1000, ReflectionTypeEnum reflectionType = ReflectionTypeEnum.Expression) where T : class { List <string> filterNameList = CommonHelper.GetExpressionList <T>(propertyExpression); return(ExecuteSet <T>(dataList, primaryKey, filterNameList, maxBufferedDocs, maxMergeFactory, reflectionType)); }