/// <summary> /// ������ת��Ϊresultobject ������ /// </summary> /// <param name="List">Դ����</param> /// <returns>����ResultObject</returns> public static ResultObject ConvertToResultObject(IList listobj) { ResultObject RO = new ResultObject(); if (listobj == null || listobj.Count == 0) { RO["records"] = 0; return null; } ArrayList list = new ArrayList(); for (int i = 0; i < listobj.Count; i++) { IDictionary dict = new SortedList(); PropertyInfo[] properties = listobj[i].GetType().GetProperties(); foreach (PropertyInfo p in properties) { dict[p.Name] = p.GetValue(listobj[i], null); } list.Add(dict); } RO["records"] = listobj.Count; RO.Rows = list; return RO; }
/// <summary> /// ������ת��Ϊresultobject /// </summary> /// <param name="dtSource">Դ����</param> /// <param name="filter">datatable��ɸѡ����</param> /// <param name="sorter">datatable����������</param> /// <param name="pageIndex">��ҳ��ʼ����</param> /// <param name="pageSize">ÿҳ��¼����0Ϊ��ҳ</param> /// <returns>����ResultObject</returns> public static ResultObject ConvertToResultObject(DataTable dtSource,string filter,string sorter,int pageIndex,int pageSize) { ResultObject RO = new ResultObject(); if (dtSource == null || dtSource.Rows.Count == 0) { RO["records"] = 0; return null; } DataRow[] row = dtSource.Select(filter, sorter); int recordCount = row.Length; int start = pageIndex * pageSize; ArrayList list = new ArrayList(); int endIndex = start + pageSize; //��ҳ״̬��endindexΪ��¼���� if (pageSize == 0) { endIndex = recordCount; } if (endIndex > recordCount) endIndex = recordCount; for (int i = start; i < endIndex; i++) { IDictionary dict = new SortedList(); foreach(DataColumn column in dtSource.Columns) { dict[column.ColumnName] = row[i][column.ColumnName]; } list.Add(dict); } RO["records"] = recordCount; RO.Rows = list; return RO; }