C# 获取集合后分页处理

1. 思路
  • 取出数据集合
  • 计算总页数等
  • 遍历取出处理
2. 这里只贴一下代码段,方便自己以后参考
Dictionary dicList = SensetimeApi.GetVisitorListByType(2);
            List resList = new List();
            int recordCount = dicList.Count;
            int pageSize = 50;
            int totalPage = 0;
            if (recordCount % pageSize == 0)
            {
                totalPage = recordCount / pageSize;
            }
            else
            {
                totalPage = (recordCount / pageSize) + 1;
            }
            for (int pageNum = 1; pageNum <= totalPage; pageNum++)
            {
                List updateList = new List();
                Dictionary strList = new Dictionary();
                List tempList = dicList.Skip(pageSize * (pageNum - 1)).Take(pageSize).Select(x => x.Value).ToList();
                strList = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(SensetimeApi.GetSensetDesrypt(tempList)));
                foreach (var item in strList)
                {
                    try
                    {
                        int dicKey = dicList.Where(x => x.Value.Equals(item.Key)).FirstOrDefault().Key;
                        if (dicKey > 0)
                        {
                            VisitorModel visitor = BizBase.Get().GetModelByPhone(item.Value);
                            if (visitor != null)
                            {
                               // Log4Helper.Warn(this.GetType(), $"用户名:{visitor.SName} sID:{Convert.ToString(dicKey)}");
                                visitor.SID = Convert.ToString(dicKey);
                                updateList.Add(visitor);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
                if (updateList != null && updateList.Count > 0)
                {
                    BizBase.Get().UpdateModelList(updateList);
                }
            }

2

//字典
var dt = new Dictionary();
dt.Add("id", 1);
dt.Add("name", null);
dt.Add("createTime", DateTime.Now);
var t66 = db.Updateable(dt).AS("student").WhereColumns("id").ExecuteCommand();

Dictionary dicList = SensetimeApi.GetVisitorListByType(2);
                    List resList = new List();
                    int recordCount = dicList.Count;
                    int pageSize = 50;
                    int totalPage = 0;
                    if (recordCount % pageSize == 0)
                    {
                        totalPage = recordCount / pageSize;
                    }
                    else
                    {
                        totalPage = (recordCount / pageSize) + 1;
                    }
                    for (int pageNum = 1; pageNum <= totalPage; pageNum++)
                    {
                        //List updateList = new List();
                        Dictionary strList = new Dictionary();
                        List> dicResList = new List>();
                        List tempList = dicList.Skip(pageSize * (pageNum - 1)).Take(pageSize).Select(x => x.Value).ToList();
                        strList = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(SensetimeApi.GetSensetDesrypt(tempList)));
                        foreach (var item in strList)
                        {
                            try
                            {
                                int dicKey = dicList.Where(x => x.Value.Equals(item.Key)).FirstOrDefault().Key;
                                if (dicKey > 0)
                                {
                                    VisitorModel visitor = BizBase.Get().GetModelByPhone(item.Value);
                                    if (visitor != null)
                                    {
                                        Dictionary dicTemp = new Dictionary();
                                        dicTemp.Add("pkCode", visitor.Code);
                                        dicTemp.Add("sID", Convert.ToString(dicKey));
                                        dicResList.Add(dicTemp);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                continue;
                            }
                        }
                        if (dicResList != null && dicResList.Count > 0)
                        {
                            BizBase.Get().UpdateDictionaryList(dicResList);
                        }
                    }

你可能感兴趣的:(C# 获取集合后分页处理)