zoukankan      html  css  js  c++  java
  • 通用类 Utility

    /// <summary>
        /// 常用方法
        /// </summary>
        public static class Utility
        {
            /// <summary>
            /// DataTable翻页
            /// </summary>
            /// <param name="pageIndex">页序号</param>
            /// <param name="pageSize">每页显示数量</param>
            /// <param name="recordCount">总记录数</param>
            /// <param name="dt">要翻页浏览的DataTable</param>
            /// <returns></returns>
            public static DataTable GetPage(int pageIndex, int pageSize, out int recordCount, DataTable dt)
            {
                recordCount = 0;
                if(dt == null)
                    return null;
    
                recordCount = dt.Rows.Count;
    
                if(pageIndex == 0)
                    pageIndex = 1;
    
                DataTable newdt = dt.Clone();
    
                int rowBegin = (pageIndex - 1) * pageSize;
                int rowEnd = pageIndex * pageSize;
    
                if(rowBegin >= dt.Rows.Count)
                    return newdt;
    
                if(rowEnd > dt.Rows.Count)
                    rowEnd = dt.Rows.Count;
                for(int i = rowBegin; i <= rowEnd - 1; i++)
                {
                    newdt.ImportRow(dt.Rows[i]);
                }
                dt.Dispose();
                return newdt;
            }
    
            /// <summary>
            /// 将数据实体序列化,返回序列化后的字符
            /// </summary>
            /// <param name="model">要序列化的数据实体</param>
            /// <returns></returns>
            public static string Serialize<TSource>(TSource model)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return serializer.Serialize(model);
            }
              
    
            /// <summary>
            /// Json反序列化,用于接收客户端Json后生成对应的对象
            /// </summary>
            /// <typeparam name="T">对象类型</typeparam>
            /// <param name="json">Json字符串</param>
            /// <returns>Json后生成对应的对象</returns>
            public static T Deserialize<T>(this string json)
            {
                if (json != null && json.Trim() != string.Empty)
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    return serializer.Deserialize<T>(json);
                }
                return default(T);
            }
        }
    
  • 相关阅读:
    Prim算法的3个版本
    [转]"undefined reference to" 问题解决方法
    C/C++ 读写 Excel
    Poj 3468
    关于PS中矩形工具的学习
    PS初学习
    java第二天学习。
    Java学习第一天
    二叉树的线索化
    struct files_struct
  • 原文地址:https://www.cnblogs.com/acyy/p/2662261.html
Copyright © 2011-2022 走看看