Esempio n. 1
0
        public DataTable GetPagedRecords(int tableId, string keyword, int pageSize, int currentPageIndex,
                                         out int recordCount, out int pageCount)
        {
            var columns = GetColumns(tableId);
            var dt      = dal.GetPagedRows(tableId, keyword, pageSize, currentPageIndex, out recordCount, out pageCount);

            //将列添加进入datatable(列名为:$+ID)
            if (columns != null && columns.Count != 0)
            {
                foreach (var c in columns)
                {
                    dt.Columns.Add(new DataColumn("$" + c.Id.ToString()));
                }
            }

            //如果不存在行则并取得数据
            if (dt.Rows.Count != 0)
            {
                //计算RowID范围
                var indent = 0;
                var ids    = new int[dt.Rows.Count];
                foreach (DataRow dr in dt.Rows)
                {
                    ids[indent] = int.Parse(dr["id"].ToString());
                    ++indent;
                }

                var          rowDatas = dal.GetRowsData(ids).ToEntityList <TableRowData>();
                TableRowData tr;
                for (var i = 0; i < dt.Rows.Count; i++)
                {
                    for (var j = 0; j < columns.Count; j++)
                    {
                        //获取包含数据的行
                        tr = rowDatas.FirstOrDefault(a =>
                                                     a.Rid == int.Parse(dt.Rows[i]["id"].ToString()) && a.Cid == columns[j].Id);

                        //对列赋值
                        if (tr != null)
                        {
                            dt.Rows[i]["$" + columns[j].Id.ToString()] = tr.Value;
                        }
                    }
                }
            }

            return(dt);
        }