Esempio n. 1
0
        /// <summary>
        /// 模拟数据库分页(实际项目中请直接使用SQL语句返回分页数据!)
        /// </summary>
        /// <returns></returns>
        private DataTable GetPagedDataTable(int pageIndex, int pageSize, int recordCount)
        {
            DataTable source   = DataSourceUtil.GetTreeDataTable();
            DataTable topTable = GetTopNodeTable(source);

            DataTable paged = source.Clone();

            int rowbegin = pageIndex * pageSize;
            int rowend   = (pageIndex + 1) * pageSize;

            if (rowend > recordCount)
            {
                rowend = recordCount;
            }

            for (int i = rowbegin; i < rowend; i++)
            {
                DataRow topTableRow = topTable.Rows[i];
                paged.ImportRow(topTableRow);

                ImportCurrentPageTable(source, paged, Convert.ToInt32(topTableRow["Id"]));
            }

            return(paged);
        }
        // GET: GridDataUrl/TreeGridData
        public ActionResult Index()
        {
            JArray ja = new JArray();

            DataTable source = DataSourceUtil.GetTreeDataTable();

            foreach (DataRow row in source.Rows)
            {
                JObject jo = new JObject();
                jo.Add("ParentId", (int)row["ParentId"]);
                jo.Add("Id", (int)row["Id"]);
                jo.Add("Name", row["Name"].ToString());
                jo.Add("Type", row["Type"].ToString());
                jo.Add("ModifyDate", (DateTime)row["ModifyDate"]);

                object fileSize = row["Size"];
                if (fileSize == DBNull.Value)
                {
                    jo.Add("Size", "");
                }
                else
                {
                    jo.Add("Size", (int)fileSize);
                }

                ja.Add(jo);
            }

            return(Content(ja.ToString(Newtonsoft.Json.Formatting.None)));
        }
 // 模拟在服务器端保存数据
 // 特别注意:在真实的开发环境中,不要在Session放置大量数据,否则会严重影响服务器性能
 private DataTable GetSourceData()
 {
     if (Session[KEY_FOR_DATASOURCE_SESSION] == null)
     {
         Session[KEY_FOR_DATASOURCE_SESSION] = DataSourceUtil.GetTreeDataTable();
     }
     return((DataTable)Session[KEY_FOR_DATASOURCE_SESSION]);
 }
Esempio n. 4
0
        /// <summary>
        /// 模拟返回总项数
        /// </summary>
        /// <returns></returns>
        private int GetTotalCount()
        {
            DataTable source = DataSourceUtil.GetTreeDataTable();

            return(GetTopNodeTable(source).Rows.Count);
        }