欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Asp.Net 通用數(shù)據(jù)操作類 (附通用數(shù)據(jù)基類)

 更新時間:2008年07月13日 21:52:53   作者:  
以前經(jīng)常用php的數(shù)據(jù)操作類,這次的asp.net數(shù)據(jù)操作類,是個方法

        /// <summary>
        /// 執(zhí)行存儲過程(返回記錄集)
        /// </summary>
        /// <param name="procName">過程名</param>
        /// <param name="hashtable">傳入的參數(shù)表</param>
        /// <returns>返回記錄集</returns>
        public DataSet ExecProcedure(string procName, System.Collections.Hashtable hashtable)
        {
            System.Data.DataSet ds = new DataSet();
            com.CommandText = procName;
            com.CommandType = CommandType.StoredProcedure;

            System.Collections.IDictionaryEnumerator ide = hashtable.GetEnumerator();

            while (ide.MoveNext())
            {
                System.Data.SqlClient.SqlParameter p = new System.Data.SqlClient.SqlParameter(ide.Key.ToString(), ide.Value);
                com.Parameters.Add(p);
            }
            try
            {
                System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(com);
                da.Fill(ds);
                da.Dispose();
            }
            catch (Exception ee)
            {
                throw new Exception(ee.Message.ToString());
            }
            finally
            {
                com.Cancel();
            }
            return ds;
        }
        #endregion

        #region 數(shù)據(jù)操作
        /// <summary>
        /// 統(tǒng)計某表記錄總數(shù)
        /// </summary>
        /// <param name="KeyField">主鍵/索引鍵</param>
        /// <param name="TableName">數(shù)據(jù)庫.用戶名.表名</param>
        /// <param name="Condition">查詢條件</param>
        /// <returns>返回記錄總數(shù)</returns>
        public int GetRecordCount(string keyField, string tableName, string condition)
        {
            int RecordCount = 0;
            string sql = "select count(" + keyField + ") as count from " + tableName + " " + condition;
            System.Data.DataSet ds = GetDataSet(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                RecordCount =Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            }
            ds.Clear();
            ds.Dispose();
            return RecordCount;
        }
        /// <summary>
        /// 統(tǒng)計某表記錄總數(shù)
        /// </summary>
        /// <param name="Field">可重復的字段</param>
        /// <param name="tableName">數(shù)據(jù)庫.用戶名.表名</param>
        /// <param name="condition">查詢條件</param>
        /// <param name="flag">字段是否主鍵</param>
        /// <returns>返回記錄總數(shù)</returns>
        public int GetRecordCount(string Field, string tableName, string condition, bool flag)
        {
            int RecordCount = 0;
            if (flag)
            {
                RecordCount = GetRecordCount(Field, tableName, condition);
            }
            else
            {
                string sql = "select count(distinct(" + Field + ")) as count from " + tableName + " " + condition;
                System.Data.DataSet ds = GetDataSet(sql);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
                }
                ds.Clear();
                ds.Dispose();
            }
            return RecordCount;
        }
        /// <summary>
        /// 統(tǒng)計某表分頁總數(shù)
        /// </summary>
        /// <param name="keyField">主鍵/索引鍵</param>
        /// <param name="tableName">表名</param>
        /// <param name="condition">查詢條件</param>
        /// <param name="pageSize">頁寬</param>
        /// <param name="RecordCount">記錄總數(shù)</param>
        /// <returns>返回分頁總數(shù)</returns>
        public int GetPageCount(string keyField, string tableName, string condition, int pageSize, int RecordCount)
        {
            int PageCount = 0;
            PageCount = (RecordCount % pageSize) > 0 ? (RecordCount / pageSize) + 1 : RecordCount / pageSize;
            if (PageCount < 1) PageCount = 1;
            return PageCount;
        }
        /// <summary>
        /// 統(tǒng)計某表分頁總數(shù)
        /// </summary>
        /// <param name="keyField">主鍵/索引鍵</param>
        /// <param name="tableName">表名</param>
        /// <param name="condition">查詢條件</param>
        /// <param name="pageSize">頁寬</param>
        /// <returns>返回頁面總數(shù)</returns>
        public int GetPageCount(string keyField, string tableName, string condition, int pageSize, ref int RecordCount)
        {
            RecordCount = GetRecordCount(keyField, tableName, condition);
            return GetPageCount(keyField, tableName, condition, pageSize, RecordCount);
        }
        /// <summary>
        /// 統(tǒng)計某表分頁總數(shù)
        /// </summary>
        /// <param name="Field">可重復的字段</param>
        /// <param name="tableName">表名</param>
        /// <param name="condition">查詢條件</param>
        /// <param name="pageSize">頁寬</param>
        /// <param name="flag">是否主鍵</param>
        /// <returns>返回頁頁總數(shù)</returns>
        public int GetPageCount(string Field, string tableName, string condition, ref int RecordCount, int pageSize, bool flag)
        {
            RecordCount = GetRecordCount(Field, tableName, condition, flag);
            return GetPageCount(Field, tableName, condition, pageSize, ref RecordCount);
        }
        #endregion

        #region 分頁函數(shù)
         /// <summary>
        /// 構造分頁查詢SQL語句
        /// </summary>
        /// <param name="KeyField">主鍵</param>
        /// <param name="FieldStr">所有需要查詢的字段(field1,field2...)</param>
        /// <param name="TableName">庫名.擁有者.表名</param>
        /// <param name="Condition">查詢條件1(where ...)</param>
        /// <param name="Condition2">查詢條件2(order by ...)</param>
        /// <param name="CurrentPage">當前頁號</param>
        /// <param name="PageSize">頁寬</param>
        /// <returns>SQL語句</returns>
        public static string JoinPageSQL(string KeyField, string FieldStr, string TableName, string Condition, string Condition2, int CurrentPage, int PageSize)
        {
            string sql = null;
            if (CurrentPage == 1)
            {
                sql = "select top " + CurrentPage * PageSize + " " + FieldStr + " from " + TableName + " " + Condition + " " + Condition2 + " ";
            }
            else
            {
                sql = "select * from (";
                sql += "select top " + CurrentPage * PageSize + " " + FieldStr + " from " + TableName + " " + Condition + " " + Condition2 + ") a ";
                sql += "where " + KeyField + " not in (";
                sql += "select top " + (CurrentPage - 1) * PageSize + " " + KeyField + " from " + TableName + " " + Condition + " " + Condition2 + ")";
            }
            return sql;
        }
        /// <summary>
        /// 構造分頁查詢SQL語句
        /// </summary>
        /// <param name="Field">字段名(非主鍵)</param>
        /// <param name="TableName">庫名.擁有者.表名</param>
        /// <param name="Condition">查詢條件1(where ...)</param>
        /// <param name="Condition2">查詢條件2(order by ...)</param>
        /// <param name="CurrentPage">當前頁號</param>
        /// <param name="PageSize">頁寬</param>
        /// <returns>SQL語句</returns>
        public static string JoinPageSQL(string Field, string TableName, string Condition, string Condition2, int CurrentPage, int PageSize)
        {
            string sql = null;
            if (CurrentPage == 1)
            {
                sql = "select top " + CurrentPage * PageSize + " " + Field + " from " + TableName + " " + Condition + " " + Condition2 + " group by " + Field;
            }
            else
            {
                sql = "select * from (";
                sql += "select top " + CurrentPage * PageSize + " " + Field + " from " + TableName + " " + Condition + " " + Condition2 + " group by " + Field + " ) a ";
                sql += "where " + Field + " not in (";
                sql += "select top " + (CurrentPage - 1) * PageSize + " " + Field + " from " + TableName + " " + Condition + " " + Condition2 + " group by " + Field + ")";
            }
            return sql;
        }
        /// <summary>
        /// 頁面分頁顯示功能
        /// </summary>
        /// <param name="Parameters">參數(shù)串(a=1&amp;b=2...)</param>
        /// <param name="RecordCount">記錄總數(shù)</param>
        /// <param name="PageSize">頁寬</param>
        /// <param name="CurrentPage">當前頁號</param>
        /// <param name="ShowJump">是否顯示跳轉(zhuǎn)輸入框及按鈕</param>
        /// <param name="Style">樣式(1:上頁下頁...,2:1234...)</param>
        /// <returns></returns>
        public static string Paging(string Parameters, int RecordCount, int PageCount, int PageSize, int CurrentPage, bool ShowJump, int Style)
        {
            string str;
            if (RecordCount <= PageSize) return "";
            if (Parameters != "") Parameters += "&";
            if (CurrentPage < 1) CurrentPage = 1;
            if (CurrentPage > PageCount) CurrentPage = PageCount;

            str = "<table align='center'  width=\"100%\"><tr><td align=\"center\">";

            str += "共 " + RecordCount + " 條記錄 頁次:" + CurrentPage + "/" + PageCount + "頁 ";
            str += PageSize + "條/頁 ";

            if (Style == 1)
            {
                if (CurrentPage == 1)
                    str += "<font color=\"#999999\">首頁 上頁</font> ";
                else
                {
                    str += "<a href='?" + Parameters + "page=1'  class=\"link\">首頁</a> ";
                    str += "<a href='?" + Parameters + "page=" + (CurrentPage - 1) + "'  class=\"link\">上頁</a> "; ;
                }
                if (CurrentPage == PageCount )
                {
                    str += "<font color=\"#999999\">下頁 尾頁</font> ";
                }
                else
                {
                    str += "<a href='?" + Parameters + "page=" + (CurrentPage + 1) + "'  class=\"link\">下頁</a> ";
                    str += "<a href='?" + Parameters + "page=" + PageCount + "'  class=\"link\">尾頁</a>  ";
                }
            }
            else if (Style == 2)
            {
                int NumberSize = 10;
                int PageNumber = (CurrentPage - 1) / NumberSize;

                if (PageNumber * NumberSize > 0)
                    str += "<a href='?" + Parameters + "page=" + PageNumber * NumberSize + "' title=上十頁 >[&lt;&lt;]</a>   ";
                int i;
                for (i = PageNumber * NumberSize + 1; i <= (PageNumber + 1) * NumberSize; i++)
                {
                    if (i == CurrentPage)
                        str += "<strong><font color=#ff0000>[" + i + "]</font></strong> ";
                    else
                        str += "<a href='?" + Parameters + "page=" + i + "'>[" + i + "]</a> ";
                    if (i == PageCount) break;
                }
                if (i < RecordCount) str += "<a href='?" + Parameters + "page=" + i + "' title=下十頁>[&gt;&gt;]</a>  ";
            }
            if (ShowJump)
            {
                str += "";
            }
            str += "</td></tr></table>";
            return str;
        }

        #endregion
    }
}

