Public class othermanager <t> { /// <Summary> /// Fragment the list /// </Summary> /// <Param name = "Source"> List of shards <t> </param> /// <Param name = "pagesize"> page size of a Part </param> /// <Returns> </returns> Public static list <t> segement (list <t> source, int pagesize) { List <list <t> List = new list <t> (); If (Source = NULL | source. Count = 0) { Return list; } Int totalrec = source. count; Int totalpage = totalrec % pagesize = 0? Totalrec/pagesize: totalrec/pagesize + 1;
For (INT Index = 0; index <totalpage; index ++) { Int start = Index * pagesize; List <t> TMP = new list <t> (); If (Index = totalpage-1) // The last page, half page { For (int row = start; row <totalrec; row ++) { TMP. Add (source [row]); } } Else // full page { For (int row = start; row <start + pagesize; row ++) { Tmp. Add (source [row]); } } List. Add (tmp ); } Return list; } /// <Summary> /// Shard the DataTable /// </Summary> /// <Param name = "source"> DataTable to be split </param> /// <Param name = "pageSize"> page size of a Part </param> /// <Returns> </returns> Public static List <DataTable> Segement (DataTable source, int pageSize) { List <DataTable> list = new List <DataTable> (); If (source = null | source. Rows. Count = 0) { Return list; } Int totalrec = source. Rows. count; Int totalpage = totalrec % pagesize = 0? Totalrec/pagesize: totalrec/pagesize + 1;
For (INT Index = 0; index <totalpage; index ++) { Int start = index * pageSize; DataTable dt = new DataTable (); If (index = totalPage-1) // The last page, half page { For (int row = start; row <totalRec; row ++) { Dt. ImportRow (source. Rows [row]); } } Else // full page { For (int row = start; row <start + pageSize; row ++) { Dt. ImportRow (source. Rows [row]); } } List. Add (dt ); } Return list; } } |