/// <summary> /// 刷新数据 /// </summary> private void RefreshData() { //请求接口获取数据 var res = Client.QueryListByObject<List<MdvcDeprPrdVo>>(ApiKey.ADMIN_PLATFORM_MDVCDEPRPRDHANDLER_GETALL, null); if (res.Flag == ResultFlag.SUCCESS) { List<MdvcDeprPrdVo> datas = res.Value ?? new List<MdvcDeprPrdVo>(); datas = datas.OrderBy(m => m.DdpYear).ThenBy(n => n.DdpMonth).ToList(); if (datas.Count > 0) { //将集合根据属性进行分组获取多个集合 var gr = datas.GroupBy(m => m.DdpYear); //对分组后获得的集合操作 foreach (var item in gr) { List<MdvcDeprPrdVo> mdpList = item.ToList(); if(mdpList!=null && mdpList.Count>0) { int i = 1; foreach(var s in mdpList) { s.DdpYearMonth = $"{s.DdpYear}年第{i}期"; i++; } } } } dgvMain.DataSource = datas; } else { MsgBox.Show($"接口报错!{res.Message}"); Common.LocalLog.Write(Common.LogLevel.important, "{0}:{1},{2}", res + "失败", res.Flag.ToString(), res.Message); } }
效果图