runliuv

runliuv@cnblogs

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

ZZ

--

/// <summary>
        /// 分批处理。
        /// </summary>
        public void PartialProc()
        {
            int per_count = 4;//每个datatable行数。每4行处理一次。
            DataTable dt = new DataTable();
            dt.Columns.Add("barcode");
            dt.Columns.Add("qty");
            dt.Rows.Add("a", "1");
            dt.Rows.Add("b", "1");
            dt.Rows.Add("c", "1");
            dt.Rows.Add("d", "1");
            dt.Rows.Add("e", "1");
            dt.Rows.Add("f", "1");
            dt.Rows.Add("g", "1");
            dt.Rows.Add("h", "1");
            dt.Rows.Add("i", "1");
            dt.Rows.Add("j", "1");
            dt.Rows.Add("k", "1");

            DataTable dtPer = dt.Clone();
            int count = dt.Rows.Count;
            int pages = count % per_count == 0 ? count / per_count : count / per_count + 1;//最终DataTable个数
            List<DataTable> list = new List<DataTable>();
            for (int i = 0; i < pages; i++)
            {
                #region 这个是LINQ方式
                //list.Add(dt.AsEnumerable().Skip(i * pre_count).Take(pre_count).CopyToDataTable());
                #endregion

                #region 这个是LINQ方式
                if (i == pages - 1)
                {
                    dtPer = dt.Clone();
                    for (int j = i * per_count; j < count; j++)
                    {
                        dtPer.Rows.Add(dt.Rows[j][0], dt.Rows[j][1]);
                    }

                    DoIt(dtPer);
                }
                else
                {
                    dtPer = dt.Clone();
                    for (int j = i * per_count; j < (i + 1) * per_count; j++)
                    {
                        dtPer.Rows.Add(dt.Rows[j][0], dt.Rows[j][1]);
                    }

                    DoIt(dtPer);
                }
                #endregion
            }
            //list为最终拆分的DataTable集合
            string som2 = string.Empty;
        }

        public void DoIt(DataTable dtProc)
        { 
            
        }

 

ZZ

--

ZZ

posted on 2013-10-13 18:30  runliuv  阅读(894)  评论(0编辑  收藏  举报