相關文章

  • 淺析.net簡單工廠模式

    淺析.net簡單工廠模式

    這篇文章主要介紹了淺析.net簡單工廠模式,需要的朋友可以參考下
    2014-12-12
  • .NET中利用js讓子窗體向父頁面?zhèn)髦档膶崿F(xiàn)方法

    .NET中利用js讓子窗體向父頁面?zhèn)髦档膶崿F(xiàn)方法

    .NET中利用js讓子窗體向父頁面?zhèn)髦档膶崿F(xiàn)方法,需要的朋友可以參考一下
    2013-02-02
  • MVC異常處理詳解

    MVC異常處理詳解

    這篇文章主要為大家詳細介紹了MVC異常處理的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • 微信公眾平臺開發(fā)教程(二) 基本原理及消息接口總結

    微信公眾平臺開發(fā)教程(二) 基本原理及消息接口總結

    本篇文章主要介紹了微信公眾平臺開發(fā)教程(二) 基本原理及消息接口,具有一定的參考價值,有興趣的朋友可以了解一下。
    2016-12-12
  • .NET?6中為record類型自定義Equals方法

    .NET?6中為record類型自定義Equals方法

    這篇文章主要介紹了.NET?6中為record類型自定義Equals方法,record類型,這是一種新引用類型,而不是類或結構。record與類不同,區(qū)別在于record類型使用基于值的相等性,下文小編將介紹更多詳細資料,需要的朋友可以參考一下
    2022-03-03
  • asp.net關于Cookie跨域(域名)的問題

    asp.net關于Cookie跨域(域名)的問題

    Cookie是一個偉大的發(fā)明,它允許Web開發(fā)者保留他們的用戶的登錄狀態(tài)。但是當你的站點有一個以上的域名時就會出現(xiàn)問題了。在Cookie規(guī)范上說,一個cookie只能用于一個域名,不能夠發(fā)給其它的域名。因此,如果在瀏覽器中對一個域名設置了一個cookie,這個cookie對于其它的域名將無效。如果你想讓你的用戶從你的站點中的其中一個進行登錄,同時也可以在其它域名上進行登錄,這可真是一個大難題。
    2012-12-12
  • .NetCore?Web?Api?利用ActionFilterAttribute統(tǒng)一接口返回值格式及問題解析

    .NetCore?Web?Api?利用ActionFilterAttribute統(tǒng)一接口返回值格式及問題解析

    在實際項目開發(fā)過程中,統(tǒng)一API返回值格式對前端或第三方調(diào)用將是非常必要的,在.NetCore中我們可以通過ActionFilterAttribute來進行統(tǒng)一返回值的封裝,對.NetCore?Web?Api?統(tǒng)一接口返回值格式相關知識感興趣的朋友一起看看吧
    2022-03-03
  • Win7安裝Visual Studio 2015失敗的解決方法

    Win7安裝Visual Studio 2015失敗的解決方法

    這篇文章主要為大家詳細介紹了Win7安裝Visual Studio 2015失敗的解決方案,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • asp.net 頁面逐步呈現(xiàn)的方法總結

    asp.net 頁面逐步呈現(xiàn)的方法總結

    分塊編碼 ( chunked encoding )就是讓 response 分塊編碼進行傳輸。response 分塊編碼,可以先傳輸一部分不需要處理的 html 代碼到客戶端,等其他耗時代碼執(zhí)行完畢后再傳輸另外的 html 代碼。
    2010-06-06
  • 封裝的一個asp.net驗證碼類

    封裝的一個asp.net驗證碼類

    昨天在一個Q群上面群主發(fā)了一個用ASP.NET實現(xiàn)驗證碼的demo,下載下來然后運行正常,頁面上的img標簽成功調(diào)用了一個一般處理程序并顯示了中文的驗證碼圖片,雖然有點模糊,但是可見上面是四個中文,圖片背景為白色,背后有噪點線,邊框黑色。
    2010-12-12

最新評論